akhauriyash/Code-Regression huggingface dataset:
// thanks to https://www.hamayanhamayan.com/entry/2020/01/18/233933
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vector<vl> ab(n, vl(2));
  rep(i, n) {
    cin >> ab[i][0];
  }
  rep(i, n) {
    cin >> ab[i][1];
  }

  constexpr ll maxi = 51;
  constexpr ll inf = 1LL<<60;
  vector<vl> dp(1LL << n, vl(maxi, inf));

  dp[0][0] = 0;
  rep(mask, 1LL<<n) {
    rep(i, maxi) {
      if (dp[mask][i] == inf) continue;

      ll done = 0;
      rep(j, n) {
        if (mask >> j & 1) done++;
      }

      rep(j, n) {
        if (mask >> j & 1) continue;

        ll parity = abs(j-done)%2;
        if (i > ab[j][parity]) continue;

        ll inversion = 0;
        rep(k, j) {
          if (!(mask & (1LL << k))) inversion++;
        }

        cmin(dp[mask | (1<<j)][ab[j][parity]], dp[mask][i] + inversion);
      }
    }
  }

  ll ans = inf;
  rep(i, maxi) {
    cmin(ans, dp[(1LL<<n)-1][i]);
  }

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


Measured memory_bytes: 112896
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


int main(){
  int n,res=1; cin >> n;
  int flag = 0; 
  //flag=1 単調増加、flag=-1　単調減少
  int a[n];
  REP(i,n)cin>>a[i];
  FOR(i,1,n){
   
    if(a[i]==a[i-1])continue;
    if(a[i]>a[i-1]&&flag==-1){
      res++;
      flag = 0;
    }
    else if (a[i]<a[i-1] &&flag == 1){
      res++;
      flag = 0;
    }
    else if(flag==0){
      if(a[i]>=a[i-1])flag=1;
      else
        flag = -1;
    }
    //cout<<a[i]<<"  "<<flag<<" "<<res<<endl;
    
  }
  cout << res << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <map>
#include <algorithm>

using namespace std;

const int N = 1e5 + 500;

int A[N], n, x, B[N];
map < int , int > rev;

int main(){
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d", A + i);
		B[i] = A[i];
	}
	sort(B, B + n);
	for(int i = 0;i < n;i++){
		rev[B[i]] = i;
	}
	for(int i = 0;i < n;i++){
		x += (i - rev[A[i]] + N) % 2;
	}
	printf("%d\n", x / 2);
	return 0;
}

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


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

    int target_num = 1;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (target_num != a[i]) {
            ans++;
        } else {
            target_num++;
        }
    }

    if (target_num == 1) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
string s;
void no()
{
    puts("No");
    exit(0);
}
void go(int cur, int target)
{
    while (cur != target) {
        if (s[cur + 1] == '.') {
            cur++;
        } else if (cur + 2 <= target && s[cur + 2] == '.') {
            cur += 2;
        } else {
            no();
        }
    }
}
main() {
    int n = readInt();
    int a = readInt();
    int b = readInt();
    int c = readInt();
    int d = readInt();
    cin >> s;
    s = "$" + s;

    if (c == d) {
        no();
    }
    go(b, d);
    go(a, c);
    if (c > d) {
        bool ok = true;
        for (int i = b; i <= d; i++) {
            if (i > 1 && s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') {
                puts("Yes");
                return 0;
            }
        }
        no();
    }
//    s[a] = 'A';
//    s[b] = 'B';
//    for (int i = 1; i <= n; i++) {
//        if (i % 2 == 1 && b != d) {
//            if (s[b + 1] == '.') {
//                swap(s[b], s[b + 1]);
//                ++b;
//            } else if (s[b + 2] == '.') {
//                swap(s[b], s[b + 2]);
//                b += 2;
//            } else {
//                no();
//            }
//        } else if (a != c) {
//            if (s[a + 1] == '.') {
//                swap(s[a], s[a + 1]);
//                ++a;
//            } else if (s[a + 2] == '.') {
//                swap(s[a], s[a + 2]);
//                a += 2;
//            } else {
//                no();
//            }
//        }
//        if (a > 1 && a + 1 == b && c > d) {
//
//        }
//    }
//    cout << s << "\n";
    puts("Yes");
}



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



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

    string s;
    cin >> s;
    int n = s.size();
    ll w = 0;
    ll cnt = 0;
    rep(i,n){
        if(s[i]=='W'){
            w+=(i-cnt);
            cnt++;
        }
    }

    cout << w << endl;

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;


ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}

