akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(void){
	int h,w;
	cin>>h>>w;
	int ans;
	string s="snuke";
	string a;
	for(int i=0;i<h*w;i++){
		cin>>a;
		if(a==s){
			ans=i;
		}
	}
	int b,c;
	b=ans/w+1;
	c=ans%w;
	char d='A'+c;
	cout<<d<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
n,s = list(map(int,input().split()));arr = list(map(int,input().split()))

mod = 998244353
dp = [0] * (s+1)
ans = 0

for i in range(n):
    dp[0] += 1
    tmp = arr[i]
    for j in range(s,tmp-1,-1):
        dp[j] += dp[j-tmp]
    ans += dp[s]
    ans %= mod
    
print(ans)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
int n, l, r, m;
ll sum, ans, mx, mi;
int a[N];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    ans = LLONG_MAX;

    // (l)(i)(r)()
    l = 0;
    m = 1;
    r = 2;
    ll sum1 = a[0];
    ll sum2 = a[1];
    ll sum3 = a[2];
    ll sum4 = sum - sum1 - sum2 - sum3;
    while (1) {
        while (1) {
            ll dl = abs(sum2 - sum1);
            ll ndl = abs(sum1 + a[l + 1] - (sum2 - a[l + 1]));
            if (ndl < dl) {
                ++l;
                sum1 += a[l];
                sum2 -= a[l];
            } else {
                break;
            }
        }
        while (1) {
            ll dr = abs(sum3 - sum4);
            ll ndr = abs(sum3 + a[r + 1] - (sum4 - a[r + 1]));
            if (ndr < dr) {
                ++r;
                sum3 += a[r];
                sum4 -= a[r];
            } else {
                break;
            }
            // cout << r << ' ' << sum3 << ' ' << sum4 << endl;
        }
        ll mx = max(max(sum1, sum2), max(sum3, sum4));
        ll mi = min(min(sum1, sum2), min(sum3, sum4));
        ans = min(ans, mx - mi);
        ++m;
        if (m >= n - 2) break;
        sum2 += a[m];
        sum3 -= a[m];
        if (r == m) {
            ++r;
            sum3 += a[r];
            sum4 -= a[r];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4436
#include <iostream>
/*#include <bits/stdc++.h>*/
using namespace std;
int md=998244353;
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i) cin>>a[i];
    int cost[n];
    cost[0]=0;
    cost[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;++i) cost[i]=min(cost[i-2]+abs(a[i]-a[i-2]),cost[i-1]+abs(a[i]-a[i-1]));
    cout<<cost[n-1];
}

Measured memory_bytes: 3916
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1<<29;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
void solve(){
   string ret = "ABC";
   string txt;
   cin >> txt;
   cout << ret + txt << endl;	
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <random>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (ll)(b); i++)

//N<=100, W<=10^5
const int MAX_N = 110;
const int MAX_V = 1000 * 100 + 1;
ll dp[MAX_N][MAX_V];
const int INF = 1000000007;

struct Item {
    ll w, v;
};

ll solve(int n, ll maxW, vector<Item> items) {
    rep(i, 110) {
        rep(j, 100010) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    rep(i, n) {
        Item item = items[i];
        rep(j, MAX_V) {
            if (dp[i][j] == INF) {
                continue;
            }
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
            if (dp[i][j] + item.w <= maxW) {
                dp[i + 1][j + item.v] = min(dp[i + 1][j + item.v], dp[i][j] + item.w);
            }
        }
    }
    ll ret = 0;
    rep(j, MAX_V) {
        if (dp[n][j] != INF) {
            ret = j;
        }
    }
    return ret;
}


int main() {
    int n;
    ll maxW;
    vector<Item> items;
    cin >> n >> maxW;
    rep(i, n) {
        ll w, v;
        cin >> w >> v;
        items.push_back({w, v});
    }
    ll ans = solve(n, maxW, items);
    cout << ans << "\n";
}


Measured memory_bytes: 86144
A, B = map(int,input().split(' '))
B += 1
l = "1" if A%4 in [0,1] else "0"
r = "1" if B%4 in [0,1] else "0"
n = 2
while n <= A:
    if A%(2*n)-n <= 0 or A%(2*n)%2 == 0:
        l += "0"
    else:
        l += "1"
    n *= 2
n = 2
while n <= B:
    if B%(2*n)-n <= 0 or B%(2*n)%2 == 0:
        r += "0"
    else:
        r += "1"
    n *= 2
print(int(l[::-1], 2)^int(r[::-1], 2))

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

ll cnt(int n, int i, ll &res, vector<int> &c, vector<int> &s, vector<int> &f){
    if(i==n) return res;
    
    if(res < s.at(i)){
        res = s.at(i);
    }

    if(res%f.at(i)!=0){
        ll tmp = res/f.at(i) + 1LL;
        res = f.at(i)*tmp;
    }

    res += c.at(i); 
    return cnt(n, i+1, res, c, s, f);
}

int main() {
    int n; cin >> n;
    vector<int> c(n), s(n), f(n);
    for(int i=1; i<n; i++){
        cin >> c.at(i) >> s.at(i) >> f.at(i);
    }

    vector<ll> t(n+1);
    ll res = 0;
    for(int i=1; i<=n; i++){
        if(i==n) {
            cout << 0 << endl;
            return 0;
        }

        res = s.at(i)+c.at(i);
        cnt(n, i+1, res, c, s, f);

        cout << res << endl;
    }
}


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

const int SIZE = 1405;
int dp[SIZE][SIZE];

int main(){
    int h, w; cin >> h >> w;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            bool c; cin >> c;
            dp[i][j] = !c;
        }
    }
    int ans = 0;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            dp[i][j] = (min(dp[i-1][j-1], min(dp[i-1][j], dp[i][j-1])) + 1) * dp[i][j];
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans * ans << endl;
}


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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int m[55];
int x[55][11];
int y[55][11];

