akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int maxn = 2e5 + 5;
const int P = 1e9 + 7;

int n, k, D[maxn];

inline int read(){
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)){if(ch == '-')f = -1; ch = getchar();}
	while(isdigit(ch)){u = u * 10 + ch - 48; ch = getchar();} return u * f; 
}

inline bool check(int x) {
	while(x) {
		if(D[x % 10])return false;
		x /= 10;
	} return true;
}

int main(){
	n = read(); k = read();
	for(register int i = 1; i <= k; i++) D[read()] = 1;
	for(register int i = n; i <= maxn; i++)
		if(check(i)) {cout << i; return 0;}
	return 0;
}

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

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

#define INF (1<<29)
const int MAX = (1<<16)+1;

int N;
int memo[MAX];
vector< vector<int> > vvs;

int dfs(int bit)
{
	if (memo[bit] != -1) return memo[bit];
	if (bit == (1<<N)-1) return memo[bit] = 0;

	int ans = INF;
	rep(i, N) {
		if ((bit>>i)&1) continue;
		int d = vvs[i][0];
		rep(j, N)
			if ((bit>>j)&1)
				d = min(d, vvs[i][j+1]);
		ans = min(ans, dfs(bit|(1<<i))+d);
	}
	return memo[bit] = ans;
}

int main(void)
{
	while (cin >> N, N) {
		memset(memo, -1, sizeof(memo));

		vvs = vector< vector<int> >();
		rep(j, N) {
			vector<int> vs = vector<int>(N+1);
			rep(i, N+1)
				cin >> vs[i];
			vvs.push_back(vs);
		}

		int ans = INF;
		rep(i, N)
			ans = min(ans, dfs(1<<i)+vvs[i][0]);
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
  string s = "",n;
  cin >> n;
  for(int i = 0;i < n.size();i++){
    if(n[i] == '0') s.push_back('0');
    else if(n[i] == '1') s.push_back('1');
    else if(s.size() != 0) s.pop_back();
  }
  cout << s << endl;
}


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<PA, vector<PA> > PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int n, a, b;

signed main()
{
    cin >> n;
    if(n < 1200){
        printf("ABC\n");
    }
    else if(n < 2800){
        printf("ARC\n");
    }
    else{
        printf("AGC\n");
    }


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){

     long long int n;

    scanf("%lld",&n);
if(n>=1 && n<=pow(10,9)){
    for(int i=1; i<=n;i++){
            
        if(n==2){
            printf("1");
            exit(0);
        }
        if(i==sqrt(n)){
            printf("%d",(int)pow(i,2));
            exit(0);
        }

        else if(i>sqrt(n)){
            printf("%d",(int)pow(i-1,2));
            exit(0);
        }
    }
}

}

Measured memory_bytes: 128
//containing t test cases
#include<bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define scan(n) ll a[n]; for(ll i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define pi 3.1415926535897932384626433832795028841971
//#define int long long
using namespace std;
//typedef vector<int>vi ;
typedef vector<ll>vi ;
typedef vector<vector<ll> >vvl ; 
typedef pair<ll,ll> pll ;
typedef vector<pair<ll,ll> > vpll;
//cout<<fixed<<setprecision(15);
/*vi adj[200005];
ll vis[200005];
ll parent[200005];
ll level[200005];
ll arr[200005];
ll size[200005];*/
//endl mut bhool!!
void solve()
{
    ll n;
    cin>>n;
    scan(n);
    ll prod=1;
    ll m=1000000000000000000;
    sort(a,a+n);
    if(a[0]==0)
    {
    	cout<<"0";
    		return;
	}
    rep(i,0,n)
    {
    	ll x=m/prod;
    	if(a[i]>x)
    	{
    		cout<<"-1";
    		return;
    	}
        prod*=a[i];
       /* if(prod>1000000000000000000 || prod<=0)
        {
            cout<<"-1";
            return;
        }*/
    }
    cout<<prod;
}
int main()
{
    fast;
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    return 0;
}
/*
cout<<"YES"<<endl;
cout<<"NO"<<endl;
*/


Measured memory_bytes: 4440
/*
    Author : Pranav_Raut.
*/

#include<bits/stdc++.h>
using namespace std;
#define input(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}
typedef long long int ll;
ll MOD = 1000000007;
ll MAXN = 100005;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t = 1;
    while(t--)
    {
        /* JUST CODE TILL YOU CRACK IT !!! */
		ll n;
      	cin>>n;
      	ll arr[n+1];
      	input(arr,n);
      	arr[n] = arr[n-1];
      	ll ans[n+1];
      	ans[n-1] = 0;
      	ans[n] = 0;
      	for(ll i=n-2;i>=0;--i)
        {
        	ans[i] = min(abs(arr[i]-arr[i+1])+ans[i+1],abs(arr[i]-arr[i+2])+ans[i+2]);
        }
      	cout<<ans[0]<<endl;
    }
    return 0;
}


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

using namespace std  ; 

const int N = 3e3 + 7; 

int n , k , mod = 1e9 + 7 ; 
long long C[N][N];

