akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;

int water[3100]={0},sugar[3100]={0};

void dp_w(int a,int b,int f){
    water[a]=1;
    water[b]=1;
    for(int i=a;i<=f;i++){
        if(water[i]==1&&i+a<3100){
            water[i+a]=1;
            if(i+b<3100){
                water[i+b]=1;
            }
        }
    }
}

void dp_s(int a,int b,int f){
    sugar[0]=1;
    sugar[a]=1;
    sugar[b]=1;
    for(int i=a;i<=f;i++){
        if(sugar[i]==1&&i+a<3100){
            sugar[i+a]=1;
            if(i+b<3100){
                sugar[i+b]=1;
            }
        }
    }
}

int main(){
    int A,B,C,D,E,F;
    int ans_a=0,ans_b=0;
    long double no=-1.0;
    cin>>A>>B>>C>>D>>E>>F;
    dp_w(100*A,100*B,F);
    dp_s(C,D,F);
    for(int i=100*A;i<=F;i++){
        for(int j=0;j+i<=F;j++){
            if(water[i]==1 && sugar[j]==1){
                int tmp=E*(i/100);//tmp(g)砂糖が溶ける
                tmp=j-tmp;//tmp(g)砂糖が溶け残っている
                if(tmp<=0){
                    long double tmp_no=(j*100.0)/(i+j);
                    if(tmp_no>no){
                        no=tmp_no;
                        ans_a=i+j;
                        ans_b=j;
                    }
                }
            }
        }
    }
    cout<<ans_a<<' '<<ans_b<<endl;
    return 0;
}

Measured memory_bytes: 256
s = input()

a = 0
b = 0
c = 0

for i in range(len(s)):
    if s[i]=='a':
        a+=1
    elif s[i]=='b':
        b+=1
    else:
        c+=1

if max(a,b,c)-min(a,b,c)>1:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 39536
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

waA = [0]
for i in range(n):
    waA.append(waA[-1] + a[i])

waB = [0]
for j in range(m):
    waB.append(waB[-1] + b[j])

j = 0
mx = 0
for i in reversed(range(n + 1)):
    while j != m + 1 and waA[i] + waB[j] <= k:
        if mx < i + j:
            mx = i + j
        j += 1

print(mx)

Measured memory_bytes: 47608
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
#include <stack>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;

    stack<char> st;
    for(int i=0; i<N; i++){
        if(st.empty()) st.push(S[i]);
        else if(st.top() == '(' && S[i] == ')') st.pop();
        else st.push(S[i]);
    }

    string A = "", B = "";
    while(!st.empty()){
        char ch = st.top(); st.pop();
        if(ch == ')') A += '(';
        else B += ')';
    }
    cout << A + S + B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}
class llm{
public:
llm(ll value){this->value = (ll)value;}
ll value;
llm operator + (llm obj){return llm((this->value + (ll)(obj.value))%MOD);}
llm operator + (ll obj){return llm((this->value + obj)%MOD);}
llm operator - (llm obj){return llm(((this->value + MOD - (ll)(obj.value)))%MOD);}
llm operator - (ll obj){return llm(((this->value + MOD - obj))%MOD);}
llm operator * (llm obj){return llm((this->value * (ll)(obj.value))%MOD);}
llm operator * (ll obj){return llm((this->value * obj)%MOD);}
llm operator / (llm obj){return llm(this->value / (ll)(obj.value));}
llm operator / (ll obj){return llm(this->value / obj);}
llm operator % (llm obj){return llm(this->value % (ll)(obj.value));}
llm operator % (ll obj){return llm(this->value % obj);}};
ostream& operator<<(ostream& os, llm l){os << l.value;return os;} 
llm operator+(ll a,llm l){return llm((a + l.value)%MOD);} 
llm operator*(ll a,llm l){return llm((a * l.value)%MOD);}

int main(void){
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]==s[2]||s[1]==s[2]&&s[2]==s[3]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000

