akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <unordered_map>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
#define dbg(...) fprintf(stderr,__VA_ARGS__);
struct range{
	int e,b=0,s=1;range(int b,int e,int s):e(e),b(b),s(s){} range(int b,int e): e(e), b(b){} range(int e):e(e){}
	struct it{int v,s; it(int v,int s):v(v),s(s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

_T using V = vector<T>;
using M = unordered_map<int, double>;

int main() {
	for (int N, T, L, B; N = in, T = in, L = in, B = in, N;) {
		V<double> d(N + 1);
		d[0] = 1.;
		V<char> c(N + 1, ' ');
		M m;
		times(i, L)
			c[in] = 'L';
		times(i, B)
			c[in] = 'B';
		times(i, T) {
			V<double> t(N + 1);
			M tm;
			t[N] = d[N];
			for (int j: range(N)) {
				double x {d[j] / 6};
				for (int k: range(j + 1, j + 7)) {
					int n = k < N ? k : 2 * N - k;
					(c[n] == 'L' ? tm[n] : t[c[n] == 'B' ? 0 : n]) += x;
				}
			}
			for (auto j: m)
				t[j.first] += j.second;
			d = move(t);
			m = move(tm);
		}
		printf("%f\n", d[N]);
	}
}


Measured memory_bytes: 2576
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def gcd3(a,b,c):
    m = gcd(a,b)
    h = gcd(m,c)
    return h

N = int(input())
count = 0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            l=gcd3(i,j,k)
            count += l
print(count)


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

const ll inf = 100000000000;

int main() {
  ll K;
  cin >> K;

  queue<ll> que;
  for (ll i = 1; i <= 9; i++) que.push(i);
  ll cnt = 0;
  ll p;

  while (cnt != K) {
    p = que.front(); que.pop();
    cnt++;
    if (p%10 == 0) {
      que.push(p*10);
      que.push(p*10+1);
    }
    else if (p%10 == 9) {
      que.push(p*10+8);
      que.push(p*10+9);
    }
    else {
      que.push(p*10+(p%10)-1);
      que.push(p*10+(p%10));
      que.push(p*10+(p%10)+1);
    }
  }
  cout << p << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <map>
using namespace std;


int main() {
    long long n;
    cin>>n;
    string s;
    cin>>s;
    map<char, long long> cnt;
    for(char c:s) {
        cnt[c] += 1;
    }
    long long ans = cnt['R'] * cnt['G'] * cnt['B'];
    for(long long i=0; i<n; ++i) {
        for(long long j=i+1; j<n; j++) {
            long long k = j + (j-i);
            if(k >= n) break;
            if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) --ans;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main(){

    int a,b,c,k;

    cin >>a>>b>>c>>k;

    int maior,flag,sum;

    maior = a;
    flag =0;
    if(b>maior){
        maior=b;
        flag=1;}
    if(c>maior){
        maior=c;
        flag=2;}
    
    for(int i=0;i<k;i++){
        maior*=2;
    }


    if(flag==0){
        sum = b+c+maior;
    }
    if(flag==1){
        sum=a+c+maior;
    }
    if(flag==2){
        sum = a+b+maior;
    }

    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int n,m,i,j,a[][]=new int[100][100],b[]=new int[100],c[]=new int[100];
		n=stdIn.nextInt();
		m=stdIn.nextInt();
		for(i=0;i<n;i++)for(j=0;j<m;j++)a[i][j]=stdIn.nextInt();
		for(i=0;i<m;i++)b[i]=stdIn.nextInt();
		for(i=0;i<n;i++)for(j=0;j<m;j++)c[i]+=a[i][j]*b[j];
		for(i=0;i<n;i++)System.out.println(c[i]);
	}
}


Measured memory_bytes: 40424
package main

import (
	"fmt"
	"io"
	"os"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func answer(reader io.Reader, writer io.Writer) {
	var n int
	_, _ = fmt.Fscan(reader, &n)
	count1 :=0
	count2 :=0
	count3 :=0
	h :=0
	t :=0
	s := make([]string, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscan(reader, &s[i])
		f :=0
		if s[i][0] == 'B' {
			h++
			f=1
		}
		if s[i][len(s[i])-1] == 'A' {
			t++
			f=1
		}
		if f==1 {
			count1++
		}
	}
	for i := 0; i < n; i++ {
		for j:=0;j < len(s[i])-1;j++ {
			if s[i][j] == 'A' {
				if s[i][j+1] == 'B' {
					count2++
				}
			}
		}
	}
	if t < h {
		count3 = t
	} else {
		count3 = h
	}
	if count3 > 0 && count1 == count3 {
		count3--
	}

	_, _ = fmt.Fprintf(writer, "%d", count2 + count3)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  vector<int>v;
  cin>>n;
  for(int i=1;i<=n;i++)
  v.push_back(i);
  do{
      for(int i=0;i<n;i++){
      if(i)
      cout<<' ';
    cout<<v[i];
    }cout<<endl;
  }while(next_permutation(v.begin(),v.end()));

return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cstring>
#include <cctype>
#include <numeric>
#include <cstdio>
#include <math.h>
#include <functional>
using namespace std;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define na(a, n) rep(i, n) cin >> a[i];
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
vb d(10);
int ans(int x)
{
    while (x)
    {
        if (d[x % 10])
            return 0;
        x /= 10;
    }
    return 1;
}
//ここからメイン
int main()
{
 int a,b,c,d;
  cin >>a>>b;
  cout<<(a*a-b);

  }
  

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

//関数
void display(vector<long> X){
    for(int i=0;i<X.size();i++){
        cout<<X.at(i)<<" ";
    }
    cout<<endl;
}
//main関数
int main() {
    
    
    //入力
    long N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    //計算
    vector<long> conzer(0);
    vector<long> conone(0);
    conone.push_back(0);
    
    bool zero=true;
    long count=0;
    for(int i=0;i<N;i++){
        if(S.at(i)=='0'){
            if(zero){
                count++;
            }else{
                conone.push_back(count);
                count=1;
                zero=true;
            }
        }else{
            if(!zero){
                count++;
            }else{
                conzer.push_back(count);
                count=1;
                zero=false;
            }
        }
    }
    
    if(zero){
        conzer.push_back(count);
        conone.push_back(0);
    }else{
        conone.push_back(count);
        conzer.push_back(0);
        conone.push_back(0);
    }
    
    
    
    long len=conzer.size();
   // display(conzer);
    //display(conone);
    
    long ans;
    if(len<=K){
        ans=N;
    }else{
        long sum=0;//初期和
        for(int i=0;i<K;i++){
            sum+=conzer.at(i);
            sum+=conone.at(i);
        }
        sum+=conone.at(K);
        ans=sum;
        
       // cout<<"hasiru"<<endl;
        for(int i=1;i<len+1-K;i++){//動ける範囲
            sum-=conzer.at(i-1);
            sum-=conone.at(i-1);
            sum+=conzer.at(i+K-1);
            sum+=conone.at(i+K);
           // cout<<sum<<endl;
            ans=max(ans,sum);
        }
    }
    
    
    //出力
    cout<<ans<<endl;
    
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll n;cin>>n;
  ll a[n];rep(i,0,n)cin>>a[i];

  reverse(a,a+n);

  rep(i,0,n){
    if(i!=n-1)cout<<a[i]<<" ";
    else out(a[i]);
  }


  return 0;
}



Measured memory_bytes: 3076
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const ll mod = 1000000007;
const ll INF = std::numeric_limits<long long>::max();
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define srep(i,s) rep(i,(ll)s.size())
#define vin(n,v) rep(i,n)cin>>v[i]
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define sz size
void YN(bool b) { cout << (b ? "YES" : "NO") << endl; }
void yn(bool b) { cout << (b ? "Yes" : "No") << endl; }
ll n, z, w,v[100000];
int main(){
	cin >> n >> z >> w;
	rep(i, n)cin >> v[i];
	if (n == 1)cout << abs(v[0] - w )<< endl;
	else {
		cout << max(abs(v[n - 1] - w), abs(v[n - 1] - v[n - 2])) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
string O, E;

void solve(){
	rep(i, O.size()){
		cout << O[i];
		if(i == E.size()) break;
		cout << E[i];
	}
	cout << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> O >> E;
		solve();
	return 0;
}


Measured memory_bytes: 256
/*
 * a.cpp
 *
 *  Created on: 2019/06/08
 *      Author: MEIP-users
 */




#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i, n-1){
		int a;
		cin >> a;
		v.at(a-1)++;
	}
	rep(i, n){
		cout << v.at(i) << endl;
	}

	return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main (){
	ll i,j,n;
	scanf ("%lld",&n);
	for (i=1;i<=3500;i++)
	{for (j=1;j<=3500;j++)
	{ll f1=n*i*j,f2=4*i*j-(i+j)*n;
	if (f2==0) {continue;}
	if (f1%f2==0&&f1/f2>0)
	{printf ("%lld %lld %lld\n",i,j,f1/f2);
	return 0;
	}
	}
	}
}

Measured memory_bytes: 256
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)


ll me(ll x,ll n )
{
  ll res=1;

  while(n)
  {
    if(n&1)
      res=res*x;

    x=x*x;

    n/=2;
  }

  return res;

}


int main() 
{ 
    ll p;
    ll n;
    lscf(n),lscf(p);

    unsigned ll g=1;

    map<ll,ll>m;

    ll x=p;

    for(ll i=2;i*i<=p;i++)
    {
        if(x%i==0)
        {
          while(x%i==0)
          x/=i,m[i]++;
        }
    }

    if(x>1)
      m[x]++;

    for(auto it:m)
    {
      if(it.S>=n)
      {
        ll z=me(it.F,it.S/n);

        g*=(z);
      }

    }

    cout<<g<<"\n";



}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 2e18 + 7;
const long long mod = 1e9 + 7;

int n;
long long k;
long long a[N];
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        /// freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> n >> k;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
    }
    sort(a, a + n);
    long long l = -inf, r = inf;
    while(r > l + 1){
        long long m = (l + r) / 2;
        /// ----------------------------------------------
        long long cnt = 0;
        for(int i = 0; i < n; i ++){
            if(a[i] > 0){
                int ll = -1, rr = n;
                while(rr > ll + 1){
                    int mm = (ll + rr) / 2;
                    if(a[i] * 1ll * a[mm] <= m){
                        ll = mm;
                    }
                    else{
                        rr = mm;
                    }
                }
                cnt += rr;
            }
            else{
                int ll = -1, rr = n;
                while(rr > ll + 1){
                    int mm = (ll + rr) / 2;
                    if(a[i] * 1ll * a[mm] > m){
                        ll = mm;
                    }
                    else{
                        rr = mm;
                    }
                }
                cnt += n - rr;
            }
        }
        for(int i = 0; i < n; i ++){
            if(a[i] * 1ll * a[i] <= m){
                cnt --;
            }
        }
        cnt /= 2;
        /// ----------------------------------------------
        if(cnt < k){
            l = m;
        }
        else{
            r = m;
        }
    }
    cout << r << "\n";
}



Measured memory_bytes: 1792
// g++ -I ~/Documents/AtCoder -std=gnu++14 -o test ~/Documents/AtCoder/test.cpp && ./test && rm test
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        ([]{int n; cin>>n; return n;}())
using namespace std;
using lint = int64_t;

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

    vector<vector<pair<int,bool>>>  to(N);
    rep( i, N-1 ) {
        int u=in-1, v=in-1; bool w=in%2;
        to[u].push_back( make_pair(v,w) );
        to[v].push_back( make_pair(u,w) );
    }

    vector<int> ans(N, -1); ans[0] = 0;
    queue <int> q;          q.push(0);
    while( !q.empty() ) {
        int u = q.front(); q.pop();
        for( pair<int,bool> p : to[u] ) {
            int v = p.first;
            if( ans[v] != -1 ) continue;
            ans[v] = ans[u] != p.second;
            q.push(v);
        }
    }

    rep( i, N ) cout << ans[i] << '\n';
}

Measured memory_bytes: 6784
#include<iostream>

using namespace std;

int main() {
	int n, y;
	bool x = false;

	cin >> n >> y; //10000円札、5000円札、1000円札

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n - i - j; k++) {
				if (10000 * i + 5000 * j + 1000 * k == y && i+ j + k == n) {
					cout << i << " " << j << " "<< k << endl;
					x = true;
					break;
				}
			}
			if (x) {
				break;
			}
		}
		if (x) {
			break;
		}
	}