void pre(){
        C[0][0] = 1ll ; 
        for(int i =1 ; i<N;i++){
                for(int j = 0 ;j <=i;j++){
                        if(!j || j ==i ){
                                C[i][j] = 1ll ; 
                        }
                        else{
                                C[i][j] = (C[i-1][j] + C[i-1][j-1]) %mod ; 
                        }
                }
        }
}

long long snb(long long x , long long y){
        if(x == y) return 1ll ; 
         x-=y ; 
         if(y - 1< 0 || x  < 0 )
                return 0ll ; 
         return C[x+y-1][y-1] ; 
}

int main(){
        ios_base::sync_with_stdio(0) ; 
        cin.tie(0) ; 
        pre() ; 
        cin>>n>>k ; 
        long long ans =1ll ; 
        for(int i = 1 ;i<=k;i++){
                long long mys = snb(k , i) ; 
                ans = (1ll * mys * snb(n - k  ,  i -1) ) %mod  ;
                if( i *2 <=n){
                        ans =ans +  2ll  * ( snb(n - k , i) * mys) %mod   ; 
                        ans%=mod ; 
                }
                if(i*2+1<=n){
                        ans = (ans + (snb(n - k , i+1) * mys)%mod ) %mod ; 
                }
                cout<<ans<<"\n" ;        
        }
        return 0; 
}

Measured memory_bytes: 69248
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;

vector<int> zyun;
void fn( int A, int B ){
  if( A == 0 ){
    zyun.push_back(B);
  }else{
    for( int i = max(0LL, B%10-1); i <= min(9LL, B%10+1); i++ ){
      int nB = B*10 + i;
      zyun.push_back(nB);
      fn(A-1, nB);
    }
  }
  
}

signed main() {
  int N;
  cin >> N;
  for( int i = 1; i < 10; i++ ){
    zyun.push_back(i);
    fn(10, i);
  }
  zyun.erase(unique(zyun.begin(), zyun.end()), zyun.end());
  sort(zyun.begin(), zyun.end());
  
  cout << zyun.at(N-1) << endl;
  
}



Measured memory_bytes: 10348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++)cin>>p[i];
    int ans=0;
    for(int i=0;i<n;i++){
        if(p[i]==i+1){
            ans++;
            if(i<n-1&&p[i+1]==i+2)i++;
        }
    }
    cout<<ans<<endl;
}


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

int main()
{
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++) cin>>arr[i];
    int m;
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        int p,x,ans=0,temp;
        cin>>p>>x;
        temp=arr[p];
        arr[p]=x;
        for(int j=1;j<=n;j++)ans+=arr[j];
        cout<<ans<<endl;
        arr[p]=temp;
    }
}


Measured memory_bytes: 256
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ITP1_10-C

Math Functions - Standard Deviation
Time Limit : 1 sec, Memory Limit : 65536 KB
?¨??????????

n ????????????????????????????????§????????°???????????°???????¨?????????£??????????????????????????????s1, s2 ... sn??¨????????¨??????????¨??????????????±???????????????°????????????????????????

??????????????????????????¨????????°????????£?±2?????\???????????§???????????????

?±2 = (???ni=1(si - m)2)/n

?????£?????£????????????????¨???????????±??¨?????????
Input

?????°??????????????????????????\?????¨??????????????????????????????????????????????????\????????¢?????§??????????????????

???????????° n
s1 s2 ... sn

n ??? 0 ?????¨?????\?????????????????¨?????????
Output

?????????????????????????????????????¨?????????????????????????????????????????????????0.0001??\????????????????????£???????????????
Constraints

    ??\?????§??????????????? n ???1000????¶????????????¨????????????
    0 ??? si ??? 100

Sample Input

5
70 80 100 90 20
3
80 80 80
0

Sample Output

27.85677655
0.00000000

=end

class Main
  def initialize
    fh = STDIN
    while fh.gets do
      n = $_.chomp.to_i
      break if n==0 
      fl = fh.gets.chomp.split.map{|x| x.to_f}
      puts stddev(fl)
    end
  end

  def stddev(f)
    n = f.length
    sum = f.inject(0.0){|acc,x| acc + x}
    ave = sum / n
    sq_sum = f.inject(0.0){|acc,x| acc + (x - ave)**2}
    Math.sqrt(sq_sum / n) 
  end
end

if $0==__FILE__ then
  Main.new()
end

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int c[10000], d[10000];
vector<int> g[10000];

int ind = 0;

void dfs(int v, int p) {
    d[v] = c[ind++];
    for (int to : g[v]) if (to != p) {
        dfs(to, v);
    }
}

int main() {
    scanf("%d", &n);
    forn(i, n - 1) {
        int from, to;
        scanf("%d%d", &from, &to), --from, --to;
        g[from].pb(to);
        g[to].pb(from);
    }
    forn(i, n) {
        scanf("%d", c + i);
    }
    sort(c, c + n);
    reverse(c, c + n);
    dfs(0, -1);
    int sum = 0;
    for (int i = 1; i < n; ++i) {
        sum += c[i];
    }
    printf("%d\n", sum);
    forn(i, n) {
        printf("%d ", d[i]);
    }
    puts("");
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;
	vector<P> X(n);
	P a;
	int mid = n/2;
	rep(i,n){int t; cin >> t; X[i] = make_pair(t,i+1); }
	sort(X.begin(),X.end());

	vector<int> ans(n);
	rep(i,n){
		swap(X[0],X[i]);
		int idx = X[0].second;
		ans[idx-1] = X[mid].first;
	}

	for(int u : ans){
		cout << u << endl;
	}

	return 0;
}

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



