akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    int odd = 0;
    for(auto e : a) if(e % 2 == 1) odd++;
    int even = n - odd;

    even += odd / 2;
    odd %= 2;

    string res = "YES";
    if(odd == 1 and even >= 1){
        res = "NO";
    }

    cout << res << endl;

    return 0;
}


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

using namespace std;

#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 DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

// 1825

int main() {
  int n;
  cin >> n;
  vector<pair<pair<string, int>, int> > p(n);
  rep (i, n) {
    cin >> p[i].first.first >> p[i].first.second;
    p[i].first.second *= -1;
    p[i].second = i + 1;
  }
  sort(all(p));
  rep (i, n) {
    cout << p[i].second << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<list>
#include<stack>
using namespace std;
#define ll long long 
#define dd cout<<endl
const int mod=1e9+7;
const int inf=1e9+7;

const int maxn=1e5+10;

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n;
	string str;
	
	map<string,int>book;
	
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
		cin>>str;
		sort(str.begin(),str.end());
		
		book[str]++;
	}
	
	ll int sum=0,now;
	for(auto it=book.begin();it!=book.end();it++)
	{
		now=it->second;
		sum+=(now*(now-1)/2);
	}
	
	cout<<sum<<endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
  ll R, G, B, N;
  cin >> R >> G >> B >> N;
  ll triples = 0;
  for(ll r = 0; r <= N / R; r++) {
    for(ll g = 0; g <= N / G; g++) {
      ll cur = N - r * R - g * G;
      if(cur >= 0) {
        triples += (cur % B == 0);
      }
    }
  }
  cout << triples << '\n';
}

Measured memory_bytes: 256
N = int(input())
C = []
S = []
F = []
for i in range(N - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N - 1):
    t = 0
    for j in range(i, N - 1):
        if t < S[j]:
            t = S[j]
        if t % F[j] != 0:
            t += F[j] - t % F[j]
        t += C[j]
    print(t)
print(0)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{

   int n,a[100],i,j,s;

   scanf("%d",&n);

   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
   }

   s=0;
   for(i=0;i<n-1;i++){
     for(j=i+1;j<n;j++){
        s=s+a[i]*a[j];
     }
   }

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

   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1000000000000
using namespace std;
using ll=long long;
using ld=long double;
using vs=vector<string>;

