akhauriyash/Code-Regression huggingface dataset:
/*
D??\??????????°??????±
???????°???????T???
N?¨??????????
???j??????????°???? A??\??? B??\???????´??????? C
??£?¶?????????\????????????????´????????????¶?????????????¨?
*/
/*
1.????????????????±???????
2.????????\??¨?¬??????\??????????????§?????§??????????±??????????
3.???????????°????????????
4.?????????????????????????????????????????????
*/
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
	int D, N, T[201], A[201], B[201], C[201], max_day = 0;
	int dp[201][201];  //[????????\][?????????]
	cin >> D >> N;
	for (int i = 0; i < D; i++){
		cin >> T[i];
	}
	for (int i = 0; i < N; i++){
		cin >> A[i] >> B[i] >> C[i];
	}
	for (int i = 0; i < D; i++){
		for (int j = 0; j < N; j++){
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < D; i++){
		for (int j = 0; j < N; j++){
			if (A[j] <= T[i] && B[j] >= T[i]){//??????????????????????????????
				dp[i][j] = 0;
			}
		}
	}
	for (int i = 0; i < D; i++){
		for (int j = 0; j < N; j++){
			if (dp[i][j] >= 0){
				for (int k = 0; k < N; k++){
					if (dp[i + 1][k] >= 0){//k????????????????????????
						dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abs(C[j] - C[k]));//?´????????????¶????????´??°
					}
				}
			}
		}
	}
	for (int i = 0; i < N; i++){
		if (dp[D - 1][i] > max_day){
			max_day = dp[D - 1][i];//?????§??¶????????´??°
		}
	}
	cout << max_day << endl;
	return 0;
}

Measured memory_bytes: 3244
#ABC-126-B
S = input()
first = int(S[0]+S[1])
second = int(S[2]+S[3])

if first > 12:
    if second > 12:
        print("NA")
    elif second > 0:
        print("YYMM")
    else: #second == 00:
        print("NA")
elif first > 0:
    if second > 12:
        print("MMYY")
    elif second > 0:
        print("AMBIGUOUS")
    else: #second == 00:
        print("MMYY")
else: #first == 00:
    if second > 12:
        print("NA")
    elif second > 0:
        print("YYMM")
    else: #second ==0:
        print("NA")

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;


public class Main{

	public static void main(String args[]){
		int n=100;
		int i,j,k,v,l;
		int a[]=new int[n+1];
		 Scanner sc = new Scanner(System.in);
		k=Integer.parseInt(sc.next());
		
		for(i=0;i<k;i++){
			a[i]=Integer.parseInt(sc.next());
		}
		for(i=0;i<k;i++){
			System.out.print(a[i]);
			if(i<k-1){
			System.out.print(" ");
			}
		}
		
		System.out.println();
		for(i=1;i<k;i++){
			v=a[i];
			j=i-1;
			while(j>=0&&a[j]>v){
				a[j+1]=a[j];
			
				j--;
			}
				a[j+1]=v;
			for(l=0;l<k;l++){
				System.out.print(a[l]);
				if(l<k-1){
				System.out.print(" ");
				}
			}
			System.out.println();
			
		}
		
	}
}

Measured memory_bytes: 25788
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl;

void solve(){
	ll n[3];
	cin >> n[0] >> n[1] >> n[2];

	if(!(n[0] % 2 && n[1] % 2 && n[2] % 2)){
		cout << 0;
	}else{
		sort(n, n+3);
		cout << n[0] * n[1];
	}
	cout << endl;
}

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

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int c[20];

int main()
{
	int n,ans = 0,re = 0;
	scanf("%d",&n);
	for(int i = 1,x;i <= n;i++)
	{
		scanf("%d",&x);
		if(x < 400 && !c[1]) c[1] = true,ans++;
		else if(x >= 400 && x < 800 && !c[2])c[2] = true,ans++;
		else if(x >= 800 && x < 1200 && !c[3])c[3] = true,ans++;
		else if(x >= 1200 && x < 1600 && !c[4])c[4] = true,ans++;
		else if(x >= 1600 && x < 2000 && !c[5])c[5] = true,ans++;
		else if(x >= 2000 && x < 2400 && !c[6])c[6] = true,ans++;
		else if(x >= 2400 && x < 2800 && !c[7])c[7] = true,ans++;
		else if(x >= 2800 && x < 3200 && !c[8])c[8] = true,ans++;
		else if(x >= 3200)re++;
	}
	printf("%d %d\n",max(ans,1),ans + re);
}

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

using namespace std;

int count_ab(string &s){
	int ans = 0;
	for(int i=0; i<s.length()-1; i++){
		if(s[i] == 'A' && s[i+1] == 'B') ans++;
	}
	return ans;
}

int main(){
	
	int N;
	string tmp;
	
	int ab = 0;
	int bx = 0, xa = 0, bxa = 0;
	bool tb, ta;
	
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> tmp;
		ab += count_ab(tmp);
		tb = (tmp[0] == 'B'); ta = (tmp[tmp.length()-1] == 'A');
		bx += tb ? 1 : 0;
		xa += ta ? 1 : 0;
		bxa += ta && tb ? 1 : 0;
	}
	
	int a_ans = min(bx, xa);
	int b_ans = ab;
	if(a_ans >= N || (bx == bxa && xa == bxa && a_ans != 0)) a_ans--;
	
	//printf("bx: %d, xa: %d, bxa: %d, a_ans: %d, b_ans:%d\n", bx, xa, bxa, a_ans, b_ans);
	printf("%d\n", a_ans + b_ans);
	
	return 0;
}