int a[100010];
int N,S,W,Q;
int special(int m){
	int c[5] = {};
	int ans = 0;
	for(int i = 0 ; i < N ; i++){
		c[a[i]%m]++;
		if( a[i] != 0 ){
			ans += c[0];
		}
	}
	return ans;
}
int main(){
	while( cin >> N >> S >> W >> Q && N){
		int g = S;
		for(int i=0; i<N; i++) {
			a[i] = (g/7) % 10;
			if( g%2 == 0 ) { g = (g/2); }
			else           { g = (g/2) ^ W; }
		}
		reverse(a,a+N);
		if( Q == 2 || Q == 5 ){
			cout << special(Q) << endl;
		}else{
			
			map<int,int> d;
			d[0] = 1;
			int now = 0;
			int ans = 0;
			int ten = 1;
			for(int i = 0 ; i < N ; i++){
				now = (now+1ll*a[i]*ten%Q) % Q;
				if( a[i] != 0 ){
					ans += d[now];
				}
				d[now]++;
				ten *= 10;
				ten %= Q;
			}
			cout << ans << endl;
		}
		
		
	}
}

Measured memory_bytes: 5804
import math
import sys
n,m = map(int, input().split())
a = list(map(int, input().split()))

def gcd(x,y):
    if x < y:
        x,y = y,x
    while x%y != 0:
        x,y = y,x%y
    return y

def lcm(x,y):
    return x/gcd(x,y)*y

def f(x):
    count = 0
    while x%2 == 0:
        x /= 2
        count += 1
    return count

for i in range(n):
    if a[i]%2 == 1:
        print(0)
        sys.exit()
    a[i] /= 2

count = f(a[0])

for i in range(n):
    if f(a[i]) != count:
        print(0)
        sys.exit()
    a[i] /= 2**count
m /= 2**count

l = 1
for i in range(n):
    l = lcm(l,a[i])
    if l > m:
        print(0)
        sys.exit()
m /= l

ans = (m+1)/2
print(int(ans))


Measured memory_bytes: 15020
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    bool ok = true;
    int n;
    cin >> n;
    while(n--) {
        int x;
        cin >> x;
        if (x % 2 ==0) {
            if (x % 3 && x % 5)
                ok = false;
        }
    }
    if (ok) {
        cout << "APPROVED";
    } else {
        cout << "DENIED";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N;
  cin >> N;
  set<string> st;
  rep(i,0,N) {
    string u;
    cin >> u;
    st.insert(u);
  }
  i64 M;
  cin >> M;
  vector<string> T(M);
  rep(i,0,M) cin >> T[i];
  i64 op = 0;
  rep(i,0,M) {
    string t = T[i];
    if(st.count(t)) {
      op ^= 1;
      if(op) {
        cout << "Opened by " << t << endl;
      }
      else {
        cout << "Closed by " << t << endl;
      }
    }
    else {
      cout << "Unknown " << t << endl;
    }
  }
}



Measured memory_bytes: 3244
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll M =1e9+7;
const int N = 1e5+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

bool check(int x,int a[],int n,int k)
{
    int ctr=0;
    
    rep(i,0,n)
    ctr+=((a[i]-1)/x);
    
    if(ctr<=k)
    return 1;
    
    else
    return 0;
}

    
int main()
{
    int n,k;
    scf(n),scf(k);
    
    int a[n];
    
    rep(i,0,n)
    scf(a[i]);
    
    int l=1,h=1e9;
    
    while(l<h)
    {
        int m=(l+h)/2;
        
        if(check(m,a,n,k))
        h=m;
        
        else
        l=m+1;
    
    }
    
    prin(h);

}

Measured memory_bytes: 4504
# Card Game for Two
N = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
a.sort!.reverse!
alice_sum = 0
bob_sum = 0
for i in 0..a.length-1 do
    if i % 2 == 0
        alice_sum = alice_sum + a[i]
    elsif i % 2 == 1
        bob_sum = bob_sum + a[i]
    end
end
puts (alice_sum - bob_sum)

Measured memory_bytes: 3836
N = int(input())
A = [int(input()) for i in range(N)]
As = sorted(A)
lowIdx = 0
highIdx = len(As)-1


l = As[lowIdx]
r = As[highIdx]
diff = r-l
lowIdx+=1
highIdx-=1

while lowIdx <= highIdx:
    low = As[lowIdx]
    high = As[highIdx]
    rHigh = abs(r - As[highIdx])
    lHigh = abs(l - As[highIdx])
    rLow = abs(r - As[lowIdx])
    lLow = abs(l - As[lowIdx])
    if rHigh >= max(lHigh, rLow, lLow):
        diff += rHigh
        r = high
        highIdx -= 1
    elif lHigh >= max(rLow, lLow):
        diff += lHigh
        l = high
        highIdx -= 1
    elif rLow >= lLow:
        diff += rLow
        r = low
        lowIdx += 1
    else:
        diff += lLow
        l = low
        lowIdx += 1

