akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

ans = float('inf')
# Aにする群、Bにする群、Cにする群、使わない群を全通り
j = 0
for P in permutations(L):
  S = [P[0]]
  for i in range(1, N):
    S.append(P[i] + S[-1])
  for ia in range(N-2):
    a = S[ia]
    for ib in range(ia+1, N-1):
      b = S[ib] - S[ia]
      for ic in range(ib+1, N):
        c = S[ic] - S[ib]
        tmp = (ic-2)*10 + abs(A-a) + abs(B-b) + abs(C-c)
        ans = ans if ans < tmp else tmp
print(ans)

Measured memory_bytes: 45296
N, M = map(int, input().split())
G = [[float('inf')] * N for i in range(N)]

Edge = []
for i in range(M):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    Edge.append([a, b, c])
    G[a][b] = c
    G[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][i] = 0
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])

need = 0
for a, b, c in Edge:
    for s in range(N):
        if G[s][a] + c == G[s][b]:
            need += 1
            break

print(M - need)


Measured memory_bytes: 3444
#include <stdio.h>
#define INF 200000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100
int n;
int color[MAX];
int M[MAX][MAX];
int d[MAX];
int p[MAX];
int prim(){
        int u,Minv;
        int i,v;
        int sum=0;
        for(i=0; i<n; i++) {
                color[i]=WHITE;
                d[i]=INF;
                p[i]=-1;

        }
        d[0]=0;
        while(1) {
                Minv=INF;
                for(i=0; i<n; i++) {
                        if(color[i]!=BLACK &&d[i]<Minv) {
                                Minv=d[i];
                                u=i;
                        }
                }

                if(Minv==INF) {
                        break;
                }
                color[u]=BLACK;
                for(v=0; v<n; v++) {
                        if(color[v]!=BLACK && M[u][v]!=INF) {
                                if(M[u][v]<d[v]) {
                                        d[v]=M[u][v];
                                        p[v]=u;
                                        color[v]=GRAY;
                                }
                        }
                }
        }
        for(i=0; i<n; i++) {
                if(p[i]!=-1) {
                        sum+=M[i][p[i]];
                }
        }

        return sum;

}
int main(){
        int i,j;

        scanf ("%d",&n);
        for(i=0; i<n; i++) {
                for(j=0; j<n; j++) {
                        scanf("%d",&M[i][j]);
                        if(M[i][j]==-1) {
                                M[i][j]=INF;
                        }
                }
        }


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

        return 0;
}



Measured memory_bytes: 2112
#if defined(LOCAL)
#define PROBLEM_NAME "d"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)

const l MAX_PRIME = 55556;
// returns v[i] = smallest prime divisor of i or 1
vl sieve_primes(vl& primes) {
  vl next_div(MAX_PRIME, 1);
  for (l i = 2; i < MAX_PRIME; i++) {
    if (next_div[i] != 1) continue;
    primes.emplace_back(i);
    for (l j = i; j < MAX_PRIME; j += i) if (next_div[j] == 1) next_div[j] = i;
  }
  return next_div;
}

// in asc order
vl factorize_to_primes(l n, vl& primes, vl& next_div) {
  auto p = primes.begin();
  vl result;
  while (n >= MAX_PRIME and p != primes.end()) {
    while (n % *p == 0) { result.emplace_back(*p); n /= *p; }
    p++;
  }
  if (n >= MAX_PRIME) {
    result.emplace_back(n);
    n = 1;
  }
  while (n != 1) {
    result.emplace_back(next_div[n]);
    n /= next_div[n];
  }
  return result;
}

// TODO: add snippet
bool is_prime(l n, vl const& primes) {
  auto p = primes.begin();
  while (p != primes.end() and ((*p) * (*p)) <= n) {
    if (n % *p == 0) return n == *p;
    p++;
  }
  return true;
}

