akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
typedef long long int ll;
using namespace std;
vector <pii> a[100];
int main(){
    ll n;
    cin >> n;
    for (int i=0;i<n;i++){
        ll x;
        cin >> x;
        for (int j=0;j<x;j++){
            ll u,v;
            cin >> u >> v;
            a[i].pb({u,v});
        }
    }
    ll ans=0;
    for (int i=0;i<(1<<n);i++){
        vector <int> b;
        ll w=i;
        ll t=0;
        while(w){
            b.pb(w%2);
            w/=2;
        }
        for (int j=0;j<b.size();j++){
            if (b[j]){
                t++;
            }
        }
        while(b.size()<n){
            b.pb(0);
        }
        ll p1=0;
        for (int j=0;j<n;j++){
            if (!b[j]){
                continue;
            }
            for (int o=0;o<a[j].size();o++){
                ll u=a[j][o].F;
                u--;
                if (b[u]!=a[j][o].S){
                    p1=1;
                }
            }
        }
        if (!p1){
            ans=max(ans,t);
        }
    }
    cout << ans ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  long long a,sum[200000];
  long long ans=20000000000;
  for(int i=0;i<n;i++){
    cin>>a;
    sum[i]=a;
    if(i)sum[i]+=sum[i-1];
  }
  for(int i=0;i<n-1;i++){
    ans=min(ans,abs(sum[n-1]-2*sum[i]));
  }
  cout<<ans;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
int main()
{
    int a[100],b[100],N,i,j,x[100], flag=0, n_temp, j_memory;

    scanf("%d", &N);

    for(i=0;i<N;i++){
      scanf("%d",&b[i]);
      if(b[i]>(i+1)){
        flag=1;
      }      
    }
    if(flag==1){
      printf("-1");
    } else {
      /*aにコピー*/
      for(i=0;i<N;i++){
        a[i]=b[i];
      }
      
      for(i=0;i<N;i++){
        n_temp=N-i;
        /*後ろからa[j]=jなものを探索*/
        for(j=0;j<n_temp;j++){
          if(a[n_temp-j-1]==(n_temp-j)){
            j_memory=n_temp-j;
            break;
          }          
        }
        /*xに記憶*/
        x[N-i-1]=j_memory;
        /*aをアップデート*/
        for(j=j_memory-1;j<n_temp;j++){
          a[j]=a[j+1];
          /*printf("%d %d %d\n",i,j,a[j]);*/
        }
        
      }
      /*print*/
      for(i=0;i<N;i++){
        printf("%d\n",x[i]);
      }
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    sort(all(s));
    if(s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

const int N=100010;

int a[N],n;

char ch[N];

int main()
{
	scanf("%s",ch+1);
	for(int i=1;i<=strlen(ch+1);i++)
	{
		int t=0;
		while(ch[i]=='R')
		{
			t++;
			i++;
		}
		a[i-1]+=(t-t/2);
		a[i]+=t/2;
	}
	for(int i=strlen(ch+1);i>=1;i--)
	{
		int t=0;
		while(ch[i]=='L')
		{
			t++;
			i--;
		}
		a[i+1]+=(t-t/2);
		a[i]+=t/2;
	}
	for(int i=1;i<=strlen(ch+1);i++)
		cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int wall[208][208];
int rate[10][10];

int main(){
    int H,W;cin>>H>>W;
    rep(i,10)rep(j,10)cin>>rate[i][j];
    REP(i,H)REP(j,W)cin>>wall[i][j];

    vector<int> m(10);
    rep(i,10){
        
        if(i == 1)continue;
        int mi = inf;
        int par[9];
        int in = 0;
        rep(j,10){
            if(j !=i)par[in++] = j;
        }
        do{
            int tmp = 0;
            int now = i;
            rep(j,10){
                tmp += rate[now][par[j]];
                now = par[j];
                if(now == 1){
                    mi = min(mi,tmp);
                    break;
                }
            }
        }while(next_permutation(par,par+9));
        m[i] = mi;
    }
    
    int ans = 0;
    REP(i,H)REP(j,W){
        if(wall[i][j] == -1)continue;
        int from = wall[i][j];
        ans += m[from];
    }
    cout<<ans<<endl; return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std ; 

typedef long long ll ; 

char s[111111] ; 

int main()
{
    scanf("%s", s) ; 
    int len = strlen(s) ; 
    for(int i = 0 ; i != len-1 ; i++) {
        if(s[i] == s[i+1]) {
            printf("%d %d\n", i+1, i+2) ; 
            return 0 ; 
        }
    }
    for(int i = 0 ; i != len-2 ; i++) {
        if(s[i] == s[i+2]) {
            printf("%d %d\n", i+1, i+3) ; 
            return 0 ; 
        }
    }
    puts("-1 -1") ; 
    return 0 ; 
}



Measured memory_bytes: 256
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int  MOD=1000000007;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


ll modInv(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1)
            res=(res*x)%MOD;
        x=(x*x)%MOD;
        n/=2;
    }
    return res;
}

void solve(){
    long n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];

    ll fact[n+2];
    fact[0]=fact[1]=1;
    for(ll i=2;i<n+2;i++){
        fact[i]=(fact[i-1]*i)%MOD;
    }
    sort(a,a+n);
    k--;
    ll res=0;
    for(long int i=0;i<n;i++){
        if(i<=n-k-1){
            ll rem=n-i-1;
            ll ans=fact[rem];
            ans=(ans*modInv(fact[rem-k],MOD-2))%MOD;
            ans=(ans*modInv(fact[k],MOD-2))%MOD;
            ans=(ans*a[i])%MOD;
            res=(res-ans+MOD)%MOD;
        }
        if(i>=k){
            ll rem=i;
            ll ans=fact[rem];
            ans=(ans*modInv(fact[rem-k],MOD-2))%MOD;
            ans=(ans*modInv(fact[k],MOD-2))%MOD;
            ans=(ans*a[i])%MOD;
            res=(res+ans+MOD)%MOD;
        }
    }
    cout<<res<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5216
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String nl = System.getProperty("line.separator");
		StringBuilder p = new StringBuilder(1000);
		StringBuilder d = new StringBuilder(".");
		StringBuilder s = new StringBuilder("#");
		Scanner r = new Scanner(System.in);
		int h, w, i, j, ww;
		String t;
		for (i = 0; i < 6; ++i) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while ((h = r.nextInt()) + (w = r.nextInt()) > 0) {
			while (w > ww) {
				d.append(d);
				s.append(s);
				ww += ww;
			}
			p.append(s.substring(0,w));
			p.append(nl);
			t = d.substring(0, w - 2);
			for (i = 2; i < h; ++i) {
				p.append('#');
				p.append(t);
				p.append('#');
				p.append(nl);
			}
			p.append(s.substring(0,w));
			p.append(nl);
			p.append(nl);
		}
		System.out.print(p);
	}
}

Measured memory_bytes: 18408
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
ll a[100000+1];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
    	ll l,r;cin >> l >> r;l--;r--;
    	a[l]++;a[r+1]--;
    }
    for (int i = 1; i < n; ++i)
    {
    	a[i]+=a[i-1];
    }
    ll ans=0;
    for (int i = 0; i < n; ++i)
    {
    	if(a[i]>=m)ans++;
    }
    cout << ans;
    }

