akhauriyash/Code-Regression huggingface dataset:
//   __      __       .__           .____________                   __________        __ ________   __                 
//  /  \    /  \ ____ |_________  __| _\______   \__ __  ____  _____\______   \__ ___/  |\_____  \ |  | ______  ___.__.
//  \   \/\/   _/ __ \|  \_  __ \/ __ | |    |  _|  |  \/ ___\/  ___/|    |  _|  |  \   __/   |   \|  |/ \__  \<   |  |
//   \        /\  ___/|  ||  | \/ /_/ | |    |   |  |  / /_/  \___ \ |    |   |  |  /|  |/    |    |    < / __ \\___  |
//    \__/\  /  \___  |__||__|  \____ | |______  |____/\___  /____  >|______  |____/ |__|\_______  |__|_ (____  / ____|
//         \/       \/               \/        \/     /_____/     \/        \/                   \/     \/    \/\/     

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define PI 3.14159265358979323846

using namespace std;

void solve()
{
    ll n;
    cin >> n;
    ll ans = 0;
    vector <ll> a;
    if(n % 2 == 0)
    {
        ll cnt = 0;
        while(n % 2 == 0)
        {
            cnt++;
            n /= 2;
        }
        a.pb(cnt);
    }
    for(ll i = 3; i * i <= n; i += 2)
    {
        ll cnt = 0;
        while(n % i == 0)
        {
            n /= i;
            cnt++;
        }
        if(cnt)
            a.pb(cnt);
    }
    if(n > 2)
        a.pb(1);
    //for(auto i : a)
        //cout << i << " ";
    //cout << endl;
    for(auto i : a)
    {
        ll x = sqrt(2 * i) + 1;
        while((x + 1) * x > 2 * i)
            x--;
        //cout << "x is " << x << endl;
        ans += x;
    }
    cout << ans << endl;
    //cout << endl;
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q = 1;
	//cin >> q;
	for(int i = 1; i <= q; i++)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int nn = n;
	cout << n << ":";
	bool cnt = true;
	while (1){
		if (n % 2 == 0){
			cout << " " << 2;
			n /= 2;
			cnt = false;
		}
		else break;
	}
	while (1){
		if (n % 3 == 0){
			cout << " " << 3;
			n /= 3;
			cnt = false;
		}
		else break;
	}
	for (int i = 3; i <= nn; i += 2){
		bool gouseisuu = false;
		for (int j = 3; j <=i; j += 2){
			if (i%j == 0){
				gouseisuu = true;
				break;
			}
			if (!gouseisuu){
				while (1){
					if (n%i == 0){
						cout << " " << i;
						n /= i;
						cnt = false;
					}
					else break;
				}
			}
		}
		if (n == 1)break;
		if (n == nn && cnt == true && i >= sqrt(n))break;
	}
	if (cnt)cout << " " << nn;
	cout << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    map<int, int> m;
    Rep(x, 1, 10000){
        if(x*x>N)continue;
        Rep(y, 1, 10000){
            if(x*x+y*y>N)continue;
            Rep(z, 1, 10000){
                int ans = x*x+y*y+z*z+x*y+y*z+z*x;
                if(ans>N)break;
                m[ans]++;
            }
        }
    }
    REP(i, N){
        pr(m[i+1]);
    }
}

Measured memory_bytes: 3892
main = do
  [x,y] <- map read . words <$> getLine :: IO [Int]
  if check x == check y then putStrLn "Yes"
                        else putStrLn "No"

check :: Int -> Int
check n
  | elem n [1,3,5,7,8,10,12] = 1
  | elem n [4,6,9,11] = 2
  | otherwise = 3


Measured memory_bytes: 508
n_list=list(input())

n=[int(i) for i in n_list]

ans=str(n[0]+1)*3

if n[0]>n[1]:
    ans=str(n[0])*3

elif n[0]==n[1]:
    if n[1]>=n[2]:
        ans=str(n[0])*3
        
print(ans)


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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


ll solve(ll val)
{
	ll ans=0;
	while(val)
	{
		val %= __builtin_popcount(val);
		ans++;
	}
	return ans;
}

int main()
{
	fastio;
	ll i,n,j;
	string str;
	cin>>n>>str;
	ll ones=0;
	for(i=0;i<n;i++)
		ones+=(str[i]-'0');
	ll val1=0,val2=0;
	ll p1[200010],p2[200010];
	p1[0]=p2[0]=1;
	for(i=1;i<=n;i++)
	{
		p1[i]=(p1[i-1]*2)%(ones+1);
		if(ones>1)
			p2[i]=(p2[i-1]*2)%(ones-1);
	}
	for(i=0;i<n;i++)
	{
		val1 = (2*val1+str[i]-'0')%(ones+1);
		if(ones>1)
			val2 = (2*val2+str[i]-'0')%(ones-1);
	}
	for(i=0;i<n;i++)
	{
		if(str[i]=='0')
		{
			ll ans = (p1[n-i-1]+val1)%(ones+1);
			cout<<1+solve(ans)<<endl;
		}
		else
		{
			if(ones==1)
				cout<<"0"<<endl;
			else
			{
				ll ans = (-p2[n-i-1]+val2+ones-1)%(ones-1);
				cout<<1+solve(ans)<<endl;
			}
		}
	}
    return 0;
}





