akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.*;

// import 
class Main {


    static int min(int a,int b)
    {
        return Math.min(a, b);
    }

    static int abs(int a)
    {
        return Math.abs(a);
    }

    public static void main(String[] args) throws Exception {
        PrintWriter p = new PrintWriter(System.out);
        // Scanner sc = new Scanner(System.in);
        // int n = sc.nextInt();
        // sc.nextLine();
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        
        int n = Integer.parseInt(bf.readLine());
        Integer arr[] = Arrays.stream(bf.readLine().split(" ")).map(Integer::parseInt).toArray(Integer[]::new);
        
        int dp[] = new int[n+1];
        // int mod = 100000000+7;
        Arrays.fill(dp, Integer.MAX_VALUE); //fill large values in dp 
        dp[0] = 0;
        for (int i = 0; i < n; i++) 
        {
            if(i+1 < n )
                dp[i+1] =  min(dp[i+1],dp[i]+abs(arr[i]-arr[i+1]));
            if (i + 2 < n)
                dp[i + 2] = min(dp[i + 2], dp[i] + abs(arr[i] - arr[i+2]));

        }
        // System.out.println(Arrays.toString(dp));
        // System.out.println(dp[n-1]);
        p.println(dp[n-1]);
        p.flush();
    }
}

Measured memory_bytes: 36820
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    dp = [0] * 4
    MOD = 10**9 + 7
    dp[0] = 1
    for c in S:
        if c == '?':
            for i in range(3, 0, -1):
                dp[i] = dp[i]*3 + dp[i-1]
                dp[i] %= MOD
            dp[0] = dp[0]*3
            dp[0] %= MOD
        elif c == 'A':
            dp[1] += dp[0] % MOD
        elif c == 'B':
            dp[2] += dp[1] % MOD
        elif c == 'C':
            dp[3] += dp[2] % MOD
    return dp[3] % MOD


def main():
    S = read_str().strip()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5708
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>

#define INF 1000000000;
#define MOD 1000000007;
typedef long long ll;
using namespace std;

ll fn(ll m, ll a) {
    return m % a;
}