print(diff)

Measured memory_bytes: 8288
#include <stdio.h>

int main(void)
{
 int N,d[100],s,i,j;

 scanf("%d",&N);

 for(i=0;i<N;i++){
  scanf("%d",&d[i]);
 }
 s=0;
 for(i=0;i<N;i++){
  for(j=i+1;j<N;j++){
   s=s+d[i]*d[j];
  }
 }

  printf("%d",s);

 return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
const long long MAXN=200005,MOD=998244353;

char S[MAXN];
long long dp[MAXN][3][3][2];

int main()
{
	scanf("%s",S+1);
	long long n=strlen(S+1),sum=0;
	if(n==2)
	{
		printf("%d\n",1+(S[1]!=S[2]));
		return 0;
	}
	if(n==3)
	{
		if(S[1]!=S[2]&&S[2]!=S[3]&&S[3]!=S[1])
			puts("3");
		else if((S[1]==S[2]&&S[2]!=S[3])||(S[2]==S[3]&&S[1]!=S[2]))
			puts("6");
		else if(S[1]==S[3]&&S[1]!=S[2])
			puts("7");
		else if(S[1]==S[2]&&S[2]==S[3])
			puts("1");
		return 0;
	}
	bool flag=false,flag2=true;
	for(long long i=1;i<=n;i++)
	{
		sum=(sum+S[i]-'a')%3;
		if(S[i]==S[i+1])
			flag=true;
		if(S[i]!=S[1])
			flag2=false;
	}
	if(flag2)
	{
		puts("1");
		return 0;
	}
	dp[1][0][0][0]=1;
	dp[1][1][1][0]=1;
	dp[1][2][2][0]=1;
	for(long long i=2;i<=n;i++)
		for(long long j=0;j<3;j++)
			for(long long k=0;k<3;k++)
			{
				for(long long p=0;p<3;p++)
					if(p!=k)
						dp[i][j][k][0]=(dp[i][j][k][0]+dp[i-1][(j-k+3)%3][p][0])%MOD;
				for(long long p=0;p<3;p++)
				{
					dp[i][j][k][1]=(dp[i][j][k][1]+dp[i-1][(j-k+3)%3][p][1])%MOD;
					if(p==k)
						dp[i][j][k][1]=(dp[i][j][k][1]+dp[i-1][(j-k+3)%3][p][0])%MOD;
				}
				//printf("dp[%d][%d][%d][%d]=%d\n",i,j,k,0,dp[i][j][k][0]);
				//printf("dp[%d][%d][%d][%d]=%d\n",i,j,k,1,dp[i][j][k][1]);
			}
	long long ans=0;
	for(long long j=0;j<3;j++)
		ans=(ans+dp[n][sum][j][1])%MOD;
	ans+=(!flag);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 28544
N, M, X = map(int,input().split())
A = list(map(int,input().split()))
ans = []
z = 0
y = 0
for i in range(X + 1, N + 1):
    if  i in A:
        z += 1
ans.append(z)
for i in range(1,X):
    if  i in A:
        y += 1
ans.append(y)
ans = sorted(ans)
print(ans[0])

Measured memory_bytes: 9184
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

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

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

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

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int V, E; cin >> V >> E;

	vector<vector<int>> adj(V, vector<int>(V,-1));

	for (int e = 0; e < E; e++) {
		int s, t, d; cin >> s >> t >> d;

		adj[s][t] = d;
	}
			
	
	//dp[既に訪れた部分集合][最後に訪れた頂点]のときの最短距離
	//dp[S][v]
	vector<vector<int>> dp(1 << V, vector<int>(V));
	
	//dp初期化
	for (int i = 0; i < (1 << V); i++) {
		for (int j = 0; j < V; j++) {
			dp[i][j] = INF;
		}
	}

	//頂点0から出発。
	//部分集合としては0…0001
	//最後に訪れたのは頂点0で頂点0からの距離は0
	dp[1][0] = 0;

	for (int s = 0; s < (1 << V); s++) {
		for (int v = 0; v < V; v++) {
			if (dp[s][v] == INF)continue;

			for (int k = 0; k < V; k++) {
				if (s >> k & 1)continue;
				if (adj[v][k] == -1)continue;
				int nexts = s | (1<<k);

				
				dp[nexts][k] = min(dp[nexts][k], dp[s][v] + adj[v][k]);
				
				
			}
			
		}
	}

	int all = (1 << V) - 1;
	int ans = INF;
	for (int v = 0; v < V; v++) {
		if (dp[all][v] == INF)continue;
		if (adj[v][0] == -1)continue;

		ans = min(ans, dp[all][v] + adj[v][0]);
	}

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

	return 0;
}


Measured memory_bytes: 6304
N = int(input())
count_maps = [{} for i in range(N)]
for i in range(N):
        S = input()
        for c in S:
            if c in count_maps[i]:
                count_maps[i][c] += 1
            else:
                count_maps[i][c] = 1
                
ans = ""
for c in count_maps[0].keys():
    max_inclusion = count_maps[0][c]
    for i in range(N):
        if c in count_maps[i]:
            max_inclusion = min(max_inclusion, count_maps[i][c])
        else:
            max_inclusion = 0
            break
    ans += c * max_inclusion
      
print("".join(sorted(list(ans))))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    set<string> s;
    for(int i=0; i<N; i++){
        string S;
        cin >> S;
        s.insert(S);
    }
    bool open = false;
    int M;
    cin >> M;
    for(int i=0; i<M; i++){
        string S;
        cin >> S;
        if(s.count(S)){
            if(open){
                cout << "Closed by " << S << enld;
            }else{
                cout << "Opened by " << S << enld;
            }
            open ^= true;
        }else{
            cout << "Unknown " << S << enld;
        }
    }
    return 0;
}