Measured memory_bytes: 6768
def main():
    n=int(input())
    A=[0]*3
    for i in map(int,input().split()):
        A[i-1]+=1
    dp=[[[0]*(n+2)for _ in range(n+2)]for __ in range(n+2)]
    for i in range(A[2]+1):
        for j in range(n-A[0]-i+1):
            for k in range(n-i-j+1):
                if i+j+k!=0:
                    dp[i][j][k]=(dp[i-1][j+1][k]*i+dp[i][j-1][k+1]*j+dp[i][j][k-1]*k+n)/(i+j+k)
    i,j,k=A
    print(dp[k][j][i])
main()

Measured memory_bytes: 507532
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

// dp[i][w] := i番目までの品物を見たとき, 重さの合計がxとなるような価値の総和の最大値
long long dp[102][100005] = { 0 };

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

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


  for (int i = 0; i < n; i++) {
    for (int sum_w = 0; sum_w <= lim_w; sum_w++) {
      // i番目の品物を選ぶとき
      if (sum_w - w[i] >= 0) {
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i]);
      }
      // i番目の品物を選ばないとき
      dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
    }
  }

  cout << dp[n][lim_w] << endl;

  return 0;
}


Measured memory_bytes: 78336
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

//using
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using LL = long long;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  for(int i=0;i<(n);i++)

//constant
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = acos(-1.0);

//debug
#define dump(x)  cout << #x << " = " << (x) << endl;

