akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 


using namespace std;

const int maxn=1e5+5;

int iP[maxn],a[maxn],n,m,mn[maxn],mn2[maxn];
set<pii >S;
bool vis[maxn];

int fP(int x)
{
	if(iP[x]==x)return x;
	return iP[x]=fP(iP[x]);
}

void fU(int x,int y)
{
	x=fP(x);y=fP(y);
	iP[x]=y;
}


int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		iP[i]=i;
		mn[i]=INF;
	}
	
	for(int i=0;i<m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		fU(x,y);
	}
	
	for(int i=0;i<n;i++)
	{
		if(mn[fP(i)]>a[i])
		{
			mn[fP(i)]=a[i];
			mn2[fP(i)]=i;
		}
		S.insert(mp(a[i],i));
	}
	
	ll res=0;
	int ans=0;
	
	for(int i=0;i<n;i++)if(!vis[fP(i)])
	{
		vis[fP(i)]=true;
		res+=1ll*mn[fP(i)];
		S.erase(mp(mn[fP(i)],mn2[fP(i)]));
		ans++;
	}	
	if(ans<=1)
	{
		printf("%d\n",0);
		return 0;
	}
	
	set<pii >::iterator it=S.begin();
	for(int i=0;i<ans-2;i++)
	{//cout<<i<<" "<<ans<<endl;
		if(it==S.end())
		{
			printf("Impossible\n");
			return 0;
		}
		res+=1ll*(it->first);
		it++;
	}	
		
	printf("%lld\n",res);	
	

	return 0;	
} 

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int N,M;
Graph G;

int main() {
  cin >>N >>M;
  G.assign(N, vector<int>());
  G.assign(N, vector<int>());
  rep(i, M){
    int u,v; cin >>u >>v; u--; v--;
    G[u].push_back(v);
  }
  // GについてBFSを行ってsからtへの最短距離を求める
  int s,t; cin >>s >>t; s--; t--;
  vector<vector<bool>> seen(N, vector<bool>(3, false));
  vector<vector<int>> dist(N, vector<int>(3, -1));
  dist[s][0] = 0;
  queue<Pi> que;
  que.push({s, 0});
  while (!que.empty()){
    auto p1 = que.front(); que.pop();
    int v = p1.first;
    int dimension = p1.second;
    for (int nv : G[v]){
      if (seen[nv][(dimension+1)%3]) continue;
      seen[nv][(dimension+1)%3] = true;
      dist[nv][(dimension+1)%3] = dist[v][dimension] + 1;
      que.push({nv, (dimension+1)%3});
    }
  }
  int res = dist[t][0] == -1 ? -1 : dist[t][0] / 3;
  cout <<res <<endl;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    cout<<n*n*n<<endl;
}


Measured memory_bytes: 256
a, b = list(map(int, input().split()))


def prime_factorize(n):
    """Return the prime factorization of n > 1.
    >>> prime_factorize(36)
    [2, 2, 3, 3]
    """
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2

    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2

    if n != 1:
        a.append(n)

    return a


def main(a, b):
    pf_a = set(prime_factorize(a))
    pf_b = set(prime_factorize(b))
    return len(pf_a & pf_b) + 1


print(main(a, b))

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  int N, Q; cin >> N >> Q;
  string S; cin >> S;
  vector<int> cntS(N, 0);
  cntS[0] = 0;
  for(int i = 1; i < N; ++i) {
    if(S[i-1] == 'A' && S[i] == 'C') {
      cntS[i] = cntS[i-1] + 1;
    } else {
      cntS[i] = cntS[i-1];
    }
  }
  vector<int> l(Q), r(Q);
  for(int i = 0; i < Q; ++i) {
    cin >> l[i] >> r[i];
    l[i]--, r[i]--;
  }
  for(int i = 0; i < Q; ++i) {
    cout << cntS[r[i]] - cntS[l[i]] << endl;
  }

  return 0;
}


Measured memory_bytes: 2176
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

const int mod=1e9+7;
int inv(int x)
{
    int r,y;
    for(r=1,y=mod-2;y>0;x=(x*x)%mod,y/=2)
        if(y%2==1)
            r=r*x%mod;
    return r;
}
int32_t main()
{
    IOS
    int fact[100005]={};
    fact[0]=1;
    for(int i=1;i<=100002;i++)
        fact[i]=(i*fact[i-1])%mod;
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int st=1;
    int ans=0;
    int sum=0;
    int mul=fact[n-1];
    for(int i=0;i<n-1;i++)
    {
        int a=(mul*inv(i+1))%mod;
        sum+=a;
        sum%=mod;
        ans+=(a*arr[i])%mod;
        ans%=mod;
    }
    ans-=(sum*arr[n-1])%mod;
    if(ans<mod)
        ans+=mod;
    ans=-ans;
    while(ans<0)
        ans+=mod;
    ans%=mod;
    cout<<ans;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

int connect(int l, int r){
    char ll[42], rr[22];
    sprintf(ll, "%d", l), sprintf(rr, "%d", r);
    strcat(ll, rr);
    return atoi(ll);
}

int main(){
    
    int n;
    cin >> n;
    vector <int> s, all;
    for(int i = 0; i < n; i++){
        int num; cin >> num;
        s.push_back(num);
    }
    
    sort(s.begin(), s.end());
    for(int i = 0; i < min(n, 15); i++){
        for(int j = 0; j < min(n, 15); j++){
            if(i == j) continue;
            all.push_back(connect(s[i], s[j]));
        }
    }
    sort(all.begin(), all.end());
    cout << all[2] << endl;
}

Measured memory_bytes: 1328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000007
#define MAX 100005
#define PAIR pair<ll,ll>

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

    ll x;

    cin>>x;
    if(x==0) cout<<"1"<<endl;
    else cout<<"0"<<endl;



    return 0;
}