void solve(istream& cin, ostream& cout) {
  l n; cin >> n;
  vl primes;
  sieve_primes(primes);
  vl v;
  for (auto p : primes) {
    if (p % 5 == 1) {
      v.emplace_back(p);
      if (v.size() == n) break;
    }
  }
  F(i, 0, n) {
    if (i) cout << ' ';
    cout << v[i];
  }
  cout << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 768
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

permutation = list(itertools.permutations(range(1, n+1), n))
idx1 = permutation.index(p)
idx2 = permutation.index(q)
print(abs(idx1 - idx2))

Measured memory_bytes: 71260
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;

vector<int> data(51,-1);

int root(int x){
  if(data[x] == -1)return x;
  else return data[x] = root(data[x]);
}

bool same(int x,int y){
  if(root(x) == root(y))return 1;
  else return 0;
}

int unite(int x,int y){
  if(!same(x,y))data[root(x)] = y;
  return 0;
}


int main(){
  int N,M,ans=0;
  cin >> N >> M;
  int a[M],b[M];
  FOR(i,0,M)cin >> a[i] >> b[i];
  FOR(i,0,M){
    FOR(j,1,51)data[j] = -1;
    FOR(j,0,M)if(i != j)unite(a[j],b[j]);
    if(root(a[i]) != root(b[i]))ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int n,k,i,j;
  int b[999];
  for(;scanf("%d%d",&n,&k),n;)
    {
      for(i=0;i<k;i++)
	scanf("%d",&b[i]);
      for(;n--;)
	for(j=0;j<k;j++)
	  scanf("%d",&i),b[j]-=i;
      for(i=0;i<k-1;i++)
	if(b[i]<0)break;
      puts(b[i]<0?"No":"Yes");
    }
  
  
  exit(0);      
}

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

#define ll long long 
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vl vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rem(i,m,n) for(ll i=(m);i>(n);i--) 

const ll INF = 1e+10;


void solve()
{
   ll n,l;
   cin>>n>>l;
   ll k;
   k= (l-(2*n));
   if(((((k%2)+2)%2) == 0) && ((k/2) <= n) && (k>=0))
   {
       cout<<"Yes";
   }
   else
   {
       cout<<"No";
   }
   
}


int main()
{
    fastio;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    
    
    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif


    return 0;
}



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

int main(){
int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(b<=c||d<=a) cout << 0 << endl;
  else if(a<=c&&d<=b) cout << d-c << endl;
  else if(c<=a&&b<=d) cout << b-a << endl;
  else if(b<=d) cout << b-c << endl;
  else if(d<=b) cout << d-a << endl;
    

	return 0;
}


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

#define rep(i,a,b) for(int i=a;i<(b);i++)
#define trav(a,x) for(auto & a :x)
#define all(x) begin(x),end(x)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vpii vector<pii>
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;


const int M=1e9+7;

/*
ll powermod(ll x, ll y, ll p)  
{  
    ll res = 1;    
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
*/


void solve()
{ 

ll n;
cin>>n;

string res = "";

	while (n > 0)
	{
		
		int index = (n - 1) % 26;
		res = char(index + 'a') + res;
		n = (n - 1) / 26;
	}
	
	cout<<res;
}

int main() 
{   
    ios::sync_with_stdio(0);
	cin.tie(0);
  
   int test=1;
  // cin>>test;
   while(test--)
    {
	  solve();
	  cout<<"\n";
    }
  return 0;
}

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

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<class T> vector<T> read_vector(sint n) {
	vector<T> vs;
	for (sint i = 0; i < n; ++i) {
		vs.push_back(read<T>());
	}
	return vs;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T> void write(vector<T> const& ts) {
	if (ts.size() > 0) {
		cout << ts[0];
	}
	for (size_t i = 1; i < ts.size(); ++i) {
		cout << ' ' << ts[i];
	}
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto const N = read<sint>();
	for (sint i = 1; i < 10; ++i) {
		if (N % i == 0 && N / i < 10) {
			writeln("Yes");
			return;
		}
	}
	writeln("No");
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int h = scan.nextInt();
    int w = scan.nextInt();
    int sum = 0;
    ArrayList<ArrayList<Character>> a = new ArrayList<ArrayList<Character>>();
    for (int i=0;i<h;i++){
      String g = scan.next();
      ArrayList<Character> b = new ArrayList<Character>();
      for (int j=0;j<w;j++){
        b.add(g.charAt(j));
        if (g.charAt(j) == '.'){
          sum += 1;
        }
      }
      a.add(b);
    }

    boolean[][] c = new boolean[h][w];
    int[][] mm = new int[h][w];
    for (int i=0;i<h;i++){
      for (int j=0;j<w;j++){
        c[i][j] = false;
        mm[i][j] = Integer.MAX_VALUE;
      }
    }

    mm[0][0] = 1;

    ArrayList<Integer> m = new ArrayList<Integer>();
    m = find(a,h-1,w-1,0,0,1,m,c,mm);
    if (m.size() == 0){
      System.out.println(-1);
      return;
    }
    Collections.sort(m);
    System.out.println(sum - m.get(0));

  }

  static ArrayList<Integer> find(ArrayList<ArrayList<Character>> g, int target_h, int target_w, int current_h, int current_w, int count, ArrayList<Integer> ret, boolean[][] pp, int[][] mm){
    if ((target_h == current_h) && (target_w == current_w)){
      ret.add(count);
      return ret;
    }

    ArrayList<Character> a = g.get(current_h);

    if (current_h < target_h){
      ArrayList<Character> b2 = g.get(current_h+1);
      if ((pp[current_h+1][current_w] != true) && (b2.get(current_w) != '#')){
        pp[current_h][current_w] = true;

        if (count+1 < mm[current_h+1][current_w]){
          mm[current_h+1][current_w] = count + 1;
          ret = find(g,target_h,target_w,current_h+1,current_w,count+1,ret,pp,mm);
        }
        
        pp[current_h][current_w] = false;
      }
    }

    if (current_w < target_w){
      if ((pp[current_h][current_w+1] != true) &&(a.get(current_w + 1) != '#')){
        pp[current_h][current_w] = true;
        if (count+1 < mm[current_h][current_w+1]){
          mm[current_h][current_w+1] = count + 1;
          ret = find(g,target_h,target_w,current_h,current_w+1,count+1,ret,pp,mm);
        }
        pp[current_h][current_w] = false;
      }
    }

    if (current_h > 0){
      ArrayList<Character> b1 = g.get(current_h-1);
      if ( (pp[current_h-1][current_w] != true) && (b1.get(current_w) != '#')){
        pp[current_h][current_w] = true;
        if (count+1 < mm[current_h-1][current_w]){
          mm[current_h-1][current_w] = count + 1;
          ret = find(g,target_h,target_w,current_h-1,current_w,count+1,ret,pp,mm);
        }
        pp[current_h][current_w] = false;
      }
    }

    if (current_w > 0){
      if ((pp[current_h][current_w-1] != true) && (a.get(current_w - 1) != '#')){
        pp[current_h][current_w] = true;
        if (count+1 < mm[target_h][current_w-1]){
          mm[current_h][current_w-1] = count + 1;
          ret = find(g,target_h,target_w,current_h,current_w-1,count+1,ret,pp,mm);
        }
        pp[current_h][current_w] = false;
      }
    }

    return ret;

  }

}


Measured memory_bytes: 41060
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {     
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    vector<int> water(31, 0);
    water[0] = 1;
    for (int i = 0; i < 30; i++) {
        for (int j = 30; j >= 0; j--) {
            if (j + a <= 30) water[j + a] = max(water[j], water[j + a]);
            if (j + b <= 30) water[j + b] = max(water[j], water[j + b]);
        }
    }
    pair<int, int> p = make_pair(1, 0);
    for (int i = 0; i <= f / 100; i++) {
        if (water[i] == 0) continue;
        int max_sugar = i * e;
        vector<int> sugar(max_sugar + 1, 0);
        sugar[0] = 1;
        for (int j = 0; j < max_sugar; j++) {
            for (int k = max_sugar; k >= 0; k--) {
                if (k + c <= max_sugar) sugar[k + c] = max(sugar[k], sugar[k + c]);
                if (k + d <= max_sugar) sugar[k + d] = max(sugar[k], sugar[k + d]);
            }
        }
        for (int j = min(max_sugar, f - i * 100); j >= 0; j--) {
            if (sugar[j] > 0 && p.second * (i * 100 + j) < p.first * j) {
                p = make_pair(i * 100 + j, j);
                break;
            }
        }
    }
    if (p.second == 0) {
        cout << a * 100 << " " << 0 << endl;
        return 0;
    }
    cout << p.first << " " << p.second << endl;
}




Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
 
z = list(range(K+1))
ans = []
 
for i in z:
  s_z = S - i
  if s_z < 0:
    pass
  elif K < s_z:
    if (K + 1) > (s_z - K):
      ans.append(2*K - s_z + 1)
  else:
    ans.append(s_z + 1)
 
print(sum(ans))

Measured memory_bytes: 3188
N,X=map(int,input().split())
A=list(map(int,input().split()))
ans=max(A[0]-X,0)
A[0]=min(X,A[0])
for i in range(1,N):
  a=A[i-1]
  b=A[i]
  if a+b>X:
    ans+=b-(X-a)
    A[i]=X-a
print(ans)

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

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> u(n);
    vector<int> v(n);
    vector<int> w(n);
    int i,j;
    vector<vector<pair<int,int>>> tree(n,vector<pair<int,int>>());
    for(i = 0;i < n-1;++i){
        cin >> u.at(i) >> v.at(i) >> w.at(i);
        tree.at(u.at(i)-1).emplace_back(v.at(i)-1,w.at(i));
        tree.at(v.at(i)-1).emplace_back(u.at(i)-1,w.at(i));
    }
    vector<int> visit(n,-1);
    stack<int> st;
    visit.at(0) = 0;
    for(i = 0;i < tree.at(0).size();++i){
        st.push(tree.at(0).at(i).first);
        if(tree.at(0).at(i).second%2 == 0){
            visit.at(tree.at(0).at(i).first) = 0;
        }else{
            visit.at(tree.at(0).at(i).first) = 1;
        }
    }
    while(!st.empty()){
        int now = st.top();
        st.pop();
        for(i = 0;i < tree.at(now).size();++i){
            if(visit.at(tree.at(now).at(i).first) == -1){
                visit.at(tree.at(now).at(i).first) = (visit.at(now) + tree.at(now).at(i).second)%2;
                st.push(tree.at(now).at(i).first);
            }
        }
    }
    for(i = 0;i < n;++i){
        cout << visit.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 7936
X,Y,A,B,C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

l = p[:X] + q[:Y] + r
print(sum(sorted(l, reverse=True)[:X+Y]))


Measured memory_bytes: 29388
#include <stdio.h>
#include<string.h>


int main ()
{
int A,B,index;
char S[11],T[11],U[11];

scanf("%s %s", &S, &T);
scanf("%d %d", &A, &B);
scanf("%s", &U);


if (strcmp(U,S)==0){
	A--;
	printf("%d %d", A, B);

}
else if(strcmp(U,T)==0){
B--;
printf("%d %d", A, B);

}


	return 0;
	}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
struct UnionFind {
    VI d;
    UnionFind(int n = 0): d(n,-1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x,int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
int deg[100005];
VI to[100005];

struct mint {
  LL x; // typedef long long ll;
  mint(LL x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(LL t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n) {
    if(n == 0) return 1;
    mint x = f(n/2);
    x *= x;
    if(n%2 == 1) x *= 2;
    return x;
}

mint choose(int n,int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main() {
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int cnt = 0;
    int a = h1 * 60 + m1;
    int b = h2 * 60 + m2;

    int u = abs(a-b);

    cout << u - k << endl;
}


Measured memory_bytes: 5984
n,k = map(int,input().split())
s = list(input())
if s[k-1]=='A':
    s[k-1]="a"
if s[k-1]=='B':
    s[k-1]='b'
if s[k-1]=='C':
    s[k-1]='c'
print(''.join(s))

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する


int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int> > e(N);
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    bool flag = true;
    rep(i,0,N){
        if(e[i].size() % 2 != 0) flag = false;
    }

    cout << (flag ? "YES" : "NO" ) << endl;

    return 0;
}


Measured memory_bytes: 5376
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Enumeration
// 2012/09/19
public class Main{
	Scanner sc=new Scanner(System.in);

	int n;
	long m;
	long[] a;
	int[] p;

	void run(){
		n=sc.nextInt();
		m=sc.nextLong();
		a=new long[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextLong();
		}
		p=new int[n];
		for(int i=0; i<n; i++){
			p[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		long[] f=new long[1<<n];
		for(int s=0; s<1<<n; s++){
			long lcm=1;
			for(int i=0; i<n; i++){
				if((s>>i&1)==1){
					lcm=lcm(lcm, a[i]);
				}
			}
			if(lcm!=0){
				f[s]=m/lcm;
			}
		}
		f[0]=0;

		for(int i=0; i<n; i++){
			for(int s=0; s<1<<n; s++){
				if((s>>i&1)==1){
					f[s]-=f[s^(1<<i)];
				}
			}
		}

		double ans=0;
		for(int s=0; s<1<<n; s++){
			f[s]=abs(f[s]);
			double E=f[s];
			for(int i=0; i<n; i++){
				if((s>>i&1)==1){
					E*=p[i]/100.0;
				}else{
					E*=(100-p[i])/100.0;
				}
			}
			ans+=E;
		}
		println(String.format("%f", ans));
	}

	long gcd(long a, long b){
		return a==0?b:gcd(b%a, a);
	}

	long lcm(long a, long b){
		if(overflow(a/gcd(a, b), b)){
			return 0;
		}else{
			return a/gcd(a, b)*b;
		}
	}

	// a*b
	boolean overflow(long a, long b){
		return b!=0&&a>Long.MAX_VALUE/b;
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MAX = 2e5+10;

int N;
ll A[MAX];

bool exists_one() {
    REP (i, N) if (A[i] == 1) return true;
    return false;
}



ll solve() {
    if (!exists_one()) return -1;

    int check = 1;
    REP (i, N) if (A[i] == check) check++;
    return N-check+1;
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

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

int main(){
	int H, W;
	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++){
			for (int k = 0; k < W; k++){
				if (k > 0 && k < W - 1){
					if (i > 0 && i < H - 1){
						cout << ".";
					}
					else{
						cout << "#";
					}
				}
				else{
					cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

i = 0
total_cost = 0
 
a = np.zeros(N, dtype=np.int64)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

for i in range(2, N):
    k = min(K,i)
    a[i] = np.min(a[i-k:i] + np.abs(hs[i] - hs[i-k:i]))    
print(a[-1])


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

signed main(){
    int a[5];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    int d=a[2]-a[0],e=a[2]-a[1];
    if(d%2==0&&e%2==0){
        cout<<d/2+e/2<<endl;
    }
    else if(d%2==1&&e%2==1){
        cout<<d/2+e/2+1<<endl;
    }
    else{
        cout<<2+d/2+e/2<<endl;
    }
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string szLine = Console.ReadLine();
            string[] szArr = szLine.Split(' ');
            long n = long.Parse(szArr[0]);
            long a = long.Parse(szArr[1]);
            long b = long.Parse(szArr[2]);

            if((b -a) % 2 == 0)
            {
                Console.WriteLine("Alice");
            }
            else
            {
                Console.WriteLine("Borys");
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vit vector<lint>::iterator
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define graph_set(n) struct edge{int to,int cost;} vector<edge> G((n))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define range(x,y) ((x) >= 0 && (x) < h && (y) >= 0 && (y) < w)
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
typedef vector<long long> vi;
typedef vector<pair<long long, long long>> vp;
typedef vector<vector<long long>> vvi;
typedef pair<long long, long long> pi;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;

/********************/
#define MAX_V 105
int main() {
	ll n; cin >> n;
	vi a(n), b(n), c(n);
	rep(n) cin >> a[i];
	rep(n) cin >> b[i];
	rep(n) cin >> c[i];

	/*****************/
	sort(all(a)), sort(all(b)), sort(all(c));
	vi bb(n), cb(n);
	for(int i = n - 1;i >= 0;i--) {
		vector<ll>::iterator it = upper_bound(all(c), b[i]);
		//debug(it);
		bb[i] = c.end() - it;
		//debug(bb[i]);
	}

	cb[n - 1] = bb[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		cb[i] = cb[i + 1] + bb[i];
	}
    //for(auto i:cb) cout << i << endl;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		vector<ll>::iterator it = upper_bound(all(b), a[i]);
		ll idx = it - b.begin();
		//cout << idx << endl;
		if(idx < n)ans += cb[idx];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
let abcd = Array.init 4 @@ fun _ -> Scanf.scanf " %1d" (+) 0
let g = string_of_int
let rec f acc op i =
  if i >= 4 then (if acc = 7 then (Printf.printf "%s=7\n" op; exit 0))
  else
    let x = abcd.(i) in
    f (acc + x) (op ^ "+" ^ g x) (i + 1);
    f (acc - x) (op ^ "-" ^ g x) (i + 1)
let _ = f abcd.(0) (g abcd.(0)) 1

Measured memory_bytes: 384
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		boolean firstFlg = true;

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;

			if(!firstFlg) System.out.println();
			if(firstFlg) firstFlg = false;

			int before = 0;
			int[] m = new int[4];
			for(int i=0;i<4;i++){
				m[i] = sc.nextInt();
				before += m[i];
			}

			int min = Integer.MAX_VALUE;
			int[] minPay = new int[4];

			for(int i=0;i<=m[0];i++){
				for(int j=0;j<=m[1];j++){
					for(int k=0;k<=m[2];k++){
						for(int l=0;l<=m[3];l++){
							int ex = exchange(n,i,j,k,l);
							if(ex == Integer.MAX_VALUE) continue;

							int after = before - (i+j+k+l) + ex;
							if(after < min){
								minPay[0] = i;
								minPay[1] = j;
								minPay[2] = k;
								minPay[3] = l;
							}
						}
					}
				}
			}

			if(minPay[0]!=0) System.out.println("10 " + minPay[0]);
			if(minPay[1]!=0) System.out.println("50 " + minPay[1]);
			if(minPay[2]!=0) System.out.println("100 " + minPay[2]);
			if(minPay[3]!=0) System.out.println("500 " + minPay[3]);
		}
	}

	private static int exchange(int n,int i,int j,int k,int l){
		int ex = n - i*10 - j*50 - k*100 - l*500;
		if(ex > 0) return Integer.MAX_VALUE;

		ex = -ex;

		int res = 0;
		int tmp;

		if((tmp=ex/500) > 0 && l > 0) return Integer.MAX_VALUE;
		res += tmp;
		if((tmp=ex%500/100) > 0 && k > 0) return Integer.MAX_VALUE;
		res += tmp;
		if((tmp=ex%100/50) > 0 && j > 0) return Integer.MAX_VALUE;
		res += tmp;
		if((tmp=ex%50/10) > 0 && i > 0) return Integer.MAX_VALUE;
		res += tmp;

		return res;
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
#define REP(inc, bgn, end) for(int inc=bgn; inc<end; inc++)
typedef long long ll;

int main() {
    ll n;cin>>n;
    ll ten=1, nine=1, eight=1;
    REP(i,0,n){
        ten *= 10;
        nine *= 9;
        eight *= 8;
        if(ten>10000000000000000) ten %= mod;
        if(eight>10000000000000000) eight %= mod;
        nine %= mod;
    }
    ll ans = (ten + eight - 2*nine)%mod;
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3632
n,a,b = map(int,input().split())
c = n//(a+b)

if c > 0:
    ans = a*c + min((n - (a+b)*c),a)
    if ans > (a+b)*(10**100):
        ans = a*(10**100)
else:
    ans = min(a,n)
    
print(ans)

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll a1, a2;
  scanf("%lld %lld", &a1, &a2);

  ll b1, b2;
  scanf("%lld %lld", &b1, &b2);

  if (a1!=b1) {
    cout << "1" << endl;
  } else {
    cout << "0" << endl;
  }
}


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

int main() {
	int m, f, r;
	while (1) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1)break;
		int total = m + f;
		if (m == -1 || f == -1) cout << 'F' << endl;
		else {
			if (total >= 80) cout << 'A' << endl;
			else if (total < 80 && total >= 65) cout << 'B' << endl;
			else if (total < 65 && total >= 50) cout << 'C' << endl;
			else if (total < 50 && total >= 30) {
				if (r >= 50) cout << 'C' << endl;
				else cout << 'D' << endl;
			}
			else if (total < 30) cout << 'F' << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 3092
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            int d = in.nextInt();

            int[] y = new int[h * w];
            int[] x = new int[h * w];
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    int tmp = in.nextInt() - 1;
                    y[tmp] = i;
                    x[tmp] = j;
                }
            }

            long[] sum = new long[h * w];
            for (int i = 0; i < d; i++) {
                for (int j = i; j + d < h * w; j++) {
                    sum[j + d] = sum[j] + Math.abs(y[j + d] - y[j]) + Math.abs(x[j + d] - x[j]);
                }
            }

            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;

                out.println(sum[r] - sum[l]);
            }
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 52352
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
    int n;cin>>n;
    vector<lint> a(n);
    vector<lint> b(n);
    lint sm=0;
    lint mn=1e18;
    bool flag=true;
    rep(i,n){
        cin>>a[i]>>b[i];
        sm+=a[i];
        if(a[i]!=b[i])flag=false;
        if(a[i]>b[i]){
            mn=min(mn,b[i]);
        }
    }
    lint res=sm-mn;
    if(res<0)res=0;
    if(flag)res=0;
    cout<<res<<"\n";
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  ll sum = 0;
  REP(i,3){
    if(s[i] == '1')
      sum++;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

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

    string str;
    cin >> str;

    int i;
    int ans = 1;
    char last = str[0];
    for(i = 1; i < n; i ++)
    {
    	if(str[i] == last)
    		continue;
    	else
    	{
    		last = str[i];
    		ans ++;
    	}
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int n, x;
	scanf("%d%d", &n, &x);
	vi a(n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	int dist = 0;
	int i;
	for (i = 0; i < n; i++) {
		dist += a[i];
		if (dist > x) break;
	}
	printf("%d\n", i + 1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int a;cin>>a;
	cout<<3*a*a<<endl;

	return 0;
}

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

int sum(int n) {
  // ベースケース
  if (n == 0) {
    return 0;
  }
  // 再帰ステップ
  int s = sum(n - 1);
  return s + n;
}

int main(){
    int N,L;
    cin >> N >> L;
    int ans=0;
    ans+=(N)*(L-1);
    ans+=sum(N);
    if(L>0)ans-=L+1-1;
    else if(L<1-N)ans-=L+N-1;
    cout << ans << endl;
}


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

int main() {
	int N;
	int a[100];
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(a, a + N, greater<int>());
	
    int Alice = 0;
	int Bob = 0;
    for (int i = 0; i < N; i += 2) {
		Alice += a[i];
	}
    for (int i = 1; i < N; i += 2) {
		Bob += a[i];
	}
    cout << Alice - Bob << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {

	int n;
	while(cin >> n, n){
		int h, w;
		cin >> w >> h;
		vector<vector<bool>> vec(h, vector<bool>(w));
		rep(i, n){
			int x, y;
			cin >> x >> y;
			vec[y-1][x-1] = true;
		}
		
		int s, t;
		cin >> s >> t;
		int ans = 0;
		for(int  i = 0; i + t <= h; i++){
			for(int j = 0; j + s <= w; j++){
				int tmp = 0;
				rep(hh, t) rep(ww, s) if (vec[i + hh][j + ww]) tmp++;
				ans = max(ans, tmp);
			}
		}
		cout << ans << endl;
	
	}
	

	return 0;
}

Measured memory_bytes: 3104
import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int cnt,i; 
        String line,chr;
        String[] str = new String[1000];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        chr = in.readLine(); cnt=0;
        while((line=in.readLine()) != null){
            if("END_OF_TEXT".equals(line)) break;
            str = line.split(" ",-1);
            for(i=0;i<str.length;i++){
                if(str[i].equalsIgnoreCase(chr)) cnt+=1;
            }
        }
        System.out.println(cnt);
        System.out.flush();
    }
}

Measured memory_bytes: 24144
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d)cout<<"Yes\n";
    else cout<<"No\n";
 
 
 
 
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

struct generator{
  int n;
  int i[3]={1,0,0};
  generator(int _n):n(_n){
  }
  bool remain(int a){
    if(a>2)return false;
    if(3*i[a]+a>n)return false;
    return true;
  }
  int get(int a){
    if(!remain(a)) return 0;
    int ret = 3*i[a]+a;
    i[a]++;
    return ret;
  }
};

int main(){
  int N;
  cin>>N;
  vector<vector<int> > c(N);
  REP(i,N-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    c[a].push_back(b);
    c[b].push_back(a);
  }
  vector<int> d(N,-1);
  int no=0,ne=1;
  queue<int> q;
  q.push(0);
  d[0]=0;
  while(!q.empty()){
    int p=q.front();
    q.pop();
    for(auto e:c[p])if(d[e]<0){
      q.push(e);
      d[e]=d[p]+1;
      if(d[e]%2==0)ne++;
      else no++;
    }
  }
  REP(i,N)cerr<<d[i]<<" ";
  cerr<<endl;
  cerr<<ne<<" "<<no<<endl;
  auto g=generator(N);
  vector<int> ans(N);
  REP(i,N){
    if(ne<=N/3){
      if(d[i]%2==0){
        ans[i]=g.get(0);
        if(ans[i]==0)return 1;
      }else{
        if(g.remain(1))ans[i]=g.get(1);
        else if(g.remain(2))ans[i]=g.get(2);
        else ans[i]=g.get(0);
      }
    }else if(no<=N/3){
      if(d[i]%2==0){
        if(g.remain(1))ans[i]=g.get(1);
        else if(g.remain(2))ans[i]=g.get(2);
        else ans[i]=g.get(0);
      }else{
        ans[i]=g.get(0);
        if(ans[i]==0)return 1;
      }
    }else{
      if(d[i]%2==0){
        if(g.remain(1))ans[i]=g.get(1);
        else ans[i]=g.get(0);
      }else{
        if(g.remain(2))ans[i]=g.get(2);
        else ans[i]=g.get(0);
      }
    }
  }
  REP(i,N)cout<<ans[i]<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 15220
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 1000

int N,a,cc=1;
vector<int> G[MAX_V];
int match[MAX_V];
int used[MAX_V];

bool dfs(int v){
  used[v]=cc;
  for(int i=0;i<(int)G[v].size();i++){
    int u=G[v][i],w=match[u];
    if( w<0 || (used[w]!=cc&&dfs(w)) ){
      match[u]=v;
      match[v]=u;
      return true;
    }
  }
  return false;
}
 
int bipartite_matching(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0;v<N;v++){
    if(match[v]<0){
      cc++;
      if(dfs(v))res++;
    }
  }
  return res;
}
 
int main(){
  scanf("%d",&N);
  N--;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      scanf("%d",&a);
      if(a==1)G[j].push_back(N+i);
    }
  }
  for(int i=0;i<N;i++)sort(G[i].begin(),G[i].end());
  int f=bipartite_matching();
  printf( f==N?"yes\n":"no\n");
  for(int i=0;i<N&&f==N;i++){
    match[ match[i] ]=-1;
    match[i]=-1;
    cc++;
    dfs(i);
    G[i].clear();
    G[i].push_back( match[i] );
    printf("%d\n",match[i]-N+1);
  }
  return 0;
}

Measured memory_bytes: 3356
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;
	template<class T>using pair = std::pair<T, T>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
	
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		auto s = 1ULL;
		for (auto i = 0; i < 63; ++i, s <<= 1)
		{
			if (p & s)
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
	template<class Range>void sort(Range& rng)
	{
		std::sort(std::begin(rng), std::end(rng));
	}
	template<class Range, class Pred>void sort(Range& rng, Pred pred)
	{
		std::sort(std::begin(rng), std::end(rng), pred);
	}
}

void check_prime(int v, std::unordered_map<int, std::size_t>& count)
{
	auto check = [&](int p)
	{
		if (v % p == 0)
		{
			++count[p];
			while (v % p == 0)
			{
				v /= p;
			}
		}
	};
	check(2);
	for (auto p = 3; p * p <= v; p += 2)
	{
		check(p);
	}
	if (v != 1)
	{
		++count[v];
	}
}

void Main()
{
	std::unordered_map<int, std::size_t> count;
	std::size_t N;
	std::cin >> N;
	for (auto i : boost::irange(N))
	{
		int v;
		std::cin >> v;
		check_prime(v, count);
	}
	std::size_t max = 0;
	for (auto [p, c] : count)
	{
		max = std::max(max, c);
	}
	if (max <= 1)
	{
		std::cout << "pairwise coprime" << std::endl;
	}
	else if (max < N)
	{
		std::cout << "setwise coprime" << std::endl;
	}
	else
	{
		std::cout << "not coprime" << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 6640
function Main(input) {
    var args = input.trim().split('\n').map(function(val) {
        return Number(val);
    });

    console.log(6-args[0] - args[1]);

}

/* var input = `3
2`;
Main(input);
 */ 
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] num = new int[3];
		int n = sc.nextInt();
		long ans = 1;
		for (int i=0;i<n;i++) {
			int count = 0;
			int place = 0;
			int input = sc.nextInt();
			for (int j=0;j<3;j++) {
				if (num[j]==input) {
					count++;
					place=j;
				}
			}
          	num[place]++;
			ans = ans*count%1_000_000_007;
		}
		System.out.println(ans);
	}
}




Measured memory_bytes: 47340
#include <iostream>

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A > 12) {
    cout << B << endl;
  } else if (A >= 6 && A <= 12) {
    cout << (B >> 1) << endl;
  } else {
    cout << 0 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3608
s = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]

hanten = -1
atama = ""
shiri = ""

for row in range(quantity):
  each = L[row]
  if each[0] == "1":
    hanten = hanten * -1
  else:
    if each[1] == "1":
      if hanten == -1:
        atama = atama + each[2]
      else:
        shiri = shiri + each[2]
    else:
      if hanten == -1:
        shiri = shiri + each[2]
      else:
        atama = atama + each[2]

atama = atama[::-1]
ans = atama + s + shiri

if hanten == 1:
  ans = ans[::-1]
print(ans)

Measured memory_bytes: 40432