akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << ' ' << y << endl
#define dbg3(x, y, z) cout << x << ' ' << y << ' ' << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin >> n;
    n %= 10;
    if(n == 3){
        cout << "bon\n";
    }else if(n == 0 || n == 1 || n == 6 || n == 8){
        cout << "pon\n";
    }else{
        cout << "hon\n";
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
//#define NDEBUG
#include <cassert>
using namespace std;


// N:0 E:1 S:2 W:3
const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};

typedef pair<int,int> pii;
#define y first
#define x second

int H, W;
vector<string> stage;
string pg;
vector<int> jmp;

bool visit[60][60][1100][4];
int dir;
pii robo;

int ans;

bool valid_range(int h, int w) {
	return 0 <= h && h < H && 0 <= w && w < W;
}

void update(int & pc, int nex_pc) {
	// cout << robo.y << " " << robo.x << " " << pc << " " << dir << endl;
	assert(pc != nex_pc);
	if(visit[robo.y][robo.x][pc][dir]) {
		cout << -1 << endl;
		exit(0);
	}
	visit[robo.y][robo.x][pc][dir] = true;
	pc = nex_pc;
}

bool check(int & pc) {
	bool res, inv;
	inv = false;
	if(pg[pc] == '~') {
		inv = true;
		update(pc, pc+1);
	}
	int nx, ny;
	ny = robo.y + dy[dir];
	nx = robo.x + dx[dir];
	switch(pg[pc]){
		case 'C' :
			res = stage[ny][nx] == '#'; break;
		case 'N' :
			res = dir == 0; break;
		case 'E' :
			res = dir == 1; break;
		case 'S' :
			res = dir == 2; break;
		case 'W' :
			res = dir == 3; break;
		case 'T' :
			res = true; break;
		default :
			assert(0);
	}
	if(inv)
		return !res;
	return res;
}

bool solve(int & pc) {
	int res = 0;
	while(pc < pg.size() && pg[pc] != ']' && pg[pc] != '}') {
		if(stage[robo.y][robo.x] == 'g')
			return true;
		if(pg[pc] == '[') {
			bool flg;
			int tmp;
			tmp = jmp[pc];
			update(pc,pc+1);
			flg = check(pc);
			if(flg) {
				update(pc,pc+1);
				if(solve(pc))
					return true;
				assert(pc == tmp);
				update(pc, pc+1);
			}
			else {
				update(pc,tmp+1);
			}
		}
		else if (pg[pc] == '{') {
			int tmp = jmp[pc];
			bool flg = true;
			update(pc,pc+1);
			while(check(pc)) {
				update(pc,pc+1);
				if(solve(pc))
					return true;
				update(pc, jmp[pc]);
				update(pc, pc+1);
			}
			update(pc,tmp+1);
		}
		else {
			int nx, ny;
			nx = robo.x; ny = robo.y;
			switch(pg[pc]) {
				case '^' :
					ny = robo.y + dy[dir];
					nx = robo.x + dx[dir];
					ans++;
					break;
				case 'v' :
					ny = robo.y + dy[dir+2&3];
					nx = robo.x + dx[dir+2&3];
					ans++;
					break;
				case '<' :
					dir = dir-1 +4 & 3;
					ans++;
					break;
				case '>' :
					dir = dir+1 +4 & 3;
					ans++;
					break;
				default  : assert(0);
			}
			if(valid_range(ny, nx) && stage[ny][nx] != '#') {
				robo.y = ny;
				robo.x = nx;
			}
			update(pc,pc+1);
		}
	}
	if(stage[robo.y][robo.x] == 'g')
		return true;
	return false;
}

int main() {
	cin >> H >> W;
	stage.resize(H);
	for(int i = 0; i < H; i++) cin >> stage[i];
	cin >> pg;

	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			if(stage[i][j] == 's') {
				robo.y = i;
				robo.x = j;
				stage[i][j] = '.';
			}
		}
	}
	jmp.resize(pg.size());
	stack<int> stk;
	for(int i = 0; i < pg.size(); i++) {
		if(pg[i] == '[' || pg[i] == '{') {
			stk.push(i);
		}
		else if(pg[i] == ']' || pg[i] == '}') {
			int tmp;
			tmp = stk.top(); stk.pop();
			jmp[i] = tmp;
			jmp[tmp] = i;
		}
	}

	int tmp;
	bool res;
	tmp = 0;
	res = solve(tmp);
	if(res)
		cout << ans << endl;
	else
		cout << -1 << endl;
}

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

