akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> coin(h, vector<int>(w)), ans(0);
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> coin.at(i).at(j);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w - 1; j++) {
      if (coin.at(i).at(j) % 2 == 1) {
        int memo;
        for (int k = j + 1; k < w; k++) {
          if (coin.at(i).at(k) % 2 == 1) {
            memo = k;
            break;
          }
          if (k == w - 1) memo = k;
        }
        coin.at(i).at(j)--;
        coin.at(i).at(memo)++;
        for (int k = 0; k < memo - j; k++) {
          vector<int> x = {i + 1, j + 1 + k, i + 1, j + 2 + k};
          ans.push_back(x);
        }
        j = memo;
      }
    }
  }
  for (int i = 0; i < h - 1; i++) {
    if (coin.at(i).at(w - 1) % 2 == 1) {
      int memo;
      for (int j = i + 1; j < h; j++) {
        if (coin.at(j).at(w - 1) % 2 == 1) {
          memo = j;
          break;
        }
        if (j == h - 1) memo = j;
      }
      coin.at(i).at(w - 1)--;
      coin.at(memo).at(w - 1)++;
      for (int j = 0; j < memo - i; j++) {
        vector<int> x = {i + 1 + j, w, i + 2 + j, w};
        ans.push_back(x);
      }
      i = memo;
    }
  }
  int n = ans.size();
  cout << n << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) cout << ans.at(i).at(j) << " ";
    cout << ans.at(i).at(3) << endl;
  }
}

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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanVecLLInt(A, N);
    ll result = 0;
    unordered_map<int, int> L;
    REP(i, N){
        auto& Ai = A[i];
        if (L.count(i - Ai)) result += L[i - Ai];
        L[i + Ai]++;
    }
    cout << result << endl;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<ll> cnt(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
        ++cnt[a[i]];
    }

    ll total = 0;
    for (int i = 0; i < n; ++i) {
        total += (cnt[i] - 1) * cnt[i] / 2;
    }

    for (int i = 0; i < n; ++i) {
        cout << total - (cnt[a[i]] - 1) << "\n";
    }
    return 0;
}

Measured memory_bytes: 4992
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
	int n;
	cin >> n;
    cin >> s >> t;
	string res = "";
    for(int i = 0; i < n; ++i)
    {
		res+=s[i];
		res+=t[i];
    }
	cout << res;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pr;
bool solve(){
    int M,N;
    scanf("%d",&M);
    if(!M)return false;
    vector<pr>cns(M);
    for(int i=0;i<M;i++){
        scanf("%d%d",&cns[i].first,&cns[i].second);
    }
    set<pr>S;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        S.insert(pr(x,y));
    }

    set<pr>::iterator it;
    for(it=S.begin();it!=S.end();it++){
        int dx=cns[0].first-it->first;
        int dy=cns[0].second-it->second;

        bool flag=true;
        for(int i=0;i<M;i++){
            int x=cns[i].first-dx;
            int y=cns[i].second-dy;
            if(S.find(pr(x,y))==S.end())flag=false;
        }

        if(flag){
            printf("%d %d\n",-dx,-dy);
            break;
        }
    }
    return true;
}
int main(){
    while(solve());
}

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;
  vector<ll> X;
  ll t;
  if(N>=M){
    cout << 0 << endl;
    return 0;
  }
  for(int i=0;i<M;i++){
    cin >> t;
    X.push_back(t);
  }
  sort(X.begin(),X.end());
  ll ans=0;
  vector<ll> Y;
  ll a,b;
  for(int i=0;i<M-1;i++){
    a=X[i];
    b=X[i+1];
    Y.push_back(abs(a-b));
  }
  sort(Y.begin(),Y.end());
  for(int i=0;i<M-N;i++){
    ans+=Y[i];
  }

  cout << ans << endl;
  return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
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 (b < a) { a = b; return 1; } return 0; }

//---------------------------------------------------------------------------------------------------
void _main() {
    string S; cin >> S;
    if (S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3612
def strength(n, people):
	total = 0
	for i in range(n):
		for j in range(2):
			if j == 1:
				total += people[i*2+1]
	return total

# print(strength(2, sorted([5,2,8,5,1,5], reverse=True)))
n = int(input())
people = sorted(list(map(lambda x: int(x), input().split())), reverse=True)
print(strength(n, people))

Measured memory_bytes: 37084
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan=new Scanner(System.in);
    		
    		String n=scan.next();
    		if(n.contains("9")) {
    			System.out.print("Yes");
    		}else {
    			System.out.print("No");
    		}
    		

    		
    	
  
    				
 
     
    }
    }