Measured memory_bytes: 3608
import sys
from itertools import accumulate
from collections import defaultdict
input = sys.stdin.readline
N,K=map(int,input().split());A=list(map(int,input().split()))
S_=list(map(lambda t: (t[1]-t[0])%K,enumerate(accumulate([0]+A))))
count=0
C=defaultdict(int)
for t in range(1,N+1):
  C[S_[t-1]]+=1
  if t-K>=0:
    C[S_[t-K]]-=1
  count+=C[S_[t]]
print(count)


Measured memory_bytes: 41204
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N-1, -1, -1):
    if A[i+1] >= 1:
        kill = min(B[i], A[i+1])
        B[i] -= kill
        A[i+1] -= kill
        ans += kill
    kill = min(B[i], A[i])
    B[i] -= kill
    A[i] -= kill
    ans += kill
print(str(ans))

Measured memory_bytes: 82148
import java.util.Scanner;

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

            int n = scan.nextInt();

            int[] a = new int[n];

              for(int i=0;i<n;i++){

                 a[i] =scan.nextInt();

              }

              for(int i =n-1;i>=0;i--){

              System.out.print(a[i]);

                 if(i!=0){
                    System.out.print(" ");
                 }
              }  
              System.out.println();            
        }
     }



Measured memory_bytes: 26352
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        k: i64,
        n: usize,
        a: [i64; n],
    }
    let mut x = vec![0i64; n+1];
    for i in 1..n {
        x[i] = a[i]-a[i-1];
    }
    x.push(a[0]+k-a[n-1]);
    println!("{}", k-x.iter().max().unwrap());
}