Measured memory_bytes: 3256
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = [list(map(int, readline().rstrip().split())) for _ in range(n)]
    A.sort(key=lambda x: x[1])
    sumTime = 0
    maxTime = 0
    for arr in A:
        maxTime = arr[1]
        sumTime += arr[0]
        if maxTime - sumTime < 0:
            print("No")
            return
    print('Yes')


if __name__ == '__main__':
    main()


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

int gcm(int x,int y)
{
  if(x%y==0)
  {
    return y;
  }
  return gcm(y,x%y);
}

int main()
{
  int a,b,k,x;
  x=0;
  cin>>a>>b>>k;
  vector<int> u;
  for(int i=1;i<=gcm(a,b);i++)
  {
    if(gcm(a,b)%i==0)
    {
      u.push_back(i);
      x++;
    }
  }
  cout<<u.at(x-k)<<endl;
}

Measured memory_bytes: 3572
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int board[1200][1200];
	int W = 0;
	int H = 0;
	int N = 0;
	int X = 0;
	int Y = 0;
	int choice = 0;
	cin>>W>>H>>N;
	for(int i=0;i<=1000;i++)
	{
		for(int j=0;j<=1000;j++)
		{
			board[i][j] = 0;
			
		}
	}
	for(int i=1;i<=H;i++)
	{
		for(int j=1;j<=W;j++)
		{
			board[i][j] = 1;
			
		}
	}
	for(int repeat = 1;repeat<=N;repeat++)
	{
		cin>>X>>Y>>choice;
		if(choice == 1)
		{
			for(int i=1;i<=H;i++)
			{
				for(int j=1;j<=X;j++)
				{
					board[i][j] += 1;
					
				}
			}
		}
		if(choice == 2)
		{
			for(int i=1;i<=H;i++)
			{
				for(int j=W;j>X;j--)
				{
					board[i][j] += 1;
					
				}
			}
		}
		if(choice == 3)
		{
			for(int i=1;i<=Y;i++)
			{
				for(int j=1;j<=W;j++)
				{
					board[i][j] += 1;
					
				}
			}
		}
		if(choice == 4)
		{
			for(int i=H;i>Y;i--)
			{
				for(int j=1;j<=W;j++)
				{
					board[i][j] += 1;
					
				}
			}
		}
	}
	
	
	
	
	int amount = 0;
	
	for(int i=1;i<=H;i++)
	{
		for(int j=1;j<=W;j++)
		{
			if(board[i][j] == 1)
			{
				amount += 1;
			}
			
		}
	}
	cout<<amount;
	
}

Measured memory_bytes: 5632
/**
 *Code Author: codeknight13
 *Institution: IIT(ISM)
**/
 
#include <bits/stdc++.h>
using namespace std;

//remember-> largest 2d memory that can be allocated is dp[5100][5100];
#define ll int
#define v vector
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define str string
#define pq priority_queue
#define vi vector< ll >
#define vii vector< vi >
#define viii vector< vii >
#define pii pair< ll, ll >
#define vpii vector< pii >
#define len length()
#define pb push_back
#define mp make_pair3
#define ff first
#define ss second
#define nl cout <<  endl
#define all(ar) ar.begin(), ar.end()
#define ini(X,Y) ll X; X=Y
#define inx(X) ll X; cin >> X
#define inxy(X, Y) ll X, Y; cin >> X >> Y
#define iter(arr) for (ll i=0; i<arr.size(); i++)
#define ret return
#define cont continue
ll inf=1000000007;

ll min1(ll a, ll b, ll c)
{
	ret (min(a,min(b,c)));
}
int k;

int solve(vi &arr, vi &dp, int n)
{
	if (n<=1)
	{
		if (n>=0)
		{
			dp[n]=0;
		}
		ret 0;
	}
	if (dp[n]!=-1)
	{
		ret dp[n];
	}
	int cost=INT_MAX;
	for (int i=1; i<=k; i++)
	{
		if (n-i>=0)
		cost=min(abs(arr[n]-arr[n-i])+solve(arr,dp,n-i),cost);
	}
	dp[n]=cost;
	ret dp[n];
}