Measured memory_bytes: 1024
line = input().split(" ")
n = int(line[1])
sunuke_num = int(line[0])

okasi_has_list = []

for i in range(n):
  okasi_num = int(input())
  okasi_list = input().split(" ")
  okasi_has_list = okasi_has_list + okasi_list

output = set(okasi_has_list)

print(sunuke_num - len(output))

Measured memory_bytes: 66640
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 8e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int n, m, k;
int a[N];
int ans[N];
int sz[N];
vector < int > g[N];
int cur;

void calc (int v, int par = 0) {
	sz[v] = 1;
	for (auto to : g[v]) {
		if (to != par) {
			calc(to, v);
			sz[v] += sz[to];
		}
	}
}

map < int, int > was;
int lim = 1;
int t[N];


void dfs (int v, int par = 0, bool cl = 1) {
	auto get = [&](int l, int r) {	
		int res = 0;
		if (l > r) return 0;
		l += lim, r += lim + 1;
		while (l < r) {
			if (l&1) res = max(res, t[l++]);
			if (r&1) res = max(res, t[--r]);

			l >>= 1;
			r >>= 1;
		}
		return res;
	};

	auto upd = [&](int p, int x) {
		p+= lim;
		t[p] = x;
		while (p > 1) {
			p >>= 1;
			t[p] = max(t[p<<1], t[p<<1|1]);
		}
	};

	int sav = was[a[v]];

	ans[v] = get(1, a[v]-1) + 1;

	was[a[v]] = ans[v];
	upd (a[v], ans[v]);

	ans[v] = max(ans[v], ans[par]);

	vector < pair < int, int > > s;
	for (auto to : g[v]) if (to != par) {
		dfs(to, v, 1);
	}

	if(cl) {
		upd (a[v], sav);
      	was[a[v]] = sav;
	}
}

int main () {
	SpeedForce;
	cin >> n;
	lim = 1;
	while (lim < n) lim <<= 1;
	map < int, int > aa;
	For (i, 1, n) {
		cin >> a[i];
		aa[a[i]];
	}
	int cur = 0;
	for (auto &it : aa)
		it.second = ++cur;

	For (i, 1, n) a[i] = aa[a[i]];

	For (i, 1, n-1) {
		int l, r;
		cin >> l >> r;
		g[l].pb(r);
		g[r].pb(l);
	}

	calc(1);
	dfs(1);

	For (i, 1, n) cout << ans[i] << '\n';

	return Accepted;
}

// B...a