int main(){
	int x[N] = {0};
	int n, i, a, max = 0, g;

	g = scanf("%d", &n);

	for(i=0; i<n; i++){
		g = scanf("%d", &a);
		if(a > 0) x[a-1]++;
		if(a < N) x[a+1]++;
		x[a]++;
	}

	printf("\n");
	for(i=0; i<N; i++){
		if(max < x[i]) max = x[i];
	}

	printf("%d\n", max);

	return 0;
}

Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int N = sc.nextInt();
    int M = sc.nextInt();

    int[] H = new int[N];
    int[] h = new int[N];
    for (int i = 0; i < N; i++) {
      H[i] = sc.nextInt();
    }

    for (int i = 0; i < M; i++) {
      int A = sc.nextInt();
      int B = sc.nextInt();

      if (H[A - 1] < H[B - 1]) {
        h[A - 1] = -1;
      } else if (H[A - 1] > H[B - 1]) {
        h[B - 1] = -1;
      } else {
        h[A - 1] = -1;
        h[B - 1] = -1;
      }

    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (h[i] == 0) {
        ans++;
      }
    }
    System.out.println(ans);

  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<long long>> a(N, vector<long long>(3));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a.at(i).at(j);
    }
  }
  vector<vector<long long>> dp(N+1, vector<long long>(3));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j == k) continue;
        dp.at(i+1).at(k) = max(dp.at(i+1).at(k), dp.at(i).at(j) + a.at(i).at(k));
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 3; i++) ans = max(ans, dp.at(N).at(i));
  cout << ans << endl;
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(true) {
    c -= b;
    if(c <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if(a <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3492
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    set<string> s;
    for(int i = 0; i < n; i++){
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19232
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstdio>

const int N = 21;
const int infi = (int)1e9 + 7;

typedef std::pair<int, int> P;

int n, m;
std::vector<P> g[N];
int cost[N];

void dijkstra(int k){
	for(int i = 0; i < n; ++i)cost[i] = infi;
	cost[k] = 0;
	std::priority_queue<P, std::vector<P>, std::greater<P> >que;
	que.push(P(0, k));
	
	while(!que.empty()){
		P p = que.top();
		que.pop();
		
		int v = p.second;
		if(cost[v] < p.first)continue;
		
		for(int i = 0; i < g[v].size(); ++i){
			int to = g[v][i].first;
			if(cost[to] > cost[v] + g[v][i].second){
				cost[to] = cost[v] + g[v][i].second;
				que.push(P(cost[to], to));
			}
		}
	}
}

int main(){
	std::cin >> n >> m;
	for(int i = 0; i < m; ++i){
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		--a, --b;
		
		g[a].push_back(P(b, c));
		g[b].push_back(P(a, d));
	}
	
	int s, gg, v, p;
	scanf("%d,%d,%d,%d", &s, &gg, &v, &p);
	--s, --gg;
	dijkstra(s);
	v -= cost[gg];
	dijkstra(gg);
	v -= cost[s];
	v -= p; 
	printf("%d\n", v);
	
	return 0;
}

Measured memory_bytes: 3240
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] strs = str.split(" ");
		int a = Integer.parseInt(strs[0]);
		int b = Integer.parseInt(strs[1]);
		if(a == b){
			System.out.println("a == b");
		}else if(a < b){
			System.out.println("a < b");
		}else{
			System.out.println("a > b");
		}//if
		br.close();
	}
}

Measured memory_bytes: 16896
n=int(input())
aList=list(map(int,input().split()))
rList = []
r1 = 0
for i in range(n):
	if i%2 == 0:
		r1 += aList[i]
	else:
		r1 -= aList[i]
rList.append(r1)

for i in range(n-1):
	r = (2 * aList[i]) - rList[i]
	rList.append(r)

print(' '.join(map(str, rList)))

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

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;}

const ll INF = 1LL << 60;