Measured memory_bytes: 384
N,A,B,C,D=map(int,input().split())
S=input()
if C<B and B<D:#パターンその1
    for i in range(A-1,C-1):
        if S[i] == '#' and S[i + 1] == '#':
            print('No')
            exit()
    for p in range(B-1,D-1):
        if S[p] == '#' and S[p + 1] == '#':
            print('No')
            exit()
    print('Yes')
    exit()
elif B<C and C<D:#パターンその2
    for i in range(A-1,D-1):
        if S[i]=='#' and S[i+1]=='#':
            print('No')
            exit()
    print('Yes')
    exit()
elif D<C:#パターンその3
    for j in range(A-1,C-1):
        if S[j]=='#' and S[j+1]=='#':
            print('No')
            exit()
    if any(S[k-1]=='.' and S[k]=='.' and S[k+1]=='.' for k in range(B-1,D)):
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using ll = long long;
constexpr int DEBUG = 0;
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<vector<int>> num(10, vector<int>(10, 0));
    for (int i = 1; i <= n; i++) {
        int r = i % 10;
        int t = i;
        while (t >= 10)
            t /= 10;
        int l = t;
        if (DEBUG >= 1) {
            cout << l << "," << r << endl;
        }
        num[l][r]++;
    }
    
    if (DEBUG >= 1) {
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                cout << num[i][j] << " ";
            }
            cout << endl;
        }
    }
    
    ll total = 0;
    for (int i = 1; i <= 9; i++)
        for (int j = 1; j <= 9; j++)
            total += num[i][j] * num[j][i];
        
    cout << total << endl;
    
    return 0;
}

Measured memory_bytes: 256
DVSR = 998244353
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def II(): return int(input())

N = int(input())
INL = [II() for _ in range(N)]
SM = sum(INL)
HSM = SM//2

DP1 = [[0]*(SM+1) for _ in range(N+1)]
DP2 = [[0]*(SM+1) for _ in range(N+1)]
DP1[0][0] = 1
DP2[0][0] = 1

for i, value in enumerate(INL, 1):
    for j in range(SM+1):
        if j-value >= 0:
            DP1[i][j] = (2*DP1[i-1][j]+DP1[i-1][j-value])%DVSR
            DP2[i][j] = (DP2[i-1][j]+DP2[i-1][j-value])%DVSR
        else:
            DP1[i][j] = (2*DP1[i-1][j])%DVSR
            DP2[i][j] = DP2[i-1][j]

sub = 0
patall = POW(3, N)
for i in range(HSM+1, SM+1):
    sub += DP1[N][i]*3

if SM % 2 == 0:
    sub += 3*(DP1[N][HSM] - 2*DP2[N][HSM])
    sub += 3*DP2[N][HSM]

# print(DP2[N])
# print(SM)
print((patall - sub) % DVSR)

Measured memory_bytes: 458520
import sys
from collections import defaultdict as ddict

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

ct=ddict(int)
tt=0
for x in A:
    ct[x]+=1
    tt+=x

for _ in range(Q):
    q=next(sys.stdin)
    a,b=map(int,q.split())
    ct[b]+=ct[a]
    tt+=ct[a]*b-ct[a]*a
    ct[a]=0
    print(tt)


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

typedef long long ll;

int main()
{
  ll N, M;
  std::cin >> N >> M;

  std::vector< std::pair<ll, ll> > vp(M);
  std::vector< std::priority_queue<ll, std::vector<ll>, std::greater<ll> > > vque(N+1);
  for (ll i = 0; i < M; i++) {
    ll P, Y;
    std::cin >> P >> Y;
    vp[i].first  = P;
    vp[i].second = Y;
    vque[P].push(Y);
  }

  std::map< std::pair<ll, ll>, ll > mnum;
  for (ll p = 1; p <= N; p++) {
    ll cnt = 1;
    while (!vque[p].empty()) {
      ll y = vque[p].top(); vque[p].pop();
      mnum[std::make_pair(p, y)] = cnt;
      cnt++;
    }
  }

  for (auto pp : vp) {
    std::cout << std::setfill('0') << std::setw(6) << pp.first;
    std::cout << std::setfill('0') << std::setw(6) << mnum[std::make_pair(pp.first, pp.second)];
    std::cout << std::endl;
  }

  return 0;
}


Measured memory_bytes: 15488
/******* all required header files *******/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

/*****All definitions*******/
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define mp make_pair
#define ll long long int
#define pb push_back
#define F first
#define S second
/***************************/

int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

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

	ll n;
	cin>>n;
	vector<int> v(n);
	for(int i = 0; i < n; i++)
	{
	    cin>>v[i];
	}
	ll cnt = 0;
	ll total = 0; 
	for(int i = 0; i < n-1; i++)
	{   
	    if(v[i+1] <= v[i])
	    {
	        cnt++;
	    }
	    else cnt = 0;
	    total = max(cnt, total);
	}
	cout<<total;
	return 0;
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second