int main() {
  long double N, T, A, votT=1, votA=1;
  long int ans=INF;
  cin >> N;
  REP(i, N) {
    cin >> T >> A;
    long double q = 1;
    q = max(q, ceil(votT/T));
    q = max(q, ceil(votA/A));
    votT = q*T;
    votA = q*A;
  }
  ans = votT + votA;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
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;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 2e5 + 10;
int N, M;
int A[MAX], B[MAX];
VI G[MAX];

int dist[MAX];
int ans[MAX];
void calc_dist() {
    fill(dist, dist + MAX, INF);
    fill(ans, ans + MAX, -1);
    queue<PII> que;
    que.emplace(0, -1);
    while (!que.empty()) {
        const auto el = que.front();
        que.pop();
        if (dist[el.first] != INF) continue;
        if (el.second != -1) {
            dist[el.first] = dist[el.second] + 1;
            ans[el.first] = el.second;
        } else {
            dist[el.first] = 0;
        }
        FORE(e, G[el.first]) if (e != el.second && dist[e] == INF) {
            que.emplace(e, el.first);
        }
    }
}

int main(void) {
    cin >> N >> M;
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        G[A[i]].EB(B[i]);
        G[B[i]].EB(A[i]);
    }
    calc_dist();

    REP(i, N - 1) if (ans[i + 1] == -1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    REP(i, N - 1) {
        cout << ans[i + 1] + 1 << endl;
    }
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,C,h[200005],dp[200005],Q[400005],head=1,tail=1;
inline double slope(int j,int k){
	return 1.0*(dp[j]-dp[k]+h[j]*h[j]-h[k]*h[k])/(h[j]-h[k]);
}
signed main(){
	cin>>n>>C;
	for(int i=1;i<=n;i++)	cin>>h[i];
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[0]=dp[1]=0;Q[1]=1;
	for(int i=2;i<=n;i++){
		while(head<tail&&slope(Q[head],Q[head+1])<=2*h[i])	head++;
		int j=Q[head];
		dp[i]=dp[j]+(h[i]-h[j])*(h[i]-h[j])+C;
		while(head<tail&&slope(Q[tail],Q[tail-1])>=slope(Q[tail],i))	tail--;
		Q[++tail]=i;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 6016
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 1200000
using namespace std;
int a[N],p[N],x;
int n,ans;
int solve(){
	if(x==n-1&&p[x]==n)return true;
	x--;
	// x 是 单独一个帽子 x+1是多个帽子
	if(p[x]+p[x+1]!=n)return false;
	ans=x+1;
	ans-=p[x];//还需要的颜色
	if(ans>p[x+1]/2)return false;
	if(ans<=0)return false;
	return true;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),p[a[i]]++,x=max(x,a[i]);
	if(solve())printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010;
int n,Q;ll q,ans[N];
vector<ll> req,cnt;

int main(){
    scanf("%d%d",&n,&Q);
    req.pb(n);
    rep(i,0,Q){
        scanf("%lld",&q);
        while(sz(req) && q<=req.back()) req.pop_back();
        req.pb(q);
    }
    cnt=vector<ll>(sz(req));
    cnt.back()=1;
    for(int i=sz(req)-1;i>=0;--i){
        ll t=req[i];
        while(t>req[0]){
            int pre=lower_bound(all(req),t)-req.begin()-1;
            cnt[pre]+=t/req[pre]*cnt[i];
            t%=req[pre];
        }
        ans[t]+=cnt[i];
    }
    for(int i=n-1;i>=1;--i) ans[i]+=ans[i+1];
    rep(i,1,n+1) printf("%lld\n",ans[i]);
    return 0;
}


Measured memory_bytes: 4212
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			
			int ans = 0;
			double diff = Double.MAX_VALUE;
			for (int i = 0; i < n; i++) {
				int d = sc.nextInt();
				int h = sc.nextInt();
				int w = sc.nextInt();
				
				double d2 = Math.abs(22 - (double)w/((double)h*h/10000));
			//	System.out.println(d+" "+((double)w/((double)h*h/10000)));
				if(diff > d2){
					diff = d2;
					ans = d;
				}
			}
			System.out.println(ans);
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;
class Solution
{
    static void Main(String[] args)
    {
 
       var s= Console.ReadLine().Split();
var k=Convert.ToInt64(s[0]);
        var a =Console.ReadLine().Split().Select(c=>(Convert.ToInt64(c))).ToList();     
        a.Sort();
        //a.Add(a[0]);
        List<long> presum= new List<long>();  
        for(int i=0;i<a.Count()-1;i++){
            presum.Add(a[i+1]-a[i]);
        }
        presum.Add(k-a[a.Count()-1]+a[0]);
        var max=presum.Max();
        Console.WriteLine(k-max);
    }
}

Measured memory_bytes: 39268
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  int mas[w+1];
  memset(mas,0,sizeof(mas));
  for(int i=0,sum=0,a;i<h;i++,sum=0){
    for(int j=0;j<w;j++){
      cin >> a;
      cout << (j!=0?" ":"") << a;
      sum += a;
      mas[j]+=a;
    }
    cout << " " << sum << endl;
    mas[w] += sum;
  }
  for(int i=0;i<=w;i++){
    cout << (i!=0?" ":"") << mas[i];
  }
  cout << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

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

int pic[100][100];
int piece[4][50][50];
int n, m;

bool ck(int sy, int sx, int d){
  rep(i, m) rep(j, m){
    if(piece[d][i][j] == -1) continue;
    //    printf("%d %d\n", pic[sy+i][sx+j], piece[d][i][j]);
    if(pic[sy+i][sx+j] != piece[d][i][j]) return false;
  }
  return true;
}

int main(){
  while(scanf("%d%d", &n, &m) && n+m){
    rep(i, n) rep(j, n) scanf("%d", &pic[i][j]);
    rep(i, m) rep(j, m) scanf("%d", &piece[0][i][j]);

    REP(k, 1, 4){
      rep(i, m) rep(j, m) piece[k][j][m-i-1] = piece[k-1][i][j];
    }

    /*    rep(k, 4){
      rep(i, m){
	rep(j, m) printf("%3d", piece[k][i][j]);
	puts("");
      }
      puts("");
      }*/

    rep(i, n-m+1){
      rep(j, n-m+1){
	rep(k, 4){
	  //	  printf("%d %d %d\n", i, j, k);
	  if(ck(i, j, k)){
	    rep(l, m) rep(h, m) if(piece[k][l][h] != -1){
	      printf("%d %d\n", j+h+1, i+l+1);
	      goto end;
	    }
	  }
	}
      }
    }
    puts("NA");
  end:;
  }
  return 0;
}

Measured memory_bytes: 1272
from collections import deque

n, q = map(int, input().split())
deq = []
total = 0
for _ in range(n):
    name, time = input().split()
    deq.append([name, int(time)])

Deq = deque(deq)
ans = []
time = 0
while Deq:
    process = Deq.popleft()
    tmp = process[1]
    remain = max(tmp-q, 0)
    if remain == 0:
        time += tmp
        ans.append([process[0], time])
    else:
        time += q
        Deq.append([process[0],remain])

for name, time in ans:
    print(name, time)


Measured memory_bytes: 19580
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll ans=0;
int n;
int i;
int main()
{
    int flag=0,f2=0;
    char op;
    for(i=0;i<3;i++)
    {
        cin>>op;
        if(op=='A')
            flag=1;
        if(op=='B')
            f2=1;
    }
    if(f2==1&&flag==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}



Measured memory_bytes: 256
program ManyFormulas

implicit none
integer :: I, J
integer(8) :: len, co, checker, K
character(10) :: S
integer(8), dimension(512) :: num, counter 

read(*,*) S
len = len_trim(S)

do I = 1, 512
num(I) = 0
end do

do I = 1, 2**(len-1)
 do J = 1, 512
 counter(J) = 0
 end do
 counter(len) = len
 do J = 1, len-1
  if (btest(I-1,J-1)) then
  counter(J) = J
  end if
 end do
!write(*,*) (counter(J),J=1,3)
checker = 1
 do J = 1, len
  if (counter(J)/=0) then
  read(S(checker:counter(J)),*) K
!  write(*,*) K
  num(I) = num(I) + K
  checker = counter(J) + 1
  end if
 end do
end do

write(*,*) sum(num)
 
end program

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static final int[][] GROUPS = { { 1, 3, 5, 7, 8, 10, 12 }, { 4, 6, 9, 11 }, { 2 } };

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

        int x = sc.nextInt();
        int y = sc.nextInt();

        System.out.println(solve(x, y) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(int x, int y) {
        return findGroup(x) == findGroup(y);
    }

    static int findGroup(int n) {
        for (int i = 0;; ++i) {
            for (int v : GROUPS[i]) {
                if (n == v) {
                    return i;
                }
            }
        }
    }
}

Measured memory_bytes: 22612
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n, m;

    cin >> n >> m;

    int sum = 0;

    for (int i = 0; i < m; i++)
    {
        int x;
        cin >> x;

        sum += x;
    }

    if (sum > n)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << n - sum << endl;
    }
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

void solve(long long N, long long K, std::vector<long long> x){
    ll ans = INF;
    rep(i, N-K+1){
        ll xs = x[i], xe = x[i+K-1];
        if(xs * xe >= 0){
            ans = min(ans, max(abs(xs), abs(xe)));
        }
        else{//* xs --- 0 --- xe
            ll leng = min(abs(xs)+2*abs(xe), 2*abs(xs)+abs(xe));
            ans = min(ans, leng);
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, K, std::move(x));
    return 0;
}


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

using namespace std;

int main()
{
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int res = 0;
  int pos = Z;
  while (pos + Y + Z <= X)
  {
    res++;
    pos += Z + Y;
  }
  cout << res;
}


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

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;

int main()
{
	int n, q;
	vector<int> a;
	vector<pair<int, int>> bc;
	long long sum = 0;
	unordered_map<int, int> mp;
	cin >> n;
	while (n--) {
		int x;
		cin >> x;
		a.push_back(x);
		sum += x;
		mp[x]++;
	}
	cin >> q;
	for(int i = 0; i < q; ++i) {
		int b, c;
		cin >> b >> c;
		bc.emplace_back(b, c);
	}

	for (auto& p : bc) {
		sum += mp[p.first] * p.second - mp[p.first] * p.first;
		mp[p.second] += mp[p.first];
		mp[p.first] = 0;
		cout << sum << '\n';
	}

	return 0;
}

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

int main() {
	int H1, H2, M1, M2;
	int K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	int start, end;
	start = H1 * 60 + M1;
	end = H2 * 60 + M2;
	int output = end - start - K;
	cout << output << endl;

	return 0;
}

Measured memory_bytes: 3160
/*
 * Author: Anmol Choudhary
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<"["<<#x<<"="<<x<<"] , ["<<#y<<"="<<y<<"]"<<"\n"
const ll mod = 1000000007;
const ll maxn = 100005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
ll ok(string s){
    ll x=1;
    ll r=0;
    for(int i=s.length()-1;i>=0;i--){
        int rr=(int)(s[i]-'0');
        r+=rr*x;
        x*=10;
    }
    return r;
}
void solve()
{
    int n,m;
    cin>>n>>m;
    string s1,s2;
    char r1=(char)(n+'0');
    char r2=(char)(m+'0');
    rep0(i,m) s1+=r1;
    rep0(i,n) s2+=r2;
    ll an=max(ok(s1),ok(s2));
    pr(an);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	string a;
	cin >> a;
	ll count = 0;
	for (int z=0;z<a.size();z++){
		if (a[z] == 'x') count++;
	}
	if (count > 7) cout << "NO" << endl;
	else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int a,b,c,d,e,f;
int ansa,ansb;
double maxn;

int main(){
  cin>>a>>b>>c>>d>>e>>f;

  for(int a1=0;100*a1<=f;a1+=a){
    for(int b1=0;100*(a1+b1)<=f;b1+=b){
      for(int c1=0;100*(a1+b1)+c1<=f;c1+=c){
        for(int d1=0;100*(a1+b1)+c1+d1<=f;d1+=d){

          if((a1+b1)*e<c1+d1) continue;
          double x = 100*(a1+b1);
          double y = c1+d1;
          if(maxn<=y/(x+y)){
            maxn = y/(x+y);
            ansa=100*(a1+b1)+c1+d1;
            ansb=c1+d1;
          }
        }
      }
    }
  }

  cout<<ansa<<' '<<ansb<<endl;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,C,K; cin>>A>>B>>C>>K;
    ll sum=0;
    if (K<=A){
        sum+=K;
        K=0;
    }else{
        sum+=A;
        K-=A;
    }
    if (K<=B){
        K=0;
    }else{
        K-=B;
    }
    if (K<=C){
        sum-=K;
        K=0;
    }else{
        sum-=C;
        K-=C;
    }
    cout<<sum<<"\n";
    return 0;
}


Measured memory_bytes: 3648
# コメントの解き方だとTLE
# after = 5*10**15

s = input()
k = int(input())

'''part = 0

for i in s:
  i = int(i)
  part += i**after
  if k <= part:
    print(i)
    break'''

s_k = s[:k]
sk1_count = s_k.count('1') 

if sk1_count == k:
  print(1)
else:
  for i in s:
    i = int(i)
    if i != 1:
      print(i)
      break

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
long long int euclidean_gcd(long long int a, long long int b) {
	if (a < b) return euclidean_gcd(b, a);
	long long int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
int main() {
	string s, t;
	cin >> s >> t;
	vector<vector<int>>A(26);
	for (int i = 0; i < s.size(); i++)A[s[i] - 'a'].push_back(i);
	long long int a = 0, ans = 0;
	bool flag = true;
	for (int i = 0; i < t.size();)
	{
		int k = t[i] - 'a';
		if (A[k].size() == 0) {
			flag = false;
			break;
		}
		if (i == 0) {
			ans=A[k][0];
			i++;
		}
		else {
			if (A[k][A[k].size() - 1] <= ans) {

				ans = A[k][0];
				i++;
				a++;
			}
			else
			{
				auto it = std::upper_bound(A[k].begin(),A[k].end(), ans);
				ans = *it;
				i++;
			}
			
		}
	}
	if (flag)cout << 1 + ans + a*s.size();
	else cout << -1;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(void){
    int n, x, total = 0, i, min = 100000, l;
    scanf("%d%d", &n, &x);
    for(i = 0; i < n; i++){
        scanf("%d", &l);
        total += l;
        if(min > l)
              min = l;
    }
    printf("%d\n", ((x - total) / min) + n);
    return 0;
}


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

int main() {
  int A,N;
  cin>>N>>A;
  if (1<=N<=10000,0<=A<=1000){
    if(N % 500 <= A){
      cout<<"Yes"<<endl;
      }
    else {
      cout<<"No"<<endl;
      }
    }
  }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
//---------------------------------------
void insertionSort(vector<int> &a);  // 0-?????????????????????A
void print(vector<int> &a);
//---------------------------------------

int main(void)
{
	int num;  //??°?????????????????¨?????´??°num
	vector<int> a;
	
	cin >> num;
	
	for(int i = 0; i < num; i++){
		int num_card;  //?????????????¨?????????????????????°
		cin >> num_card;
		a.push_back(num_card);
	}
	
	insertionSort(a); //????????????
	
	return 0;
}

//------------------------------------------
void insertionSort(vector<int> &a)
{
	print(a);
	for(int i = 1; i < a.size(); i++){
		int v = a[i];  //????????????
		
		int j = i - 1;
		while(j >= 0 && a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		
		print(a);
	}
}

//--------------------------------------------
void print(vector<int> &a)
{
	if(a.size() >= 1){
	
		cout << a[0];
	}
	for(int i = 1; i < a.size(); i++){
		cout << ' ' << a[i] ;
	}
	
	cout << endl;
}

Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
 
int n,m,r;
const int INF=1e7;
int d[2][200][200],z[1000];
typedef pair<int,int> P;
 
int main(){
 
 
    while(scanf("%d %d",&n,&m),n){
	    
	   for(int i=0;i<n;i++){
		  for(int j=0;j<n;j++) d[0][i][j]=d[1][i][j]=INF;
		  d[0][i][i]=d[1][i][i]=0;
	   }
	    
	   for(int i=0;i<m;i++){
		  int x,y,t;
		  char c;
		  scanf("%d %d %d %c",&x,&y,&t,&c);
		  x--; y--;
		  
		  d[c=='L'][x][y]=min(d[c=='L'][x][y],t);
		  d[c=='L'][y][x]=min(d[c=='L'][y][x],t);
	   }
	    
	   for(int k=0;k<n;k++){
		  for(int i=0;i<n;i++){
			 for(int j=0;j<n;j++){
				d[0][i][j]=min(d[0][i][j],d[0][i][k]+d[0][k][j]);
				d[1][i][j]=min(d[1][i][j],d[1][i][k]+d[1][k][j]);
			 }
		  }
	   }
	    
	   scanf("%d",&r);
	   for(int i=0;i<r;i++){
		  scanf("%d",&z[i]);
		  z[i]--;
	   }
	    
	   vector<vector<int> > dp(1000,vector<int>(200,INF));
	   dp[0][z[0]]=0;
 
	   int res=INF;
	   for(int i=1;i<r;i++){
		  for(int j=0;j<n;j++){
						    
			 for(int k=0;k<n;k++){
				dp[i][k]=min(dp[i][k],dp[i-1][j]+d[1][z[i-1]][j]+d[0][j][k]+d[1][k][z[i]]);
			 }
			 dp[i][j]=min(dp[i][j],dp[i-1][j]+d[1][z[i-1]][z[i]]);
		  }
	   }
 
	   printf("%d\n",*min_element(dp[r-1].begin(),dp[r-1].end()));
	    
    }
}

Measured memory_bytes: 2248
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $N, $M);
$A = explode(" ", trim(fgets(STDIN)));
$ans = $N;
$sum = array_fill(1, $N, 0);
$arr = array_fill(1, $N, 0);
foreach ($A as $v) {
    // $arr[$v]++;
    manip($v, true);
    if (DEBUG) dump();
    if (DEBUG) echo $ans . PHP_EOL;
}
for ($i = 0; $i < $M; $i++) {
    if (DEBUG) printf("queue: %d/%d\n", $i + 1, $M);
    // echo "****\n";
    fscanf(STDIN, "%d %d", $X, $Y);

    // $arr[$A[$X-1]]--;
    manip($A[$X-1], false);

    $A[$X-1] = $Y;

    // $arr[$Y]++;
    manip($Y, true);

    if (DEBUG) dump();

    echo $ans . PHP_EOL;
}
if (DEBUG) echo "That's all\n";

function dump() {
    global $arr, $sum, $N;

    echo "arr: ";
    for ($x = 1; $x <= $N; $x++) {
        echo "[$x]" . $arr[$x] . " ";
    }
    echo PHP_EOL;

    echo "sum: ";
    for ($x = 1; $x <= $N; $x++) {
        echo "[$x]" . $sum[$x] . " ";
    }
    echo PHP_EOL;

}

function manip($num, $increase) {
    global $ans, $arr, $sum;
    if ($increase === true) {
        $target = $num - $sum[$num];
        if ($arr[$target] === 0) {
            $ans--;
            if (DEBUG) echo "GET!!!\n";
        }
        if (isset($arr[$target])) $arr[$target]++;
        $sum[$num]++;
    }
    if ($increase === false) {
        $target = $num - $sum[$num] + 1;
        if (isset($arr[$target]) && $arr[$target] === 1) {
            $ans++;
            if (DEBUG) echo "LOST!!!\n";
        }
        $arr[$target]--;
        $sum[$num]--;
        if ($arr[$sum] < 0) {
            exit('ERR');
        }
    }
    if (DEBUG) printf("LOG : inc:%d num:%d target:%d sum:%d\n", $increase * 1, $num, $target, $sum[$num]);
}


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

typedef long long ll;
typedef long double ld;

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

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll n, m;

    cin >> n >> m;

    cout << (n - 1) * (m - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = 0
d = {0: 1}
for i in a:
  s = (s + i) % m
  if s not in d:
    d[s] = 1
  else:
    d[s] += 1
ans = 0
for k, v in d.items():
  ans += v * (v - 1) // 2
print(ans)


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

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) a.begin(), a.end()

int bit(int a, int i) { return (a >> i) & 1; }

typedef long long ll;

const int MOD = 1e9 + 7;
const int N = 20, M = N * (N - 1) / 2;

void add(int &a, int b) {
	if ((a += b) >= MOD)
		a -= MOD;
}

int n, m, c[N][N], cnt[1 << (N - 1)];
struct Edge {
	int a, b;
} e[M];

int mask;
bool dfs(int a, int b, int p = -1) {
	if (a == b) {
		mask = 0;
		return 1;
	}
	forn(i, n)
		if (c[a][i] && i != p && dfs(i, b, a)) {
			mask |= 1 << (c[a][i] - 1);
			return 1;
		}
	return 0;
}

int f[1 << (N - 1)][M]; // 380mb = 10^6/2 * 190 * 4
int g[1 << (N - 1)][M]; 

void solve() {
	memset(c, 0, sizeof(c));
	memset(cnt, 0, sizeof(cnt));
	forn(i, m) {
		int a, b;
		cin >> a >> b, a--, b--;
		e[i] = {a, b};
		if (i < n - 1)
			c[a][b] = c[b][a] = i + 1;
		else
			dfs(a, b), cnt[mask]++;
	}

	int en = n - 1, all = 1 << en;
	forn(i, en)
		for (int mask = all - 1; mask > 0; mask--)
			if (bit(mask, i))
				cnt[mask] += cnt[mask ^ (1 << i)];

	memset(f, 0, sizeof(f[0]) * all);
	memset(g, 0, sizeof(g[0]) * all);
	f[0][0] = 1;

	forn(mask, all) {
		int bn = 0;
		forn(i, n)
			bn += bit(mask, i);
		for (int e = cnt[mask]; e > 0; e--)
			if (f[mask][e]) {
				add(f[mask][e - 1], (ll)f[mask][e] * e % MOD);
				add(g[mask][e - 1], (g[mask][e] + (ll)(en - bn) * f[mask][e]) * e % MOD);
			}
		forn(i, en)
			if (!bit(mask, i)) {
				int mask1 = mask | (1 << i), de = cnt[mask1] - cnt[mask]; 
				forn(e, cnt[mask] + 1) {
					add(f[mask1][e + de], f[mask][e]);
					add(g[mask1][e + de], g[mask][e]);
				}
			}
	}
	cout << (g[all - 1][0] + (ll)f[all - 1][0] * (en + 1) * en / 2) % MOD << endl;
}

int main() {
	while (cin >> n >> m && n)	
		solve();
}

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

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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
 
#define INF 987654321
#define IINF 2987654321987654321
#define MOD 1000000007


const int MAXN = 2e5 + 50;
ll a[MAXN];
int main() {
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);

	vector<ll> v;
	for(int i = 1; i <= n; i++)
		v.push_back(a[i] - i);
	sort(v.begin(), v.end());
	ll mid = v[(int)v.size()/2], sum = 0;
	for(int i = 1; i <= n; i++)
		sum += abs(a[i] - (mid + i));
	printf("%lld\n", sum);
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for(long long int (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long int (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pb push_back
#define mp make_pair
#define debugx cout << "DONE" << endl;
const unsigned int mod = 1e9+7;
const int mx=100005;
int n;
vector <int > v[mx];//0-black  1-white
int dp[mx][2];
long long solve(ll x,ll par,int co){
	if(dp[x][co]!=-1)return dp[x][co];
	if(v[x].size()==0 or (v[x].size()==1 and v[x][0]==par))return 1;
	/*if(x==2)cout << 2 << endl;
	else if(x==3)cout << 3 << endl;
	else if(x==4)cout << 4  << endl;
	else if(x==1)cout << 1<< endl;*/
	ll sum=1;
	for(int i=0;i<v[x].size();++i){
		if(v[x][i]!=par){
			if(co)
				{sum=(sum*(solve(v[x][i],x,1)+solve(v[x][i],x,0)))%mod;}
			else 
				{sum=(sum*(solve(v[x][i],x,1)))%mod;}
		}
	}
	dp[x][co]=sum%mod;
return dp[x][co];
}
int main(){
	/*freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);*/  
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> n;
	rep(i,n-1){
		int x,y;cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	rep(i,mx)rep(j,2)dp[i][j]=-1;
	//cout << (solve(1,-1,1)) << endl <<(solve(1,-1,0)) << endl;  
	cout << ((solve(1,-1,1))+(solve(1,-1,0)))%mod << endl;//gonderdigin renge dikkat
}

Measured memory_bytes: 16256
#include <stdio.h>
#define TRUE 1
#define FALSE 0

int n1,array[2001];

int caluc(int,int);

int main(){
  int n2,i,value,result;
  
  scanf("%d",&n1);
  for(i=0;i<n1;i++)scanf("%d",&array[i]);

  scanf("%d",&n2);
  for(i=0;i<n2;i++){
    result = 0;
    scanf("%d",&value);
    
    result = caluc(0,value);
    if(result == TRUE)printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int caluc(int i,int m){
  int result;
  
  if(m == 0) return TRUE;
  if(i >= n1) return FALSE;
  result = caluc(i+1,m)||caluc(i+1,m-array[i]);
  return result;
}



Measured memory_bytes: 2104
import std.stdio : write, writeln, writefln, stdin;
import std.array;
import std.range;
import std.typecons;
import std.algorithm : max, min;

void main(){
	bool[3000] y;
	foreach(i; 3000.iota){
		y[i] = i%4==0 && i%100!=0 || i%400==0;
	}
	
	bool first=true;
	while(true){
		int a = next!int();
		int b = next!int();
		if((a|b)==0){ break; }
		
		if(first){
			first = false;
		}else{
			writeln;
		}
		
		bool done;
		for(int i=a; i<=b; ++i){
			if(y[i]){
				writeln = i;
				done |= true;
			}
		}
		
		if(!done){
			writeln = "NA";
		}
	}
}


import std.stdio : readln, chomp;
import std.conv : to;
import std.string : split;
shared string[] input;
shared string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

void next(T)(ref T v){
	v = next!T();
}

bool hasNext(){
	if(input.length > 0){
		return true;
	}
	
	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return true;
	}else{
		return false;
	}
}


void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}
	
	return v_;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint h,w,K;std::cin>>h>>w>>K;
    std::vector<std::vector<lint>>a(h,std::vector<lint>(w+1));
    for(lint i=0;i<h;i++){
        for(lint j=1;j<=w;j++){
            char c;std::cin>>c;
            a.at(i).at(j)=a.at(i).at(j-1)+(c=='1');
        }
    }
    lint H=1ll<<h;
    lint ans=h*w;
    for(lint bs=H/2;bs<H;bs++){
        std::vector<std::vector<lint>>b;
        for(lint i=0,j=0;j<h;j++){
            if(bs>>j&1){
                std::vector<lint>c(w+1);
                for(lint k=i;k<=j;k++){
                    for(lint l=0;l<=w;l++){
                        c.at(l)+=a.at(k).at(l);
                    }
                }
                b.push_back(std::move(c));
                i=j+1;
            }
        }
        lint sz=__builtin_popcountll(bs);
        lint now=sz-1;
        bool ng=false;
        for(lint i=0;i<sz;i++){
            for(lint j=0;j<w;j++){
                if(K<b.at(i).at(j+1)-b.at(i).at(j)){
                    ng=true;
                    break;
                }
            }
            if(ng)break;
        }
        if(ng)continue;
        for(lint i=0,j=0;j<=w;j++){
            bool ng=false;
            for(lint k=0;k<sz;k++){
                if(j==w||K<b.at(k).at(j+1)-b.at(k).at(i)){
                    ng=true;
                    break;
                }
            }
            if(ng){
                if(j!=w)now++;
                i=j;
            }
        }
        if(now<ans)ans=now;
    }
    std::cout<<ans<<'\n';
}


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int x, y;
    cin >> x >> y;
    for (int i = 1; i <= 1500; ++i) {
    	int a = i * 0.08;
    	int b = i * 0.1;
    	if (a == x && b == y) {
    		cout << i << '\n';
    		exit(0);
    	}
    }
    cout << -1 << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define L_T_S_K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
const int mod = 1e9 + 7;
const int N = 1e5 + 9;

int32_t main(){
 L_T_S_K;
 int t;
 string s , ss;
 cin >> t >> s >> ss;
 int f = 1 , i = 0 , j = 0;
 int n = 2 * s.size();
 string ans = "";
 while(n--){
  if(f){f--;cout << s[i++];}
  else{f++;cout << ss[j++];}
 } 
 return 0;
}

Measured memory_bytes: 256
#coding: utf-8

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

L = {}
for i, a in enumerate(A):
    k = i + a
    if k not in L:
        L[k] = 1
    else:
        L[k] += 1

count = 0
for j, a in enumerate(A):
    k = j - a
    if k in L:
        count += L[k]
print(count)


Measured memory_bytes: 40660
import itertools
n = int(input())
work_lst = []

for _ in range(n):
    a,b = map(int,input().split())
    work_lst.append((a,b))

work_lst.sort(key=lambda x: x[1])
work_acc = [i[0] for i in work_lst]
work_acc = itertools.accumulate(work_acc)
work_dead = [i[1] for i in work_lst]
for x, dead in zip(work_acc, work_dead):
    if x > dead:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 37532
H, W = map(int, input().split())

diff = float("inf")

for h in range(1, H):
    sa = h * W
    nw = W // 2
    sb = (H - h) * nw
    sc = (H - h) * (W - nw)
    diff = min(diff, max(sa, sb, sc) - min(sa, sb, sc))

    nh = (H - h) // 2
    sb = nh * W
    sc = (H - h - nh) * W
    diff = min(diff, max(sa, sb, sc) - min(sa, sb, sc))

for w in range(1, W):
    sa = w * H
    nh = H // 2
    sb = (W - w) * nh
    sc = (W - w) * (H - nh)
    diff = min(diff, max(sa, sb, sc) - min(sa, sb, sc))

    nw = (W - w) // 2
    sb = nw * H
    sc = (W - w - nw) * H
    diff = min(diff, max(sa, sb, sc) - min(sa, sb, sc))

print(diff)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[114514];
signed main(){
    int n,m;
    cin>>n>>m;
    a[1]=1;
    a[2]=2;
    for(int i=3;i<114514;i++){
        a[i]=(a[i-1]*i)%1000000007;
    }
    if(abs(n-m)>1){
        cout<<0<<endl;
    }
    else if(abs(n-m)==1){
        cout<<(a[n]*a[m])%1000000007<<endl;
    }
    else{
        cout<<(2*a[n]*a[m])%1000000007<<endl;
    }
}

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(A.rbegin(), A.rend());

  unordered_map<int, int> count;
  int answer = 0;
  rep(i, N) {
    bool use = false;
    rep(j, 30) {
      int k = (1 << (j + 1)) - A[i];
      if (count.count(k) && count[k] > 0) {
        ++answer;
        count[k]--;
        use = true;
        break;
      }
    }
    if (!use) count[A[i]]++;
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 12140
#include<bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int mod = 1e9+7;
#define MAXN 3000009
int fat[MAXN];
void preprocess_fat(){
    fat[0] = 1;
    for(int i=1; i<MAXN; ++i)
        fat[i]=(i*fat[i-1])%mod;
}
int ext_gcd(int a, int b, int& x, int& y){
    if(b==0){
        x=1; y=0; return a;
    }
    else{
        int g = ext_gcd(b, a%b, y, x);
        y-=a/b*x; return g;
    }
}
int mod_inv(int a){
    int x, y;
    ext_gcd(a, mod, x, y);
    return (x%mod+mod)%mod;
}
int calc(int a, int b){
	return (fat[a]*((mod_inv(fat[b])*mod_inv(fat[a-b]))%mod))%mod;
}
int32_t main(){
	ios::sync_with_stdio(0);
	preprocess_fat();
	int x, y;
	cin >> x >> y;
	int ans = 0;
	for(int a=0; a<MAXN; ++a){
		int b = y-2LL*a;
		if(b<0) break;
		if(x==2LL*b+a and y==2LL*a+b){
			if(b>a) swap(a, b);
			ans = calc(a+b, a);
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 23680
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    ll a[100];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a + N, greater<int>());
    ll alice = 0, bob = 0;
    for(int i = 0; i < N; i++){
        if(i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	char t[52][52] = { '.' };
	char m[2];
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> t[i][j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			int n = 0;
          if(!(t[i][j] == '#')){
			for (int k = -1; k <= 1; k++) {
				for (int l = -1; l <= 1; l++) {
					if(t[i+k][j+l] == '#'){
							n++;
		
					}
				}
			}
			sprintf(m, "%d", n);
			t[i][j] = m[0];
          }
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cout << t[i][j];
		}
		cout << endl;
	}

	return 0;
}


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

double f(double x){
  if(x < 0){x *= (-1);}
  return x;
}

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  double sum = 0;
  for(int i = 0; i < n; i++){
    cin >> v[i];
    sum += v[i];
  }

  double ave = sum / 2;
  double sum1 = v[0];
  double res = f(ave - v[0]);
  double memo;
  if(n == 2){cout << fixed << setprecision(0); cout << f(v[0] - v[1]) << endl;}
  else{
  for(int i = 1; i < n -1; i++){
    sum1 += v[i];
    if(f(sum1 - ave) < res){res = f(sum1 - ave); memo = sum1;}
  }
  cout << fixed << setprecision(0);
  //cout << memo << endl;
  //cout << res << endl;
  cout << f(sum - memo * 2)  << endl;
  }
}       

Measured memory_bytes: 1024