Measured memory_bytes: 21076
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int f[N],g[N],he[N],ne[N*2],t[N*2],a[N],p[N],tot=0;
long long sum[N];
struct aa
{
	int u,v,c;
}e[N];
bool cmp(aa x,aa y)
{
	return x.c<y.c;
}
int get(int x)
{
	if (f[x]==x) return x;
	return f[x]=get(f[x]);
}
void add(int x,int y)
{
	tot++;
	ne[tot]=he[x];
	he[x]=tot;
	t[tot]=y;
}
void flow(int x)
{
	for (int i=he[x];i;i=ne[i]) 
	{
		if (!p[t[i]]) p[t[i]]=p[x];
		flow(t[i]);
	}
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]),f[i]=i,sum[i]=a[i];
	for (int i=1;i<=m;i++) scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].c);
	sort(e+1,e+m+1,cmp);
	for (int i=1;i<=m;i++) 
	{
		int xx=get(e[i].u),yy=get(e[i].v);
		if (xx!=yy)
		{
			if (sum[xx]+sum[yy]>=e[i].c) p[i]=1;
			f[xx]=yy;
			sum[yy]=sum[yy]+sum[xx];
			if (g[xx]) add(i,g[xx]);
			if (g[yy]) add(i,g[yy]);
			g[yy]=i;
		}
	}
	int rt=get(1);
	flow(g[rt]);
	for (int i=1;i<=n;i++) f[i]=i,sum[i]=a[i];
	for (int i=1;i<=m;i++) if (p[i]) sum[get(e[i].v)]+=sum[get(e[i].u)],f[get(e[i].u)]=get(e[i].v);
	int ans=m;
	for (int i=1;i<=m;i++) if (get(e[i].u)==get(e[i].v)&&sum[get(e[i].u)]>=e[i].c) ans--;
	printf("%d\n",ans);
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int w[n],s1=0,s2=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>w[i];
		s2+=w[i];
	}
	int ans=100000;
	for (int i = 0; i < n-1; ++i)
	{
		s1+=w[i];
		s2-=w[i];
		ans=min(ans,abs(s1-s2));
	}
	cout<<ans<<endl;
	return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

bool check(vector<int> &vec) {
  if( vec[0] >= 32 ) return true;
  if( vec[0] == 31 && vec[1] >= 5 ) return true;
  return false;
}

int main() {
  string g;
  while(cin >> g, g != "#" ) {
    vector<int> vec(3);
    rep(i,3) cin >> vec[i];
    cout << ( check(vec) ? "?" : g ) << " "; 
    cout << ( check(vec) ? vec[0]-30 : vec[0] );
    rep(i,2) {
      cout << " ";
      cout << vec[i+1];
    } puts("");
  }
  return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e6 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   string s;
   cin >> s;
   int q;
   cin >> q;
   deque<char> start,end;
   int c = 0;
   while(q--){
      int t;
      cin >> t;
      if(t == 1){
         c = c^1;
      }else{
         char ch;
         int f;
         cin >> f >> ch;
         if(c){
            if(f == 1){
               end.pb(ch);
            }else{
               start.push_front(ch);
            }
         }else{
            if(f == 1){
               start.push_front(ch);
            }else{
               end.pb(ch);
            }
         }
      }
   }
   if(c){
      reverse(all(s));
      reverse(all(start));
      reverse(all(end));
      swap(start,end);
   }
   for(auto &e : start) cout << e;
   cout << s;
   for(auto &e : end) cout << e;
   return 0;
}