int main()
{
    ll n;
    cin >> n;
    ll a[n+2];

    ll ans=0;
    map<ll,ll> mp;

    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
        ans += mp[i-a[i]];
        mp[i+a[i]]++;
    }
    cout << ans;

    return 0;
}

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

using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)



signed main()
{
	int n;
	cin >> n;
	string str;
	cin >> str;
	vector<bool> checker(n,false);
	int n1 = 0, n2 = 0;
	REP(i, n) 
	{
		if (checker[i] == false) 
		{
			if (str[i] == '(') 
			{
				if (i != n)
				{
					FOR(j, i + 1, n) { if (str[j] == ')' && checker[j] == false) { checker[i] = true; checker[j] = true; break; } }
				}
			}

			if (str[i] == ')')
			{
				if (i != 0)
				{
					for (int j = i; j >= 0; j--) { if (str[j] == '(' && checker[j] == false) { checker[i] = true; checker[j] = true; break; } }
				}
			}
		}
	}

	REP(i, n) {
		if (checker[i] == false) {
			if (str[i] == '(') n2++;
			else if (str[i] == ')') n1++;
		}
	}

	REP(i, n1) cout << '(';
	cout << str;
	REP(i, n2) cout << ')';
	cout << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0xfff;
const int maxn = 100005;
ll gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int main()
{
    int x[6];
    int index = 0;
    for (int i = 1; i <= 5;i++)
    {
         cin >> x[i];
        if(!x[i])
            index = i;
    }
    cout << index << endl;
    return 0;
}

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

int a[200010];
int b[200010];

int main() {
	long long n;
	long long x,m;
	long long ans;
	long long  p,p_max,p_round;
	long long ansm;
	long long mm,mn;

	cin >> n >> x >> m ;
	rep(i, m) a[i]=0;
	rep(i, m) b[i]=-1;

	p=x;
	rep(i, m){
		b[p]=i;
		p=p*p;
		p%=m;
		a[i]=p;
		if (b[p]<0){
		}else{
			p_max=i+1;
			p_round=i-b[p]+1;
	        if (p_round==0)p_round=1;
            break;
		}
	}
	if (n<5*p_max){
		ans=0;
		rep(i, n){
			ans+=x;
			x=x*x;
			x%=m;
		}
		cout << ans << endl;
		return 0;
	}
	ans=0;
	p=x;
	rep(i,p_max+1){
      	ans+=p;
      	p*=p;
      	p%=m;
	}
	ansm=0;
	rep(i,p_round){
      	ansm+=p;
      	p*=p;
      	p%=m;
	}
	mm=n-4*p_round;
	mm/=p_round;
	mn=n-mm*p_round;
 	ans=0;
	p=x;
	rep(i,mn){
      	ans+=p;
      	p*=p;
      	p%=m;
	}
	ans+=mm*ansm;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

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

  string s;
  cin >> s;
  int na, su;
  na = su = 0;
  rep(i, s.size()){
    if(s[i] == '0'){
      if(i % 2 == 0){
	na ++;
      } else {
	su ++;
      }
    } else {
      if(i % 2 == 0){
	su ++;
      } else {
	na ++;
      }
    }
  }
  cout << min(na, su) << '\n';
  return 0;
}


Measured memory_bytes: 512
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K=MI()
    edge = [[]for _ in range(N)]
    for _ in range(N-1):
        a,b = MI_()
        edge[a].append(b)
        edge[b].append(a)
    ans = inf
    if K&1: #辺が中心となり、両端点からどのへんにもD/2イカ
        for a,l in enumerate(edge):
            for b in l:
                res = 0
                q = [a,b]
                visited = set(q)
                for step in range(N-1):
                    if step*2 > (K-1):
                        res += len(q)
                    tmp = []
                    while q:
                        v = q.pop()
                        visited.add(v)
                        for u in edge[v]:
                            if u in visited:
                                continue
                            visited.add(u)
                            tmp.append(u)
                    q = tmp

                ans = min(res, ans)

    else: #点が中心となり、どのへんにもD/2イカ
        for center in range(N):
            res = 0
            q = [center]
            visited = set()
            for step in range(N-1):
                tmp = []
                if step*2 > K:
                    res += len(q)
                while q:
                    v = q.pop()
                    if v in visited:
                        continue
                    visited.add(v)
                    for u in edge[v]:
                        if u in visited:
                            continue

                        tmp.append(u)
                q = tmp
            ans = min(res, ans)
    print(ans)
if __name__ == '__main__':
    main()

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

Measured memory_bytes: 600
S = input()
chr_list = [1] * 26

if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for s in S:
        chr_list[ord(s) - ord("a")] = 0

    if all(map(lambda c: c == 0, chr_list)):
        c_set = [S[-1]]
        for i in range(24, -1, -1):
            if not ord(S[i]) > ord(S[i+1]):
                c_set = [c for c in c_set if c >= S[i]]
                print(S[:i] + min(c_set))
                break
            c_set.append(S[i])
    else:
        for i, v in enumerate(chr_list):
            if v == 1:
                print(S + chr(ord("a") + i))
                break

Measured memory_bytes: 3064
def main():

    s = list(input())
    now = 0
    ans = [''] * 10
    for i, ss in enumerate(s):
        if ss == '0':
            ans[now] = '0'
            now += 1
        elif ss == '1':
            ans[now] = '1'
            now += 1
        else:
            now -= 1
            now = max(0,now)
            ans[now] = ''
    strans = ''
    for i, a in enumerate(ans):
        if a == '':
            print(strans)
            return
        else:
            strans += a
    print(strans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
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;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    //vector<ll> X(N);
    //string s;
    //in >> s;
    //vector<string> s;
    //s.resize(N);
    ll N,M;
    in >> N >> M;
    ll ans=-1,c=0;
    vector<ll> A(M);
    REP(i,M){
        in >> A[i];
        c += A[i];
    }
    



    if(N<M){
        out << ans << endl;
    }else if(N-c >= 0){
        out << N-c << endl;
    }else{
        out << ans << endl;
    }
    
    
    
    
}

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

#define int long long

const int maxn = 2e5 + 5, mod = 1e9 + 7;
int P2[maxn], P3[maxn], C[maxn];

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	P2[0] = P3[0] = 1;
	for (int i = 1; i < maxn; i++) {
		P2[i] = P2[i - 1] * 2 % mod;
		P3[i] = P3[i - 1] * 4 % mod;
	}
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> C[i];
	sort(C, C + n);
	reverse(C, C + n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += C[i] * P2[i + 1] % mod * P3[n - i - 1] % mod * (P2[i] + P2[max(0ll, i - 1)] * i % mod) % mod;
		ans %= mod;
//		cout << i << ' ' << C[i] << ' ' << ans << endl;
	}
	cout << ans;
}


