akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

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

const int MaxN = 1000;
const int MaxV = MaxN * (MaxN - 1) / 2;

vector<vector<int>> id(MaxN, vector<int>(MaxN));
vector<vector<int>> to(MaxV);

bool visited[MaxV];
bool calculated[MaxV];
int dp_maxLength[MaxV];

int toId(int i, int j)
{
    if (i > j) swap(i, j);
    return id[i][j];
}

int dfs(int v)
{
    if (visited[v])
    {
        if (!calculated[v]) return -1;
        return dp_maxLength[v];
    }
    
    visited[v] = true;
    dp_maxLength[v] = 1;
    
    for (int u : to[v])
    {
        int res =  dfs(u);
        if (res == -1) return -1;
        dp_maxLength[v] = max(dp_maxLength[v], res+ 1);
    }
    
    calculated[v] = true;
    
    return dp_maxLength[v];
    
}

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    vector<vector<int>> a(N, vector<int>(N-1));
    rep(i, N)rep(j, N - 1)
    {
        cin >> a[i][j];
        --a[i][j];
    }
    
    // init id
    int V = 0;
    rep(i, N)rep(j, N)
    {
        if (i < j) id[i][j] = V++;
    }
    
    // init to (graph)
    rep(i, N)
    {
        vector<int> matches(N - 1);
        rep(j, N - 1)
        {
            matches[j] = toId(i, a[i][j]);
        }
        rep(j, N - 2)
        {
            to[matches[j + 1]].push_back(matches[j]);
        }
    }
    
    int ans = 0;
    rep(i, V)
    {
        int res = dfs(i);
        if (res == -1)
        {
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, res);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 38400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	ll N, K;
	cin >> N >> K;
	vector<int> P(N + 1, 0);
	for (int i = 1; i <= N; i++) {
		cin >> P[i];
	}
	vector<ll> C(N + 1, 0);
	ll aC = 0;
	for (int i = 1; i <= N; i++) {
		cin >> C[i];
		aC += C[i];
	}

	ll cMax = -10000000000;
	for (int i = 1; i <= N; i++) {
		// i から start
		int p = i;
		ll c = 0;
		for (int j = 1; j <= K; j++) {
			p = P[p];
			c += C[p];
			if (cMax < c) cMax = c;
			if (p == i) {
				ll l = ((K - j) / j) - 1;
				l = (l < 0 ? 0 : l);
				j += l * j;
				c += l * c;
				if (cMax < c) cMax = c;
			}
		}
	}
	cout << cMax << endl;
	return(0);
}


Measured memory_bytes: 3696
import sys
def m(L,R):
 global c
 T=[];i=j=0
 for _ in L[:-1]+R[:-1]:
  if L[i]<R[j]:T+=[L[i]];i+=1
  else:T+=[R[j]];j+=1
  c+=1
 return T
def d(A):s=len(A)//2;return m(d(A[:s])+[1e9],d(A[s:])+[1e9]) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,sys.stdin.readline().split()))))
print(c)