	if (!x) {
		cout << -1 << " " << -1 << " " << -1 << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int face[7][7][4] = {
    {{0},{0},{0},{0},{0},{0},{0}},
    {{0},{0},{0,1,2,3},{0,1,3,5},{0,1,4,2},{0,1,5,4},{0}},
    {{0},{0,2,1,4},{0},{0,2,3,1},{0,2,4,6},{0},{0,2,6,3}},
    {{0},{0,3,1,2},{0,3,2,6},{0},{0},{0,3,5,1},{0,3,6,5}},
    {{0},{0,4,1,5},{0,4,2,1},{0},{0},{0,4,5,6},{0,4,6,2}},
    {{0},{0,5,1,3},{0},{0,5,3,6},{0,5,4,1},{0},{0,5,6,4}},
    {{0},{0},{0,6,2,4},{0,6,3,2},{0,6,4,5},{0,6,5,3},{0}}};
int dice[7];

int main(){
    int n,i,t,f;
    for(i=1;i<=6;i++) scanf("%d",&dice[i]);
    scanf("%d",&n);
    while(n--)
    {
       
        scanf("%d%d",&t,&f);
        for(i=1;i<=6;i++){
            if(t==dice[i]) t=i;
            if(f==dice[i]) f=i;
        }
        printf("%d\n",dice[face[t][f][3]]);
    }
    return 0;
}



Measured memory_bytes: 2128
#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()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------
int n,k,s;

int dfs(int prev,int pos,int sum)
{   
    int res=0;
    if(pos==k) return sum==s;
    for(int i=prev+1;i<=n;i++){
        res+=dfs(i,pos+1,sum+i);
    }
    return res;
}   

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(cin>>n>>k>>s,n){
        cout<<dfs(0,0,0)<<endl;
    }
}



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

int main() {
	int N = 0;
	int M = 0;
	int a[10000] = { 0 };
	int b[10000] = { 0 };
	int n = 0;

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

	for (int i = 0; i < N - 1; i++) {
		if (a[i] > a[i + 1]) {
			M++;
		}
	}

	cout << M+1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 2e18L
int main()
{ ll n,W;
 cin>>n>>W;
 vector<ll> weight(n);
 vector<ll> val(n);
 for(int i=0;i<n;i++)
 {
     cin>>weight[i]>>val[i]; 
 }
 ll sum=0;
 for(auto x: val)
 {
     sum+=x;
 }
 vector<ll> dp(sum+1,INF);
 dp[0]=0;
 for(ll i=0;i<n;i++)
 {
     for(ll j=sum-val[i];j>=0;j--)
     {
         dp[j+val[i]]=min(dp[j+val[i]],dp[j]+weight[i]);
     }
 }
 ll ans=0;
 for(ll i=0;i<=sum;i++)
 {
     if(dp[i]<=W)
     {
         ans=max(ans,i);
     }
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 3964
/**
 * Author: AcFunction
 * Date:   2019-02-24 19:56:49
 * Email:  3486942970@qq.com
**/

#include <bits/stdc++.h>
#define ll long long

using namespace std;
char s[10005]; int a[1005]; 
int main() {
  cin >> s; 
  for(int i = 0; i < 9; i++) a[i] = s[i] - '0'; 
  int y = a[0] * 1000 + a[1] * 100 + a[2] * 10 +a[3]; 
int m = a[5] * 10 + a[6]; 
int d = a[8] * 10 + a[9]; 
  if(y < 2019) { cout << "Heisei" << endl; }
  else if(y > 2019) { cout << "TBD" << endl; }
  else if(m < 4) { cout << "Heisei" << endl; }
  else if(m > 4) { cout << "TBD" << endl; }
  else if(d <= 30) { cout << "Heisei" << endl; }
  else cout << "TBD" << endl; 
  return 0; 
}

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

long long GCD(long long m, long long n){
    if(n == 0) return m;
    else return GCD(n, m % n);
}

signed main(){
    int tt;
    cin >> tt;
    while(tt--){
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        if(a < b || d < b){
            cout << "No" << endl;
            continue;
        }
        if(b - c <= 1){
            cout << "Yes" << endl;
            continue;
        }
        ll t = GCD(b, d);
        if(t == 1){
            cout << "No" << endl;
            continue;
        }
        if(a % t <= c && b - c <= t){
            cout << "Yes" << endl;
            continue;
        }else{
            cout << "No" << endl;
            continue;
        }
    }
    return 0;
}

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

const int MOD = 1e9+7;
int add(int a, int b){return ((ll)a + (ll)b)%MOD;}
int mul(int a, int b){return ((ll)a * (ll)b)%MOD;}

void solve(){
  int n; cin >> n;
  set<string> ans;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    ans.insert(s);
  }
  cout << ans.size() << '\n';
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}


Measured memory_bytes: 19100
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,p,q;
    cin>>n;

    if(n%1000==0)
    {
      cout<<"0"<<endl;
      return 0;
    }

   else if(n<1000) cout<<1000-n<<endl;
   else if(n<2000) cout<<2000-n<<endl;
   else if(n<3000) cout<<3000-n<<endl;
   else if(n<4000) cout<<4000-n<<endl;
   else if(n<5000) cout<<5000-n<<endl;
   else if(n<6000) cout<<6000-n<<endl;
   else if(n<7000) cout<<7000-n<<endl;
   else if(n<8000) cout<<8000-n<<endl;
   else if(n<9000) cout<<9000-n<<endl;
   else if(n<10000) cout<<10000-n<<endl;

   return 0;

}


Measured memory_bytes: 3596
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C++ (GCC 9.2.1)
*/

#include <bits/stdc++.h>
using namespace std;

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod int(1e9+7)

// fact(n)
template <typename T>
T fact(T n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// nCr(n, r)
template <typename T>
T nCr(T n, T r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (nCr(n - 1, r - 1) + nCr(n - 1, r));
}

// swap(&a, &b);
template <typename T>
void swap(T *a, T *b){
	T tmp;
	tmp = *a;	*a = *b;	*b = tmp;
	return;
}

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

// lcm(a, b)
template <typename T>
T lcm(T a,T b){
	return a / gcd(a,b) * b;
}

// divisor(type n)
template <typename T>
vector<T> divisor(T n)
{
  vector<T> ret;
  for(T i = 1; i * i <= n; i++)
	{
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

// eratosthenes(type n)
template <typename T>
vector<T> eratosthenes(T n){
	vector<bool> is_prime(n + 2, true);
	vector<T> primes;

	for (T i = 2; i <= n; i++)
	{
		if(is_prime[i]){
			for (T j = 2 * i; j <= n; j += i)	is_prime[j] = false;
			primes.push_back(i);
		}
	}
	return primes;
}

// vector scanner
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
	for(T& x : vec)	is >> x;
	return is;
}

int main(int argc, char const *argv[])
{
	// DON'T CHANGE
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	// here
	int n, x, t;
	cin >> n >> x >> t;
	OUT(t * ((n + x - 1) / x)) BR;
	RET;
}


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

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

    int sum = a+b;
    int diff = a-b;
    int prod = a*b;

    if (sum > diff && sum > prod)
    {
        cout << sum << endl;
        return 0;
    }

    if (diff > prod)
    {
        cout << diff << endl;
        return 0;
    }
    
    cout << prod << endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool used[150];
    memset(used, false, sizeof(used));
    int point = -1;
    string ans = "";
    for(int i = 0; i < s.size(); i++) used[s[i]] = true;
    if(s.size() == 26)
    {
        if(s == "zyxwvutsrqponmlkjihgfedcba")
        {
            cout << -1 << endl;
            return 0;
        }
        string t = s;
        next_permutation(t.begin(), t.end());
        for(int i = 0; i < s.size(); i++)
        {
            ans += t[i];
            if(s[i] == t[i]) continue;
            cout << ans << endl;
            return 0;
        }
    }
    else
    {
        for(int i = 97; i <= 122; i++)
        {
            if(used[i]) continue;
            s += (char)i;
            cout << s << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2]){
    cout<<"Yes"<<endl;
  }else if(s[1]==s[2]&&s[2]==s[3]){
    cout<<"Yes"<<endl;
  }else cout<<"No"<<endl;    
}


Measured memory_bytes: 256
import sys
# gcd
# from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


A, B, T = mi()

print(B * (T // A))

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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 200010, M = 1010;

int n;
LL m;
LL a[N], b[N];

bool check(LL x)
{
	LL cnt = 0;
	for (int i = 0; i < n; i ++ )
		if (a[i] * b[i] > x)
			cnt += a[i] - x / b[i];
	return cnt <= m;
}

int main()
{
	scanf("%d%lld", &n, &m);
	for (int i = 0; i < n; i ++ ) scanf("%lld", &a[i]);
	for (int i = 0; i < n; i ++ ) scanf("%lld", &b[i]);
	sort(a, a + n);
	sort(b, b + n);
	reverse(a, a + n);
	
	LL l = 0LL, r = 1e12 + 10;
	while (l < r)
	{
		LL mid = l + r >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1LL;
	}
	printf("%lld\n", r);
    return 0;
}

Measured memory_bytes: 6924
using System;

namespace Count
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] nums = new int[n];
            for (int i = 0; i < n; ++i)
            {
                nums[i] = int.Parse(input[i]);
            }

            int times = int.Parse(Console.ReadLine());
            int[] ans = new int[times]; 
            for (int i = 0; i < times; ++i)
            {
                string[] temp = Console.ReadLine().Split(' ');
                int idx1 = int.Parse(temp[0]);
                int idx2 = int.Parse(temp[1]);
                int num = int.Parse(temp[2]);

                int count = 0;
                for (int j = idx1; j < idx2; ++j)
                {
                    if (nums[j] == num)
                    {
                        ++count;
                    }
                }
                ans[i] = count;
            }

            for (int i = 0; i < times; ++i)
            {
                Console.WriteLine(ans[i]);
            }
        }
    }
}



Measured memory_bytes: 17968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;


int main(){
 VI n(3);
  cin >> n.at(0) >> n.at(1) >> n.at(2);
  sort(n.begin(),n.end());
  int m;
  m=n.at(2)*2-n.at(0)-n.at(1);
  if(m%2==0){
    cout << m/2 << endl;
  }
    else{
      cout << (m+1)/2+1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
//using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
////////////////

void solve(){
  inl(N);
  vl A(N); in(A);
  ll sum = 0; each(x , A) sum += x;
  ll ans = sum;
  ll cur = 0;
  rep(i , N){
    cur += A[i];
    amin(ans , abs(cur - (sum - cur) ));
  }
  out(ans);

}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;

int ans;

signed main(){

    int n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d>>s;
    int f=1,f2=0;
    
    int co=0;
    if(c<d){
        for(int i=a-1;i<d;i++){
            if(i==n-1){continue;}
            if(s[i]=='#' && s[i+1]=='#'){
                f=0;
                break;
            }
        }
        if(f)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;
    }
    else{
        for(int i=a-1;i<d;i++){
            if(i==n-1){continue;}
            if(s[i]=='#' && s[i+1]=='#'){
                f=0;
                break;
            }
        }
        for(int i=b-1;i<d;i++){
            if(i==n-1){continue;}
            if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
                f2=1;
            }
        }
        if(f && f2)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


}


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


const int combination_max=400000+1000;
const int combination_modulo=998244353;
vector<int64_t> factorials(combination_max);
vector<int64_t> factorials_inv(combination_max);
vector<int64_t> inverse(combination_max);
int combination_mod(int n, int k);
int prepare_combination_mod();

int main()
{
	int n,m,k;
	cin >> n >> m >> k;

	int64_t total=0;
	prepare_combination_mod();

	vector<int64_t> mminus1pow(n);
	mminus1pow[0]=1;
	for (int i=1;i<n;++i)
	{
		mminus1pow[i]=mminus1pow[i-1]*(m-1)%combination_modulo;
	}

	for (int i=0;i<=k;++i)
	{
		int64_t add=m*mminus1pow[n-1-i]%combination_modulo;
		add*=combination_mod(n-1,i);
		add%=combination_modulo;
		//fprintf(stderr,"%d %lld\n",i,add);
		total+=add;
		total%=combination_modulo;
	}
	cout << total << endl;


}

int prepare_combination_mod()
{
	factorials[0]=1;
	factorials[1]=1;
	factorials_inv[0]=1;
	factorials_inv[1]=1;
	inverse[1]=1;
	for (int i=2;i<combination_max;++i)
	{
		factorials[i]=factorials[i-1]*i%combination_modulo;
		inverse[i]=combination_modulo - inverse[combination_modulo%i]*(combination_modulo/i)%combination_modulo;
		factorials_inv[i]=factorials_inv[i-1]*inverse[i]%combination_modulo;
	}
	return 0;
}

int combination_mod(int n, int k)
{
	return factorials[n]*(factorials_inv[k]*factorials_inv[n-k]%combination_modulo)%combination_modulo;
}







Measured memory_bytes: 14344
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)

[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;

struct Edge {
  int to, from, cost;
  Edge(int t, int f, int c) : to(t), from(f), cost(c) {}
};

int main() {

  int n, m;
  cin >> n >> m;
  vector<Edge> es;
  vector<vector<int>> g(n, vector<int>(n, INF));
  rep(i, 0, m) {
    int f, t, c;
    cin >> f >> t >> c;
    --f, --t;
    es.emplace_back(f, t, c);
    g[f][t] = c;
    g[t][f] = c;
  }
  rep(i, 0, n) g[i][i] = 0;
  rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) g[i][j] =
    min(g[i][j], g[i][k] + g[k][j]);

  int ans = 0;
  rep(i, 0, m) if (g[es[i].from][es[i].to] != es[i].cost)++ ans;
  cout << ans << endl;
  return 0;
}


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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

void calc(vector<bool> &ab,string a,string b){
  rep(i,sz(a)+1){
    bool flag=true;
    rep(j,sz(b)){
      if(i+j>=sz(a))  break;
      if(a.at(i+j)=='?' || b.at(j)=='?')  continue;
      if(a.at(i+j)!=b.at(j)){
        flag=false;
        break;
      }
    }
    if(!flag) ab.at(i)=false;
  }
}

int solve(string a,string b,string c){
  vector<bool> ab(sz(a)+1,true);
  vector<bool> ac(sz(a)+1,true);
  vector<bool> bc(sz(b)+1,true);
  calc(ab,a,b);
  calc(ac,a,c);
  calc(bc,b,c);

  int ans=7000;
  rep(i,sz(a)+1){
    if(!ab.at(i)) continue;
    REP(j,i,sz(a)+sz(b)+1){
      int tmp=min(j,sz(a));
      if(!ac.at(tmp)) continue;
      tmp=min(j-i,sz(b));
      if(!bc.at(tmp)) continue;

      tmp=max({sz(a),i+sz(b),j+sz(c)});
      chmin(ans,tmp);
    }
  }
  return ans;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  string a,b,c;
  cin >> a >> b >> c;

  int ans=7000;
  chmin(ans,solve(a,b,c));
  chmin(ans,solve(a,c,b));
  chmin(ans,solve(b,a,c));
  chmin(ans,solve(b,c,a));
  chmin(ans,solve(c,a,b));
  chmin(ans,solve(c,b,a));
  cout << ans << endl;

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int t = 0, x = 0, y = 0;
  bool can = true;
  for (int i = 0; i < N; i++) {
    int t_next, x_next, y_next;
    cin >> t_next >> x_next >> y_next;
    int time = t_next - t;
    int distance = abs(x - x_next) + abs(y - y_next);
    if (time < distance || (time - distance) % 2 != 0) can = false;
    t = t_next;
    x = x_next;
    y = y_next;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
N, K = inpl()

if K == 0:
    print(N*N)
    exit()

ans = 0
for b in range(K+1, N+1):
    d, m = divmod(N, b)
    ans += d*(b-K)
    ans += max(0, m+1-K)

print(ans)

Measured memory_bytes: 3060
using namespace std;
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define debug(x) cout << #x <<" = " << x << endl
void solve()
{
  ll n,m,k,i,j,result=0;
  int a[200010]={0};
  string s,t;
  cin >> s;
  cin >> t;
  n = s.size();
  m = t.size();
  result = 9999;
  for(i=0;i<n-m+1;i++){
    k=0;
    for(j=0;j<m;j++){
      if(s[i+j]!=t[j]) k++;
    }
    result = min(result,k);
  }
  cout << result << endl;
}
int main()
{
    
FASTIO
 long long int t;
 t=1;
 while(t--)
  solve();
  return 0;
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int N; 
	cin >> N;
	int arr[N] = {0};
	REP(i, 0, N) cin >> arr[i];
	
	int next = arr[0];
	int i = 1;
	while(i < N && next != 2){
		//cout << i << " " << next << endl;
		next = arr[next-1];
		++i;
		
	}
	if(i == N) cout << -1;
	else cout << i;

}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int n,m;
  bool x = false;
  while(cin >>n>>m,n||m){
    if(x) cout <<endl;
    x = true;
    bool f = false;
    for(int i=n; i<=m; i++){
      if(i%400 == 0){cout <<i<<endl;f = true;}
      else if(i%100 == 0) continue;
      else if(i%4 == 0){cout <<i<<endl;f = true;}
    }
    if(!f) cout <<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let Y: i32 = read();
    let mut ans = None;

    'outer: for x in 0..n+1 {
        for y in 0..n+1-x {
            let z = n - x - y;
            if 10000*x+5000*y+1000*z == Y {
                ans = Some((x, y, z));
                break 'outer;
            }
        }
    }

    let (x, y, z) = ans.unwrap_or((-1, -1, -1));
    println!("{} {} {}", x, y, z);
}


Measured memory_bytes: 4352
h,w = map(int,input().split())
s = [list(map(int,input().split())) for i in range(h)]
t = [s,[],0]

def migrate1(i,t,w):
    s1 = t[0]
    for j in range(w-1):
        if s1[i][j] % 2 == 0:
            continue
        else:
            t[1].append(str(i+1)+" "+str(j+1)+" "+str(i+1)+" "+str(j+2))
            t[2] += 1
            s1[i][j] -= 1
            s1[i][j+1] += 1
    if s1[i][w-1] % 2 == 1:
        t[1].append(str(i+1)+" "+str(w)+" "+str(i+2)+ " "+str(w))
        t[2] += 1
        s1[i][w-1] -= 1
        s1[i+1][w-1] += 1
    return t

def migrate2(h,t):
    s1 = t[0]
    for j in range(w-1):
        if s1[h-1][j] % 2 == 0:
            continue
        else:
            t[1].append(str(h)+" "+str(j+1)+" "+str(h)+" "+str(j+2))
            t[2] += 1
            s1[h-1][j] -= 1
            s1[h-1][j+1] += 1
    return t


for i in range(h-1):
    t = migrate1(i,t,w)

t = migrate2(h,t)

print(t[2])
for i in range(len(t[1])):
    print(t[1][i])


Measured memory_bytes: 16472
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(void){
    int n,m,a[1100],b[1100],c[1100],d[110][110],inf = 1<<29;
    cin >> n >> m;
    
    for(int i = 0;i < 110;i++){
        for(int j = 0;j < 110;j++) d[i][j] = inf;
        d[i][i] = 0;
    }
    
    for(int i = 0;i < m;i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--,b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    
    for(int k = 0;k < n;k++)for(int i = 0;i < n;i++)for(int j = 0;j < n;j++)
    d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
    
    int ans = 0;
    for(int i = 0;i < m;i++){
        if(d[a[i]][b[i]] < c[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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


template <typename T>
struct BIT{
    int n;
    vector<T> d;

    BIT(int sz){
        n = sz+10;
        d.resize(n);
    }

    void add(int i, T x){

        while(i<=n){
            d[i] += x;
            i += i&-i;
        }
    }

    T getSum(int i){
        T ret = 0;

        while(i>0){
            ret += d[i];
            i -= i&-i;
        }
        return ret;
    }

    T getSum(int a, int b){
        return getSum(b-1) - getSum(a-1);
    }
};


int main(){
    ll N; cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];

    ll ng = 0, ok = 1e9;
    while(ok-ng>1){
        ll mid = (ng+ok)/2;

        ll sum = 0, num = 0;
        BIT<ll> bit(N*2+10);
        bit.add(N+1,1);
        rep(i,N){
            if(a[i]<=mid) sum++;
            else sum--;
            num += bit.getSum(1,sum+N+1);
            bit.add(sum+N+1,1);
        }
        if (num > (N+1)*N/2/2) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;
}

Measured memory_bytes: 5600
L = list(input())
L = [int(L[i]) for i in range(len(L))]
n = 4

for mask in range(2**n):
    total = L[0]
    s = str(L[0])
    for i in range(1, n):
        num = L[i]
        # maskのi番目にフラグが立っているかどうか
        if mask & (1 << i):
            total += num
            s += '+' + str(num)
        else:
            total -= num
            s += '-' + str(num)
    if total == 7:
        print(s+'=7')
        exit()


Measured memory_bytes: 62024
N = int(input())
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
    
print(num2alpha(N).lower())

Measured memory_bytes: 9172
#include <iostream>

using namespace std;

int dis(int x){ //xを10で割っていくと同時にxのmodを求める
    int g, sum;
    sum = 0;
    while(x != 0){
        g = x % 10;
        sum += g;
        x /= 10;
    }
    return sum;
}

int main(){ //1 <= N 10000, 1 <= A <= B <= 36
    int n, a, b, sum, num, count;
    sum = 0;
    count = 1;
    cin >> n >> a >> b;
    while(count <= n){
        num = dis(count);
        if(a <= num && num <= b){
            sum += count;
        }
        count++;
    }
    printf("%d\n", sum);
    return 0;
}


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

 int main(void)
 {
     ll n,m;
     cin>>n>>m;
     if(2*n>m){
         cout<<m/2<<endl;
         return 0;
     }
     else {
         cout<<n+(m-2*n)/4<<endl;
         return 0;
     }
     return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;
#define MAX 20000000

int H,A[MAX+1];

int parent(int i){return i/2;}
int left(int i){return i*2;}
int right(int i){return i*2+1;}

void maxheapify(int i){
  int l, r ,largest;
  l=2*i;
  r=2*i+1;

  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;

  if(largest !=i){
    swap(A[i],A[largest]);
    maxheapify(largest);
  }
}

int main(){
  cin>>H;
  for(int i=1;i<=H;i++){
    cin>> A[i];
  }
  for(int i=H/2;i>=1;i--) maxheapify(i);
  for(int i=1;i<=H;i++){
    cout << " " << A[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4992