akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int count = Integer.parseInt(br.readLine());
            String str[] = br.readLine().split(" ");
            int ans = 0;
            while (true) {
                boolean flag = false;
                for (int i = 0; i < count; i++) {
                    long tmp = Long.parseLong(str[i]);
                    if (tmp % 2 == 0) {
                        str[i] = Long.toString(tmp / 2);
                    } else {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    break;
                }
                ans++;
            }
            System.out.println(ans);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


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

typedef long long ll;

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

    int n; cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++) cin >> p[i];
    int minn = p[0];
    int ans = 0;
    for(int i=1;i<n;i++){
        if(p[i] > minn) ans++;
        minn = min(minn,p[i]);
    }
    cout << n - ans << endl;
    return 0;
}

Measured memory_bytes: 1024
N, X, Y = map(int, input().split())
dists = [[-1] * N for _ in range(N)]
graph = [[1]]
graph .extend([i - 1, i + 1] for i in range(1, N - 1))
graph.append([N - 2])
graph[X - 1].append(Y - 1)
graph[Y - 1].append(X - 1)

d_count = [0] * N

for i in range(N):
    q = [i]
    dists[i][i] = 0
    while len(q) >= 1:
        n = q.pop(0)
        for n_next in graph[n]:
            if dists[i][n_next] >= 0:
                continue
            dists[i][n_next] = dists[i][n] + 1
            d_count[dists[i][n_next]] += 1
            q.append(n_next)