Measured memory_bytes: 62604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  rep(i, N) cin >> D[i];
  sort(all(D));
  int ans = D[N/2-1] == D[N/2] ? 0 : D[N/2] - D[N/2-1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int q; cin >> q;
	for (int i = 0; i < q; i ++) {
		long long a, b; cin >> a >> b;
swap(a,b);
		long long root = sqrt(a*b);
		long long ans = root + (a*b-1)/root - (a!=b);
		if (root >= a) ans --;
		if ((a*b-1)/root >= b) ans --;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
def resolve():
    X, Y = map(int, input().split())

    for i in range(X+1):
        turu = 2*i
        kame = 4*(X-i)
        tot = turu + kame
        if tot == Y:
            print("Yes")
            return
    else:
        print("No")

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
 
#define __m int mid=(l+r)>>1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
 
template<class T>
inline bool rd(T &num) {
    char in;
    bool IsN = false;
    while(in = getchar(), in != '-' && (in < '0' || in > '9'))if(in == EOF)return false;
    in == '-' ? (IsN = true, num = 0) : num = in - '0';
    while(in = getchar(), in >= '0' && in <= '9')num = num * 10 + in - '0';
    return IsN ? num = -num : num, true;
}
 
#define rep(i,a,b) for(register int i = (a); i< (b); i++)
#define per(i,a,b) for(register int i = (a); i> (b); i--)
#define clr(a) memset(a,0,sizeof(a))
#define inf(a) memset(a,0x3f,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define rd2(a,b) rd(a)&&rd(b)
#define rd3(a,b,c) rd(a)&&rd(b)&&rd(c)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
 
string nico;
#ifdef LOCAL
#define bug(x) cout<<#x<<" : "<<x<<endl
#define infile(x) freopen(x,"r",stdin)
#define outfile(x) freopen(x,"w",stdout)
#else
#define bug(x)
#define infile(x)
#define outfile(x)
#endif
 
const int maxn = 4e6 + 7;
const int inf  = 0x3f3f3f3f;
const LL linf  = (LL)inf << 32 | inf;
const int mod  = 1e9 + 7;
 
int main(){
    int ans=inf;
    int num[3];
    cin>>num[0]>>num[1]>>num[2];
    do{
        ans = min(ans,abs(num[1]-num[0])+abs(num[1]-num[2]));
    }while(next_permutation(num,num+3));
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    map<char, int> cnt;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char a;
            cin >> a;
            cnt[a]++;
        }
    }

    int g1 = (H * W) % 2;
    int g2 = (H % 2 == 0 ? 0 : W / 2) + (W % 2 == 0 ? 0 : H / 2);
    int g3 = H * W - g1 - g2;
    for (auto& p : cnt) {
        if (g1 == 0)
            break;
        if (p.second % 4 == 1 || p.second % 4 == 3) {
            p.second--;
            g1--;
        }
    }
    for (auto& p : cnt) {
        if (g2 == 0)
            break;
        if (p.second % 4 == 2) {
            p.second -= 2;
            g2--;
        }
    }
    for (auto& p : cnt) {
        if (g3 == 0)
            break;
        if (p.second % 4 == 0) {
            while (p.second > 0 && g3 > 0) {
                p.second -= 4;
                g3--;
            }
        }
    }
    for (auto& p : cnt) {
        if (p.second != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
    }

    int ans[n+1] = {0};
    for(int i = 0; i < m; i++){
        ans[a[i]]++;
        ans[b[i]]++;
    }

    for(int i = 1; i <= n; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class MainClass
{
    static void Main()
    {
        var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = r[0], K = r[1], L = r[2];
        var road = new Union_Find(N);
        var rail = new Union_Find(N);
        for (int i = 0; i < K; i++)
        {
            r = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            road.Unite(r[0], r[1]);
        }
        for (int i = 0; i < L; i++)
        {
            r = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            rail.Unite(r[0], r[1]);
        }
        var dic = new Dictionary<Tuple<int, int>, int>();
        for (int i = 0; i < N; i++)
        {
            if (dic.ContainsKey(Tuple.Create(road.Root(i),rail.Root(i))))
            {
                dic[Tuple.Create(road.Root(i), rail.Root(i))]++;
            }
            else
            {
                dic[Tuple.Create(road.Root(i), rail.Root(i))] = 1;
            }
        }
        var ans = new int[N];
        for (int i = 0; i < N; i++)
        {
            ans[i] = dic[Tuple.Create(road.Root(i), rail.Root(i))];
        }
        Console.WriteLine(string.Join(" ",ans));
    }
}

public class Union_Find
{
    private int[] data;
    public Union_Find(int size)
    {
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);
        if (x != y)
        {
            if (data[y] < data[x])
            {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    public bool IsSameGroup(int x, int y) => Root(x) == Root(y);
    public int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]);
    public int getMem(int x) => -data[Root(x)];
}

Measured memory_bytes: 38404
N = gets.to_i
S = gets.chomp

cnt = 0
k = 0
l = 0
N.times do |i|
  
  if S[i] == ?(
    
    cnt += 1
    
  else
    
    cnt -=1
    if cnt < 0
      k += 1
      cnt = 0
    end
    
  end
  
  # p cnt
  
end

puts ?( * k + S + ?) * cnt

Measured memory_bytes: 3836
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;
    if(n==m)
    {
        cout<<"Yes"<<endl;
    }
    else

    {
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 3664
a, b = map(int, input().split())
import fractions
import math
n = fractions.gcd(a,b)
a = []
while n % 2 == 0:
  a.append(2)
  n //= 2
f = 3
while f * f <= n:
  if n % f == 0:
    a.append(f)
    n //= f
  else:
    f += 2
if n != 1:
  a.append(n)
print(len(set(a))+1)

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n+k,0);
    vector<int> dp(n+k,1000000000);
    for(int i=0;i<n;i++){
        cin >> h.at(i);
    }
    dp.at(0)=0;

    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            dp.at(i+j)=min(dp.at(i+j),dp.at(i)+abs(h.at(i+j)-h.at(i)));
        }
    }
    cout << dp.at(n-1);

}

Measured memory_bytes: 1024
#include <iostream>
#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>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {

    ll K, X;
    cin >> K >> X;

    if (500 * K >= X){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)

vector<int> makePrimeLst(int N)
{
    if (N < 2) return vector<int>();
    if (N == 2) return vector<int>{2};
    vector<int> ans;
    vector<int> alive(N+1, 1);
    for (int i=2; (long long)i*i<=(long long)N; i++)
    {
        if (alive[i]) ans.push_back(i);
        for (int t = i; t<=N; t += i) alive[t] = 0;
    }
    for (int i=ans.back()+1; i<=N; i++) if (alive[i]) ans.push_back(i);
    return ans;
}

constexpr int Nmax = 503;
lint ans[Nmax][Nmax];

int main()
{
    vector<int> info = makePrimeLst(100000);
    vector<lint> p, q;
    int now = 2;
    while (p.size() < Nmax + 1)
    {
        p.insert(p.begin(), info[now++]);
        q.insert(q.begin(), info[now++]);
        p.push_back(info[now++]);
        q.push_back(info[now++]);
    }

    set<int> seen;
    REP(i, Nmax) REP(j, Nmax)
    {
        int u = (i + j) / 2, v = (i + (Nmax - 1 - j)) / 2;
        if ((i + j) & 1)
        {
            ans[i][j] = p[u + 1] * q[v + 1];
        }
        else
        {
            ans[i][j] = p[u] * p[u + 1] * q[v] * q[v + 1] + 3;
        }
        // if (seen.find(ans[i][j]) != seen.end()) exit(1);
        if (ans[i][j] > 1000000000000000LL) exit(1);
        seen.insert(ans[i][j]);
    }

    int N;
    cin >> N;
    REP(i, N) REP(j, N)
    {
        lint min_ = min(ans[i][j], ans[i + 1][j]);
        lint max_ = max(ans[i][j], ans[i + 1][j]);
        if (max_ % min_ != 3) exit(1);
    }
    REP(i, N) REP(j, N)
    {
        lint min_ = min(ans[i][j], ans[i][j + 1]);
        lint max_ = max(ans[i][j], ans[i][j + 1]);
        if (max_ % min_ != 3) exit(1);
    }

    REP(i, N)
    {
        REP(j, N) cout << ans[i][j] << (j == N - 1 ? "\n" : " ");
    }
}


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

using namespace std;
typedef long long ll;

int A, B;

int main()
{
	ios_base::sync_with_stdio(0);

	cin >> A >> B;

	int tot = 1, ans = 0;

	while (tot < B)
	{
		tot = tot - 1 + A;
		ans++;
	}

	cout << ans;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(void) {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i, n) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(i, n) rep(j, i) {
    int ng = -1;
    int ok = j;
    int mid = 0;
    while(abs(ok - ng) > 1) {
      int mid = (ok + ng) / 2;
      if(L[mid] + L[j] > L[i])
        ok = mid;
      else
        ng = mid;
    }
    ans += j - ok;
  }
  cout << ans << endl;
  return 0;
}

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

x = [0] * N
if S[0] == "E":
    x[0] = 1

for i in range(N-1):
    if S[i+1] == "E":
        x[i+1] = x[i] + 1
    else:
        x[i+1] = x[i]

z = x[N-1]
if S[0] == "E":
    ans = z-1
else:
    ans = z

for i in range(N-1):
    tmp = z - 2 * x[i]
    if S[i+1] == "E":
        tmp = tmp - 1
    tmp += (i+1)
    if ans > tmp:
        ans = tmp

print(ans) 

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

if H%3==0 or W%3==0:
    print(0)
else:
    ans5=W
    ans6=H
    ans1=max(int(H/3)*W,(H-int(H/3))*int(W/2),H*W-int(H/3)*W-(H-int(H/3))*int(W/2))-min(int(H/3)*W,(H-int(H/3))*int(W/2),H*W-int(H/3)*W-(H-int(H/3))*int(W/2))
    ans2=max((int(H/3)+1)*W,(H-int(H/3)-1)*int(W/2),H*W-(int(H/3)+1)*W-(H-int(H/3)-1)*int(W/2))-min((int(H/3)+1)*W,(H-int(H/3)-1)*int(W/2),H*W-(int(H/3)+1)*W-(H-int(H/3)-1)*int(W/2))
    ans3=max(int(W/3)*H,(W-int(W/3))*int(H/2),W*H-int(W/3)*H-(W-int(W/3))*int(H/2))-min(int(W/3)*H,(W-int(W/3))*int(H/2),W*H-int(W/3)*H-(W-int(W/3))*int(H/2))
    ans4=max((int(W/3)+1)*H,(W-int(W/3)-1)*int(H/2),H*W-(int(W/3)+1)*H-(W-int(W/3)-1)*int(H/2))-min((int(W/3)+1)*H,(W-int(W/3)-1)*int(H/2),H*W-(int(W/3)+1)*H-(W-int(W/3)-1)*int(H/2))
    print(min(ans1,ans2,ans3,ans4,ans5,ans6))

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

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

  int ans=0;
  for(int i=1; i<=n; ++i){
    int m=i, num=0;
    while(m!=0){m/=10; ++num;}
    if(num%2!=0)++ans;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
    
  if (abs(a-b)<=d && abs(c-b)<=d){
    cout << "Yes" << endl;
  }
  else if (abs(a-c)<=d){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC104
{
    class Program
    {
        static void Main(string[] args)
        {
            //65 90 67
            string s = Console.ReadLine();
            string subs = "";
            string ans = "AC";
            int flag = 0;
            if (s.Substring(0, 1) != "A") { ans = "WA"; }
            if (s[1]>=65&&s[1]<=90) { ans = "WA"; }
            for (int i = 2; i < s.Length-1; i++)
            {
                subs = s.Substring(i, 1);
                if ((s[i] >= 65 && s[i] <= 90) && (flag == 1||s[i] != 67)) { ans = "WA"; }
                if (subs == "C") { flag = 1; }

            }
            if (flag == 0) { ans = "WA"; }
            if(s[s.Length-1]<=90&&s[s.Length-1]>=65) { ans = "WA"; }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
fn main() {
    let nk: Vec<usize> = read_vec();
    let (n, k) = (nk[0], nk[1]);
    let mut v: Vec<isize> = Vec::new();
    for i in 0..n {
        let h = read();
        v.push(h);
    }
    v.sort();
    let mut d: Vec<isize> = Vec::new();
    for i in 0..n - k + 1 {
        let f = v[i] - v[i + k - 1];
        if f >= 0 {
            d.push(f);
        } else {
            d.push(-f);
        }
    }
    let mut min = 10000000000;
    for i in d {
        if min > i {
            min = i;
        }
    }
    println!("{}", min);
}

// ########################################################################################### //

// 標準入力から一行を読み取り、指定の型に変換する関数
pub 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()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

// 10進数での各桁の和
pub fn sum_dights(x: isize) -> isize {
    if x % 10 == 0 {
        return 0;
    }
    let m = x % 10;
    m + sum_dights((x - m) / 10)
}


Measured memory_bytes: 6396
# include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=10;
const int MAXV=100;
                                
    ll edges[maxn][maxn];                                                                       //图中当前的顶点数和边数         

ll path[MAXV][MAXV];
ll A[MAXV][MAXV];int n;
void Floyd()
{
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
{
A[i][j]=edges[i][j];
path[i][j]=-1;
}

for(int k=0;k<=n;k++)
{for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
if(A[i][j]>(A[i][k]+A[k][j]))
{
A[i][j]=A[i][k]+A[k][j];
path[i][j]=k;
}
}
}
int main()
{
	
	n=9;
	
	int c,r;
	cin>>r>>c;
	for(int i=0;i<=9;i++)
		for(int j=0;j<=9;j++){
			scanf("%d",&edges[i][j]);
		}
	Floyd();
	
	int t;
	ll ans=0;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			scanf("%d",&t);
			if(t==1||t==-1) continue;
			ans+=A[t][1];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N, K;
        {int[] a = in.ii(); N = a[0]; K = a[1];}

        int[] D = in.ii();

        boolean[] no = new boolean[10];

        for(int i = 0; i < K; i++){
          no[D[i]] = true;
        }

        int i = N;
        for(; i <= 10*N; i++){
          int j = i;
          while(j > 0 && !no[j%10]) j /= 10;
          if(j == 0) break;
        }
        out.println(i);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


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

using namespace std;

typedef long long ll;

#define db(m)  cout<<#m<<" = "<<m<<"\n"

#define MAX 100000

void bang(){
    string s; cin>>s;
    ll tot = 0;
    for(auto c : s) tot += (int) c - '0';
    cout<<(tot % 9ll == 0 ? "Yes\n" : "No\n");
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // int q; cin>>q;
    // while(q--)
        bang();
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>

using namespace std;

int main()
{
    int h,w;
    cin >>h>>w;
    char C[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>C[i][j];
        }
    }

     for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<C[i][j];
        }
        cout<<endl;
        for(int j=0;j<w;j++){
            cout<<C[i][j];
        }
        cout<<endl;

    }


}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int arr[] = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt();
        int num[] = new int[n];
        for (int i=0; i<n; i++) num[i] = i+1;

        int count = 0;

        for (int i=0; i<n; i++){
            if (arr[i]!=num[i]){
                count++;
            }
        }
        if ((count==0) || (count==2)){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}


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

int main() {
  string s;
  cin >> s;
  
  bool jud = true;
  
  if (s.at(0) != 'A') jud = false;
  
  if (s.find('C') != s.rfind('C') || !(s.find('C') >= 2 && s.find('C') <= s.size()-2)) jud = false;
  
  int cnt = 0;
  for (int i=0;i<s.size(); i++){
    if (islower(s.at(i))) cnt++;
  }
  if (cnt != s.size()-2) jud = false;
  
  if (jud) cout << "AC" << endl;
  else cout << "WA" << endl;
  
}


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

using namespace std;

int main(){
	
	int x,y[5]={0},ans=0;
	cin>>x;
	y[0]=x/1000;y[1]=x/100%10;y[2]=x/10%10;y[3]=x%10;
	for(int i=0;i<4;i++)ans+=y[i];
	if(ans==7)cout<<y[0]<<"+"<<y[1]<<"+"<<y[2]<<"+"<<y[3]<<"=7\n";
	else if(y[1]==(ans-7)/2)cout<<y[0]<<"-"<<y[1]<<"+"<<y[2]<<"+"<<y[3]<<"=7\n";
	else if(y[2]==(ans-7)/2)cout<<y[0]<<"+"<<y[1]<<"-"<<y[2]<<"+"<<y[3]<<"=7\n";
	else if(y[3]==(ans-7)/2)cout<<y[0]<<"+"<<y[1]<<"+"<<y[2]<<"-"<<y[3]<<"=7\n";
	else if(y[1]+y[2]==(ans-7)/2)cout<<y[0]<<"-"<<y[1]<<"-"<<y[2]<<"+"<<y[3]<<"=7\n";
	else if(y[1]+y[3]==(ans-7)/2)cout<<y[0]<<"-"<<y[1]<<"+"<<y[2]<<"-"<<y[3]<<"=7\n";
	else if(y[3]+y[2]==(ans-7)/2)cout<<y[0]<<"+"<<y[1]<<"-"<<y[2]<<"-"<<y[3]<<"=7\n";
	else if(y[1]+y[2]+y[3]==(ans-7)/2)cout<<y[0]<<"-"<<y[1]<<"-"<<y[2]<<"-"<<y[3]<<"=7\n";
	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 2e5+5;
LL a[MAX] , b[MAX] , dp[MAX];
LL ST[4*MAX + 5];

LL query(LL start , LL end , LL node , LL s , LL e)
{
        if(e < start || s > end || start > end) return 0;
        if(s <= start && e >= end)
        {
                return ST[node];
        }
        LL mid = (start + end)/2;
        return max(query(start,mid,2*node,s,e) , query(mid+1,end,2*node+1,s,e));
}

void update(LL start , LL end , LL node , LL pos , LL val)
{
        if(pos < start || pos > end || start > end) return;
        if(start == end)
        {
                ST[node] = val;
                return;
        }
        LL mid = (start + end)/2;
        if(pos >= start && pos <= mid)
                update(start,mid,2*node,pos,val);
        else
                update(mid+1,end,2*node+1,pos,val);
        ST[node] = max(ST[2*node] , ST[2*node+1]);
}

int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        memset(ST , 0 ,sizeof(ST));
        LL n;
        cin >> n;
        for(int i = 1 ; i <= n ; i++)
        {
                cin >> a[i];
        }
        for(int i = 1 ; i <= n ; i++)
        {
                cin >> b[i];
        }
        for(int i = 1 ; i <= n ; i++)
        {
                LL x = query(1,n,1,1,a[i]);
                dp[i] = x + b[i];
                update(1,n,1,a[i] , dp[i]);
        }
        LL ans = 0;
        for(int i = 1 ; i <= n ; i++)
        {
                //cout << dp[i] << " ";
                ans = max(ans , dp[i]);
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 11264
n = int(input())
 
ans = 0
 
if n >= 10:
  ans += 10 - 1
  if n >= 10**2:
    if n >= 10**3:
      ans += 10**3 - 10**2
      if n >= 10**4:
        if n == 10**5:
          ans += 10**5 - 10**4
        else:
          ans += n - 10**4 + 1
    else:
      ans += n - 10**2 + 1
else:
  ans += n
 
print(ans)

Measured memory_bytes: 3060
package main

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

func main() {
	n := getInt()
	as := getIntSlice(n)

	xs := make([]int, n)

	for i := n - 1; i >= 0; i-- {
		t := i + 1
		sum := as[i]
		for j := t * 2; j-1 < n; j += t {
			sum += xs[j-1]
		}
		xs[i] = sum % 2
	}

	bs := make([]int, 0, 200000)
	for i, x := range xs {
		if x == 1 {
			bs = append(bs, i+1)
		}
	}

	fmt.Println(len(bs))
	for _, b := range bs {
		fmt.Println(b)
	}
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  lint n, t = 0;
  cin >> n;
  v1li v(n);
  map<lint, lint> m, o;
  rep(i, n){
    cin >> v[i];
    m[v[i]]++;
  }
  for(auto p: m){
    t += p.se * (p.se-1) / 2;
    if(p.se < 3) o[p.fi] = p.se * (p.se-1) / 2;
    else o[p.fi] = p.se * (p.se-1) / 2 - (p.se-1) * (p.se-2) / 2;
  }
  rep(i, n){
    cout << t - o[v[i]] << endl;
  }
  return 0;
}

Measured memory_bytes: 18944
#include <cmath>
#include <cstdio>
#include <vector>
#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#define ll long long int
using namespace std;


int main() {
    int n,m;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)a[i][j]=0;
    int k;
    cin>>k;
    int b[k+1];
    b[0]=0;
    for(int i=1;i<=k;i++)cin>>b[i];
    int r=1;
    int sum=0;
    int u=0,w=0,l=0;
    
    while(sum!=(n*m)){
        
        a[u][w]=r;
        if(w==m-1&&l==0){l=1;u++;}
        else
            if(w==0&&l==1){l=0;u++;}
        else
        if(l==0)w++;
        else
        if(l==1)w--;
        sum++;
        --b[r];
        if(b[r]<=0)++r;
       
            
        
    }
    
   for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    
}


Measured memory_bytes: 512
# 参考URL https://note.nkmk.me/python-union-find/
class UnionFind():
    # parents
    # 各要素の親要素の番号を格納するリスト
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # find(x)
    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # union(x, y)
    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

import sys
def input():
    return sys.stdin.readline().strip()

n, k, l = map(int, input().split())

road = UnionFind(n)
rail = UnionFind(n)
for _ in range(k):
    p, q = map(int, input().split())
    road.union(p-1, q-1)
for _ in range(l):
    r, s = map(int, input().split())
    rail.union(r-1, s-1)

dic = {}
l = []
for i in range(n):
    tup = (road.find(i), rail.find(i))
    l.append(tup)
    if tup in dic:
        dic[tup] += 1
    else:
        dic[tup] = 1

ans = []
for i in l:
    ans.append(dic[i])

print(' '.join(map(str, ans)))

Measured memory_bytes: 51868
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	X = int(input())
	if X >= 30:
		print("Yes")
	else:
		print("No")




if __name__ == '__main__':
	main()

Measured memory_bytes: 64784
def check_mod(target_list):
    for target in target_list:
        if int(target) % 2 != 0:
            return False
    else:
        return True


def replace_target(target_list):
    new_list = list()
    for target in target_list:
        new_list.append(int(target) / 2)
    return new_list


def main():
    target_num = input()
    target_list = input().split()

    repeat_count = 0

    while True:
        repeat_flg = check_mod(target_list)
        if repeat_flg:
            target_list = replace_target(target_list)
            repeat_count += 1
        else:
            print(repeat_count)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
s = input()
t = input()

ans = float("inf")

for i in range(len(s) - len(t) + 1):
    num = 0
    for j in range(len(t)):
        if s[i + j] == t[j]:
            continue
        else:
            num += 1

    ans = min(ans, num)

print(ans)



Measured memory_bytes: 67616
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  double a, b, x;
  cin >> a >> b >> x;

  double s = x / a;
  if(s == a*b){
    cout << 0 << endl;
    return 0;
  }
  
  if(s <= a*b/2.0){
    double c = 2.0*s/b;
    cout << setprecision(10) << 90.0 - atan(c/b) * (180.0/PI) << endl;
  }else{
    double c = b - ((2*s)/a - b);
    cout << setprecision(10) << 90.0 - atan(a/c) * (180.0/PI) << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;

int32_t main(){
	int n , r;
	cin >> n >> r;
	if(n>=10) cout <<r << endl;
	else cout << r +  100*(10 -n ) << endl;	
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int z,X,Y,N,M,x[100],y[100];

    scanf("%d %d %d %d ",&N,&M,&X,&Y);

    for(int i=0;i<N;i++){scanf("%d",&x[i]);};

    for(int i=0;i<M;i++){scanf("%d",&y[i]);};

     for(int i=0; i<N; i++){
    for(int j=N-1; j>i; j--){
      if(x[j] < x[j-1]){
        z= x[j];
        x[j] = x[j-1];
        x[j-1] = z;
      }
    }
  }

    for(int i=0; i<M; i++){
    for(int j=M-1; j>i; j--){
      if(y[j] < y[j-1]){
        z = y[j];
        y[j] = y[j-1];
        y[j-1] =z;
      }
    }
  } 
  if(x[N-1]<y[0]&&x[N-1]<Y&&y[0]>X){
      printf("No War");
  }else{
      printf("War");
  }
return 0;
}

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

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

#include <iostream>
using i64 = long long;
template<i64 M> struct modint { i64 a;
  constexpr modint(const i64 x = 0): a((x%M+M)%M){}
  constexpr i64 value() const { return a; }
  constexpr modint inv() const { return this->pow(M-2); }
  constexpr modint pow(i64 r) const {
    modint ans(1); modint aa = *this;
    while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; }
    return ans;
  }
  constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; }
  constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; }
  constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; }
  constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; }
  constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; }
  constexpr modint operator+(const modint r) const { return modint(*this) += r; }
  constexpr modint operator-(const modint r) const { return modint(*this) -= r; }
  constexpr modint operator*(const modint r) const { return modint(*this) *= r; }
  constexpr modint operator/(const modint r) const { return modint(*this) /= r; }
  constexpr bool operator!=(const modint r) const { return this->value() != r.value(); }
};

template<const i64 M> std::ostream& operator<<(std::ostream& os, const modint<M>& m) { os << m.value(); return os; }

using fp = modint<998244353>;

int main() {
  i64 N, S;
  cin >> N >> S;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
  }

  auto dp = ndvec(N + 1, S + 1, fp());
  dp[0][0] = 1;
  rep(i,0,N) {
    rep(s,0,S + 1) {
      if(s - A[i] >= 0) {
        dp[i + 1][s] = dp[i][s] * fp(2) + dp[i][s - A[i]];
      }
      else {
        dp[i + 1][s] = dp[i][s] * fp(2);
      }
    }
  }
  cout << dp[N][S] << endl;
}