int main(){
  int n;
  cin >> n;
  int v=0;int sum=n;
  while(sum>=10){
    v+=sum%10;
    sum/=10;
  }
  v+=sum;

  if(n%v==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
vector<int> E[101010];
int in[101010];
int cur[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		x--,y--;
		E[x].push_back(y);
		in[y]++;
	}
	
	queue<int> Q;
	FOR(i,N) if(in[i]==0) Q.push(i);
	int ma=0;
	while(Q.size()) {
		x=Q.front();
		Q.pop();
		
		cur[x]++;
		ma=max(ma,cur[x]);
		FORR(e,E[x]) {
			cur[e]=max(cur[e],cur[x]);
			in[e]--;
			if(in[e]==0) Q.push(e);
		}
	}
	cout<<ma-1<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <string>

using namespace std;

string S;
int num[4];

pair<int, string> func(int i, int x, string eq) {
	if (i == 4) return {x, eq};

	auto sum1 = func(i + 1, x + num[i], eq + "+" + to_string(num[i]));
	if (sum1.first == 7) return sum1;

	auto sum2 = func(i + 1, x - num[i], eq + "-" + to_string(num[i]));
	if (sum2.first == 7) return sum2;

	return {0, ""};
}


int main() {
	cin >> S;
	for (int i = 0; i < 4; ++i) {
		num[i] = S[i] - '0';
	}

	auto sum = func(1, num[0], S.substr(0, 1));
	cout << sum.second + "=7" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ActiveInfants | diff ActiveInfants.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ActiveInfants.cpp && ./a.out

/*
 
 4/19/2020
 
 5:48-
 
 */

const int MAX_N=2e3+1;
LL A[MAX_N];
int N;

LL memo[MAX_N][MAX_N];
vector<pair<LL,int>> X;
LL f(int l, int r) {
  if(r<l) return 0LL;
  LL &res=memo[l][r];
  if(res>=0) return res;
  res=0;
  int cnt=N-1-r+l;
  LL a; int i; tie(a,i)=X[cnt];
  LL x=a*abs(l-i)+f(l+1,r),y=a*abs(r-i)+f(l,r-1);
  return res=max(x,y);
}
void solve() {
  REP(i,N) X.emplace_back(A[i],i);
  sort(X.rbegin(),X.rend());
  
  MINUS(memo);
  cout<<f(0,N-1)<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 35128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/challenges/search/volumes/0297>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(){
    ll K,P; cin >> K >> P;
    return (K-1)%P + 1;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N; cin >> N;
    while(N--){
        cout << solve() << endl;
    }
    return 0;
}



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

using namespace std;
typedef long long ll;

int ctoi(char c) {
  return c - '0';
}

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

  for (int i = A; i < A * B; i+=A) {
    if (i % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

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

int main() {
  int n,m;
  while(cin >> n >> m && (n || m)) {
    n=m-n;
    int a[3]={0,0,0};
    while(n>=1000) {
      n-=1000;
      a[2]++;
    }
    while(n>=500) {
      n-=500;
      a[1]++;
    }
    while(n>=100) {
      n-=100;
      a[0]++;
    }
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
  }
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int sum = 0;
    for(int i=0; i<s.size()/2; i++){
        if(s[i] != s[s.size()-1-i]){
            sum++;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
/* kadai6_2
   reo012 */

#include <stdio.h>
#include <string.h>

#define SIZE 101

int main(void){
    char word[SIZE];    //単語入る配列word用意
    int length;    //単語の文字数length用意
    scanf("%s", word);    //単語入力
    length = (int)strlen(word);    //単語の文字数取得
    printf("%c%d%c\n", word[0], length-2, word[length-1]);    //最初の文字、間の文字数、最後の文字出力
    return 0;
}

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

using namespace std;

#define N 200005
#define LL long long

int n, a, b, c, i, flag;
char s[3], st[N][3], Sol[N];

int main (void)
{
	scanf("%d%d%d%d",&n,&a,&b,&c);
	if ((LL)a+b+c>=3) {
		flag=0;
		for (i=1; i<=n; i++) {
			scanf("%s",s);
			if (s[0]=='A'&&s[1]=='B') {
				if (a>b) a--,b++,Sol[i]='B';
				else a++,b--,Sol[i]='A';
				if (a<0||b<0) flag=1;
			}
			else if (s[0]=='A'&&s[1]=='C') {
				if (a>c) a--,c++,Sol[i]='C';
				else a++,c--,Sol[i]='A';
				if (a<0||c<0) flag=1;
			}
			else {
				if (b>c) b--,c++,Sol[i]='C';
				else b++,c--,Sol[i]='B';
				if (b<0||c<0) flag=1;
			}
		}
		if (flag) puts("No");
		else {
			puts("Yes");
			for (i=1; i<=n; i++) printf("%c\n",Sol[i]);
		}
	}
	else {
	//	assert(0);
	    flag=0;
		for (i=1; i<=n; i++) scanf("%s",st[i]);
		for (i=1; i<=n; i++) {
			if (st[i][0]=='A'&&st[i][1]=='B') {
				if (!a) a++,b--,Sol[i]='A';
				else if (!b) a--,b++,Sol[i]='B';
				else {
					if (st[i+1][0]=='A'&&st[i+1][1]=='C') a++,b--,Sol[i]='A';
					else if (st[i+1][0]=='B'&&st[i+1][1]=='C') b++,a--,Sol[i]='B';
					else a++,b--,Sol[i]='A';
				}
				if (a<0||b<0) flag=1;
			}
			else if (st[i][0]=='A'&&st[i][1]=='C') {
				if (!a) a++,c--,Sol[i]='A';
				else if (!c) a--,c++,Sol[i]='C';
				else {
					if (st[i+1][0]=='A'&&st[i+1][1]=='B') a++,c--,Sol[i]='A';
					else if (st[i+1][0]=='B'&&st[i+1][1]=='C') c++,a--,Sol[i]='C';
					else a++,c--,Sol[i]='A';
				}
				if (a<0||c<0) flag=1;
			}
			else {
				if (!b) b++,c--,Sol[i]='B';
				else if (!c) b--,c++,Sol[i]='C';
				else {
					if (st[i+1][0]=='A'&&st[i+1][1]=='C') c++,b--,Sol[i]='C';
					else if (st[i+1][0]=='A'&&st[i+1][1]=='B') b++,c--,Sol[i]='B';
					else b++,c--,Sol[i]='B';
				}
				if (b<0||c<0) flag=1;
			}
		}
		if (flag) puts("No");
		else {
			puts("Yes");
		    for (i=1; i<=n; i++) printf("%c\n",Sol[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 4120
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

pair<int, int> pos[55], check[55];

int main(){
  FAST_IO
  int N, M;
  cin >> N >> M;

  for(int rep = 0, x, y; rep < N; ++rep){
    cin >> x >> y;
    pos[rep] = MP(x, y);
  }

  for(int rep = 1, x, y; rep <= M; ++rep){ 
    cin >> x >> y;
    check[rep] = MP(x, y);
  }

  for(int rep = 0, dis, idx, X, Y; rep < N; ++rep){
    dis = idx = INF;
    X = pos[rep].F, Y = pos[rep].S;

    for(int ck = 1, x, y; ck <= M; ++ck){
      x = check[ck].F, y = check[ck].S;
      if(abs(X - x) + abs(Y - y) < dis){
        dis = abs(X - x) + abs(Y - y);
        idx = ck;
      }
    }

    cout << idx << '\n';
  }
      
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int n,bit[500],bitk[500],mx,ans[500];
ll k,two[50],res;
void bin (ll x, bool ink){
    queue <ll> s;
    while(x>0){
        s.push(x);
        x/=2;
    }
    int idx = -1;
    while(!s.empty()){
        idx ++;
        mx = max(mx,idx);
        if(s.front() % 2 == 1){
            if(!ink)bit[idx]++;
            else bitk[idx]++;
        }
        s.pop();
    }
}
int main(){
    two[0]=1;
    for(int i=1;i<=45;i++){
        two[i] = 2 * two[i-1];
    }

    cin>>n>>k;
    bin(k,true);
    for(int i=1;i<=n;i++){
        ll temp;
        cin>>temp;
        bin(temp,false);
    }

//    for(int i=0;i<=mx;i++)cout<<bit[i];cout<<endl;
//    for(int i=0;i<=mx;i++)cout<<bitk[i];cout<<endl;

    for(int i=0;i<=mx;i++){
        if(bit[i] < n - bit[i]){ans[i]=1;}
    }
    for(int i=mx;i>=0;i--){
        if(bitk[i]>ans[i]){break;}
        if(bitk[i]<ans[i]){ans[i]=0;}
    }
//    for(int i=0;i<=mx;i++)cout<<ans[i];cout<<endl;
    for(int i=0;i<=mx;i++){
        if(ans[i]==1){
            res += (ll) two[i] * (n-bit[i]);
        }
        else if(ans[i]==0){
            res += (ll) two[i] * (bit[i]);
        }
    }
    cout<<res<<endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  long long k, q;
  cin>>k>>q;
  long long d[k];
  REP(i, k){
    cin>>d[i];
  }
  REP(i, q){
    long long n, x, m;
    cin>>n>>x>>m;
    long long dm[k];
    long long s = 0;
    REP(i, k){
      dm[i] = d[i] % m;
      s += dm[i];
    }
    long long cnt = 0;
    REP(i, k){
      if(dm[i] == 0)cnt++;
    }
    long long zcnt = 0;
    zcnt += ((n - 1) / k) * cnt;
    long long r = (n - 1) % k;
    REP(i, r){
      if(dm[i] == 0)zcnt++;
    }
    long long lcnt;
    long long lvalue = x;
    lvalue += ((n - 1) / k) * s;
    REP(i, r){
      lvalue += dm[i];
    }
    lcnt = lvalue/m - x/m;
    long long res = (n - 1) - zcnt - lcnt;
    cout<<res<<endl;
  }
  return 0;
}


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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  int sum = 0, ans = 1;
  rep(_, n) {
    int l;
    cin >> l;
    sum += l;
    if (sum > x) {
      cout << ans << '\n';
      return 0;
    }
    ans++;
  }
  cout << n + 1 << '\n';
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
#define MOD 1000000007

int main(int argc, char const *argv[]) {
  int a,b;
  std::cin >> a >> b;
  std::cout << (a-1)*(b-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N_MAX 100005
#define NIL -1

void print(int t);
int get_depth(int t);
//tree *create_node(int num);

struct node
{
  int parent;
  int left;
  int right;
};

struct node tree[N_MAX];


/*tree *create_node(int num)
{
  tree_node *new;
  
  node *new=malloc(sizeof(tree));
  if(new = NULL)
    exit(3);
  new -> left=NULL;
  new -> right=NULL;
  new -> value=num;

  return tree_new;
  }*/


int get_depth(int t)
{
  int depth=0;
  while(tree[t].parent != NIL){
    t = tree[t].parent;
    depth ++;
  }
  
  return depth;
}


void print(int t)
{
  printf("node %d: ",t);

  printf("parent = %d, ",tree[t].parent);

  printf("depth = %d, ",get_depth(t));

  if(tree[t].parent == NIL){
    printf("root, ");
  }
  else if(tree[t].left == NIL){
    printf("leaf, ");
  }
  else{
    printf("internal node, ");
  }


  int c=tree[t].left;
  printf("[");
  while(c != NIL){
    printf("%d",c);
    c = tree[c].right;
    if(c != NIL){
      printf(", ");
    }
  }
  printf("]\n");
}



int main()
{
  int n, i, j;
  int id, k, c, left=0, r;

  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    tree[i].parent=NIL;
    tree[i].left=NIL;
    tree[i].right=NIL;
  }

  
  for(i=0; i<n; i++){
    scanf("%d", &id);
    scanf("%d", &k);
    for(j=0; j<k; j++){
      scanf("%d", &c);
      if(j==0){
	tree[id].left = c;
      }
      else{
	tree[left].right = c;
      }
      left = c;
      tree[c].parent = id;
    }
  }

  
  for(i=0; i<n; i++){
    print(i);
  }
  
  return 0;
}

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
bool calc(int n){
  for(int i=1;i<=n;i++){
    if(i*i==n) return true;
  }
  return false;
}
int main(){
  int n,d,cnt=0,sum;
  cin >> n >> d;
  int x[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> x[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      sum=0;
      for(int k=0;k<d;k++){
        sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      if(calc(sum)) cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int N;

vector<string> bs(vector<string> c)
{
	REP(i, N)
	{
		for (int j = N - 1; j >= i + 1; --j)
		{
			if (c[j][1] < c[j - 1][1])
			{
				swap(c[j], c[j - 1]);
			}
		}
	}
	return c;
}

vector<string> ss(vector<string> c)
{
	REP(i, N)
	{
		int minj = i;
		FOR(j, N, i)
		{
			if (c[j][1] < c[minj][1])
			{
				minj = j;
			}
		}
		swap(c[i], c[minj]);
	}
	return c;
}

int main()
{
	cin >> N;
	vector<string> C(N);
	REP(i, N)
	{
		cin >> C[i];
	}

	string s = "Stable";
	vector<string> t1 = bs(C);
	vector<string> t2 = ss(C);
	REP(i, N)
	{
		if (t1[i] != t2[i])
		{
			s = "Not stable";
		}
	}
	cout << t1[0];
	FOR(i, N, 1)
	{
		cout << " " << t1[i];
	}
	cout << endl << "Stable" << endl;
	cout << t2[0];
	FOR(i, N, 1)
	{
		cout << " " << t2[i];
	}
	cout << endl << s << endl;
	return 0;
}


Measured memory_bytes: 3216
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <iostream>
using namespace std;

vector<string>split(string s, char delim){
  int len = s.length();
  string currStr = "";
  vector<string>retVec;
  for(int i = 0;i<len;i++){
    char ch = s[i];
    if(ch==delim){
      retVec.push_back(currStr);
      currStr = "";
    }else{
      currStr += ch;
    }
  }
  retVec.push_back(currStr);
  return retVec;
}



vector<int>strToIntVec(string s){
  int len = s.length();
  //  s = s.substr(1,len-2);
    vector<string>strVec = split(s,' ');
  vector<int>retVec;
  for(int i=0;i<strVec.size();i++){
    int el = atoi(strVec[i].c_str());
    retVec.push_back(el);
  }
  return retVec;
}

class PD{
public:
  string getMaxIndex(string t){
  int len = t.length();
  for(int i=0;i<len;i++){
    if(t[i]=='?'){
      t[i] = 'D';
    }
  }
  return t;
}
};

int main(int argc, const char*argv[]){
  PD pd;
  string tLn;
  getline(cin,tLn);
  string retS = pd.getMaxIndex(tLn);
  cout<<retS<<endl;
  return 0;
}


Measured memory_bytes: 3864
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    int sum = a + b + c;
    if (sum >= 22) {
      System.out.println("bust");
    }
    else{
      System.out.println("win");
    }
  }
}


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

int main(){
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    ll a[1000],b[1000],c[1000];
    for(int i=0;i<x;i++)cin>>a[i];
    for(int i=0;i<y;i++)cin>>b[i];
    for(int i=0;i<z;i++)cin>>c[i];
    vector<ll> d(1000000);
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            d.push_back(a[i]+b[j]);
        }
    }
    sort(d.begin(),d.end(),greater<ll>());
    vector<ll> e(3000000);
    for(int i=0;i<min(k,x*y);i++){
        for(int j=0;j<z;j++){
            e.push_back(d[i]+c[j]);
        }
    }
    sort(e.begin(),e.end(),greater<ll>());
    for(int i=0;i<k;i++)cout<<e[i]<<endl;
}


Measured memory_bytes: 64760
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
#include<set>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	int n, k;
	cin >> n >> k;
	vector<int>a(n);
	int ans = 0;
	rep(i, n) {
		cin >> a[i];
		ans += a[i];
	}
	sort(a.begin(), a.end());
	rep(i, n - k) {
		ans -= a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

struct Point {
	int x;
	int y;
};

int main()
{

	int n, d;
	int cnt = 0;
	cin >> n >> d;

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

		Point p;
		cin >> p.x >> p.y;

		double dist = sqrt(pow(p.x, 2) + pow(p.y, 2));
		if (dist <= d) cnt++;

	}

	cout << cnt;

	return 0;
}

Measured memory_bytes: 3156
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<string, pair<int,int> > P;

//int A,P;
/*cin>>A>>P;
    cout<<(3*A+P)/2;*/
int N;
P s[105];
int main(){
    

    cin>>N;
    for(int i=0;i<N;i++){
        cin>>s[i].first>>s[i].second.first;
        s[i].second.first*=-1;
        s[i].second.second=i;
    }
    sort(s,s+N);
    for(int i=0;i<N;i++){
        cout<<s[i].second.second+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

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

    vector<ll> sum(n+1);    sum[0] = 0;
    vector<pair<ll,ll>> vp;
    ll a, b;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        vp.push_back({a,b});
    }
    sort(vp.begin(), vp.end());
    for(int i = 0; i < n; i++){
        sum[i+1] = sum[i] + vp[i].second;
    }

    ll ans = 0, tmpmin = 1ll<<60;
    for(int i = 1; i <= n; i++){
        tmpmin = min(tmpmin, sum[i-1]-vp[i-1].first);
        ans = max(ans, sum[i]-vp[i-1].first-tmpmin);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 15136
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

int n, a, b, c;
vector <pair <int, pair <int, int> > > v;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    while(n-- && cin >> a >> b >> c)
        v.push_back(make_pair(a, make_pair(b, c)));
    v.push_back(make_pair(0, make_pair(0, 0)));
    sort(v.begin(), v.end());
    for(int i = 1 ; i < v.size() ; i++){
        int dis = abs(v[i].second.first-v[i-1].second.first)+abs(v[i].second.second-v[i-1].second.second);
        int tim = v[i].first-v[i-1].first;
        if(dis > tim || (tim-dis)&1)finish("No");
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1912
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

LL solve(VVLL &memo, VLL &a, int s, int e) {
    if (s >= e) return 0;
    if (memo[s][e] < (1LL << 60)) return memo[s][e];
    return memo[s][e] = max(a[s] - solve(memo, a, s+1,e), a[e-1] - solve(memo, a, s, e-1));
}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    VVLL memo(n+1,VLL(n+1,1LL<<60));
    cout << solve(memo, a, 0,n) << endl;
}

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

Measured memory_bytes: 71040
#include<stdio.h>

int main(void){

    int a,b;

    scanf("%d",&a);
    scanf("%d",&b);

    if(a<b)
        printf("a < b\n");
    else if(a>b)
        printf("a > b\n");
    else
        printf("a == b\n");

    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

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

int main(){
    long long N;
    cin >> N;
    long long d[N];
    rep(i, N){
        cin >> d[i];
    }

    sort(d, d + N);
    int K_range = d[N / 2] - d[(N / 2 - 1)];

    cout << K_range << endl;

    return 0;
}

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

typedef long long LL;
typedef pair<int, int> II;

int main() {
	int n, m, k; cin >> n >> m >> k;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= m; ++j) {
			int x = i * (m - j) + (n - i) * j;
			if (x == k) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main(){	
	int room[4][3][10],num,a, b, c, d;
	memset(room, 0, sizeof(room));
	cin >> num;
	for (int i = 0; i < num; i++){	
		cin >> a >> b >> c >> d ;
		room[a - 1][b - 1][c - 1] += d;
	}
	for (a = 0; a < 4; a++){
		for (b = 0; b < 3; b++){
			for (int c = 0; c < 10; c++)
				cout << " " << room[a][b][c];
			cout << endl;
		}
		if(a != 3)cout << "####################" << endl;
	}
}

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

ll factorial_of(ll num){
    ll sum=1;
    for(int i=1;i<=num;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    vector<int> vec;
    vec = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int k;
    cin >> k;
    int ans = vec.at(k-1);
    cout << ans << endl;
}


Measured memory_bytes: 256
# include"stdio.h"
int main(){
    char a,b;
    scanf("%c %c",&a,&b);
    if(a=='H'){
        printf("%c\n",b);
    }
    if(a=='D'){
        if(b=='H')
            printf("D\n");
        else
            printf("H\n");
    }
}


Measured memory_bytes: 1732
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};
use std::collections::BTreeSet;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }
    a.sort_unstable();
    let a = a;

    let mut setwise_gcd = a[0];
    for i in 2..=n {
        setwise_gcd = gcd(setwise_gcd, a[i - 1]);
    }
    if setwise_gcd > 1 {
        println!("not coprime");
        return;
    }

    // let mut nononecount = 0;
    // for &ai in &a {
    //     if ai == 1 {
    //         continue;
    //     }
    //     nononecount += 1;
    // }
    // if nononecount > 78498 {
    //     println!("setwise coprime");
    //     return;
    // }

    // Sieve of Eratosthenes
    const PMAX: usize = 1000000;
    let mut is_prime: Vec<bool> = vec![true; PMAX];
    is_prime[0] = false;
    is_prime[1] = false;
    let mut primes_vec: Vec<usize> = Vec::new();
    for i in 2..PMAX {
        if is_prime[i] {
            for j in i..=(PMAX - 1) / i {
                is_prime[i * j] = false;
            }
            primes_vec.push(i);
        }
    }
    let _ = is_prime;
    let primes_vec = primes_vec;

    let mut already_got = vec![false; primes_vec.len()];

    for &ai in &a {
        if ai == 1 {
            continue;
        }
        match primes_vec.binary_search(&ai) {
            Ok(i) => {
                if already_got[i] {
                    println!("setwise coprime");
                    return;
                } else {
                    already_got[i] = true;
                }
                continue;
            }
            Err(_) => {}
        }

        for i in 0..primes_vec.len() {
            let p = primes_vec[i];
            if p > ai {
                continue;
            }
            if ai % p == 0 {
                if already_got[i] {
                    println!("setwise coprime");
                    return;
                } else {
                    already_got[i] = true;
                }
            }
        }
    }
    println!("pairwise coprime");
}

fn gcd(m: usize, n: usize) -> usize {
    if m < n {
        return gcd(n, m);
    } else if n == 0 {
        return m;
    } else {
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 18228
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  string s;
  cin >> s;
  cout << ((s.size() % 2) ^ (s[0] == s[s.size() - 1]) ? "First" : "Second")
       << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void)
{
    int a;
    cin >> a;
    int n[100];
    for (int i = 0; i < a; i++)
        cin >> n[i];

    for (int i = 0; i < a; i++)
    {
        int v = n[i];
        int j = i - 1;
        while (j >= 0 && n[j] > v)
            n[j + 1] = n[j--];
        n[j+1] = v;
        for (int i = 0; i < a; i++)
            cout << n[i] << (i<a - 1 ? " " : "\n");
    }
}



Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
set<pair<ll,ll>> spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
//vector<ll> vll;
ll num[10][10];
//priority_queue<ll> pq;          //decreasing

int main(void)
{
    long long int m,n,i,j,k,sum=0,l,r;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>m;
        if(i%2==1)
        {
            if(m%2==1)
                sum++;
        }
    }
    cout<<sum;
    return 0;
}





Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11;
int n, a[N], du[N], x[N];
int head[N], nex[N<<1], to[N<<1], size;
bool flag = 1;
void add(int x, int y){
    to[++size] = y;
    nex[size] = head[x];
    head[x] = size;
}
void dfs(int u, int fa){
    if(du[u] == 1){
        x[u] = a[u];
        return ;
    }
    int sum = 0, ma = 0;
    for(int i = head[u];i;i = nex[i]){
        int v = to[i];
        if(v == fa)continue;
        dfs(v, u);
        sum += x[v];
        ma = max(ma, x[v]);
    }
    int k = sum - a[u];
    if(k < 0)flag = 0;
    x[u] = sum - 2 * k;
    if(x[u] < 0)flag = 0;
    if(u == fa && x[u] > 0)flag = 0;
    if(k > min(sum / 2, sum - ma))flag = 0;
}
int main(){
    scanf("%d", &n);
    for(int i = 1;i <= n; i++){
        scanf("%d", &a[i]);
    }
    if(n == 2){
        if(a[1] == a[2])puts("YES");
        else puts("NO");
        return 0;
    }
    int u, v;
    for(int i = 1;i < n; i++){
        scanf("%d%d", &u, &v);
        du[u]++; du[v]++;
        add(u, v);
        add(v, u);
    }
    int rt = 1;
    for(int i = 1;i <= n; i++)if(du[i] != 1)rt = i;
    dfs(rt, rt);
    if(flag)puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 10496
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
  for(int W,N;cin>>W>>N,W|N;){
    int x[52345];
    for(int i=0;i<N;i++){
      cin>>x[i];
    }
    int l=0,h=1e9;
    while(h-l>1){
      int m=(h+l)/2;
      vector<pair<int,int> > v[52345];
      bool p[52345]={};
      v[0].emplace_back(0,1);
      for(int i=0;i<N;i++){
	v[i+1].reserve(v[i].size());
	bool f=false;
	for(auto e:v[i]){
	  p[i]|=e.first+x[i]<=W;
	  int nl=e.first+x[i]+1;
	  if(nl<W){
	    int nh=min(W,e.second+x[i]+m);
	    if(!v[i+1].empty()&&v[i+1].back().second>=nl){
	      v[i+1].back().second=nh;
	    }else{
	      v[i+1].emplace_back(nl,nh);
	    }
	  }
	  f|=e.first<=W-x[i]&&W-x[i]<e.second;
	}
	if(f){
	  v[i+1].insert(v[i+1].begin(),make_pair(0,1));
	}
      }
      (!p[N-1]?l:h)=m;
    }
    cout<<h<<endl;
  }
}

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

using namespace std;

int main() {
	int a, b, c, k;
	cin>>a>>b>>c>>k;
	int ans = min(k, a);
	k -= a;
	if(k > 0) {
		k -= b;
	}
	if(k > 0) {
		int negs = min(k, c);
		ans -= negs;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
struct state { long long a, b; };
inline bool operator<(const state& s1, const state& s2) { return s1.a < s2.a; }
int N; long long D, A[33], B[33];
int cnt1, cnt2, cnt3, cnt4; state vl[14348922], vr[14348922]; // meet-in-the middle
int que[14348922]; // searching deque
int main() {
	scanf("%d%lld", &N, &D);
	for (int i = 0; i < N; i++) scanf("%lld%lld", &A[i], &B[i]);

	// Meet-in-the-middle Algorithm
	int sep1 = (N >> 1), sep2 = N - sep1;
	vector<long long> sa1(1 << sep1), sb1(1 << sep1);
	vector<long long> sa2(1 << sep2), sb2(1 << sep2);
	for (int i = 0; i < sep1; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa1[j] = sa1[j - b1] + A[i];
			sb1[j] = sb1[j - b1] + B[i];
		}
	}
	for (int i = 0; i < sep2; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa2[j] = sa2[j - b1] + A[i + sep1];
			sb2[j] = sb2[j - b1] + B[i + sep1];
		}
	}
	cnt1 = 0;
	for (int i = 0; i < 1 << sep1; i++) {
		int r = (1 << sep1) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa1[k] - sa1[j];
			long long r2 = sb1[k] - sb1[j];
			if (r1 >= 0) vl[cnt1++] = state{ r1, r2 };
			if (r1 > 0) cnt3++;
			j = (j - 1) & r;
		} while (j != r);
	}
	cnt2 = 0;
	for (int i = 0; i < 1 << sep2; i++) {
		int r = (1 << sep2) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa2[k] - sa2[j];
			long long r2 = sb2[k] - sb2[j];
			if (r1 >= 0) vr[cnt2++] = state{ r1, r2 };
			if (r1 > 0) cnt4++;
			j = (j - 1) & r;
		} while (j != r);
	}
	sort(vl, vl + cnt1); cnt1 += cnt3;
	sort(vr, vr + cnt2); cnt2 += cnt4;
	int cnt5 = cnt1 - cnt3;
	int cnt6 = cnt2 - cnt4;

	vector<state> wl(cnt1), wr(cnt2);
	for (int i = 0; i < cnt3; i++) wl[i] = state{ -vl[cnt5 - i - 1].a, -vl[cnt5 - i - 1].b };
	for (int i = 0; i < cnt4; i++) wr[i] = state{ -vr[cnt6 - i - 1].a, -vr[cnt6 - i - 1].b };
	copy(vl, vl + cnt5, wl.begin() + cnt3);
	copy(vr, vr + cnt6, wr.begin() + cnt4);

	// Searching with deque
	int cl = 0, cr = 0, dl = 0, dr = 0;
	long long ret = 0;
	for (int i = cnt2 - 1; i >= 0; i--) {
		while (cr < cnt1 && wl[cr].a + wr[i].a <= D) {
			while ((dr - dl) && wl[que[dr - 1]].b <= wl[cr].b) dr--;
			que[dr++] = cr++;
		}
		while (cl < cnt1 && wl[cl].a + wr[i].a < -D) {
			if ((dr - dl) && que[dl] == cl) dl++;
			cl++;
		}
		if (dr - dl) ret = max(ret, wr[i].b + wl[que[dl]].b);
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 681832