akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main()
{
  ll n, a;
  const int m = 26;
  string ans = "";
  cin >> n;
  while (n > 0)
  {
    n--;
    a = n % m;
    n /= m;
    ans += 'a' + a;
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

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

	LL N; cin >> N;
	LL A = 1, T = 1;
	FOR(i, 0, N) {
		LL t, a; cin >> t >> a;
		if (i == 0)A = a, T = t;
		else {
			LL x = max((A + a - 1) / a, (T + t - 1) / t);
			// 現在数のx.yyyみたいなのの大きい方
			DD(de(t, a, x));
			A = a * x;
			T = t * x;
		}
		DD(de(T,A));
	}
	LL ans = A + T;
	cout << ans << "\n";

	return 0;
}



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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define P				pair<string, int>
#define fi				first
#define se				second

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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAX_N = 100;

bool G[MAX_N][MAX_N];

signed main() {
	string s; cin >> s;
	int cnt = 0;
	REP( i, s.size() ) {
		if( s[i] == '1' ) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

vec c(10010),d(10010);
mat G(10010);
int k=0;
void DFS(int s, int p){
    d[s]=c[k++];
    each(t,G[s]){
        if(t==p) continue;
        DFS(t,s);
    }
    return;
}

int main(){
    int N; cin>>N;
    rep(i,N-1){
        int a,b; cin>>a>>b; a--;b--;
        G[a].pb(b); G[b].pb(a);
    }
    ll ans=0;
    rep(i,N){
        cin>>c[i];
        ans+=c[i];
    }
    sort(all(c),greater<ll>());
    DFS(0,-1);
    ans-=c[0];
    cout<<ans<<endl;
    rep(i,N-1) cout<<d[i]<<" ";
    cout<<d[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1408
def calc_dist(N, K, x):
    dists = [2 * min(K - x_i, x_i) for x_i in x]
    return sum(dists)

if __name__ == "__main__":
    N = int(raw_input())
    K = int(raw_input())
    x = map(int, raw_input().split())
    print(calc_dist(N, K, x))

Measured memory_bytes: 2820
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int f[300], a, b, c, N;
int exam[1000][4];

int main(){
  while(scanf("%d%d%d", &a, &b, &c) && a+b+c){
    rep(i, a+b+c) f[i] = 2;
    scanf("%d", &N);
    int l, j, k, r;
    rep(i, N){
      scanf("%d%d%d%d", &l, &j, &k, &r); --l; --j; --k; 
      exam[i][0] = l; exam[i][1] = j; exam[i][2] = k; exam[i][3] = r;
    }
    
    rep(i, N){
      if(!exam[i][3]) continue;
      rep(j, 3) f[exam[i][j]] = 1;
    }

    rep(i, N){
      if(exam[i][3]) continue;
      int c = 0;
      rep(j, 3) if(f[exam[i][j]] == 1) c++;
      if(c == 2) rep(j, 3) if(f[exam[i][j]] == 2) f[exam[i][j]] = 0;
    }

    rep(i, a+b+c) printf("%d\n", f[i]);
  }
  return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>

int main(){
int N,a[100001],i,b,c,count=0;
scanf("%d",&N);
for(i=0;i<N;i++){
scanf("%d",&a[i]);
}
b=0;
while(a[b]!=2){
if(a[b]==0){
count=-2;
break;
}
c=b;
b=a[b]-1;
a[c]=0;
count++;
}
printf("%d",count+1);
return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

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


int main() {
  int n;
  cin >> n;
  int ma = -1, ma2 = 0;
  rep (i, n) {
    int a, b;
    cin >> a >> b;
    if (ma < a) {
      ma = a;
      ma2 = b;
    }
  }
  cout << ma + ma2 << endl;
}



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

using namespace std;

long long n, k, c = 0, m = 10000000000, a[1000001];

int main(){
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x != 0){
            c++;
            a[c] = x;
        }
    }
    if (n != c) k--, n--;
    if (k == 0) cout << 0;
    else{
        for (int i = 1; i + k - 1 <= n; i++){
            if (a[i]*a[i+k-1] > 0) m = min(m, max(abs(a[i]), abs(a[i+k-1])));
            else{
                long long x = abs(a[i] - a[i+k-1]);
                m = min(m, min(x + abs(a[i]), x + abs(a[i+k-1])));
            }
        }
        cout << m;
    }
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); 
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}	
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}		    
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}	    	  	
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}		
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}	
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}	    	
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}	    	
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}				
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        
        int T = 1;//in.nextInt();
        for(int t = 1; t <= T; t++)
        {
            int n = in.nextInt();
            String s = in.next().trim();
            String p = in.next().trim();
            char ch[] = new char[2*n];
            int pt = 0;
            for(int i=0;i<n;i++){
                ch[pt] = s.charAt(i);
                ch[pt+1] = p.charAt(i);
                pt+=2;
                // char ch = 
                // out.write((char)s.charAt(i)+(char)p.charAt(i)+"");
            }
            out.write(new String(ch)+"\n");
        }
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21076
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
using ll = long long;