Measured memory_bytes: 73672
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
long l;
long A[1000000];
long n;
vector<long> G;

void insertionSort(long A[], long n, long g){
	for (long i = g; i < n; i++){
		long v = A[i];
		long j = i - g;
		while ( j >= 0 && A[j] > v){
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(long A[], long n){
	for (long h = 1; ; ){
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (long i = G.size() - 1; i >= 0; i--){
		insertionSort(A, n, G[i]);
	}
}

int main(){
	cin >> n;
	//for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	for (long i = 0; i < n; i++) cin >> A[i];
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;
	for (long i = G.size() - 1; i >= 0; i--){
		//printf("%d", G[i]);
		cout << G[i];
		//if (i) printf(" ");
		if (i) cout << " ";
	}
	//printf("\n");
	cout << endl;
	//printf("%d\n", cnt);
	cout << cnt << endl;
	//for (int i = 0; i < n; i++) printf("%d\n", A[i]);
	for (long i = 0; i < n; i++) cout << A[i] << endl;

	return 0;
}

Measured memory_bytes: 9032
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
ll gA,sA,bA,gB,sB,bB;
vector<ll> memo(5001,INF);
vector<ll> memo2(25000001,INF);
ll rec(ll x){
    if(memo[x]!=INF) return memo[x];
    
    ll tmp=x;
    if(x>=gA) chmax(tmp,rec(x-gA)+gB);
    if(x>=sA) chmax(tmp,rec(x-sA)+sB);
    if(x>=bA) chmax(tmp,rec(x-bA)+bB);
    
    return memo[x]=tmp;
}
ll rec2(ll x){
    if(memo2[x]!=INF) return memo2[x];
    
    ll tmp=x;
    if(x>=gB) chmax(tmp,rec2(x-gB)+gA);
    if(x>=sB) chmax(tmp,rec2(x-sB)+sA);
    if(x>=bB) chmax(tmp,rec2(x-bB)+bA);
    
    return memo2[x]=tmp;
}
int main(){
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N>>gA>>sA>>bA>>gB>>sB>>bB;
    cout<<rec2(rec(N))<<endl;
}



Measured memory_bytes: 323920
if __name__ == "__main__":
    s = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
    l = s.split(', ')

    print(l[int(input()) - 1])


Measured memory_bytes: 2940
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc164_b solver = new abc164_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc164_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();

            while (true) {
                C -= B;
                if (C <= 0) {
                    out.println("Yes");
                    return;
                }
                A -= D;
                if (A <= 0) {
                    out.println("No");
                    return;
                }

            }


        }

    }
}



Measured memory_bytes: 35872
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


typedef struct {
    int a, b, c, d;
} quadruple_t;


bool comp( quadruple_t a, quadruple_t b ) {
    return a.d > b.d;
}


int main() {

    int a, b;

    cin >> a >> b;

    int at = 1;
    int i = 0;
    while ( at < b ) {
        at += a - 1;
        i++;
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
H=list(map(int,input().split()))
#配るDPでやってみる
#dp[i]をi番目の足場まで行くときの最小コストとする。
dp=[float('inf')]*(2*n)
dp[0]=0
dp[1]=0
for i in range(1,n+1):
    for a in range(1,min(k+1,n-i+1)):
            dp[i+a]=min(dp[i+a], dp[i]+abs(H[i+a-1]-H[i-1]))
print(dp[n])


Measured memory_bytes: 57568
#include <iostream>

int main() {
    using namespace std;
    int n, m, x;
    cin >> n >> m >> x;
    int a[m];
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
    int count = 0;
    for (int i = 0; i < m; i++) {
        if (x < a[i]) {
            break;
        }
        count++;
    }
    cout << (count < m - count ? count : m - count) << endl;
}

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

x=0
y=0
ans=n

# if s[0]=="L":
#     y+=1
# if s[-1]=="R":
#     y+=1
# ans+=y
# s="R"+s+"L"
for i in range(n-1):
    if s[i:i+2]=="RL":
        x+=1
        # x+=1
        # ans-=2
    if s[i:i+2]=="LR":
        y+=1

x=max(x-k,0)
y=max(y-k,0)
ans=ans-x-y-1
# ans+=min(k,x-1)*2
#
# if (k-x+1>0)&(y==0):
#     ans+=1

print(ans)

Measured memory_bytes: 9244
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);

		int a;
		int b;

		ArrayList<String> arr = new ArrayList<String>();

		while((a = sc.nextInt()) != 0 | (b = sc.nextInt()) != 0){
			if(a >= b) arr.add(b + " " + a);
			else arr.add(a + " " + b);
		}

		for(int i = 0; i < arr.size(); i++) {
			System.out.println(arr.get(i));
		}

	}

}