Measured memory_bytes: 66696
#include <stdio.h>

int main(void) {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a < b) {
    printf("a < b\n");
  } else if (a > b) {
    printf("a > b\n");
  } else {
    printf("a == b\n");
  }
  return 0;
}



Measured memory_bytes: 2048
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i = 0, j, x, y, z, r, H, W;
	while (1) {
		cin >> x >> y;
		if (x == 0 && y==0) {
			break;
		}
		if (x > y) {
			printf("%d %d\n", y, x);
		}
		else {
			printf("%d %d\n", x, y);
		}
	}
}

Measured memory_bytes: 3108
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int cnt = 0;
        for(int i=a; i<=b; i++){
            boolean flag = true;
            String s = ""+i;
            for(int j=0; j<2; j++){
                if(s.charAt(j)!=s.charAt(4-j)){
                    flag = false;
                    break;
                }
            }
            if(flag == true) cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 34260
/* cerberus97 - Hanit Banga */

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

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	fast_cin();
	vector<int> seq = {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};
	int k; cin >> k;
	cout << seq[k - 1] << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define pque priority_queue<long long int >
#define pquem priority_queue<long long int ,vector<long long int>,greater<long long int> >
#define setbits(x) __builtin_popcountll(x)
#define mod 1000000007
#define inf 1e18 
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int ab[1000001];
void sieve()
{
	ab[1]=1;
	for(int i=2;i<1000001;i++)
	ab[i]=i;
	for(int i=4;i<1000001;i+=2)
	ab[i]=2;
    for(int i=3;i*i<1000001;i++)
    {
        if(ab[i]==i)
        {
            for(int j=i*i;j<1000001;j+=i)
            {
            	if(ab[j]==j)
                ab[j]=i;
            }
        }
    }
}
ll power(ll a,ll b)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)
		ans*=a;
		b/=2;
		a*=a;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll k,a,b,f=0;
	cin>>k;
	ll x=100;
	while(x<k)
	{
		f++;
		x+=x/100;
	}
	cout<<f<<endl;
	return 0;
}


Measured memory_bytes: 3652
from collections import defaultdict
import bisect
s = input()
t = input()
dicta = defaultdict(list)
for i in range(len(s)):
    dicta[s[i]] += [i]
snow = -1
count = 0
flag = True
for i in t:
    if i not in s:
        flag = False
        break
    nowt = dicta[i]
    snowind = bisect.bisect_right(nowt,snow)
    if snowind == len(nowt):
        count += 1
        snow = nowt[0]
    else:
        snow = nowt[snowind]
if flag:
    print(len(s)*count+snow +1)
else:
    print(-1)
        

Measured memory_bytes: 7924
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;