int main() {
	ll n;
	cin >> n;
	vector<ll>v;
	map<ll, ll>num;
	for (int i = 0;i < n;i++) {
		ll a;
		cin >> a;
		num[a]++;
		if (num[a] == 2)v.push_back(a);
		if (num[a] == 4)v.push_back(a);
	}
	if (v.size() < 2) {
		cout << 0 << endl;
		return 0;
	}
	sort(v.begin(), v.end());
	ll k = v.size();
	cout << v[k - 1] * v[k - 2] << endl;
}

Measured memory_bytes: 6528
import math

K = int(input())


memo = [[None for _ in range(201)]  for _ in range(201)]
for i in range(1,201):
    for j in range(1,201):
        memo[i][j] = math.gcd(i,j)

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = memo[a][b]
        for c in range(1, K+1):
            ans += memo[tmp][c]


print(ans)

Measured memory_bytes: 9424
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    string s;
    string z,y;
    cin>>s;
    int n;
    cin>>n;
    int flag=1;
    while(n--)
    {
        int a,b,c;
        char op;
        cin>>a;
        if(a==1)
        {
            if (flag==1)
                flag=0;
            else
                flag=1;
        }
        else{
        if(flag==1)
        {
            string op;
            cin>>b>>op;
            if(b==1)
                z=op+z;
            if(b==2)
                y=y+op;
        }
        else
        {
            string op;
            cin>>b>>op;
            if(b==2)
                z=op+z;
            if(b==1)
                y=y+op;
        }


    }} s=z+s;
        s=s+y;  if(flag==0)
            reverse(s.begin(),s.end());
cout<<s<<endl;
}


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

struct UnionFind{
	vector<int>par;
	vector<int>sz;
	UnionFind(int n){
		par=sz=vector<int>(n);
		rep(i,n)par[i]=i,sz[i]=1;
	}
	int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		par[y]=x;
		sz[x]+=sz[y];
	}
	int size(int x){
		x=find(x);
		return sz[x];
	}
};

P a[200000],b[200000];