int main()
{
    int a, b; cin >> a >> b;
    int ans = 0;
    if (a <= b) {
        ans = a;
    }
    else {
        ans = a-1;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set> 
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h> 
#include <cstdio>
using namespace std;
int main()
{
int a,b,cnt,x=0;
cin>>a>>b;
if(b==100){
cnt=1000*a+100;
for(int i=1;i<=317;i++)
{if(cnt==i*i)
cout<<"Yes";
else x++;}
if(x==317)
cout<<"No";}
if(b<10){
cnt=10*a+b;
for(int i=1;i<=317;i++)
{if(cnt==i*i)
cout<<"Yes";
else x++;}
if(x==317)
cout<<"No";}
else if(9<b<100){
cnt=100*a+b;
for(int i=1;i<=317;i++)
{if(cnt==i*i)
cout<<"Yes";
else x++;}
if(x==317)
cout<<"No";}
system ("pause");
return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
#define l long
#define ll long long
#define ull unsigned long long
int main()
{
    string a,b;
    cin>>a>>b;
    int m=a.size(),n=b.size();
    int dp[m+1][n+1];
for(int i=0;i<=m;i++)
dp[i][0]=0;

for(int j=0;j<=n;j++)
dp[0][j]=0;
vector<char>ans;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
    if(a[i-1]==b[j-1])
   { dp[i][j]=1+dp[i-1][j-1];}
    else 
    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
/*for(int i=0;i<=m;i++)
{for(int j=0;j<=n;j++)
cout<<dp[i][j]<<" ";
cout<<endl;
}cout<<endl;
*/
int i=m,j=n;
int t=dp[m][n];
while(t)
{
    if(a[i-1]==b[j-1]){ans.push_back(b[j-1]);i--;j--;t--;}
    else {
        if(dp[i][j-1]==t){
j--;
        }
        else {
i--;
        }
    }
}
vector<char>v(ans.size());
for(int i=0;i<ans.size();i++){v[i]=ans[ans.size()-i-1];cout<<v[i];}

    
}

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

int main(){
    int n,m;
    typedef tuple<vector<char>,vector<char>,int> T;
    while(1){
        cin >> n >> m;
        if(n == 0 && m == 0)break;
        //vector<char> cup(n,0);
        vector<char> cup;
        vector<char> beforecup;
        cup.resize(n);

        bool flag = true;
        rep(i,3){
            int n1;
            cin >> n1;
            rep(j,n1){
                int n2;
                cin >> n2;
                n2--;
                cup[n2] = i;
            }
        }//入力ここまで
        queue<T> que;
        que.push(T(cup,cup,0));
        while(que.size()!=0){
            T state = que.front();
            cup = get<0>(state);
            beforecup = get<1>(state);
            int movecount = get<2>(state);
            que.pop();
            //rep(i,cup.size())cout << cup[i];
            //cout << endl;
            int bigger[3];
            int maxcount = 0;
            bool tray[3] ={true,true,true};
            if(n == count(cup.begin(),cup.end(),0) ||n == count(cup.begin(),cup.end(),2)){
                cout << movecount << endl;
                flag = false;
                break;
            }
            rep(i,n){
                int i2 = n-i-1;
                rep(j,3){
                    if(tray[j] == true && cup[i2] == j){
                        tray[j] = false;
                        bigger[maxcount] = i2;
                        maxcount++;
                        break;
                    }
                }
                if(maxcount == 3)break;
            }
            movecount++;
            if(movecount > m) break;
            if(cup[bigger[0]]-1 >= 0){
                cup[bigger[0]]--;
                if(cup != beforecup) que.push(T(cup,get<0>(state),movecount));
                cup[bigger[0]]++;
            }
            if(cup[bigger[0]]+1 <= 2){
                cup[bigger[0]]++;
                if(cup != beforecup) que.push(T(cup,get<0>(state),movecount));
                cup[bigger[0]]--;
            }
            if(maxcount >= 2){
                if(cup[bigger[1]]-1 >= 0 && cup[bigger[1]]-1 != cup[bigger[0]]){
                    cup[bigger[1]]--;
                    if(cup != beforecup) que.push(T(cup,get<0>(state),movecount));
                    cup[bigger[1]]++;
                }
                else if(cup[bigger[1]]+1 <= 2 && cup[bigger[1]]+1 != cup[bigger[0]]){
                    cup[bigger[1]]++;
                    if(cup != beforecup) que.push(T(cup,get<0>(state),movecount));
                    cup[bigger[1]]--;
                }
            }
        }
        if(flag) cout << "-1" << endl;
    }
    return 0;
}


Measured memory_bytes: 3040
#include <iostream>

using namespace std;

int main() {

	int number[10][3][4] = { 0 };//部屋・階数・棟
	int b, f, r, v, n;//b棟f階のr番目の部屋にv人が追加で入居or退去+情報の数n

	cin >> n;

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

		cin >> b >> f >> r >> v;

		number[r - 1][f - 1][b - 1] += v;
	}

	for (int j = 0; j < 4;j++) {//棟

		for (int k = 0; k < 3;k++) {//階数

			for (int l = 0; l < 10;l++) {//部屋

				cout << ' ' << number[l][k][j];
			}
			cout << endl;
		}
		if(j != 3) for (int m = 0; m < 20; m++) {
			cout << "#";
		}
		if(j != 3) cout << endl;
	}
	//cin >> /*変数他*/;
	//cout << /*文字列*/ << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
ll x;
cin>>x;

cout<<(-x+1);

return 0;
}






ll gcd(ll a, ll b){

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

}

Measured memory_bytes: 3620
class UnionFind():
    __slots__ = ['parent']
    # 負の値はルートで集合の個数
    # 正の値は次の要素を返す

    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        parent_x = self.find(x)
        parent_y = self.find(y)

        if parent_x != parent_y:
            if self.parent[parent_x] < self.parent[parent_y]:
                self.parent[parent_x] += self.parent[parent_y]
                self.parent[parent_y] = parent_x
            else:
                self.parent[parent_y] += self.parent[parent_x]
                self.parent[parent_x] = parent_y

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        while self.parent[x] >= 0:
            x = self.find(self.parent[x])
        return abs(self.parent[x])


n, m = map(int, input().split())

brige = [list(map(int, input().split())) for _ in range(m)]

uf = UnionFind(n)
ans = [0] * m
ans[m-1] = int(n*(n-1)/2)

for i in range(m-1, 0, -1):
    a = brige[i][0]-1
    b = brige[i][1]-1
    if uf.find(a) != uf.find(b):
        ans[i-1] = ans[i] - uf.size(a)*uf.size(b)
    else:
        ans[i-1] = ans[i]
    uf.union(a, b)

for ans_i in ans:
    print(int(ans_i))

Measured memory_bytes: 36544
#include<stdio.h>
int main(void){
 int n;
  scanf("%d",&n);
  switch(n%10){
    case 0:
    case 1:
    case 6:
    case 8:puts("pon");break; 
    case 3: puts("bon");break;
    default:puts("hon");break;
  }
  return 0;
}


Measured memory_bytes: 1628
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
		//		new Main().solveE();
		//		new Main().solveF();
	}

	private void solveA() {
		Scanner scanner = null;
		int numN = 0;
		int numA = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numA = scanner.nextInt();

			int res = numN % 500;

			System.out.println(res <= numA ? "Yes" : "No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			int[] wk = new int[numN];
			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt();
			}

			Arrays.sort(wk);

			int alice = 0;
			int bob = 0;
			boolean convert = true;
			for (int i = wk.length - 1; i >= 0; i--) {
				if (convert) {
					alice += wk[i];
				} else {
					bob += wk[i];
				}
				convert = !convert;
			}

			System.out.println(alice - bob);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveE() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveF() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 21716
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

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

        // 入力
        String s = sc.next();

        // 処理
        String out = "";
        for (int i = 0; i < s.length(); i++) {
            out = out + "x";
        }

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 25172
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
	int main() {
		std::string s, t;
		std::cin >> s >> t;
		std::sort(s.begin(), s.end());
		std::sort(t.begin(), t.end(), std::greater<>());
		if (s < t) {
			std::cout << "Yes" << std::endl;
		}
		else{
			std::cout << "No" << std::endl;
		}
		return 0;
	}

Measured memory_bytes: 256
import java.util.Scanner;

class MyMain{
    Scanner scanner;
    public MyMain(){
        scanner = new Scanner(System.in);
    }
    int getInt(){
        return Integer.parseInt(scanner.next());
    }
    public void main() {
        int s = getInt();
        int h = s / 3600;
        s %= 3600;
        int m = s / 60;
        s %= 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}

public class Main {

    public static void main(String[] args) {
        MyMain mymain = new MyMain();
        mymain.main();
    }
}



Measured memory_bytes: 26156
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = 0;
  int num = 1;
  for (int i = 0; i < n; i ++) {
    if (a[i] == num) {
      num ++;
    } else {
      ans ++;
    }
  }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const ll INF = 1LL<<60;

vector<bool> seen;
vector<int> counter;
void dfs(const vector<vector<int>> &G, vector<int> &counter, int v, vector<vector<int>> &c){
    seen[v] = true;
    if(c[v].size() != 0) rep(i,c[v].size()) counter[v] += c[v][i]; 

    for(auto nextv : G[v]){
        if(seen[nextv]) continue;
        counter[nextv] += counter[v];
        dfs(G,counter,nextv,c);
    }
}


int main()
{
    int N,Q;
    cin >> N >> Q;
    vector<vector<int>> G(N);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> p(Q);
    vector<int> x(Q);
    vector<vector<int>> c(N);
    rep(i,Q){
        int p,x;
        cin >> p >> x;
        p--;
        c[p].push_back(x);
    }


    counter.assign(N,0);
    seen.assign(N,false);
    dfs(G,counter,0,c);

    rep(i,N){
        cout << counter[i] << endl;       
    }

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

int main(){
	int n,a,b,c;
	cin>>n;
	while(cin>>a>>b>>c){
		if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2988
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

vector<vector<char>> field;
int H, W;

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

bool check(int i, int j) {
	int sq = 0;
	for (int k = 0; k < 4; k++) {
		int ni = i + dx[k];
		int nj = j + dy[k];
		if (0 <= ni && ni < H && 0 <= nj && nj < W&&field[ni][nj] == '.')
			sq++;
	}
	if (sq == 4)return true;
	else return false;
}

void dfs(int i, int j) {
	field[i][j] = 'a';
	for (int k = 0; k < 4; k++) {
		int ni = i + dx[k];
		int nj = j + dy[k];
		if (0 <= ni && ni < H && 0 <= nj && nj < W&&field[ni][nj] == '#')
			dfs(ni, nj);
	}
	return;
}

int main() {
	cin >> H >> W;
	field.assign(H, vector<char>(W, ' '));
	for (int i = 0; i < H; i++) {
		string s; cin >> s;
		for (int j = 0; j < W; j++) {
			field[i][j] = s[j];
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (field[i][j] == '#') {
				if (check(i, j)) {
					cout << "No" << endl;
					return 0;
				}
				else dfs(i, j);
			}
		}
	}
	cout << "Yes" << endl;
	




	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int n,a[100],i,max=0,min=1000,c;
  while(1){
    c=0;
    max=0;
    min=1000;
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
      if(max<a[i])max=a[i];
      if(min>a[i])min=a[i];
    }
    for(i=0;i<n;i++){
      c+=a[i];
    }
    c-=max+min;
    printf("%d\n",c/(n-2));
  }
  return 0;
}

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

ll solve() {
    int N, K;
    cin >> N >> K;
    vector<ll> X(N), cx(N+1);
    for ( int i = 0; i < N; i++ ) {
        cin >> X[i];
    }
    int p0 = lower_bound(X.begin(), X.end(), 0) - X.begin();
    ll ans = 1LL<<60;
    for ( int i = p0-K; i <= p0; i++ ) {
        if ( i < 0 ) continue;
        if ( i + K - 1 >= N ) break;
        ll x1 = 0, x2 = 0;
        if ( i < p0 ) x1 = -X[i];
        if ( i + K - 1 >= p0 ) x2 = X[i+K-1];
        ll a1 = 2 * x1 + x2;
        if ( ans > a1 ) ans = a1;
        ll a2 = x1 + 2 * x2;
        if ( ans > a2 ) ans = a2;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
D = int(input()) #365
c = list(map(int, input().split()))
s_matrix = [list(map(int, input().split())) for _ in range(D)]
last = [0] * 26
satis = 0

for i in range(D):
    satis3 = satis
    last3 = last.copy()
    for k in range(26):
        satis2 = satis3
        last2 = last3.copy()

        satis2 += s_matrix[i][k]
        last2[k] = i + 1
        for j in range(26):
            satis2 -= c[j] * (i+1 - last2[j])
        
        if satis2 > satis:
            satis = satis2
            ans = k + 1
            last = last2.copy()
    
    print(ans)


Measured memory_bytes: 68684
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
dp = [[0,0,0] for _ in range(N+1)]
for i in range(1,N+1):
    a,b,c = LI()
    dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a
    dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c
print(max(dp[-1]))

Measured memory_bytes: 56620
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int sumDigit(int n){
      int ans = 0;
      while(n > 0){
            ans += n % 10;
            n /= 10;
      }
      return ans;
}
int main(void){
   int n,a,b;
   cin >> n >> a >> b;
   int ans = 0;
   for(int i = 1;i <= n;i++){
         if(a <= sumDigit(i) && sumDigit(i) <= b){
               ans += i;
         }
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from fractions import gcd

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    A, B = map(int, input().split())
    C = gcd(A, B)
    l = factorization(C)
    if l == [[1, 1]]:
        print(1)
    else:
        ans = len(l) + 1
        print(ans)


if __name__ == '__main__': main()

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

int main(){
    string s, p;
    cin >> s >> p;
    string ss = s + s;
    for (int i = 0; i < s.size(); i++){
        bool isYes = true;
        for (int j = 0; j < p.size(); j++){
            if (ss[i+j] != p[j]) isYes = false;
        }
        if (isYes){
            cout << "Yes" << endl;
            break;
        }
        if (i == s.size() -1) cout << "No" << endl;
    }
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
const int N=1000005;
typedef set<int>::iterator It;
set<int> S[N];
queue<pair<int,int> > q;
map<pair<int,int>,int> Map;
int FA[N],n;
int find(int u) { if (u!=FA[u]) FA[u]=find(FA[u]); return FA[u]; }
pair<int,int> work(int u,int v) { if (u>v) swap(u,v); return make_pair(u,v); }
void Add(int u,int v) {
	if (u>v) swap(u,v);
	S[u].insert(v),S[v].insert(u);
	Map[work(u,v)]++; int num=Map[work(u,v)];
	if (num==2) q.push(work(u,v));
}
void Del(int u,int v) {
	S[u].erase(v); S[v].erase(u);
	Map.erase(work(u,v));
}
bool Solve() {
	for (int i=1; i<=n; i++) FA[i]=i;
	for (int i=1; i<n; i++) {
		if (q.empty()) return false;
		int u=q.front().first,v=q.front().second;
		q.pop(); u=find(u),v=find(v);
		if (S[u].size()>S[v].size()) swap(u,v);
		FA[u]=v; Del(u,v);
		for (It i=S[u].begin(),j; i!=S[u].end(); i=j) {
			(j=i)++; int x=*i; x=find(x);
			Del(u,x); Add(v,x);
		}
	}
	return true;
}
int main() {

	scanf("%d",&n);
	for (int i=1; i<=(n-1)<<1; i++) {
		int u,v; scanf("%d%d",&u,&v);
		Add(u,v);
	}
	if (Solve()) printf("YES\n"); else printf("NO\n");
	return 0;
}

Measured memory_bytes: 80640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;

#define mp make_pair
#define pb push_back

const int maxn = 2e5+1;
int n, a[maxn], sorted[maxn];

int main()
{
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a+i);
  memcpy(sorted, a, sizeof(sorted));
  sort(sorted+1, sorted+1+n);
  for (int i = 1; i <= n; ++i)
    printf("%d\n", a[i]<=sorted[n/2]?sorted[n/2+1]:sorted[n/2]);
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
     int n,a,b;
     cin>>n;
     if(n==1){
        cout<<"Hello World"<<endl;
     }
     else{
        cin>>a;
        cin>>b;
        cout<<a+b<<endl;
     }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int candy;
	
	while (scanf("%d", &candy) != EOF){
		if (candy % 39 == 0){
			printf("3C39\n");
		}
		else {
			printf("3C%02d\n", candy % 39);
		}
	}
	
	return (0);
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
  	cin >> a >> b >> c;
  	int s = a+b+c;
  	if(s<=21)
      	cout << "win" << endl;
  	else
      	cout << "bust" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  int a=0,b=0;
  cin>>n>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='R')a++;
    else b++;
  }
  if(a>b){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
//include
//------------------------------------------
#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 <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int x, y; cin >> x >> y;

	cout << x / y << " " << x%y<<" ";
	cout << fixed;
	cout << setprecision(8) << (double)x/(double)y<<endl;

	return 0;
}


Measured memory_bytes: 3300
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int dp[(int)1e5 + 1][19][19];

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

    int n;
    cin >> n;

    int a[3];
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
        a[i] = min(a[i], 6);
    }
    int sum = a[0] + a[1] + a[2];

    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        char c[3];
        cin >> c;
        int t;
        if (c[0] == 'B') t = 0;
        else if (c[1] == 'B') t = 2;
        else t = 1;
        s[i] = t;
    }

    dp[0][a[0]][a[1]] = 1;
    for (int i = 0; i < n; i++) {
        for (int k = 0; k < 19; k++) {
            for (int l = 0; l < 19; l++) {
                if (!dp[i][k][l]) continue;
                int m = sum - k - l;

                if (s[i] == 0) {
                    if (l > 0) dp[i + 1][k][l - 1] = 1;
                    if (m > 0) dp[i + 1][k][l + 1] = 1;
                } else if (s[i] == 1) {
                    if (k > 0) dp[i + 1][k - 1][l] = 1;
                    if (m > 0) dp[i + 1][k + 1][l] = 1;
                } else {
                    if (k > 0) dp[i + 1][k - 1][l + 1] = 1;
                    if (l > 0) dp[i + 1][k + 1][l - 1] = 1;
                }
            }
        }
    }

    for (int k = 0; k < 19; k++) {
        for (int l = 0; l < 19; l++) {
            if (dp[n][k][l]) {
                cout << "Yes" << '\n';

                int m = sum - k - l;
                a[0] = k;
                a[1] = l;
                a[2] = m;

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

                    if (s[i] == 0) {
                        if (l > 0 && dp[i][k][l - 1]) l--, m++, r[i] = 1;
                        if (m > 0 && dp[i][k][l + 1]) l++, m--, r[i] = 2;
                    } else if (s[i] == 1) {
                        if (k > 0 && dp[i][k - 1][l]) k--, m++, r[i] = 0;
                        if (m > 0 && dp[i][k + 1][l]) k++, m--, r[i] = 2;
                    } else {
                        if (k > 0 && dp[i][k - 1][l + 1]) k--, l++, r[i] = 0;
                        if (l > 0 && dp[i][k + 1][l - 1]) k++, l--, r[i] = 1;
                    }
                }

                for (int i = 0; i < n; i++) {
                    cout << "ABC"[r[i]] << '\n';
                }
                exit(0);
            }
        }
    }

    cout << "No" << '\n';

    return 0;
}

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

int main(){
	int n, q, query, x, t, s;
	
	cin>>n>>q;
	
	list<int> hoge[n];
	
	for(int i = 0; i < q; i++){
		cin>>query>>t;
		
		if(query == 0){
			cin>>x;
			hoge[t].push_back(x);
		} else if(query == 1){
			bool flag = false;
			for(int y : hoge[t]) cout<<(flag++?" ":"")<<y;cout<<endl;
		} else {
			cin>>s;
			hoge[s].splice(hoge[s].end(), hoge[t]);
		}
	}
	
	return 0;
}



Measured memory_bytes: 18648
def upTime(t)
    ((t/10.0).ceil*10).to_i
end
A = gets.to_i
B = gets.to_i
C = gets.to_i
D = gets.to_i
E = gets.to_i
x = [A,B,C,D,E].select { |a| a%10==0 }
y = [A,B,C,D,E].select { |a| a%10!=0 }
y =y.sort_by{|a| a%10 }.reverse
z = y.empty? ? 0 : y.pop
t = x.empty? ? 0 : x.inject(:+)
y.each do |a|
    t += upTime a
end
t += z
puts t

Measured memory_bytes: 1788
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>
#include <stdlib.h>
# include <map>

using namespace std;

int main(){
    int x,y;
    cin >> x >> y;
    cout << x+y/2 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10;
char s[N],c[N];
int n,l,pos[N],r,len,ans;
int main()
{
	int i,j;
	scanf("%s",s+1);
	n=strlen(s+1);
	for (i=1;i<=n;i++)
	  if (s[i]!='x')
	    c[++len]=s[i],pos[len]=i;
	pos[0]=0;
	pos[len+1]=n+1;
	for (l=1,r=len;l<r;l++,r--)
	  if (c[l]!=c[r])
	  {
	  	printf("-1\n");
	  	return 0;
	  }
	if (len%2!=0)
	  l=r=(1+len)/2;
	else
	  l=len/2,r=l+1;
	for (;l>0&&r<=n;l--,r++)
	{
	  int t=max(pos[l]-pos[l-1]-1,pos[r+1]-pos[r]-1);
	  int mn=min(pos[l]-pos[l-1]-1,pos[r+1]-pos[r]-1);
	  ans+=t-mn;
	}
	printf("%d",ans);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double  
#define mp make_pair
inline void io()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
int main()
{
    io();
    int a, b;
    cin >> a >> b;
    cout << max(a + a - 1, max(b + b - 1, a + b));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55;
int n,m,k,s,t,a[N],b[N],vis[N];
ll c[N][N];
int main()
{
    for(int i=1;i<N;i++)
        for(int j=0;j<=i;j++)
        if(j==0||j==i) c[i][j]=1;
        else if(j==1) c[i][j]=i;
        else c[i][j]=c[i-1][j-1]+c[i-1][j];
    for(int i=1;i<N;i++)
        for(int j=1;j<N;j++)
        c[i][j]+=c[i][j-1];
    scanf("%d%d%d%d",&n,&k,&s,&t);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        if((s&x)==s&&(x&t)==x) a[++m]=x;
    }
    if(m==0){printf("0\n");return 0;}
    assert((s&t)==s);
    t-=s;
    if(t==0)
    {
        int sum=0;
        for(int i=1;i<=m;i++)
            sum+=a[i]==0;
        printf("%lld\n",c[sum][k]-1);
        return 0;
    }
    int l=__builtin_popcount(t);
    for(int i=0,j=0;i<18;i++)
        if(t>>i&1) vis[i]=++j;
    for(int i=1;i<=m;i++)
    {
        int x=0;
        for(int j=0;j<18;j++)
            if(vis[j]&&(a[i]>>j&1)) x|=1<<vis[j]-1;
        a[i]=x;
    }
    ll ans=0;
    for(int i=0;i<1<<l;i++)
    {
        ll res=0;
        for(int j=1;j<=m;j++)
            b[j]=a[j]&i;
        sort(b+1,b+1+m);
        int t=1;
        for(int j=2;j<=m;j++)
            if(b[j]==b[j-1]) t++;
        else res+=c[t][k]-1,t=1;
        res+=c[t][k]-1;
        if(__builtin_popcount(i)&1) ans-=res;
        else ans+=res;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 3784
//ABC073C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int n;
	cin >> n;
	set<long long int> a;
	for(int i=0;i<n;i++){
		long long int x;
		cin >> x;
		if(a.count(x)){
			a.erase(x);
		}else{
			a.insert(x);
		}
	}
	cout << a.size() << endl;
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9+5;
const int maxn=100005;
int a[maxn];
int dp[maxn];
int k;
int mincost(int n)
{
    if(n==1)
        return 0;
    else if(n==2)
        return abs(a[n]-a[1]);
    else if(dp[n]!=-1)
        return dp[n];
    else
    {
        dp[n]=inf;
        for(int i=1;i<=k;i++)
        {
            if(n-i>=0)
            dp[n]=min(dp[n],mincost(n-i)+abs(a[n]-a[n-i]));
        }
    }
    return dp[n];

}
int main()
{
    int n;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof(dp));
        cout<<mincost(n)<<endl;
    return 0;
}



Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int a, b, p; string s;
	cin >> a >> b;
	p = a & b;
	for (int i = 0; i < 32; i++) {
		s = (p % 2 ? '1' : '0') + s;
		p /= 2;
	}
	cout << s << endl; s.clear();
	p = a | b;
	for (int i = 0; i < 32; i++) {
		s = (p % 2 ? '1' : '0') + s;
		p /= 2;
	}
	cout << s << endl; s.clear();
	p = a ^ b;
	for (int i = 0; i < 32; i++) {
		s = (p % 2 ? '1' : '0') + s;
		p /= 2;
	}
	cout << s << endl;
}


Measured memory_bytes: 3228
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
S = input()
from collections import defaultdict
from bisect import bisect_left, bisect_right
a = []
b = []
c = []
# a = defaultdict(list)
# b = defaultdict(list)
# c = defaultdict(list)
q = []

for e,s in enumerate(S):
    if s == "A" :
        a.append(e)
    if s == "B" :
        b.append(e)
    if s == "C" :
        c.append(e)
    if s == "?":
        q.append(e)

ans = 0
MOD = int(1e9+7)

for eb in b:
    range_a = bisect_right(a, eb-1)
    # print("eb: {eb}, bisect_right({a}, {eb1}): {bis}".format
            # (eb = eb, a=a, eb1=eb-1, bis=bisect_right(a,eb-1)))
    range_c = len(c) - bisect_left(c, eb+1)
    
    range_cq = len(q) - bisect_left(q, eb+1)
    range_aq = bisect_right(q, eb-1)

    ans += range_a*range_c * pow(3, len(q), MOD) % MOD
    ans %= MOD
    if len(q)>=1:
        ans += range_a*range_cq * pow(3, len(q)-1, MOD)
        ans += range_aq*range_c * pow(3, len(q)-1, MOD)
        ans %= MOD
    if len(q)>=2:
        ans += range_aq*range_cq * pow(3, len(q)-2, MOD)
        ans %= MOD
for eq in q:
    # print("eb: {eb}, bisect_right({a}, {eb1}): {bis}".format
            # (eb = eq, a=a, eb1=eq-1, bis=bisect_right(a,eq-1)))
    range_a = bisect_right(a, eq-1)
    range_c = len(c) - bisect_left(c, eq+1)
    range_cq = len(q) - bisect_left(q, eq+1)
    range_aq = bisect_right(q, eq-1)

    ans += range_a*range_c * pow(3, len(q)-1, MOD)
    ans %= MOD
    if len(q) >= 2:
        ans += range_a*range_cq * pow(3, len(q)-2, MOD)
        ans += range_aq*range_c * pow(3, len(q)-2, MOD)
        ans %= MOD
    if len(q) >= 3:
        ans += range_aq*range_cq * pow(3, len(q)-3, MOD)
        ans %= MOD
    
print(ans % MOD)
    



Measured memory_bytes: 54232
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int n; cin >> n;
  vector<int> tot(26,100);
  string s;
  rep(i,n){
    cin >> s;
    vector<int> tmp(26,0);
    rep(j,s.size()) tmp[s[j]-'a']++;

    rep(k,26) tot[k] =  min(tot[k],tmp[k]);
  }

  rep(i,26){
    rep(j,tot[i]) {
      char c = 'a' + i;
      cout << c;
    }
  }
  cout << endl;




  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	ll n,k;
	cin >> n>> k;
	ll i=1;
	ll ans=k;
	while(i<n){
		ans*=(k-1);
		i++;
	}
	cout << ans;

	return 0;
}

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

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef long long int llint;

// Display Map
//~for (auto const& pair: m) {
//~std::cout << "{" << pair.first << ": " << pair.second << "}\n";
//~}

// Extract word(w) from sentence(s)
//~stringstream str(s);
//~string w;
//~while(str >> w){
//~// w is your word
//~}

//Memset Syntax
// memset(array, value,sizeof(array)) val is 0,-1 or bool only

// To get accurate precision
//~cout.precision(20);

int main() {
    fast_io;
	int a,b,c,d,e;
	cin >>a >> b >> c>> d >> e;
	if(a == 0) cout << 1 << endl;
	else if(b == 0) cout << 2 << endl;
	else if(c == 0) cout << 3 << endl;
	else if(d == 0) cout << 4 << endl;
	else  cout << 5 << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 1e5;
int height[N+5];
vector<int> adj[N+5];
bool bad[N+5];

int main(){
    int n, m;
    cin>>n>>m;
    for(int i=1; i<=n; i++){
        cin>>height[i];
    }

    for(int i=0; i<m; i++){
        int x, y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int ans = 0;

    for(int i=1; i<=n; i++){
        int tot = 0;
        for(int j=0; j<adj[i].size(); j++){
            if(height[i] > height[adj[i][j]])
                tot++;
        }
        if(tot==adj[i].size())
            ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9092
// Comment
// Dp[k][i] = k bit 까지 생각 했을 때, (x&i) == x 인 x 집합
// Dp[k][i] = Dp[k-1][i] U Dp[k-1][i - (1<<k) when ((1<<k) & i == (1<<k))

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 18;
const int MAX_NN = (1<<MAX_N) + 100;

int N, Nr[MAX_NN];
vector<int> Dp[MAX_N+1][MAX_NN];
int main() {
	cin >> N;
	int NN = (1<<N);
	for(int i=0; i<NN; i++) {
		scanf("%d", &Nr[i]);
		Dp[0][i].push_back(Nr[i]);
	}
	for(int k=0; k<N; k++) {
		for(int i=0; i<NN; i++) Dp[k+1][i] = Dp[k][i];
		for(int i=0; i<NN; i++) {
			if (i & (1<<k)) {
				for(int x: Dp[k][i-(1<<k)]) Dp[k+1][i].push_back(x);
				sort(ALL(Dp[k+1][i]));
				reverse(ALL(Dp[k+1][i]));
				if(SZ(Dp[k+1][i]) > 2) {
					Dp[k+1][i].erase(Dp[k+1][i].begin()+2, Dp[k+1][i].end());
				}
			}
		}
	}

	int ans = 0;
	for(int i=1; i<NN; i++) {
		ans = max(ans, Dp[N][i][0] + Dp[N][i][1]);
		printf("%d\n", ans);
	}
	return 0;
}


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


int main(){
  	int a,b,n,cnt = 0,memo,check = 0;
  	cin >> n >> a >> b;
  
  	rep(i,1,n+1){
      	memo = 0;
      	check = i;
      
      	memo += check / 10000;
      	check %= 10000;
      	memo += check / 1000;
      	check %= 1000;
      	memo += check / 100;
      	check %= 100;
      	memo += check / 10;
      	check %= 10;
      	memo += check;
      	
     	if(memo >= a && memo <= b){
          cnt += i;
        }
    }
  
  	cout << cnt << endl;
  
  
 	return 0; 
}


Measured memory_bytes: 256
import collections

N = int(input())
lan = ["".join(sorted(input())) for n in range(N)]
#print(lan)
lans = collections.Counter(lan)
#print(lans)
ans = 0
for si in set(lan):
    n = lans[si]
    ans += n * (n - 1) // 2
print(ans) 


Measured memory_bytes: 28296
#include <iostream>
#include <vector>
#include <utility>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint N;
llint s[100005];
vector<P> G[100005];
llint ans[100005];
llint centi, centa, centb;

llint dfs(int v, int prev)
{
	llint ret = 0, res, d1, d2;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i].first == prev) continue;
		res = dfs(G[v][i].first, v);
		ret += res;
		if(N % 2 == 0 && res == N/2){
			centi = G[v][i].second;
			centa = v;
			centb = G[v][i].first;
			continue;
		}
		ans[G[v][i].second] = (s[v] - s[G[v][i].first]) / (2*res - N);
	}
	return ret + 1;
}

P dfs2(int v, int prev)
{
	P ret = make_pair(0, 0), res;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i].first == prev) continue;
		res = dfs2(G[v][i].first, v);
		ret.first += res.first + res.second * ans[G[v][i].second];
		ret.second += res.second;
	}
	ret.second++; 
	return ret;
}

int main(void)
{
	cin >> N;
	int a, b;
	for(int i = 1; i <= N-1; i++){
		cin >> a >> b;
		G[a].push_back(make_pair(b, i));
		G[b].push_back(make_pair(a, i));
	}
	for(int i = 1; i <= N; i++) cin >> s[i];
	
	dfs(1, -1);
	if(centi != 0){
		llint s1 = dfs2(centa, centb).first;
		llint s2 = dfs2(centb, centa).first;
		ans[centi] = (s[centa] - (s1+s2)) / (N / 2);
	}
	
	for(int i = 1; i <= N-1; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 17280
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int d, g;
vi p, c;
int calc(vi & jr) {
  int score = 0;
  int cnt = 0;
  rep (j, d) {
    int i = jr[j];
    int rest = g - score;
    if (rest <= i*100 * (p[i] - 1)) {
      cnt += (rest + i*100 - 1) / (i*100);
      return cnt;
    } else if (rest <= i*100 * p[i] + c[i]) {
      cnt += p[i];
      return cnt;
    } else {
      cnt += p[i];
      score += i*100 * p[i] + c[i];
    }
  }
  assert(false);
}

int main() {
  scanf("%d %d", &d, &g);
  p.assign(d+1, 0);
  c.assign(d+1, 0);
  FOR(i, 1, d+1) {
    scanf("%d %d", &p[i], &c[i]);
  }
  vi jr(d);
  rep (i, d) {
    jr[i] = i+1;
  }
  int ans = INT_MAX;
  do {
    ans = min(ans, calc(jr));
  } while (next_permutation(all(jr)));

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

  return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif // LOCAL
#include <bits/stdc++.h>

#define sz(c) int((c).size())

using namespace std;

const int mod = 998244353;

void add (int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}
void sub (int &a, int b)
{
    a -= b;
    if (a < 0)
        a += mod;
}
int mult (int a, int b)
{
    return a * 1LL * b % mod;
}

void solve (istream &cin = std::cin, ostream &cout = std::cout)
{
    int n, m;

    while (cin >> n >> m)
    {
        const int bound = 4 * max(n, m);
        vector<int> fact(bound, 1), ifact(bound, 1), inv(bound, 1);
        for (int i = 2; i < bound; i++)
        {
            fact[i] = mult(fact[i - 1], i);
            inv[i] = mod - mult(mod / i, inv[mod % i]);
            assert(mult(i, inv[i]) == 1);
            ifact[i] = mult(ifact[i - 1], inv[i]);
        }

        auto C = [&] (int from, int what)
        {
            if (what < 0 || what > from)
                return 0;
            return mult(fact[from], mult(ifact[what], ifact[from - what]));
        };

        int ans = C(3 * m + n - 1, n - 1);
        sub (ans, mult(n, C(m - 1 + n - 1, n - 1)));

        for (int cnt_odd = m + 1; cnt_odd <= n; cnt_odd++)
        if (cnt_odd % 2 == m % 2)
            sub (ans, mult(C(n, cnt_odd), C((3 * m - cnt_odd) / 2 + n - 1, n - 1)));

        cout << ans << endl;
    }
}

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

#ifdef LOCAL
    ifstream in ("input.txt");
//    ofstream out ("output.txt");
    solve (in, cout);

    cout << setprecision (4);
    cout << "clock: " << clock () / (double) CLOCKS_PER_SEC << endl;
#else
    solve ();
#endif // LOCAL

    return 0;
}


Measured memory_bytes: 47104