Measured memory_bytes: 6744
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<utility>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<deque>
#include<cctype>
using namespace std;
int main()
{
	int five=0;
	int seven=0;
	int a,b,c;
	cin>>a>>b>>c;
	if(a==5) five++;
	else if(a==7) seven++;
	if(b==5) five++;
	else if(b==7) seven++;
	if(c==5) five++;
	else if(c==7) seven++;
	if(five==2&&seven==1) cout<<"YES";
	else cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<queue>
#define INF 99999999
using namespace std;
typedef pair<int, int> P;
vector<P> point[7];
int x,y;
int dp[6][1001][6];
char mas[1001][1001];
int cx[6],ans;
int sp,ans1;
int solve(int i , int j, int z);
int main(){
  while(1){
    for(int i = 0; i < 7; i++){
      point[i].clear();
    }
    memset(cx, 0, sizeof(cx));
    ans1 = INF;
    sp = INF;
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    for(int i = 0; i < y; i++) cin >> mas[i];
    for(int i = 0; i < y; i++){ 
      for(int j = 0; j < x; j++){
	if(mas[i][j] == 'S'){
	  point[0].push_back(P(j,i));
	}
	if(mas[i][j] == 'G'){
	  point[6].push_back(P(j,i));
	}
	if(mas[i][j] >= '1' && mas[i][j] <= '5'){
	  point[mas[i][j] - '0'].push_back(P(j,i));
	  cx[mas[i][j] - '0']++;
	}
      }
    }
    for(int i = 1; i <= 5; i++){
      rotate(point + 1, point + 2, point + 6);
      rotate(cx + 1, cx + 2, cx + 6);
      memset(dp, -1, sizeof(dp));
      ans = solve(0, 0, 0);
      if(ans < ans1){
	ans1 = ans;
	sp = i;
      }
    }
    if(ans1 == INF) cout << "NA" << endl;
    else cout << sp << " " << ans1 << endl;
  }
}
int solve(int i, int j,int z){
  if(dp[i][j][z] >= 0) return dp[i][j][z];
  if(i == 4){
    return abs(point[6][0].first - point[z][j].first) + abs(point[6][0].second - point[z][j].second);
  }
  int res = INF;
  for(int k = 0; k < cx[z + 1]; k++){
    res = min(abs(point[z + 1][k].first - point[z][j].first) + abs(point[z + 1][k].second - point[z][j].second) + solve(i + 1, k, z + 1),res);
  }
  return dp[i][j][z] = res;
}

Measured memory_bytes: 2388
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 2100
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int TC = sc.nextInt();
		for (int tc = 0; tc < TC; tc++) {
			int n = sc.nextInt(), p = sc.nextInt(), low = 0, high = 0, c = 0;
			for (int i = 1; i < n; i++) {
				c = sc.nextInt();
				low = min(low, c - p);
				high = max(high, c - p);
				p = c;
			}
			System.out.println(high +  " " + abs(low));
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <string>
#include <sstream>
int fix()
{
    //example to format floating point numbers.
    double pi = 3.141592653589793;
    double r = 3.141592653589793 * 128;
    std::ios_base::fmtflags f(std::cout.flags()); //[1]
    std::cout << "default:\n  " << pi << " " << r << "\n";
    std::cout << std::setprecision(4) << "setprecision(4):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout << std::setiosflags(std::ios::fixed) << "setiosflags(std::ios::fixed):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout << std::setprecision(5) << "setprecision(5):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout.flags(f);
    std::cout << "reset:\n  " << pi << " " << r << "\n";
    //[1] https://stackoverflow.com/questions/2273330/restore-the-state-of-stdcout-after-manipulating-it
    //[2] https://stackoverflow.com/questions/4217510/how-to-cout-the-correct-number-of-decimal-places-of-a-double-value
    return 0;
}
void multipleLines()
{
    //example to parse multiple lines input.
    std::istringstream isin("1 2 3\n3 2 4\n0 0 0");

    for (std::string str; std::getline(isin, str);)
    {
        std::istringstream tisin(str);
        int a, b, c;
        tisin >> a >> b >> c;
        std::cout << a << " " << b << " " << c << "\n";
    }
    //[1]  https://stackoverflow.com/questions/19767644/c-parsing-input-string-to-variables
}
#include <vector>
#include <set>
#include <map>

int main()
{
    std::map<uint8_t, uint8_t> mapAa;
    std::map<uint8_t, int64_t> mapACount;
    for (uint8_t a = 0; true; a++)
    {
        mapAa[a] = a;
        if (a == 255)
        {
            break;
        }
    }
    for (uint8_t a = 0; a < 26; a++)
    {
        mapAa[a + 'a'] = a + 'a';
        mapAa[a + 'A'] = a + 'a';
        mapACount[a + 'a'] = 0;
    }

    std::string str;
    while (std::getline(std::cin, str))
    {
        for (auto it : str)
        {
            auto itp = mapACount.find(mapAa[it]);
            if (itp != mapACount.end())
            {
                itp->second++;
            }
        }
    }
    for (auto it : mapACount)
    {
        std::cout << it.first << " : " << it.second << "\n";
    }
}


Measured memory_bytes: 3132
#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[400001];
	int size;
} min_heap;

void push(data x, min_heap* h)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key < h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(min_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1;
		if (h->obj[j].key < h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

void add_BIT(int N, int BIT[], int i, int k)
{
	while (i <= N) {
		BIT[i] += k;
		i += (i & -i);
	}
}

int sum_BIT(int BIT[], int r)
{
	int sum = 0;
	while (r > 0) {
		sum += BIT[r];
		r -= (r & -r);
	}
	return sum;
}

int main()
{
	int i, H, W, A, B;
	scanf("%d %d", &H, &W);
	
	int j, k, s[200002], left[200002], right[200002], BIT[200001] = {}, L, R, M, tmp;
	data d;
	min_heap h;
	h.size = 0;
	for (i = 0; i <= W + 1; i++) {
		s[i] = i;
		left[i] = i - 1;
		right[i] = i + 1;
	}
	for (i = 1, d.key = 0; i <= W; i++) {
		d.id = i;
		push(d, &h);
		add_BIT(W, BIT, i, 1);
	}
	for (i = 1; i <= H; i++) {
		scanf("%d %d", &A, &B);
		tmp = sum_BIT(BIT, B);
		if (sum_BIT(BIT, A - 1) == tmp) {
			printf("%d\n", h.obj[1].key + i);
			continue;
		}
		
		L = A;
		R = B++;
		while (L < R) {
			M = (L + R) / 2;
			if (sum_BIT(BIT, M) < tmp) L = M + 1;
			else R = M;
		}
		
		if (s[B] < 0) {
			s[B] = s[L];
			left[right[L]] = B;
			right[B] = right[L];
			add_BIT(W, BIT, B, 1);
		}
		for (j = L; j >= A; j = left[j]) {
			s[j] = -1;
			add_BIT(W, BIT, j, -1);
		}
		left[B] = j;
		right[j] = B;
		
		if (B <= W) {
			d.key = B - s[B];
			d.id = B;
			push(d, &h);
		}
		while (h.size > 0 && s[h.obj[1].id] < h.obj[1].id - h.obj[1].key) pop(&h);
		if (h.size > 0) printf("%d\n", h.obj[1].key + i);
		else break;
	}
	for (; i <= H; i++) printf("-1\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 6580
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

typedef struct {
  int number;
  int road;
  int railway;
} city;

int
city_comp(const void *a, const void *b)
{
  city *x, *y;
  x = (city *)a; y = (city *)b;
  if (x->road > y->road) return  1;
  if (x->road < y->road) return -1;
  if (x->railway > y->railway) return  1;
  if (x->railway < y->railway) return -1;
  return 0;
}

int get_root(int i, int *root) {
  while (root[i] != i) i = root[i];
  return i;
}

void Union(int i, int j, int *root, int *rank) {
  i = get_root(i, root); j = get_root(j, root);
  if (rank[i] > rank[j]) {
    root[j] = i;
    rank[i] = Max(rank[j] + 1, rank[i]);
  } else {
    root[i] = j;
    rank[j] = Max(rank[i] + 1, rank[j]);
  }
  return;
}

int
main(int argc, char *argv[])
{
  int n, k, l;
  scanf("%d %d %d", &n, &k, &l);
  int root1[200010], root2[200010];
  int rank1[200010] = {}, rank2[200010] = {};
  for (int i = 1; i <= n; i++) root1[i] = root2[i] = i;

  int p, q;
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &p, &q);
    Union(p, q, root1, rank1);
  }
  for (int i = 0; i < l; i++) {
    scanf("%d %d", &p, &q);
    Union(p, q, root2, rank2);
  }

  city a[200010];

  for (int i = 1; i <= n; i++) {
    a[i - 1].number = i;
    a[i - 1].road = get_root(i, root1);
    a[i - 1].railway = get_root(i, root2);
  }

  qsort(a, n, sizeof(city), city_comp);

  int i = 0, ans[200010];
  while (i < n) {
    int j = i + 1;
    while (a[i].road == a[j].road && a[i].railway == a[j].railway) j++;
    for (int k = i; k < j; k++) {
      ans[a[k].number - 1] = j - i;
    }
    i = j;
  }

  for (int i = 0; i < n; i++) printf("%d ", ans[i]); endl;

  return 0;
}
			   


Measured memory_bytes: 8572
#include<iostream>
using namespace std;
void dfs(int pos,string s,int v,string op);
string ans="";
int main(){
    string s;
    cin>>s;
    string op="";
    dfs(1,s,s[0]-'0',op+s[0]);
    cout<<ans<<endl;
}
void dfs(int pos,string s,int v,string op){
    if(pos==s.size()){
        //cout<<op<<" "<<v<<endl;
        if(v==7){
            ans=op+"=7";
        }
        return;
    }
    dfs(pos+1,s,v+(s[pos]-'0'),op+"+"+s[pos]);
    dfs(pos+1,s,v-(s[pos]-'0'),op+"-"+s[pos]);
}


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

#define ll long long int
ll const mod = 1e9 + 7;

ll power(ll x, ll y, ll p){ //x^y % p
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {
        if (y & 1) // If y is odd, multiply x with result 
        res = (res*x) % p; 
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string a, b;
    cin>>a>>b;
    
    int n=a.length();
    int m=b.length();
    
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0 || j==0)
                dp[i][j] = 0;
            else if(a[i-1]==b[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    int s = dp[n][m];
    int x=n, y=m;
    vector<char> ans;
    while(s!=0)
    {
        if(dp[x-1][y]==s)
            x--;
        else if(dp[x][y-1]==s)
            y--;
        else
            {
                ans.push_back(a[x-1]);
                x--; y--;
                s--;
            }
    }
    for(int i=ans.size()-1;i>=0;i--)
        cout<<ans[i];
    
	// your code goes here
	return 0;
}


Measured memory_bytes: 35456
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define rep(i,n)for(long long i=0;i<n;i++)
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x,int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
		return ans;
}
int yakusuunowa(int n) {
	int ans=0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
int a[224514];
signed main() {
	int n, cnt = 0,cnta=0,cntb,inf=1000000000000000;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		cnt += a[i];
	}
	for (int i = 0; i < n-1; i++) {
		cnta +=a[i];
		cntb = cnt - cnta;
		if (abs(cnta - cntb) < inf)inf = abs(cnta - cntb);
	}
	cout << inf << endl;
	ll
}

Measured memory_bytes: 1792
a,b = map(int,input().split())
ans = -1
#print(a,b)
for i in range(1001):
#  print(i,int(i * 0.08),int(i * 0.1))
  if int(i * 0.08) == a and int(i *0.1) == b:
    ans = i
    break
print(ans)

Measured memory_bytes: 2940
N = int(input())
l = [0]*(10**6+1)
for a in map(int,input().split()) :
    l[a] += 1
ans = 0

for i in range(1, 10**6 + 1) :
    if l[i] == 1 :
        ans += 1
    if l[i] > 0 :
        for j in range(i , 10**6 + 1, i) :
            l[j] = 0

print(ans)

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

bool check(ll n, ll m) {
	if (m == 0) return false;
	if (n / m == n % m) return true;
	return false;
}

int main(int argc, char const *argv[])
{
	ll n; cin >> n;
	// n = k(m + 1)
	set<ll> st;
	for (ll k = 1; k * k <= n; ++k) {
		if (n % k == 0) {
			ll m1 = n / k - 1;
			ll m2 = k - 1;
			if (check(n, m1)) st.insert(m1);
			if (check(n, m2)) st.insert(m2);
		}
	}
	ll ans = 0;
	for (auto u : st) ans += u;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
S = list(input())
N = len(S)

ans = 0
for i in range(1 << (len(S) - 1)):
    ss = S[0]
    for j in range(len(S) - 1):
        if ((i >> j) & 1) == 1:
            ss += "+"
            ss += S[j + 1]
        else:
        	ss += S[j + 1]

    ss = list(map(int, ss.split("+")))
    ans += sum(ss)

print(ans)

Measured memory_bytes: 3064
// バブルソート
#include<bits/stdc++.h>
using namespace std;

void BubbleSort(int *a, int N);
void swap(int *x, int *y);

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    BubbleSort(a,N);
}

void BubbleSort(int *a, int N){
    int count = 0;
    bool f = true;
    while(f){
        f = false;
        for(int j = N-1; j >= 1; j--){
            if(a[j] < a[j-1]){
                swap(a[j],a[j-1]);
                count ++;
                f = true;
            }
        }
    }
    
    for(int i = 0; i < N; i++){
        cout << a[i];
        if(i != N-1) cout << " ";
        else cout << endl;
    }
    cout << count << endl;
}

void swap(int *x, int *y){
    int work = *x;
    *x = *y; *y = work;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N, M, R;
vector<int> r;
int dist[205][205];

int main() {
    cin >> N >> M >> R;
    r.resize(R);
    rep(i, R) cin >> r[i];
    sort(ALL(r));

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (i == j) continue;
            dist[i][j] = dist[j][i] = INF;
        }
    }
    rep(i, M) {
        int a, b, c; cin >> a >> b >> c;
        dist[a][b] = dist[b][a] = c;
    }

    for (int k = 1; k <= N; k++) {
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                if (dist[i][k] != INF && dist[k][j] != INF) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
    }

    int ans = INF;
    do {
        int sum = 0;
        for (int i = 0; i < R - 1; i++) {
            sum += dist[r[i]][r[i+1]];
        }
        chmin(ans, sum);
    } while (next_permutation(ALL(r)));
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int A,B;

int main(){
	cin>>A>>B;
	cout<<max({A+B,A-B,A*B})<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 998244353;
const int maxn = 3e5 + 100;
long long fac[maxn],inv[maxn];
ll n,a,b,k;
ll sum=0;
long long q_pow(long long x,long long n)
{
    long long res = 1;
    while(n > 0)
    {
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

void init()
{
    int i;
    fac[0] = 1;
    for(i = 1;i < maxn;i++)
    {
        fac[i] = (fac[i - 1] * i) % mod;
    }
    inv[maxn - 1] = q_pow(fac[maxn - 1],mod - 2);
    for(i = maxn - 2;i >= 0;i--)
    {
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
}

long long C(int n,int m)
{
    if(n < m) return 0;
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
}


int main ()
{
    init();
    cin>>n>>a>>b>>k;
    if(k==0)
    {
        puts("1");
        return 0;
    }
    for(register int x=0;x<=n;x++)
    {
        if(k-a*x<0)
            continue;
        if((k-a*x)%b)
            continue;
        ll y=(k-a*x)/b;
        if(y>n)
            continue;
        sum=(sum+C(n,x)%mod*C(n,y)%mod)%mod;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4992
using System;
public class test
{
  public static void Main(){
    var input = Console.ReadLine().Split(' ');
    var result = int.Parse(input[0]) + int.Parse(input[1]) + int.Parse(input[2]);
    
    if(result >=22)
    {
      Console.WriteLine("bust");
    }
    else if(result <=21)
    {
      Console.WriteLine("win");
    }
  }
}

Measured memory_bytes: 11092
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, l;
	cin >> n >> l;
	int sum = 0;
	int ch;
	int best = 1e9;
	rep(i, n){
		sum += l + i;	
		int cur = (l + i);
		if(abs(cur) < best){
			best = abs(cur);
			ch = cur;
		}
	}
	cout << sum - ch << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, l uint8
	fmt.Scanln(&n, &m, &l)
	a := make([][]uint16, n)
	for i := uint8(0); i < n; i++ {
		a[i] = make([]uint16, m)
	}
	b := make([][]uint16, m)
	for i := uint8(0); i < m; i++ {
		b[i] = make([]uint16, l)
	}
	c := make([][]uint64, n)
	for i := uint8(0); i < n; i++ {
		c[i] = make([]uint64, l)
	}
	for i := uint8(0); i < n; i++ {
		for j := uint8(0); j < m; j++ {
			fmt.Scan(&a[i][j])
		}
	}
	for i := uint8(0); i < m; i++ {
		for j := uint8(0); j < l; j++ {
			fmt.Scan(&b[i][j])
		}
	}
	for i := uint8(0); i < n; i++ {
		for j := uint8(0); j < l; j++ {
			for k := uint8(0); k < m; k++ {
				c[i][j] += uint64(a[i][k]) * uint64(b[k][j])
			}
		}
	}
	for i := uint8(0); i < n; i++ {
		for j := uint8(0); j < l; j++ {
			if j == l-1 {
				fmt.Printf("%d", c[i][j])
			} else {
				fmt.Printf("%d ", c[i][j])
			}
		}

		fmt.Printf("\n")
	}
	return
}



Measured memory_bytes: 2496
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>

int ns[10];

void stringToN(std::string s){
	for(int i=1;i<=9;i++){//初期化
		ns[i] = 0;
	}
	for(int i=0;i<s.length();i++){
		ns[s[i]-'0']++;
	}
}

bool rec(int _ns[10], int remained_n, bool janto_flag){
	if(remained_n == 0){
		return true;
	}



	for(int i=1;i<=9;i++){
		if(_ns[i] >= 3){
			_ns[i] -= 3;
			if(rec(_ns, remained_n-3, janto_flag)){
				return true;
			}
			_ns[i] += 3;
		}
		
		if(i+2 <= 9 && _ns[i] && _ns[i+1] && _ns[i+2]){
			_ns[i]--;
			_ns[i+1]--;
			_ns[i+2]--;
			if(rec(_ns, remained_n-3, janto_flag)){
				return true;
			}
			_ns[i]++;
			_ns[i+1]++;
			_ns[i+2]++;
		}
		
		if(!janto_flag && _ns[i] >= 2){
			_ns[i] -= 2;
			if(rec(_ns, remained_n-2, true)){
				return true;
			}
			_ns[i] += 2;
		}
	}

	return false;
}

int main(){
	std::string s = "";
	while(std::cin >> s, !std::cin.eof()){
		stringToN(s);

		std::vector<int> res;
		for(int i=1;i<=9;i++){
			if(ns[i] <= 3){
				int _ns[10];
				memcpy(_ns, ns, sizeof(ns));
				_ns[i]++;
				if(rec(_ns, 14, false)){
					res.push_back(i);
				}
			}
		}

		if(res.size() == 0){
			puts("0");
		}else{
			printf("%d", res[0]);
			for(int i=1;i<res.size();i++){
				printf(" %d", res[i]);
			}
			puts("");
		}
	}
}

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

int gcd(int x, int y){//最大公約数 greatest common divisor
    if(x<y)swap(x,y);
    if(y==0)return x;
    return gcd(x%y,y);
}
int main() {
  int N,X;
  cin>>N>>X;
  vector<int> x(N);
  rep(i,N) {
    cin>>x[i];
    x[i] -= X;
    x[i] = abs(x[i]);
  }
  //x[i]の最大公約数＝D
  int D=x[0];
  rep(i,N){
    D=gcd(D,x[i]);
  }
  cout<<D<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll A, B, C, D; cin >> A >> B >> C >> D;
  while (true) {
    C -= B;
    if (C <= 0) {
      cout << "Yes\n";
      return 0;
    }
    A -= D;
    if (A <= 0) {
      cout << "No\n";
      return 0;
    }
  }

  return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int dp[5],a,b,c,n;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b>>c;
		int a2=dp[0],b2=dp[1],c2=dp[2];
		dp[0]=max(b2+a,c2+a);
		dp[1]=max(a2+b,c2+b);
		dp[2]=max(a2+c,b2+c);
	}
	cout<<max(dp[0],max(dp[1],dp[2]));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
    int n, m, x;
    scanf("%d %d %d", &n, &m, &x);
    
    int a[m];
    rep(i, m) scanf("%d", &a[i]);

    int count_r = 0, count_l = 0;
    rep(i, m) {
        if(a[i] < x) ++count_l;
        else ++count_r;
    }
    printf("%d\n", min(count_r,count_l));
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    let mut xl = vec![];
    let mut yl = vec![];
    for _ in 0..n {
        parse!(it, x: i64, y: i64);
        xl.push(x + y);
        yl.push(x - y);
    }
    xl.sort();
    yl.sort();
    let mut ret = (xl[n - 1] - xl[0]).abs();
    ret.chmax((yl[n - 1] - yl[0]).abs());
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

int main() {
  int N;
  cin >> N;
  long long int sum = 0;
  vector<long long int> a(N);
  vector<long long int> s(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    sum += a.at(i);
    s.at(i) = sum;
  }
  long long int hsum;
  if (sum % 2== 0) {
    hsum = sum / 2;
  }
  else {
    hsum = sum / 2 + 1;
  }
  for (int i = 0; i < N; i++) {
    if (hsum <= s.at(i)) {
      if (sum % 2 == 0 && hsum == s.at(i)) {
        cout << 0 << endl;
        break;
      }
      else if (i == 0) {
         long long int u = sum - s.at(i);
        printf("%lld\n", s.at(i) - u);
        break;
      }
      else {
        long long int u = sum - s.at(i);
        long long int uu = s.at(i) - u;
        long long int l = sum - s.at(i-1);
        long long int ll = l - s.at(i-1);
        printf("%lld\n", min(uu, ll));
        break;
      }
    }
  }
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    s = set(A)
    if len(s) == N:
        print("YES")
    else:
        print("NO")


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 31896
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
 
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
//Greatest Common Devider
LL gcd(LL a,LL b){
  if(b == 0) return a;
  return gcd(b,a%b);
}
//------------------------------------------
//Least Common Multiple
//Must be used with GCD
LL lcm(LL a,LL b){
  LL g = gcd(a,b);
  return a / g * b;
}
//grobal var
//------------------------------------------

const int MAX_V = 10e5+2;
vector <PII> graph[MAX_V];
int col[MAX_V];

void dfs(int v){
  EACH(i,graph[v]){
    if(col[(*i).first]!=-1) continue;
    col[(*i).first] = (col[v] + (*i).second)%2;
    dfs((*i).first);
  }
}
 
int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int N;
  while(cin >> N ){
    REP(i,N) col[i]=-1;
    REP(i,N-1){
      int u,v,w;
      cin >> u >> v >> w;
      u--;
      v--;
      w%=2;
      graph[u].PB(make_pair(v,w));
      graph[v].PB(make_pair(u,w)); 
      if(u==0)  col[v] = w;
      if(v==0)  col[u] = w;
    }
    col[0]=0;
    EACH(i,graph[0]){
      dfs((*i).first);
    }

    REP(i,N) cout << col[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 30592
S = input()

ans = 0

for i in S:
  if str.islower(i):
    ans += 1

s = S[2:len(S)-1]

if S[0] == 'A' and s.count('C') == 1 and ans == len(S)-2:
  print('AC')
else:
  print('WA')

Measured memory_bytes: 3060
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n , m , k ;
    cin >> n >> m >> k ; 
    vector<int> A(n + 1) , B(m + 1) ; 
    for(int i = 0; i < n; i++){
        int x ;
        cin >> x ;
        A[i + 1] = A[i] + x ;
    }
    for(int i = 0; i < m; i++){
        int x ;
        cin >> x ;
        B[i + 1] = B[i] + x ;
    }
    int answer = 0 ;
    for(int i = 0; i < n + 1; i++){
        if ( A[i] <= k ){
            int target = k - A[i] ;
            int index = upper_bound(B.begin(), B.end(), target) - B.begin();
            index--;
            answer = max(answer, i + index) ;
        }
    }
    cout << answer << endl;
    return 0; 
}

Measured memory_bytes: 6364
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

max_1 = 0
max_2 = 0
max_index = -1
for i in range(N):
    if A[i] > max_1:
        max_1 = A[i]
        max_index = i
    elif A[i] > max_2:
        max_2 = A[i]

for i in range(N):
    if max_1 == max_2:
        print(max_1)
    else:
        if i == max_index:
            print(max_2)
        else:
            print(max_1)

Measured memory_bytes: 12568
package main

import "fmt"

func main() {
	var n, r int
	fmt.Scanf("%d %d\n", &n, &r)

	i := 0
	if n >= 10 {
		i = r
	} else {
		i = r + 100*(10-n)
	}

	fmt.Printf("%d\n", i)
}


Measured memory_bytes: 512
/*input
7
218 786 704 233 645 728 389
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(l.begin(), l.end());
    int ans = 0;
    rep(i, n-2) {
        for (int j = i+1; j < n-1; j++) {
            ans += lower_bound(l.begin(), l.end(), l[i]+l[j])-l.begin()-j-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ar[n+2];
    long long sum=0;
    ar[0]=0;
    ar[n+1]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i];
        sum+=abs(ar[i]-ar[i-1]);
    }
    sum+=abs(0-ar[n]);
    //cout<<sum<<endl;
    long long res=0;
    long long res1=0;
    long long tem=sum;
    for(int j=1;j<=n;j++)
    {
        sum=tem;
        res+=abs(ar[j]-ar[j-1])+abs(ar[j+1]-ar[j]);
        //cout<<"abs(ar[j]-ar[j-1])="<<abs(ar[j]-ar[j-1])<<"   abs(ar[j+1]-ar[j])="<<abs(ar[j+1]-ar[j])<<endl;
        res1+=abs(ar[j+1]-ar[j-1]);
        //cout<<"res="<<res<<" res1="<<res1<<endl;
        sum-=res;
        sum+=res1;

        cout<<sum<<endl;
        sum=0;
        res=0;
        res1=0;
    }



    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P) {
    int i = 0;
    for ( int j = 0; j < k; j++ ) {
        llong s = 0;
        while( s + T[i] <= P ) {
            s += T[i];
            i++;
            if ( i == n ) return n;
        }
    }
    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while( right - left > 1 ) {
        mid = ( left + right ) / 2;
        int v = check(mid);
        if ( v >= n) right = mid;
        else left = mid;
    }
    return right;
}

main() {
    cin >> n >> k;
    for ( int i = 0; i < n; i++ ) cin >> T[i];
    llong ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3860
// G - Longest path
// A. Bacca
#include <bits/stdc++.h>
using namespace std;

int n, m;
vector <vector <int> > Adj;
vector <bool> Visited;
vector <int> dp_path;

void Recibir() {
	int x, y;
	
	cin >> n >> m;
	Adj.resize(n);
	
	for (int i=0; i<m; i++) {
		cin >> x >> y;
		Adj[x-1].push_back(y-1);
	}
	
	dp_path.assign(n, 0);
}

int DFS_VISIT(int u) {
	int tot {0};
	
	for (int v : Adj[u]) {
		if (dp_path[v] != 0) tot = max(tot, dp_path[v] + 1);
		else tot = max(tot, DFS_VISIT(v) + 1);
	}
	
	return dp_path[u] = tot;
}

int DFS() {
	for (int i=0; i<n; i++)  {
		if (dp_path[i] == 0) DFS_VISIT(i);
	}
	
	int res {0};
	for (int x : dp_path) res = max(res, x);
	return res;
}

int main() {
	Recibir();
	cout << DFS();
	return 0;
}

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

int get_type(char *s) {
  int l = strlen(s);
  int c, d, p;
  if (s <= 0) return 2;
  if (s[0] != '>') return 2;
  if (s[1] == '\'') {
    c = d = 0;
    while (c+2<l && s[c+2]=='=') ++c;
    if (!c || c+2>=l || s[c+2]!='#') return 2;
    while (d+c+3<l && s[d+c+3]=='=') ++d;
    if (c!=d || d+c+4!=l || s[d+c+3]!='~') return 2;
    return 0;
  } else if (s[1] == '^') {
    c = 0;
    while (2*c+3<l && s[2*c+2]=='Q' && s[2*c+3]=='=') ++c;
    if (!c || 2*c+4!=l || s[2*c+2]!='~' || s[2*c+3]!='~') return 2;
    return 1;
  }
  return 2;
}

int main() {
  int n, t;
  char snake[201];
  const char *type[] = {"A", "B", "NA"};
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> snake;
    cout << type[get_type(snake)] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {

		static void solve() {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int mult = 0;
			for(int i = 0;i<=999;i+=111) {
				if(n>i) {
					mult++;
				}
			}
			System.out.println(mult*111);
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

}


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

int n;
char s[51][51];
long long f[51][51][51],ans;

int main()
{
	scanf("%d",&n),n<<=1;
	for (int i=1; i<=n; i++) scanf("%s",s[i]+1);
	if (n==2) return putchar(s[1][2]),0;
	for (int i=1; i<=n; i++) f[i][i][i]=1;
	for (int len=3; len<n; len+=2)
		for (int i=2,j=i+len-1; j<=n; i++,j++)
			for (int k=i+1; k<j; k++)
			{
				if (k==i+1)
				{
					if (k==j-1) f[i][j][k]=(s[i][j]-'0'); else
					for (int m=k+2; m<j; m++) if (s[i][m]=='1') f[i][j][k]+=f[k+1][j][m];
				} else
				{
					if (k<j-1) 
					{
						f[i][j][k]=(s[i][j]=='1')*f[i+1][j-1][k];
						for (int m=k+2; m<j; m++) if (s[i][m]=='1')
							for (int q=k+1; q<m; q++)
								f[i][j][k]+=f[i+1][q-1][k]*f[q][j][m];
						for (int l=i+1; l<k-1; l++) if (s[l][j]=='1')
							for (int p=l+1; p<k; p++)
								f[i][j][k]+=f[i][p][l]*f[p+1][j-1][k];
						for (int l=i+1; l<k-1; l++)
							for (int m=k+2; m<j; m++) if (s[l][m]=='1')
								for (int p=l+1; p<k; p++)
									for (int q=k+1; q<m; q++)
										f[i][j][k]+=f[i][p][l]*f[p+1][q-1][k]*f[q][j][m];
					} else
					for (int l=i+1; l<k-1; l++) if (s[l][j]=='1') f[i][j][k]+=f[i][k-1][l];
				}
			}
	ans=0;
	for (int i=3; i<n; i++) if (s[1][i]=='1') ans+=f[2][n][i];
	return printf("%lld\n",ans),0;
}

Measured memory_bytes: 768