ll nCm(ll n, ll m){
    ll res = 1;
    Rreps(i, n + 1, n - m + 1){
        (res *= i)%=MOD;
    }
    reps(i, 1, m + 1){
        (res *= fastpow(i, MOD - 2))%=MOD;
    }
    return res;
}
int main() {
    cin>>N>>A>>B;
    ll ans = fastpow(2, N);
    (ans += MOD - 1)%=MOD;
    //cout<<nCm(4, 1)<<endl;
    (ans += MOD - nCm(N, A))%=MOD;
    (ans += MOD - nCm(N, B))%=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N=int(input())
if N>=64:
  print(64)
elif 64>N>=32:
  print(32)
elif 32>N>=16:
  print(16)
elif 16>N>=8:
  print(8)
elif 8>N>=4:
  print(4)
elif 4>N>=2:
  print(2)
elif 2>N>=1:
  print(1)

Measured memory_bytes: 3060
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#define f first
#define s second
#define MOD 1000000007
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#include<bits/stdc++.h>
using namespace std;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
    
}


int main()
{
    fast;
    ll a,b;
    cin>>a>>b;
    ll ans = a*b;
    
    ll g = gcd(a, b);
    
    ans = ans / g;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int spr[128][128];
    int r, c, i, j, sum;
    scanf("%d %d" , &r, &c);
    for(i = 0; i < r; i++){
        sum = 0;
        for(j = 0; j < c; j++){
            scanf("%d", &spr[i][j]);
            sum += spr[i][j];
        }
        spr[i][c] = sum;
    }
    c++;
    for(i = 0; i < c; i++){
        sum = 0;
        for(j = 0; j < r; j++){
            sum += spr[j][i];
        }
        spr[r][i] = sum;
    }
    r++;
    for(i = 0; i < r; i++){
        printf("%d", spr[i][0]);
        for(j = 1; j < c; j++){
            printf(" %d", spr[i][j]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2044
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef long long ll;
typedef pair<int, int> pll;
typedef vector<int> vll;
typedef vector<pll> vpll;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

int n, W;
int w[105], v[105];
int dp[105][100005];

int32_t main() {
  FAST_IO;
  cin >> n >> W;
  rep(i, n)
    cin >> w[i] >> v[i];
  rep(i, n) {
    for (int j = 0; j <= W; j++) {
      dp[i + 1][j] = dp[i][j];
      if (j - w[i] >= 0)
        dp[i + 1][j] = max(dp[i + 1][j], v[i] + dp[i][j - w[i]]);
    }
  }
//  rep(i, n + 1) {
//    rep(j, W + 1) {
//      cout << dp[i][j] << " ";
//    }
//    cout << '\n';
//  }
  cout << dp[n][W] << '\n';
  rtn 0;
}


Measured memory_bytes: 79360
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	string s;
	cin >> s;

	rep(i,s.size()) {
		if (i == 4)cout << " ";
		 cout << s[i];
	}
	cout << endl;
	return	0;
}




Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1187&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Team 
{
	int id;
	int AC;
	int time;
	vector<int> WA;
	Team(int ID,int P):id(ID),AC(0),time(0),WA(P+1,0){}

	void accepted(int m, int p){
		AC += 1;
		time += (m + 20*WA[p]);
	}

	void wrongAnswer(int p){
		WA[p] += 1;
	}

	bool operator<( const Team& right ) const 
	{
		if(AC == right.AC)
		{
			if(time == right.time){
				return id > right.id;
			}else{
				return time < right.time;
			}
		}
		else{
			return AC > right.AC;
		}
	}
};


int main()
{
	int M,T,P,R;
	int m,t,p,j;
	while(true)
	{
		cin >> M >> T >> P >> R;
		if( !M && !T && !P && !R ){ break; }
		vector<Team> teams;
		rep(i,T){
			teams.push_back(Team(i+1,P));
		}

		rep(nth,R)
		{
			cin >> m >> t >> p >> j;
			if(j==0){
				teams[--t].accepted(m,p);
			}else{
				teams[--t].wrongAnswer(p);
			}
		}

		sort(ALL(teams));
		
		rep(i,T){
			if(i!=0){
				char sep=',';
				Team prev = teams[i-1];
				if(teams[i].AC==prev.AC && teams[i].time==prev.time){ sep='='; }
				cout << sep;
			}
			cout << teams[i].id;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                           //     #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;
                                        
                                  class pas{
                                    	public:
                                    	int x,y;
                                    	pas(int x=0,int y=0):x(x),y(y) {}
                                    	pas operator + (pas p) {return pas(x+p.x,y+p.y);}
                                    	pas operator - (pas p) {return pas(x-p.x,y-p.y);}
                                    	pas operator * (int a) {return pas(x*a,y*a);}
                                    	pas operator / (int a) {return pas(x/a,y/a);}
                                    //	double absv() {return sqrt(norm());}
                                    	int norm() {return x*x+y*y;}
                                    	bool operator < (const pas &p) const{
                                    		return x != p.x ? x<p.x: y<p.y;
                                    	}
                                    	bool operator == (const pas &p) const{
                                    		return x==p.x && y==p.y;
                                    	}
                                    };
int a[60]={0};
           signed main(){
   int n,l;
           	cin>>n>>l;
           	cout<<n*n-l<<endl;
           }
             

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

#define MAX 500000

struct Node
{
	int key;
	Node *parent, *left, *right;
public:
	Node() { parent = left = right = NULL; }
};

Node *root;

void insert(int u)
{
	Node *y = NULL;
	Node *x = root;
	Node *z = new Node();
	z->key = u;
	//?????????????????§?§????
	while (x != NULL) {
		y = x;
		if (z->key < x->key)
			x = x->left;
		else x = x->right;
	}
	z->parent = y;

	//?????????????????????????????\
	if (y == NULL) root = z;
	else if (z->key < y->key) y->left = z;
	else y->right = z;
}

void Preorder(Node *u)
{
	if (u == NULL) return;
	printf(" %d", u->key);
	Preorder(u->left);
    Preorder(u->right);
}

void Inorder(Node *u)
{
	if (u == NULL) return;
	Inorder(u->left);
	printf(" %d", u->key);
	Inorder(u->right);
}

int main()
{
	int n;
	scanf("%d", &n);

	char order[20];
	int z;
	for (int i = 0; i < n; i++) {
		scanf("%s", order);
		switch (order[0])
		{
		case 'i':
			scanf("%d", &z);
			insert(z);
			break;
		case 'p':
			Inorder(root);
			printf("\n");
			Preorder(root);
			printf("\n");
			break;
		default:
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 24468
//Trained?

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    int N;cin >> N;
    vector<int> a(N);
    rep(i,0,N)cin >> a[i];
    bool flag = false;
    map<int,int> mmp{};
    rep(i,0,N){
        mmp[i+1]=a[i];
        if(a[i]==2)flag = true;
    }
    int c = 1,cc, Ans = 0;
    while(flag){
        cc = c;
        c = mmp[c];
        if(c==0){flag=false;break;}
        mmp[cc] = 0;
        Ans++;
        if(c==2)break;
    }
    if(!flag)cout << "-1" << endl;
    else cout << Ans << endl;
    return 0;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    cout << ((N % K) ? 1 : 0) << endl; 
    return 0;
}

Measured memory_bytes: 256
H, W, A, B = map(int, input().split())

# if A > W/2 or B > H/2:
#     print('No')
#     exit()

for i in range(H):
    if i < B:
        print('0'*(W-A)+'1'*A)
    else:
        print('1'*(W-A)+'0'*A)


Measured memory_bytes: 39920
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
	int a,b,c,d;
	string s;
	cin >> a >> b >>c >> d;
	if(a!=c){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
from collections import deque
S = list(input())
S = deque(S)
Q = int(input())
c = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0]) == 1:
        if c == 0:
            c = 1
        else:
            c = 0
    else:
        if c == 0:
            if int(q[1]) == 1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1]) == 2:
                S.appendleft(q[2])
            else:
                S.append(q[2])
S = list(S)
if c == 0:
    print("".join(S))
else:
    S = S[::-1]
    print("".join(S))


Measured memory_bytes: 10084
DBG = !true

def ufinit(n)
  $ufsz = Array.new(n,1)
  $ufances = Array.new(n)
  for i in 0...n
    $ufances[i] = i
  end
end

def ufroot(x)
  a = []
  y = x
  while $ufances[y] != y
    a << y
    y = $ufances[y]
  end
  for z in a
    $ufances[z] = y
  end
  return y
end

def ufconn(x,y)
  i = ufroot(x)
  j = ufroot(y)
  return if i==j
  k  = [i,j].min
  if i>j
    $ufances[i] = j
  else
    $ufances[j] = i
  end
  $ufsz[k] = $ufsz[i] + $ufsz[j]
end

# # #

n,m = gets.split.map{|z| z.to_i}
a = []
b = []
for i in 0...m
  aa,bb = gets.split.map{|z| z.to_i}
  a << aa-1
  b << bb-1
end


ufinit(n)
sum = n*(n-1)/2
ans = Array.new(n)
ans[m-1] = sum
if DBG
  print a
  puts " - a"
  print b
  puts " - b"
  print $dboss
  puts " - dboss"
end
(m-1).downto(1) { |z|
  x = a[z]
  y = b[z]  # x<y
  i = ufroot(x)
  j = ufroot(y)
  if i==j
    ans[z-1] = sum
    next
  end
  p = $ufsz[i]
  q = $ufsz[j]
  sum -= ((p+q)*(p+q-1)-p*(p-1)-q*(q-1))/2 if sum > 0
  ufconn(x,y)
  ans[z-1] = sum
}
for i in 0...m
  puts "#{ans[i]}"
end
#puts ""


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

void solve() {
	map<char, string> player;
	for (char ch = 'A'; ch <= 'C'; ch++) {
		string s; cin >> s;
		player[ch] = s;
	}

	int i = 1, j = 0, k = 0;
	char tmp = player['A'][0];
	while (true) {
		if (tmp == 'a') {
			if (player['A'].size() == i) {
				cout << "A" << endl;
				break;
			}
			tmp = player['A'][i];
			i++;
		}
		else if (tmp == 'b') {
			if (player['B'].size() == j) {
				cout << "B" << endl;
				break;
			}
			tmp = player['B'][j];
			j++;
		}
		else {
			if (player['C'].size() == k) {
				cout << "C" << endl;
				break;
			}
			tmp = player['C'][k];
			k++;
		}
	}
}

int main(void) {
	solve();

	return 0;
}

Measured memory_bytes: 256
A=list(map(int,input().split()))
a=A[0]
b=A[1]
c=A[2]
d=A[3]
if abs(a-c) <= d:
  print("Yes")
elif (abs(a-b) <= d) & (abs(b-c) <= d):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
from fractions import gcd
 
def gcdL(L):
    g=L[0]
    for i in range(1,len(L)):
        if g==1:
            return(g)
        g=gcd(g,L[i])
    return g
def play(A,i):
    A[i]-=1
    g=gcdL(A)
    return [x//g for x in A]
def cnt(A):
    odd,even=0,0
    for a in A:
        if a%2:
            odd+=1
        else:
            even+=1
    return odd,even    

n=int(input())
A=list(map(int,input().split()))
First=1
while True:
    odd,even=cnt(A)
    if even%2:
        print('First' if First else 'Second')
        break
    elif odd>1:
        print('Second' if First else 'First')
        break
    else:
        for i in range(n):
            if A[i]%2:
                break
        if A[i]==1:
            print('Second' if First else 'First')
            break
        else:
            A=play(A,i)
            First^=1

Measured memory_bytes: 108688
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int N,M,K;
class union_find{//union by rank
public:
	vector<int> par;
    vector<int> sub;
	union_find(int n):par(n),sub(n){
		rep(i,0,n){ par[i]=i; sub[i]=1; }
	}
	int root(int v){
		if(par[v]==v) return v;
		else{ par[v]=root(par[v]); return par[v]; }
	}
	void unite(int x,int y){
		int a=root(x);
		int b=root(y); 
		if(a==b) return;
		if(sub[a]<sub[b]) swap(x,y);
		par[b]=a;
		sub[a]+=sub[b];
		return;
	}
	bool same(int x,int y){
		return root(x)==root(y);
	}
};
int main(){
	cin>>N>>M>>K;
	union_find uf(N);
	set<int> g[N];
	int a,b;
	rep(i,0,M){
		cin>>a>>b; a--; b--;
		uf.unite(a,b);
		g[a].insert(b);
		g[b].insert(a);
	}rep(i,0,K){
		cin>>a>>b; a--; b--;
		g[a].insert(b);
		g[b].insert(a);
	}
	rep(i,0,N){
		int cnt = uf.sub[uf.root(i)] - 1;
		for(int j:g[i]){
			if(uf.root(i)==uf.root(j)) cnt--;
		}
		cout<<(i ? " ":"")<<cnt;
	}cout<<endl;
}

Measured memory_bytes: 25856
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 300005
#define MOD 1000000007
#define INF 1000000000000000000
#define EPS 0.0000000001
#define CHAINS 18
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
long long int fact[MAX+1],fact_inv[MAX+1];
long long int gcd(long long int a,long long int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
long long int egcd(long long int a, long long int b, long long int & x, long long int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    long long int x1, y1;
    long long int d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
long long int ModuloInverse(long long int a,long long int n)
{
    long long int x,y;
    x=gcd(a,n);
    a=a/x;
    n=n/x;
    long long int res = egcd(a,n,x,y);
    x=(x%n+n)%n;
    return x;
}
void precal()
{
    int i;
    fact[0]=fact_inv[0]=1;
    for(i=1;i<=MAX;i++)
    {
        fact[i]=(fact[i-1]*i)%MOD;

    }
    i=MAX;
    fact_inv[i]=ModuloInverse(fact[i],MOD);
    for(i=MAX-1;i>0;i--)
    {
        fact_inv[i]=(fact_inv[i+1]*(i+1))%MOD;
    }
}
long long int C(int n,int r)
{
    long long int res=fact[n];
    res=(res*fact_inv[n-r])%MOD;
    res=(res*fact_inv[r])%MOD;
    return res;
}
int main()
{
    precal();
    int N,i;
    scanf("%d",&N);
    long long temp,ans=0;
    for(i=1;i*3<=N;i++)
    {
        temp=C(N-i*3+i-1,i-1);
        ans=(ans+temp)%MOD;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 8452
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int d = sc.nextInt();
        int cnt = 0;
        if (d < 22) {
            System.out.println(0);
            return;
        }
        for (int i = 1; i <= m; i++) {
            for (int j = 22; j <= d; j++) {
                if (j / 10 < 2 || j % 10 < 2) {
                    continue;
                }
                if ((j / 10) * (j % 10) == i) {
                    cnt++;
                }
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int h,a,c=0;
    h=in.nextInt();
    a=in.nextInt();
    while(h>0)
    {
      h=h-a;
      c=c+1;
    }
    System.out.println(c);
  }
}


Measured memory_bytes: 23764
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt(), B=sc.nextInt(),
		    C=sc.nextInt(), D=sc.nextInt();
	    int s, n;
	    
	    s = A*B;
	    n = C*D;
	    
	    if(s>n){
	        System.out.println(s);
	    }
	    
	    else if(n>s){
	    	 System.out.println(n);
	    }
	    
	    else{
	    	 System.out.println(A*B);
	    }
	    }

	}


Measured memory_bytes: 21844
n = int(input())
t = [int(input()) for i in range(n)]
p = 0
q = 0
l = [0]
r = [0]

for i in range(1,n):
    if p < t[i-1]:
        p = t[i-1]
        l.append(p)
    else:
        l.append(p)
    
    if q < t[-i]:
        q = t[-i]
        r.append(q)
    else:
        r.append(q)

for i in range(n):
    print(max(l[i], r[-(i+1)]))

Measured memory_bytes: 15660
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
  int A, B;
  char op;
  cin >> A >> op >> B;

  if(op == '+'){
    cout << A + B << endl;
  }else{
    cout << A - B << endl;
  }

  return 0;
}


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

ll ketawa(ll n) {   // nの各桁の数の和
    ll res = 0;    
    while(n != 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

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

    if(n%ketawa(n) == 0) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstdlib>

using namespace std;

struct S{
  int b,p,c;
  bool operator<(S s)const{
    return c>s.c;
  }
};

int main(){
  for(int N;cin>>N,N;){
    char p[2][17];
    cin>>p[0]>>p[1];
    int b=0;
    for(int i=0;i<N;i++){
      b|=(p[0][i]!=p[1][i])<<i;
    }
    priority_queue<S> que;
    for(int i=0;i<N;i++){
      que.push({b,i,0});
    }
    bool u[1<<16][16]={};
    for(;;){
      S cs=que.top();
      if(cs.b==0)break;
      que.pop();
      if(u[cs.b][cs.p]++)continue;
      for(int i=0;i<N;i++){
	if(cs.b>>i&1){
	  for(int j=0;j<N;j++){
	    if(cs.b>>j&1&&p[0][i]!=p[0][j]){
	      que.push({cs.b^1<<i^1<<j,j,cs.c+abs(cs.p-i)+abs(i-j)});
	    }
	  }
	}
      }
    }
    cout<<que.top().c<<endl;
  }
}

Measured memory_bytes: 45644
from sys import stdin
import math
import itertools
import copy


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    a = makeMultiInteger(input_string[0])
    _max = 0
    two = copy.deepcopy(a)
    c = two[0]
    two[0] -= 1
    c += two[0]
    two[0] -= 1
    if _max < c:
        _max = c

    two = copy.deepcopy(a)
    c = 0
    c = two[0]
    two[0] -= 1
    c += two[1]
    two[1] -= 1
    if _max < c:
        _max = c

    two = copy.deepcopy(a)
    c = 0
    c = two[1]
    two[1] -= 1
    c += two[1]
    two[1] -= 1
    if _max < c:
        _max = c
    return _max


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            string input = sc.str;
            char[] num_array = input.ToCharArray();
            int number = int.Parse(input);
            int sum = 0;

            for(int i=0; i<num_array.Length; i++)
            {
                sum += int.Parse(num_array[i].ToString());
            }
            int judge = number % sum;

            if(judge == 0)
            {
                wr.wri("Yes");
            }
            else
            {
                wr.wri("No");
            }
        }
    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;bool ans=true;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++)    cin>>s[i];
    for(int i=0;i<n-1;i++){
        if(s[i][s[i].size()-1]!=s[i+1][0])
        ans=false;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(s[i]==s[j])
            ans=false;
        }
    }
    if(ans) cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;
    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

ll dp[100][2];

int main(){
    int N;
    ll K; 
    cin>>N>>K;
    vector<ll> A(N);
    rep(i,N)cin>>A.at(i);

    rep(i,100)dp[i][0] = dp[i][1] = -1;
    dp[45][0] = 0;
    for(int d = 44; d >= 0; d--){
        ll mask = 1LL<<d;
        int num = 0; //d桁目の1の立ってる数
        rep(i,N)if(A[i]&mask)num++;

        if(dp[d+1][1] >= 0) dp[d][1] = max(dp[d][1],dp[d+1][1] + mask*max(num,N-num));
        if(dp[d+1][0] >= 0){
            if(K & mask){
                dp[d][1] = max(dp[d][1],dp[d+1][0]+mask*num);
                dp[d][0] = max(dp[d][0],dp[d+1][0]+mask*(N-num));
            }
            else {
                dp[d][0] = max(dp[d][0], dp[d+1][0]+mask*num);
            }
        }
    }
    cout<<max(dp[0][0],dp[0][1])<<endl;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

bool get_line( double , double , double , double , double& , double& );

int main(void)
{
	double x1, x2, x3, xp;
	double y1, y2, y3, yp;
	double a1, a2, a3, b1, b2, b3;
	bool result1 , result2 , result3;

	int flag1, flag2, flag3;
	int flag1p , flag2p , flag3p;

	while(1)
	{
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp;
		if( cin.eof() ) break;

		result1 = get_line( x1 , y1 , x2 , y2 , a1 , b1 );
		result2 = get_line( x2 , y2 , x3 , y3 , a2 , b2 );
		result3 = get_line( x3 , y3 , x1 , y1 , a3 , b3 );

		if( result1 == true )
		{
			if( y3 > a1 * x3 + b1 ) flag1 = 1;
			else flag1 = 0;
			if( yp > a1 * xp + b1 ) flag1p = 1;
			else flag1p = 0;
		}
		else
		{
			if( x3 > (x1+x2)/2 ) flag1 = 1;
			else flag1 = 0;
			if( xp > (x1+x2)/2 ) flag1p = 1;
			else flag1p = 0;
		}
		if( result2 == true )
		{
			if( y1 > a2 * x1 + b2 ) flag2 = 1;
			else flag2 = 0;
			if( yp > a2 * xp + b2 ) flag2p = 1;
			else flag2p = 0;

		}
		else
		{
			if( x1 > (x2+x3)/2 ) flag2 = 1;
			else flag2 = 0;
			if( xp > (x2+x3)/2 ) flag2p = 1;
			else flag2p = 0;
		}
		if( result3 == true )
		{
			if( y2 > a3 * x2 + b3 ) flag3 = 1;
			else flag3 = 0;
			if( yp > a3 * xp + b3 ) flag3p = 1;
			else flag3p = 0;
		}
		else
		{
			if( x2 > (x3+x1)/2 ) flag3 = 1;
			else flag3 = 0;
			if( xp > (x3+x1)/2 ) flag3p = 1;
			else flag3p = 0;
		}

		if( flag1 == flag1p && flag2 == flag2p && flag3 == flag3p ) cout << "YES" << endl;
		else cout << "NO" << endl;
	}


	return 0;
}

bool get_line( double x1 , double y1 , double x2 , double y2 , double& a , double& b )
{
	if( x1 - x2 >= -0.0001 && x1 - x2 <= 0.0001 )
	{
		return false;
	}
	else
	{
		a = ( y1 - y2 )/( x1 - x2 );
		b = y1 - a * x1;

		return true;
	}
}

Measured memory_bytes: 1216
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

_int64 a[60];

int main()
{
  _int64 i,j,n,k,tmp;
  n=50;
  scanf("%lld",&k);
  if (k==0)
  {
    printf("2\n");
    printf("1 1\n");
    return 0;
  }
  tmp=(k-1)/50+1;
  for (i=0;i<n;i++)
    a[i]=(n-1)+tmp;
  for (i=0;i<tmp*50-k;i++)
  {
    a[i]-=n;
    for (j=0;j<n;j++)
      if (j!=i) a[j]++;
  }
  printf("%lld\n",n);
  for (i=0;i<n;i++)
  {
    if (i!=0) printf(" ");
    printf("%lld",a[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val c = sc.next()
  val wc = c.scanLeft(0){case (x, c) => if (c == 'W') x+1 else x}
  val rc = c.scanRight(0){case (c, x) => if (c == 'R') x+1 else x}
  val ans = wc.zip(rc).map{ case (w, r) =>
    w.max(r)
  }.min
  println(ans)
}


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

int main(){
    int N, K;
    cin >> N >> K;
    int R, S, P;
    char T[N];
    cin >> R >> S >> P;
    cin >> T;
    
    bool used[N];
    
    int r_num = 0;
    int s_num = 0;
    int p_num = 0;
    for ( int i = 0; i < N; ++i){
        if ( i < K ) {
            if ( T[i] == 'r' ){
                r_num += 1;
                used[i] = true;
            } else if ( T[i] == 's') {
                s_num += 1;
                used[i] = true;
            } else {
                p_num += 1;
                used[i] = true;
            }
        } else {
            if ( T[i] == 'r' ){
                if ( T[i-K] != 'r' or ( T[i-K] == 'r' and used[i-K] == false ) ) {
                    r_num += 1;
                    used[i] = true;
                } else {
                    used[i] = false;
                }
            } else if ( T[i] == 's') {
                if ( T[i-K] != 's' or ( T[i-K] == 's' and used[i-K] == false ) ) {
                    s_num += 1;
                    used[i] = true;
                } else {
                    used[i] = false;
                }
            } else {
                if ( T[i-K] != 'p' or ( T[i-K] == 'p' and used[i-K] == false ) ) {
                    p_num += 1;
                    used[i] = true;
                } else {
                    used[i] = false;
                }
            }
        }
    }
    int ans = 0;
    ans = P * r_num + R * s_num + S * p_num;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int a[3005],x,y,n;vector<int>e[3005];
int dfs(int x,int fa)
{
	for(int i=0;i<e[x].size();i++) if(e[x][i]!=fa&&a[x]>a[e[x][i]]&&!dfs(e[x][i],x)) return 1;
	return 0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<n;i++) scanf("%d%d",&x,&y),e[x].push_back(y),e[y].push_back(x);
	for(int i=1;i<=n;i++) if(dfs(i,0)) printf("%d ",i);
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int t[] = new int[n];
        int m = 0;
        int s = 0;

        for (int i = 0; i < n; i++) {
            t[i] = scan.nextInt();
        }

        for (int l = 0; l < n; l++) {
            if (m < l * 10) {
                s = 1;
            }
            if (m < l * 10 + t[l]) {
                m = l * 10 + t[l];
            }
        }
        if (s == 1) {
            System.out.println("no");
        } else {
            m = 0;
            for (int i = 0; i < n; i++) {
                if (m < i * 10) {
                    s = 1;
                }
                if (m < i * 10 + t[n - 1 - i]) {
                    m = i * 10 + t[n - 1 - i];
                }
            }
            if (s == 1) {
                System.out.println("no");
            } else {
                System.out.println("yes");
            }
        }
    }
}



Measured memory_bytes: 104800
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int nxt[100005][26];
int tmp[26];
int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  string S, T;
  cin >> S >> T;
  int s = S.length(), t = T.length();
  S = "?" + S;
  FORD(i, s, 1) {
    memcpy(nxt[i], tmp, sizeof(tmp));
    int x = S[i] - 'a';
    tmp[x] = i;
  }
  FOR(i, 1, s) FOR(j, 0, 25) if (!nxt[i][j]) nxt[i][j] = tmp[j];
  ll cnt = 0;
  int p = 0;
  FOR(i, 0, t - 1) {
    int x = T[i] - 'a';
    if (!i) p = tmp[x], cnt += p;
    else {
      int np = nxt[p][x];
      if (np <= p) cnt += s - p + np;
      else cnt += np - p;
      p = np;
    }
    if (!p) {
      printf("-1\n"); return 0;
    }
  }
  printf("%lld\n", cnt);
  return 0;
}

Measured memory_bytes: 10604
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define pb(x) push_back(x)
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)

/*struct comp
{
    bool operator()()
    {
        
    }
};*/
struct node
{
    int idx,a,b,c;
    node(int i,int A,int B,int C)
    {
        idx=i;a=A;b=B;c=C;
    }
};
int N,A,B,C;
vector<string> S;
vector<int>ANS;
bool flag=false;
set<pair<int,pair<int,pair<int,int> > > >MAP;
void call(int idx,int a,int b,int c)
{
    //cout<<idx<<" "<<a<<" "<<b<<" "<<c<<endl; MAP;
    if(idx==N) {flag=true;return;}
    pair<int,pair<int,pair<int,int> > > temp=mp(idx,mp(a,mp(b,c)));
    
    if(MAP.find(temp)!=MAP.end())
    {
        return;
    }
    if(S[idx]=="AB")
    {
        if(b>0)
        {
            ANS.pb(1);
            call(idx+1,a+1,b-1,c);
            if(flag) return;
            ANS.pop_back();
        }
        if(a>0)
        {
            ANS.pb(2);
            call(idx+1,a-1,b+1,c);
            if(flag) return;
            ANS.pop_back();
        }
    }
    
    else if(S[idx]=="BC")
    {
        if(c>0)
        {
            ANS.pb(1);
            call(idx+1,a,b+1,c-1);
            if(flag) return;
            ANS.pop_back();
        }
        if(b>0)
        {
            ANS.pb(2);
            call(idx+1,a,b-1,c+1);
            if(flag) return;
            ANS.pop_back();
        }
    }
    
    else if(S[idx]=="AC")
    {
        if(c>0)
        {
            ANS.pb(1);
            call(idx+1,a+1,b,c-1);
            if(flag) return;
            ANS.pop_back();
        }
        if(a>0)
        {
            ANS.pb(2);
            call(idx+1,a-1,b,c+1);
            if(flag) return;
            ANS.pop_back();
        }
    }
    MAP.insert(temp);
    return;
}
int32_t main() {
    int t=1;
    //cin>>t;
    while(t--)
    {
    
     cin>>N>>A>>B>>C;
     for(int i=0;i<N;i++)
     {
         string s;
         cin>>s;
         S.pb(s);
     }
     flag=false;
     call(0,A,B,C);
     if(flag==false) 
        {
            cout<<"No";return 0;
        }
    cout<<"Yes\n";
    for(int i=0;i<ANS.size();i++)
    {
        if(ANS[i]==1)
        {
            cout<<S[i][0]<<endl;
        }
        else
        {
            cout<<S[i][1]<<endl;
        }
    }
    

    }
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, Q;
  string S;
  cin >> N >> S >> Q;
  vector<set<int>> V(26);
  for (int i = 0; i < N; i++) {
    V.at(S.at(i) - 'a').insert(i);
  }
  while (Q--) {
    int q;
    cin >> q;
    if (q == 1) {
      int a;
      char c;
      cin >> a >> c;
      a--;
      int now = c - 'a';
      int pre = S.at(a) - 'a';
      V.at(pre).erase(a);
      V.at(now).insert(a);
      S.at(a) = c;
    } else {
      int a, b;
      cin >> a >> b;
      a--, b--;
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        auto it1 = V.at(i).lower_bound(a);
        if (it1 == V.at(i).end()) continue;
        auto it2 = V.at(i).upper_bound(b);
        if (it1 != it2) cnt++;
      }
      cout << cnt << "\n";
    }
  }
}

Measured memory_bytes: 27232
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int parent[30][100005];//parent[i][j]:jの2^i親の場所
int d[100005],depth[100005];//根からの距離,根からの深さ
int lca(int u,int v){//共通の直近の親を伝える
  if(depth[u]>depth[v])swap(u,v);
  int U=u,V=v;
  int diff=depth[v]-depth[u];
  int cnt=0;
  while(diff){
    if(diff&1)v=parent[cnt][v];
    cnt++;
    diff>>=1;
  }
  if(u==v)return u;
  int high=25,low=-1;
  for(int k=25;k>=0;k--)if(parent[k][u]!=parent[k][v])u=parent[k][u],v=parent[k][v];
  return parent[0][u];
}
//main
signed main(){
  int N,Q;cin>>N>>Q;
  typedef pair<int,int> P;
  typedef pair<int,P> PP;
  std::vector<PP> edge[N];//行き先、色、長さ
  for(int i=1;i<N;i++){
    int u,v,c,d;cin>>u>>v>>c>>d;u--;v--;
    edge[u].push_back(PP(v,P(c,d)));
    edge[v].push_back(PP(u,P(c,d)));
  }
  //ここからdを作る
  std::vector<PP> ed[N],ged[N];//根付き木として見た時に下に降りる辺と上に上がる辺に分ける
  queue<int> que;
  std::vector<int> used(N,0);
  que.push(0);d[0]=0;depth[0]=0;
  while(que.size()){
    int p=que.front();que.pop();
    if(used[p])continue;used[p]++;
    for(auto q:edge[p]){
      int u=q.first,c=q.second.first,l=q.second.second;
      if(used[u])ged[p].push_back(PP(u,P(-c,-l)));
      else{
        ed[p].push_back(q);
        d[u]=d[p]+l;
        que.push(u);
        depth[u]=depth[p]+1;
      }
    }
  }
  //ここまでdを作った
  //ここからparentを作る
  memset(parent,-1,sizeof(parent));
  for(int i=0;i<N;i++)for(auto q:ged[i])parent[0][i]=q.first;
  for(int i=1;i<30;i++)
    for(int j=0;j<N;j++)
      if(parent[i-1][j]>=0)parent[i][j]=parent[i-1][parent[i-1][j]];
  //ここまでparentを作った
  std::vector<int> qu[N],x(Q),y(Q),u(Q),v(Q);
  for(int i=0;i<Q;i++){
    cin>>x[i]>>y[i]>>u[i]>>v[i];u[i]--;v[i]--;
    qu[u[i]].push_back(x[i]);
    qu[v[i]].push_back(x[i]);
    qu[lca(u[i],v[i])].push_back(x[i]);
  }
  std::vector<int> cnum(N,0),clong(N,0);//色iの今の個数と距離の合計
  stack<PP> sta;
  map<P,P> ma;//ma[P(i,j)]:頂点iの色jの個数と距離
  sta.push(PP(0,P(0,-1)));
  fill(used.begin(),used.end(),0);
  while(sta.size()){
    PP statop=sta.top();sta.pop();
    int p=statop.first,colo=statop.second.first,lon=statop.second.second;
    if(colo){
      if(colo>0)cnum[colo]++;
      else cnum[-colo]--;
      clong[abs(colo)]+=lon;
    }
    if(used[p]==0){
      for(auto qco:qu[p])ma[P(p,qco)]=P(cnum[qco],clong[qco]);//初めて来たならmapに書き込み
      for(auto rev:ged[p])sta.push(rev);//初めて来たなら辺を張る
      for(auto nonrev:ed[p])sta.push(nonrev);
    }
    used[p]++;
  }
  for(int i=0;i<Q;i++){
    int du=d[u[i]]-ma[P(u[i],x[i])].second+ma[P(u[i],x[i])].first*y[i];
    int dv=d[v[i]]-ma[P(v[i],x[i])].second+ma[P(v[i],x[i])].first*y[i];
    int w=lca(u[i],v[i]);
    int dw=d[w]-ma[P(w,x[i])].second+ma[P(w,x[i])].first*y[i];
    cout<<du+dv-2*dw<<endl;
  }
}


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

void swap(int *a, int *b)
{
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

int main(){
  int yakusuu;
  int x, y;
  int amari;

  cin >> x >> y;
  
  if(x == y)
    {
      printf("%d\n", x);
      return 0;
    }
  
  if(x < y)
    {
      swap(&x, &y);
    }
  
  amari = x % y;
  yakusuu = floor(amari / 2);
  
  do
    {
      if((x % yakusuu) == 0)
	{
	  if((y % yakusuu) == 0)
	    {
	      break;
	    }
	}
      yakusuu--;
    }while (yakusuu > 1);
  
  cout << yakusuu << endl;
  
  return 0;
}



Measured memory_bytes: 3088