akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
int n, k;
const int maxn = 2005;
const int maxk = 10005;
const int maxc = 1e6 + 20;
int len[maxn];
int start[maxn];

bitset<maxk> can[maxn];
int ss[maxc];
int critical[maxc];

int loc[2][maxc];

int main(){
  memset(critical, -1, sizeof(critical));
  scanf("%d%d\n", &n, &k);
  int tt = 0;
  vector<bool> appr(26);
  for(int i=0;i<n;i++){
    //string s; getline(cin, s);
    string s; cin >> s;
    len[i] = s.length();
    start[i] = tt;
    critical[tt] = i;
    for(int e=0;e<s.length();e++){
      int c = s[e] - 'a';
      appr[c] = true;
      ss[tt] = c;
      tt++;
    }
  }
  int numappr = 0;
  for(int i=0;i<26;i++)if(appr[i]) numappr++;
  if(numappr == 1){
    for(int i=0;i<26;i++){
      if(appr[i]){
	cout << string(k, (i + 'a')) << "\n";
	return 0;
      }
    }
  }
  
  can[n][0] = true;
  for(int i=n-1;i>=0;i--){
    can[i] = can[i+1] | (can[i+1]<<len[i]);
  }

  int q = 0;
  int cnt = 0;
  
  for(int i=0;i<n;i++){
    if(can[i+1][k-len[i]]) loc[q][cnt++] = start[i];
  }
  string ans = "";

  
  for(int eee = 0; eee < k; eee++){
    int mn = 1e9;
    for(int i=0;i<cnt;i++){
      int x = loc[q][i];
      mn = min(mn, ss[x]);
    }
    ans.push_back(mn + 'a');
    int mnn = 1e9;
    int ncnt = 0;
    for(int i=0;i<cnt;i++){
      int x = loc[q][i];
      if(ss[x] != mn) continue;
      if(critical[x+1] != -1){
	mnn = min(mnn, critical[x+1]);
      }
      else{
	loc[q ^ 1][ncnt++] = x + 1;
      }
    }
    if(mnn != 1e9){
      for(int i = mnn; i < n; i++){
	if(k-eee-1-len[i]>=0 && can[i+1][k-eee-1-len[i]]) loc[q ^ 1][ncnt++] = start[i];
      }
    }

    q ^= 1;
    cnt = ncnt;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 10624
fun main() = Thread(null, ::abc168b, "", 128 * 1024 * 1024).start()

@OptIn(ExperimentalStdlibApi::class)
fun abc168b() {
    val k = readLine()!!.toInt()
    val s = readLine()!!

    val answer = if (s.length > k) s.take(k) + "..." else s

    println(answer)
}


Measured memory_bytes: 36068
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;


int main()
{
	int N;
	cin >> N;
	vector<string> words;
	string t;
	cin >> t;
	words.push_back(t);
	for (int i=1; i < N; i++) {
		cin >> t;
      vector<string>::iterator ite = find(words.begin(), words.end(), t);
		if (ite != words.end()) {
			cout << "No" << endl;
			return 0;
		}
		string last = words[words.size()-1];
		if(last[last.size()-1]!=t[0]){
			cout << "No" << endl;
			return 0;
		}
		else {
			words.push_back(t);
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

ll a[20][20], dp[N], pr[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < n; j++) {
			if ((1 << j) & i) {
				for (int k = j; k < n; k++) {
					if ((1 << k) & i) {
						pr[i] += a[j][k];
					}
				}
			}
		}
	}

	for (int i = 0; i < (1 << n); i++) {
		for (int j = i; j; j = (j - 1) & i) {
			dp[i] = max(dp[i], dp[(i ^ j)] + pr[j]);
		}
	}

	cout << dp[(1 << n) - 1];
}

Measured memory_bytes: 1280
#include<iostream>
#include<climits>
#include<vector>
using namespace std;
//Reference: submission #5108576,2019/04/24
int main(){
  int N;
  string S;

  cin >> N >> S;

  vector<int> WhiteVec;
  vector<int> BlackVec;
  int Black_temp=0, White_temp=0;

  //make cumulative-sum of black and white, respectively.
  WhiteVec.push_back(0);
  BlackVec.push_back(0);
  for(int i=1; i<N+1; i++){
    WhiteVec.push_back(WhiteVec[i-1]);
    BlackVec.push_back(BlackVec[i-1]);
    if(S[i-1] == '.') WhiteVec[i]++;
    else BlackVec[i]++;
  }
  int Answer = INT_MAX;
  for(int i=0; i<N+1; i++){
    //We have to change the 'black' to 'white' before i-th (all stones must be white)
    //If there is black stone (after i-th), we have to change the 'white' to 'black'
    Answer = min(Answer, BlackVec[i]+(WhiteVec[N]-WhiteVec[i]));
  }
  cout<<Answer<<endl;
  return 0;
}


Measured memory_bytes: 2288
#include <iostream>
using namespace std;

int main (){
	int n;
	cin >> n;
	int b[n-1];
	for(int i=0; i<n-1; i++){
		cin >> b[i];
	}
	int res=b[n-2]+b[0];
	for(int i=n-2; i>0; i--){
		res+=min(b[i], b[i-1]);
	}
	cout << res;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (countBlack, pointBlack) = readLine()!!.split(" ").map { it.toInt() }
    val (min, max) = Pair((pointBlack - countBlack + 1), (pointBlack + countBlack - 1))

    val sb = StringBuilder()
    for (i in min..max){
        sb.append("$i ")
    }
	//削らない場合の結果確認
    println(sb)
}

Measured memory_bytes: 37876
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[,]A = new int[10,10];
		for(var i=1;i<=9;i++){
			if(i<=N){
				A[i,i]++;
			}
		}
		for(var i=11;i<=99;i++){
			int a1 = i/10;
			int a2 = i%10;
			if(a1!=0&&a2!=0){
				if(i<=N){
					A[a1,a2]++;
				}
			}
		}
		for(var i=11;i<=99;i++){
			int a1 = i/10;
			int a2 = i%10;
			if(a1!=0&&a2!=0){
				if(a1*100+a2<=N){
					A[a1,a2] += Math.Min((N-(a1*100+a2))/10+1,10);
				}
			}
		}
		for(var i=11;i<=99;i++){
			int a1 = i/10;
			int a2 = i%10;
			if(a1!=0&&a2!=0){
				if(a1*1000+a2<=N){
					A[a1,a2] += Math.Min((N-(a1*1000+a2))/10+1,100);
				}
			}
		}
		for(var i=11;i<=99;i++){
			int a1 = i/10;
			int a2 = i%10;
			if(a1!=0&&a2!=0){
				if(a1*10000+a2<=N){
					A[a1,a2] += Math.Min((N-(a1*10000+a2))/10+1,1000);
				}
			}
		}
		for(var i=11;i<=99;i++){
			int a1 = i/10;
			int a2 = i%10;
			if(a1!=0&&a2!=0){
				if(a1*100000+a2<=N){
					A[a1,a2] += Math.Min((N-(a1*100000+a2))/10+1,10000);
				}
			}
		}
		long ans = 0;
		for(var i=1;i<=9;i++){
			for(var j=1;j<=9;j++){
				ans += A[i,j]*A[j,i];
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;

int s[3000][3000]; 
char c[3000][3000];
int main(){
    int h,w,k;
    cin >> h >> w >> k;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++){
        cin >> c[i][j];
        s[i][j] =c[i][j] - '0';
    }
    int flag=0;
    int solv=1e9;
    int tmp;
    for(int i=0;i<(1<<h);i++){
        vector<int> ans;
        flag=0;
        tmp=__builtin_popcount(i);
        ans.push_back(s[0][0]);
        for(int j=0;j<h-1;j++){
            if(i&(1<<j))ans.push_back(s[j+1][0]);
            else ans[ans.size()-1]+=s[j+1][0];
            if(ans[ans.size()-1]>k){
                flag++;
                break;
            }
        }
        if(flag==0){
            for(int l=1;l<w;l++){
                flag=0;
                vector<int> num;
                num.push_back(s[0][l]);
                for(int j=0;j<h-1;j++){
                    if(i&(1<<j))num.push_back(s[j+1][l]);
                    else num[num.size()-1]+=s[j+1][l];
                    if(num[num.size()-1]>k){
                        flag++;
                        break;
                    }
                }
                if(flag>0)break;
                else{
                    for(int l=0;l<ans.size();l++){
                        ans[l]+=num[l];
                        if(ans[l]>k){
                            flag++;
                            break;
                        }
                    }
                    if(flag>0){
                        tmp++;
                        for(int l=0;l<ans.size();l++)ans[l]=num[l];
                        flag=0;
                    }
                }
            }
            if(flag==0)solv=min(solv,tmp);
        }
    }
    cout << solv << endl;
}


Measured memory_bytes: 2304
# https://atcoder.jp/contests/abc171/tasks/abc171_c

TBL = [*'a'..'z'].freeze
n = N = gets.to_i

ans = ''
while n.positive?
  k = n % 26
  k = 26 if k.zero?
  ans = TBL[k - 1] + ans
  n = (n - k) / 26
end

puts ans


Measured memory_bytes: 14340
from functools import reduce

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

for i in range(N):
    P[i] -= 1
    Q[i] -= 1

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

# return [g, x, y]
# g = gcd(a, b)
# x, y satisfies a x + b y = g
def extgcd(a, b):
    if b == 0:
        return [a, 1, 0]
    g, x, y = extgcd(b, a%b)
    return [g, y, x - a//b * y]

# eq0: x = a0 (mod m0)
# eq1: x = a1 (mod m1)
# returns [xt, mod] such that x = xt + k mod for integer k.
def crt(eq0, eq1):
    a0, m0 = eq0
    a1, m1 = eq1

    g = gcd(m0, m1)

    if a0 % g != a1 % g:
        print(-1)
        exit(0)

    if g > 1:
        m0 //= g
        m1 //= g

        while True:
            gt = gcd(m0, g)
            if gt == 1:
                break
            m0 *= gt
            g //= gt
        
        m1 *= g

        a0 %= m0
        a1 %= m1

    g, p, q = extgcd(m0, m1)
    
    x = a0 * q * m1 + a1 * p * m0
    mod = m0 * m1
    x = x % mod

    return [x, mod]

eqs = []
for i in range(N):
    a = []
    for j in range(3 * N):
        if len(a) == 2:
            break
        if P[i] == i:
            a.append(j)
        P[i] = Q[P[i]]
    if len(a) != 2:
        print(-1)
        exit(0)
    eqs.append([a[0], a[1] - a[0]])

x, mod = reduce(crt, eqs, (0, 1))
print(x % mod)


Measured memory_bytes: 6292
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    if(a > b) {
        out(0);
        re0;
    }

    if(n == 1 && a != b) {
        out(0);
        re0;
    }

    if(n == 1) {
        out(1);
        re0;
    }
    
    out( (b*(n-1) + a) - (a*(n-1) + b) + 1 );
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cerr<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

#define INF (int)10000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 998244353

ld find(int x, int y)
{
	ld z = x*x + y*y;
	z = sqrtl(z);
	return z;
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 	int n, d;
 	cin>>n>>d;
 	int cnt = 0;
 	for (int i=0;i<n;++i)
 	{
 		int x, y;
 		cin>>x>>y;
 		ld l = find(x, y);
 		if (l <= d)
 			cnt++;
 	}
 	cout << cnt << "\n";
    
    return 0;
}



Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < 3; i++) {
			sb.append(sc.next().charAt(i));
		}

		System.out.println(sb);
	}
}

Measured memory_bytes: 35388
import sys
from itertools import permutations
from math import factorial

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def distance_nd(p, q):
    return sum((px - qx) ** 2.0 for px, qx in zip(p, q)) ** 0.5


def main():
    N = int(readline())
    P = [0] * N
    for i in range(N):
        P[i] = tuple(map(int, readline().split()))

    dist = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(i + 1, N):
            dist[i][j] = dist[j][i] = ((P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2) ** 0.5

    ans = 0
    for perm in permutations(range(N)):
        for i in range(N - 1):
            ans += dist[perm[i]][perm[i + 1]]

    ans /= factorial(N)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define vi vector<int>
#define umap unordered_map
#define pii pair<int, int>
#define vpii vector<pii>
#define uset unordered_set
#define frw(i, a, b) for(int i = (a); i < (b); i++)
#define bck(i, a, b) for(int i = (a); i > (b); i--)
#define T() int testcases; cin >> testcases; frw(TC, 1, testcases + 1)
#define tez ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define fi first
#define se second
#define pow asdihagsiduh
#define pub push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (int)(a.size())
#define sq(a) ((a) * (a))

#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1> 
void ZZ(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}

//console o/p without variable names
#define trace1(...) ZZZ(__VA_ARGS__)
template<typename Arg1>
void ZZZ(Arg1&& arg1){
    cerr << arg1 << endl;
}
template<typename Arg1, typename... Args>
void ZZZ(Arg1&& arg1, Args&&... args){
    cerr << arg1 << ' ';
    ZZZ(args...);
}

signed main(){
    tez
    int n; cin >> n;
    vpii a(n);
    frw(i, 0, n){
        cin >> a[i].fi >> a[i].se;
        a[i] = {a[i].fi - a[i].se, a[i].fi + a[i].se};
    }
    sort(all(a), [&] (auto x, auto y){
        if(x.se == y.se)    return x.fi < y.fi;
        return x.se < y.se;
    });
    int ans = 1, curr = a[0].se;
    frw(i, 1, n){
        if(a[i].fi >= curr){
            ++ans;
            curr = a[i].se;
        }
    }
    cout << ans;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >>N;
  if(N%2==0){
    cout<<N*(N-1)/2-N/2<<endl;
    for(int i=1;i<N;i++){
      for(int j=i+1;j<=N;j++){
        if(j!=N-i+1){
          cout << i << " " << j << endl;
        }
      }
    }
  }else{
    cout<<N*(N-1)/2-(N-1)/2<<endl;
    for(int i=1;i<N;i++){
      for(int j=i+1;j<=N;j++){
        if(j!=N-i)
          cout<<i<<" "<< j << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>

#define _USE_MATH_DEFINES
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999;
#define atcoder 1000000007;

using namespace std;

int main() {
	
	int A, B;
	cin >> A >> B;

	if (A == 1)A += 13;
	if (B == 1)B += 13;

	if (A == B) {
		cout << "Draw" << endl;
	}
	else if (A == 2 || A>B) {
		cout << "Alice" << endl;
	}
	else if (B == 2||A<B) {
		cout << "Bob" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main(){
      int N;cin >> N;
      if(N == 2){
            cout << 1 << endl;
      }else if(N%2 == 1){
            cout << N/2 + 1 << endl;
      }else{
            cout << N/2 << endl;
      }
}


Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_060_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 i      PIC 9(5).
    01 INP    PIC X(10).
    01 A      PIC 9(3).
    01 B      PIC 9(3).
    01 C      PIC 9(2).
    01 num    PIC 9(5).
    01 flg    PIC 9(1) VALUE 0.
    01 pi     PIC 9(5).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO A B C.

    MOVE A TO num.

    PERFORM VARYING i FROM 1 BY 1 UNTIL A * B < num
        IF FUNCTION MOD(num, B) = C THEN
            MOVE 1 TO flg
            EXIT PERFORM
        ELSE
            ADD 1 TO i GIVING pi
            MULTIPLY pi BY A GIVING num
        END-IF
    END-PERFORM.

    IF flg = 1 THEN
        DISPLAY "YES"
    ELSE
        DISPLAY "NO"
    END-IF.

    STOP RUN.


Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;


int main(int argc, char *argv[]) {
    int a, b;
    cin >> a >> b;
    if (a <= 9 && b <= 9)
        cout << a * b << endl;
    else
        cout << -1 << endl;
}




Measured memory_bytes: 256
let () = Scanf.scanf "%d %d %d %d %d %d" @@ fun a b c d e f ->
  begin
  List.concat @@ Array.to_list @@ Array.init (1 + f / (100 * a)) (fun i ->
    List.concat @@ Array.to_list @@ Array.init (1 + (f - 100 * a * i) / (100 * b)) (fun j ->
      if i = 0 && j = 0 then []
      else
      List.concat @@ Array.to_list @@ Array.init (1 + (f - 100 * (a * i + b * j)) / c) (fun k ->
        if e * (a * i + b * j) < c * k then []
        else
        List.concat @@ Array.to_list @@ Array.init (1 + (f - 100 * (a * i + b * j) - c * k) / d) (fun l ->
          if e * (a * i + b * j) < c * k + d * l then []
          else [(100 * (a * i + b * j), c * k + d * l)]))))
  end
  |> (fun ((a, b) :: abs) ->
      List.fold_left (fun (a, b) (a', b') ->
        if b' * (a + b) <= b * (a' + b') then (a, b) else (a', b')) (a, b) abs)
  |> (fun (a, b) -> Printf.printf "%d %d\n" (a + b) b)



Measured memory_bytes: 62952
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var test = new Test();
            var n = test.ConvertIntArray(test.ReadInput());
            var list = new List<string>();

            var sb1 = new StringBuilder();
            for (var i = 0; i<n[1]; i++)
            {
                sb1.Append(n[0].ToString());
            }
            list.Add(sb1.ToString());

            var sb2 = new StringBuilder();
            for (var i = 0; i<n[0]; i++)
            {
                sb2.Append(n[1].ToString());
            }
            list.Add(sb2.ToString());
            list.Sort();
            Console.WriteLine(list[0]);

        }

        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public int[] ConvertIntArray(string[] x)
        {
            var convertedArray = new int[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public double[] ConvertDoubleArray(string[] x)
        {
            var convertedArray = new double[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = int.Parse(x[i]);
            }

            return convertedArray;
        }

        public long[] ConvertLongArray(string[] x)
        {
            var convertedArray = new long[x.Length];
            for (var i = 0; i < x.Length; i++)
            {
                convertedArray[i] = long.Parse(x[i]);
            }

            return convertedArray;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

Measured memory_bytes: 11360
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n-- >0 ){
            vector<double>x(4),y(4);
            for(int i=0;i<4;i++)
	             cin>>x[i]>>y[i];
	    if( fabs((x[1]-x[0])*(y[3]-y[2]) - (x[3]-x[2])*(y[1]-y[0])) <1.0e-10  )          
			cout << "YES" << endl;
            else
                       cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll x,m=100;
    cin >> x;
    rep(i,1,1000000){
        m += m/100;
        if(m>=x){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>
#include<numeric>

using namespace std;


int main()
{
  long long N, K;

  cin >> N >> K;

  long long temp = N % K;

  long long ans = min(temp, abs(temp-K));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
char num1[10000000]={0},num11[10000000]={0},num2[10000000]={0},b[10000000]={0};
int main(void)
{
    int n1=0,n2=0;
    int i,j,k;
    while(scanf("%d",&n1)!=EOF)
    {
        if(n1==0)break;
        //fflush(stdin);
        getchar();
        for(i=0;i<n1;i++)
        {
            //fflush(stdin);
            //getchar();
            scanf("%[^\n]",b);
            num1[i]=b[0];
            num11[i]=b[2];
            b[0]='\0';b[1]='\0';b[2]='\0';
            //fflush(stdin);
            getchar();
        }
        //fflush(stdin);
        //printf("ok3\n");
        //getchar();
        scanf("%d",&n2);
        for(i=0;i<n2;i++)
        {
            //printf("ok4\n");
            //fflush(stdin);
            scanf("%s",b);
            num2[i]=b[0];
            b[0]='\0';
            //fflush(stdin);
            getchar();
        }
        for(i=0;i<n2;i++)
        {
            //printf("ng");
            if(num2[i]!=9999)
            {
                for(j=0;j<n1;j++)
                {
                    if(num2[i]==num1[j])
                    {
                        //printf("%c = %c\n",num2[i],num11[j]);
                        num2[i]=num11[j];
                        //printf("\n%c = %c\n",num2[i],num11[j]);
                        break;
                    }
                }
            }
        }
        //printf("%c\n",num2[3]);
        for(i=0;i<10000000;i++)
        {
            if(num2[i]!='\0')printf("%c",num2[i]);
            num1[i]='\0';
            num11[i]='\0';
            num2[i]='\0';
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 31884
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  string s;
  cin >> s;
  if (s == "SUN") {
    cout << 7 << endl;
  }
  if (s == "MON") {
    cout << 6 << endl;
  }
  if (s == "TUE") {
    cout << 5 << endl;
  }
  if (s == "WED") {
    cout << 4 << endl;
  }
  if (s == "THU") {
    cout << 3 << endl;
  }
  if (s == "FRI") {
    cout << 2 << endl;
  }
  if (s == "SAT") {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdio.h>

#define _ << " " <<
#define debug(x) #x << " = " << x

#define ll long long
#define ull unsigned long long

const int maxn= 1e5+10;
int seen[maxn];

const ll mod = 1000000007;
ll precomp[maxn];
ll f(int x)
{
    return precomp[x];
}

ll pow(ll b, ll e) {
    if (e == 0)
        return 1;
    if (e == 1) return b;

    ll t = pow(b, e / 2);
    t = t * t;
    t %= mod;
    if (e & 1)
        return (t * b) % mod;
    else
        return t;
}

ll inv(ll x)
{
    return pow(x, mod - 2);
}

ll comb(ll n, ll k) {
    if (n < k) return 0;
    ll a = f(n);
    ll b = f(n - k) * f(k);
    b %= mod;

    return (a * inv(b)) % mod;
}

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;

    precomp[1] = precomp[0] = 1;
    for (ll i = 2; i < maxn; i++)
        precomp[i] = precomp[i - 1] * i, precomp[i] %= mod;

    std::memset(seen, -1, sizeof(seen));
    int a[n + 1];
    int idx = -1;
    for (int i = 0; i < n + 1; i++) {
        std::cin >> a[i];
        if (seen[a[i]] > -1) {
            idx = i;
            break;
        } else {
            seen[a[i]] = i;
        }
    }

    int i = seen[a[idx]];
    int j = idx;

    ll x, y, z;
    ll c1 = i;
    ll c2 = n - j;
    //std::cout << debug(i) _ debug(j) << std::endl;

    x = c1;
    y = c2;

    std::cout << n << "\n";
    std::cout << (comb(n + 1, 2) - x - y + mod) % mod << std::endl;

    z = c1 * c2;
    x *= c1 - 1;
    y *= c2 - 1;

    x %= mod;
    y %= mod;
    z %= mod;

    for (int i = 3; i <= n + 1; i++) {
        ll s = comb(n + 1, i);

        if (i - 1 <= c1) {
            x = comb(c1, i - 1);
        } else {
            x = 0;
        }

        if (i - 1 <= c2) {
            y = comb(c2, i - 1);
        } else {
            y = 0;
        }

        if (i - 1 <= c1 + c2) {
            z = comb(c1 + c2, i - 1);
            z -= comb(c1, i - 1);
            z = z % mod;
            z -= comb(c2, i - 1);
            z = (z % mod + mod) % mod;
        } else {
            z = 0;
        }

        std::cout << ((s - x - y - z) % mod + mod) % mod << std::endl;

    }


    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

struct Node { // left-child, right-sibling
    int parent;
    int child;   // left
    int sibling; // right
};

#define NIL -1

vector<Node> tree;
vector<int> depth;

void setDepth(int u, int p) {
    depth[u] = p;
    if (tree[u].sibling != NIL)
        setDepth(tree[u].sibling, p); // right sibling -> same depth
    if (tree[u].child != NIL)
        setDepth(tree[u].child, p+1); // left child -> depth + 1
}

int main() {
    int n;
    cin >> n;
    int i;
    rep(i, n) { // init
        Node node;
        node.parent = NIL;
        node.child = NIL;
        node.sibling = NIL;
        tree.push_back(node);
    }
    rep(i, n) {
        depth.push_back(0);
    }

    int child;
    rep(i, n) { // input
        int id, sibcnt;
        cin >> id >> sibcnt;
        int j;
        rep(j, sibcnt) {
            int c;
            cin >> c;
            if (j == 0)
                tree[id].child = c; // left child
            else
                tree[child].sibling = c; // right sibling
            child = c;
            tree[c].parent = id;
        }
    }

    int root;
    rep(i, n) { // search root
        if (tree[i].parent == NIL)
            root = i;
    }

    setDepth(root, 0);

    rep(i, n) { // print
        cout << "node " << i << ": ";
        cout << "parent = " << tree[i].parent << ", ";
        cout << "depth = " << depth[i] << ", ";

        if (tree[i].parent == NIL)
            cout << "root, ";
        else if (tree[i].child == NIL)
            cout << "leaf, ";
        else
            cout << "internal node, ";

        cout << "[";
        int cl = tree[i].child;
        while (cl != NIL) {
            cout << cl;
            if (tree[cl].sibling == NIL)
                break;
            else
                cout << ", "; cl = tree[cl].sibling;
        }
        cout << "]" << endl;
    }

    return 0;
}



Measured memory_bytes: 7920
#include<bits/stdc++.h>
using namespace std;
int dp[100005]={0};
int in[100005]={0};
int vis[100005]={1};
void dfs(int u,vector<int> g[])
{
  vis[u]=1;
  for(auto v : g[u])
  {
    dp[v]=max(dp[v],1+dp[u]);
    --in[v];
    if(in[v]==0)
      dfs(v,g);
  }
}
int main()
{
  int n,m;
  cin>>n>>m;
  int x,y;
  vector<int> g[n+1];
  for(int i=1;i<=m;i++)
  {
    cin>>x>>y;
    g[x].push_back(y);
    ++in[y];
  }
  for(int i=1;i<=n;i++)
  {
    if(vis[i]==0&&in[i]==0)
      dfs(i,g);
  }
  int ans=0;
  for(int i=1;i<=n;i++)
    ans=max(ans,dp[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 16448
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    long long N, M, K;
    cin >> N >> M >> K;
    vector<long long> A(N), B(M), AA(N+1), BB(M+1);
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i];
    for(int i=1; i<=N; i++) AA[i] = AA[i-1] + A[i-1];
    for(int i=1; i<=M; i++) BB[i] = BB[i-1] + B[i-1];

    long long ans = 0;
    for(int i=0; i<=N; i++){
        long long cur = AA[i];
        if(cur > K) break;
        auto itr = lower_bound(BB.begin(), BB.end(), K-cur);
        if(itr==B.end()) ans = max(ans, i+M);
        else if(*itr==K-cur){
            long long idx = itr-BB.begin();
            ans = max(ans, i+idx);
        }else if(itr!=B.begin()){
            long long idx = itr-BB.begin();
            ans = max(ans, i+idx-1LL);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9600
#include <cstdio>
#include <cstring>
//#include <cstdlib>
//#include <cmath>
//#include <string>
#include <algorithm>
//#include <vector>
#define INF (2000000000)
using namespace std;

//typedef vector<int> VI;
//typedef vector<int>::iterator VII;
//typedef vector<double> VD;
//typedef vector<double>::iterator VDI;

char map[1024][1024];
int dp[1024][1024];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		memset(dp, 0, sizeof(dp));
		for (int i = 0; i < 1024; i++){
			for (int j = 0; j < 1024; j++){
				map[i][j] = '\0';
			}
		}
		
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				scanf(" %c", &map[i][j]);
			}
		}
		
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				if (map[i][j] == '.'){
					dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
				}
	//			printf("%d", dp[i][j]);
			}
	//		printf("\n");
		}
		
		int maxi = 0;
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				maxi = max(maxi, dp[i][j]);
			}
		}
		
		printf("%d\n", maxi);
	}
	
	return 0;
}

Measured memory_bytes: 6156
#include <bits/stdc++.h>
#define mod 1000000007
#define mi first
#define ma second
#define N 100000000
#define fo(i,m,n) for(int i=m;i<n;i++)
#define M 7
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
using ul=unsigned long long;
using pii=pair<int,int>;
using vvi=vector<vector<int>>;
using vi=vector<int>;
using pll=pair<ll,ll>;
using vsi=vector<set<int>>;
using vll=vector<ll>;

ll power(ll a,ll n){
    ll j=0;
    ll x=1;
    while(1ll<<j<=n){
        if(1ll<<j&n)
            x=(x*a)%mod;

        a=a*a%mod;
        j++;
    }

    return x;
}

int gcd(int a,int b){
    if(b==0)
        return a;
    else
        return gcd(b,a%b);

}

int lb(vi &a,int x){
    int n=a.size();
    int l=0;
    int r=n-1;
    int ind=-1;
    while(l<=r){
        int mid=(l+r)/2;
        if(x>=a[mid]){
            l=mid+1;
            ind=mid;
        }
        else
            r=mid-1;

    }

    return ind+1;

}

int up(vll &a,ll x){
    int n=a.size();
    int l=0;
    int r=n-1;
    int ind=-1;

    while(l<=r){
        int mid=(l+r)/2;
        if(a[mid]>x){
            r=mid-1;
            ind=mid;
        }
        else
            l=mid+1;

    }

    return ind;
}

ll max(ll a,ll b){
    if(a>b)
        return a;
    else
        return b;

}

ll min(ll a, ll b){
    if(a>b)
        return b;
    else
        return a;

}

void yn(bool a){
    if(a)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

}


struct fenwick_tree{
    int n;
    int* bit;
    fenwick_tree(int n){
        this->n=n;
        bit=new int[n+1];
        fill(bit,bit+n+1,0);
    }

    void update(int idx,int x){
        while(idx<=n){
            bit[idx]+=x;
            x+=(x&-x);
        }
    }

    int query(int r){
        int tot;
        while(r){
            tot+=bit[r];
            r-=(r&-r);
        }
        return tot;
    }

};


int main(){
    int n,k;
    cin>>n>>k;

    vi p(n+1);
    fo(i,1,n+1)
            cin>>p[i];

    vi c(n+1);
    fo(i,1,n+1)
            cin>>c[i];

    set<int> done;
    vvi adj(n+1);
    fo(i,1,n+1){
        if(!done.count(i)){
            int j=i;
            do{
                done.insert(j);
                adj[i].push_back(c[j]);
                j=p[j];

            }while(j!=i);

        }


    }
    ll ans=INT_MIN;

    fo(i,1,n+1){
        int n=adj[i].size();
        //cout<<n<<endl;
        if(!n)
            continue;

        for(int j=0;j<n;j++)
            adj[i].push_back(adj[i][j]);

        vll pre(2*n+1);
        fo(j,1,2*n+1)
                pre[j]=adj[i][j-1]+pre[j-1];

        int tk;
        if(k>=n)
            tk=n;
        else
            tk=k;
            ll dt=INT_MIN;
        fo(j,0,2*n-tk){
            fo(i,j+1,j+tk+1)
                dt=max(pre[i]-pre[j]+max(0,pre[n]*((k-(i-j))/n)),dt);
           // cout<<dt<<endl;
        }


        ans=max(ans,dt);

    }
    cout<<ans<<endl;


}


Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

struct edge {
    ll from, to, cost;
};

const ll INF = 1ll << 60;
ll N,M;
vector<edge> edges;
vector<ll> d;

// src->dstの間に閉路があればfalse
bool bellman_ford(ll src, ll dst){
    d[src] = 0;
    rep(i,0,2*N){
        for (auto e: edges) {
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if (i>=N-1 && e.to == dst)
                    return false;
            }
        }
    }
    return true;
}

signed main() {
    cin>>N>>M;
    rep(i,0,M){
        ll a,b,c;
        cin>>a>>b>>c;
        edges.push_back(edge{a-1,b-1,-c});
    }
    d.resize(N, INF);
    auto t = bellman_ford(0, N-1);
    if (t){
        cout<<-d[N-1]<<endl;
    }else{
        cout<<"inf"<<endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

constexpr int INF = numeric_limits<int>::max()/2;

typedef vector<vector<int>> Graph;
bool f=true;
vector<int> dp(1000,0),x(1000);

int dfs(const Graph& g, int node){
    int sz=g[node].size();
    if(sz==0){
        return dp[node]=0;
    }
    int cnt=0;
    vector<vector<bool>> sum(2,vector<bool>(x[node]+1,false));
    sum[0][0]=true;
    for(int i=0;i<sz;i++){
        int next = g[node][i];
        int y=dfs(g,next); // dp[next]
        if(y>x[node] && x[next]>x[node]){
            f=false;
            return 0;
        }
        for(int j=x[node];j>=0;j--){
            if(j<y) break;
            sum[1][j] = sum[0][j-y];
        }
        for(int j=x[node];j>=0;j--){
            if(j<x[next]) break;
            sum[1][j] = sum[1][j] || sum[0][j-x[next]];
        }
        for(int j=0;j<=x[node];j++){
            sum[0][j] = sum[1][j];
            sum[1][j] = false;
        }
        cnt += x[next] + y;
    }
    for(int j=x[node];j>=0;j--){
        if(!sum[0][j]) continue;
        return dp[node]=cnt-j;
    }
    f=false;
    return 0;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;cin>>n;
    Graph g(n);
    for(int i=1;i<=n-1;i++){
        int p;cin>>p;p--;
        g[p].push_back(i);
    }
    for(int i=0;i<n;i++) cin>>x[i];
    dfs(g,0);
    if(f) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;

int a[30000] = {};

int kaijo(){
	for(int i = 1; i < 21000;i++){
		int l = i;
		a[i] = a[i - 1];
		while(true){
			if (l % 5 != 0) { break; }
			else if (l == 0) { break; }
			else {
				a[i]++;
				l /= 5;
			}
		}
	}
	return 0;
}

int main(){
	kaijo();
	int in;
	while (cin >> in){
		if (in == 0) { break; }
		cout << a[in] << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
    string s;
    cin>>s;
    lli n = s.length();
    s += "....";
    lli i = 0;
    while(i < n){
        string temp = s.substr(i, 2);
        if(temp == "hi")
            i += 2;
        else{
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> hoge(n);
    for(int i=1;i<=n;i++){
        cin>>hoge[i-1];
        hoge[i-1]-=i;
    }
    
    sort(hoge.begin(),hoge.end());
    int b=0;
    long long ans=0;
    
    if(n%2==1){
        b=hoge[n/2];
        for(int i=0;i<n;i++){
            long long tmp=hoge[i]-b;
            if(tmp<0) tmp*=-1;
            ans+=tmp;
        }
    }else{
            b=hoge[(n/2)-1];
            long long pre1=0,pre2=0;
            for(int i=0;i<n;i++){
                long long tmp=hoge[i]-b;
                if(tmp<0) tmp*=-1;
                pre1+=tmp;
            }
            
            b=hoge[n/2];
            for(int i=0;i<n;i++){
                long long tmp=hoge[i]-b;
                if(tmp<0) tmp*=-1;
                pre2+=tmp;
            }
            
            ans=min(pre1,pre2);
        }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
n = int(input())
s = str(input())
 
cnt = 0
"""
for i in range(n - 2):
    for j in range(i + 1,n -1):
        for k in range(j + 1,n):
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k] and j - i != k - j:
                cnt += 1
                """
 
for i in range(n -2):
    num = 1
    while i + (num)* 2 <= n -1:
        if s[i] != s[i + num] and s[i] != s[i + 2 * num] and s[i + num] != s[i + 2 * num]:
            cnt += 1
        num += 1
print(s.count("R") * s.count("G") * s.count("B") - cnt)

Measured memory_bytes: 67828
#include <bits/stdc++.h>
using namespace std;

long long gcd(long long N, long long X) {
    if (X == 0) return N;
    return gcd(X, N % X);
}

int main() {
    long long N, X;
    cin >> N >> X;
    cout << 3 * (N - gcd(N, X)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    Vec<u32> X(3);
    cin >> X[0] >> X[1] >> X[2];
    sort(ALL(X));
    if (X[0] == X[1] && X[1] != X[2] || X[0] != X[1] && X[1] == X[2]) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 384
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val n    = inputs.head.toInt
  val nums = inputs(1).split(" ").map(_.toInt)

  println(solve(n, nums))

  def solve(n: Int, nums: Seq[Int]): Long = {
    // 5 8 1 9 3 2 7
    // 0 -> 9 -> 8 -> 8 -> 7 -> 7 ->
    var comfort = 0L
    var currentMinNum  = 0
    val sortedNums = nums.sorted
    val lastIndex  = n - 1
    var times = 1

    Range.inclusive(lastIndex, 0, -1).foreach { i =>
      comfort = comfort + currentMinNum
      currentMinNum = sortedNums(lastIndex - (times/2))
      times = times + 1
    }
    comfort
  }
}

Measured memory_bytes: 86392
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int x1 { get; set; }
    public int x2 { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            var c = int.Parse(line[2]);
            if (a == 0 && b == 0 && c == 0) break;
            getAns(a, b, c);
        }
    }
    static void getAns(int a, int b, int c)
    {
        var ok = false;
        var ps = new P[2];
        if (c == 0)
        {
            ps[0] = new P { x1 = 1, x2 = 0 };
            ps[1] = new P { x1 = a, x2 = b };
            ok = true;
            goto exit;
        }
        var ta = getDiv(a);
        var tc = getDiv2(c);
        foreach (var x in ta)
            foreach (var y in tc)
            {
                var p = x.x1;
                var r = x.x2;
                var q = y.x1;
                var s = y.x2;
                if (p * s + q * r == b)
                {
                    ps[0] = new P { x1 = p, x2 = q };
                    ps[1] = new P { x1 = r, x2 = s };
                    ok = true;
                    goto exit;
                }
                if (p * q + s * r == b)
                {
                    ps[0] = new P { x1 = p, x2 = s };
                    ps[1] = new P { x1 = r, x2 = q };
                    ok = true;
                    goto exit;
                }
            }
        exit:;
        if (!ok) Console.WriteLine("Impossible");
        else
        {
            var prt = ps.OrderByDescending(x => x.x1).ThenByDescending(x => x.x2).ToArray();
            Console.WriteLine("{0} {1} {2} {3}",prt[0].x1,prt[0].x2,prt[1].x1,prt[1].x2);
        }
    }
    static List<P> getDiv2(int a)
    {
        var ap = a < 0 ? -a : a;
        var t = new List<P>();
        for (int i = 1; i * i <= ap; i++)
            if (ap % i == 0)
            {
                var w = ap / i;
                if (i <= w)
                    if (a > 0)
                    {
                        t.Add(new P { x1 = i, x2 = w });
                        t.Add(new P { x1 = -w, x2 = -i });
                    }
                    else
                    {
                        t.Add(new P { x1 = -i, x2 = w });
                        t.Add(new P { x1 = -w, x2 = i });
                    }
            }
        return t;
    }
    static List<P> getDiv(int a)
    {
        var t = new List<P>();
        for (int i = 1; i * i <= a; i++)
            if (a % i == 0)
            {
                var w = a / i;
                if (i <= w) t.Add(new P { x1 = i, x2 = w });
            }
        return t;
    }
}


Measured memory_bytes: 20344