Measured memory_bytes: 36468
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    ll res = 1;
    ll Max = 1e18;
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n)
        if (a[i] == 0) {
            cout << 0;
            return 0;
        }
    FOR(i,1,n) {
        ll x = a[i];
        ll need = Max / res;
        if (x <= need) {
            res *= x;
        }
        else {
            cout << -1;
            return 0;
        }
    }
    cout << res;
    return 0;
}


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

void solve(){
  int a; cin >> a;
  if(a >= 30 ) cout << "Yes" <<endl;
  else cout << "No" << endl;
}

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


Measured memory_bytes: 3632
N= int(input())
S = input()

abc = "ABC"
ans = 0
j = 0

for i in range(N):
    if S[i] == abc[j]:
        j += 1
        if S[i] == "C":
            j = 0
            ans += 1
    elif S[i] == "A":
        j = 1
    else:
        j = 0
print(ans)

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

int main() {
  long N, M;
  cin >> N >> M;
  vector<pair<long, long>> A(N);
  for (long i = 0; i < N; i++) {
    long a, b;
    cin >> a >> b;
    A.at(i) = {a, b};
  }
  vector<pair<long, long>> B(M);
  for (long i = 0; i < M; i++) {
    long c, d;
    cin >> c >> d;
    B.at(i) = {c, d};
  }
  for (long i = 0; i < N; i++) {
    auto[a, b] = A.at(i);
    long mi = LONG_MAX;
    long ans = 0;
    for (long j = 0; j < M; j++) {
      auto[c, d] = B.at(j);
      long tmp = abs(a - c) + abs(b - d);
      if (tmp < mi) mi = tmp, ans = j;
    }
    cout << ans + 1 << "\n";
  }
}

Measured memory_bytes: 3540
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

int frq[123];
int main(){
	Lancer();
	ll t, a, b, res = 0;
	cin >> t;
	while (t--)
	{
		cin >> a >> b;
		res += ((b - a) + 1);
	}
	cout << res;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3708
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		long ans = 1;
		int y = 0;
		int[] s = new int[N+1];

		for (int i = 2; i <= N; i++) {
			// 素因数分解
			y = i;
			for (int j = 2; j <= i; j++) {
				while (y % j == 0) {
					y = y / j;
					s[j] = s[j] + 1;
				}
			}
		}

		for (int i = 0; i <= N; i++) {
			if (s[i] != 0) {
				ans = ans * (s[i] + 1);
				ans = ans % 1000000007;
			}
		}
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    string S;
    cin >> S;
    if(S == "ABC"){
        cout << "ARC";
    }
    else{
        cout << "ABC";
    }
}

Measured memory_bytes: 3648