using namespace std;
typedef long long int ll;

long double calc(long double x, long double y)
{
	return sqrtl(x * x + y * y);
}

void solve()
{
	int n;
	long double d;
	cin >> n >> d;
	int cnt=  0;
	for(int i = 0; i < n; i++)
	{
		long double x, y;
		cin >> x >> y;
		if(calc(x,y) <= d) cnt++;
	}
	cout << cnt << "\n";
}

int main()
{
//	cin.sync_with_stdio(false);
//	cin.tie(0);
//	cout.tie(0);
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3808
#include<iostream>
using namespace std;
string s;
long long n,ans,cur;
int main()
{
	cin>>s;
	n=s.size();
	for (int mask=0;mask<(1<<(n-1));mask++)
	{
		cur=s[0]-'0';
		for (int i=0;i<n-1;i++)
		{
			if (mask&(1<<i))
			{
				ans+=cur;
				cur=0;
			}
			cur=cur*10+(s[i+1]-'0');
		}
		ans+=cur;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n, c;
	cin >> n >> c;

	vector<int> w(n + 1), v(n + 1);
	vector<vector<long long>> dp(n + 1, vector<long long>(c + 1));

	for(int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= c; j++) {
			dp[i][j] = dp[i-1][j];
			if(j >= w[i]) {
				dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
			}
		}
	}

	cout << dp[n][c];

	return 0;
}

Measured memory_bytes: 80256
import sys

inLine = []
strings = []
for line in sys.stdin:
    for i in range(len(list(str(line).lower()))):
        strings.append(list(str(line).lower())[i])
arr = []
for i in range(26):
    arr.append(0)

for i in range(len(strings)):
    if ord(strings[i]) >= 97 and ord(strings[i]) <= 122:
        arr[ord(strings[i]) - 97] += 1

for i in range(97,123):
    print(chr(i) + " : "  + str(arr[i - 97]))



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

#define pb push_back

int main()
  {
  vector<string>vs;
  int n,l;
  cin>>n>>l;
  string s;
  getchar();
  for(int i=0;i<n;i++)
  {
    cin>>s;
    vs.pb(s);
  }
  sort(vs.begin(),vs.end());
  for(int i=0;i<n;i++)
    cout<<vs[i];
  cout<<endl;
}


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

int main(){
	int A[N][N], b[N], c[N] = {0}, n, m;

	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>A[i][j];
		}
	}

	for(int j=0;j<m;j++){
		cin>>b[j];
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			c[i] += A[i][j] * b[j];
		}
		cout<<c[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int n;
bool c,f;
string s;
int main()
{
	int i,j;
	cin>>s;
	n=s.size();
    for(i=0;i<n;i++)
    if(s[i]=='C')
    {
    	c=false;
    	for(j=i+1;j<n;j++)
    	if(s[j]=='F')
    	{
    		cout<<"Yes";
    		return 0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=1e5+5;
int k1,k2,k3;
int c1,c2,c3;
int n;
bool fl=0;
int main(){
	scanf("%d",&n);
	k1=k2=k3=-1;
	for (int i=1;i<=n;i++){
		int x; scanf("%d",&x);
		if (k1==-1) k1=x,c1=1;
		else if (x!=k1){
			if (k2==-1) k2=x,c2=1;
			else if (x!=k2){
				if (k3==-1) k3=x,c3=1;
				else if (k3!=x) fl=1;
				else c3++;
			}
			else c2++;
		}
		else c1++;
	}
	if (fl) return printf("No\n"),0;
//	cout<<k1<<" "<<k2<<" "<<k3<<endl;
	if (k3==-1&&k2==-1){
		if (k1==0) printf("Yes\n");
		else printf("No\n");
	}
	else if (k3==-1){
		if ((k1==0||k2==0)&&(c1==2*c2||c2==2*c1)) printf("Yes\n");
		else printf("No\n");
	}
	else if (c1==c2&&c2==c3&&(k1^k2)==k3) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))

for i in range(N):
    x=T-0.006*H[i]
    if i==0:
        ans=1
        diff=abs(x-A)
    else:
        if diff>abs(x-A):
            ans=i+1
            diff=abs(x-A)
print(ans)

Measured memory_bytes: 3060
def check(P):
    global k,T,n
    
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= P:
            s += T[i]
            i += 1
            if(i == n):
                return n
    return i
    
def solve():
    left = 0
    right = 100000 * 10000
    
    while right - left > 1:
        mid = (left + right)//2
        v = check(mid)
        if(v >= n):
            right = mid
        else:
            left = mid
    return right
    
if __name__ == '__main__':
    n,k = map(int,input().split())
    T = [int(input()) for i in range(n)]
    
    ans = solve()
    print(ans)


Measured memory_bytes: 9560
#include <bits/stdc++.h>
using namespace std;
int main() {
	int i, j, sz, qnt = 0;
	string s;
	cin >> s;
	sz = s.size();
	for(i = 0, j = sz - 1; i < sz/2; i++, j--) {
		if(s[i] != s[j]) qnt++;
	}
	cout << qnt << endl	;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int64_t> a(N);
  int64_t a_in=0;
  for(int i=0;i<N;++i){
    cin>>a_in;
    a.at(i)=a_in-(i+1);
  }

  sort(a.begin(),a.end());
  int index=N/2;

  int64_t sum=0;
  for(int i=0;i<N;++i){
    sum+=abs(a.at(i)-a.at(index));
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 1792
/* WORK HARD MAN ! IT DEFINETELY AIN'T EASY FOR THE PRIZE IT HOLDS .... */
/* GET YOUR ASS TO WORK ALREADY */
/* FALTU HI LIKH ... BUT KHALI NI BAITHNA */
#include<bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long
#define ld long double
#define pb emplace_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)1e15
#define pii pair<int,int>
#define ff first
#define ss second
// #define N --

using namespace std;

/* if not able to handle the ques.. see up */
int32_t main() {
	fast
	int t_c = 1;
	// cin >> t_c;
	while (t_c--) {
		// cout << "#: ";
		int a, b, n;
		cin >> a >> b >> n;
		int x = min(b - 1, n);
		int ans = floor((ld)(a * x) / b);
		cout << ans;
	}
}

Measured memory_bytes: 3604
#define _USE_MATH_DEFINES

#pragma GCC optimize("Ofast,no-stack-protector") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") 
#pragma GCC optimize("unroll-loops") 
#pragma GCC optimize("fast-math")
  
#include <bits/stdc++.h> 
  
using namespace std;
  
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second    
#define int long long
#define double long double       
#define vec vector            
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double> 
#define beg begin
  
#ifdef LOCAL
    #define dbg(x) cerr << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
  
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
  
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i; 
    }
    return str;
}
  
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
  
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();   
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vec<vec<pii>> a(n);
    for (int i = 0; i < n; ++i) {
        int num; cin >> num;
        a[i].resize(num);
        cin >> a[i];
    }

    int ans = 0;
    for (int mask = 0; mask < (1 << n); ++mask) {
        bool flag = true;
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (((mask >> i) & 1) == 0)  {
                continue;
            }
            else {
                cnt++;
                for (auto it : a[i]) {    
                    int x = it.x, y = it.y;
                    x--;
                    if (((mask >> x) & 1) != y) {
                        flag = false;
                    }
                }
            }
        }
        if (flag) {
            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if( T[u].p == NIL ) cout << "root, ";
  else if( T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i=0, c=T[u].l; c!=NIL; i++,c=T[c].r) {
    if(i) cout <<", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void) {
  int i,j,d,v,c,l,r;
  cin >> n;
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    cin >> v >> d;
    for(j=0;j<d;j++) {
      cin >> c;
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
  
  rec(r,0);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}


Measured memory_bytes: 7764
# include <bits/stdc++.h>
# define sz(a) int(a.size())

using namespace std;

int main()
{          
	int n;
	cin >> n;                    
	set <int> d;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		d.insert (x);
	}
	int dst = sz(d);
	int r = n - sz(d);
	if (r%2 == 1) {
		if (dst > 1)
			dst--;
	}
	cout << dst << endl;	
	 	
	return 0;
}

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

using namespace std;

#define MAX_S 1000000000

void solve() {
  int N, K, S;

  cin >> N >> K >> S;

  vector<int> ans(N);

  int num = S < MAX_S ? S + 1 : S - 1;
  for (int i = 0; i < N; i++) {
    if (i < K) {
      ans[i] = S;
    } else {
      ans[i] = num;
    }
  }

  for (int i = 0; i < N; i++) {
    if (i > 0) {
      cout << " ";
    }
    cout << ans[i];
  }
  cout << endl;
}

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


Measured memory_bytes: 1664
from collections import deque
N,K = list(map(int,input().split()))
S = list(input())
S = deque(S)
ans = 0
S_2 = [S.popleft()]
while len(S) > 0:
    if S[0] == S_2[-1]:
        ans += 1
        S.popleft()
    else:
        S_2.append(S.popleft())
cnt = 0

for i in range(1,len(S_2)-1):
    if S_2[i] != S_2[i-1] and S_2[i] != S_2[i+1]:
        ans += 2
        K -= 1
        S_2[i] = S_2[i-1]
        if K ==0:
            break
if len(S_2) == 1:
    print(ans) 
elif len(S_2) == 2:
    if S_2[0] == S_2[1] or K == 0:
        print(ans)
    else:
        print(ans + 1)
else:
    if S_2[0] != S_2[1] and S_2[-1] != S_2[-2] and K > 1:
        print(ans + 2)
    elif K == 0 or (S_2[0] == S_2[1] and S_2[-1] == S_2[-2]):
        print(ans)
    else:
        print(ans + 1)

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

#define MAX 500000
int n;

void maxHeapify(int A[], int i){
  int l = 2*i;
  int r = l + 1;
  int m, tmp;

  if(l <= n && A[l] > A[i]) m = l;
  else m = i;

  if(r <= n && A[r] > A[m]) m = r;

  if(m != i){
    tmp = A[i];
    A[i] = A[m];
    A[m] = tmp;
    maxHeapify(A, m);
  }
}

void buildMaxHeap(int A[]){
  for(int i = n/2; i > 0; i--){
    maxHeapify(A,i);
  }
}

int main(){
  int A[MAX+1];

  cin >> n;

  for(int i = 1; i <= n; i++){
    cin >> A[i];
  }

  buildMaxHeap(A);

  for(int i = 1; i <= n; i++){
    cout << " " << A[i];
  }
  cout << endl;



}

Measured memory_bytes: 3112
N = int(input())
S = list(str(input()))

tmp = 0
count = 0
for i in S:
  if i == "A":
    tmp = 1
  elif i == "B" and tmp == 1:
    tmp = 2
  elif i == "C" and tmp == 2:
    count += 1
    tmp = 0
  else:
    tmp = 0
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define reup(a, b) for(int i = a; i <= b; ++i)

int main(void) {
    int x, y, z;
    while(cin >> x >> y >> z) {
        cout <<  (x - z) / (y + z) << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		Integer a = Integer.valueOf(r+g+b);

		if (a % 4 == 0) {
			System.out.println("YES");

		} else {
			System.out.println("NO");
		}

	}

}

Measured memory_bytes: 38948
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <map>

using namespace std;

void solve()
{
	int N, x;
	cin >> N >> x;
	vector<unsigned long long int> a(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
	}
	unsigned long long int ans = 0;
	if (a[0] > x)
	{
		ans += a[0] - x;
		a[0] = x;
	}
	for (int i = 0; i < N - 1; ++i)
	{
		if (a[i] + a[i + 1] <= x)
		{
			continue;
		}
		else
		{
			unsigned long long int temp = a[i] + a[i + 1] - x;
			if (a[i + 1] > temp)
			{
				ans += temp;
				a[i + 1] -= temp;
			}
			else
			{
				ans += a[i + 1];
				temp -= a[i + 1];
				a[i + 1] = 0;
				ans += temp;
				a[i] -= temp;
			}
		}
	}
	cout << ans << endl;
}

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

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

using namespace std;

#define ff first
#define ss second
#define int long long
#define pii pair<int,int>

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,i,j,m;
	cin>>m>>n;
	int memo[n+1];
	for(i=1;i<n+1;i++)memo[i]=-1;
	memo[0]=0;
	for(i=0;i<m;i++){
		pii novo;
		cin>>novo.ff>>novo.ss;
		for(j=n-novo.ff;j>=0;j--){
			if(memo[j]!=-1){
				memo[j+novo.ff] = max(memo[j+novo.ff],memo[j]+novo.ss);
			}
		}
	}
	int maior=-1;
	for(i=0;i<n+1;i++){
		if(memo[i]>maior)maior=memo[i];
	}	

	cout<<maior<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 5005;
const int MOD = 1e9 + 7;

int n,len;
int head[MAXN],f[MAXN][MAXN],g[MAXN],size[MAXN];

namespace ModOperation{
	int addMod(int x,int y){
		x += y;
		if(x >= MOD)
			x -= MOD;
		return x;
	}
	
	int subMod(int x,int y){
		x -= y;
		if(x < 0)
			x += MOD;
		return x;
	}
	
	int mulMod(int x,int y){
		return 1ll * x * y % MOD;
	}
}

using namespace ModOperation;

struct Edge{
	int to,next;
} e[MAXN << 1];

void add(int u,int v){
	e[++len].to = v;
	e[len].next = head[u];
	head[u] = len;
}

void dfs(int u,int fa){
	static int tmp[MAXN];
	size[u] = 1;
	f[u][1] = 1;
	for(int i = head[u];i != -1;i = e[i].next){
		int v = e[i].to;
		if(v == fa)
			continue;
		dfs(v,u);
		for(int i = 1;i <= size[u] + size[v];i++)
			tmp[i] = 0;
		for(int i = 1;i <= size[u];i++){
			for(int j = 0;j <= size[v];j++)
				tmp[i + j] = addMod(tmp[i + j],mulMod(f[u][i],f[v][j]));
		}
		for(int i = 1;i <= size[u] + size[v];i++)
			f[u][i] = tmp[i];
		size[u] += size[v];
	}
	for(int i = 2;i <= size[u];i += 2)
		f[u][0] = subMod(f[u][0],mulMod(f[u][i],g[i]));
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i = 1;i < n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	g[0] = 1;
	for(int i = 2;i <= n;i += 2)
		g[i] = mulMod(g[i - 2],i - 1);
	dfs(1,0);
	printf("%d\n",subMod(0,f[1][0]));
	return 0;
}



Measured memory_bytes: 97280
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,m,i,j=0,sum=0;
   cin>>n>>m;
   int arr[n+1];
   for(i=0;i<n;i++)
   {
       cin>>arr[i];

   }
   for(i=0;i<n;i++)
   {
       sum=sum+arr[i];
   }
   for(i=0;i<n;i++)
   {
       if(arr[i]>=(double(sum)/(4*m)))
       j++;

   }
   j>=m?cout<<"Yes"<<endl:cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];

    int tmp = n-k;
    int ans = 1;
    while(tmp > k-1){
        tmp -= k-1;
        ans++;
    }
    if(tmp != 0)ans++;
    cout << ans << endl;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

K = ii()
n = 7 % K
cnt = 1
flag = [0] * K
flag[n] = 1

while True:
    if n == 0:
        print(cnt)
        exit()
    n = (n * 10 + 7) % K
    if flag[n]:
        print(-1)
        exit()
    cnt += 1
    flag[n] = 1

Measured memory_bytes: 16784
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
int g(long long p){//逆元
    long long x=1;
    for(int i=mod-2;i>0;i/=2){
        if(i%2){
            x*=p;
            x%=mod;
        }
        p*=p;
        p%=mod;
    }
    return x;
}
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    long long ans=0;
    long long M[n];//m-1の累乗
    M[0]=1;
    for(int i=1;i<n;i++)M[i]=M[i-1]*(m-1)%mod;
    long long c=1;
    for(long long i=1;i<=k+1;i++){
        ans+=M[n-i]*c;
        ans%=mod;
        c*=(n-i)*g(i)%mod;
        c%=mod;
    }
    cout<<(ans*m)%mod<<endl;
    return 0;
}

Measured memory_bytes: 5132
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	for (int i = 1; i < 10000000; i++) {
		if (Y * i + Z * (i + 1) <= X) {

		}
		else {
			cout << i - 1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
using namespace std;
int main(void){
    string a,b;
    cin>>a>>b;
    int k=0;
    for(int i=0;i<a.size();i++){
        if(a[i]==b[i]){
        k++;
    }
    }
    
    cout<<a.size()-k;
    return 0;
}


Measured memory_bytes: 3928
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

bool from1[2505];
bool fromN[2505];
bool ok[2505];
vector<vl> G(2505);
vector<vl> rG(2505);



int main(){
    ll a,b,c; cin >> a >> b >> c;
    if(b-a == c-b) puts("YES");
    else puts("NO");
}


Measured memory_bytes: 384
import collections

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

B = collections.Counter(A)
#print(B)

C = list(B.keys())
#print(C)

ans = 0
for c in C:
    if c != B[c] and B[c] > c:
        ans += B[c]-c
    elif c != B[c] and B[c] < c:
        ans += B[c]
print(ans)

Measured memory_bytes: 93596
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  vector<string> S(N);
  rep(i, N) cin >> S[i];

  vector<vector<int>> S_int(N, vector<int>(10));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 10; j++){
      S_int[i][j] = int(S[i][j] - 'a');
    }
  }

  for(int i = 0; i < N; i++){
    sort(S_int[i].begin(), S_int[i].end());
  }

  sort(S_int.begin(), S_int.end());


  ll ans  = 0;
  int pos = 0;
  while(pos < N-1){
    ll cnt = 1;
    int endI;
    bool flag = true;
    for(int j = pos+1; j < N; j++){
      for(int k = 0; k < 10; k++){
        if(S_int[pos][k] != S_int[j][k]){
          flag = false;
          break;
        }
      }
      if(flag)cnt++;
      else{
        endI = j;
        break;
      }
      if(j == N-1) endI = N;
    }
    pos = endI;
    ans += cnt * (cnt -1) /2;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 14336
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
### 素数の逆元とCombination

M = 10**9+7 # 出力の制限
N = n+10 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

from collections import Counter
c = Counter(a)
t = []
for i,num in enumerate(a):
    if c[num]==2:
        t.append(i)
i0, i1 = t
n0 = i0
n1 = i1-i0-1
n2 = n - i1
ans = [None]*(n+1)
for k in range(1, n+2):
    if k==1:
        val = n
    else:
        val = cmb(n-1, k, M) + cmb(n-1, k-2, M) + (cmb(n-1, k-1, M) - cmb(n0+n2, k-1, M))*2 + cmb(n0+n2, k-1, M)
        val%= M
    ans[k-1] = val
write("\n".join(map(str, ans)))

Measured memory_bytes: 110536
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll A,B,V,W,T;
    cin>>A>>V>>B>>W>>T;
    if(V<=W)cout<<"NO"<<endl;
    else{
        ll dis=abs(A-B);
        if((V-W)*T>=dis)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;

constexpr int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

// 高速nCk（n == 10**9まで対応）
mint nCk(int n, int k) {
  mint x = 1, y = 1;
  for (int i = 0; i < k; i++) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

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

  ll n, k;
  cin >> n >> k;

  mint maxx = mint(0);
  vector<mint> maxv(n + 10);
  for (int a = 0; a < n + 1; a++) {
    maxx += mint(n - a);
    maxv[a + 1] = maxx;
  }

  mint minn = mint(0);
  vector<mint> minv(n + 10);
  for (int a = 1; a <= n + 1; a++) {
    minn += mint(a);
    minv[a + 1] = minn;
  }

  mint ans = mint(0);
  for (int c = k; c <= n + 1; c++) {
    maxv[c];
    minv[c];

    mint cnt = maxv[c] - minv[c] + mint(1);

    ans += cnt;
  }

  cout << ans.x << ln;

  return 0;
}

Measured memory_bytes: 6348
x, y, a, b, c = map(int, input().split())
ps = sorted(list(map(int, input().split())), reverse=True)[:x]
qs = sorted(list(map(int, input().split())), reverse=True)[:y]
rs = list(map(int, input().split()))
apples = sorted(ps + qs + rs, reverse=True)
print(sum(apples[:x+y]))


Measured memory_bytes: 108780
#include<iostream>
using namespace std;
int n,a[100];
main()
{
    while(cin>>n,n)
    {
        for(int i=0;i<n;i++)cin>>a[i];
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i;j<n;j++)cnt+=a[i]>a[j];
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main(){
int A;
char B;
int C;
char D;
int E;
cin>>A>>B>>C>>D>>E;
if(A<2019){
    cout<<"Heisei"<<endl;
}
else if(A==2019){
    if(C<=4){
        cout<<"Heisei"<<endl;
    }
    else 
    cout<<"TBD"<<endl;
}
}

Measured memory_bytes: 3596
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
string S;
int cnt=0;
int main()
{
    cin >> S;
    if(S[0]!='A' || S[1]=='C' || S[S.length()-1]=='C')
        cout << "WA" << endl;
    else
    {
        for(int i=1; i<S.length(); i++)
        {
            if(S[i]=='C' && cnt==0)
            {
                cnt++;
                continue;
            }
            else if(S[i]=='C' && cnt!=0)
            {
                cout << "WA" << endl;
                return 0;
            }
            if(S[i]<'a' || S[i]>'z')
            {
                cout << "WA" << endl;
                return 0;
            }

        }
        if(cnt)
            cout << "AC" << endl;
        else
            cout << "WA" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	if(n%2==1){
		cout<<"No"<<endl;
	}else{
		int ret=n/2;
		string t;
		rep(i,ret) t+="hi";
		if(s==t) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    long n = 0;
    
    cin >> n;
    vector < long > lists, arr;
    
    for(int i = 0; i < n; i++){
        long temp;
        cin >> temp;
        lists.push_back(temp);
        arr.push_back(temp);
    }
    
    sort(lists.begin(), lists.end());
    
    if (lists[n/2-1] == lists[n/2]) {
        for(int i = 0; i < n; i++){
            cout << lists[n/2] << endl;
        }
        return 0;
    }
    
    for(int i = 0; i < n; i++){
        if(arr[i] < lists[n/2]) cout << lists[n/2] << endl;
        if(arr[i] > lists[n/2-1]) cout << lists[n/2-1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 5476
import Data.List

main=do
  [n,k]<-map read.words<$>getLine :: IO [Int]
  s<-getLine
  print $ solve n k s

solve n k s = go ns (drop (2*k+1) ns) (sum $ take (2*k+1) ns)
  where
  go _ [] su = su
  go (n1:n2:ns) [m] su = max su (go ns [] new)
    where new = su-n1-n2+m
  go (n1:n2:ns) (m1:m2:ms) su = max su (go ns ms new)
    where new = su-n1-n2+m1+m2
  ns
    | head s == '0' = 0:cs
    | otherwise  = cs
    where cs = map length $ group s

Measured memory_bytes: 7548
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <iostream>
#include <string.h>
#include <map>
#include <set>
#include <functional>

using namespace std;

const int INF = (1<<30) - 1;

int H, W;
int dh[] = {0, 0, 1, -1};
int dw[] = {1, -1, 0, 0};

void dfs(vector<string>& field, int h, int w){
    char c = field[h][w];
    field[h][w] = '.';
    for(int i=0; i<4; i++){
        int nh = h + dh[i];
        int nw = w + dw[i];
        if(0<=nh&&nh<H && 0<=nw&&nw<W && c == field[nh][nw])
            dfs(field, nh, nw);
    }
}

int main(){
	ios::sync_with_stdio(false);
    while(cin >> H >> W, H|W){
        vector<string> field(H);
        for(int i=0; i<H; i++)
            cin >> field[i];
        
        int ans = 0;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(field[i][j] != '.'){
                    dfs(field, i, j);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const int N = 5e2 + 5;

int n, k;
int a[N];

int b[N];
bool solve(int x)
{
    for(int i = 1; i <= n; i++)
        b[i] = a[i] % x;
    sort(b + 1, b + n + 1);

    int need = 0, last = n;
    for(int i = 1; i < last; i++)
    {
        while(b[i])
        {
            while(b[last] == 0)
                last--;

            int have = x - b[last];
            if(have >= b[i])
            {
                need += b[i];
                b[last] += b[i];
                b[i] = 0;
            }
            else
            {
                b[i] -= have;
                need += have;
                b[last] = 0;
            }

            if(need > k)
                return false;
        }
    }

    return (need <= k);
}


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

    int sum = 0;

    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    int ans = 0;
    for(int i = 1; i * i <= sum; i++)
    {
        if(sum % i == 0)
        {
            if(solve(i))
                ans = max(ans, i);
            if(solve(sum / i))
                ans = max(ans, sum / i);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
n=int(input())
b=list(map(int,input().split()))

a=[b[0]]
for i in range(n-2):
  if b[i+1]<=b[i]:
    a.append(b[i+1])
  else:
    a.append(b[i])
 
a.append(b[n-2])

sum=0
for i in range(n):
  sum += a[i]
  
print(sum)
    

Measured memory_bytes: 12420
-- Question A

import Control.Applicative
import Control.Monad

main = do
  [a, b] <- map read . words <$> getLine
  putStrLn $ check a b
  
check :: Int -> Int -> String
check x y
 | x `mod` 3 == 0 = "Possible"
 | y `mod` 3 == 0 = "Possible"
 | (x+y) `mod` 3 == 0 = "Possible"
 | otherwise = "Impossible"

Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

const long long MX = 1e18;
int main() {
  long long n;
  cin >> n;

  long long ans = 1;
  bool ng = false;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || MX / ans < a) {
      ng = true;
    }
    ans *= a;
  }

  if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int N[maxn];
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;int ans=0;
	for(int i=0;i<=d/a;i++)
	for(int j=0;j<=d/b;j++)
	{
		int tmp=d-a*i-b*j;
		if(tmp>=0&&tmp%c==0) ans++;
	}
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 256
/*
  AOJ 2142
  Title:Bitwise Kingdom
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int N;
long long M;
char result[61];

int Factorization(int num,int primes[])
{
  int i,cnt;

  cnt=0;
  for(i=2;i<=num/2;i++)
    while((num % i)==0)
      {
	primes[cnt++]=i;
	num /= i;
	if(num==1)
	  return(cnt);
      }
  primes[cnt++]=num;
  return(cnt);
}

long long combi(int n, int r)
{
  int i,j,k,cnt,prime;
  long long p;
  int a[200],pr[10];

  if(r==0)
    return(1);

  for(i=0;i<r;i++)
    a[i]=n-r+i+1;

  for(i=r;i>=2;i--)
    {
      cnt=Factorization(i,pr);
      for(j=0;j<cnt;j++)
	{
	  prime=pr[j];
	  for(k=0;k<r;k++)
	    if((a[k] % prime)==0)
	      {
		a[k] /= prime;
		break;
	      }
	}
    }
  p=1LL;
  for(i=0;i<r;i++)
    p*=a[i];
  return(p);
}

solve2(int n,int r,long long m,char *prefix)
{
  int i;
  long long x;
  char buf[61];

  if(n==0)
    return;

  if(m==0)
    {
      for(i=0;i<n-r;i++)
	buf[i]='0';
      for(i=0;i<r;i++)
	buf[i+n-r]='1';
      buf[n]='\0';
      strcat(prefix,buf);
    }
  else if(m < (x=combi(n-1,r)))
    {
      strcat(prefix,"0");
      solve2(n-1,r,m,prefix);
    }
  else
    {
      strcat(prefix,"1");
      solve2(n-1,r-1,m-x,prefix);
    }
}

void solve(int n,long long m)
{
  int i;
  long long s,s1;

  if(m==0)
    {
      for(i=0;i<n;i++)
	result[i]='0';
      return;
    }
  for(i=0,s=0;i<=n;i++)
    {
      s1 = combi(n,i)+s;
      if(m<s1)
	{
	  solve2(n,i,m-s,result);
	  return;
	}
      s=s1;
    }
}

main()
{
  int i,ret;
  while(scanf("%d %lld",&N,&M)  && (N||M))
    {
      memset(result,0,sizeof(result));
      solve(N,M-1);
      
      printf("%s\n",result);
    }
  return(0);
}

Measured memory_bytes: 600
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
A=a[0]
for i in range(n-1):
    if i==0:
        ans=abs(b-2*A)
    else:
        ans=min(abs(b-2*A),ans)
    A+=a[i+1]
print(ans)


Measured memory_bytes: 24832
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        
        int N=sc.nextInt();
        int D=sc.nextInt();
        int X=sc.nextInt();
        int[] A=new int[N];
        for(int i=0;i<N;i++){
            A[i]=sc.nextInt();
        }
        
        int ans=X;
        for(int i=0;i<N;i++){
            ans+=(D-1)/A[i]+1;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23380
macro_rules! input {
    // ?
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };

    // stdinの生成 値の読み込み開始
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    // ?
    ($next:expr) => {};
    // ?
    ($next:expr, ) => {};

    // 変数名:型の読み込みの繰り返し
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    // 値を読み込むベース 型,の繰り返し
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    // 配列の読み込み
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    // 文字列Vec<char>の読み込み
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    // usize1?の読み込み
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // 指定した型で読み込み
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
pub fn main() {
    input! {
        s:String
    };

    println!("{}", solve(s));
}

fn solve(s: String) -> usize {
    let top = s.match_indices("o").count();
    return 700 + top * 100;
}
macro_rules! tests {
    ($($test_name:ident:$name:ident($( $args:expr ),*) => $expected:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $test_name() {
                    assert_eq!($expected,super::$name($($args),*));
                }
            )*
        }
    }
}


tests! {
    //テスト名:[引数]=>expected
    test1:solve("ooo".to_string()) => 1000,
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int flag=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<i+1<<" "<<i+2<<endl;
            flag=1;
            break;
        }
        else if(i<s.size()-2&&s[i]==s[i+2])
        {
            cout<<i+1<<" "<<i+3<<endl;
            flag=1;
            break;
        }
    }
    if(!flag)
    cout<<-1<<" "<<-1<<endl;
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;

	int cnt = 0;

	REP (i, 1, n + 1) {
		if (s.substr(n - i, i) == t.substr(0, i)) {
			cnt = i;
		}
	}

	cout << 2 * n - cnt << endl;

	return 0;
}

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

int main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int cnt = 0;
	for (int i = 0; i < n - 1; i++)
		if (s[i] == s[i + 1])
			cnt++;
	cout << min(n - 1, cnt + 2 * k) << '\n';
	return 0;
}


Measured memory_bytes: 3716