Measured memory_bytes: 4992
# ABC157 B

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A = [A1, A2, A3]
n = int(input())

for i in range(n):
    b = int(input())
    for j in range(len(A)):
        if b in A[j]:
            A[j][A[j].index(b)] = "-"

v0Count = 0
v1Count = 0
v2Count = 0
res = "No"

# 横ビンゴ確認
for k in range(len(A)):
    if A[k].count("-") == 3:
        res = "Yes"
        break
    if A[k][0] == "-":
        v0Count += 1
    if A[k][1] == "-":
        v1Count += 1
    if A[k][2] == "-":
        v2Count +=1

# 縦ビンゴ確認
if res == "No":
    if 3 in [v0Count, v1Count, v2Count]:
        res = "Yes"
    
    # 斜めビンゴ確認
    if (A[0][0] == "-" and A[1][1] == "-" and A[2][2] == "-") or (A[0][2] == "-" and A[1][1] == "-" and A[2][0] == "-"):
        res = "Yes"

print(res)

Measured memory_bytes: 3064
read*,i,j

if( i==j )then
  print*,'Draw'
  stop
end if

if(i==1)then
  print*,'Alice';stop
end if
if(j==1)then
  print*,'Bob';stop
end if


if( i>j  )then
  print*,'Alice'
elseif( j>i  )then
  print*,'Bob'
end if
end


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

int main(void){
  int a,b;
  while(1){
    cin >> a >> b;
    if(a==0 && b==0) break;
    if(a < b){
      printf("%d %d\n", a, b);
    }else{
      printf("%d %d\n", b, a);
    }
  }
  return 0;
}



Measured memory_bytes: 3224
n=int(input())
if n%10==3:
    print('bon')
elif n%10==0:
    print('pon')
elif n%10==1:
    print('pon')
elif n%10==6:
    print('pon')
elif n%10==8:
    print('pon')
else:
    print('hon')
    