int dx[4][11];
int dy[4][11];

int main(void){
	int n;
	while(cin >>n){
		if(n==0)
			break;
		rep(i,n+1){
			cin >> m[i];
			rep(j,m[i]) cin >> x[i][j] >> y[i][j];
		}


		rep(i,4)rep(j,m[0]-1){
			int xx=x[0][j+1]-x[0][j];
			int yy=y[0][j+1]-y[0][j];

			if(i==1){
				yy*=-1;
				swap(xx,yy);
			}else if(i==2){
				xx*=-1;
				yy*=-1;
			}else if(i==3){
				xx*=-1;
				swap(xx,yy);
			}
			dx[i][j]=xx;
			dy[i][j]=yy;
		}
		for(int i=1;i<=n;++i){
			bool ok=false;
			if(m[0]!=m[i])
				continue;
			rep(j,4){
				bool p=true;
				for(int k=0;k<m[i]-1;++k){
					int ddx=x[i][k+1]-x[i][k];
					int ddy=y[i][k+1]-y[i][k];
					if(ddx!=dx[j][k]||ddy!=dy[j][k])
						p=false;
				}
				bool r=true;
				for(int k=0;k<m[i]-1;++k){
					int ddx=x[i][m[i]-k-1]-x[i][m[i]-k-2];
					int ddy=y[i][m[i]-k-1]-y[i][m[i]-k-2];
					if(ddx!=dx[j][k]||ddy!=dy[j][k])
						r=false;
				}
				if(p||r)
					ok=true;
			}
			if(ok)
				cout << i << endl;
		}
		puts("+++++");
	}
	return 0;
}

//(0,1)  (1,1)
//
//(0,0)  (1,0)
//

// dx  0 1  0
// dy  1 0 -1

// dx  1  0 -1
// dy  0 -1  0

// dx  0 -1 0
// dy -1  0 1

// dx -1  0  1
// dy  0  1  0

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{   

        fast_cin;
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

    int x;
    cin>>x;
    int y=!x;
    cout<<y<<"\n";
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;


int main()
{
	int i, j, k, l, m, X, Y,sum,flag;
	sum = 1;
	int ans[10000];
	for (i = 0; i < 10000; i++) {
		ans[i] = 0;
	}
	for (i = 2; i <= 31; i++) {
		for (j = i*i; j <= 1000; j *= i) {
			ans[j] = 1;
		}
	}
	ans[1] = 1;
	cin >> X;
	for (i = 0; i <= X; i++) {
		if (ans[i]==1) {
			sum = i;
		}
	}
	cout << sum << endl;

}



Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	vvi dp(m+1,vi(20010,-inf));
	dp[0][0]=0;
	rep(i,n){
		int a,b,c;cin>>a>>b>>c;
		for(int j=m-c;j>=0;j--)rep(k,20010)if(dp[j][k]+inf){
			int s=k+a,t=dp[j][k]+b;
			cmax(dp[j+c][max(s,t)],min(s,t));
			s=k+b,t=dp[j][k]+a;
			cmax(dp[j+c][max(s,t)],min(s,t));
		}
//		rep(j,m+1){rep(k,7)cout<<" "<<dp[j][k];cout<<endl;}
//		cout<<endl;
	}
	int ma=-inf;
	rep(j,m+1)rep(i,20010)ma=max(ma,dp[j][i]);
	cout<<ma<<endl;
}







Measured memory_bytes: 10808
#include<stdio.h>