int main()
{
	while (1) {
		string s;
		cin >> s;
		if (s[0] == '0' && s[1] == '0' && s[2] == '0' && s[3] == '0')
			break;
		if (s == "6174") {
			cout << 0 << endl;
		}
		else if (s[0] == s[1] &&  s[2] == s[3] && s[1] == s[2])
			cout << "NA" << endl;
		else {
			ll ans = 0;
			while (s != "6174") {
				while (s.size() != 4)
					s = '0' + s;
				
				int a[4];
				for (int i = 0; i < 4; i++)
					a[i] = s[i] - '0';

				sort(a, a + 4);

				ll small=0,large=0;
				for (int i = 0; i < 4; i++)
					large += a[i] * (ll)pow(10, i);
				
				reverse(a,a+4);
				for (int i = 0; i < 4; i++) 
					small += a[i] * (ll)pow(10, i);
				
				s = to_string(large - small);
				ans++;
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3408
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n, p[10], mxnum = 0, pri = 0;
	
	cin >> n;

	for (int k = 0; k < n; k++) {
		cin >> p[k];
		pri += p[k];
		mxnum = max(mxnum, p[k]);
	}

	pri -= mxnum / 2;

	cout << pri << "\n";

	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys

sys.setrecursionlimit(10**7)

n=int(input())
to=[[] for _ in range(n)]
eda=[]
for _ in range(n-1):
  a,b=map(int,input().split())
  to[a-1].append(b-1)
  to[b-1].append(a-1)
  eda.append([a-1,b-1])
  
c=list(map(int,input().split()))

c.sort(reverse=True)

cd=deque(c)
poi=[0 for _ in range(n)] 
vi=[-1 for _ in range(n)]

vi[0]+=1
def dfs(now):
  vi[now]+=1
  v=cd.popleft()
  poi[now]+=v
  for i in to[now]:
    if vi[i]==-1:
      dfs(i)
  
dfs(0)

ans=0

for u in eda:
  x,y=u
  ans+=min(poi[x],poi[y])
  
print(ans)
for u in range(n):
  poi[u]=str(poi[u])
  
print(' '.join(poi))
      



Measured memory_bytes: 85952
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int a, b; cin >> a >> b;
  if(a>b) swap(a, b);
  rep(i, b){
    cout << a;
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int num[10];
bool is_OK(int X){
    while(X > 0){
        int n = X % 10;
        if(num[n]){
            return false;
        }
        X /= 10;
    }
    return true;
}
int main(void){
    int N,K;
    cin >> N >> K;
    int D[K];
    for(int i=0;i<K;i++){
        cin >> D[i];
    }
    
    for(int i=0;i<K;i++){
        num[D[i]]++;
    }
    int ans;
    for(int i=N;;i++){
        if(is_OK(i)){
            cout << i << endl;
            return 0;
        }
    }
}


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

namespace TYC
{
	typedef long long ll;
	const int N = 55;

	int n, MX, D, V[N * N];
	ll W[N * N], F[N * N * N];
	vector<int> E[N];
	struct data
	{
		int v, id;
		ll w;
		bool operator < (const data &t) const { return v * t.w > t.v * w; }
	} A[N];

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	void dfs(const int u)
	{
		for (int v : E[u])
		{
			dfs(v);
			A[u].v += A[v].v;
			A[u].w += A[v].w;
		}
	}

	void work()
	{
		n = read(), MX = read(), D = read();
		A[1] = {1, 1, read()};
		for (int i = 2; i <= n; i++)
		{
			A[i] = {1, i, read()};
			E[read()].push_back(i);
		}
		dfs(1);
		sort(A + 1, A + 1 + n);
		int tot = 0, cnt = 0;
		for (int i = 1; i <= n; i++)
		{
			tot += A[i].v * n;
			for (int j = 1, t = min(D, n); t; t -= j, j = min(j << 1, t))
				V[++cnt] = j * A[i].v, W[cnt] = j * A[i].w;
		}
		memset(F, 0x3f, sizeof(F));
		F[0] = 0;
		for (int i = 1; i <= cnt; i++)
			for (int j = tot; j >= V[i]; j--)
				F[j] = min(F[j], F[j - V[i]] + W[i]);
		ll ans = 0;
		for (int i = 0; i <= tot; i++)
			if (F[i] <= MX)
			{
				ll val = i, res = MX - F[i], mx;
				for (int j = 1; j <= n; j++)
				{
					if (A[j].id == 1)
						mx = res / A[j].w;
					else
						mx = min((ll)max(0, D - n), res / A[j].w);
					val += mx * A[j].v;
					res -= mx * A[j].w;
				}
				ans = max(ans, val);
			}
		printf("%lld\n", ans);
	}
}

int main()
{
	TYC::work();
	return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//
        int A, B, C;
        cin >> A >> B >> C;

        cout << min(B / A, C) << endl;
        return 0;
}


Measured memory_bytes: 256
import Foundation

//素数判定する関数 ex:) primeJudge(32) -> true
func primeJudge(_ num: Int) -> Bool {
    var i = 2
    if num == 1 {
        return false
    }
    if num == 2 || num == 3{
        return true
    }
    
    for i in 2 ... Int(sqrt(Double(num))) {
        if num%i == 0 {
            return false
        }
    }
    return true
}

//約数列挙する関数 ex:) multiple(32) -> [1,2,4,8,16,32]
func factors(_ num: Int) -> [Int] {
    var factorsArr = [Int]()
    for i in 1 ... Int(sqrt(Double(num))) {
        if num.isMultiple(of: i) {
            factorsArr.append(i)
            if num/i != i {
            factorsArr.append(num/i)
            }
        }
    }
    
    return factorsArr.sorted()
}
//指数を求める ex:) exponents(32,2) -> 5
func exponents(_ num1: Int, _ num2: Int) -> Int {
    if num2 == 1 {
        return 1
    }
    var count = 0
    var num1 = num1
    while num1.isMultiple(of: num2) {
        num1 /= num2
        count += 1
    }
    return count
}


//素因数分解1 役数と指数を連続で格納
func primeFactorization1(_ num: Int) -> [Int] {
    var factorsArr = [Int]()
    for i in 2 ... Int(sqrt(Double(num))) {
        if num.isMultiple(of: i) {
            if primeJudge(i) {
            factorsArr.append(i)
            factorsArr.append(exponents(num, i))
            }
        }
    }
    print(factorsArr)
    return factorsArr.sorted()
}

//素因数分解2 役数と指数を別の配列に格納
func primeFactorization2(_ num: Int) -> [Int] {
    var factorsArr = [Int]()
    var exponentsArr = [Int]()
    for i in 2 ... Int(sqrt(Double(num))) {
        if num.isMultiple(of: i) {
            if primeJudge(i) {
            factorsArr.append(i)
            exponentsArr.append(exponents(num, i))
            }
        }
    }
    print(factorsArr)
    print(exponentsArr)
    return factorsArr.sorted()
}
//素因数分解3 役数と指数を二次元配列に格納
func primeFactorization3(_ num: Int) -> [[Int]] {
    var primeFactArr = [[Int]]()
    for i in 2 ... Int(sqrt(Double(num))) {
        if num.isMultiple(of: i) {
            if primeJudge(i) {
                primeFactArr.append([i,exponents(num, i)])
            }
        }
    }
    return primeFactArr
}
primeFactorization3(150)
//桁数を返す関数
func numberOfDigits(_ num: Int) -> Int {
    var digits = 1
    var num = num
    while num >= 10 {
        num /= 10
        digits += 1
    }
    return digits
}


let rdInt = Int(readLine()!)!


func factors1(_ num: Int) -> Int {
    var factorsArr = [Int]()
    for i in 1 ... Int(sqrt(Double(num))) {
        if num.isMultiple(of: i) {
            factorsArr.append(max(numberOfDigits(i),numberOfDigits(num/i)))
        }
    }
    
    return factorsArr.min()!
}

print(factors1(rdInt))

Measured memory_bytes: 13132
import java.util.*;
class Main {
	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);

        String s = sc.next();
        sc.close();
        char t = s.charAt(0);

        for (int i = 1; i < 3; i++) {
            if(t != s.charAt(i)){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 23892
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int W, H;
char table[72][72][72];
char matrix[72][72];

char maximum[72];

char *greater(char *s1, char *s2)
{
  int i;
  int nan1 = !strcmp(s1, "NaN");
  int nan2 = !strcmp(s2, "NaN");
  int len1, len2;
  if (nan1) { return s2; }
  if (nan2) { return s1; }

  len1 = strlen(s1);
  len2 = strlen(s2);
  if (len1 > len2) { return s1; }
  if (len1 < len2) { return s2; }
  for (i = 0; i < len1; i++) {
    if (s1[i] < s2[i]) { return s2; }
    if (s1[i] > s2[i]) { return s1; }
  }
  return s1;
}

void concatenate(char s[], char d[], char c)
{
  int len = strlen(s);
  if (isdigit(c)) {
    if (c == '0') {
      if (strcmp(s, "NaN") == 0) { strcpy(d, "NaN"); }
      else {
        strcpy(d, s);
        d[len] = c;
        d[len+1] = '\0';
        if (d == greater(maximum, d)) { strcpy(maximum, d); }
      }
    }
    else {
      if (strcmp(s, "NaN") == 0) {
        d[0] = c; d[1] = '\0';
        if (d == greater(maximum, d)) { strcpy(maximum, d); }
      }
      else {
        strcpy(d, s);
        d[len] = c;
        d[len+1] = '\0';
        if (d == greater(maximum, d)) { strcpy(maximum, d); }
      }
    }
  } else {
    strcpy(d, "NaN");
  }
}

int main()
{
  int i, j;
  char s[1024], greater_s[72];

  while (1) {
    if (NULL == gets(s)) { break; }
    sscanf(s, "%d%d", &W, &H); if (W == 0 && H == 0) { break; }
    for (i = 0; i < H; i++) {
      gets(matrix[i]);
    }

    strcpy(maximum, "0");

    concatenate("NaN", table[0][0], matrix[0][0]);
    /*printf("%d,%d - %s\n", 0, 0, table[0][0]);*/
    for (j = 1; j < W; j++) {
      concatenate(table[0][j-1], table[0][j], matrix[0][j]);
      /*printf("%d,%d - %s\n", 0, j, table[0][j]);*/
    }
    for (i = 1; i < H; i++) {
      concatenate(table[i-1][0], table[i][0], matrix[i][0]);
      /*printf("%d,%d - %s\n", i, 0, table[i][0]);*/
      for (j = 1; j < W; j++) {
        strcpy(greater_s, greater(table[i-1][j], table[i][j-1]));
        concatenate(greater_s, table[i][j], matrix[i][j]);
        /*printf("%d,%d - %s\n", i, j, table[i][j]);*/
      }
    }
    printf("%s\n", maximum);
  }
  return 0;
}

Measured memory_bytes: 940
#include <stdio.h>

int main(){
  int A,B;
  int ans=0;
  scanf("%d %d",&A,&B);
  for(int i=0; i<2; i++){
  if(A>B){
    ans+=A;
    A--;
  }else{
    ans+=B;
    B--;
  }
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 ll t[n+10];
 ll mod[5];
 rep(i,0,5)mod[i]=0;
 rep(i,0,n){
  sc(t[i]);
  mod[t[i]%4]++;  
 }
 ll mod_0=mod[0],mod_e=mod[1]+mod[3];
 if((mod[2]!=0&&mod_e<=mod_0)||mod[2]==0&&mod_e<=mod_0+1)py;
 else pn;
 return 0;}



Measured memory_bytes: 4388
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

     int x = sc.nextInt();
     int y = sc.nextInt();
     int z = sc.nextInt();

     int sum = z;
     int count = 0;

     while(sum<x){
       sum+=y+z;
       count++;
       if (sum>x) {
         count--;
       }
     }
     
     System.out.println(count);


      }
    }


Measured memory_bytes: 22996
n = int(input())
a = list(map(int, input().split()))
res1 = []
res2 = []
if n % 2 == 1:
  res1.append(a.pop(-1))
  n = n -1
  for i in range(n//2):
    res1.append(a[n-2-2*i])
    res2.append(a[1+i*2])
  res1.extend(res2)
  print(*res1)
else:
  for i in range(n//2):
    res1.append(a[n-1-2*i])
    res2.append(a[i*2])
  res1.extend(res2)
  print(*res1)

Measured memory_bytes: 26180
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}


signed main(){
int n;
cin>>n;
int a[n];
int cnt=0;
FOR(i,n){
cin>>a[i];
if(i%2==0){
    if(a[i]&1){cnt++;}
}
}
out(cnt);
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll val[105], wt[105];
map<ll, ll>M;
vector<ll>wt_sum[5];

int main(){

    ll n, W;
    cin>>n>>W;
    ll x, y, temp;
    cin>>x>>y;
    temp=x;
    M[x]=1;
    M[x+1]=2;
    M[x+2]=3;
    M[x+3]=4;
    wt_sum[1].push_back(y);
    for(int i=2; i<=n; i++){
        cin>>x>>y;
        int ind = M[x];
        wt_sum[ind].push_back(y);
    }
    for(int i=1; i<=4; i++){
        sort(wt_sum[i].begin(), wt_sum[i].end());
        reverse(wt_sum[i].begin(), wt_sum[i].end());

        for(int j=1; j<wt_sum[i].size(); j++){
            wt_sum[i][j]=wt_sum[i][j-1]+wt_sum[i][j];
            //cout<<wt_sum[i][j]<<endl;
        }
        //cout<<endl;
    }
    int c1 = wt_sum[1].size();
    int c2 = wt_sum[2].size();
    int c3 = wt_sum[3].size();
    int c4 = wt_sum[4].size();
    //cout<<c1<<" "<<c2<<" "<<c3<<" "<<c4<<endl;

    ll dp[c1+1][c2+1][c3+1][c4+1];

    for(int i=0; i<=c1; i++){
        for(int j=0; j<=c2; j++){
            for(int k=0; k<=c3; k++){
                for(int l=0; l<=c4; l++){
                    dp[i][j][k][l]=0;
                }
            }
        }
    }
    ll ans=0;
    for(int i=0; i<=c1; i++){
        for(int j=0; j<=c2; j++){
            for(int k=0; k<=c3; k++){
                for(int l=0; l<=c4; l++){
                    if(temp*i+(temp+1)*j+(temp+2)*k+(temp+3)*l<=W){
                        //cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;
                        if(i-1>=0)
                            dp[i][j][k][l] = max(dp[0][j][k][l] + wt_sum[1][i-1], max(dp[i-1][j][k][l], dp[i][j][k][l]));
                        if(j-1>=0)
                            dp[i][j][k][l] = max(dp[i][0][k][l] + wt_sum[2][j-1], max(dp[i][j-1][k][l], dp[i][j][k][l]));
                        if(k-1>=0)
                            dp[i][j][k][l] = max(dp[i][j][0][l] + wt_sum[3][k-1], max(dp[i][j][k-1][l], dp[i][j][k][l]));
                        if(l-1>=0)
                            dp[i][j][k][l] = max(dp[i][j][k][0] + wt_sum[4][l-1], max(dp[i][j][k][l-1], dp[i][j][k][l]));
                        ans = max(ans, dp[i][j][k][l]);
                    }
                }
            }
        }
    }
    cout<<ans;
    return 0;

}


Measured memory_bytes: 3840
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)


int main()
{
	int n;
	cin >> n;
	long long  ans = 1;
	int a = 1;
	FOR(i, 0, 9) {
		a *= 10;
	}
	FOR(i, 1, n+1) {
		ans *=i;
		ans %= (a+7);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long x=n/11;
		long y=n%11;
		int r = 0;
		if(y>0){
			r= y<=6?1 : 2;
		}
		System.out.print(x*2+r);
	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin >> n;
	auto cnt = vector<int>(9);
	for(auto i = 0; i < n; ++i){
		int a;
		cin >> a;
		if(a < 400) ++cnt[0];
		else if(a < 800) ++cnt[1];
		else if(a < 1200) ++cnt[2];
		else if(a < 1600) ++cnt[3];
		else if(a < 2000) ++cnt[4];
		else if(a < 2400) ++cnt[5];
		else if(a < 2800) ++cnt[6];
		else if(a < 3200) ++cnt[7];
		else ++cnt[8];
	}
	int low = 0;
	for(auto i = 0; i < 8; ++i){
		if(cnt[i]) ++low;
	}
	cout << max(low, (int)!!cnt[8]) << " " << low + cnt[8] << endl;
	return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC opatimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }

int main() {
//    freopen("in.txt","r", stdin);
//    freopen("out.txt","w", stdout);
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n,k,s;
    cin >> n >> k >> s;
    vector<int> a(n);
    if (s == 1000000000) {
        fill(begin(a), begin(a) + k, s);
        fill(begin(a) + k, end(a), 1);
    } else {
        fill(begin(a), begin(a) + k, s);
        fill(begin(a) + k, end(a), s + 1);
    }
    for (int i = 0; i < n; ++i)
        cout << a[i] << " \n"[i == n - 1];
}



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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll,ll> vll;
typedef pair<ll,ll> pll;

template<class T, int SZ> struct segtree {
	T identity = 0;
	T comb(T l, T r) {
		return max(l, r);
	}
	void updLeaf(T& l, T val) {
		l = val;
	}
	T tree[2*SZ+1];
	segtree() {
		M00(i, 2*SZ+1) tree[i] = identity;
	}
	void upd(int pos, T val) {
		pos += SZ+1;
		updLeaf(tree[pos], val);
		for(pos >>= 1; pos >= 1; pos >>= 1) {
			tree[pos] = comb(tree[2*pos], tree[2*pos+1]);
		}
	}
	//inclusive
	T query(int l, int r) {
		l += SZ+1;
		r += SZ+1;
		T res = identity;
		while(l <= r) {
			if(l&1) res = comb(res, tree[l++]);
			if(!(r&1)) res = comb(res, tree[r--]);
			l >>= 1; r >>= 1;
		}
		return res;
	}
};


int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	segtree<ll, 200010> tree;
	int n;
	cin >> n;
	vi H(n), A(n);
	M00(i, n) cin >> H[i];
	M00(i, n) cin >> A[i];

	M00(i, n) {
		ll best = tree.query(0, H[i]-1);
		ll cur = tree.query(H[i], H[i]);
		tree.upd(H[i], max(best + A[i], cur));
	}

	finish(tree.query(0, n));
}






Measured memory_bytes: 4992
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288

using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int main(){
    FAST_IO ;
    int x ; cin >> x ;
    cout << !x << endl ;
        
    return 0 ;
  }





// dp[x] = represents the expected value of steps to get gcd = 1 when current gcd = x


// Exepected Value  = 1 + sigma ( dp[i] / M ) from i = 1 to M ;

// 001
// 110
// 011
// 100




Measured memory_bytes: 3632
#include "bits/stdc++.h"
#include<stdio.h>
#include <sstream>
#define pi 3.141592653589793238462
#define limit 100005
#define mo 1000000007
typedef long long int lli;
typedef unsigned long long int ulli;
const lli mod=9999999999999983;
lli primes[6]={1125899906842597,1495921043,1005985879,1495921043,1005985879,1495921043};
using namespace std;
vector<lli>adj[2000009];
lli parent[2000009];
lli vis[2000009];
lli level[2000009];
lli dist[2000009];
lli dp[29][4194309];
lli arr[2009][2009];
lli brr[2000009];
lli crr[2000009];
lli hashing[2000009];
lli ar[509][509];
lli br[509][509];
lli cr[509][509];
lli nn;
map< pair<lli,lli> ,lli>mp;



lli solve(lli n,lli mask)
{
      //cout<<"n="<<n<<" "<<"mask="<<mask<<endl;

   if(dp[n][mask]!=-1)
    return dp[n][mask];

//    if(n<0)
  //      return 0;

  if(n<0)
    return 0;

   if(n==0)
   {
       //cout<<"insider="<<"n="<<n<<" mask="<<mask<<endl;
       return mask==(1<<(nn+1))-1;
   }

   lli res=0,i;

   for(i=1;i<=nn;i++)
   {
      if(arr[n][i]==1&&((mask>>i)&1)==0)
      {
        res+=solve(n-1,mask|(1<<i));
        res%=mo;
      }
   }

   return dp[n][mask]=res;
}



int main()
{
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int start_s = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    vector<lli>vect,vt,vct;
    vector<lli>::iterator itt;
    set<lli>st;
    set<lli>::iterator itr;
    //map<lli,lli>mp;
    //map<lli,lli>::iterator it;
    string str;

    lli i,j,k,m,q,t,a,b,c,maxi=INT_MIN,mini=INT_MAX,sum=0,ans=0,res=0,val=0,ans1=0,ans2=0,rem=0,diff=0,cnt=0,l,r,flag=0,e,index,val1=0,val2=0,x,y,z,h=0,u,v,mid,len,tot,fl=0;

    cin>>nn;

    for(i=1;i<=nn;i++)
    {
        for(j=1;j<=nn;j++)
        {
            cin>>arr[i][j];
        }
    }

    memset(dp,-1,sizeof(dp));

    cout<<solve(nn,1)%mo;

    //cout<<ans<<endl;
}


Measured memory_bytes: 1005184
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end() 
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;
int a[2];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	rep(ind,0,2){
		vector<int> v;
		rep(i,0,n){
			int x;
			cin >> x;
			v.push_back(x);
		}
		vector<int> p;
		rep(i,0,n){
			p.push_back(i+1);
		}
		while(1){
			if(equal(all(v), p.begin())){
				break;
			}
			++a[ind];
			next_permutation(all(p));
		}
	}
	cout << abs(a[0] - a[1]) << '\n';
}


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


int main() {
  int N, c;
  cin >> N >> c;
  vector<vector<int>> D(c, vector<int>(c));
  for (int i = 0; i < c; ++i) {
    for (int j = 0; j < c; ++j) {
      cin >> D.at(i).at(j);
    }
  }
  vector<vector<int>> T(3, vector<int>(c, 0));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      int ci;
      cin >> ci;
      ++T.at((i + j) % 3).at(ci - 1);
    }
  }
  int result = pow(2, 30);
  for (int i = 0; i < c; ++i) {
    for (int j = 0; j < c; ++j) {
      if (i == j) {
        continue;
      }
      for (int k = 0; k < c; ++k) {
        if (i == k || j == k) {
          continue;
        }
        int sum = 0;
        for (int l = 0; l < c; ++l) {
          sum += T.at(0).at(l) * D.at(l).at(i);
        }
        for (int l = 0; l < c; ++l) {
          sum += T.at(1).at(l) * D.at(l).at(j);
        }
        for (int l = 0; l < c; ++l) {
          sum += T.at(2).at(l) * D.at(l).at(k);
        }
        if (sum < result) {
          result = sum;
        }
      }
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main() {
    string S;
    cin >> S;

    int A[4];
    REP(i, 4){
        A[i] = ctoi(S[i]);
    }
    

    int res = 0;
    for (int bit = 0; bit < (1<<4); ++bit) {
        res = A[0];
        FOR(i, 1, 3) {
            if (bit & (1<<i)) {
                res += int(A[i]);
            }
            else{
                res -= int(A[i]);
            }
        }

        if(res == 7){
            cout << A[0];
            FOR(j, 1, 3){
                if (bit & (1<<j)){
                    cout << '+';
                }
                else{
                    cout << '-';
                }
                cout << A[j];
            }
            cout << "=7" << endl;
            break;
        }
    }
}

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

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> vec(H + 2, vector<char>(W + 2, '#'));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> vec.at(i + 1).at(j + 1);
		}
	}

	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			cout << vec.at(i).at(j);
		}
		cout << endl;
	}
}

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

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

  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  vector<pii>x(N);
  for(int i=0;i<N;i++)x[i]={A[i],i};
  sort(rng(x));
  for(auto it:x)cout<<it.second+1<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX 30000

signed main(){
    int n;
    cin >> n;
    vector<int> ans;
    int t, sum = 0;
    for(int i = 1; i <= MAX; i++){
        if(ans.size() == n - 2){
            t = i;
            break;
        }
        if(i % 2 == 0 || i % 3 == 0 || i % 5 == 0){
            ans.emplace_back(i);
            sum += i;
        }
    }
    for(int i = t; i <= MAX; i++){
        if(i % 2 == 0 || i % 3 == 0 || i % 5 == 0){
            for(int j = i + 1; j <= MAX; j++){
                if(j % 2 == 0 || j % 3 == 0 || j % 5 == 0){
                    if((sum + i + j) % 30 == 0){
                        ans.emplace_back(i);
                        ans.emplace_back(j);
                        goto fin;
                    }
                }
            }
        }
    }
    fin:;
    rep(i,n){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int x, y, i, j;
    cin >> x >> y;
    if(y == (x*4)|| y == (x*2)) cout << "Yes" << endl;
    else{
        for(i = 1; i <= x; i++){
            if(y == (i*4 + (x-i)*2)){
                cout << "Yes" << endl;
                return 0;
            }

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

Measured memory_bytes: 3672
def euclid(a,b):
	c=0
	if (a-b)<0:
		c=a
		a=b
		b=c
	r=-1
	while r!=0:
		r=a%b
		a=b
		b=r
	return a

N,X=map(int,input().split())
x=list(map(int,input().split()))
for i in range(N):
	x[i]=x[i]-X
	if x[i]<0:
		x[i]=x[i]*(-1)
D=x[0]
d=x[0]
for j in range(N-1):
	D=euclid(d,x[j+1])
	d=D
print(D)

Measured memory_bytes: 14100
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int x = -1, y = -1, z = -1;
    int ans = 1;
    rep(i, n)
    {
        //cout << x << " " << y << " " << z << endl;
        int cnt = 0;
        bool fx = false, fy = false, fz = false;
        if (x + 1 == a[i])
            fx = true, cnt++;
        if (y + 1 == a[i])
            fy = true, cnt++;
        if (z + 1 == a[i])
            fz = true, cnt++;
        (ans *= cnt) %= mod;
        if (fx)
            x++;
        else if (fy)
            y++;
        else
            z++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024