Measured memory_bytes: 848
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;
int main()
{
    lli n, x;
    cin >> n >> x;
    lli ans = 0;
    lli a[100005];
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, n - 1)
    {
        if (a[i] + a[i + 1] > x) {
            lli tmp = a[i + 1];
            a[i + 1] = max(0LL, x - a[i]);
            ans += tmp - a[i + 1];
            if (a[i] + a[i + 1] > x) {
                ans += a[i] - x + a[i + 1];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
S = str(input())
n = len(S)
ans = 0

for i in range(1 << n-1):
    ins = S[0]
    for j in range(n-1):
        if i & (1 << j):
            ins += "+" + S[j+1]
        else:
            ins += "-" + S[j+1]

    if eval(ins) == 7:
        print(ins + "=7")
        break


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A == B && B == C){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    vector<string> w = {"Sunny", "Cloudy", "Rainy"};
    string t;
    cin >> t;
    cout << w[(find(all(w),t)-w.begin()+1)%3] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
	int n,k;
	cin>>n>>k;
	vector<int> cnt(n+1,0);
	while(k--){
		int d;
		cin>>d;
		rep(i,0,d)
		{
			int t;
			cin>>t;
			cnt[t] = 1; 
		} 
	} 
	int ans=0;
	for(int i=1;i<=n;i++){
		if(!cnt[i])ans++;
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
std::vector<int> G[200100];
int di[200100];

void dfs(int v, int p, int d){
    di[v] = d;

    for(int w : G[v]){
        if(w == p){
            continue;
        }

        dfs(w, v, d + 1);
    }
}

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

    std::cin >> N;

    for(int i=0;i<N-1;++i){
        int a, b;
        std::cin >> a >> b;

        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    dfs(1, -1, 0);
    
    int v = std::max_element(di + 1, di + 1 + N) - di;

    dfs(v, -1, 0);

    int d = *std::max_element(di + 1, di + 1 + N);
    
    if(d % 3 == 1){
        std::cout << "Second" << std::endl;
    }else{
        std::cout << "First" << std::endl;
    }
}


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

N_100 = N // 100

ANS = 1

if N_100 == 0:
  ANS = 0

for i in range(20):
  if (N > (i + 1) * 100 + (i + 1)*5) and (N < ((i + 2) * 100)):
    ANS = 0
    break

if ANS == 0:
  print(0)
else:
  print(1)

Measured memory_bytes: 3064
#! /usr/bin/env ruby

S = gets.chop

is_yymm = !!S.match(/\d\d(0[1-9]|1[0-2])/)
is_mmyy = !!S.match(/(0[1-9]|1[0-2])\d\d/)

if is_yymm && is_mmyy
  puts 'AMBIGUOUS'
elsif is_yymm && !is_mmyy
  puts 'YYMM'
elsif !is_yymm && is_mmyy
  puts 'MMYY'
else
  puts 'NA'
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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 (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int h, w;
char g[51][51]; 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i, 0, h) rep(j, 0, w) cin >> g[i][j];
    rep(i, 0, h) rep(j, 0, w) {
        if (g[i][j] == '#') {
            bool flag = true;
            rep(k, 0, 4) {
                int nx = i + dx[k], ny = j + dy[k];
                if (0 <= nx && nx < h && 0 <= ny && ny < w && g[nx][ny] == '#') {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                cout << "No" << endl;
                return 0;
            }
        }
    } 
    cout << "Yes" << endl;
    return 0;
}


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

bool ok[100];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int d;
    cin >> d;
    for (int j = 0; j < d; ++j) {
      int a;
      cin >> a;
      ok[a - 1] = true;
    }
  }
  
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (!ok[i]) ++cnt;
  }
  cout << cnt << endl;
}

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

using namespace std;

int main()
{
    int N;
    while (cin >> N, N) {
        vector<int> cnt(26, 0);
        vector<char> ch(N);
        for (int i = 0; i < N; i++) {
            cin >> ch[i];
        }
        
        int mn = -1, mx = 0;
        bool found = 0;        
        for (int i = 0; i < N; i++) {
            int n = ch[i] - 'A';
            cnt[n]++;
            if (mx < cnt[n]) {
                mx = cnt[n];
                mn = n;
            }
                
            int mx2 = 0;
            for (int j = 0; j < 26; j++) {
                if (j == mn) continue;
                mx2 = max(mx2, cnt[j]);
            }
            if (mx2 + (N - i - 1) < mx) {
                found = 1;
                cout << (char)(mn + 'A') << " " << i + 1 << endl;
                break;
            }
        }
        if (!found) {
            cout << "TIE" << endl;
        }
    }
    return 0;
}

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

int main(){


  while(1){
    int a,b;
    char s;
    //    cin >> a >> s >> b;
    scanf("%d %c %d",&a,&s,&b);
    if(s == '?')break;
    
    switch(s){
    case '+':
      cout << a+b << endl;
      break;
    case '-':
      cout << a-b << endl; 
      break;
    case '*':
      cout << a*b << endl;
      break;
    case '/':
      cout << a/b << endl;
      break;
    }

  }
}

Measured memory_bytes: 1212
s = input()
a = s[:2]
b = s[2:]
month=range(1,13)
m = []
for i in month:
    m_s = str(i)
    if i<9:
        m_s = "0" + m_s
    m.append(m_s)

isM_a = a in m 
isM_b = b in m 

if isM_a:
    if isM_b:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if isM_b:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String ans;
    if (S.equals("Sunny")) {
      ans = "Cloudy";
    } else if (S.equals("Cloudy")) {
      ans = "Rainy";
    } else {
      ans = "Sunny";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 20180
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
#define pr pair<int,int>
#define mp make_pair
#define fr first
#define se second
int n,i;
queue<pr > q;
bool f[50][100050];
int main()
{
	scanf("%d",&n);
	while (n%2==0) n/=2;
	while (n%5==0) n/=5;
	for (i=1;i<=9;i++) q.push(mp(i,i%n)),f[i][i%n]=true;
	while (!q.empty()){
		pr psz=q.front();q.pop();
		for (i=0;i<=9;i++) if (psz.fr+i<=45&&!f[psz.fr+i][((psz.se<<3)+(psz.se<<1)+i)%n]) f[psz.fr+i][((psz.se<<3)+(psz.se<<1)+i)%n]=true,q.push(mp(psz.fr+i,((psz.se<<3)+(psz.se<<1)+i)%n));
	}
	for (i=1;i<=45;i++) if (f[i][0]) return printf("%d\n",i),0;
	return 0;
}

Measured memory_bytes: 17208
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  int a1 = 0, a2 = 0;
  for (int i = 0; i < n; i++)
  {
    if (s.at(i) == '0' && i % 2 == 0)
    {
      a1++;
    }
    if (s.at(i) == '1' && i % 2 == 1)
    {
      a1++;
    }
  }

  for (int i = 0; i < n; i++)
  {
    if (s.at(i) == '0' && i % 2 == 1)
    {
      a2++;
    }
    if (s.at(i) == '1' && i % 2 == 0)
    {
      a2++;
    }
  }
  int ans = min(a1, a2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
static int table[2][2001][2001] = {{{0}}};

inline int clamp(int x, int lo, int hi){
	return min(max(x, lo), hi);
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	const int m = 2 * k;
	for(int i = 0; i < n; ++i){
		int x, y;
		string color;
		cin >> x >> y >> color;
		const int c = (color[0] == 'W' ? 0 : 1);
		x %= m;
		y %= m;
		table[c][y][x]++;
	}
	for(int c = 0; c < 2; ++c){
		for(int y = 0; y <= m; ++y){
			int acc = 0;
			for(int x = 0; x <= m; ++x){
				const int t = table[c][y][x];
				table[c][y][x] = acc;
				acc += t;
			}
		}
		for(int x = 0; x <= m; ++x){
			int acc = 0;
			for(int y = 0; y <= m; ++y){
				const int t = table[c][y][x];
				table[c][y][x] = acc;
				acc += t;
			}
		}
	}
	int answer = 0;
	for(int y = 0; y <= m; ++y){
		for(int x = 0; x <= m; ++x){
			int sum = 0;
			for(int i = -2; i <= 2; ++i){
				for(int j = -2; j <= 2; ++j){
					const int c = (i + j) & 1;
					const int y0 = y + k * i, x0 = x + k * j;
					sum += table[c][clamp(y0 + k, 0, m)][clamp(x0 + k, 0, m)];
					sum -= table[c][clamp(y0 + k, 0, m)][clamp(x0    , 0, m)];
					sum -= table[c][clamp(y0    , 0, m)][clamp(x0 + k, 0, m)];
					sum += table[c][clamp(y0    , 0, m)][clamp(x0    , 0, m)];
				}
			}
			answer = max(answer, sum);
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 31488
"""
灘入試コンのあれに似てる？？

bはあんまり関係ない

n回更新したとする
最小xの答えは左からn//2番目のa

f(x) = すべてのb + 他のaとの差の合計

一つ追加しても左右に1つ移動するだけ
→左右にあるaの数でb以外部分の変化を計算できる

→数列中に挿入が高速にできる必要がある？

二つのヒープを使って調整する？
いけそう

"""

import heapq

numQ = int(input())
bsum = 0

Lheap = [] #最大値を出す→負
Rheap = [] #最小値、正

for loop in range(numQ):

    query = input()

    if query == "2":

        print (nx , fx + bsum)

    else:

        query , newa , newb = query.split()
        newa = int(newa)
        newb = int(newb)

        bsum += newb

        if loop == 0:

            nx = newa
            fx = 0
            heapq.heappush(Lheap , -1 * newa)

        else:

            #ヒープの移動を行う→数字をいじるでokそう

            fx += abs(nx - newa)


            if -1 * Lheap[0] > newa:

                heapq.heappush(Lheap , -1 * newa)

            else:

                heapq.heappush(Rheap , newa)

            


            while len(Lheap) > len(Rheap) + 1:

                temp = heapq.heappop(Lheap)
                heapq.heappush(Rheap , -1 * temp)

            while len(Rheap) > len(Lheap):

                temp = heapq.heappop(Rheap)
                heapq.heappush(Lheap, -1 * temp)

            ox = nx

            nx = -1 * Lheap[0]

            
            #print (Lheap,Rheap)

            if nx < ox:
            
                fx += (ox-nx) * ( len(Rheap) - len(Lheap))

            elif nx > ox:

                fx += (nx-ox) * ( len(Lheap) - 1 - (len(Rheap) + 1))

      

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

map<string, int> mp;
vector<pair<string, int> > v;

bool cmp(pair<string, int> x, pair<string, int> y)
{
	if (x.second == y.second)	return x.first < y.first;
	return x.second > y.second;
}

int main()
{
	map<string, int>::iterator it;
	int n; cin >> n;
	while (n--)
	{
		string s;
		cin >> s;
		mp[s]++;
	}
	for (it = mp.begin(); it != mp.end(); it++)
	{
		v.push_back(make_pair(it->first, it->second));
	}
	sort(v.begin(), v.end(), cmp);
	cout << v[0].first << '\n';
	for (int i = 1; i < v.size(); i++)
	{
		if (v[i].second == v[0].second)
		{
			cout << v[i].first << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 29680
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	int A, B; cin >> A >> B;
	if ((A + B) % 2 == 0)cout << (A + B) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;
}





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

using namespace std;

int N, M, sum = 0;

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	cin >> N >> M;
	int t = N;
	vector<int> list(N);
	while (N--)
	{
		cin >> list[N];
		sum += list[N];}
	sort(list.rbegin(), list.rend());
	for (int i = 0; i < M; ++i)
	{
		if (list[i] < (sum / 4.0) / M)
		{
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <functional>

using namespace std;

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

    vector<long> H(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> H[i];
    }

    int prev=0;
    for (int i = 0; i < N; i++)
    {
        if(H[i]==prev-1){
            prev = H[i]+1;
            continue;
        }
        if(H[i]>=prev){
            prev = H[i];
            continue;
        }
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1024
n,m = map(int,input().split())

list_l = []
list_r = []
seen = [0]*n
sta = []
count = 0
sta.append(1)

for i in range(m):
  temp = list(map(int,input().split()))
  list_l.append(temp[0])
  list_r.append(temp[1])
  
def dfs(count):
  a = sta.pop()
  seen[a-1] = 1
  
  if not (0 in seen):
    count = count + 1

  for i,x in enumerate(list_l):
    if x == a:
      next_num = list_r[i]
      if seen[next_num-1] == 0:
        sta.append(next_num)
        count = dfs(count)
        seen[next_num-1] = 0
    
  for i,x in enumerate(list_r):
    if x == a:
      next_num = list_l[i]
      if seen[next_num-1] == 0:
        sta.append(next_num)
        count = dfs(count)
        seen[next_num-1] = 0
      
  return count

ans = dfs(0)
print(ans)

Measured memory_bytes: 3064
N = int(input())
s = list(input())

l = [[0]*2 for _ in range(N+1)]
r = [[0]*2 for _ in range(N+1)]

for i,j in enumerate(s, start=1):
    l[i][0] = l[i-1][0]
    l[i][1] = l[i-1][1]
    if j=="#":
        l[i][0] += 1
    else:
        l[i][1] += 1

for i,j in enumerate(s[::-1], start=1):
    r[N-i][0] = r[N-i+1][0]
    r[N-i][1] = r[N-i+1][1]
    if j=="#":
        r[N-i][0] += 1
    else:
        r[N-i][1] += 1

ans = N
for i in range(N+1):
    ans = min(ans, l[i][0]+r[i][1])

print(ans)

Measured memory_bytes: 91336
def solve():
    from sys import stdin
    f_i = stdin
    
    N, K = map(int, f_i.readline().split())
    
    # combination
    mod = 10 ** 9 + 7
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    
    for i in range(2, N):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
    
    def comb(n, r):
        return fact[n] * factinv[r] * factinv[n - r] % mod
    
    A = sorted(map(int, f_i.readline().split()))
    
    ans = A[K-1] - A[N-K]
    for i, j in zip(range(K, N), range(1, N)):
        ans += (A[i] - A[N-i-1]) * comb(i, K - 1)
        ans %= mod
    
    print(ans)

solve()

Measured memory_bytes: 25996
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<class T, class ...Tail>
void tiedSort(vector<T> &a, vector<Tail>&... tail) {
	int n = a.size();
	using S = tuple<T, Tail...>;
	vector<S> s(n);
	for (int i = 0; i < n; i++)
		s[i] = make_tuple(a[i], tail[i]...);
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++)
		tie(a[i], tail[i]...) = s[i];
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, C; cin >> N >> M >> C;
	vector<int> l(C); rep(i, 0, C) {
		cin >> l[i];
	}
	vector<int> c(N), w(N); rep(i, 0, N) {
		cin >> c[i] >> w[i];
		c[i]--;
		w[i] = -w[i];
	}

	tiedSort(w, c);
	dump(w, c);
	int ans = 0;

	int m = 0;
	rep(i, 0, N) {
		if (l[c[i]]) {
			l[c[i]]--;
			m++;
			ans -= w[i];
		}
		dump(l);
		dump(ans);
		if (m == M)break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6440
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18
 
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}
 
vector<int> a;
int n;
map<pair<int,int>,int> done;
 
 
int f(int l,int r,int left)
{
	if(left==0)
		return 0;
	if(r-l+1<left*2-1 || r<l)
		return -INF;
	if(done.find({l,left})!=done.end())
		return done[{l,left}];
	return done[{l,left}]=max(a[l]+f(l+2,r,left-1), f(l+1,r,left));
}
 
 
signed main()
{
	fio
	cin>>n;
	a.resize(n);
	fo(i,n)	
		cin>>a[i];
	cout<<f(0,n-1,n/2)<<'\n';
	printclock;
}

Measured memory_bytes: 34688
import java.util.*;

public class Main {
	static int cnt=0;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] a=new int[N];
		for(int i=0;i<N;i++){
			a[i]=sc.nextInt();
		}
		shellSort(a,N);
		System.out.println(cnt);
		for(int i=0;i<N;i++){
				System.out.println(a[i]);
		}	
	}
	
	static void insertionSort(int[] A,int n,int g){
		for(int i=g;i<n;i++){
			int v=A[i];
			int j=i-g;
			while(j>=0&&A[j]>v){
				A[j+g]=A[j];
				j=j-g;
				cnt++;
			}
			A[j+g]=v;
		}
	}
	
	static void shellSort(int[] A,int n){
		cnt=0;
		int h=1;
		int m=0;
		while(true){
			if(h>A.length){
				break;
			}
			h=3*h+1;
			m++;
		}
		System.out.println(m);
		int[] G=new int[m];
		G[m-1]=1;
		for(int i=m-2;i>=0;i--){
			G[i]=3*G[i+1]+1;
		}
		for(int i=0;i<m;i++){
			if(i==m-1){
				System.out.println(G[i]);
			}else{
				System.out.print(G[i]+" ");
			}
		}
		for(int i=0;i<m;i++){
			insertionSort(A,n,G[i]);
		}	
	}
}

Measured memory_bytes: 299316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[20];
map<int,ll> dp;
ll solve(int l, int r, int vl, int vr)
{
	if (l>r) return 0;
	ll hs = 0;
	hs = hs*23+l;
	hs = hs*23+r;
	hs = hs*23333333+vl;
	hs = hs*23333333+vr;
	if (dp.find(hs)!=dp.end()) return dp[hs];
	ll &cur = dp[hs];
	cur = 8e18;
	for (int i=l; i<=r; i++)
	{
		ll val = solve(l, i-1, vl, vl+vr)+solve(i+1, r, vl+vr, vr)+1ll*a[i]*(vl+vr);
		cur = min(cur, val);
	}
	return cur;
}
int main()
{
	cin>>n;
	for (int i=1; i<=n; i++) cin>>a[i];
	cout<<solve(2, n-1, 1, 1)+a[1]+a[n]<<endl;
	return 0;
}

Measured memory_bytes: 16640
def main():
    n, a, b = map(int, input().split())

    if n == 1:
        if a != b:
            print(0)
        else:
            print(1)
        return

    if a > b:
        print(0)
        return

    print((b - a) * (n - 2) + 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(a))
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	string s;
	int n,k;
	cin>>n>>k>>s;
	if(s[k-1]=='A')s[k-1]='a';
	else if(s[k-1]=='B')s[k-1]='b';
	else if(s[k-1]=='C')s[k-1]='c';
	cout<<s<<endl;
	return 0;
}


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

int main() {
  int n, alice=0, bob=0;
  cin >> n;
  vector<int> a(n);
  rep(i, n)
  {
    cin >> a.at(i);
  }
  sort(a.rbegin(), a.rend());

  rep(i, n)
  {
    if(i%2 == 0)
      alice += a.at(i);
    else
      bob += a.at(i);
  }

  cout << alice-bob << endl;
}


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

typedef struct  {
  char suit;
  int value;
  int order;
} CARD;

void printcards(CARD *, int);
void printisstable(CARD *, int);
void swap(CARD *, int, int);

int main()
{
  int i, j, numdata, valuedata[36], inttmp, minj;
  int stable1[37], stable2[37]; //0は添字に用いない
  char indata[3], chartmp;
  CARD c1[36],c2[36];
  
  scanf("%d",&numdata);

  for(i = 0; i <= numdata; i++) {
    stable1[i] = stable2[i] = 0;
  }

  for(i = 0; i < numdata; i++) {
    scanf("%s",indata);
    c1[i].suit = c2[i].suit = indata[0];
    c1[i].value = c2[i].value = indata[1] - '0';
    c1[i].order = c2[i].order = stable1[c1[i].value] = stable2[c2[i].value] += 1;
  }

  //Bubble Sort
  for(i = 0; i < numdata; i++) {
    for(j = numdata - 1; j >= i + 1; j--) {
      if(c1[j].value < c1[j-1].value) {
	swap(c1,j,j-1);
      }
    }
  }

  printcards(c1,numdata);
  printisstable(c1,numdata);
  

  //SelectionSprt
  for(i = 0; i < numdata; i++) {
    minj = i;
    for(j = i; j < numdata; j++) {
      if(c2[j].value < c2[minj].value) minj = j;
    }
    swap(c2,i,minj);
  }

  printcards(c2,numdata);
  printisstable(c2,numdata);
  return 0;
}

void printcards(CARD *c, int numdata)
{
  int i;

  for(i = 0; i < numdata; i++) {
    if(i) printf(" ");
    printf("%c%d",c[i].suit,c[i].value);
  }
  printf("\n");
}

void printisstable(CARD *c, int numdata)
{
  int i;
  int judge[37];
  
  for(i = 0; i <= 36; i++) {
    judge[i] = 1;
  }

  for(i = 0; i < numdata; i++) {
    if(c[i].order > judge[c[i].value]) {
      printf("Not stable\n");
      return;
    }
    judge[c[i].value]++;
  }

  printf("Stable\n");
}

void swap(CARD *c, int x, int y)
{
  int inttmp;
  char chartmp;
  
  inttmp = c[x].value;
  c[x].value = c[y].value;
  c[y].value = inttmp;
	
  chartmp = c[x].suit;
  c[x].suit = c[y].suit;
  c[y].suit = chartmp;

  inttmp = c[x].order;
  c[x].order = c[y].order;
  c[y].order = inttmp;
}




Measured memory_bytes: 2148
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#if __cplusplus >= 201103
#include <numeric>
#endif
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

//#if __cplusplus >= 201103
typedef long long ll;
//#endif
typedef pair<int, int> P;
typedef pair<int, P> IP;

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

const int INF = 100000000;
//#if __cplusplus >= 201103
const ll LINF = 10000000000000000ll;
//#endif
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
// }}}

int h, w;
char grid[50][50];

void init()
{
}

void solve()
{
    bool ans = true;
    REP(i, h){
        REP(j, w){
            if(grid[i][j] == '.') continue;
            REP(k, 4){
                if(i+dx[k] < 0 || h <= i+dx[k] || j+dy[k] < 0 || w <= j+dy[k]) continue;
                if(grid[i+dx[k]][j+dy[k]] == '#') goto next;
            }
            ans = false;
next:
            if(!ans) goto end;
        }
    }
end:
    cout << (ans ? "Yes" : "No") << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    REP(i, h){
        REP(j, w){
            cin >> grid[i][j];
        }
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, char> > rules(m);
    for (size_t i = 0; i < m; i++) {
        int s;
        char c;
        cin >> s >> c;
        rules[i] = make_pair(s, c);
    }

    int ans = -1;
    for (size_t i = 0; i < 1000; i++) {
        string num = to_string(i);
        if (num.size() == n) {
            bool ok = true;
            for (size_t j = 0; j < m; j++) {
                if (num[rules[j].first-1] != rules[j].second) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                ans = i;
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3700
#include "bits/stdc++.h"
using namespace std;


#define MAX 2002

int n;
int k;

#define MM 10002

char buf[MM];

vector<string> v;


bitset<1000000> b;

int star[MAX];

bitset<1000000> lab[26];

bool dp[2002][10002];
bool use[2002][10002];

inline bool dfs(int a, int b) {
	if (a == n) {
		return b == k;
	}
	if (b > k) {
		return false;
	}
	if (use[a][b]) {
		return dp[a][b];
	}
	use[a][b] = true;
	dp[a][b] = dfs(a + 1, b) | dfs(a + 1, b + v[a].size());
	return dp[a][b];
}
string ans;
int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%s", buf);
		v.push_back(buf);
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		star[i] = sum;
		sum+=v[i].size();
		for (int j = 0; j < v[i].size(); j++) {
			for (int k = v[i][j] - 'a'; k < 26; k++) {
				lab[k].set(star[i]+(v[i].size()-j-1), 1);
			}
		}
		if (dfs(i+1,v[i].size() ) ) b.set(star[i] + v[i].size() - 1, 1);
	}
	star[n] = sum;
	for (int i2 = 0; i2 < k; i2++) {
		int mint = -1;
		int maxt = 25;
		while (mint + 1 < maxt) {
			int mid = (mint + maxt) >> 1;
			if ((lab[mid] & b).any()) {
				maxt = mid;
			}
			else {
				mint = mid;
			}
		}
		mint++;
		b &= lab[mint];
		ans.push_back('a' + mint);
		if (i2 + 1 == k)break;
		//next move
		int add = n;
		for (int i = 0; i < n; i++) {
			if (b.test(star[i])) {
				add = min(add,i + 1);
				b.reset(star[i]);
			}
		}
		b >>= 1;
		for (int j = add; j < n; j++) {
			if (dfs(j + 1,i2 + 1 + v[j].size())) {
				b.set(star[j + 1] - 1, 1);
			}
		}
	}
	printf("%s\n", ans.c_str());
	return 0;
}

Measured memory_bytes: 43904
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
	ll x;cin>>x;
	ll temp,temp2,ans_num=1;
	int sqrt_x = ceil(sqrt(x) + 0.1);
  FOR(p,2,sqrt_x){
  	temp=x;
  	temp2=0;
  	while(temp/p>0){
  		temp2++;
  		temp/=p;
  	}
  	if(ans_num<pow(p,temp2)){
  		ans_num=pow(p,temp2);
  	}
  }
  cout<<ans_num<<endl;
  return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
//		HashSet<Integer> set = new HashSet<>();
		int n = sc.nextInt(); int m = sc.nextInt();
		int[] p = new int[n+1];
		int[] par = new int[n+1];
		init(par, n+1);
		for(int i=1; i<=n; i++) {
			p[i] = sc.nextInt();
		}
		for(int i=0; i<m; i++) {
//			set.add(sc.nextInt());
//			set.add(sc.nextInt());
			unite(sc.nextInt(), sc.nextInt(), par);
		}
//		HashSet<Integer> pos = new HashSet<>();
//		for(int e : set) {
//			pos.add(p[e]);
//		}
		int cnt = 0;
		for(int i=1; i<=n; i++) {
			if(same(p[i], i, par)) cnt++;
		}
		System.out.println(cnt);
	}
	
	static void init(int[] par, int n) {
		for(int i=0; i<n; i++) par[i] = i;
	}
	
	static int root(int x, int[] par) {
		if(par[x] == x) return x;
		return par[x] = root(par[x], par);
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}

	static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public MyScanner(InputStream s) 
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 46492
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int r;
	cin >> r;
	if (r < 1200)cout << "ABC" << endl;
	else if (r < 2800)cout << "ARC" << endl;
	else cout << "AGC" << endl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1001001001;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

template <int mod>
struct ModInt {
  int x;
  ModInt(): x(0) {}
  ModInt(long long a) { x = a % mod; if (x < 0) x += mod; }
  ModInt &operator+=(ModInt that) { x = (x + that.x) % mod; return *this; }
  ModInt &operator-=(ModInt that) { x = (x + mod - that.x) % mod; return *this; }
  ModInt &operator*=(ModInt that) { x = (long long) x * that.x % mod; return *this; }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return ModInt(u);
  }
  #define op(o, p) ModInt operator o(ModInt that) { return ModInt(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  friend ostream& operator<<(ostream &os, ModInt m) { return os << m.x; }
};

using mint = ModInt<998244353>;

void solve() {
  int n, s;
  cin >> n >> s;
  vi32 a(n);
  cin >> a;
  using vm = vector<mint>;
  vector<vm> dp(n + 1, vm(s + 1));
  dp[0][0] = exp((mint) 2, n);
  rep(i, n) repc(j, s) {
    dp[i + 1][j] += dp[i][j];
    if (j + a[i] <= s) dp[i + 1][j + a[i]] += dp[i][j] / 2;
  }
  cout << dp[n][s] << endl;
}


Measured memory_bytes: 38504
-module('Main').
-export([main/1]).

solve() ->
    [N] = input("~d"),
    A = input(lists:flatten(lists:duplicate(N, "~d"))),
    Rest = case N rem 2 of
        0 -> 1;
        1 -> 2
    end,
    ABList = [{A, B} || A <- lists:seq(0, Rest), B <- lists:seq(0, A)],
    Inf = 1000 * 1000 * 1000 * 1000 * 1000,
    Arr0 = maps:from_list([{{I, J}, -Inf} || I <- lists:seq(-1, N), J <- lists:seq(0, Rest)]),
    Arr1 = lists:foldl(fun ({I, Ai}, Acc) ->
        lists:foldl(fun ({J, K}, Acc) ->
            case I - K - 2 >= -1 of
                true ->
                    Value = maps:get({I - K - 2, J - K}, Acc),
                    case Value < -Inf div 2 of
                        true -> Acc;
                        false ->
                            Old = maps:get({I, J}, Acc),
                            Acc#{{I, J} => max(Value + Ai, Old)}
                    end;
                false -> Acc
            end
        end,
        Acc,
        ABList)
    end, Arr0#{{-1, 0} => 0}, lists:zip(lists:seq(1, N), A)),
    Ans = lists:max([maps:get({N - I, Rest - I}, Arr1) || I <- lists:seq(0, Rest)]),
    io:format("~B~n", [Ans]),
    ok.

main(_) ->
    solve(),
    halt().

input(Pat) ->
    {ok, L} = io:fread("", Pat),
    L.


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

typedef long long LL;


int main()
{
    //freopen("./test.txt","r",stdin);
    LL L,R;
    scanf("%lld %lld",&L,&R);
    if(L <= 0 && R >= 0)
    {
        puts("Zero");
        return 0;
    }
    else if(L > 0 && R > 0)
    {
        puts("Positive");
    }
    else if(L < 0 && R < 0)
    {
        LL dif = (R-L+1);
        if(dif % 2 == 0)
            puts("Positive");
        else
            puts("Negative");

    }




    return 0;
}


Measured memory_bytes: 256