int main(){
	int x,y;
	while(1){
		scanf("%d %d\n",&x,&y);
		if(x==0&&y==0)break;
		if(x<y)printf("%d %d\n",x,y);
		else printf("%d %d\n",y,x);
	}
	return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
 
priority_queue <int> pq;
 
int main(){
  	ios_base::sync_with_stdio(false);
	int h, n, x; cin >> h >> n;
 	while (n--){
    	cin >> x; pq.push(x);
    }
  	while (h > 0 && !pq.empty()){
    	h -= pq.top(); pq.pop();
    }
  	if (h > 0) cout << "No";
 	else cout << "Yes";
}

Measured memory_bytes: 892
import sys
sys.setrecursionlimit(10 ** 7)

'''
#import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
#sys.setrecursionlimit(10 ** 7)
'''
inf = 10 ** 20
'''
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]

def main():
'''

N = int(input())
h = list(map(int, input().split()))
dp = [inf]*N
dp[0] = 0
for i in range(1, N):
    if i >= 2:
        dp[i] = min(abs(h[i]-h[i-1]) + dp[i-1], dp[i])
        dp[i] = min(abs(h[i]-h[i-2]) + dp[i-2], dp[i])
    else:
        dp[i] = min(abs(h[i]-h[i-1]) + dp[i-1], dp[i])

print(dp[N-1])

'''
if __name__ == '__main__':
    main()
'''

Measured memory_bytes: 13908
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
ab.sort(key=lambda x:x[0])
now = 0
ans = 0
for a, b in ab:
    if now == M:
        break
    buy = min(b, M-now)
    now += buy
    ans += buy * a
print(ans)

Measured memory_bytes: 29028
#include<bits/stdc++.h>
using namespace std;
char str[150];

bool sym(int l,int r){ //qi
	int mid=(l+r)>>1;
	while(l<mid&&r>mid){
		if(str[l]==str[r]){
			l++;r--;
		}
		else return false;
	}
	return true;
}
bool sym1(int l,int r){
	
	while(l<r){
		if(str[l]==str[r]){
			l++;r--;
		}
		else return false;
	}
	return true;
}
int main(){
	
	scanf("%s",str+1);
	int l=1,r=strlen(str+1),mid;
	mid=(l+r)>>1;
    if(r%2==0){
    	printf("No\n");return 0;
	}  
	if(sym(l,r)){
		if((mid-1)%2==0){ //ou
			if(sym1(1,mid-1)){
				printf("Yes\n");return 0;
			}
			else{
				printf("No\n");return 0;
			}
		}
		else{
			if(sym(1,mid-1)){
				printf("Yes\n");return 0;
			}
			else{
				printf("No\n");return 0;
			}
		}
	}
    else{
	 printf("No\n");return 0;} 
	
} 

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
s=0
count=0
i=0
while i<=C:
        j=0
        while j<=B:
            k=0
            while k<=A:
                s=i*50+j*100+k*500
                if s>X:
                    break
                elif s==X:
                    count+=1
                k+=1
            j+=1
        i+=1
print(count)

Measured memory_bytes: 3064
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-10 19:05:44
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=300010,mod=1000000007;
i64 &Add(i64 &a,i64 b){ return a=(a+b)%mod; }
i64 n,p[N],f[N][2][2],ans,l[N],r[N];
char s[N];
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	p[n+1]=1;
	fd(i,n,1){ p[i]=p[i+1]*(s[i]=='?'?2:1)%mod; l[i]=s[i]=='1'; r[i]=s[i]!='0'; }
	if(n==1){ printf("%d\n",r[1]!=0); return 0; }
	fr(i,l[1],r[1]) f[1][0][i]=1;
	fr(i,1,n-3) fr(j,0,1)
	{
		//k=0
		fr(o,l[i+1],r[i+1]) fr(p,l[i+2],r[i+2]) Add(f[i+2][j][o+p==2],f[i][j][0]);
		//k=1
		if(j==0) fr(o,l[i+1],r[i+1]) Add(f[i+1][1][o],f[i][0][1]);
		else Add(ans,f[i][1][1]*p[i+1]%mod);
	}
//	fr(i,1,n) printf("%I64d %I64d %I64d %I64d\n",f[i][0][0],f[i][0][1],f[i][1][0],f[i][1][1]);
	fr(i,0,1) fr(j,l[n-1],r[n-1]) fr(k,l[n],r[n]) if(i+j+k>=2) Add(ans,f[n-2][0][i]);
	fr(i,0,1) fr(j,l[n],r[n]) if(i+j>=1) Add(ans,f[n-1][1][i]);
	printf("%d\n",int(ans));
	return 0;
}

Measured memory_bytes: 16896
#include<bits/stdc++.h>
#define ll long long int
#define mi map<int,int>
#define mcr map<char,int>
using namespace std;

int main()
{
    ll n, t, k, x, a, b, c, o, e;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}


Measured memory_bytes: 3636
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
Hlist = [int(x) for x in input().split()]

count = 0
for i in range (N):
    if Hlist[i] >= max(Hlist[0:i+1]):
        count+= 1

print(count)


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

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

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, T; cin>>n>>T;
    ll now = -1;
    ll ans = 0;
    rep(i,n){
        ll t; cin>>t;
        if (now>=t){
            ans+=(t+T)-now;
        }else{
            ans+=T;
        }
        now = t+T;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
$Description$
给定一张图（可能存在自环），每个点上有0或1。求是否存在一条路径，使得在上面不断走，能够得到所有01串组合（可以重复经过点）。
$n\leq2\times10^5,m\leq2\times10^5$。
$Solution$
对于一个点，如果它的后继只有0或1，显然它不能在这条路径上。
$Sol 1$
我们把这样的点删掉。然后再判断连向它的点是否要被删掉...这样一直删，判断最后是否存在未被删掉的点。和拓扑排序差不多。
$Sol 2$
由上面的结论也可以看出，路径只能是AABB这样的环（或者AABBAABB...）（这样每个点就存在两种转移）。
AA,AB,BB,BA，这样的环我们可以通过二分图找，即对于相同字符连一条S->T的边，不同字符连一条T->S的边，最后判环。
*/
#include <cstdio>
#include <cctype>
#include <cstdlib>
#define gc() getchar()
const int N=4e5+5;

int Enum,H[N],nxt[N],to[N],vis[N];
char s[N>>1];

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now;
}
inline void AE(int u,int v)
{
	to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
}
void DFS(int x)
{
	vis[x]=1;
	for(int i=H[x],v; i; i=nxt[i])
		if(!vis[v=to[i]]) DFS(v);
		else if(vis[v]==1) {puts("Yes"); exit(0);}
	vis[x]=-1;
}

