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

using namespace std;

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

    int N; cin>>N;
    vector<int> tree[N+1];
    for (int i = 0; i < N-1; i++) {
        int a,b; cin>>a>>b;
        a--,b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<long> C(N);
    for (auto& c : C) cin>>c;
    sort(C.begin(), C.end());

    queue<int> nodes;
    nodes.push(0);
    vector<long> scores(N, 0);
    long ans = 0;
    while (not nodes.empty() and C.size() > 0) {
        auto n = nodes.front(); nodes.pop();
        scores[n] = C.back();
        C.erase(C.end()-1);
        for (auto edge : tree[n]) {
            if (scores[edge] > 0) {
                ans += scores[n];
            } else {
                nodes.push(edge);
            }
        }
    }
    cout << ans << endl;
    for (int i = 0; i < N; i++)
        cout << scores[i] << ' ';
    cout << endl;

    return 0;
}



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

#define int long long

signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    
    int ans = n / (a + b) * a;
    int rem = n % (a + b);
    ans += min(rem, a);
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int p = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        
        System.out.println(p+q+r - Math.max(p, Math.max(q, r)));
    }
}

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

constexpr int64_t mod = 998244353;

int64_t mpow(int64_t x, int64_t y){
    if(y==0) return 1;
    if(y==1) return x%mod;
    if(y%2==0) return mpow(x*x%mod, y/2)%mod;
    return mpow(x*x%mod, y/2)%mod*x%mod;
}
int main(){
    int n, d[100000], b[100000] = {0};
    int mx = 0;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> d[i];
        ++b[d[i]];
        mx = max(mx, d[i]);
    }

    if(d[0] != 0 || b[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    int64_t ans = 1;
    for(int i=1;i+1<=mx;++i){
        ans = ans * mpow(b[i], b[i+1]) % mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=10000;
const ll INF=1000000000;
const int MAX=100001;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;
    cin>>n;
    int a[200010];
    int b[200010];
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]>b[n/2-1]){
            cout<<b[n/2-1]<<endl;
        }else{
            cout<<b[n/2]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3712
'use strict';

function Main(input) {
  const A = Number(input.split(" ")[0])
  const B = Number(input.split(" ")[1])
  const K = Number(input.split(" ")[2])
  let counter = 0

  for (let i = Math.max(A, B); i > 0; i--) {
      if (A % i === 0 && B % i === 0) {
          counter++
      }
      if (counter === K) {
          console.log(i)
          return
      }
  }
  
};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 7372
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    double ans = 0;

    for (int i = K; i <= N; i++) {
        ans += (1.0 / N);
    }

    int k = 1, tmp;
    while (K > 1) {
        if (K % 2 == 0) {
            tmp = (K >> 1);
        } else {
            tmp = (K >> 1) + 1;
        }

        if (N >= tmp) {
            ans += (min(K, N + 1) - tmp) * (1.0 / N) / pow(2, k);
        }
        K = tmp;
        k += 1;
    }

    cout.precision(12);
    cout << fixed << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int n;
	cin >> n;

	if(n%2==0){
		cout << n << endl;
	}
	else{
		cout << n*2 << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[3010][3010];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	string s, t;
	cin >> s >> t;
	ll n = s.length();
	ll m = t.length();
	rep(i, n) {
		rep(j, m) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}
	string ans;
	while (n > 0 && m > 0) {
		if (dp[n][m] == dp[n - 1][m]) {
			n--;
		}
		else if (dp[n][m] == dp[n][m - 1]) {
			m--;
		}
		else {
			ans = s[n - 1] + ans;
			n--;
			m--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 74100
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define pb        push_back
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 2e5+7;
const ll mod = 1e9+7;
ll a[N];
ll b[N];
int check(string k,string t)
{
	int cnt = 0;
	for(int i=0;i<k.size();i++)
	{
		if(k[i]==t[i]) 
		cnt++;
	}
	return cnt;
}
inline void solve()
{
	string s,t;cin>>s>>t;
	int ans = MIN;
	for(int i=0;i+t.size()<=s.size();i++)
	{
		string k = s.substr(i,t.size());

		ans = max(ans,check(k,t));
	}
	cout<<t.size()-ans<<endl;
}
int main()
{
	IOS();
	solve();
	return 0;
}




Measured memory_bytes: 3652
N, M, X = list(map(int, input().split()))
A = list(map(int, input().split(" ")))
count = 0

for i in A:
    if i < X:
        count += 1
    else:
        break

if count >= (M / 2):
    answer = M - count
else:
    answer = count

print(answer)
        

Measured memory_bytes: 2940
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    String ans = "Yes";
    h[0]--;
    for(int i = 1; i < n; i++) {
      if(h[i] > h[i - 1]) {
        h[i]--;
      } else if(h[i] == h[i - 1]) {
        
      } else {
        ans = "No";
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 59568
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>

const int kN = 202 + 5;
int A, B, d[kN][kN];
std::vector<std::tuple<int, int, int>> edges;
int n = 202;
int S = 1, T = 202;

std::vector<std::pair<int, int>> graph[kN];

bool validate()
{
    for (int x = 1; x <= A; ++ x) {
        for (int y = 1; y <= B; ++ y) {
            for (int i = 1; i <= n; ++ i) graph[i].clear();
            for (auto t : edges) {
                int a, b, c;
                std::tie(a, b, c) = t;
                graph[a].emplace_back(b, c == -1 ? x : c == -2 ? y : c);
            }
            std::vector<int> dist(n + 1, 101);
            dist[S] = 0;
            std::priority_queue<std::pair<int, int>> pq;
            pq.emplace(0, S);
            while (!pq.empty()) {
                int u, tmp;
                std::tie(tmp, u) = pq.top(); pq.pop();
                if (-tmp != dist[u]) continue;
                for (auto t : graph[u]) {
                    int v, w;
                    std::tie(v, w) = t;
                    if (dist[v] > dist[u] + w) {
                        dist[v] = dist[u] + w;
                        pq.emplace(-dist[v], v);
                    }
                }
            }
            if (dist[T] != d[x][y]) return false;
        }
    }
    return true;
}

int main()
{
    scanf("%d%d", &A, &B);
    for (int i = 1; i <= A; ++ i)
        for (int j = 1; j <= B; ++ j)
            scanf("%d", &d[i][j]);

    for (int i = 1; i < 101; ++ i)
        edges.emplace_back(i, i + 1, -1);
    for (int i = 102; i < 202; ++ i)
        edges.emplace_back(i, i + 1, -2);

    for (int i = 0; i <= 100; ++ i) {
        for (int j = 0; j <= 100; ++ j) {
            int v = 0;
            for (int x = 1; x <= A; ++ x)
                for (int y = 1; y <= B; ++ y)
                    v = std::max(v, d[x][y] - i * x - j * y);
            edges.emplace_back(i + 1, T - j, v);
        }
    }
    if (!validate())
        return puts("Impossible"), 0;
    puts("Possible");
    printf("%d %d\n", n, edges.size());
    for (auto t : edges) {
        int a, b, c;
        std::tie(a, b, c) = t;
        printf("%d %d ", a, b);
        if (c < 0) putchar("YX"[c + 2]);
        else printf("%d", c);
        puts("");
    }
    printf("%d %d\n", S, T);
}


Measured memory_bytes: 704
#include<stdio.h>
int main(void)

{
 double a,b,r;
 
 
 a=0;
 b=0;
 
scanf("%lf",&r);

a=r*r*3.141592653589;

b=r*2*3.141592653589;


 
 printf("%lf %lf\n",a,b);

 return 0;

}


Measured memory_bytes: 2744
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	stack<long> S1;
	stack<pair<long, long> > S2;
	char ch;
	long sum = 0;
	for (long i = 0; cin >> ch; i++){
		if (ch == '\\') S1.push(i);
		else if (ch == '/' && S1.size() > 0){
			long j = S1.top();
			S1.pop();
			sum += i - j;
			long a = i - j;
			while (S2.size() > 0 && S2.top().first > j){
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}

	// vector<long> ans;
	// while (S2.size() > 0){
	// 	ans.push_back(S2.top().second);
	// 	S2.pop();
	// }
	// reverse(ans.begin(), ans.end());
	// cout << sum << endl;
	// cout << ans.size();
	// for (long i = 0; i < ans.size(); i++){
	// 	cout << " ";
	// 	cout << ans[i];
	// }
	// cout << endl;

	stack<long> ans;
	while (S2.size() > 0){
		ans.push(S2.top().second);
		S2.pop();
	}
	cout << sum << endl;
	cout << ans.size();
	while (ans.size() > 0){
		cout << " ";
		cout << ans.top();
		ans.pop();
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1360
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)
ans = -1
t = a[0]
target = (a[0] + (2 - 1)) // 2
#print(target)
pre = inf
if n == 2:
    print(max(a), min(a))
    sys.exit()
for i in range(1, n):
    #print(pre)
    dif = abs(target - a[i])
    if pre < dif:
        print(t, a[i-1])
        sys.exit()
    else:
        pre = dif


Measured memory_bytes: 99300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main(){
    string S;
    cin >> S;
    if (S[0] == S[1] && S[1] == S[2]) out("No");
    else out("Yes");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
map<ll,ll>mp;

int main ()
{
    map<char,char>mp;
    mp['A']='T';
    mp['T']='A';
    mp['C']='G';
    mp['G']='C';
    char b;
    cin>>b;
    cout<<mp[b]<<endl;
    return 0;

}


Measured memory_bytes: 3472
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int dp[100005][3];
int n;
int a[100005];
int b[100005];
int c[100005];

int main()
{
//	freopen("input.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	int res=0;
	for(int i=1;i<n;i++)
	{
		dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
		dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
	}
	for(int i=0;i<3;i++)
	{
		res=max(res,dp[n-1][i]);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int sum = 0;
	for(int i=0;i<3;i++)
	{
		if(s[i]==t[i])sum++;
	}
	cout<<sum<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	int ans = 0;
	int x = 1;
	for(int i=0; i<N; i++){
		if(A[i]==x){
			x+=1;
		} else {
			ans+=1;
		}
	}

	if(ans==N) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
typedef long long ll;
const int N=0;
int n,h,w;
string s;
vector<int>v;
int main(){
	scanf("%d%d%d",&n,&h,&w);
	printf("%d\n", (n-h+1)*(n-w+1));

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int Q = sc.nextInt();
        List <Integer> list = new ArrayList<Integer>();
        for (int i = 3 ; i < 100000 ; i = i + 2) {
            if (is2017LikeNumber(i)) {
                list.add(i);
            }
        }
        int [] q = new int [Q];
        for (int i = 0 ; i < Q ; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int count = 0;
            for (int j = 0 ; j < list.size() ; j++) {
                if (list.get(j) >= l && list.get(j) <= r) {
                    count++;
                }
            }
            q[i] = count;
        }
        for (int i = 0 ; i < Q ; i ++) {
            System.out.println(q[i]);
        }

    }

    private static boolean isPrimeNumber (int n) {
        for (int i = 2 ; i <= Math.sqrt(n) ; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

    private static boolean is2017LikeNumber (int n) {
        return isPrimeNumber(n) && isPrimeNumber((n + 1)/ 2);
    }

}

Measured memory_bytes: 64376
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

template<typename T>
struct bit {
  vector<T> data;

  bit(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return ret;
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

signed main() {
  int N, Q;
  string S;
  cin >> N >> S >> Q;

  vector<bit<int>> vec(26, bit<int>(N+2));
  REP(i, S.size()){
    vec[S[i]-'a'].add(i+1, 1);
  }

  REP(i, Q){
    int a;
    cin >> a;
    if(a == 1){
      int b;
      string c;
      cin >> b >> c; b--;
      vec[S[b]-'a'].add(b+1, -1);
      vec[c[0]-'a'].add(b+1, 1);
      S.replace(b, 1, c);
    }else{
      int l, r;
      cin >> l >> r;
      int ret = 0;
      REP(k, 26){
        if(vec[k].sum(r)-vec[k].sum(l-1) > 0){
          ret++;
        }
      }
      cout << ret << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 106372
# -*- coding: utf-8 -*-

# 入力
S= list(input())
N = len(S)

# 移動回数
cnt = 10**5

# jにいた子の2**i回移動後の座標
M = len(format(cnt, 'b'))
dp = [[-1 for j in range(N)] for i in range(M+1)]

# i = 0
for j in range(N):
    if S[j] == 'L':
        dp[0][j] = j - 1
    else:
        dp[0][j] = j + 1

# i = 1~M+1
for i in range(M):
    for j in range(N):
        dp[i+1][j] = dp[i][dp[i][j]]
# print(dp)

# cnt回移動後の座標を求める
after = []
for j in range(N):
    i = 0
    n = cnt
    cur_j = j
    while n > 0:
        if ((n & 1) == 1):
            cur_j = dp[i][cur_j]
        n >>= 1
        i += 1
    after.append(cur_j)
# print(after)

# 解答出力
ans = [0] * N
for j in range(N):
    ans[after[j]] += 1
print(' '.join([str(n) for n in ans]))


Measured memory_bytes: 29224
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll n, m;
vector<vector<ll>> v(1111);
int used[1111];
int dist[1111];
int pre[1111];
int pass[1111];

void out(int a, int b){
	//cout << "in out " << a << " " << b << endl;
	cout << b - a + 1 << endl;
	for(int i = a;i <= b;i++)cout << pass[i]+1 << endl;

	return;
}

void seica(int length){
	//cout << "in seica " << length << endl;
	REP(i, 1111)used[i] = -1;
	REP(i, length){
		int node = pass[i];
		int now = -1;
		REP(j, v[node].size()){
			now = max(now, used[v[node][j]]);
		}
		if(now >= 0){
			out(now, i);
			return;
		}
		used[node] = i;
	}
}

bool keymoon(int now){
	//cout << "keymoon " << now << endl;
	REP(i, 1111)dist[i] = INF;
	dist[now] = 1;

	queue<int> q;
	q.push(now);
	while(!q.empty()){
		int node = q.front();q.pop();
		//cout << node << " " << dist[node] << endl;

		REP(i, v[node].size()){
			if(v[node][i] == now){
				//cout << " tyome " << node << " " << v[node][i] << " " << now << endl;
				int tmp = node;
				REP(j, dist[node]){
					pass[dist[node] - j - 1] = tmp;
					tmp = pre[tmp];
				}
				//SHOW1d(pass, dist[node]);
				seica(dist[node]);
				return true;
			}

			if(dist[v[node][i]] > dist[node] + 1){
				dist[v[node][i]] = dist[node] + 1;
				pre[v[node][i]] = node;
				q.push(v[node][i]);
			}
		}
	}

	return false;
}

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

	cin >> n >> m;
	REP(i, m){
		ll a, b;cin >> a >> b;
		a--;b--;
		v[a].PB(b);
	}

	REP(i, n){
		if(keymoon(i))return 0;
	}

	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 384
<?php
fscanf(STDIN, '%d', $cnt);
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 0;
$ref = $nums[0];
for ($i=1; $i < $cnt; $i++) { 
    if ($nums[$i] == $ref) {
        continue;
    }
    if ($nums[$i] > $ref) {
        $ref = $nums[$i];
        continue;
    }
    if ($nums[$i] < $ref) {
        $ans += $ref - $nums[$i];
    }
}
echo $ans;

Measured memory_bytes: 37788
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, m, v, p = MAP()
a = LIST()
a = sorted(a, reverse=True)

def hantei(i):
    if i < p: return True
    if a[p-1] > a[i] + m: return False
    if ((i-p+1)*(a[i]+m)-sum(a[p-1:i]))+m*(p-1+n-i) < m*v: return False
    return True

if hantei(n-1):
    print(n)
    sys.exit()
    
right = n-1
left = 0

while right-left > 1:
    mid = (right+left)//2
    if hantei(mid):
        left = mid
    else:
        right = mid

print(right)


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

typedef long long ll;

int main()
{
    int n,i;
    cin >> n;
    vector<int> p(n);
    for(i = 0;i < n;++i){
        cin >> p.at(i);
    }
    ll ans = 0;
    for(i = 0;i < n-1;++i){
        if(p.at(i) == i+1 && p.at(i+1) == i+2){
            p.at(i) = i+2;
            p.at(i+1) = i+1;
            ++ans;
        }
    }
    for(i = 0;i < n;++i){
        if(p.at(i) == i+1){
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
k = int(input())

runrun = []

import queue
q = queue.Queue()
for i in range(1,10,1):
    q.put(i)
num = 0
while num <= 3234566667:
    num = q.get()
    runrun.append(num)
    tale = str(num)
    if(tale[-1] == '0'):
        same_tale = tale + '0'
        same_tale = int(same_tale)
        q.put(same_tale)

        max_tale =  tale + '1'
        max_tale = int(max_tale)
        q.put(max_tale)
    elif(tale[-1] == '9'):
        min_tale = tale + '8'
        min_tale = int(min_tale)
        q.put(min_tale)

        same_tale = tale + '9'
        same_tale = int(same_tale)
        q.put(same_tale)
    else:
        v = int(tale[-1])
        min_tale = tale + str(v-1)
        min_tale = int(min_tale)
        q.put(min_tale)

        same_tale = tale + str(v)
        same_tale = int(same_tale)
        q.put(same_tale)

        max_tale =  tale + str(v+1)
        max_tale = int(max_tale)
        q.put(max_tale)

print(runrun[k-1])


Measured memory_bytes: 58452
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        Map<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            long num = sc.nextLong();
            if (map.containsKey(num)) {
                map.put(num, map.get(num) + 1);
            } else {
                map.put(num, 1);
            }
        }

        long a = 0;
        long b = 0;
        for (long num : map.keySet()) {
            if (map.get(num) < 2) continue;

            if (num > a && num > b && map.get(num) >= 4) {
                a = num;
                b = num;
            } else if (num > a) {
                b = a;
                a = num;
            } else if (num > b && num < a) {
                b = num;
            }
        }
        System.out.println(a * b);
    }
}


Measured memory_bytes: 61376
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    int MAXD = 60;
    vector<vector<ll>> nex(MAXD + 1, vector<ll>(n + 5, -1));
    for (int i = 0; i < n; i++)
    {
        nex[0][i] = a[i];
    }
    for (ll i = 0; i < MAXD; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            nex[i + 1][j] = nex[i][nex[i][j]];
        }
    }
    int ans = 0;
    for (int i = 0; i < MAXD; i++)
    {
        if (k & (1LL << i))
        {
            ans = nex[i][ans];
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 101708
#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

ll ans;

void upd2(ll a, ll b, ll c) {
    ans = min(ans, max({a, b, c}) - min({a, b, c}));
}

void upd(ll a, ll h, ll w) {
    upd2(a, h * (w / 2), h * ((w + 1) / 2));
    upd2(a, w * (h / 2), w * ((h + 1) / 2));
}

ll h, w;
int main() {
    cin >> h >> w;
    ans = 1e11;
    for (ll i = 1; i < h; ++i) {
        upd(i * w, h - i, w);
    }
    for (ll i = 1; i < w; ++i) {
        upd(i * h, h, w - i);
    }
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 256
mizu = 0
def mizuyari(H):
    global mizu
    if len(H) == 0:
        return "finish"
    zeroindex = [-1]
    grow = min(H)
    mizu += grow
    for i in range(len(H)):
        H[i] -= grow
        if H[i] == 0:
            zeroindex.append(i)
    zeroindex.append(len(H))
    for i in range(len(zeroindex) - 1):
        mizuyari(H[zeroindex[i] + 1: zeroindex[i + 1]])

def main():
    global mizu
    N = int(input())
    *H, = map(int, input().split())
    mizuyari(H)
    print(mizu)

main()


Measured memory_bytes: 3064
def solve(a, b, k):
    i = 0
    for c in range(max(a,b), 0, -1):
        if (a % c == 0) and (b % c == 0):
            i += 1
            if i == k:
                return c
    return -1

assert solve(8, 12, 2) == 2
assert solve(100, 50, 4) == 5
assert solve(1, 1, 1) == 1

a, b, k = list(map(int, input().split()))
print(solve(a,b,k))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin>>N;
    if(N==1){
        cout<<1<<endl;
    }else if(N<4){
        cout<<2<<endl;
    }else if(N<7){
        cout<<4<<endl;
    }else if(N<8){
        cout<<4<<endl;
    }else if(N<16){
        cout<<8<<endl;
    }else if(N<32){
        cout<<16<<endl;
    }else if(N<64){
        cout<<32<<endl;
    }else{
        cout<<64<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

ll x;

int main() {
    fastio();

    cin >> x;

    ll c = x / 11;

    if (x == c * 11)
        cout << c * 2 << endl;
    else if (x - c * 11 > 6)
        cout << c * 2 + 2 << endl;
    else
        cout << c * 2 + 1 << endl;

    return 0;
}

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

int main(){
  int N;
  int x = 0;
  int y = -2;
  cin >> N;
  int A[N];
  int B[N];
  int C[N - 1];
  for(int i = 0; i < N; i++)cin >> A[i];
  for(int i = 0; i < N; i++)cin >> B[i];
  for(int i = 0; i < N - 1; i++)cin >> C[i];
  
  for(int i = 0; i < N; i++){
    x += B[A[i] - 1];
   // cout << x << endl;
    if(A[i] == y + 1) x += C[y - 1];
    // cout << x << endl;
    y = A[i];
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
def parent(i)
  return i/2
end
def left(i)
  return i*2
end
def right(i)
  return i*2+1
end
def maxHeap(arr,i)
  l=left(i)
  r=right(i)
  if l<=@n && arr[l]>arr[i]
    largest=l
  else
    largest=i
  end
  if r<=@n && arr[r]>=arr[largest]
    largest=r
  end
  if largest!=i
    arr[i],arr[largest]=arr[largest],arr[i]
    maxHeap(arr,largest)
  end
end
def buildMaxHeap(arr)
  @n.downto(1) do |i|
    maxHeap(arr,i)
  end
end
arr=Array.new()
@n=gets.to_i
arr=gets.split.map(&:to_i)
arr.unshift(nil)
buildMaxHeap(arr)
puts arr.join(' ')

Measured memory_bytes: 63340
/**
 * AOJ 0118
 * 2016/8/14 by xuesen
 * Property Distribution
 */
#include <iostream>
#include <fstream>
using namespace std;
int h,w;
#define max_n 105
char Map[max_n][max_n];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int rst;

bool safe(int x,int y){
	return x>=0 && x< h && y>=0 && y<w;
}
void dfs(int x,int y){
	char flag = Map[x][y];
	Map[x][y]='.';
	for ( int i=0;i<4;++i){
		int xx = x + dx[i];
		int yy = y + dy[i];
		if(safe(xx,yy) && Map[xx][yy]==flag){
			dfs(xx,yy);
		}
	}
}
int main(){
	while(cin>>h>>w && h && w){
		//reader
		for(int i=0;i< h;++i)
			for(int j=0;j<w;++j)
				cin>>Map[i][j];
		//
		rst = 0;
		for(int i=0;i<h;++i){
			for(int j=0;j<w;++j){
				if(Map[i][j]!='.'){
					dfs(i,j);
					rst++;
				}
			}
		}
		cout<<rst<<endl;
	}
}

Measured memory_bytes: 1640
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
const val YES = "Yes"
const val NO = "No"
fun solve(N: Long, L: LongArray){
    val l = L.sortedDescending()
    if(l[0] < l.slice(1 until l.size).sum()) {
        pw.println(YES)
    }else{ pw.println(NO) }
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val L = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        L[i] = sc.next().toLong()
    }
    solve(N, L)
}



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

bool used[26];
int main() {
	string s;cin>>s;
	for(char c:s)used[c-'a']=true;
	rep(i,26){
		if(!used[i]){
			printf("%c\n",'a'+i);
			return 0;
		}
	}
	puts("None");
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	string s,t;
	cin >> s >> t;
	map<char, VL> mp;
	LL loop = 0;
	for (int i = 0; i < s.size(); i++) {
		mp[s[i]].push_back(i);
	}
	for (auto&& var : mp) {
		var.second.push_back(s.size()*2);
	}
	int prev = -1;
	for (auto&& c : t) {
		if (mp[c].empty()) {
			cout << -1 << endl;
			return 0;
		}
		int b = *lower_bound(ALL(mp[c]), prev);
		if (b > s.size()) {
			loop++;
			b = *lower_bound(ALL(mp[c]), -1);
		}
		prev = b+1;
	}
	LL ans = s.size()*loop + prev;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1736
A = list(input())
max_nu = 0 
nu = 0
for i in range(len(A)):
    if A[i] == "A" or A[i] == "C" or A[i] == "G" or A[i] == "T":
        nu += 1
        if max_nu < nu:
            max_nu = nu
    else:
        nu = 0
print(max_nu)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,M; cin>>N>>M;
    vint c(N);
    REP(i,M){
        int a,b; cin>>a>>b;
        if(a==1) c[b]++;
        if(b==N) c[a]++;

    }
    for(int i=2;i<=N-1;i++){
        if(c[i]>=2){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;

}


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

int a[]={1,2,3,4,5,6,7,8,9,};
int b[]={1,2,3,4,5,6,7,8,9,};
int main()
{
    int n;
    cin >> n;
    int x[10];
    int y[10];
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&y[i]);
    }
    int flag1 = 0;
    int flag2 = 0;
    for(int i=0;i<n;i++){
        if(x[i]!=a[i]) flag1 = 1;
    }
    for(int i=0;i<n;i++){
        if(y[i]!=b[i]) flag2 = 1;
    }
    while(flag1){
        flag1++;
        next_permutation(a,a+n);
        int flag = 0;
        for(int i=0;i<n;i++){
            if(x[i]!=a[i]) flag = 1;
        }
        if(flag==0)
            break;
        // cout << 1 << endl;
    }
    while(flag2){
        flag2++;
        next_permutation(b,b+n);
        int flag = 0;
        for(int i=0;i<n;i++){
            if(y[i]!=b[i]) flag = 1;
        }
        if(flag==0)
            break;
    }
    if(flag1==0) flag1=1;
    if(flag2==0) flag2=1;
    cout << abs(flag1-flag2);

}

Measured memory_bytes: 3724
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,a,b = readline() |> split |> parseMap
	x = div(n,a+b)
	y = min(n%(a+b),a)
	println(x*a+y)
end

main()

Measured memory_bytes: 168944
#include<bits/stdc++.h>

using namespace std;

int main () {
	ios::sync_with_stdio(0);
   cin.tie(0);
   int n,s1,s2,s3;
	cin >> n;
	s1 = n % 10;
	s2 = (n/10) % 10;
	s3 = (n/100) % 10; 
	if ( s1 == 7 || s2 == 7  || s3 == 7){
		cout << "Yes" << "\n";
	}
	else cout << "No" << "\n";

  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define debug(x) cout<<#x<<"="<<x<<endl;

using namespace std;
const int N=1000;
char g[N][N];
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
int main(void)
{
	int h,m;
	scanf("%d%d",&h,&m);
	rep(i,0,h)
	{
		rep(j,0,m)
		{
			scanf(" %c",&g[i][j]);
		}
	}
	rep(i,0,h)
	{
		rep(j,0,m)
		{
			if(g[i][j]=='.')
			{
				int cnt=0;
				rep(k,0,8)
				{
					int x=i+dir[k][0];
					int y=j+dir[k][1];
					if(x<0||x>=h||y<0||y>=m)continue;
					if(g[x][y]=='#')cnt++;
				}
				g[i][j]='0'+cnt;
			}
		}
	}
	rep(i,0,h)
	{
		rep(j,0,m)
		{
			printf("%c",g[i][j]);
		}
		cout<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void){
    // Your code here!
    int n;
    char S[10005];
    int cnt;
    int ans;
    cnt=0;
    ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>S[i];
    }
    for(int a=0;a<n-1;a++){
        for(int b=a+1+ans;b<n-ans;b++){
            cnt=0;
            if(S[a]==S[b]){
                cnt+=1;
                if(S[a+ans]==S[b+ans]){
                    for(int c=1;c<min(b-a,n-b);c++){
                        if(S[a+c]==S[b+c]){
                        cnt+=1;
                        if(ans<cnt){
                            ans=cnt;
                        }
                    }else{break;}
                }
            }}
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;

namespace abc177
{
    class Program
    {
        static void Main()
        {
            var nm = ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            var r = new Random();
            var friends = new int[m][];
            for (var i = 0; i < m; ++i)
            {
                var ab = ReadLine().Split(' ');
                friends[i] = new int[] { int.Parse(ab[0]), int.Parse(ab[1]) };
            }
            if (m == 0)
            {
                WriteLine(1);
            }
            else
            {
                WriteLine(MaxGroupSize(n, friends));
            }
        }
        static int MaxGroupSize(int n, int[][] friends)
        {
            // group references
            var gref = new List<int>[n + 1];
            var ftree = new HashSet<int>[n + 1];
            for (var i = 0; i < friends.Length; ++i)
            {
                var a = friends[i][0];
                var b = friends[i][1];
                if (ftree[a] == null)
                {
                    ftree[a] = new HashSet<int>();
                }
                ftree[a].Add(b);
                if (ftree[b] == null)
                {
                    ftree[b] = new HashSet<int>();
                }
                ftree[b].Add(a);
            }

            var dp = new int[n + 1];
            for (var i = 1; i < n; ++i)
            {
                if (dp[i] == 0)
                {
                    var friendList = GetFriendList(i, ftree);
                    foreach (var friend in friendList)
                    {
                        dp[friend] = friendList.Count;
                    }
                }
            }

            var max = 0;
            foreach (var subTotal in dp)
            {
                max = Math.Max(max, subTotal);
            }
            return max;
        }
        static List<int> GetFriendList(int k, HashSet<int>[] ftree)
        {
            var q = new Queue<int>();
            q.Enqueue(k);
            var set = new HashSet<int>(){ k };
            while (q.Count > 0)
            {
                var i = q.Dequeue();
                if (ftree[i] != null)
                {
                    foreach (var friend in ftree[i])
                    {
                        if (!set.Contains(friend))
                        {
                            q.Enqueue(friend);
                            set.Add(friend);
                        }
                    }
                }
            }
            return new List<int>(set);
        }
    }
}


Measured memory_bytes: 90584
#include<iostream>
#include<vector>
#include<string>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))

typedef long long ll;

const int INF=1e9+7;
const int MAX_N=1e5+5;

ll A[MAX_N];
int main(){
	ll n;
	cin>>n;
	rep(i,n)cin>>A[i];
	ll sum=0;
	rep(i,n)sum+=A[i];
	if(((2*sum)%(n*(n+1)))!=0){
		cout<<"NO"<<endl;
		return 0;
	}
	ll k=2*sum/(n*(n+1));
	ll a=0;
	rep(i,n){
		if((A[i]-A[(i+1)%n]+k)>=0 && (A[i]-A[(i+1)%n]+k)%n==0)a+=((A[i]-A[(i+1)%n]+k)/n);
	}
	if(a==k){
		cout<<"YES"<<endl;
	}
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int gcd(int a, int b){
    int r, tmp;
  /* 自然数 a > b を確認・入替 */
    if(a < b){
        tmp = a;
        a = b;
        b = tmp;
    }
  /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int main(){
    int k;
    int sum = 0;
    scanf("%d", &k);
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                sum = sum + gcd(a, gcd(b, c));
            }
        }
    }
    printf("%d", sum);
    return 0;
}


Measured memory_bytes: 1736
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto b = iota(42, 133, 10);
	auto ptr = new int[](10);
	auto str = readln.chomp;
	int pos;
	foreach (c; str) {
		int cur;
		foreach (e; b) {
			if (c <= e) break;
			cur++;
		}
		while (cur < pos) {
			write("<");
			pos--;
		}
		while (cur > pos) {
			write(">");
			pos++;
		}
		while (ptr[pos] < c) {
			write("+");
			ptr[pos]++;
		}
		while (ptr[pos] > c) {
			write("-");
			ptr[pos]--;
		}
		write(".");
	}
}

Measured memory_bytes: 1032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seqS = new int[n];
      String line = br.readLine();
      StrSplitToInt stoi = new StrSplitToInt(line, " ");
      for (int i=0; i<n; i++)
        seqS[i] = stoi.nextInt();

      int q = Integer.parseInt(br.readLine());
      String[] lines = br.readLine().split(" ");
      
      int cnt=0;
      for (String ref : lines) {
        if( isExistSeachByBinary(seqS, Integer.parseInt(ref)) )
          cnt++;
      }

      System.out.println(cnt);
    }
  }

  static boolean isExistSeachByBinary(int[] tar, int ref) {
    int left = 0;
    int right= tar.length;
    int mid;
    while( left < right ) {
      mid  = (left + right) / 2;
      if( tar[mid] > ref ) right = mid;
      else if(tar[mid] < ref ) left = mid + 1;
      else return true;
    }

    return false;
  }
}

class StrSplitToInt {
  String s;
  String split;
  int currentPos;
  int nextPos;
  int endPos;

  public StrSplitToInt(String s,String split) {
    this.s = s;
    this.split = split;
    currentPos = 0;
    nextPos = s.indexOf(split, currentPos);
    endPos = s.length();
  }

  public int nextInt() {
    if( currentPos < endPos ) {
      String i = s.substring(currentPos, nextPos);
      currentPos = nextPos + split.length();
      nextPos = s.indexOf(split, currentPos);
      if(nextPos == -1) nextPos = endPos;

      return Integer.parseInt(i);
    }
    else
      return -1;
  }
}


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

int main() {
  int a, b;
  cin >> a >> b;

  if ( a % 2 == 0 || b % 2 == 0 ) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,a[200001];
long long d[200001];
long long sum=0;

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        d[a[i]]++;
    }
    for (int i=1;i<=n;++i)
    {
        sum+=(d[i]*(d[i]-1))/2;
    }
    for (int i=1;i<=n;++i)
    {
        cout<<sum-(d[a[i]]*(d[a[i]]-1))/2+((d[a[i]]-2)*(d[a[i]]-1))/2<<"\n";
    }
}

int main()
{
    nhap();
    return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
int n,k,maxi;

int main()
{
    cin>>n;
    for(int i=0;i*i<=n;i++)
    {
        if(i*i<=n)
        {
           
                maxi=i;
            
            
        }
    }
    printf("%d",maxi*maxi);
    
  
   
    
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main() {
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(s==u) a--;
    if(t==u) b--;
    cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
/*
ID: andy.sc1
LANG: JAVA
TASK: addsub
*/

// Imports
import java.util.*;
import java.io.*;

public class Main {

    /**
     * @param args the command line arguments
     * @throws IOException, FileNotFoundException 
     */
    public static void main(String[] args) throws IOException, FileNotFoundException {
        
        // TODO UNCOMMENT WHEN ALGORITHM CORRECT
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        
        // TODO code application logic here
        StringTokenizer st = new StringTokenizer(f.readLine());
        long i = Long.parseLong(st.nextToken());
        char ch = st.nextToken().charAt(0);
        long j = Long.parseLong(st.nextToken());
        
        if(ch == '+') {
            System.out.println(i + j);
        }
        else {
            System.out.println(i - j);
        }
    }

}


Measured memory_bytes: 22740