int main() {
    ll h,w,k;
    cin>>h>>w>>k;
    vs c(h);
    ll bnum=0;
    ll ans=0;
    rep(i,h){
        cin>>c[i];
    }
    for(int bit=0;bit<(1<<h);bit++){
        vs c_cp=c;
        for(int i=0;i<h;i++){
            if(bit&(1<<i)){
                rep(d,w)c_cp[i].replace(d,1,"r");
            }
        }
        vs c_cp2=c_cp;
        for(int bit2=0;bit2<(1<<w);bit2++){
            vs c_cp3=c_cp2;
            for(int i=0;i<w;i++){
                if(bit2&(1<<i)){
                    rep(j,h)c_cp3[j].replace(i,1,"r");
                }
            }
            rep(i,h){
            bnum+=ll(count(begin(c_cp3[i]),end(c_cp3[i]),'#'));
            }
            if(bnum==k)ans++;
            bnum=0;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cmath>
using namespace std;
long long n,a,b,h[100005];
bool check(long long k)
{
	long long ck=k;
	for(int i=0;i<n;i++)
	{
		if(k*b>=(long long) h[i]);
		else if(k*a>=(long long) h[i])
		{
			ck-=(long long) ceil((double) ((double) (h[i]-k*b))/((double) (a-b)));
			if(ck<0) return false;
		}
		else return false;
	}
	return true;
}
int solve()
{
	int lb=-1,rb=1e9;
	while (lb<rb-1)
	{
		int mid=(lb+rb)/(long long)2;
		if (!check(mid))
		{
			lb=mid;
		}
		else
		{
			rb=mid;
		}
	}
	return rb;
}
int main()
{
	cin>>n>>a>>b;
	for (int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	cout<<solve();
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a, b;
  char check_a = 'M', check_b = 'M';
  b = N % 100;
  a = N / 100;
  if (a == 0 || 13 <= a && a <= 99) {
    check_a = 'Y';
  }
  if (b == 0 || 13 <= b && b <= 99) {
    check_b = 'Y';
  }
  if (check_a == 'M' && check_b == 'M') {
    cout << "AMBIGUOUS" << endl;
  }
  else if (check_a == 'M' && check_b == 'Y') {
    cout << "MMYY" << endl;
  }
  else if (check_a == 'Y' && check_b == 'M') {
    cout << "YYMM" << endl;
  }
  else {
    cout << "NA" << endl;
  }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        cin >> b[i];
        if (b[i] < a[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    priority_queue<pii> q;
    rep(i, n) q.push(pii(b[i], i));
    
    ll cnt = 0;
    while (!q.empty()) {
        int t = q.top().F;
        int id = q.top().S;
        q.pop();
        
        if (t == a[id]) {
            continue;
        } else if (t < a[id]) {
            cout << -1 << endl;
            return 0;
        }
        
        ll neig = (b[(id - 1 + n) % n] + b[(id + 1) % n]);
        if (b[id] % neig >= a[id]) {
            cnt += b[id] / neig;
            b[id] %= neig;
            if (b[id] == t) continue;
        } else { // a[id]まで下げていい
            cnt += (b[id] - a[id]) / (b[(id - 1 + n) % n] + b[(id + 1) % n]);
            b[id] = a[id];
            continue;
        }
        
        q.push(pii(b[id], id));
    }
    
    if (a == b) cout << cnt << endl;
    else cout << -1 << endl;
}




Measured memory_bytes: 3956
a, b = (int(x) for x in input().split())
list1 = [1, 3, 5, 7, 8, 10, 12]
list2 = [4, 6, 9, 11]

if ((a in list1) & (b in list1)):
  print("Yes")
elif ((a in list2) & (b in list2)):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {

	int A, B;

	scanf("%d %d", &A, &B);

	if(A <= 8 && B <= 8) {
		printf("Yay!\n");
	} else {
		printf(":(\n");
	}

	return 0;
}

Measured memory_bytes: 128
//1818
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000001

using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;


int main(){
	int n,m;
	while(cin >> n){
		if(n==0) break;
		int c=0;
		map<string,int> mp;
		char in1[50],in2[50];
		static int g[401][401];
		int i,j,k;
		for(i=0;i<201;i++) for(j=0;j<201;j++) g[i][j]=INF;
		
		for(i=0;i<n;i++){
			scanf("%s",in1);
			string x,y,in=in1;
			for(j=0;j<in.length(),in[j]!='-';j++) x+=in[j];
			j++;
			for(;j<in.length();j++) y+=in[j];
			if(mp.find(x)==mp.end()) mp.insert(pair<string,int>(x,c++));
			if(mp.find(y)==mp.end()) mp.insert(pair<string,int>(y,c++));
			g[(*mp.find(x)).second][(*mp.find(y)).second]=1;
		}
		
		for(i=0;i<c;i++){
			for(j=i+1;j<c;j++){
				if(g[i][j]==INF && g[j][i]==INF){
					int f=INF;
					for(k=0;k<c;k++){
						if(k==i || k==j) continue;
						if(f!=-1 && g[i][k]==1 && g[j][k]==1) f=0;
						if(f!=-1 && g[k][i]==1 && g[k][j]==1) f=0;
						if(g[i][k]==1 && g[k][j]==1) f=-1;
						if(g[j][k]==1 && g[k][i]==1) f=-1;
					}
					if(f==-1) f=INF;
					g[i][j]=f;
					g[j][i]=f;
				}
			}
		}
		for(k=0;k<c;k++){
			for(i=0;i<c;i++){
				for(j=0;j<c;j++){
					if(g[i][j] > g[i][k]+g[k][j]) g[i][j]=g[i][k]+g[k][j];
				}
			}
		}
		cout << c << endl;
	/*	for(i=0;i<c;i++){
			for(j=0;j<c;j++){
				cout << (g[i][j]==INF?-1:g[i][j]) << '	';
			}
			cout << endl;
		}*/
		cin >> m;
		for(i=0;i<m;i++){
			scanf("%s",in1);
			string x,y,in=in1;
			for(j=0;j<in.length(),in[j]!='-';j++) x+=in[j];
			j++;
			for(;j<in.length();j++) y+=in[j];
			
			if(mp.find(x)==mp.end() || mp.find(y)==mp.end()) printf("NO\n");
			else if(g[(*mp.find(x)).second][(*mp.find(y)).second]<INF && g[(*mp.find(x)).second][(*mp.find(y)).second]%2==1){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
		}
	}
			
		
	return 0;
}

Measured memory_bytes: 1308
n,m=map(int,input().split())
l=[]
r=[]
for i in range(m):
    strl,strr=map(int,input().split())
    l.append(strl)
    r.append(strr)
num1=max(l)
num2=min(r)
if num1>num2:
    print(0)
else:
    print(num2-num1+1)


Measured memory_bytes: 10996
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2e5+5;
char s[N]; ll ans;
int main()
{
  scanf("%s",s+1); bool fx=0; int cnt=0;
  int n=strlen(s+1);
  for(int i=n;i;i--)
    {
      if(s[i]=='A')
	{ if(fx){cnt=0; fx=0;} ans+=cnt;}//ans+= after!!!
      else if(s[i]=='B')
	{ if(fx)cnt++; else cnt=0; fx=0;}
      else
	{ if(fx)cnt=0; fx=1;}//cnt=0!!!
    }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 384
import sys
s=int(input())

ans=[s]
i=0
while True:
  if ans[i]%2==0:
    ans.append(int(ans[i]/2))
  if ans[i]%2==1:
    ans.append(int(ans[i]*3+1))
  if ans[i+1] in ans[:i]:
    print(i+2)
    break
  i+=1


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>

using namespace std;

typedef long long ll;

int main(){
    int n, m; cin >> n >> m;
    vector<int> p(m), y(m);
    map<int, vector<int> > mp;

    for(int i = 0; i < m; i++)
    {
        cin >> p[i] >> y[i];
        mp[p[i]].push_back(y[i]);
    }

    for(auto &num: mp)
    {
        //それぞれの県の中でソート
        //id[0]は無いので飛ばす
        sort(num.second.begin(), num.second.end()); 
    }
    
    for(int i = 0; i < m; i++)
    {
        cout << setw(12) << setfill('0') <<(ll)p[i] * 1000000 + int(lower_bound(mp[p[i]].begin(), mp[p[i]].end(), y[i]) - mp[p[i]].begin() + 1) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 13184
//--------------------------------------------------
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
int n;
int a[2*100*1000];
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    forn(i, n) cin >> a[i];
}


int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    map<int, int> m;
    ll ans = 0;
    forn(i, n){
        ans += m[i - a[i]];
        m[i + a[i]]++;
    }

    cout << ans;
}


Measured memory_bytes: 21468
al=list('abcdefghijklmnopqrstuvwxyz')
#####segfunc######                                                              
def segfunc(x,y):
    return x|y

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=1<<al.index(init_val[i])
    #built                                                                      
    for i in range(num-2,-1,-1):
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
    
def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
        k=(k-1)//2
        seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
        if p&1==0:
            res=segfunc(res,seg[p])
        if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
        p=p//2
        q=(q-1)//2
    if p==q:
        res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    ans=0
    while res>0:
        if res%2==1:
            ans+=1
        res=res//2
    return ans

ide_ele=0
n=int(input())
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
a=list(input())
init(a)
ans=0
q=int(input())

for i in range(q):
    p=list(map(str,input().split()))
    if p[0]=='1':
        update(int(p[1])-1,1<<al.index(p[2]))
    else:
        print(query(int(p[1])-1,int(p[2])))
#for i in range(n):
    #ans=max(gcd(query(0,i),query(i+1,n)),ans)
#print(ans)


Measured memory_bytes: 47400
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define printx(x) printf("%lld\n",x);
#define printxy(x,y) cout << x << y <<endl;
#define printxyz(x,y,z) cout << x << y << z <<endl;
#define deba(a) cout << #a << a << endl;
#define debab(a,b) cout << #a << a << #b << b << endl;
int main()
{
	fast;
	string s;
	cin >> s;
	if (s.length() == 2)
	{
		if (s[0] == s[1])
			cout << "1 2";
		else
			cout << "-1 -1";
	}
	else
	{
		ll fl = 0;
		ll n = s.length();
		rep(i, 0, n - 2)
		{
			if (s[i] == s[i + 1] or s[i] == s[i + 2] or s[i + 1] == s[i + 2])
			{
				cout << i + 1 << " " << i + 3;
				fl = 1;
				break;
			}
		}
		if (fl == 0)
			cout << "-1 -1";
	}
	return 0;
}

Measured memory_bytes: 3708
N = int(input())
M = 10**6 + 1

counts = [0 for _ in range(M)]
for a in map(int, input().split()):
  counts[a] += 1

max_count = 0
for i in range(2,M):
  count = 0
  for j in range(i,M,i):
    count += counts[j]
  max_count = max(max_count,count)

if max_count == N:
  answer = 'not coprime'
elif max_count >= 2:
  answer = 'setwise coprime'
else:
  answer = 'pairwise coprime'

print(answer)

Measured memory_bytes: 172844
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long int ll;
#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()
{
    string s;
    cin >> s;
    if (s.substr(0, 4) < "2019")
    {
        cout << "Heisei" << endl;
        return 0;
    } else if (s.substr(0,4) == "2019") {
        if (s.substr(5, 2) < "04") {
            cout << "Heisei" << endl;
            return 0;
        } else if (s.substr(5, 2) == "04") {
            if (s.substr(8, 2) <= "30") {
                cout << "Heisei" << endl;
                return 0;
            } else {
                cout << "TBD" << endl;
                return 0;
            }
        } else {
            cout << "TBD" << endl;
            return 0;
        }
    } else {
        cout << "TBD" << endl;
        return 0;
    }
    return 0;
}



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

int main(){
  int n,count,d[100],m;
  cin >> n;
  m = n;
  for (int i = 0; i < n; i++)
  {
    cin >> d[i];
  }
  for (int i = m-1; i >=0;i--)
  {
    for (int j = 1; j <= i;j++){
      if(d[j-1]>d[j]){
        int tmp = d[j-1];
        d[j-1] = d[j];
        d[j] = tmp;
      }
    }
  }
  count = n;
  for (int i = 0; i < n - 1; i++)
  {
    if (d[i] == d[i + 1])count--;

  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int main() {
	int H, N;
	long long A = 0LL;
	std::cin >> H >> N;
	for (int i = 0; i < N; i++) {
		long long a;
		std::cin >> a;
		A += a;
	}
	std::cout << (A >= H ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include <stack>
#include <queue>
#include <map>
#include<math.h>
#include<string.h>

using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define pb push_back

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

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


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(8,0);
    int x = 0;
    rep(i,n) cin >> a[i];
    rep(i,n){
        int rate = 0;
        rep(j,8){
            if(rate<=a[i] && a[i]<rate+400){
                b[j] +=1;
                break;
            }
            else{
                rate += 400;
            }
        }
        if(a[i]>=3200){
            x +=1;
        }
        else continue;
    }
    int ans = 0;
    rep(i,8){
        if(b[i]>0) ans +=1;
        else continue;
    }
    int max = ans + x;
    if(ans==0){
        ans = 1;
    }
    cout << ans << " " << max << endl;
}

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

int main() {
    string s;
    cin >> s;
    /*
    int year = stoi(s[0:4]);
    int month = stoi(s[4:6]);
    int day = stoi(s[6:8]);
    if (year == 2019 && 
    */

    string now = "2019/04/30";
    if (s <= now) cout << "Heisei" << endl;
    else cout << "TBD" << endl;

    return 0;
}



Measured memory_bytes: 256
SENTINEL = 1000000001

def merge(A, l, m, r):
  L = A[l:m] + [SENTINEL]
  R = A[m:r] + [SENTINEL]
  i = 0
  j = 0
  cnt = 0
  for k in range(l, r):
    if L[i] <= R[j]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1
      cnt += len(L) - 1 - i
  return cnt

def merge_sort(A, l, r):
  if l + 1 < r:
    m = (l + r) // 2
    cnt = 0
    cnt += merge_sort(A, l, m)
    cnt += merge_sort(A, m, r)
    cnt += merge(A, l, m, r)
    return cnt
  else:
    return 0

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

print(merge_sort(A, 0, n))

Measured memory_bytes: 30304
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;
int main(){
	int n,x;
	int l,ans=1,sum=0;

	scanf("%d %d",&n,&x);

	for(int i=0;i<n;i++){
		scanf("%d",&l);
		sum+=l;
		if(sum<=x){
			ans++;
		}
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>

using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;


bool solve()
{
	int N;
	cin >> N;
	if (N == 0)return false;

	mat Info(N, vec(N, 0));

	for (int i = 0; i < N; ++i)
	{
		int M; cin >> M;

		for (int j = 0; j < M; ++j)
		{
			int p; cin >> p; --p;
			Info[i][p] = 1;
		}
	}

	int K;
	cin >> K;

	vec L(N, 0);

	for (int i = 0; i < K; ++i)
	{
		int l; cin >> l; --l;
		L[l] = 1;
	}

	int ans = -1;

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			if (Info[i][j] == 0 && L[j] == 1)
			{
				break;
			}

			if (j == N - 1)
			{
				if (ans != -1)
				{
					cout << -1 << endl;
					return true;
				}
				ans = i + 1;
			}
		}
	}

	cout << ans << endl;
	
	return true;
}


int main()
{
	while(solve())
	{
	}

	return 0;
}


Measured memory_bytes: 3196
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto A = RDR.ARR;
	
	long dir, last = A[0];
	long ans = 1;
	foreach (i; 0..N)
	{
		auto diff = A[i] - last;
		if (sgn(diff) != 0)
		{
			if (sgn(diff) * dir < 0)
			{
				++ans;
				dir = 0;
			}
			else
				dir = sgn(diff);
		}
		last = A[i];
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 4404
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	vector<ll> T(N), A(N);
	REP(i, N) cin >> T[i] >> A[i];
	FOR(i, 1, N) {
		if (T[i] < T[i - 1] || A[i] < A[i - 1]) {
			ll tmp = max(T[i - 1] / T[i] + (bool)(T[i - 1] % T[i]), A[i - 1] / A[i] + (bool)(A[i - 1] % A[i]));
			T[i] *= tmp;
			A[i] *= tmp;
		}
	}
	cout << T[N - 1] + A[N - 1] << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

  if (N > M) {
    std::swap(N, M);
  }

  if (N == 1) {
    if (M == 1) {
      std::cout << 1 << std::endl;
    } else {
      std::cout << M - 2 << std::endl;
    }
  } else {
    std::cout << (N - 2) * (M - 2) << std::endl;
  }
}


Measured memory_bytes: 256
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

const MOD: usize = 1_000_000_000 + 7;
fn main() {
    let n: usize = read();
    let a: Vec<usize> = read_vec();
    let l = 61;
    let mut table = vec![vec![0; l]; n+1];

    // 各桁に立っているビットを数える
    for i in (0..n).rev() {
      for j in 0..l {
        table[i][j] = table[i+1][j];
        let flag: usize = 1<<j;
        if (flag & a[i]) == flag {
           table[i][j] += 1;
        }
      }
    }

    let mut ans: usize = 0;

    for i in 1..n {
      for j in 0..l {
        let tmp: usize = n - i;
        //println!("{} {} {:?} {} ", ans, a[i-1], table[i], tmp);
        let flag: usize = 1<<j;
  
        if table[i][j] == 0 && (a[i-1] & flag) == flag {
           ans += tmp * (flag % MOD);
           ans %= MOD;
        } else if table[i][j] < tmp && (a[i-1] & flag) == flag {
          ans += (tmp - table[i][j]) * (flag % MOD);
          ans %= MOD
        } else if table[i][j] > 0 && (a[i-1] & flag) != flag {
          ans += table[i][j] * (flag % MOD);
          ans %= MOD;
        }
      }
    }
    println!("{}", ans);

    // for x in table {
    //   println!("{:?}", x);
    // }
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


int v[200005];

void solve() {
    int N; cin >> N;
    rep1(i, N){
        int a; cin >> a;
        v[a] = i;
    }
    int cnt = 1;
    int res = 0;
    rep1(i, N-1){
        if(v[i] < v[i+1]){
            cnt++;
        }else{
            res = max(res, cnt);
            cnt = 1;
        }
    }
    res = max(res, cnt);
    cout << N-res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 8464
s = input()

n = len(s) - 1
ans = 0
for i in range(1 << n):
    exp = s[0]
    for j in range(n):
        if i & (1 << j):
            exp += "+"
        else:
            exp += "-"
        exp += s[j + 1]
    if eval(exp) == 7:
        ans = exp

ans += "=7"
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
const double eps = 1e-8;

class P {
public:
	double x, y, z;
	P(){};
	P(double x, double y, double z) : x(x), y(y), z(z) {};
	P operator+(const P &p) {
		return P(x + p.x, y + p.y, z + p.z);
	}
	P operator-(const P &p) {
		return P(x - p.x, y - p.y, z - p.z);
	}
	P operator*(const double &n) {
		return P(x * n, y * n, z * n);
	}
	P operator/(const double &n) {
		return P(x / n, y / n, z / n);
	}
};

double dot(const P &a, const P &b) {
	return a.x * b.x + a.y * b.y + a.z * b.z;
}

P cross(const P &a, const P &b) {
	return P(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}

int main() {
	P p[5];
	for (int i=0; i<5; ++i) cin >> p[i].x >> p[i].y >> p[i].z;

	P z = cross(p[3] - p[2], p[4] - p[2]);
	double a = dot(p[2] - p[0], z);
	double b = dot(p[1] - p[0], z);
	double c = abs(a);
	double d = abs(b) - c;

	if (abs(a) < eps || (b < -eps && eps < a) || (a < -eps && eps < b) || d < -eps) {
		cout << "HIT" << endl;
		return 0;
	}

	P i = (p[0] * d + p[1] * c) / (c + d);
	int plus = 0;
	if (-eps < dot(z, cross(p[3] - p[2], i - p[2]))) ++plus;
	if (-eps < dot(z, cross(p[4] - p[3], i - p[3]))) ++plus;
	if (-eps < dot(z, cross(p[2] - p[4], i - p[4]))) ++plus;
	int minus = 0;
	if (eps > dot(z, cross(p[3] - p[2], i - p[2]))) ++minus;
	if (eps > dot(z, cross(p[4] - p[3], i - p[3]))) ++minus;
	if (eps > dot(z, cross(p[2] - p[4], i - p[4]))) ++minus;

	cout << (plus == 3 || minus == 3 ? "MISS" : "HIT") << endl;
	return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>

int main(){
	int honsen,honsenf,A,B,N;
	scanf("%d %d %d\n",&N,&A,&B);
	honsen = A + B;
	honsenf = B;
	char c;
	
	for(int i=0;i<N;i++){
		c = getchar();
		//putchar(c);
		//printf("%d",i);
		if(c=='a'){
			if(honsen > 0){
				printf("Yes\n");
				honsen--;
			}else{
				printf("No\n");
			}
		}else if(c == 'b'){
			if(honsen > 0){
				if(honsenf > 0){
					printf("Yes\n");
					honsenf--;
					honsen--;
				}else{
					printf("No\n");
				}
			}else{
				printf("No\n");
			}
		}else if(c == 'c'){
			printf("No\n");
		}
	}
	
	
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
 
int main() {
    //Recieve the inputs
    int D, T, S;
    cin >> D >> T >> S;
 
    //Calculate the duration of Takahashi's journey
    double time = (double)D / S;
 
    //Output depending on the inequality between T and time
    if (T >= time) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3552
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
     
using namespace std;
     
typedef long long ll;
     
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
     
#define MOD 1000000007

ll d[10010];

int main(){
  clr(d,0);
  ll n;
  cin>>n;
  rep(x,1,101){
    rep(y,1,101){
      rep(z,1,101){
        ll a = x*x+y*y+z*z+x*y+y*z+x*z;
        if(a<10005){
          d[a]++;
        }
      }
    }
  }
  rep(i,1,n+1){
    cout << d[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main()
{
 int i,j,k,mAx,all,fa;
 cin>>i>>j>>k;
 all=i+j+k;
 if(i>j){
    if(i>k){
        mAx=i;
    }
    else{
        mAx=k;
    }
 }
 else if(j>k){
    mAx=j;
 }
 else{
    mAx=k;
 }
 fa=all-mAx;
 cout<<fa;
 return 0;
}

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

int main(void) {
    
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b&& a!=c){
        cout << "Yes" << endl;
    }else if(c == b&& b!=a){
        cout << "Yes" << endl;
    }else if(c == a&& b!=a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
numk={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[0]+[-1]*(N+1)
for i in range(N):
    for j in A:
        if i+numk[j]<=N:
            dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1)
m=N
ans=[]
while m>0:
    for i in A:
        if m-numk[i]>=0 and dp[m-numk[i]]==dp[m]-1:
          ans.append(str(i))
          m-=numk[i]
          break
print(''.join(ans))

Measured memory_bytes: 3696
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
2 900
---+/

void main(string[] args) {
  long K, X;
  readf(" %d %d ", &K, &X);
  (K*500 >= X? "Yes": "No").writeln;
}


Measured memory_bytes: 256
// ABC_165_C

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

int main()
{
	ll n;
	cin >> n;

  ll a = 0;
	ll b = 0;

	bool flag = false;

	for(ll i = -1000; i <= 1000; ++i) {
		for(ll j = -1000; j <= 1000; ++j) {
			if(pow(i, 5) - pow(j, 5) == n) {
				a = i;
				b = j;
				flag = true;
				break;
			}
			else continue;
		}
		if(flag) break;
		else continue;
	}

	cout << a << " " << b << "\n";

	return 0;
}

Measured memory_bytes: 4104
#!/usr/bin/env python3
# coding: utf-8

def main():
    N, M = map(int, input().split())
    H = dict(zip(range(1, N + 1), map(int, input().split())))
    m = dict(zip(range(1, N + 1), [[0] for _ in range(N)]))
    for _ in range(M):
        A, B = map(int, input().split())
        m[A].append(H[B])
        m[B].append(H[A])
    c = 0
    for k, v in m.items():
        if H[k] > max(v):
            c += 1
    print(c)

if __name__ == "__main__":
    main()


Measured memory_bytes: 46772
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	if (k < a)print(k);
	else if(k<=(a+b))print(a);
	else print(2 * a + b - k);
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [int(x) for x in input().split()]
n, x = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
#p, q, r = map(int, input().split())
l = [int(x) for x in input().split()]

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
#a.sort()
#print(l, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re

def doit():
  p = 0
  res = 1
  for lx in l:
    p += lx
    if x < p:
      break
    res += 1
  
  return res

#print(doit([0] * 4))
#doit(s)
try:
  print(doit())
except Exception as e:
  print("e", e, file=sys.stderr)


Measured memory_bytes: 3956
#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSMutableString*)stringFromStdIn;
+(void)printf:(NSString*)format, ...;
@end
@implementation StdIO
+(NSMutableString*)stringFromStdIn
{
    NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
    NSMutableString *result = [NSMutableString string];
    NSData *data = [handle availableData];
    while ([data length] > 0) {
        [result appendString:[[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]];
        data = [handle availableData];
    }
    NSUInteger length = [result length];
    if ([result characterAtIndex: length-1] == '\n') { // 末尾に改行文字があれば削除
        [result deleteCharactersInRange: NSMakeRange(length-1,1)];
    }
    return result;
}
+(void)printf:(NSString*)format, ...
{
    va_list arguments;
    va_start(arguments, format);
    NSString *string = [[[NSString alloc] initWithFormat: format arguments: arguments] autorelease];
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[string dataUsingEncoding: NSUTF8StringEncoding]];
    va_end(arguments);
}
@end
  
int main() {
    @autoreleasepool {
        NSArray *numbers = [[StdIO stringFromStdIn] componentsSeparatedByString:@"\n"];
        numbers = [numbers subarrayWithRange:NSMakeRange(1, [numbers count]-1)]; // 入力のうち最初の行を捨てる
        [StdIO printf:@"%lu", [[numbers valueForKeyPath:@"@distinctUnionOfObjects.self"] count]];
    }
    return 0;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int k, s;
    cin >> k >> s;

    int cnt = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = -(x + y - s);
            if (z >= 0 && z <= k) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    char x[n];
    scanf("%s", x);
    
    vector<int> viCount(n+1,0);
    for(int i = 1; i <= n; i++){
        int k = i;
        int nSum = 0;
        while(k != 0){
            nSum += (k % 2);
            k /= 2; 
        }
        viCount[i] = viCount[i % nSum] + 1;
    }
    
    int nSum = 0;  //popcount(x)
    for(int i = 0; i < n; i++){
        if(x[i] == '1'){
            nSum++;
        }
    }  
    //各popcount(x_i) はnSum+1 or nSum-1;
    if(nSum == 0){
        for(int i = 0; i < n; i++){
            printf("1\n");
        }
        return 0;
    }
    if(nSum == 1){
        for(int i = 0; i < n; i++){
            if(x[i] == '1'){
                printf("0\n");
            }
            else if(i == n-1 || x[n-1] =='1'){
                printf("2\n");
            }
            else{
                printf("1\n");
            }
        }
        return 0;
    }
    
    vector<int> viPow2RemainPlus(n, 1);
    vector<int> viPow2RemainMinus(n, 1);
    viPow2RemainMinus[0] %= (nSum-1);
    int nRemainPlus = viPow2RemainPlus[0] * (x[n-1] - '0');   //xをnSum+1で割ったあまり
    int nRemainMinus = viPow2RemainMinus[0] * (x[n-1] - '0');   //xをnSum-1で割ったあまり
    
  

    for(int i = 1; i < n; i++){
        viPow2RemainPlus[i] = viPow2RemainPlus[i - 1] * 2;
        viPow2RemainMinus[i] = viPow2RemainMinus[i - 1] * 2;
        viPow2RemainPlus[i] %= (nSum + 1);
        viPow2RemainMinus[i] %= (nSum - 1);
        nRemainPlus += viPow2RemainPlus[i] * (x[n-i-1] - '0');
        nRemainMinus += viPow2RemainMinus[i] * (x[n-i-1] - '0');
        nRemainPlus %= (nSum + 1);
        nRemainMinus %= (nSum - 1);
    }

    for(int i = 0; i < n; i++){
        if(x[i] == '0'){//nSum+1
            int k = nRemainPlus + viPow2RemainPlus[n-i-1];
            k %= (nSum+1);
            if(k < 0){
                k += (nSum+1);
            }
            printf("%d\n", viCount[k]+1);

        }
        else{//nSum-1
            int k = nRemainMinus - viPow2RemainMinus[n-i-1];
            k %= (nSum-1);
            if(k < 0){
                k += (nSum-1);
            }
            printf("%d\n", viCount[k]+1);

        }
    }
    return 0;
}


Measured memory_bytes: 5520
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
   int n,k;
   cin >> n >> k;
   vector<int> l(n);
   rep(i,n) cin>>l[i];
   sort(l.begin(),l.end());
   int cnt = 0;
   int ans = 0;
   rrep(i,n) {
       cnt++;
       ans+=l[i];
       if(cnt==k) break;
   }
   cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        if (n<=999) {
            System.out.println("ABC");
        }
        if (n>=1000) {
            System.out.println("ABD");
        }

    }
}


Measured memory_bytes: 21076