int main()
{
	int n=read(),m=read(); scanf("%s",s+1);
	for(int u,v; m--; )
	{
		u=read(),v=read();
		s[u]==s[v]?(AE(u,v+n),AE(v,u+n)):(AE(u+n,v),AE(v+n,u));
	}
	for(int i=1; i<=n; ++i) if(!vis[i]) DFS(i);
	puts("No");

	return 0;
}

Measured memory_bytes: 10496
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    if (n == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    long long num = n;
    map<long long, long long> dic;
    for(long long i = 2; i * i <= n; ++i)
    {
        long long r = num % i;
        while (r == 0)
        {
            ++dic[i];
            num = num / i;
            r = num % i;
        }
    }
    // 割り続けて1とならない場合はまだ出ていない素数となるので、これもカウントする
    if (num != 1)
    {
        ++dic[num];
    }

    long long ans = 0;
    for (const auto& e : dic)
    {
        long long cnt = 0;
        long long ex = e.second;
        long long i = 1;
        while(ex > 0)
        {
            ex -= i;
            if (ex < 0) break;
            ++cnt;
            ++i;
        }
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstring>

using namespace std;

struct HL {
    int h, p, q;
} hl[1001];

int main() {
    int n, m, a;

    while (cin >> n >> m >> a) {
        if (!n && !m && !a) { break; }
        memset(hl, 0, sizeof(hl));

        for (int i = 0; i < m; i++) {
            cin >> hl[i].h >> hl[i].p >> hl[i].q;
        }

        int ans = a;

        for (int h = 1000; h > 0; h--) {
            for (int i = 0; i < m; i++) {
                if (hl[i].h != h) { continue; }
                if (hl[i].p == ans) {
                    ans = hl[i].q;
                    break;
                } else if (hl[i].q == ans) {
                    ans = hl[i].p;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
int main()
{
   long long a,b;
   char c;
   cin>>a>>c>>b;
   if(c=='+')
      cout<<a+b;
   else
      cout<<a-b;
   cout<<nl;
    return 0;
}


Measured memory_bytes: 256
t=int(input())
x,y=list(map(str, input().split()))
a=list(x)
b=list(y)
z=[0]*(2*t)
for i in range(2*t):
	if i%2==0:
		z[i]=a[i//2]
	else:
		z[i]=b[i//2]
print(*z,sep=(''))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll INF=100000000000;

int N,Q;
struct LazySegmentTree{
  private:
  int n; vector<ll> node,lazy;
  
  public:
  LazySegmentTree(vector<ll> v){
    int sz=(int)v.size();
    n=1;  while(n<sz)n*=2;
    node.resize(2*n-1);
    lazy.resize(2*n-1,0);
    for(int i=0;i<sz;i++)node[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)node[i]=min(node[2*i+1],node[2*i+2]);
  }
  
  void eval(int k,int l,int r){
    if(lazy[k]!=0){
      node[k]+=lazy[k];
      if(r-l>1){lazy[2*k+1]+=lazy[k]; lazy[2*k+2]+=lazy[k];}
      lazy[k]=0;
    }
  }
  void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    eval(k,l,r);
    if(b<=l || r<=a)return;
    if(a<=l && r<=b){lazy[k]+=x; eval(k,l,r);}
    else{
      add(a,b,x,2*k+1,l,(l+r)/2);
      add(a,b,x,2*k+2,(l+r)/2,r);
      node[k]=min(node[2*k+1],node[2*k+2]);
    }
  }
  ll getsum(int a,int b,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    eval(k,l,r);
    if(b<=l || r<=a)return INF;
    if(a<=l && r<=b)return node[k];
    ll vl=getsum(a,b,2*k+1,l,(l+r)/2);
    ll vr=getsum(a,b,2*k+2,(l+r)/2,r);
    return min(vl,vr);
  }
};

int main(){
  cin >> N >> Q;
  LazySegmentTree seg(vector<ll>(N,0));
  for(int i=0;i<Q;i++){
    int q; cin >> q;
    if(q==0){
      int s,t,x; cin >> s >> t >> x;
      seg.add(s,t+1,x);
    }
    else{
      int s,t; cin >> s >> t;
      cout << seg.getsum(s,t+1) << endl;
    }
  }
}


Measured memory_bytes: 7588
from collections import defaultdict, deque
def main():
  N, M, *L = map(int, open(0).read().split())
  dic = defaultdict(list)
  par =  [None]*N
  cnt = [0]*(N+1)
  for a,b in zip(*[iter(L)]*2):
    dic[a].append(b)
    cnt[b] += 1

  for i in range(1,N+1):
    if cnt[i]==0:
      q = deque([i])
      par[i-1] = '0'
      break
  
  while q:
    m = q.popleft()
    for c in dic[m]:
      cnt[c] -= 1
      if cnt[c]==0:
        par[c-1] = str(m)
        q.append(c)

  ans = '\n'.join(par)
  print(ans)
  
if __name__== '__main__':
  main()


Measured memory_bytes: 37228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> cnt(9,0);
    rep(i,n){
      cin>>a[i];
      if(1<=a[i] && a[i]<=399) cnt[0]++;
      if(400<=a[i] && a[i]<=799) cnt[1]++;
      if(800<=a[i] && a[i]<=1199) cnt[2]++;
      if(1200<=a[i] && a[i]<=1599) cnt[3]++;
      if(1600<=a[i] && a[i]<=1999) cnt[4]++;
      if(2000<=a[i] && a[i]<=2399) cnt[5]++;
      if(2400<=a[i] && a[i]<=2799) cnt[6]++;
      if(2800<=a[i] && a[i]<=3199) cnt[7]++;
      if(3200<=a[i]) cnt[8]++;
    }
    int a1=8-count(begin(cnt),begin(cnt)+8,0);
    int a2=a1+cnt[8];
    if(a1==0){
      a1=1;
    }
    cout<<a1<<' '<<a2<<endl;
}

Measured memory_bytes: 256
def c_train_ticket():
    from itertools import product
    operands = tuple(input())
    # 演算子の選び方は高々 8 通りなので全探索する
    for operators in product('+-', repeat=3):
        formula = ''.join(ch + op for ch, op in zip(operands, operators + ('',)))
        if eval(formula) == 7:
            return formula + '=7'
    return None  # 1 つは答えがあるような入力なので，ここには来ない

print(c_train_ticket())

Measured memory_bytes: 9028
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	cin >> N;
	int ans = mod;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		int cnt = 0;
		while (A % 2 == 0) {
			cnt++;
			A /= 2;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

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

int main() {
  int n, x, d = 0, ans = 1;
  cin >> n >> x;
  int l;
  for (int i = 0; i < n; i++) {
    cin >> l;
    d += l;
    if (d <= x)
      ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import heapq as hq
import bisect as bs

def resolve():
    X,Y,A,B,C = map(int,input().split())
    P = list(map(int,input().split()))
    Q = list(map(int,input().split()))
    R = list(map(int,input().split()))

    P.sort()
    Q.sort()
    R.sort()

    P = P[A-X:]
    Q = Q[B-Y:]
    
    PQ =[]
    for i in P:
        PQ.append([i,0])    
    for i in Q:
        PQ.append([i,1])

    PQ.sort()
    mn = PQ[0][0]

    point =bs.bisect_right(R,mn)
    R=R[point:]

    for i in R:
        PQ.append([i,2])
    PQ.sort(reverse= True)
    AC=0
    BC=0
    CC=0

    score =0
    R = []
    for i in PQ:
        if i[1]==0 and AC < X:
            score += i[0]
            AC+=1
        if i[1]==1 and BC < Y:
            score += i[0] 
            BC+=1
        if i[1]==2:
            R.append(i[0])
            CC+=1
        
        if AC + BC +CC >= X+Y:
            break

    for i in range(CC):
        score+=R[i]
    
    print(score)








if __name__ == "__main__":
    resolve()

Measured memory_bytes: 124908
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    map<char,int> m;
    REP(i,n) {
        char c; cin >> c;
        m[c]++;
    }

    if (m.size() == 3) OUT("Three")
    else OUT("Four")


    return 0;
}

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

using namespace std;
typedef char TElemType;
#define OK 1
typedef int Status;
typedef struct BiNode {
    TElemType data;
    struct BiNode *lchild, *rchild;
} BiNode, *BiTree;
const int MAXN = 200005;
const int INF = 0x3f3f3f3f;

void CreateBiTree(BiTree &T) {
    if (T == NULL) {
        T = new BiNode;
        T->data = 'c';
    } else {
        CreateBiTree(T->rchild);
        CreateBiTree(T->lchild);
    }
}

int pr(BiTree T) {
    if (T == NULL) return OK;
    else {
        pr(T->lchild);
        cout << T->data;
        pr(T->rchild);
    }
}

int main() {
# ifdef ONLINE_JUDGE
# else
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
# endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long a, c, d;
    double b;
    scanf("%lld %lf", &a, &b);
    d = round(b * 100.00);
    //  cout<<d<<endl;
    c = a * d;
    c /= 100;
    printf("%lld", c);
    return 0;

}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,a,b,c;
  cin >> A >> B;
  a=A+B;
  b=A-B;
  c=A*B;
  vector<int> AA(3);
  AA.at(0)=a;
  AA.at(1)=b;
  AA.at(2)=c;
  sort(AA.begin(), AA.end());
  cout << AA.at(2) << endl;
}

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

using namespace std;

int n,d,x,arr[105];

int main(){
	cin >> n >> d >> x;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	int help[105];
	for(int i = 0; i < n; i++){
		help[i] = 1;
	}
	int choc = 0;
	for(int k = 1; k <= d; k++){
		for(int i = 0; i < n; i++){
			if(help[i] == k){
				choc++;
				help[i] += arr[i];
			}
		}
	}
	cout << choc + x;
}

Measured memory_bytes: 256
N = int(input())

m = dict()
for i in range(1, N + 1):
    n = str(i)
    s = n[0]
    t = n[-1]
    
    if t == 0:
        continue
    
    k = (s, t)
    if k in m:
        m[k] += 1
    else:
        m[k] = 1

ans = 0
for k, v in m.items():
    s, t = k
    if s == t:
        ans += v ** 2
    else:
        if (t, s) in m:
            ans += v * m[(t, s)]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  string s;
  cin >> s;
  if(s=="Sunny") cout << "Cloudy" << endl;
  else if(s=="Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int n;
	cin >> n;
	string p = to_string(n);
	if (p[0] == p[2])print("Yes"); else print("No");





	return 0;
}

Measured memory_bytes: 256
uses math;
var
	ans,n,Ma,Mb,i,j,a,b,c,x:Longint;
	p,m:array[0..400]of Longint;
begin
	read(n,Ma,Mb);
	ans:=10000;
	for i:=1 to 400 do begin
		p[i]:=ans;
		m[i]:=ans;
	end;
	for i:=1 to n do begin
		read(a,b,c);
		x:=Ma*b-Mb*a;
		if x>0 then begin
			for j:=400-x downto 0 do p[j+x]:=min(p[j+x],p[j]+c);
		end else if x<0 then begin
			for j:=400+x downto 0 do m[j-x]:=min(m[j-x],m[j]+c);
		end else ans:=min(ans,c);
	end;
	for i:=1 to 400 do ans:=min(ans,p[i]+m[i]);
	if ans<10000 then writeln(ans)else writeln(-1);
end.


Measured memory_bytes: 128
#include <iostream>
#include <utility>
using namespace std;
typedef pair<int,int> P;
int main(){
	int a;
	char board[8][9];
	P l[4];
	while(cin >> board[0]){
		a = 0;
		for(int i = 1;i < 8;++i){
			cin >> board[i];
		}
		for(int i = 0;i < 8;++i){
			for(int j = 0;j < 8;++j){
				if(board[i][j] == '1'){
					l[a].first = j;
					l[a].second = i;
					++a;
				}
			}
		}
		if(l[3].first - l[0].first == 3){
			cout << 'C' << endl;
		}
		else if(l[3].second - l[0].second == 3){
			cout << 'B' << endl;
		}
		else if(l[3].second - l[0].second == l[3].first - l[0].first){
			cout << 'A' << endl;
		}
		else if(l[0].first == l[3].first){
			cout << 'G' << endl;
		}
		else if(l[3].first - l[0].first == 2){
			cout << 'E' << endl;
		}
		else if(l[3].first - l[0].first == -1){
			cout << 'D' << endl;
		}
		else cout << 'F' << endl;
	}
	return 0;
}

Measured memory_bytes: 1132
## 3
#N = 7
#A = [1, 2, 3, 4, 5, 6]
N = int(input())
A = list(map(int, input().split()))

sub = [0] * N
for i in range(N-1):
    sub[A[i]-1] += 1

for s in sub:
    print(s)

Measured memory_bytes: 32248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int minDist = 1000000;
		int minNum = -1;
		for(int i=10000;i>=0;i--) {
			if (isPalindromic(i)) {
				if (Math.abs(n-i) <= minDist) {
					minDist = Math.abs(n-i);
					minNum = i;
				}
			}
		}
		System.out.println(minNum);
	}

	public static boolean isPalindromic(int n) {
		String s = String.valueOf(n);
		for(int i=0;i<s.length()/2;i++) {
			if (s.charAt(i) != s.charAt(s.length()-1-i)) {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 20448
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  while(1) {
    int n;
    cin>>n;
    if( n==0) break;
    int dp[301] = {};
    for(int j=0;j<=300;j++) dp[j] = 1;

    for(int i=2;i*i<=n;i++) 
      for(int j=0;j<=n;j++)
	if(j-i*i >= 0) dp[j] += dp[j-i*i];
    cout << dp[n] <<endl;
  }
return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,enable_if_t<iterable<T>::value,int> =0>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}
template<class T,enable_if_t<is_integral<T>::value,int> =0>T mod(T a, T b){if(a>0)return a%b;return b-(-a%b);}
template<class T,enable_if_t<is_floating_point<T>::value,int> =0>T mod(T a, T b){if(a>0)return a%b;return b-fmod(-a,b);}
inline ll ka(ll a, ll b){
    return (a+b-1)/b;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    ll n;
    ll a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    b-=a;
    if(b<0)b=-b;
    ll w=(d-c)*(n-1);
    if(!(c||d)){
        YES(0);
        return 0;
    }
    dprint(b,w);
    dprint((-d*(n-1)-b+w));
    ll ncc=ka(-(-d*(n-1)-b+w), d+c);
    ll nc = ncc*c-(n-1-ncc)*d-b+w;
    dprint(ncc,nc);
    if(0<=ncc && ncc <= n-1 && 0<=nc && nc<=w){
        YES(1);
        return 0;
    }
    YES(0);
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt
  val a = Array.fill(m)(sc.nextInt)

  val alts = Map(
    1 -> 2,
    2 -> 5,
    3 -> 5,
    4 -> 4,
    5 -> 5,
    6 -> 6,
    7 -> 3,
    8 -> 7,
    9 -> 6
  ).filter(i => a.contains(i._1)).toList.sortBy(-_._1)

  val dp = Array.fill(n + 1)(-1)
  dp(0) = 0

  for (i <- 1 to n) {
    dp(i) = {
      val next = alts.filter(_._2 <= i).map{ alt =>
        if (dp(i - alt._2) == -1) -1
        else dp(i - alt._2) + 1
      }
      if (next.size == 0) -1 else next.max
    }
  }

  val ans = Array.fill(dp(n))(0)
  var rest = n

  for (i <- 0 until dp(n)) {
    val next = alts.filter(_._2 <= rest)
      .find(i => dp(rest - i._2) == dp(rest) - 1).get
    ans(i) = next._1
    rest -= next._2
  }

  println(ans.mkString(""))
}

Measured memory_bytes: 38660
// 2020-08-22 21:32:54
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<P> t(m), hc(h), wc(w);
  rep(i, h) hc[i] = P(0, i);
  rep(i, w) wc[i] = P(0, i);
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--; wi--;
    t[i] = P(hi, wi);
    hc[hi].first++;
    wc[wi].first++;
  }
  sort(ALL(t));
  sort(RALL(hc));
  sort(RALL(wc));
  int ans = 0;
  int hm = hc[0].first;
  int wm = wc[0].first;
  bool br = false;
  for(const auto [hn, hi] : hc) {
    for(const auto [wn, wi] : wc) {
      if(hn < hm && wn < wm) { br = true; break; }
      if(hn + wn <= ans) break;
      auto itr = lower_bound(ALL(t), P(hi, wi));
      if(itr != t.end() && (*itr) == P(hi, wi)) {
        chmax(ans, hn + wn - 1);
      } else {
        chmax(ans, hn + wn);
      }
    }
    if(br) break;
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 10308
using System;

namespace AtCoder.ABC096
{
    class b
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var spl = line.Split(' ');
            var A = int.Parse(spl[0]);
            var B = int.Parse(spl[1]);
            var C = int.Parse(spl[2]);
            var K = int.Parse(Console.ReadLine().Trim());
            var max = Math.Max(A, Math.Max(B, C));
            Console.WriteLine(A + B + C + max * (Math.Pow(2, K) - 1));
        }
    }
}


Measured memory_bytes: 11092
N, M, Q = map(int, input().split())


class Ruisekiwa2D:
    def __init__(self, h, w):
        self.H = h
        self.W = w
        self.G = [[0] * w for _ in range(h)]

    def load(self, points):
        # 問題によってイメージしやすいよう書き換えてください
        # load終了時にcalcが呼ばれることに注意してください
        for x, y in points:
            self.G[x][y] += 1

        self.calc()

    def load_imos(self, points):
        # pointsは[[左上h, 左上w, 右下h, 右下w], ...]であること
        for i1, j1, i2, j2 in points:
            self.G[i1][j1] += 1  # 左上
            if j2 + 1 < self.W:  # 右上
                self.G[i1][j2+1] -= 1
            if i2 + 1 < self.H:
                self.G[i2+1][j1] -= 1  # 左下
            if j2 + 1 < self.W and i2 + 1 < self.H:  # 右下
                self.G[i2+1][j2+1] += 1

        self.calc()

    def calc(self):
        for y in range(self.W):
            for x in range(1, self.H):
                self.G[x][y] += self.G[x-1][y]

        for y in range(1, self.W):
            for x in range(self.H):
                self.G[x][y] += self.G[x][y-1]

    def get(self, i1, j1, i2, j2):
        if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
            return 0
        elif i1 > 0 and j1 > 0:
            return self.G[i2][j2] - self.G[i1-1][j2] - self.G[i2][j1-1] + self.G[i1-1][j1-1]
        elif i1 <= 0 < j1:
            return self.G[i2][j2] - self.G[i2][j1-1]
        elif j1 <= 0 < i1:
            return self.G[i2][j2] - self.G[i1 - 1][j2]
        else:
            return self.G[i2][j2]


R2D = Ruisekiwa2D(N, N)
I = []
for i in range(M):
    l, r = map(int, input().split())
    l, r = l -1, r- 1
    I.append((l, r))
R2D.load(I)

for i in range(Q):
    p, q = map(lambda x: int(x) - 1, input().split())
    print(R2D.get(p, p, q, q))


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

int main() {
  int N;
  cin >> N;
  int S, H, J, I;
  
  S = N / 1000;
  N = N % 1000;
  H = N / 100;
  N = N % 100;
  J = N / 10;
  N = N % 10;
  I = N;

  if (S == H){
    if (H == J){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else if(H == J){
    if (J == I){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl; 
    }
  }else{
      cout << "No" << endl;
  }
}  

Measured memory_bytes: 256
""" abc055_a """

import sys

H = pow(10, 9) + 7

def _main():
    _n = int(sys.stdin.readline())
    answers = list(map(lambda a: a == 'o', sys.stdin.readline()))

    # ooxoox
    # S-----
    # a[0] = o: SS---S
    # a[1] = o: SSS--S
    # a[2] = x: SSSW-S
    # a[3] = o: SSSWWS
    # a[4] = o: SSSWWS OK
    # a[5] = x: SSSWWS OK

    def _evaluate(zoo_first, zoo_last):

        zoo = [None] * _n

        zoo[0] = zoo_first == 'S'
        zoo[_n-1] = zoo_last == 'S'

        for i in range(0, _n):
            same = answers[i] if zoo[i] else not answers[i]
            next_z = zoo[(i-1)%_n] if same else not zoo[(i-1)%_n]
            if zoo[(i+1)%_n] is None:
                zoo[(i+1)%_n] = next_z
            else:
                if zoo[(i+1)%_n] != next_z:
                    return -1

        return zoo

    for _f, _l in [['S', 'S'], ['W', 'W'], ['S', 'W'], ['W', 'S'],]:
        result = _evaluate(_f, _l)
        if -1 != result:
            print(_format(result))
            return

    print(-1)

def _format(result):
    return ''.join(map(lambda e: 'S' if e else 'W', result))

if __name__ == '__main__':
    _main()


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

using namespace std;

struct Point {
    int x, y;
};

Point ReadPoint() {
    int x, y;
    cin >> x >> y;
    return Point{x, y};
}

int main() {
    auto from = ReadPoint(), to = ReadPoint();
    int n; cin >> n;
    vector<Point> points;
    while (n--) {
        points.push_back(ReadPoint());
    }

    if (to.x < from.x) {
        to.x = -to.x;
        from.x = -from.x;
        for (auto& p : points)
            p.x = -p.x;
    }

    if (to.y < from.y) {
        to.y = -to.y;
        from.y = -from.y;
        for (auto& p : points)
            p.y = -p.y;
    }

    const double bullshit = 20.0 * atan(1.0);

    cout << fixed << setprecision(12);

    if (to.x == from.x) {
        double ans = to.y - from.y;
        ans *= 100;

        for (auto& p : points) {
            if (p.x == to.x && p.y > from.y && p.y < to.y)
                ans += 2 * bullshit - 2 * 10;
        }
        cout << ans << endl;
        return 0;
    }


    if (to.y == from.y) {
        double ans = to.x - from.x;
        ans *= 100;

        for (auto& p : points) {
            if (p.y == to.y && p.x > from.x && p.x < to.x)
                ans += 2 * bullshit - 2 * 10;
        }
        cout << ans << endl;
        return 0;
    }


    points.erase(remove_if(
        points.begin(),
        points.end(),
        [&](Point p) {
            return p.x < from.x or p.x > to.x or p.y < from.y or p.y > to.y;
        }
    ), points.end());

    sort(points.begin(), points.end(), [](Point a, Point b) {
            return a.x < b.x;
    });
    vector<int> allYs;
    for (auto& p : points)
        allYs.push_back(p.y);
    sort(allYs.begin(), allYs.end());

    vector<int> T(points.size() + 1, 0);

    auto update = [&](int pos, int val) {
        for (++pos; pos < (int)T.size(); pos += (pos & -pos))
            T[pos] = max(T[pos], val);
    };
    auto query = [&](int pos) {
        int ans = 0;
        for (++pos; pos > 0; pos -= (pos & -pos))
            ans = max(ans, T[pos]);
        return ans;
    };

    int best = 0;
    for (auto p : points) {
        p.y = lower_bound(allYs.begin(), allYs.end(), p.y) - allYs.begin();
        int now = 1 + query(p.y);
        best = max(best, now);
        update(p.y, now);
    }

    cerr << "Best: " << best << endl;

    double ans = to.x - from.x + to.y - from.y;
    ans *= 100;

    ans -= 20 * best;
    ans += bullshit * best;

    cerr << ans << endl;
    if (best >= to.x - from.x + 1 or best >= to.y - from.y + 1) {
        ans += bullshit;
    }

    cout << ans << endl;

    return 0;
}


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

int main(void) {
  int x, y, z, k, s;
  cin >> k >> s;

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

  cout << cnt << endl;
}


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


int main() {
    int K, S, ans=0;
    cin >> K >> S;
    for (int i = 0; i <= K; ++i) {
        for (int j = 0; j <= K; ++j) {
            int z = S - i - j;
            if (z >= 0 && z <= K) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def LunLun(k, count, base):
    nx = []
    n = len(base)
    if count + n >= k:
        print(base[k - count - 1])
        return
    for x in base:
        count += 1
        p = x % 10
        x *= 10
        a = x + p - 1
        b = a + 1
        c = b + 1
        n = 3
        if p == 0:
            n -= 1
            nx.extend([b, c])
        elif p == 9:
            n -= 1
            nx.extend([a, b])
        else:
            nx.extend([a, b, c])

    LunLun(k, count, nx)


def main():
    k = int(input())
    base = range(1, 10)
    LunLun(k, 0, base)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18312