int main()
{
	fast;
	int n;
	cin >> n;
	cin >> k;
	if (k>=n)
	{
		k=n-1;
	}
	vi arr(n+2);
	arr[0]=	INT_MAX;
	arr[1]=	INT_MAX;
	for (int i=2; i<n+2; i++)
	{
		cin >> arr[i];
	}
	vi dp(n+2,-1);
	dp[2]=0;
	cout << solve(arr,dp,n+1);
	ret 0;
}

Measured memory_bytes: 8832
// ABC071 C - Make a Rectangle.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <stack>


using lolo=long long;
using namespace std;
using vec=vector<lolo>;
using pari=pair<lolo, lolo>;
using vvec=vector<vec>;
using vecb=vector<bool>;
using Rpriority_queue=priority_queue<lolo, vector<lolo>, greater<lolo>>;
using priority_Q = priority_queue<lolo>;

#define FOR(i,n) for (lolo i=0; i<n; ++i)
#define FORIT(it,V) for (auto it=V.begin(); it!=V.end(); ++it)
#define FORANGE(v, V) for (auto v : v)
#define FORN(i,a,b) for (lolo i=a; i<b; ++i)
#define REV(i,a,b) for (lolo i=a; i>b; --i)
#define REVCNT(i, const_cnt, N) for (lolo i=N-1, cnt=const_cnt; cnt > 0; --cnt, --i)
#define ALL(x) x.begin(), x.end()

int main()
{
	lolo N;
	cin >> N;
	vec A(N);
	map<lolo, lolo> cnt;
	lolo a;
	FOR(i, N) {
		cin >> a;
		cnt[-a] += 1;
	}

	vec B;
	for (auto v : cnt) {
		auto val = v.first * -1;
		auto v_cnt = v.second;
		if (B.empty() and v_cnt >= 4) {
			cout << val * val << endl;
			exit(0);
		} 
		
		if (v_cnt >= 2)
			B.push_back(val);


		if (B.size() == 2) {
			cout << B[0] * B[1] << endl;
			exit(0);
		}
	}
	cout << 0 << endl;
}



Measured memory_bytes: 7296
A, B, C, D, E, F = map(int, input().split())
ans0 = 100*A
ans1 = 0

for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if sugar*ans0>ans1*(water+sugar):
                    ans0 = water+sugar
                    ans1 = sugar

print(ans0, ans1)

Measured memory_bytes: 43740
//#pragma GCC optimize("O3") 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
//#define TASK "triangle"
#define pb push_back
#define fi first
#define se second
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) (void)42
#endif

// every true-boy doesn't read statement!

typedef long long ll;
typedef vector < ll > vi;
typedef pair < ll, ll > pll;
typedef long double ld;

const int MAXN = 5005;

bool dl[MAXN][MAXN], dr[MAXN][MAXN];
int a[MAXN];
int N, K;

int findLess(int id, int pos) {
	pos--;
	while (pos >= 0) {
		if (dr[id][pos])
			break;
		pos--;
	}
	return max(0, pos);
}

void solve() {
	cin >> N >> K;
	for (int i = 0; i < N; i++)
		cin >> a[i];
	dl[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int k = K; k >= 0; k--) {
			if (dl[i][k] && k + a[i] <= K)
				dl[i + 1][k + a[i]] = 1;
			dl[i + 1][k] = max(dl[i + 1][k], dl[i][k]);
		}
	}
	dr[N][0] = 1;
	for (int i = N - 1; i >= 0; i--) {
		for (int k = K - 1; k >= 0; k--) {
			if (dr[i + 1][k] && k + a[i] <= K)
				dr[i][k + a[i]] = 1;
			dr[i][k] = max(dr[i][k], dr[i + 1][k]);
		}
	}
	int ans = 0, maxk = 0, k;
	bool flag;
	for (int i = 0; i < N; i++) {
		maxk = 0;
		flag = 0;
		k = K;
		k = findLess(i + 1, k);
		for (int j = 0; j < K; j++) {
			while (k + j >= K && k > 0)
				k = findLess(i + 1, k);
			if (dl[i][j] && dr[i + 1][k] && k + j < K && k + j + a[i] >= K) {
				flag = 1;
				break;
			}
		}
		ans += flag;
	}
	cout << N - ans;
}

int main() {
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);
#ifdef LOCAL
	assert(freopen("xxx.in", "r", stdin));
	assert(freopen("xxx.out", "w", stdout));
#else
	//assert(freopen(TASK".in", "r", stdin));
	//assert(freopen(TASK".out", "w", stdout));
#endif
	solve();
	return 0;
}


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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=998244353;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int n,i;
	cin>>n;
	int a[n],x=0;
	REP(i,0,n-1) cin>>a[i],x^=a[i];
	REP(i,0,n-1) cout<<(a[i]^x)<<" ";
	return 0;
}

Measured memory_bytes: 4372
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN


    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    vector<int> bCount(50, 0);
    for(int i=0;i<N;i++){
        cin >> A[i];
        for(int j=0; j<50; j++){
            if(A[i] & ((ll)1<<j)) bCount[j]++;
        }
    }
    // REP(i,50) cout<<bCount[i];
    ll X = 0;
    for(int j=49; j>=0; j--){
        if(2 * bCount[j] < N){
            auto x = X | (ll)1 << j;
            
            if(x > K) continue;
            X = x;
        }
        // cout<<X<<endl;
    }
    ll res = 0;
    for(auto v : A) res += X ^ v;
    cout<<res<<endl;
 
    return 0;
}

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

