akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[MAXn];
int main(){
  IOS();
  ll n,m;
  cin >> n >> m;
  REP (i,m) {
    ll u,v;
    cin >> u >> v;
    u--,v--;
    d[u]++, d[v]++;
  }
  bool ok = true;
  REP (i,n) if (d[i]&1) ok = false;
  if (ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

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

int lcm(int a,int b) {
  return (a/gcd(a,b))*b;
}


int main() {
  int a,b;
  while(cin >> a >> b) {
    cout << gcd(a,b) << " " << lcm(a,b) << endl;
  }
}

Measured memory_bytes: 3072
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#define ll long long
using namespace std;
const int maxn=200005;
int n,L ;
struct node
{
	ll id;
	ll A,B;
}a[maxn];
bool cmp(node x,node y)
{
	if(x.B==y.B)
		return x.A<y.A;
	return x.B<y.B;
}
int main()
{
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++)
	{
		cin>>a[i].A>>a[i].B;
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	ll t=0;
	int k=0;
	for(int i=0;i<=1454;i++)
        k+=i;
	for(int i=1;i<=n;i++)
	{
		if(t+a[i].A<=a[i].B)
		{
			t+=a[i].A;
		}
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>

int f(int k, int a, int b, int c)
{
    if (k == 0) {
        return a + b + c;
    }

    int t1 = f(k-1, a * 2, b, c);
    int t2 = f(k-1, a, b * 2, c);
    int t3 = f(k-1, a, b, c * 2);

    return std::max({t1, t2, t3});
}

int main()
{
    int a, b, c, k;
    std::cin >> a >> b >> c >> k;

    std::cout << f(k, a, b, c) << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main(){
	int n;
	while(cin>>n){
		int ans = 0;
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				for (int k = 0; k < 10; k++)
				{
					if(n - (i+j+k) >= 0 && n - (i+j+k) <= 9)
						ans++;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

short dp[11][1<<10][341];
short ans[11][341];
int main(){
	dp[0][0][0] = 1;
	for(int i = 0 ; i < 10 ; i++){
		for(int j = 0 ; j < (1<<10) ; j++){
			for(int c = 0 ; c < 331 ; c++){
				if(dp[i][j][c] == 0 ) continue;
				for(int k = 0 ; k < 10 ; k++){
					if(!(j>>k&1)){
						dp[i+1][j|(1<<k)][(i+1)*k+c] += dp[i][j][c];
					}
				}
			}
		}
	}
	/*cout << dp[1][2][2] << endl;*/
	for(int i = 0 ; i < 11 ; i++){
		for(int j = 0 ; j < (1<<10) ; j++){
			for(int c = 0 ; c < 331 ; c++){
				ans[i][c] += dp[i][j][c];
			}
		}
	}
	int n,s;
	
	while(~scanf("%d%d",&n,&s)){
		if(n > 10 || s > 330){
			cout << 0 << endl;
		}else{
			cout << ans[n][s] << endl;
		}
	}
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

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

  if (n == 1) {
    cout << "Yes" << endl;
    cout << 2 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 1 << " " << 1 << endl;
    return 0;
  }
  if (n == 2) {
    cout << "No" << endl;
    return 0;
  }

  int k = 0;
  FOR(i,3,450) {
    if (n == i*(i-1)/2) {
      k = i;
      break;
    }
  }
  if(k == 0) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  cout << k << endl;

  int s[500][500];

  int c = 1;
  REP(i,k) {
    REP(j,k-1) {
      if(i > j) {
        s[i][j] = s[j][i-1];
      } else {
        s[i][j] = c;
        c++;
      }
    }
  }

  REP(i,k) {
    cout << k-1;
    REP(j,k-1) {
      cout << " " << s[i][j];
    }
    cout << endl;
  }
}


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

int main() {
  int n; cin >> n;
  vector<string> S(n);
  for (int i = 0; i < n; i++) cin >> S[i];
  
  vector<int> a(26,100);
  for (int i = 0; i < n; i++) {
    vector<int> count(26,0);
    for (int j = 0; j < S[i].size(); j++) {
      count[S[i][j]-'a']++;
    }
    for (int j = 0; j < 26; j++) {
      a[j] = min(a[j],count[j]);
    }
  }
  string s;
  for (int i = 0; i < 26; i++) {
    while (a[i] > 0) {
      s = s + char(i + 'a');
      a[i]--;
    }
  }
  
  cout << s << endl;
}


Measured memory_bytes: 256
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

int main(void)
{
    string S;
    int K;
    cin >> K;
    cin >> S;
    if (S.size() <= K)
        cout << S << endl;
    else
        cout << S.substr(0, K) + "..." << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
        int heights[10];
        for (int i = 0; i < 10; i++){
                cin>>heights[i];
        }
        int t3[3];
        for (int i = 0; i < 3; i++){
                t3[i]=0;
        }
        for (int i = 0; i < 10; i++){
                if(heights[i] > t3[0]){
                        t3[2] = t3[1];
                        t3[1] = t3[0];
                        t3[0] = heights[i];
                }else if (heights[i] > t3[1]){
                        t3[2] = t3[1];
                        t3[1] = heights[i];
                }else if (heights [i] > t3[2]){
                        t3[2] = heights[i];
                }
        }
        for (int i = 0; i < 3; i++){
                cout<<t3[i]<<"\n";
        }
        return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;



int main() {
	
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int ans=0;
	int mxy = (x >= y) ? x : y, mixy = x + y - mxy;
	
	if (mixy == x && (a*mixy + b * mixy < 2 * c*mixy)) {
		ans += (a + b)*mixy+b*(mxy-mixy);
	}
	else if (mixy == y && (a*mixy + b * mixy < 2 * c*mixy)) {
		ans += (a + b)*mixy + a * (mxy- mixy);
	}
	else {
		ans += 2 * c*mixy;
		if(mixy == x&& 2*c > b){
			ans += (mxy - mixy)*b;
		}
		else if (mixy == y && 2 * c > a) {
			ans += (mxy - mixy)*a;
		}
		else {
			ans += 2 * c*(mxy - mixy);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
warp = list(map(int, input().split()))
warp = [i - 1 for i in warp]

visit = [0]

current_loc = 0
while warp[current_loc] != -1:
  visit.append(warp[current_loc])
  warp[current_loc] = -1
  current_loc = visit[-1]

res = visit.index(visit[-1])
cycle = visit[res + 1:]
if K <= res:
  print(visit[K] + 1)
else:
  answer = cycle[(K - res - 1) % (len(visit) - 1 - res)] + 1
  print(answer)

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

const long long mod=1000000007LL;

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	int n=s.size();
	long long dp[n+5][4]={};
	dp[0][0]=1LL;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			dp[i+1][j]=dp[i][j];
		}
		if (s[i]=='A')
		{
			dp[i+1][1]+=dp[i][0];
			dp[i+1][1]%=mod;
		}
		else if (s[i]=='B')
		{
			dp[i+1][2]+=dp[i][1];
			dp[i+1][2]%=mod;
		}
		else if (s[i]=='C')
		{
			dp[i+1][3]+=dp[i][2];
			dp[i+1][3]%=mod;
		}
		else
		{
			dp[i+1][0]+=2*dp[i][0];
			dp[i+1][0]%=mod;
			dp[i+1][1]+=dp[i][0];
			dp[i+1][1]+=2*dp[i][1];
			dp[i+1][1]%=mod;
			dp[i+1][2]+=dp[i][1];
			dp[i+1][2]+=2*dp[i][2];
			dp[i+1][2]%=mod;
			dp[i+1][3]+=dp[i][2];
			dp[i+1][3]+=2*dp[i][3];
			dp[i+1][3]%=mod;
		}
	}
	cout<<dp[n][3]<<endl;
	return 0;
}


Measured memory_bytes: 3584
N=int(input())
A=list(map(int,input().split()))
TMP=sum(A)
Q=int(input())
import collections
List=collections.Counter(A)
for i in range(Q):
  S,T=map(int,input().split())  
  TMP=TMP+(T-S)*List[S]
  print(TMP)  
  List[T]+=List[S]
  List[S]=0

Measured memory_bytes: 23852
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

struct Node{
	long key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(long k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = new Node;
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL){
		y = x;
		if (z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent = y;

	if (y == NIL) root = z;
	else {
		if (z->key < y->key) y->left = z;
		else y->right = z;
	}
}

void inorder(Node *u){
	if (u == NIL) return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}

void preorder(Node *u){
	if (u == NIL) return;
	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}

int main(){
	long n, x;
	string com;
	cin >> n;
	for (long i = 0; i < n; i++){
		cin >> com;
		if (com == "insert"){
			cin >> x;
			insert(x);
		}
		else if (com == "print"){
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 24648
#include <stdio.h>

int main(void)
{
	int n;
	int customer[10000];
	int i;
	int flag;
	int buf;
	int time[10000];
	long long total;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		for (i = 0; i < n; i++){
			scanf("%d", &customer[i]);
		}
		
		/*昇順にソート*/
		flag = 1;
		while (flag == 1){
			flag = 0;
			for (i = 0; i < n - 1; i++){
				if (customer[i] > customer[i + 1]){
					buf = customer[i];
					customer[i] = customer[i + 1];
					customer[i + 1] = buf;
					flag = 1;
				}
			}
		}
		
		
		for (i = 0; i < n; i++){
			time[i] = 0;
		}
		
		total = 0;
		for (i = 0; i < n; i++){
			if (i != 0){
				time[i] = time[i - 1] + customer[i - 1];
				total += time[i];
			}
			/*printf("%d %d\n", customer[i], time[i]);*/
		}
		
		
		printf("%lld\n", total);
	}
	
	return (0);
}

Measured memory_bytes: 676
#!/usr/bin/env python3
import sys


def solve(x: int, a: int, b: int):
    abs_a = abs(x - a)
    abs_b = abs(x - b)

    if abs_a < abs_b:
        print('A')
    else:
        print('B')

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(x, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long 
using namespace std;
const int maxn = 57;
 
int n, m, s, u[maxn * 2], v[maxn * 2], a[maxn * 2], b[maxn * 2], c[maxn], d[maxn], ans[maxn];
int dist[maxn][maxn * maxn], ok[maxn][maxn * maxn];
vector<int> vt[maxn];
priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
 
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    fill_n(&dist[0][0], maxn * maxn * maxn, 1e18);
    cin >> n >> m >> s;
    for(int i = 1; i <= m; i++)
    {
        cin >> u[i] >> v[i] >> a[i] >> b[i];
        vt[u[i]].push_back(i);
        vt[v[i]].push_back(i);
    }
    for(int i = 1; i <= n; i++)
    {
        cin >> c[i] >> d[i];
        ans[i] = 1e18;
    }
    s = min(s, 50 * 50ll);
    pq.emplace(0, 1, s);
    dist[1][s] = 0;
    while(pq.size())
    {
        auto it = pq.top();
        pq.pop();
        int di = get<0>(it);
        int id = get<1>(it);
        int cost = get<2>(it);
        assert(cost <= 50 * 50);
        if(di != dist[id][cost]) continue;
        if(ok[id][cost]) continue;
        ok[id][cost] = 1;
        ans[id] = min(ans[id], dist[id][cost]);
        for(int j = 1;; j++)
        {
            if(cost + j * c[id] > 50 * 50)
            {
                if(dist[id][50 * 50] > dist[id][cost] + j * d[id])
                {
                    dist[id][50 * 50] = dist[id][cost] + j * d[id];
                    pq.emplace(dist[id][50 * 50], id, 50 * 50);
                }
                break;
            }
            else
            if(dist[id][cost + j * c[id]] > dist[id][cost] + j * d[id])
            {
                dist[id][cost + j * c[id]] = dist[id][cost] + j * d[id];
                pq.emplace(dist[id][cost + j * c[id]], id, cost + j * c[id]);
            }
        }
        for(auto j: vt[id])
        {
            int v = ::u[j] + ::v[j] - id;
            if(cost >= a[j])
            {
                if(dist[v][cost - a[j]] > dist[id][cost] + b[j])
                {
                    dist[v][cost - a[j]] = dist[id][cost] + b[j];
                    pq.emplace(dist[v][cost - a[j]], v, cost - a[j]);
                }
            }
        }
    }
    for(int i = 2; i <= n; i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 103168
#include <iostream>
using namespace std;
int A[10101];
int main(){
	int n;
	cin >> n;
	for(int i = 1 ; i <= 100 ; ++ i)
		for(int j = 1 ; j <= 100 ; ++ j)
			for(int k = 1 ; k <= 100 ; ++ k){
				int w = i * i + j * j + k * k + i * j + j * k + k * i;
				if(w <= n)
					A[w] ++;
			}
	for(int i = 1 ; i <= n ; ++ i)
		cout << A[i] << endl;
	return 0;
}

Measured memory_bytes: 3528
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (ll i = 0;i < (a);++i)
#define FOR(i,a,b) for (ll i = (a);i < (b); ++i)
#define FORR(i,a,b) for (ll i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n,k;
    cin >> n >> k;
    ll answer = 0;

    ll min_sum = 0,max_sum = 0;
    REP(j,k-1){
        min_sum=(min_sum+j)%MOD;
    }
    FORR(j,n,n-k+2){
        max_sum=(max_sum+j)%MOD;
    }
    FOR(i,k,n+2){
        min_sum=(min_sum+(i-1))%MOD;
        max_sum=(max_sum+(n-i+1))%MOD;
        answer = (answer+(max_sum-min_sum)+1)%MOD;
    }
    while(answer < 0){
        answer += MOD;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3636
#! /usr/bin/python
# -*- encoding: utf-8 -*-

import sys

if __name__ == '__main__':
    inputN = int(input())
    inputMonster = list(map(int, input().split()))
    inputPower = list(map(int, input().split()))

    sumVictory = 0
    zanMonster = inputMonster[-1]
    
    for i in range(inputN):
        # 末尾から，力量がモンスター数をうわまった場合，モンスター数を加算
        # そうでなければ，力量を加算し，一つ後の街の残りモンスター数を記録
        if inputPower[inputN - i - 1]  >= inputMonster[inputN - i - 1] + zanMonster:
            sumVictory += inputMonster[inputN - i - 1] + zanMonster
            zanMonster = 0
        
        else:
            sumVictory += inputPower[inputN - i - 1]
            if zanMonster > inputPower[inputN - i - 1]:
                zanMonster = inputMonster[inputN - i - 1]
            else:
                zanMonster = inputMonster[inputN - i - 1] + zanMonster - inputPower[inputN - i - 1]
        #print(sumVictory)
    sys.stdout.write(str(sumVictory))
            





Measured memory_bytes: 19004
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER)
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define EPS 1e-9
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;


const int MOD = 1000000;
int n, m;
int dp[111][111];
int rec(int y, int x) {
	if(dp[y][x] != -1) return dp[y][x];
	int r = 0;
	if(y == n+1)
		r = x == m;
	else {
		rer(i, 0, m)
			r += rec(y+1, i);
		if(m == 2) {
			if(x == 0) rer(i, y+1, n)
				r += rec(i+1, 2);
			if(x == 2) rer(i, y+1, n)
				r += rec(i+1, 0);
		}
	}
	return dp[y][x] = r % MOD;
}

int main() {
	scanf("%d%d", &n, &m);
	mset(dp, -1);
	printf("%d\n", rec(0, 0));
	return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> w(n + 1);

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        w[a].push_back(b);
        w[b].push_back(a);
    }

    vector<int> marked(n + 1, 0);
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int i : w[now]) {
            if (marked[i]) continue;
            marked[i] = now;
            q.push(i);
        }
    }

    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++) cout << marked[i] << endl;
}


Measured memory_bytes: 10072
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n;
        while((n = scn.nextInt()) > 0) {
            int[] ary = new int[n];
            for(int i = 0; i < n; i++) {
                ary[i] = scn.nextInt();
            }
            Arrays.sort(ary);
            int sum = 0;
            for(int i = 1; i < n - 1; i++) {
                sum += ary[i];
            }
            System.out.println(sum / (n - 2));
        }
    }
}

Measured memory_bytes: 28356
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <limits>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define x first
#define y second
#define sf scanf
#define pf printf
#define vec vector
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define bin_cnt(x) __builtin_popcount(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define srep(sub,s) for(int sub=s&(s-1);sub;sub=(sub-1)&s)
#define irep(i,a) for(__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define irrep(i,a) for(__typeof(a.rbegin()) i=a.rbegin();i!=a.rend();i++)
#define inf numeric_limits<int>::max()
#define finf numeric_limits<double>::infinity()
#define eps 1e-8
#pragma GCC optimize ("O3")
#define o3 __attribute__((optimize("O3")))
#pragma comment(linker, "/STACK:32505856")

template<class T> inline T sqr(T a) {return a*a;}
template<class T> inline int gmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> inline int gmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
inline int dcmp(const double &a) {return a>eps?1:(a<-eps?-1:0);}
struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}}initializer;

char st[1024];

int main() {
  sf("%s", st + 1);
  int len= strlen(st+1);
  int c=0;
  rep(i,1,len) {
    if (st[i]=='C') c=1;
    if (st[i]=='F' && c) {
      pf("Yes\n");
      return 0;
    }
  }
      pf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#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, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );

int main(){
    //エラトステネスの篩 N以下 N log(log N)
    vector<bool> p(100005);
    //ll cnt = 0;
    FOR(i,0,100005){
        p[i]=true;
    }
    FOR(i,2,100005){
        if(p[i]==true){
            //cnt++;
            FOR(j,2,100005/i+1){
                p[i*j]=false;
            }
        }  
    }

    vector<ll> c(100005,0);

    FOR(i,3,100005){
        if(p[i] && p[(i+1)/2]) c[i]=c[i-1]+1;
        else c[i]=c[i-1];
    }

    cin.tie(0);
    ios::sync_with_stdio(false);
    ll Q;
    cin>>Q;
    ll l,r;
    FOR(i,0,Q){
        cin>>l>>r;
        cout<<c[r]-c[l-1]<<endl;
    }
    
}
//73

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int n;
int a[202020], ans[202020];

signed main()
{
    cin >> n;
    REP(i,n) {
        cin >> a[i];
    }

    reverse(a, a + n);
    int s = 0, t = n - 1;
    REP(i,n) {
        if (i % 2 == 0) {
            ans[s++] = a[i];
        } else {
            ans[t--] = a[i];
        }
    }

    REP(i,n) {
        if (i != 0) {
            cout << " ";
        }
        cout << ans[i];
    }
    cout << endl;
}


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

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

    int hole =1,cnt=0;
    while(true){
        if(hole >= B){
            cout << cnt << endl;
            break;
        }else{
            hole += A-1;
            cnt ++;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const long long mod = 1000000007;
long long W[100005], W2[100005], W4[100005], X[100005], n, q, E[42][100005];
long long modpow(long long a, long long p, long long m) {
	long long cnt = 1, r = a;
	for (long long i = 0; i < 60; i++) {
		if ((p / (1LL << i)) % 2 == 1) { cnt *= r; cnt %= m; }
		r *= r; r %= m;
	}
	return cnt;
}
long long div(long long a, long long b, long long m) {
	return a*modpow(b, m - 2, m) % mod;
}
long long gcd(long long a, long long b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int main() {
	cin >> n >> q; for (long long i = 1; i <= n; i++)cin >> X[i];
	for (long long i = 1; i <= n; i++) {
		long long cnt = 0, t = i;
		while (cnt == 0 || t != i) { W2[i] += t; cnt++; t = X[t]; }
		W[i] = cnt; E[W[i]][i]++;
	}
	for (long long i = 1; i <= 40; i++) {
		for (long long j = 1; j <= n; j++) E[i][j] += E[i][j - 1];
	}
	long long W3 = 1;
	for (long long i = 1; i <= 40; i++) {
		if (E[i][n] - E[i][0] >= 1)W3 *= (i / gcd(i, W3));
	}
	for (long long i = 1; i <= n; i++) {
		W4[i] = ((W3 / W[i]) % mod)*W2[i]; W4[i] %= mod;
	}
	for (long long i = 1; i <= n; i++)W4[i] += W4[i - 1];
	for (long long i = 1; i <= q; i++) {
		long long l, r; cin >> l >> r;
		long long W5 = 1;
		for (long long j = 1; j <= 40; j++) {
			if (E[j][r] - E[j][l - 1] >= 1)W5 *= (j / gcd(W5, j));
		}
		long long W6 = W3 / W5; W6 %= mod;
		long long W7 = W4[r] - W4[l - 1]; W7 %= mod;
		long long W8 = div(W7, W6, mod);
		cout << W8 << endl;
	}
	return 0;
}

Measured memory_bytes: 37488
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * ceil_(a, b)); }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}
bool judge_Palindrome(string S) {
  for (int i = 0; i < S.size() / 2; i++) {
    if (S[i] != S[S.size() - 1 - i]) {
      return false;
    }
  }
  return true;
}

class CInsertingX {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    string S;
    cin >> S;
    string temp{};
    rep(i, S.size()) {
      if (S[i] != 'x') {
        temp += S[i];
      }
    }
    if (!judge_Palindrome(temp)) {
      cout << -1 << endl;
      return;
    }
    vector<int> x_num;
    int before = 0;
    int now    = 0;
    rep(i, S.size()) {
      if (now == ceil_(temp.size(), 2)) break;
      if (S[i] == temp[now]) {
        x_num.emplace_back(i - before);
        before = i + 1;
        now++;
      }
    }
    now    = 0;
    before = S.size() - 1;
    for (int i = S.size() - 1; i >= 0; i--) {
      if (now == ceil_(temp.size(), 2)) break;
      if (S[i] == temp[now]) {
        x_num[now] = abs(x_num[now] - (before - i));
        before     = i - 1;
        now++;
      }
    }
    cout << accumulate(ALL(x_num), 0LL) << endl;
  }
};


signed main() {
  CInsertingX solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    ll n;
    cin>>n;
    vector<ll> x(n+1),y(n+1);
    for(int i = 0; i < n; i++)
    {
        cin >> x[i+1];
        y[i+1] = x[i+1];
    }
    sort(y.begin(),y.end());
    for(int i = 1; i <= n; i++)
    {
        if (x[i]<= y[n/2]) cout << y[n/2+1] << endl;
        else cout << y[n/2] << endl;
    }

    return 0;
}

Measured memory_bytes: 5376
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[][] c = new int[3][3];
        String result = "Yes";

        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                c[i][j] = in.nextInt();
            }
        }
        int b1 = c[0][0];
        int b2 = c[1][0];
        int b3 = c[2][0];
        if ((c[0][1] - b1 != c[1][1] -b2) || (c[1][1] -b2 != c[2][1] -b3)){
            result = "No";
        }
        if ((c[0][2] - b1 != c[1][2] -b2) || (c[1][2] -b2 != c[2][2] -b3)){
            result = "No";
        }

        System.out.println(result);
        
        in.close();
    }
}


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

int main()
{
  double w,h,x,y;
  cin>>w>>h>>x>>y;
  double ans = (double)w*(double)h/2.0;
  cout<<ans<<" ";
  if((x == (w/2))&&(y == (h/2)))
  	cout<<1;
  else
  	cout<<0;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>京都
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N;
int A[100001];
int B[100000];

signed main()
{
	cin >> N;
	REP(i, N + 1) cin >> A[i];
	REP(i, N) cin >> B[i];

	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		int n = MIN(A[i], B[i]);
		sum += n;
		A[i] -= n;
		B[i] -= n;

		int m = MIN(A[i + 1], B[i]);
		sum += m;
		A[i + 1] -= m;
		B[i] -= m;
	}

	cout << sum << endl;
}











Measured memory_bytes: 1792
#include <stdio.h>

int solve(int, int);

int A[2000], n;

int main(){
  int i, q, mi[2000];

  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d", &A[i]);
  scanf("%d", &q);
  for(i=0;i<q;i++) scanf("%d", &mi[i]);

  for(i=0;i<q;i++){
    if(solve(0, mi[i])) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int solve(int i, int m){
  int res;
  if(m == 0) return 1;
  if(i>=n) return 0;
  res = solve(i+1, m)||solve(i+1, m-A[i]);
  return res;
}

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

double dp[21000][110];
int T[100];
int V[100];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;
	for(int i = 0; i < 21000; i++){
		for(int j = 0; j < 110; j++){
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	for(int i = 0; i < N; i++){
		cin >> T[i];
	}
	for(int i = 0; i < N; i++){
		cin >> V[i];
	}

	int tsum = 0;
	for(int i = 0; i < N; i++){
		int t = T[i], v = V[i];
		for(int j = tsum; j < tsum + t; j++){
			for(int k = 0; k <= v; k++){
				if(dp[j][k] < 0) continue;
				for(int dk = -1; dk <= 1; dk++){
					int nv = max(0, min(v, k + dk));
					double sum = dp[j][k] + (k + nv) / 2.0;
					if(dk == 0 && k < v) sum += 0.25;
					dp[j + 1][nv] = max(dp[j + 1][nv], sum);
				}
			}
		}
		tsum += t;
	}
	cout << fixed << setprecision(15)<< dp[tsum][0] << endl;
}


Measured memory_bytes: 18304
use std::collections::BTreeMap;
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let n = read::<usize>();
  let mut map: BTreeMap<String, BTreeMap<u32, usize>> = BTreeMap::new();

  for i in 0..n {
    let s = read::<String>();
    let p = read::<u32>();

    if map.contains_key(&s) {
      let mut prev_vec = map.get_mut(&s).unwrap();
      prev_vec.insert(p, i + 1);
    } else {
      let mut item_map = BTreeMap::new();
      item_map.insert(p, i + 1);
      map.insert(s, item_map);
    }
  }

  for (_, v) in &map {
    for (_, index) in v.iter().rev() {
      println!("{}", index)
    }
  }
}


Measured memory_bytes: 4352
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, K, i, j, k, l, ans, cnt = 0;

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

    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	inputN := sc.Text()
	sc.Scan()
	inputLine := sc.Text()

	n, err := strconv.Atoi(inputN)
	if err != nil {
		panic(err)
	}

	list := []int{}
	newInput := strings.Split(inputLine, " ")
	for _, v := range newInput {
		num, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		list = append(list, num)
	}

	insertionSort(list, n)
}

func insertionSort(list []int, n int) {
	listDisplay(list)

	for i := 1; i < n; i++ {
		v := list[i]
		j := i - 1
		for ; j >= 0; j-- {
			if list[j] <= v {
				break
			}
			list[j+1] = list[j]
		}
		list[j+1] = v
		listDisplay(list)
	}
}

func listDisplay(list []int) {
	row := ""
	for _, v := range list {
		row += fmt.Sprintf("%d ", v)
	}
	row = strings.TrimRight(row, " ")
	fmt.Println(row)
}


Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int mi = INT_MAX, ma = 0;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        mi = min(mi, a);
        ma = max(ma, a);
    }
    cout  << abs(ma-mi) << endl;
}

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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  int la[100000], tte[100000];
  const int mod = 1000000007;
  for(int i = 0; i < 100000; i++) {
    la[i] = 0;
    tte[i] = 0;
  }
  // "yes"の場合の配列の値の出現回数
  for(int i = 0; i < n; i++) {
    int l = i, r = n - 1 - i;
    la[abs(r - l)]++;
  }

  // 出現回数を数える
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    tte[a]++;
  }

  int ans = 1;
  for(int i = 0; i < n; i++) {
    if(la[i] != tte[i]) {
      cout << 0 << endl;
      return 0;
    }
    // powを使わず, 毎回掛け算して毎回nodをとる
    if(la[i]) {
      ans = ans * la[i] % mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int h = s.nextInt();
        int w = s.nextInt();
        int k = s.nextInt();
        char [][] arr = new char[h][w];
        String s1;
        int bl,wh;
        bl=0;
        wh=0;
        for(int i=0;i<h;i++){
            s1=s.next();
            for(int j=0;j<w;j++){
                arr[i][j]=s1.charAt(j);
            }
        }
        int res=0;
        for (int i = 0; i < (1 << h); ++i) {
            for (int j = 0; j < (1 << w); ++j) {
                int cur = 0;
                for (int l = 0; l < h; ++l) {
                    for (int m = 0; m < w; ++m) {
                        if (((i&(1 << l))!=0) || (j & (1 << m)) !=0) {
                            continue;
                        }
                        if(arr[l][m] == '#')
                            cur++;
                    }
                }
                if(cur==k)
                    res++;
            }
        }
        System.out.println(res);
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

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

vector<char> nest;
vector<int> dot;
int idx;

int solve(){
  if('0' <= nest[idx] and nest[idx] <= '9') return nest[idx++] - '0';
  int k = idx++, res = (nest[k] == '+' ? 0 : 1);
  while(dot[idx] == dot[k] + 1){
    if(nest[k] == '+') res += solve();
    if(nest[k] == '*') res *= solve();
  }
  return res;
}

int main(){
  int n;
  while(cin >> n, n){
    string str;
    nest.clear();
    dot.clear();
    for(int i = 0; i < n; i++){
      cin >> str;
      dot.push_back(str.size());
      nest.push_back(str[str.size() - 1]);
    }
    dot.push_back(0);
    idx = 0;
    cout << solve() << endl;
  }
  return 0;
}



Measured memory_bytes: 3160
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

class X{
	
	}

void main(){
	// A=1、B=2として、区間の合計を3で割った余りが一致すればYES。一致しなければNO
	
	// xs[i]はSの先頭i文字を3で割った余りを保持する
	// ys[i]はTの先頭i文字を3で割った余りを保持する
	
	// 求めるものは (xs[b] - xs[a - 1]) == (ys[d] - ys[c - 1])
	
	string s = readln.chomp;
	string t = readln.chomp;
	
	int[] xs = [0];
	int x = 0;
	foreach(c; s){
		if(c == 'A') x += 1; else x += 2;
		xs ~= x;
		}
	
	debug xs.writeln;
	
	int[] ys = [0];
	int y = 0;
	foreach(c; t){
		if(c == 'A') y += 1; else y += 2;
		ys ~= y;
		}
	
	debug ys.writeln;
	
	int q = read.to!int;
	for(int i = 0; i < q; i ++){
		int a = read.to!int;
		int b = read.to!int;
		int c = read.to!int;
		int d = read.to!int;
		
		string ans;
		if((xs[b] - xs[a - 1]) % 3 == (ys[d] - ys[c - 1]) % 3) ans = "YES";
		else ans = "NO";
		
		ans.writeln;
		}
	
	}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin>>s;
    REP(i,SZ(s)-1) {
        if(s.substr(i,2)=="AC") {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

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

int main() {
    int n;cin>>n;
    const int MAX_N = 35000;
    
    
    for(ll i=1;i<MAX_N;++i){
        for(ll j=1;j<=i;++j){
            ll tmp1 = n*i*j;
            ll tmp2 = 4*i*j - i*n - j*n;
            ll tmp3 = tmp1/tmp2;
            if(tmp2>0 && tmp1%tmp2==0 && tmp3>0){
                cout<<i<<" "<<j<<" "<<tmp3<<endl;
                return 0;
            }
        }
    }
	return 0;
}

Measured memory_bytes: 256
N, X = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

L = list( map(int, input().split()) )	# 1 2 3 4 5 ...

d=0
ans=1
for l in L:
	d+=l
	if d<=X:
		ans+=1
	else:
		break

print(ans)


Measured memory_bytes: 2940
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

from bisect import bisect_left, bisect_right
ans = 0
for b in B:
    ai = bisect_left(A, b)
    ci = bisect_right(C, b)
    ans += ai * (N-ci)
print(ans)

Measured memory_bytes: 107108
from itertools import combinations

def main():
    n, m = map(int, input().split())

    ans = 0

    n_list = [i+1 for i in range(n)]
    m_list = [i+1 for i in range(m)]

    ans += len(list(combinations(n_list, 2)))
    ans += len(list(combinations(m_list, 2)))

    print(ans)

if __name__ == '__main__':
    main()

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

int main () {
  int n, ans = 0;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    int c = a[i]-b[i];
    if (c > 0) {
      ans += c;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

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

  using ll = long long;
  ll T1,T2; cin>>T1>>T2;
  ll A1,A2; cin>>A1>>A2;
  ll B1,B2; cin>>B1>>B2;
  ll d1 = T1*(A1-B1);
  ll dd = d1 + T2*(A2-B2);
  if (dd == 0) {
    cout << "infinity" << endl;
  } else if (d1/abs(d1) == dd/abs(dd)) {
    cout << 0 << endl;
  } else {
    ll ans;
    if (abs(d1)%abs(dd) == 0) {
      ans = abs(d1)/abs(dd)*2;
    } else {
      ans = abs(d1)/abs(dd)*2+1;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int N,M;
    cin >> N >> M;
    vector<ll> homework(M);
    for (int i=0; i<M; i++) cin >> homework[i];

    // resolve
    ll total = 0;
    for (int i=0; i<M; i++) total+=homework[i];

    // output
    if (total <= N) cout << N-total << endl;
    else cout << -1 << endl;
    
    return 0;
}


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

#define INF 1000050000

int main()
{
	int n;
	scanf("%d", &n);
	int h[100005][3];
	int dp[100005][3];
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			scanf("%d", &h[i][j]);
			dp[i][j] = 0;
		}
	}
	dp[0][0] = h[0][0];
	dp[0][1] = h[0][1];
	dp[0][2] = h[0][2];
	for(int i = 0; i < n-1; i++) {
		dp[i+1][0] = max(dp[i+1][0], max(dp[i][1], dp[i][2]) + h[i+1][0]);
		dp[i+1][1] = max(dp[i+1][1], max(dp[i][0], dp[i][2]) + h[i+1][1]);
		dp[i+1][2] = max(dp[i+1][2], max(dp[i][1], dp[i][0]) + h[i+1][2]);
	}
	printf("%d\n", max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}));
}

Measured memory_bytes: 2560
n = gets.to_i
s = gets.chomp
he = 0
hw = 0

1.upto(n-1){|i| he += 1 if s[i] == "E"}

ans = he
(n-1).times do |i|
    hw += 1 if s[i] == "W"
    he -= 1 if s[i+1] == "E"
    ans = he + hw if ans > he + hw
end

puts ans

Measured memory_bytes: 2436