Measured memory_bytes: 8952
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define MOD 100000000000009LL
#define MAX_N 100010
typedef unsigned long long ull;
vector<ull>x[MAX_N], y[MAX_N]; vector<int>G;
ull dp[MAX_N]; queue<ull>Q; ull r[MAX_N];
bool used[MAX_N];
int main() {
	int n; cin >> n;
	for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; y[a].push_back(b); y[b].push_back(a); }
	Q.push(1LL); used[1] = true;
	while (!Q.empty()) {
		ull a1 = Q.front(); Q.pop(); G.push_back(a1);
		for (int i = 0; i < (int)y[a1].size(); i++) {
			if (used[y[a1][i]] == false) { used[y[a1][i]] = true; Q.push(y[a1][i]); }
		}
	}
	for (int i = 0; i < (int)G.size(); i++)r[G[i]] = i + 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < (int)y[i].size(); j++) {
			x[r[i]].push_back(r[y[i][j]]);
		}
	}
	for (int i = n; i >= 1; i--) {
		ull sum = 0; int cnt2 = 0;
		for (int j = 0; j < (int)x[i].size(); j++) {
			if (i > x[i][j])continue;
			sum += dp[x[i][j]]; sum %= MOD; cnt2++;
		}
		dp[i] = (sum * 100009ULL + 1) % MOD;
	}
	sort(dp + 1, dp + n + 1); ull cnt = 0, cnt2 = 0;
	for (int i = 1; i <= n + 1; i++) {
		if (dp[i - 1] != dp[i]) { cnt += cnt2*(cnt2 - 1) / 2; cnt2 = 1; }
		else { cnt2++; }
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
  int N, K, sum;
  cin >> N >> K;
  
  vector<int> L(N);    
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  
  sort(L.begin(),L.end());
  reverse(L.begin(),L.end());
  
  sum = 0;
  
  for (int i = 0; i < K; i++) {
    sum = sum + L.at(i);
  } 
     
  cout << sum << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
	ll n; cin >> n;
	vvll c(10, vll(10));
	for (int i = 1; i <= n; i++) {
		string _i = to_string(i);
		c[_i[0] - '0'][_i[_i.size() - 1] - '0']++;
	}

	ll cnt = 0;
	rep(i, 10) rep(j, 10) {
		cnt += c[i][j] * c[j][i];
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <cstring>

#define mp make_pair
#define s second
#define f first
#define ll long long
using namespace std;
const ll MAX = 1e10;
ll h[100003], dp[100003];

int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
	
	int n, k;
	cin >> n >> k;
	
	for (int i=0; i<n; i++) {
		cin >> h[i];
	}
	
	dp[0] = 0;
	for (int i=1; i<n; i++) {
		dp[i] = MAX;
		for (int j=1; j<=k; j++) {
			if (i - j < 0) continue;
			dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
		}
	}
	
	cout << dp[n-1];
return 0;	
}




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


int main()
{
	int s, k, ans;
	ans = 0;
	cin >> k >> s;
	for (int x = 0; x <= k; x++)
	{
		for (int y = x; y <= k; y++)
		{
			for (int z = y; z <= k; z++)
			{
				if (x + y + z == s)
				{
					if (x < y && y<z) { ans += 6; }
					if ((x < y) && (y == z)) { ans += 3; }
					if ((x == y) && (y < z)) { ans += 3; }
					if (x == y && y== z) { ans += 1; }
				}

			}

		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

void Eratos(vector<int> &d) {
	int i, j;
	for (i = 2; i < d.size(); i++) {
		if (d[i]) {
			for (j = i << 1; j < d.size(); j += i)
				d[j] = false;
		}
	}
	return;
}

ll Pow(ll n, ll k) {
	ll ans = 1, a = n % MOD;
	while (k > 0) {
		if (k & 1) {
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		k >>= 1;
	}
	return ans;
}

ll Inverse(ll a) {
	return Pow(a, MOD - 2);
}

ll Combi(ll n, ll k) {
	k = min(k, n - k);
	if (k == 0)
		return 1ll;
	ll ans = n--, i;
	for (i = 2; i <= k; i++, n--) {
		ans *= n;
		ans %= MOD;
		ans *= Inverse(i);
		ans %= MOD;
	}
	return ans;
}

int main(void) {
	int num, m, sq, i;
	ll a, ans = 1;
	cin >> num >> m;
	sq = (int)sqrt(m);
	vector<int> d(sq + 1, true);
	Eratos(d);
	for (i = 2; i < d.size(); i++) {
		if (d[i]) {
			a = 0;
			while (m % i == 0) {
				a++;
				m /= i;
			}
			ans *= Combi(a + num - 1, a);
			ans %= MOD;
		}
	}
	if (m > 1) {
		ans *= num;
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 384
using System;

class Program {
    static void Main(string[] args) {
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        int len_s = s.Length;
        int len_t = t.Length;

        //dpテーブルを用意する
        var dp = new int[len_s, len_t];
        if (s[0] == t[0]) {
            dp[0, 0] = 1;
        } else {
            dp[0, 0] = 0;
        }
        //初期化できるところは初期化する
        for (int i = 1; i < len_s; i++) {
            if (s[i] == t[0]) {
                dp[i, 0] = 1;
            } else {
                dp[i, 0] = Math.Max(dp[i - 1, 0], dp[i, 0]);
            }
        }
        for (int j = 1; j < len_t; j++) {
            if (t[j] == s[0]) {
                dp[0, j] = 1;
            } else {
                dp[0, j] = Math.Max(dp[0, j - 1], dp[0, j]);
            }
        }

        //dp開始
        for (int i = 1; i < len_s; i++) {
            for (int j = 1; j < len_t; j++) {
                int value = 0;
                if (s[i] == t[j]) {
                    value = dp[i - 1, j - 1] + 1;
                }
                int value2 = dp[i - 1, j];
                int value3 = dp[i, j - 1];

                value = Math.Max(value, Math.Max(value2, value3));

                dp[i, j] = value;
            }
        }

        //dpの復元
        string ans = "";
        int ind_i = len_s - 1;
        int ind_j = len_t - 1;
        while (true) {
            if (ind_i >= 1 && ind_j >= 1) {
                if (dp[ind_i, ind_j] == dp[ind_i, ind_j - 1]) {
                    ind_j--;
                } else if (dp[ind_i, ind_j] == dp[ind_i - 1, ind_j]) {
                    ind_i--;
                } else {
                    ans = s[ind_i] + ans;
                    ind_i--;
                    ind_j--;
                }
            }

            //終了条件
            if (ind_i == 0 && ind_j == 0) {
                if (dp[ind_i, ind_j] == 1) {
                    ans = s[0] + ans;
                }
                break;
            } else if (ind_j == 0) {
                if (dp[ind_i, ind_j] == 1 && dp[ind_i - 1, ind_j] == 0) {
                    ans = t[0] + ans;
                    break;
                } else {
                    ind_i--;
                }
            } else if (ind_i == 0) {
                if (dp[ind_i, ind_j] == 1 && dp[ind_i, ind_j - 1] == 0) {
                    ans = s[0] + ans;
                    break;
                } else {
                    ind_j--;
                }
            }

        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 50004
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */
int powz(int v,int k) { int r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }

signed main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<std::pair<int,int> > > g(n,std::vector<std::pair<int,int> >());
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		g[a].emplace_back(b,i);
		g[b].emplace_back(a,i);
	}
	std::vector<std::pair<int,int> > qq;
	debug(n);
	int m;
	std::cin >> m;
	debug(n);
	rep(i,m) {
		int a,b;
		std::cin >> a >> b;
		debug(a,b);
		a--;b--;
		qq.emplace_back(a,b);
	}
	debug(m);
	// use dfs to color the tree
	std::vector<int> paths(n-1,0);
	rep(i,m) {
		int a=qq[i].first; int b=qq[i].second;
		std::vector<std::pair<int,int> > par(n);
		std::function<void(int,int,int)> dfs = [&] (int i, int pari,int pare) {
			par[i]=std::make_pair(pari,pare);
			for(auto to:g[i]) {
				if(to.first==pari) continue;
				dfs(to.first,i,to.second);
			}
		};
		dfs(a,-1,-1);
		int cur = b;
		while(par[cur].first!=-1) {
			paths[par[cur].second]+=(1<<i);
			cur = par[cur].first;
		}
	}
	debug(paths);

	int ans = 0;
	for(int i=0;i<(1<<(m));i++) {
		int count = 0;
		int cnt = 0;
		rep(j,m) {
			if((i>>j)&1) cnt++;
		}
		rep(j,n-1) {
			if((paths[j]&i)) count++;
		}
		debug(i,cnt,n-count-1,count);
		ans+=pow(-1,cnt)*pow(2,n-count-1);
	}
	print(ans);


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


int32_t main() {
	FAST
	int n;
	cin >> n;
	vector<int> dish(n);
	vector<int> b(n);
	vector<int> c(n - 1);
	
	for(int i = 0; i < n; i++) 
		cin >> dish[i];
	for(int i = 0; i < n; i++) 
		cin >> b[i];
	for(int i = 0; i < n - 1; i++) 
		cin >> c[i];
	
	int last = dish[0];
	int point = b[last - 1];
	for(int i = 1; i < n; i++)
	{
		point += b[dish[i] - 1];
		if(dish[i] == last + 1) point += c[last - 1];

		last = dish[i];
	}
	cout << point << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define X first
#define Y second
#define sz(v) (int)v.size()
using ord = tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update>;
 
void solve();
 
main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef ONPC
	freopen("in.txt", "r", stdin);
#endif
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}

const int N = 1e5 + 5;
const int INF = 1e9 + 7;
int n, a, b, ans, dist1[N], dist2[N];
vector<int> g[N];

void solve() {
	cin >> n >> a >> b;
	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for (int i = 1; i <= n; ++i) dist1[i] = dist2[i] = INF;
	queue<int> q;
	q.push(a);
	dist1[a] = 0;
	while (!q.empty()) {
		auto t = q.front();
		q.pop();
		for (auto d : g[t]) {
			if (dist1[d] == INF) {
				dist1[d] = dist1[t] + 1;
				q.push(d);
			}
		}
	}
	dist2[b] = 0;
	q.push(b);
	while (!q.empty()) {
		auto t = q.front();
		q.pop();
		for (auto d : g[t]) {
			if (dist2[d] == INF) {
				dist2[d] = dist2[t] + 1;
				q.push(d);
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (dist1[i] < dist2[i]) {
			ans = max(ans, dist2[i] - 1);
		}
	}
	cout << ans;
}


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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N,K,ans;
	ans = 0;
	cin >> N >> K;
	vint l(N);
	for (int i = 0; i < N; i++)cin >> l[i];

	sort(l.begin(), l.end(), greater<int>());
	for (int i = 0; i < K; i++) {
		ans += l[i];
	}
	cout << ans << endl;
}

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

string s;
int ans = 0;

signed main(){
	cin >> s;
	int o = 0, cc = 0;
	for(int i=0; i< s.length(); ++i){
		if(i > 0 && (s[i] == '<' && s[i-1] == '>')){
			if(o>= cc) ans += o*(o+1)/2 + cc*(cc-1)/2;
			else ans += o*(o-1)/2 + cc*(cc+1)/2;
			o = 1; cc = 0;
			continue;
		}
		if(s[i] == '<')++o;
		if(s[i] == '>')++cc;
	}
	if(o>= cc) ans += o*(o+1)/2 + cc*(cc-1)/2;
	else ans += o*(o-1)/2 + cc*(cc+1)/2;
	cout << ans<< "\n";
}

Measured memory_bytes: 900
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();

		for ( int i=0; i<n; i++ ) {
			int a = sc.nextInt();
			if ( a%2==0 ) {
				if ( a%3!=0 && a%5!=0 ) {
					System.out.println("DENIED");
					System.exit(0);
				}
			}
		}

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

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

int main(){
  int n;
  cin >> n;
  string ans;
  while(n != 0){
    if(n%2 != 0){
      ans = '1' + ans;
      --n;
    }else{
      ans = '0' + ans;
    }
    n /= (-2);
  }
  if(ans.size() == 0) cout << 0 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main(void)
{
  long long int bank = 100,x,count = 0;
  double adv = 1.01;
  cin >> x;
  
  while(bank < x)
  {
    bank *= adv;
    count++;
  }
  
  cout << count;
  return 0;
}

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

static const int check_number = 8;

int main() {
  int N; cin >> N;
  int answer = 0;
  for (int odd_number = 1; odd_number <= N; odd_number+=2) {
    int divisor = 0;
    for (int divide_number = 1; divide_number <= odd_number; divide_number++) {
      if (odd_number%divide_number == 0) {
        divisor++;
      }
    }
    if (divisor==check_number) {
      answer++;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define endl "\n"
#define int long long int 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 3e5 + 5  ;


int32_t main()
{ 
  IOS;
  //#ifndef ONLINE_JUDGE 
    //freopen("input.txt","r",stdin) ;
    //freopen("output.txt","w",stdout) ;
  //#endif 
  int n ;
  cin >> n ; 
  vector<int>a(5) ;
  
  int mini = 1e18 , miniind = 0 ;
  for(int i = 0 ; i < 5 ; i++ ) 
  {
    cin >> a[i] ;
    mini = min(mini,a[i]) ;

  }
  int m = (n + mini-1) / mini ;
  cout<<m+4<<endl;
  return 0 ;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(2*N);
	for(int i = 0; i < 2*N; i++) cin >> A[i];
	vector<bool> used(2*N, 0);
	for(int i = 0; i < N; i++) if(A[2*i] != -1 && A[2*i+1] != -1)
		used[A[2*i]-1] = used[A[2*i+1]-1] = 1;
	vector<int> renum(2*N, 0);
	int n = 0;
	for(int i = 2*N-1; i >= 0; i--) if(!used[i]) renum[i] = n++;
	n /= 2;
	for(int i = 0; i < 2*N; i++) if(A[2*i] == -1 || A[2*i+1] == -1) {
		if(A[2*i] != -1) A[2*i] = renum[A[2*i]-1];
		if(A[2*i+1] != -1) A[2*i+1] = renum[A[2*i+1]-1];
	}
	int n_empty = 0;
	for(int i = 0; i < 2*N; i++) if(A[2*i] == -1 && A[2*i+1] == -1) n_empty++;
	vector<bool> unpaired(2*n, 0);
	for(int i = 0; i < 2*N; i++) if((A[2*i] == -1) != (A[2*i+1] == -1)) {
		if(A[2*i+1] == -1) unpaired[A[2*i]] = 1;
		else unpaired[A[2*i+1]] = 1;
	}
	vector<int> num_unpaired(2*n, 0);
	for(int i = 1; i < 2*n; i++) num_unpaired[i] = num_unpaired[i-1] + unpaired[i-1];
	cat mod = 1000000007;
	vector< vector< vector<cat> > > dp(n+1, vector< vector<cat> >(2*n+1, vector<cat>(n+1, 0)));
	dp[0][0][0] = 1;
	for(int j = 0; j < 2*n; j++) for(int i = 0; i < n; i++) for(int k = 0; k <= n; k++) {
		if(j-2*i-k < 0) dp[i][j][k] = 0;
		if(dp[i][j][k] == 0) continue;
		if(j >= 2*i+1) {
			if(unpaired[j]) {
				dp[i+1][j+1][k] += dp[i][j][k];
				if(dp[i+1][j+1][k] >= mod) dp[i+1][j+1][k] -= mod;
			}
			else {
				if(k > 0) {
					dp[i+1][j+1][k-1] += dp[i][j][k] * k % mod;
					if(dp[i+1][j+1][k-1] >= mod) dp[i+1][j+1][k-1] -= mod;
				}
				if(j-2*i-k > 0) {
					dp[i+1][j+1][k] += dp[i][j][k] * (n_empty-i+num_unpaired[j]-k) % mod;
					if(dp[i+1][j+1][k] >= mod) dp[i+1][j+1][k] -= mod;
				}
			}
		}
		if(unpaired[j]) {
			dp[i][j+1][k+1] += dp[i][j][k];
			if(dp[i][j+1][k+1] >= mod) dp[i][j+1][k+1] -= mod;
		}
		else {
			dp[i][j+1][k] += dp[i][j][k];
			if(dp[i][j+1][k] >= mod) dp[i][j+1][k] -= mod;
		}
	}
	cout << dp[n][2*n][0] << "\n";
	return 0;
}

// look at my code
// my code is amazing


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

int main(){
    ll n, a, b; cin >> n >> a >> b;

    ll tmp = n/(a+b);
    ll ans = a*tmp;
    ll remain = n - (a+b)*tmp;
    if(remain >= a) ans += a;
    else ans += remain;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    ll x;
    cin>>x;
    for(ll a=0;;a++){
        ll tar = a*a*a*a*a-x;
        ll lb = -1000;
        ll ub = 1000;
        while(ub-lb>1){
            ll mid = (ub+lb)/2;
            if(mid*mid*mid*mid*mid<=tar){
                lb = mid;
            }
            else{
                ub=mid;
            }
        }
        if(lb*lb*lb*lb*lb==tar){
            cout<<a<<" "<<lb<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		char[] s = scanner.nextLine().toCharArray();
		char[] t = scanner.nextLine().toCharArray();
		String flg = "Yes";

		Map<Character, Character> tmap  = new HashMap<>();
		Map<Character, Character> smap = new HashMap<>();

		for(int i = 0; i < t.length; i++) {

			if(!tmap.containsKey(t[i])) {

				tmap.put(t[i], s[i]);
			}else {

				if(tmap.get(t[i]) != s[i]) {

					flg = "No";
					break;
				}
			}

			if(!smap.containsKey(s[i])) {

				smap.put(s[i], t[i]);
			}else {

				if(smap.get(s[i]) != t[i]) {

					flg = "No";
					break;
				}
			}


		}

		System.out.println(flg);
	}

}


Measured memory_bytes: 43544
package main

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

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func lineToInts(line string) []int {
	var res []int
	for _, s := range strings.Split(line, " ") {
		i, _ := strconv.Atoi(s)
		res = append(res, i)
	}
	return res
}

func judge(as, bs []int, m, c int) bool {
	calc := 0
	for j := 0; j < m; j++ {
		calc += as[j] * bs[j]
	}
	calc += c
	return calc > 0
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	line1 := lineToInts(readLine(sc))
	n, m, c := line1[0], line1[1], line1[2]

	bs := lineToInts(readLine(sc))
	res := 0
	for i := 0; i < n; i++ {
		as := lineToInts(readLine(sc))
		if judge(as, bs, m, c) {
			res++
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 640
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int X = sc.nextInt();
    
    int Max = 0;
    int[] list = new int[N];
    for(int i = 0 ; i < N; i++){
      list[i] = sc.nextInt();
      Max += list[i];
    }
    
    if(Max <= X){
      int Min = list[0];
       for(int i = 0 ; i < N; i++){
            if(list[i] < Min){
              Min = list[i];
            }
       }
      int ans1 = X -Max;
      int ans2 = ans1 / Min;
      
      System.out.println(ans2 + N);  
      
    }else{
      System.out.println("ドーナツを全種類作ることは不可能です");  
    }
    
  }  
}

Measured memory_bytes: 36044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		int n = Integer.parseInt(str);
		str = input.readLine( );
		String[] strlist = str.split(" ");
		int[] list = new int[n];
		for(int i=0; i<n; i++){
			list[i] = Integer.parseInt(strlist[i]);
		}
		Arrays.sort(list);
		System.out.println(list[n-1]-list[0]);
	}
}




Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<functional>
#include<map>
using namespace std;
typedef long long ll;
#define lscan(x) scanf("%I64d",&x);
#define lprint(x) printf("%I64d",x);
ll gcd(ll a, ll b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}
struct UnionFind {
	vector<int> par;

	UnionFind(int N) : par(N) {
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
	}

	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

ll M = 1000000007;

vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll mpow2(ll x, ll n, ll mod) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 1000000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
	}
	ifac[1000000] = mpow(fac[1000000], M - 2);
	for (ll i = 1000000; i > 0; i--) {
		ifac[i - 1] = ifac[i] * i%M;
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	return fac[a] * ifac[a - b] % M;
}
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}

vector<vector<ll>> li(222222);
int main() {
	ll n, i,ans,a,b,d[222222],p[222222],s[222222],c[222222];
	cin >> n;
	p[0] = 1;
	for (i = 0; i < n; i++) {
		c[i] = 0;
		d[i] = 0;
		s[i] = 1;
		p[i + 1] = p[i] * modinv(2) % M;
	}
	ans = n * modinv(2) % M;
	ans += (n - 2)*p[n] % M;
	ans %= M;
	for (i = 0; i < n-1; i++) {
		cin >> a >> b;
		li[a - 1].push_back(b - 1);
		li[b - 1].push_back(a - 1);
		d[a - 1]++;
		d[b - 1]++;
	}
	queue<pair<ll, ll>> que;
	for (i = 0; i < n; i++) {
		if (d[i] == 1)
			que.push(make_pair(i, 1));
	}
	while (!que.empty()) {
		ll now = que.front().first, size = que.front().second;
		que.pop();
		c[now]++;
		for (auto &e : li[now]) {
			d[e]--;
			if (c[e] == 0) {
				ans += M - p[size];
				ans %= M;
				ans += M - p[n-size];
				ans %= M;
				s[e] += s[now];
			}
			if (d[e] == 1)
				que.push(make_pair(e, s[e]));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 36992