using namespace std;

inline int read()
{
    int x=0;char ch=getchar();
    while(ch<'0'|| ch>'9')ch=getchar();
    while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
    return x;
}

typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<pr> vec;
#define x first
#define y second
const int N=131100;

int n,fa[N];
vec g[N],f[N];
ll mid,mv[N];

inline bool cmpx(pr a,pr b){return a.x<b.x;}
inline bool cmpy(pr a,pr b){return a.y<b.y;}

inline void work(vec &ls,vec &rs,vec &f)
{
    if(ls.size()>rs.size())swap(ls,rs);
    int el=ls.size(),er=rs.size();

    sort(ls.begin(),ls.end(),cmpy);
    sort(rs.begin(),rs.end(),cmpx);

    mv[0]=rs[0].y;
    for(int i=1;i<er;i++)
        mv[i]=min(mv[i-1],rs[i].y);

    for(int i=0,j=er-1;i<el;i++)
    {
        while(j>=0 && ls[i].y+rs[j].x>mid)j--;
        if(j>=0)f.push_back(pr(ls[i].x,mv[j]));
    }

    sort(ls.begin(),ls.end(),cmpx);
    sort(rs.begin(),rs.end(),cmpy);
    mv[0]=rs[0].x;
    for(int i=1;i<er;i++)
        mv[i]=min(mv[i-1],rs[i].x);

    for(int i=0,j=er-1;i<el;i++)
    {
        while(j>=0 && ls[i].x+rs[j].y>mid)j--;
        if(j>=0)f.push_back(pr(mv[j],ls[i].y));
    }
}

inline void dfs(int u)
{
    if(!f[u].empty())f[u].clear();
    if(g[u].empty())
    {
        f[u].push_back(pr(0,0));
        return;
    }

    for(int i=0,e=g[u].size();i<e;i++)
        dfs(g[u][i].x);

    vec &ls=f[g[u][0].x];
    for(int i=0,e=ls.size(),c=g[u][0].y;i<e;i++)
        ls[i].x+=c,ls[i].y+=c;
    vec &rs=f[g[u][1].x];
    for(int i=0,e=rs.size(),c=g[u][1].y;i<e;i++)
        rs[i].x+=c,rs[i].y+=c;

    work(ls,rs,f[u]);
    ls.clear();
    rs.clear();
}