int main(){
	int n;cin>>n;
	rep(i,n)scanf("%d",&a[i].first),a[i].second=i;
	rep(i,n)scanf("%d",&b[i].first),b[i].second=i;
	sort(a,a+n);
	sort(b,b+n);
	UnionFind uf(n);
	rep(i,n){
		if(a[i].first>b[i].first){
			puts("No");return 0;
		}
		uf.unite(a[i].second,b[i].second);
	}
	if(uf.size(0)!=n){puts("Yes");return 0;}
	rep(i,n-1){
		if(a[i+1].first<=b[i].first){
			puts("Yes");return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 3456
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
template <typename T>
T gcd(T a,T b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
template <typename T>
T lcm(T a,T b){
  return a/gcd(a,b)*b;
}
int dp[200][200];
struct z{
	int a,b,c;
};
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
	int a,b;char c;cin>>a>>b>>c;
	cout << "+";
	for(int i = 1; a-1 > i; i++){
		cout << "-";
	}
	cout << "+";
	cout << endl;
	for(int i = 1; b-1 > i; i++){
		cout << "|";
		for(int j = 1; a-1 > j; j++){
			if(i==b/2 && j==a/2)cout << c;
			else cout << ".";
		}
		cout << "|";
		cout << endl;
	}
	cout << "+";
	for(int i = 1; a-1 > i; i++){
		cout << "-";
	}
	cout << "+";
	cout << endl;
	
}


Measured memory_bytes: 3156
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

priority_queue<string> qu;

int main(){
  string s;
  int k;
  cin >> s >> k;
  int lg = s.length();

  // for(int i=0;i<lg;i++){
  //   for(int j=1;j<=lg-i;j++){
      
  //     string b=s.substr(i,j);
  //     //cout<<b<<endl;
  //     if(qu.empty()||qu.top()>s){
  //       if(qu.size()==k){
  //         qu.pop();
  //       }
  //       qu.push(b);
  //       if(qu.size()==k){
  //         break;
  //       }
  //     }
  //   }
  // }
  // cout<<qu.top()<<endl;
  // while(!qu.empty()){
  //   cout<<qu.top()<<endl;
  //   qu.pop();
  // }

  vector<string> v;
  for(int i=0;i<lg;i++){
    int m=0;
    for(int j=1;j<=lg-i;j++){
      string b=s.substr(i,j);

      if(v.empty()||find(v.begin(),v.end(),b)==v.end()){
        if(v.size()==k&&v.back()>b){
          v.pop_back();
          v.push_back(b);
        }
        if(v.size()<k){
          v.push_back(b);
        }
        if(m>k){break;}
        m++;
        sort(v.begin(),v.end());
        
      }
    }
  }
  cout<<v.back()<<endl;
  
  return 0;
}

Measured memory_bytes: 888
//#include<bits/stdc++.h>
//#pragma GCC optimize(2)
//using namespace std;
//typedef long long ll;
//int A,B;
//int main()
//{
//	scanf("%d%d",&A,&B);
//	int add=A+B;
//	int jian=A-B;
//	int times=A*B;
//	printf("%d\n",max(times,max(add,jian)));
//	return 0;
//}
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	if(n==1) {printf("%d\n",m);}
	else 
	{
		for(int i=m-n+1;i<=m+n-1;i++)
		{
			printf("%d ",i);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
N = [x for x in input().split(' ')]
#データを格納するための整数型1次元配列
stack = []
for i in N:
    # +が入っていた場合
    if i == '+':
        num1 = stack.pop()
        num2 = stack.pop()
        stack.append(num1 + num2)
    # -が入っていた場合
    elif i == '-':
        num2 = stack.pop()
        num1 = stack.pop()
        stack.append(num1 - num2)
    # *が入っていた場合
    elif i == '*':
        num1 = stack.pop()
        num2 = stack.pop()
        stack.append(num1 * num2)
    #算術演算子( + - *)以外が入っていた場合
    else:
        stack.append(int(i))

#表示
print(stack.pop())


Measured memory_bytes: 5604
n,m,l = map(int, input().split())
a = []
b = []
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(list(map(int, input().split())))
for i in range(n):
    for j in range(l):
        ans = 0
        for k in range(m):
            ans += a[i][k]*b[k][j]
        if j == l-1:
            print(f'{ans}', end='')
        else:  
            print(f'{ans} ', end='')
    print() 


Measured memory_bytes: 6588
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstddef>
#include <cinttypes>
#include <memory>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <array>
#include <valarray>
#include <string>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <queue>
#include <complex>
#include <tuple>
#include <utility>
#include <functional>
#include <algorithm>
#include <numeric>

using namespace std;

const double EPS = 1e-10;
const int64_t INF = 1e9;

typedef long long ll;

int A[200000], B[200000];
int ans[200000];

int main()
{
	int N;

	scanf("%d", &N);

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

	int p = 0, q = 0;
	int p1 = -1, q1, p2, q2;
	int cur = 0;
	while (p < N || q < N) {
		int m;
		if (p < N) {
			m = A[p];
			if (q < N && B[q] < A[p])
				m = B[q];
		} else {
			m = B[q];
		}
		int np = p, nq = q;
		while (np < N && A[np] == m) ++np;
		while (nq < N && B[nq] == m) ++nq;
		//printf("m: %d np: %d nq: %d\n", m, np, nq);
		if (np-p + nq-q > N) {
			printf("No\n");
			return 0;
		}

		if (p1 == -1 && np >= N - nq) {
			p1 = p;
			q1 = q;
			p2 = np;
			q2 = nq;
		}
		
		p = np;
		q = nq;
	}

	printf("Yes\n");

	//printf("%d %d %d %d\n", p1, p2, q1, q2);
	int r = min(min(p1, q2-q1), p2-(N-q2));
	int spl = q2 - r;
	for (int i = spl; i < N; ++i) {
		if (i != spl) printf(" ");
		printf("%d", B[i]);
	}
	for (int i = 0; i < spl; ++i) {
		if (spl != N || i != 0) printf(" ");
		printf("%d", B[i]);
	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 4784
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstring>

#define ll long long
const ll MOD = 1e9 + 7;

int main()
{
    std::ios::sync_with_stdio(false);

    int N;
    std::cin >> N;
    std::vector<double> p(N);

    double dp[N + 1][N + 1];
    memset(dp, 0, sizeof(dp));

    for (int i=0; i<N; i++)
    {
        std::cin >> p[i];
    }

    dp[0][0] = 1;
    // i番目まで投げて
    for (int i=0; i<N; ++i)
    {
        // j枚表が出てる場合
        for (int j=0; j<=i; ++j)
        {
            // i番目が表の場合
            dp[i+1][j+1] += dp[i][j] * p[i];

            // 裏の場合
            dp[i+1][j] += dp[i][j] * (1 - p[i]);
        }
    }

    // N枚まで投げた時 半分以上表の確率の合計
    double result = 0;
    for (int i=(N/2+1); i<=N; ++i)
    {
        result += dp[N][i];
        //std::cout << "表が" << i << "枚出る確率" << dp[N][i] << std::endl;
    }
    std::cout << std::fixed << std::setprecision(10) <<  result;
}

Measured memory_bytes: 70656
#include <iostream>
#include <cstdio>

using namespace std;

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

    int ans = 0;
    for (int i = n; i > 0; --i) {
        if (i < 10 || (i >= 100 && i < 1000) || (i >= 10000 && i < 100000))
            ++ans;
    }

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

    return 0;
}


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n;

signed main()
{
	IOS;
	cin >> n;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (i * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		long X;
		X = sc.nextLong();
		long Y;
		Y = sc.nextLong();
		solve(X, Y);
	}

	static void solve(long X, long Y) {
		if (Math.abs(X - Y) <= 1) {
			System.out.println("Brown");
		} else {
			System.out.println("Alice");
		}

	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define lli long long
using namespace std;

vector<long long>vp;
int n;
int ara[22][22];
long long dp[22][10+(1<<21)];
long long mod=1e9+7;
long long dpp(int i,int mask)
{
  if(i==n)
  return 1;

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

  long long ans=0;
  for(int j=0;j<n;j++)
  {

     if(ara[i][j] && !(mask&(1<<j)))
     {
      ans+=dpp(i+1,mask|(1<<j));
      if(ans>=mod)
      ans%=mod;
     }

  }
  return dp[i][mask]=ans;

}

int main()
{

  memset(dp,-1,sizeof dp);
  cin>>n;
  for(int i=0;i<n;i++)
  for(int j=0;j<n;j++)
  cin>>ara[i][j];
  cout <<dpp(0,0);
}






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

int n,a[400010],b[400010];
int s[400010],S[400010],fail[400010],pre[400010]; 

inline void failure()
{
	int i,j=-1;
	fail[0]=-1;
	for(int i=0;i<n;i++){
		while(j>=0&&s[i]!=s[j]) j=fail[j];
		j++;
		fail[i+1]=j;
	}
}

inline void kmp()
{
	int i,j=0;
	pre[0]=0;
	for(int i=0;i<n*2;i++){
		while(j==n||(j>=0&&S[i]!=s[j])) j=fail[j];
		j++;
		pre[i+1]=j;
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++) S[i]=a[i]^a[(i+1)%n];
	for(int i=n;i<n*2;i++) S[i]=S[i-n];
	for(int i=0;i<n;i++) s[i]=b[i]^b[(i+1)%n];
	failure();kmp();
	for(int i=1;i<n*2;i++){
		if(pre[i]==n){
			cout<<i-n<<" "<<(b[0]^a[i-n])<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 12032
#include <iostream>
using namespace std;
int main(){
    struct Box{
        int count;
        int flag;
    };
    int num,step,from,to,ans=0;
    Box box[100005];
    cin>>num>>step;
    for(int i = 1;i<=num;i++){
        box[i].count = 1;
        box[i].flag = 1;
    }
    box[1].flag = -1;
    while(step--){
        cin>>from>>to;
        if(box[from].flag==-1){
            box[to].flag=-1;
        }
        box[to].count++;
        box[from].count--;
        if(box[from].count==0) box[from].flag=1;
    }
    for(int i = 1;i<=num;i++){
        if(box[i].flag==-1) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
import sys
arr = {'A':1,'B':0,'C':0}
for line in sys.stdin:
    s = line.split(',')
    n = s[0]
    m = s[1][0]

    if arr[n] == 1 or arr[m] == 1:
        arr[n] = (arr[n]+1)%2
        arr[m] = (arr[m]+1)%2

for k,v in arr.items():
    if v == 1:
        print(k)

Measured memory_bytes: 7352
#include<bits/stdc++.h>
using namespace std;
vector <long long> v[4];
long long b, t, pn;
long long r(long long poz, long long ot)
{
	if(poz == 4)
	{
		return 0;
	}
	long long z = 0;
	z = r(poz+1, ot);
	for(int i = v[poz].size()-1; i >= 0; i--)
	{
		if(ot < (long long)((long long)(poz+pn)*(long long)(v[poz].size()-i)))
		{
			break;
		}
		z = max(z, r(poz+1, ot-((poz+pn)*(v[poz].size()-i))) + v[poz][i]);
	}
	return z;
}
int main()
{
    cin >> b >> t;
    long long n, c;
    for(int i = 0; i < b; i++)
    {
    	cin >> n >> c;
    	if(i == 0)
    	{
    		pn = n;
		}
		v[n-pn].push_back(c);
	}
	sort(v[0].begin(), v[0].end());
	sort(v[1].begin(), v[1].end());
	sort(v[2].begin(), v[2].end());
	sort(v[3].begin(), v[3].end());
	for(int i = 0; i < 4; i++)
	{
		for(int j = v[i].size()-2; j >= 0; j--)
		{
			v[i][j] += v[i][j+1];
		}
	}
	cout << r(0, t) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
      int c=0;
      if((a+b)%2!=0){
      c=1;}
		System.out.println(c+((a+b)/2));
    
    }}


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

int main() {
  int64_t a, b, c;
  cin >> a >> b >> c;

  if(c-a-b<0){
		printf("No\n");return 0;
	}
	if(4*a*b<(c-a-b)*(c-a-b)){
		printf("Yes\n");
	} else {
    printf("No\n");
  }

}


Measured memory_bytes: 256
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

function next() {
    return +cin[cid++];
} // number一個取得
function nextstr() {
    return cin[cid++];
} // 文字列一個取得
function nextbig() {
    return BigInt(cin[cid++]);
} // BigInteger一個取得
// 長さnの配列として取得。aは文字列フラグ
function nexts(n, a) {
    return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a);
}
// 長さnのBigInt配列として取得。
function nextsbig(n) {
    return cin.slice(cid, cid += n).map(a => BigInt(a));
}
// w個ずつを組にして長さhの配列。aは文字列フラグ。
function nextm(h, w, a) {
    var r = [],
        i = 0;
    if (a)
        for (; i < h; i++) r.push(cin.slice(cid, cid += w));
    else
        for (; i < h; i++) r.push(cin.slice(cid, cid += w).map(a => +a));
    return r;
}
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
function xArray(v) {
    var a = arguments,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + v + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
}


console.log(main().toString());

function main() {
    let N = next();
    let K = next();
    return (N & 1) && (K & 1) ? 'Odd' : 'Even'
}

Measured memory_bytes: 7372
#include <iostream>
using namespace std;
 
int main(){
    int a, b;
    char op;
    while(cin >> a >> op >> b && op != '?'){
        switch(op){
            case '+': cout << a+b << endl;break;
            case '-': cout << a-b << endl;break;
            case '*': cout << a*b << endl;break;
            case '/': cout << a/b << endl;break; 
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    cin>>N;
    cout<<1000 * ((N + 999) / 1000) - N<<endl;
}


Measured memory_bytes: 3640
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s[2]; cin>>s[0]>>s[1];
	For(i,0,sz(s[0])+sz(s[1])-1) cout<<s[i%2][i/2];
	cout<<"\n";
	return 0;
}





























Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll H,W;
    cin>>H>>W;
    vector<vector<bool>> S(H,vector<bool>(W,false));
    for(auto i=0;i<H;i++){
        for(auto j=0;j<W;j++){
            char c;
            cin>>c;
            if(c=='#'){
                S[i][j]=false;
            }else if(c=='.'){
                S[i][j]=true;
            }else{
                cout<<"ERROR"<<endl;
            }
        }
    }
    int imos_w[H][W]={0};
    for(auto i=0;i<H;i++){
        for(auto j=0;j<W;j++){
            if(!S[i][j]){
                imos_w[i][j] = 0;
            }else{
                int right;
                for(right=0;;right++){
                    if(j+right>=W||!S[i][j+right]){
                        // cout<<"i:"<<i<<", j:"<<j<<", right:"<<right<<endl;
                        imos_w[i][j] = right;
                        for(ll k=1;k<right;k++){
                            imos_w[i][j+k] = right;
                        }
                        j+=right-1;
                        break;
                    }
                }
            }
        }
    }
    int imos_h[H][W]={0};
    for(auto j=0;j<W;j++){
        for(auto i=0;i<H;i++){
            if(!S[i][j]){
                imos_h[i][j] = 0;
            }else{
                int down;
                for(down=0;;down++){
                    if(i+down>=H||!S[i+down][j]){
                        imos_h[i][j] = down;
                        for(ll k=0;k<down;k++){
                            imos_h[i+k][j] = down;
                        }
                        i+=down;
                        break;
                    }
                }
            }
        }
    }
    // for(auto i=0;i<H;i++){
    //     for(auto j=0;j<W;j++){
    //         cout<<imos_w[i][j];
    //     }
    //     cout<<endl;
    // }

    int res=0;
    for(auto i=0;i<H;i++){
        for(auto j=0;j<W;j++){
            res = max(res,imos_h[i][j]+imos_w[i][j]-1);
        }
    }
    cout<<res<<endl;
}
 

Measured memory_bytes: 32128
#include<iostream>
using namespace std;
int a,b,cnt[31],ans;
int main()
{
cin>>a>>b;
for(int i=1;i<=a;i++)
{
int k;
cin>>k;
for(int j=1;j<=k;j++)
{
int l;
cin>>l;
cnt[l]++;
}
}
for(int i=1;i<=30;i++)if(cnt[i]==a)ans++;
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
	int i, j, aux;
	int n=3;
	int arr[n];
	for(i=0;i<n;i++){
    	scanf("%i",&arr[i]);
	}
	for(i=0; i<=n; i++){
		for(j=0; j<n-1; j++){
			if(arr[j]>=arr[j+1]){
				aux= arr[j];
				arr[j] = arr[j+1];
				arr[j+1]=aux;
			}
		}
	}
	int resultado= arr[0]+arr[1];
	printf("%i", resultado);
}

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(void) {
	string S,T;
	cin >> S >> T;
	int len = S.length();
	int snum,tnum;
	snum = tnum = 0;
	vector<int> smemo('z'-'a'+1,-1);
	vector<int> tmemo('z'-'a'+1,-1);
	bool flag = false;
	for (int i = 0; !flag && i < len; ++i) {
		int snow;
		if (smemo[S[i]-'a'] < 0) {
			snow = snum;
			smemo[S[i]-'a'] = snum;
			++snum;
		}
		else {
			snow = smemo[S[i]-'a'];
		}

		int tnow;
		if (tmemo[T[i]-'a'] < 0) {
			tnow = tnum;
			tmemo[T[i]-'a'] = tnum;
			++tnum;
		}
		else {
			tnow = tmemo[T[i]-'a'];
		}
		
		if (snow != tnow) {
			flag = true;
		}
	}

	if (!flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 776
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second

template <typename T> int sgn(T val) {
    return (T(0) < val) - (val < T(0));
}

int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A;
    rep(i, N) {
        ll a;
        cin >> a;
        A.pb(a);
    }
    ll a1 = 0;
    ll S1 = 0;
    rep (i, N) {
        S1 += A[i];
        if (i % 2 == 0) {
            if (S1 <= 0) {
                a1 += abs(S1 - 1);
                S1 = 1;
            }
        } else {
            if (S1 >= 0) {
                a1 += abs(S1 + 1);
                S1 = -1;
            }
        }
    }
    ll a2 = 0;
    ll S2 = 0;
    rep (i, N) {
        S2 += A[i];
        if (i % 2 != 0) {
            if (S2 <= 0) {
                a2 += abs(S2 - 1);
                S2 = 1;
            }
        } else {
            if (S2 >= 0) {
                a2 += abs(S2 + 1);
                S2 = -1;
            }
        }
    }
    cout << min(a1, a2) << endl;
}



Measured memory_bytes: 1400
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


signed main(){
    FASTER;
    vi v(3);cin>>v;
    sort(all(v));
    cout<<v[0]+v[1];
}

Measured memory_bytes: 3552
using System;
using System.Collections.Generic;
using System.Linq;

namespace A
{
	class Program
	{
		static void Main()
		{
			var a = new List<int>();
			for (int i = 0; i < 5; i++) {
				a.Add(int.Parse(Console.ReadLine()));
			}
			var k = int.Parse(Console.ReadLine());

			for (int i = 0; i < 5; i++) {
				for (int j = i + 1; j < 5; j++) {
					if (a[j] - a[i] > k) { Console.WriteLine(":("); Environment.Exit(0); }
				}
			}
			Console.WriteLine("Yay!");
		}
	}
}

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

int main(){
	int n;
	cin >> n;
	int ans = 1;

	while(true){
		if(ans*2 <= n) ans *=2;
		else break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String A = scanner.next();
		String x = scanner.next();
		String C = scanner.next();
		System.out.println(A.substring(0,1)+x.substring(0,1)+C.substring(0,1));
		scanner.close();
	}
}
	

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

const int MAXN = 100010;
struct Edge {
	int to;
	Edge *next;
}*head[MAXN];
int indegree[MAXN];
void addedge(int a, int b) {
	head[a] = new Edge{b, head[a]};
	indegree[b]++;
}

int ans=0;
int dp[MAXN];
void dfs(int p, int dis) {
	if (dis > ans) {
		ans = dis;
	}
	dp[p] = max(dp[p], dis);
	if (--indegree[p] <= 0)
		for (Edge *e=head[p]; e; e=e->next)
			dfs(e->to, dp[p]+1);
}
int n,m;
int main() {
	memset(head, 0, sizeof(head));
	memset(indegree, 0, sizeof(indegree));
	memset(dp, 0, sizeof(dp));
	cin>>n>>m;
	for (int i=0; i<m; i++) {
		int a, b;
		cin>>a>>b;
		addedge(a, b);
	}
	for (int i=1; i<=n; i++)
		if (indegree[i] == 0)
			addedge(0, i);
	dfs(0, 0);
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define all(vv) (vv).begin(), (vv).end()
#define rep(ii, jj, ll, ss) for(int ii = jj; ii < ll; ii += ss)
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0;
#define get(vv, times) for(int ii = 0; ii < times; ++ii) {int jj; cin >> jj; (vv).pb(jj);}

int n, both;
string s;
vector <int> v;

int32_t main() {
	cin >> n;
	cin >> s;
	rep(i, 1, n, 1) {
		string x = s.substr(0, i);
		string y = s.substr(i, n);
		set <char> a = set <char> (all(x));
		set <char> b = set <char> (all(y));
		both = 0;
		for (auto it:a) {
			if (b.find(it) != b.end()) ++both;
		}
		v.pb(both);
		cerr << x << ' ' << y << ' ' << both << '\n';
	}
	cout << *max_element(all(v));
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <limits>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <forward_list>
#include <cstdint>

using namespace std;
typedef long long ll;

#define rep(_i,_t) for (int _i=0; _i<(int)(_t); _i++)
#define rep1(_i,_t) for (int _i=1; _i<=(int)(_t); _i++)
#define repn(_i,_n,_t) for (int _i=(int)_n; _i<=(int)(_t); _i++)
#define all(_c) _c.begin(), _c.end()

class bipartite_matching {
public:
	int n;
	std::vector<std::vector<int>> g;
	std::vector<int> match;

	bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {}

	void add_edge(int u, int v) {
		g[u].push_back(v);
		g[v].push_back(u);
	}

	int maximum_matching(void) {
		int res = 0;
		fill(begin(match), end(match), -1);
		for (int v = 0; v < n; ++v) {
			if (match[v] == -1) {
				fill(begin(used), end(used), false);
				if (dfs(v)) res++;
			}
		}
		return res;
	}

private:
	std::vector<int> used;
	bool dfs(int v) {
		used[v] = true;
		for (int u : g[v]) {
			int w = match[u];
			if (w == -1 || (!used[w] && dfs(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
};

using t = pair<int, int>;

int main()
{
	int N;
	cin >> N;
	vector<t> a;
	vector<t> b;
	rep(i, N) {
		int x, y;
		cin >> x >> y;
		a.emplace_back(x, y);
	}
	rep(i, N) {
		int x, y;
		cin >> x >> y;
		b.emplace_back(x, y);
	}
	//sort(all(a));
	//sort(all(b));
	bipartite_matching bm(2*N);
	rep(i, N) {
		rep(j, N) {
			if (a[i].first < b[j].first && a[i].second < b[j].second) {
				bm.add_edge(i, j + N);
			}
		}
	}
	int ans = bm.maximum_matching();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/25/20 20:57:10
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int INF = 1e9;

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

  int n; cin>>n;
  struct City {
    int x,y,p;
  };
  vector<City> C(n);
  for (int i = 0; i < n; i++) {
    int x,y,p; cin>>x>>y>>p;
    C[i] = {x, y, p};
  }
//  n = 15;
  ll distx[1<<n][n], disty[1<<n][n];
  for (int mask = 0; mask < (1<<n); mask++) {
    for (int i = 0; i < n; i++) {
      int mindistx = abs(C[i].x), mindisty = abs(C[i].y);
      for (int j = 0; j < n; j++) {
        if ((mask & (1<<j)) == 0) continue;
        mindistx = min(mindistx, abs(C[i].x-C[j].x));
        mindisty = min(mindisty, abs(C[i].y-C[j].y));
      }
      distx[mask][i] = (ll)mindistx * C[i].p;
      disty[mask][i] = (ll)mindisty * C[i].p;
    }
  }
  vector<ll> ans(n+1, 1e18);
  for (int mask = 0; mask < (1<<n); mask++) {
    int popcnt = __builtin_popcount(mask);
    for (int xmask = mask; xmask >= 0; xmask=(xmask-1)&mask) {
      int ymask = mask^xmask;
      ll sum = 0;
      for (int i = 0; i < n; i++) {
        sum += min(distx[xmask][i], disty[ymask][i]);
      }
      ans[popcnt] = min(ans[popcnt], sum);
      if (xmask == 0)
        break;
    }
  }
  for (auto a:ans)
    cout << a << endl;

  return 0;
}


Measured memory_bytes: 11296
#include <iostream>
#include <string>
int main(int argc, char *argv[]) {
	unsigned int n, a;
	std::cin >> n >> a;
	const unsigned int r = n % 500;
	const bool avail = (r <= a);
	const std::string s = (avail) ? "Yes" : "No";
	std::cout << s << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define For(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)
int N;

int main() {
    string s;
    cin >> s;
    string result="No";
    if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)) result="Yes";
    cout << result << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N = input()
    l = len(N)
    K = int(input())

    ans = 0
    # 最上位K桁が0の場合
    # l-K_C_K * 9^K
    if K == 1:
        ans += (l-1) * 9
    elif K == 2:
        ans += (l-1) * (l-2) * 81 // 2
    else:
        ans += (l-1) * (l-2) * (l-3) * 729 // 6

    if K == 1:
        # 最上位の数以外0
        ans += int(N[0])
    elif K == 2:
        # 最上位1桁が0ではなく,残りl-1桁中1桁だけ0以外（Nより大きくならないように注意）
        if l >= 2:
            # ans += int(N[0]) * (l-1) * 9 - (9 - int(N[1]))
            for a in range(1,int(N[0])+1):
                for b in range(l-1):
                    for p in range(1,10):
                        tmp = a * 10**(l-1) + p * 10**b
                        if tmp <= int(N):
                            ans += 1
    else:
        # 最上位1桁が0ではなく,残りl-1桁中2桁だけ0以外（Nより大きくならないように注意）
        if l >= 3:
            NN = int(N)
            N0 = int(N[0])
            L = 10**(l-1)

            ans += (N0-1) * (l-1) * (l-2) * 81 // 2

            for p in range(1,10):
                for q in range(1,10):
                    for b in range(l-1):
                        for c in range(b+1,l-1):
                            tmp = N0 * L + p * 10**b + q * 10**c
                            if tmp <= NN:
                                ans += 1
                            else:
                                break
    print(ans)

if __name__ == "__main__":
    main()


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

typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
const int N=5000+5,D=1e9+7;
ll mi(ll x,int y=D-2)
{
	ll ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}
int n;
vector<int>lk[N];
int fa[N],sz[N],q[N];
ll jie[N],nijie[N];
ll qa[2][N],*dp=qa[0],*dp0=qa[1];

void bfs(int rt)
{
	int tail=1;
	q[1]=rt;
	fa[rt]=0;
	rep(head,1,tail)
	{
		int x=q[head];
		for(auto y:lk[x])
		if(y!=fa[x])
		{
			fa[y]=x;
			q[++tail]=y;
		}
	}
	rep(x,1,n)sz[x]=1;
	per(head,tail,1)
	{
		int x=q[head];
		sz[fa[x]]+=sz[x];
	}
}

ll C(int n,int m)
{
	return jie[n]*nijie[m]%D*nijie[n-m]%D;
}

int main()
{
	//freopen("1.in","r",stdin);
	cin>>n;
	rep(i,1,n-1)
	{
		int x,y;
		cin>>x>>y;
		lk[x].pb(y);lk[y].pb(x);
	}
	bfs(1);
	int rt=0;
	per(head,n,1)
	{
		int x=q[head];
		if(sz[x]>=(n+1)/2)
		{
			rt=x;
			break;
		}
	}
	bfs(rt);
	jie[0]=1;
	rep(i,1,n)jie[i]=jie[i-1]*i%D;
	nijie[n]=mi(jie[n]);
	per(i,n-1,0)nijie[i]=nijie[i+1]*(i+1)%D;
	int tot=1;
	dp[0]=1;
	for(auto y:lk[rt])
	{
		int nsz=sz[y];
		swap(dp,dp0);
		rep(i,0,tot+nsz)dp[i]=0;
		rep(j,0,nsz)
		{
			ll fj=C(nsz,j)*C(nsz,j)%D*jie[j]%D;
			rep(i,0,tot)(dp[i+j]+=dp0[i]*fj)%=D;
		}
		tot+=nsz;
	}
	ll ans=0;
	rep(i,0,n)
	{
		if(i%2==0)(ans+=dp[i]*jie[n-i])%=D;
		else (ans-=dp[i]*jie[n-i])%=D;
	}
	cout<<(ans+D)%D<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll n;
vector<pair<ll,ll>>ch[100010];
ll ans[100010];
void dep(ll now,ll c){
	if(now!=0&&ch[now].size()==1){
		return ;
	}
	for(ll i=0;i<ch[now].size();i++){
		ll next=ch[now][i].first;
		if(ans[next]!=-1){
			continue;
		}
		ll co=ch[now][i].second;
		if(co%2==0){
			ans[next]=c;
			dep(next,c);
		}
		else{
			ans[next]=abs(c-1);
			dep(next,ans[next]);
		}
	}
}
int main() {
	cin>>n;
	for(ll i=0;i<n;i++){
		ans[i]=-1;
	}
	for(ll i=0;i<n-1;i++){
		ll x,y,c;
		cin>>x>>y>>c;
		x--;y--;
		ch[x].push_back(make_pair(y,c));
		ch[y].push_back(make_pair(x,c));
	}
	ans[0]=0;
	dep(0,0);
	for(ll i=0;i<n;i++){
		cout <<ans[i]<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 13228