print("\n".join(str(d_count[i] // 2) for i in range(1, N)))

Measured memory_bytes: 74204
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

def resolve():
    n, q = LI()
    uf = UnionFind(n)
    for _ in range(q):
        comxy = LI()

        com = comxy[0]
        x = comxy[1]
        y = comxy[2]

        if com==0:
            uf.unite(x, y)
        else:
            print(int(uf.same(x, y)))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 6432
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};
 
int pw(int x){
	int ret = 1;
	rep(i,x) ret *= 10;
	return ret;
}
 
int main() {
	int n,m;
	cin >> n >> m;
	int s[10],c[10];
	rep(i,m) cin >> s[i] >> c[i];
 
	for(int i = (n==1 ? 0 : pw(n-1)); i < pw(n); i++){
		int flag = 1;
		for(int j = 0; j < m; j++){
			int a = (int)(i/pow(10,n-s[j]))%10;
			if(c[j] != a) flag = 0;
		}
		if(flag){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

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

int main(){long N;
cin >> N;
long x = 1; long ans;
while(pow(x, 2) <= N){
    ans = pow(x, 2);
    x++;
}

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

Measured memory_bytes: 256
s = gets.split('').map(&:to_i)
N = s.length

def first0check(s)
  sum = 0
  (N-1).times do |i|
    num = s[i]
    if i.odd? && num == 0
      sum += 1
    elsif i.odd? && num == 1
      next
    elsif i.even? && num == 0
      next
    elsif i.even? && num == 1
      sum += 1
    end
  end
  sum
end

def first1check(s)
  sum = 0
  (N-1).times do |i|
    num = s[i]
    if i.odd? && num == 0
      next
    elsif i.odd? && num == 1
      sum += 1
    elsif i.even? && num == 0
      sum += 1
    elsif i.even? && num == 1
      next
    end
  end
  sum
end

sum_1 = first0check(s)
sum_2 = first1check(s)

puts [sum_1,sum_2].min


Measured memory_bytes: 7676
#!/usr/bin/env python3
#AGC18 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)

n,k = LI()
a = LI()
if k in a:
    print('POSSIBLE')
    quit()
if max(a) < k:
    print('IMPOSSIBLE')
    quit()
g = a[0]
for i in range(1,n):
    g = gcd(g,a[i])
if k % g != 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')


Measured memory_bytes: 58736
a=int(input())
b=int(input())
c=int(input())
s=int(input())
n=0
for x in range(a+1):
    for y in range(b+1):
        for z in range(c+1):
            if 500*x+100*y+50*z==s:
                n=n+1
print(n)


Measured memory_bytes: 9096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

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

int main(void){
    int n;
    while(cin >> n, n){
        vector<string> a(n);
        REP(i, n) cin >> a[i];
        int ans = 0;
        REP(i, n-1){
            if(a[i] == "lu" && a[i+1] == "ru") ans++;
            if(a[i] == "ld" && a[i+1] == "rd") ans++;
            if(a[i] == "ru" && a[i+1] == "lu") ans++;
            if(a[i] == "rd" && a[i+1] == "ld") ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

int main(int argc, char* argv[]){
  int n,k;
  cin >> n >> k;
  long long int x[100001];
  for(int i=0;i<n;i++){
    cin >> x[i];
  }

  long long int ans = 2000000000;
  int t;
  for(int i=0;i<n-k+1;i++){
    if(x[i] < 0 && 0 < x[i+k-1]){
      t = min(2*abs(x[i])+x[i+k-1], abs(x[i])+2*x[i+k-1]);
    }else{
      t = max(abs(x[i]), abs(x[i+k-1]));
    }
    if(t < ans)ans=t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<queue>

using namespace std;

#define INF (1 << 29)

struct Entry
{
    int x, y;
    int direction;
};

int main()
{
    int w, h;

    while(cin >> w >> h, (w | h) )
    {
        //map[h][w]
        int map[30][30];

        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                cin >> map[i][j];
            }
        }
        
        //command[0] to straight
        //command[1] to right
        //command[2] to back
        //command[3] to left
        int command[4];
        for(int i = 0; i < 4; i++)
        {
            cin >> command[i];
        }

       
        //direction and costs when comes to the Entry
        //cost[direction][y][x]
        int cost[4][30][30];

        //cost[0][][] to right
        //cost[1][][] to down
        //cost[2][][] to left
        //cost[3][][] to up


        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                cost[0][i][j] = INF;
                cost[1][i][j] = INF;
                cost[2][i][j] = INF;
                cost[3][i][j] = INF;
            }
        }

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


        //start
        queue<Entry> que;

        que.push(Entry{0, 0, 0});
        cost[0][0][0] = 0;

        bool check = true;

        while(!que.empty())
        {
            Entry now = que.front();
            que.pop();

            //if follows the Entry rule
            int followedDirection = now.direction + map[now.y][now.x];
            followedDirection %= 4;

            //halt
            if(map[now.y][now.x] == 4)followedDirection = INF;

            //(now.direction + i) % 4 is next direction
            //i is rotating degree
            for(int i = 0; i < 4; i++)
            {
                int nextDirection = (now.direction + i) % 4;

                int nextX = now.x + dx[nextDirection];
                int nextY = now.y + dy[nextDirection];

                //if not out of range
                if( !(nextX < 0 || nextX >= w || nextY < 0 || nextY >= h) ) 
                {
                    int tmp_cost = cost[now.direction][now.y][now.x] + (nextDirection != followedDirection) * command[i];

                    //update to lower costs
                    if(tmp_cost < cost[nextDirection][nextY][nextX])
                    {
                        cost[nextDirection][nextY][nextX] = tmp_cost;
                        que.push( Entry{ nextX, nextY, nextDirection } );
                    }
                }
            }
        }
        cout << min(cost[0][h - 1][w - 1], cost[1][h - 1][w - 1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 3044
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string s;
  cin>>s;
  int n = s.size();
  for(int i = n-2; i >= 0; i-=2){
    if(s.substr(0, i/2)==s.substr(i/2, i/2)){
      cout<<i<<endl;
      return 0;
    }
  }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include<utility>
using namespace std;
using ll = long long;



int main() {
	int n, a[100],ans=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (n == 2) {
		cout << ((a[0] == a[1]) ? 1 : 0 )<< endl;
		return 0;
	}
	for (int i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) {
			ans++;
			a[i] = 114514;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#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 <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x; cin >> x;
  FOR(i,-200,200) {
    FOR(j,-200,200) {
      if(pow(i,5) - pow(j,5) == x) { cout << i << " " << j << endl; return 0;}
    }
  }
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    ll d, a;
    cin >> d >> a;
    d *= 2;
    vector<pll> M(n);
    rep(i, n) {
        ll x, h;
        cin >> x >> h;
        M[i] = {x, h};
    }
    ll ans = 0;
    ll acc = 0;
    sort(all(M));
    queue<pll> que;
    rep(i, n) {
        ll x, h;
        tie(x, h) = M[i];
        while (!que.empty() && que.front().fi < x) {
            acc -= que.front().se;
            que.pop();
        }
        if (acc * a >= h) continue;
        ll y = (h - (acc * a) + a - 1) / a;
        ans += y;
        acc += y;
        que.emplace(x + d, y);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 7928
n = int(input())
a = [int(e) for e in input().split()]
tmp_mat = [[a[j]>i  for j in range(n)] for i in range(max(a))]
mat = [[a for a,b in zip(row,row[1:]+[False]) if a and a!=b]for row in tmp_mat]
print(sum([len(row)for row in mat]))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int a, b, c; cin >> a >> b >> c;
  cout << min(c, b/a) << endl;
}


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

using namespace std;

typedef long long ll;
ll mod = 1e9 + 7;
ll d[1000001][2][2];
int n;

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

    cin >> n;
        
    ll ans = 0;
    d[0][0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2; k++){
                if(j == 0 && k == 0){
                    d[i][j][k] += d[i - 1][j][k] * (ll)8; d[i][j][k] %= mod;
                }else if(j == 0 && k == 1){
                    d[i][j][k] += d[i - 1][0][0]; d[i][j][k] %= mod;
                    d[i][j][k] += d[i - 1][j][k] * (ll)9; d[i][j][k] %= mod;
                }else if(j == 1 && k == 0){
                    d[i][j][k] += d[i - 1][0][0]; d[i][j][k] %= mod;
                    d[i][j][k] += d[i - 1][j][k] * (ll)9; d[i][j][k] %= mod;
                }else{
                    d[i][j][k] += d[i - 1][1][0]; d[i][j][k] %= mod;
                    d[i][j][k] += d[i - 1][0][1]; d[i][j][k] %= mod;
                    d[i][j][k] += d[i - 1][j][k] * (ll)10; d[i][j][k] %= mod;
                }
            }
        }
    }

    cout << d[n][1][1] << '\n';

}


Measured memory_bytes: 34760
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


class Point(object):
    epsilon = 1e-10

    def __init__(self, x=0.0, y=0.0):
        if isinstance(x, tuple):
            self.x = x[0]
            self.y = x[1]
        else:
            self.x = x
            self.y = y

    # ????????????
    def __add__(self, other):
        return (self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return (self.x - other.x, self.y - other.y)

    def __mul__(self, other):
        return (other * self.x, other * self.y)

    def __truediv__(self, other):
        return (other / self.x, other / self.y)

    def __lt__(self, other):
        if self.x == other.x:
            return self.y < other.y
        else:
            return self.x < other.x

    def __eq__(self, other):
        from math import fabs
        if fabs(self.x - other.x) < Point.epsilon and fabs(self.y - other.y) < Point.epsilon:
            return True
        else:
            return False

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        from math import sqrt
        return sqrt(self.norm())


class Vector(Point):
    @classmethod
    def dot(cls, a, b):
        return a.x * b.x + a.y * b.y

    @classmethod
    def cross(cls, a, b):
        return a.x * b.y - a.y * b.x

    @classmethod
    def is_orthogonal(cls, a, b):
        return Vector.dot(a, b) == 0.0

    @classmethod
    def is_parallel(cls, a, b):
        return Vector.cross(a, b) == 0.0


class Segment(object):
    def __init__(self, p1=Point(), p2=Point()):
        if isinstance(p1, Point):
            self.p1 = p1
            self.p2 = p2
        elif isinstance(p1, tuple):
            self.p1 = Point(p1[0], p1[1])
            self.p2 = Point(p2[0], p2[1])

    @classmethod
    def is_orthogonal(cls, s1, s2):
        a = Vector(s1.p2 - s1.p1)
        b = Vector(s2.p2 - s2.p1)
        return Vector.is_orthogonal(a, b)

    @classmethod
    def is_parallel(cls, s1, s2):
        a = Vector(s1.p2 - s1.p1)
        b = Vector(s2.p2 - s2.p1)
        return Vector.is_parallel(a, b)


class Line(Segment):
    pass


class Cirle(object):
    def __init__(self, c=Point(), r=0.0):
        self.c = c
        self.r = r


def solve(data):
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = data
    a = Segment((x_p0, y_p0), (x_p1, y_p1))
    b = Segment((x_p2, y_p2), (x_p3, y_p3))
    if Segment.is_orthogonal(a, b):
        return 1
    elif Segment.is_parallel(a, b):
        return 2
    else:
        return 0


def main(args):
    q = int(input())
    for _ in range(q):
        result = solve([int(x) for x in input().split()])
        print(result)

if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 8000
g_memo = {0: 1}
h_memo = {0: 1}
dp = {}

def g(l):
    if not l in g_memo:
        g_memo[l] = 3 + 2*g(l-1)
    return g_memo[l]

def h(l):
    if not l in h_memo:
        h_memo[l] = 1 + 2*h(l-1)
    return h_memo[l]

def solve(l, x):
    if x <= 0:
        return 0
    if l == 0: # x > 0
        return 1
    if x >= g(l):
        return h(l)
    if (l, x) in dp:
        return dp[l,x]
    y = 0
    res = 0
    # B
    y += 1
    # f(l-1)
    res += solve(l-1, x-y)
    y += g(l-1)
    # P
    if y < x: # P
        res += 1
    y += 1
    # f(l-1)
    res += solve(l-1, x-y)
    y += g(l-1)
    # B 
    y += 1

    dp[l,x] = res
    return res

n, x = map(int, raw_input().split())
print(solve(n, x))

Measured memory_bytes: 2696
a = gets.split.map(&:to_i)

def roll(a)
    tmp = a[0]
    a[0] = a[1]
    a[1] = a[5]
    a[5] = a[4]
    a[4] = tmp
end

def spin(a)
    tmp = a[1]
    a[1] = a[2]
    a[2] = a[4]
    a[4] = a[3]
    a[3] = tmp
end

n = gets.to_i

n.times do
    t, f = gets.split.map(&:to_i)
    i = 0
    while t != a[0]
        spin(a) if i == 3
        roll(a)
        i += 1
    end
    while a[1] != f
        spin(a)
    end
    p a[2]
end


Measured memory_bytes: 6872
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {
	string s;
	cin >> s;
	rep(i, s.length()) {
		if (s[i] == ',')s[i] = ' ';
		
	}
	cout << s << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        ab: [i32; 2]
    }
    let (a, b) = (ab[0], ab[1]);
    let answer = if b % a == 0 {
        a + b
    } else {
        b - a
    };
    println!("{}", answer);
}


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

int keta(int n) {
    int t;
    t = 0;
    while(n){
        t += n % 10;
        n /= 10;
    }
    return t;
}

int main(void) {
    int n, a, b, ans;
    ans = 999999;
    cin >> n;
    for(int i = 1; i < n / 2 + 1; i++){
        a = keta(i);
        b = keta(n - i);
        ans = min(ans, a + b);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>

#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))

using namespace std;

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> a(n);
    vector<vector<long long> > gp(n+1, vector<long long>(n+1, 0));
 
    long i, j;
    for(i=0; i<n; i++) {
        scanf("%ld", &(a[i]));
        gp[i][0] = a[i];
    }

    for(j=1; j<n; j++) {
        for(i=0; i<n-j; i++) {
            gp[i][j] = MAX(a[i]-gp[i+1][j-1], a[i+j]-gp[i][j-1]);
        }
    }
   
    printf("%lld\n", gp[0][n-1]);

    return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll A[2][N];
  REP(i, 2) {
    REP(j, N) { cin >> A[i][j]; }
  }

  ll sum[2][N];

  REP(i, 2) {
    sum[i][0] = A[i][0];
    FOR(j, 1, N) { sum[i][j] = sum[i][j - 1] + A[i][j]; }
  }

  ll ans = 0;

  REP(x, N) {
    ll tmp;
    if (x == 0) {
      tmp = sum[0][x] + sum[1][N - 1];
    } else {
      tmp = sum[0][x] + sum[1][N - 1] - sum[1][x - 1];
    }
    ans = max(ans, tmp);
  }
  cout << ans;
  return 0;
}

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

int main(void){
   double x1,y1,x2,y2;
   cin >> x1 >> y1;
   cin >> x2 >> y2;
   double d = pow(x1-x2,2) + pow(y1-y2,2);
   cout << fixed << setprecision(5) << sqrt(d);
   cout << d << endl;
}


Measured memory_bytes: 3276
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (N, M) = Read2Longs();

            var roots = new List<long>[N + 1];
            for (int i = 0; i < N + 1; i++)
            {
                roots[i] = new List<long>();
            }

            for (int i = 0; i < M; i++)
            {
                var (a, b) = Read2Longs();
                roots[a].Add(b);
                roots[b].Add(a);
            }

            var hints = new long[N + 1];
            for (int i = 2; i < N + 1; i++)
            {
                hints[i] = -1;
            }

            var queue = new Queue<long>();
            queue.Enqueue(1);
            while (queue.Count > 0)
            {
                var from = queue.Dequeue();
                foreach (var to in roots[from])
                {
                    if (hints[to] == -1)
                    {
                        hints[to] = from;
                        queue.Enqueue(to);
                    }
                }
            }

            if (hints.Any(x => x == -1)) return "No";

            var sb = new StringBuilder();
            sb.AppendLine("Yes");
            foreach (var hint in hints.Skip(2))
            {
                sb.AppendLine(hint.ToString());
            }

            return sb.ToString().Trim();
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 55236
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}/*swap 交換*/
ll max2(ll a,ll b){return a>=b?a:b;}/*2つのうち大きい数を返す*/ 
ll min2(ll a,ll b){return a>=b?b:a;}/*2つのうち小さい数を返す*/ 
ll ABS(ll a){return a>=0?a:(-a);}/*絶対値*/ 
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    char s[100005],bs[200005],as[200005];
    ll q,front=1,bsmark=0,asmark=0;
    scanf("%s%lld",s,&q);
    ll query[q],n=strlen(s);
    rep(i,0,q){
        scanf("%lld",&query[i]);
        if(query[i]==1){
            front*=-1;
        }else{
            ll a;
            char c[2];
            scanf("%lld%s",&a,c);
            if(a*front==1 || a*front==-2){
                bs[bsmark]=c[0];
                bsmark++;
            }else{
                as[asmark]=c[0];
                asmark++;
            }
        }
    }
    if(front==1){
        rep(i,0,bsmark){
            printf("%c",bs[bsmark-i-1]);
        }
        rep(i,0,n){
            printf("%c",s[i]);
        }
        rep(i,0,asmark){
            printf("%c",as[i]);
        }
    }else{
        rep(i,0,asmark){
            printf("%c",as[asmark-i-1]);
        }
        rep(i,0,n){
            printf("%c",s[n-i-1]);
        }
        rep(i,0,bsmark){
            printf("%c",bs[i]);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>

int min(int a, int b, int c){
  int min = (a<b) ? a:b;
  return (min<c) ? min : c;
}

int main()
{
  int N;
  scanf("%d", &N);
  int a[N], sum=0;
  for(int i=0;i<N;i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }
  
  int c1=0, c2=0, c3=0;
  for(int i=0;i<N;i++){
    c1 += (a[i] - sum/N) * (a[i] - sum/N);
    c2 += (a[i] - sum/N + 1) * (a[i] - sum/N + 1);
    c3 += (a[i] - sum/N - 1) * (a[i] - sum/N - 1);
  }
  printf("%d", min(c1,c2,c3));
  return 0;
}

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int x,k,d;
  cin>>x>>k>>d;
  x=abs(x);
  if(((__int128_t)k)*((__int128_t)d)<=(__int128_t)x) drop(x-k*d);

  Int mv=x/d;
  x-=mv*d;
  k-=mv;
  k%=2;
  if(k) x=abs(x-d);
  cout<<x<<newl;
  return 0;
}


Measured memory_bytes: 3636
import numpy as np
n,k=list(map(int,input().split(' ')))
h=list(map(int,input().split(' ')))
dp=np.zeros(n, dtype=int)
h=np.array(h)
for i in range(1,n):
    j=max(0,i-k)
    dp[i] = np.min(dp[j:i]+abs(h[i]-h[j:i]))
print(dp[n-1])  

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


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

    ll n,m;cin>>n>>m;
    ll mn=0; ll mx=1e5+9;
    REP(i,m){
        ll a,b;cin>>a>>b;
        mn = max(mn,a);
        mx = min(mx,b);
    }
    if (mn>mx){
        cout<<0<<endl;
        return 0;
    }
    else cout<<mx-mn+1<<endl;
    return 0;
}

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

int dp[3][200001];

int main()
{
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	string s;
	cin>>s;

	for(int i=1; i<=int(s.size()); i++)
	{
		if(1)
		{
			dp[1][i] = dp[2][i-1]+1;

			if(i>1 && s[i-1]!=s[i-2]) dp[1][i] = max(dp[1][i],1+dp[1][i-1]);
		}

		if(2)
		{
			if(i>1) dp[2][i] = dp[1][i-2]+1;

			if(i>=4 && (s[i-1] != s[i-3] || s[i-2] != s[i-4])) dp[2][i] = max(dp[2][i],1+dp[2][i-2]);
		}

		//cout << dp[1][i] << " " << dp[2][i] << endl;
	}

	cout << max(dp[1][s.size()],dp[2][s.size()]) << endl;
}

Measured memory_bytes: 2180
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v)                      \
    for (auto __macro_vi : v)      \
    {                              \
        cout << __macro_vi << " "; \
    }                              \
    cout << endl;
#define DA(a, n)                                        \
    for (int __macro_i = 0; __macro_i < n; ++__macro_i) \
    {                                                   \
        cout << a[__macro_i] << " ";                    \
    }                                                   \
    cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <string>
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
 
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int k;
    cin >> k;
    char last = '*';
    long long ans = 0;

    char s0 = s[0];
    bool same = true;
    REP(i, s.size()) {
        if (s0 != s[i]) {same = false; break;}
    }
    if (same) {
        long long l = (long long)k * s.size();
        cout << l / 2 << endl;
        return 0;
    }
    int cnt = 0;
    bool last_buf = true;
    while(1) {
        long long tmp = 0;
        bool first_buf = false;
        REP(i, s.size())
        {
            if (last == s[i])
            {
                last = '*';
                tmp += 1;
                if (i == 0) first_buf = true;
            }
            else
            {
                last = s[i];
            }
        }
        ans += tmp;
        cnt++;
        // DD(last_buf, first_buf);
        if (last_buf == first_buf) {
            ans += tmp * (k - cnt);
            break;
        }
        last_buf= first_buf;
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#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())

#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
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void resolve() {
    int n;
    cin >> n;
    VI d(n);
    REP(i,0,n) cin >> d[i];
    int m;
    cin >> m;
    VI t(m);
    REP(i,0,m) {
        cin >> t[i]; 
    }
    sort(all(d));
    sort(all(t));
    int id = 0, it = 0;
    while (id < d.size() && it < t.size()) {
        if (d[id] == t[it]) {
            ++id;
            ++it;
        } else if (d[id] < t[it]) {
            ++id;
        } else {
            break;
        }
    }
    if (it == t.size()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    resolve();
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <set>
using namespace std;

struct Card {
	char suit;
	int rank;

	int suitIndex() const {
		return (suit == 'S') ? 1 :
			(suit == 'H') ? 2 :
			(suit == 'C') ? 3 :
			(suit == 'D') ? 4 : 0;
	}
};

bool operator<(const Card& lhs, const Card& rhs) {
	if (lhs.suitIndex() == rhs.suitIndex()) {
		return lhs.rank < rhs.rank;
	} else {
		return lhs.suitIndex() < rhs.suitIndex();
	}
}

ostream& operator<<(ostream& out, const Card& card) {
	out << card.suit << " " << card.rank;
	return out;
}

istream& operator>>(istream& in, Card& card) {
	in >> card.suit >> card.rank;
	return in;
}


int main() {

	const char suits[] = {'S', 'H', 'C', 'D'};
	set<Card> cards;
	for (auto suit : suits) {
		for (int i = 1; i <= 13; i++) {
			cards.insert({suit, i});
		}
	}

	int n;
	cin >> n;
	set<Card> inputs;
	for (int i = 0; i < n; i++) {
		Card card;
		cin >> card;
		cards.erase(card);
	}

	copy(cards.begin(), cards.end(), ostream_iterator<Card>(cout, "\n"));

	return 0;
}



Measured memory_bytes: 3068
#include <stdio.h>
#define N 100
#define M 100
#define L 100
int main(void)
{
	int n, m, l, i, j, k;
	int A[N][M];
	int B[M][L];
	long long C[N][L]={{0}};
	scanf("%d%d%d", &n, &m, &l);
	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			scanf("%d", &A[i][j]);
		}
	}
	for(i=0; i<m; i++){
		for(j=0; j<l; j++){
			scanf("%d", &B[i][j]);
		}
	}
	for(i=0; i<n; i++){
		for(j=0; j<l; j++){
			for(k=0; k<m; k++){
				C[i][j] += A[i][k] * B[k][j];
			}
			printf("%lld", C[i][j]);
			if(j < l-1){
				printf(" ");
			}else{
				puts("");
			}
		}
	}
	return 0;
}

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


struct LIS{
  int n;
  vector<int>dp,a;
  LIS(int sz):n(sz),dp(sz),a(sz){}
  void input(vector<int>&v){
    r(i,v.size())a[i]=v[i];
  }
  int lis(){
    dp[0]=a[0];
    int len=1;
    for(int i=1;i<n;i++){
      if(dp[len-1]<a[i]) dp[len++] = a[i];
      else *lower_bound(dp.begin(),dp.begin()+len,a[i]) = a[i];
    }
    return len;
  }
};

signed main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    a[i]--;
  }

  int ans=0;

  for(int i=0;i<n;i++){

    //cout<<i<<endl;
    
    vector<int>v;
    int x=a[i];
    if( x<i ) continue;
    
    for(int j=i+1;j<x;j++){
      //cout<<i<<' '<<j<<endl;
      if( i<a[j] && a[j]<x )continue;
      int t=a[j];
      if(t<i)t+=8800;
      v.push_back(t);
      
    }

    if(!v.size())continue;

    //cout<<v.size()<<endl;

    LIS L(v.size());
    L.input(v);

    ans=max(ans,L.lis());
  }

  ans++;

  cout<<ans+min(k,n/2-ans)<<endl;
}



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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N), B(N);
  for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];

  vector<long long> C(N+1, 0); // C[N] = 0 を番兵としておく
  for (int i = N-1; i >= 0; --i) {
      A[i] += C[i+1]; // とりあえず前回分を足しておく
      long long amari = A[i] % B[i];
      long long need = 0;
      if (amari != 0) need = B[i] - amari; // 追加で必要な分
      C[i] = C[i+1] + need;
  }
  cout << C[0] << endl;
}

Measured memory_bytes: 5616
#include <cstdio>
#include <cstring>
using namespace std;

bool comp(int a, int b, int c){
	if(a == b && b == c) return false;
	else return true;
}

int main(){
	const int MAX_K = 100;
	const int MAX_N = 100;
	int N, K;
	int A[MAX_K], B[MAX_K];
	int C[MAX_N + 1];
	int dp[MAX_N + 1][4][4][4];
	int ans;
	
	scanf("%d%d", &N, &K);
	for(int i = 0; i < K; i++){
		scanf("%d%d", &A[i], &B[i]);
	}
	
	memset(C, 0, sizeof(C));
	for(int i = 0; i < K; i++){
		C[A[i]] = B[i];
	}
	
	memset(dp, 0, sizeof(dp));
	for(int a = 1; a <= 3; a++){
		for(int b = 1; b <= 3; b++){
			for(int c = 1; c <= 3; c++){
				if((C[1] == 0 || C[1] == a) && (C[2] == 0 || C[2] == b) && (C[3] == 0 || C[3] == c)){
					if(comp(a, b, c)) dp[1][a][b][c] = 1;
				}
			}
		}
	}
	for(int a = 2; a <= N - 2; a++){
		for(int b = 1; b <= 3; b++){
			for(int c = 1; c <= 3; c++){
				for(int d = 1; d <= 3; d++){
					if(b == c && c == d) continue;
					
					if((C[a] == 0 || C[a] == b) && (C[a + 1] == 0 || C[a + 1] == c) && (C[a + 2] == 0 || C[a + 2] == d)){
						for(int x = 1; x <= 3; x++){
							if(C[a - 1] == 0 || C[a - 1] == x){
								if(comp(x, b, c)){
									dp[a][b][c][d] += dp[a - 1][x][b][c];
								}
							}
						}
					}
					
					dp[a][b][c][d] %= 10000;
				}
			}
		}
	}
	
	ans = 0;
	for(int a = 1; a <= 3; a++){
		for(int b = 1; b <= 3; b++){
			for(int c = 1; c <= 3; c++){
				ans = (ans + dp[N - 2][a][b][c]) % 10000;
			}
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 1060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int n, m, cup[15];
int ipow(int t, int p)
{
	int res = 1;
	while (p--)
		res *= t;
	return res;
}
int count(bool left_base)
{
	int res = 0;
	for (int i = 0; i < n; ++i)
	{
		if (left_base && cup[i] == 2
			|| !left_base && cup[i] == 0)
			res += 2 * ipow(3, n-1 - i);
		else if (cup[i] == 1)
		{
			res += ipow(3, n-1 - i);
			left_base ^= true;
		}
	}
	return res;
}
int main()
{
	while (scanf("%d%d", &n, &m), n|m)
	{
		for (int i = 0; i < 3; ++i)
		{
			int c;
			scanf("%d", &c);
			while (c--)
			{
				int t;
				scanf("%d", &t);
				cup[t-1] = i;
			}
		}
		int res = min(count(true), count(false));
		if (res <= m)
			printf("%d\n", res);
		else
			puts("-1");
	}
}

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

int main(){
	int n;
	cin >> n;
	cout << n * n * n << endl;
    return 0;
}



Measured memory_bytes: 256
let n = read_int ()
let h n = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ps = h n
let qs = h n
let fs = [|1; 1; 2; 6; 24; 120; 720; 5040|]
let g n us = let c = ref 0 in for i = 1 to n do if not us.(i) then incr c done; !c
let f a = let c, us = ref 1, Array.make 10 false in for i = 1 to n - 1 do c := !c + g (a.(i - 1) - 1) us * fs.(n - i); us.(a.(i - 1)) <- true done; !c
let _ = Printf.printf "%d\n" @@ abs (f ps - f qs)

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> ans;
vector<vector<int>> g(200005,vector<int> (0));
void dfs(int v,int p){
    for(auto i:g[v]){
        if(i==p) continue;
        ans[i] += ans[v];
        dfs(i,v);
    }
}
int main(){
    int n,q;
    cin >> n >> q;
    ans.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,q){
        int p1,x1;
        cin >> p1 >> x1;
        p1--;
        ans[p1] += x1;
    }
    dfs(0,-1);
    rep(i,n) cout << ans[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 24292
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>


#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;

typedef long long ll;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
     int n,k,l,c,d,p,nl,np;
    ll a,b;
    cin>>a>>b;
    if((a+b)%2==0)
        cout<<(a+b)/2;
    else
        cout<<"IMPOSSIBLE";



}


Measured memory_bytes: 3632
import java.util.*;
class Main {
    static int n ;
    static int m ;
    static int q;
    static int ans = 0;
    static int[] a,b,c,d;
    static List<Integer> A = new ArrayList<>();
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        m = scan.nextInt();
        q = scan.nextInt();
        a = new int[q];
        b = new int[q];
        c = new int[q];
        d = new int[q];
        for(int i = 0;i<q;i++){
            a[i]=scan.nextInt();
            b[i]=scan.nextInt();
            c[i]=scan.nextInt();
            d[i]=scan.nextInt();
        }
        A.add(1);
        dfs(A);
        System.out.println(ans);
}
static void dfs(List<Integer> A) {
    if(A.size() == n) {
        int temp = 0;
        for(int i = 0; i < q; i++) {
            if(A.get(b[i]-1)-A.get(a[i]-1) == c[i])
                temp += d[i];
        }
        ans = Math.max(ans, temp);
        return;
    }
    int x = A.get(A.size()-1);
    for(int i = x; i <= m; i++){
        A.add(i);
        dfs(A);
        A.remove(A.size()-1);
    }
}
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for(int i=0; i<M; i++){
        cin >> A.at(i) >> B.at(i);
    }
    
    int count=0;
    vector<int> result(N);
    for(int j=0; j<N; j++){
    for(int i=0; i<M; i++){
        if(A.at(i)==j+1 || B.at(i)==j+1){
            count+=1;
        }
        
    }
        result.at(j)=count;
        count=0;
        }

    for(int i=0; i<N; i++){
        cout << result.at(i) << endl;
        
    }
    return 0;
}



Measured memory_bytes: 256