int main()
{
    n=read();
    for(int i=2,a;i<=n;i++)
    {
        fa[i]=read();
        g[fa[i]].push_back(pr(i,read()));
    }

    ll l=0,r=1e10,ans=1e10;
    while(l<=r)
    {
        mid=l+r>>1;
        dfs(1);
        if(f[1].empty())
            l=mid+1;
        else
            r=mid-1,ans=mid;
    }

    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 32244
import java.util.Scanner;

class Main{
 public static void main(String[] args){
  int S;
  Scanner scn = new Scanner(System.in);
  S = scn.nextInt();
  int hour;
  int minute;
  int second;
  hour = S/3600;
  minute = (S-3600*hour)/60;
  second = S-3600*hour-minute*60;

  System.out.println(hour+":"+minute+":"+second);
}
}

Measured memory_bytes: 17224
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define k 10000

int main( ){
  short A[MAX],B[MAX];
  int C[k];
  int n,i,j;

  scanf("%d",&n);
  for(i=0;i <= k;i++) C[i] = 0;

  for(j=1;j <= n;j++){
    scanf("%d",&A[j]);
    C[A[j]]++;
  }

  for(i=1;i <= k;i++){
    C[i] = C[i] + C[i-1];
  }
  
  for(j=n;j >= 1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i = 1; i<= n; i++){
    if( i > 1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 8452
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
cond = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    cond.append((a, b, c, d))


def calc(l):
    score = 0
    for a, b, c, d in cond:
        if l[b] - l[a] == c:
            score += d
    return score


ans = 0
for l in combinations_with_replacement(range(1, m + 1), n):
    cand = calc(l)
    ans = max(ans, cand)

print(ans)


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

using namespace std;
vector<vector<long long>> dp(101,vector<long long>(1e5+1,-1));
long long sol(vector<vector<long long>> &a,int i,int k){
	int n=a.size();
	if(i>=n)
		return 0;

	if(dp[i][k]!=-1)
		return dp[i][k];
	long long ans=sol(a,i+1,k);
	
	if(a[i][0]<=k)
		ans=max(ans,sol(a,i+1,k-a[i][0])+a[i][1]);

	return dp[i][k]=ans;
}

int main(){
	int n,k;
	cin>>n>>k;
	vector<vector<long long>> a(n,vector<long long>(2));

	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++)
			cin>>a[i][j];
	}
	dp[0][8]=sol(a,0,k);
	cout<<dp[0][8]<<endl;
}

Measured memory_bytes: 83052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;

#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;

int32_t main() {
    fast();
    int k,x;
    cin >> k >> x;
    if(k*500>=x){
    	cout<<"Yes\n";
    }
    else
    	cout<<"No\n";
    return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓

ll n, m;
ll a[10010];

int main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> a[i];
		n -= a[i];
	}
	if (n < 0) cout << -1 << endl;
	else cout << n << endl;



	return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	LL c[5] = {};
	for(int i=0; i<N; i++){
		string S;
		cin >> S;
		if(S[0] == 'M') c[0]++;
		if(S[0] == 'A') c[1]++;
		if(S[0] == 'R') c[2]++;
		if(S[0] == 'C') c[3]++;
		if(S[0] == 'H') c[4]++;
	}
	LL ans = 0;
	for(int i=0; i<5; i++){
		for(int j=i+1; j<5; j++){
			for(int k=j+1; k<5; k++){
				ans += c[i] * c[j] * c[k];
			}
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let (n, m, l) = (sc.read(), sc.read(), sc.read());
    let a: Vec<Vec<u64>> = (0..n).map(|_| (0..m).map(|_| sc.read()).collect()).collect();
    let b: Vec<Vec<u64>> = (0..m).map(|_| (0..l).map(|_| sc.read()).collect()).collect();
    let mut c = vec![vec![0; l]; n];
    for i in 0..n {
        for k in 0..m {
            for j in 0..l {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for i in 0..n {
        for j in 0..l {
            print!("{}{}", c[i][j], if j == l-1 { '\n' } else { ' ' });
        }
    }
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  string N;
  cin>>N;
  int a=N[N.size()-1]-'0';
  if(a==3)cout<<"bon"<<endl;
  else if(a==2||a==4||a==5||a==7||a==9)cout<<"hon"<<endl;
  else cout<<"pon"<<endl;
  return 0;
}


Measured memory_bytes: 3672
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1110111110111
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppl                      pair < int , pii>              
#define    sp(x)                    setprecision(x)

int32_t main()
{
    speed upp
    int n,ans=0;
    cin>>n;
    int a[n];
    set<int>s;
    set<int>:: iterator it;
    f(i,1,n)
        cin>>a[i];
    f(i,1,n)
    {
        it=s.lower_bound(a[i]);
        if(it==s.begin())
            ans++;
        s.insert(a[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vi c(n-1), s(n-1), f(n-1);
    rep(i,n-1) cin >> c.at(i) >> s.at(i) >> f.at(i);
    // まずはn=0にいる場合を考える
    vi t(n,0);
    rep(j,n-1){
        for(int64_t i=j; i<n-1; i++){
            // cout << "j:" << j << " i:" << i << " t:" << t.at(j) << endl;
            if(s.at(i)>t.at(j)){
                t.at(j) = s.at(i);
            }else{
                int64_t remain = t.at(j)%f.at(i);
                if(remain!=0){
                    t.at(j) += f.at(i) - remain;
                }
            }
            t.at(j) += c.at(i);
        }
        cout << t.at(j) << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a;
  cin >> a;
  if (a == 'A' || a == 'B' || a == 'C' || a == 'D' || a == 'E' || a == 'F' || a == 'G' || a == 'H' || a == 'I' || a == 'J' || a == 'K' || a == 'L' || a == 'M' || a == 'N' || a == 'O' || a == 'P' || a == 'Q' || a == 'R' || a == 'S' || a == 'T' || a == 'U' || a == 'V' || a == 'W' || a == 'X' || a == 'Y' || a == 'Z') {
    cout << 'A' << endl;}
  else {cout << 'a' << endl;}}

Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define MAX 100005
int main(){
  int n,m,s,t,di;
  cin >> n >> m >> s >> t;
  int i,j,k;
  vector<int> v[MAX];
  ll d[MAX]={},d2[MAX]={};
  for(i=0;i<m;i++){
    cin >> j >> k;
    v[j].push_back(k);
    v[k].push_back(j);
  }

  bool used[MAX]={},used2[MAX]={};
  queue<P> q;
  P p,b;
  p.first=s;
  p.second=0;
  q.push(p);
  while(!q.empty()){
    p=q.front();q.pop();
    if(used[p.first]) continue;
    //cout << p.first << ":" << p.second << endl;
    if(p.first==t) di=p.second;
    used[p.first]=true;
    d[p.second]++;
    b.second=p.second+1;
    for(i=0;i<v[p.first].size();i++){
      b.first=v[p.first][i];
      q.push(b);
    }
  }
  p.first=t;
  p.second=0;
  q.push(p);
  while(!q.empty()){
    p=q.front();q.pop();
    if(used2[p.first]) continue;
    //cout << p.first << ":" << p.second << endl;
    used2[p.first]=true;
    d2[p.second]++;
    b.second=p.second+1;
    for(i=0;i<v[p.first].size();i++){
      b.first=v[p.first][i];
      q.push(b);
    }
  }
  
  //cout << di << endl;
  ll o=0;
  
  for(i=0;i<di-1;i++){
    o+=d[i]*d2[di-2-i];
  }
  
  cout << o << endl;
  return 0;
}

Measured memory_bytes: 10764