akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  map<char, int> dict = {
    { 'I', 1 },
    { 'V', 5 },
    { 'X', 10 },
    { 'L', 50 },
    { 'C', 100 },
    { 'D', 500 },
    { 'M', 1000 },
  };
  
  string s;
  while (cin >> s) {
    int n = s.size();
    if (n == 1) {
      cout << dict[s[0]] << '\n';
      continue;
    }
    int ans = 0;
    rep(i, n) {
      if (i + 2 <= n) {
        if (dict[s[i]] < dict[s[i + 1]]) {
          ans += dict[s[i + 1]] - dict[s[i]];
          i++;
          continue;
        }
      }
      ans += dict[s[i]];
    }
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include<cmath>
#include <ctype.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <stack>
#define ll long long
#define endl '\n'
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(x: int, y: int):
    g = [4, 6, 9, 11]
    ret = YES
    if x == 2 or y == 2:
        ret = NO
    elif x in g and not y in g or y in g and not x in g:
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,a[100010];
map <int,int> M;
int main()
{
	int Ans=0;
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),M[a[i]]++;	
	for(int i=1;i<=n;i++)
	{
		Ans=max(Ans,M[a[i]]+M[a[i]-1]+M[a[i]+1]);
	}
	cout << Ans << endl;
	return 0 ;
}

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

int main() {
  int count = 0;
  int N;
  string S;
  cin >> N >> S;
  string k[3];
  for (int keta1 = 0; keta1 < 10; keta1++) {
    k[0] = to_string(keta1);
    for (int keta2 = 0; keta2 < 10; keta2++) {
      k[1] = to_string(keta2);
      for (int keta3 = 0; keta3 < 10; keta3++) {
        k[2] = to_string(keta3);
        int k_now = 0;
        for (int i = 0; i < N; i++) {
          if (k[k_now][0] == S[i])
            k_now++;
          if (k_now == 3) {
            count++;
            break;
          }
        }
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <vector>
using namespace std;

struct edge{
	int y, c, d;
};
vector<edge> G[100100], V[100100];

const int Z = 16;
int N, Q, C, S[100100], E[100100], D[100100], P[100100][Z+1];
int bit[720][100100], B, I[100100];

void go(int x, int l)
{
	S[x] = ++C;

	D[x] = D[l] + 1;
	P[x][0] = l;
	for (int i = 1; i <= Z; i++) P[x][i] = P[P[x][i - 1]][i - 1];

	for (auto &e : G[x]) if (e.y != l){
		V[e.c].push_back(e);
		go(e.y, x);
	}

	E[x] = C + 1;
}

int lca(int x, int y)
{
	if (D[x] > D[y]) swap(x, y);

	int d = D[y] - D[x];
	for (int i = 0; i <= Z; i++) if (d & (1 << i)) y = P[y][i];

	if (x != y){
		for (int i = Z; i >= 0; i--) if (P[x][i] != P[y][i]){
			x = P[x][i];
			y = P[y][i];
		}
		x = P[x][0];
	}
	return x;
}

void push(int *b, int x, int p)
{
	while (x <= N){
		b[x] += p;
		x += x & (-x);
	}
}

int pop(int *b, int x)
{
	int r = 0;
	while (x){
		r += b[x];
		x -= x & (-x);
	}
	return r;
}

int main()
{
	scanf ("%d %d", &N, &Q);
	for (int i = 1; i < N; i++){
		int x, y, c, d; scanf ("%d %d %d %d", &x, &y, &c, &d);
		G[x].push_back({ y,c,d });
		G[y].push_back({ x,c,d });
	}

	go(1, 0);
	
	for (int i = 1; i < N; i++){
		for (auto &e : V[i]){
			push(bit[0], S[e.y], e.d);
			push(bit[0], E[e.y], -e.d);
		}
		if (V[i].size() >= 300){
			I[i] = ++B;
			for (auto &e : V[i]){
				push(bit[B], S[e.y], -e.d);
				push(bit[B], E[e.y], e.d);
				push(bit[360+B], S[e.y], 1);
				push(bit[360+B], E[e.y], -1);
			}
		}
	}

	while (Q--){
		int c, d, x, y;
		scanf ("%d %d %d %d", &c, &d, &x, &y);
		int z = lca(x, y);

		if (V[c].size() < 300){
			for (auto &e : V[c]){
				push(bit[0], S[e.y], d - e.d);
				push(bit[0], E[e.y], e.d - d);
			}
			int r = pop(bit[0], S[x]) + pop(bit[0], S[y]) - 2 * pop(bit[0], S[z]);
			printf ("%d\n", r);
			for (auto &e : V[c]){
				push(bit[0], S[e.y], e.d - d);
				push(bit[0], E[e.y], d - e.d);
			}
		}
		else{
			int i = I[c];
			int r = pop(bit[0], S[x]) + pop(bit[0], S[y]) - 2 * pop(bit[0], S[z]);
			r += pop(bit[i], S[x]) + pop(bit[i], S[y]) - 2 * pop(bit[i], S[z]);
			i += 360;
			r += (pop(bit[i], S[x]) + pop(bit[i], S[y]) - 2 * pop(bit[i], S[z])) * d;
			printf ("%d\n", r);
		}
	}

	return 0;
}


Measured memory_bytes: 28416
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

N, A = map(int, input().split())
x = readints()

sum = 0
for i in range(N):
    sum += x[i]

dp = [[[0]*(3000) for _ in range(55)] for _ in range(55)]
dp[0][0][0] = 1
for i in range(N):
    for j in range(N+1):
        for k in range(2900):
            dp[i+1][j][k] += dp[i][j][k]
            if k >= x[i]:
                dp[i+1][j+1][k] += dp[i][j][k-x[i]]
ans = 0
for j in range(1, N+1):
    ans += dp[N][j][j*A]
print(ans)


Measured memory_bytes: 114012
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    ll n; cin >> n;
    if(n % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int i = 1;
    ll res = 0;
    while(1) {
        ll m = 2 * pow(5, i);
        if(n < m) break;
        else res += n / m;
        i++; 
    }
    cout << res << endl;
}

Measured memory_bytes: 512
#k,x = map(int,input().split())	
n= int(input())
arr = list(map(int,input().split()))
keys = []
for _ in range(1,n+1):
    keys.append(_)
#print(keys)

values = [0]*(n+1)
dic = {k: v for k, v in zip(keys, values)}
#print(dic)
for i in range(n-1): #各単語の出現回数を数える
 if arr[i] not in dic:
   dic[arr[i]]=1
 else:
   dic[arr[i]]+=1
#print(dic)  # -> {'a': 2, 'b': 3}
for i in dic.values():
    print(i)


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

using ll = long long;
const ll INF = 1e18;

using ld = long double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

/*
                    CCW

 -- BEHIND -- [a -- ON -- b] --- FRONT --

                    CW
 */
enum { CCW = +1, CW = -1, BEHIND = +2, FRONT = -2, ON = 0 };
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > eps)  return CCW;    // counter clockwise
    if (cross(b, c) < -eps) return CW;     // clockwise
    if (dot(b, c) < 0)      return BEHIND; // c--a--b on line
    if (norm(b) < norm(c))  return FRONT;  // a--b--c on line
    return ON;
}


namespace std {
    bool operator < (const P& a, const P& b) {
        return abs(real(a) - real(b)) > eps ? real(a) < real(b) : imag(a) < imag(b);
    }
}

G andrewScan(G ps){
    int N = ps.size(), k = 0;
    sort(ps.begin(), ps.end());
    G res(N*2);
    for(int i=0; i<N; i++) {
        while(k>=2 && ccw(res[k-2], res[k-1], ps[i])!=CCW) k--;
        res[k++] = ps[i];
    }
    int t = k+1;
    for(int i=N-2; i>=0; i--) {
        while(k>=t && ccw(res[k-2], res[k-1], ps[i])!=CCW) k--;
        res[k++] = ps[i];
    }
    res.resize(k-1);
    return res;
}

int n;
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
int x[100010], y[100010];

using pii = pair<int,int>;
set<pii> S;

G g;

int main(){
    while(cin >> n){
        S.clear();
        rep(i,n-1){
            int k,d;
            cin >> k >> d;
            x[i+1] = x[k] + dx[d];
            y[i+1] = y[k] + dy[d];
        }
        rep(i,n){
            S.emplace(x[i],   y[i]);
            S.emplace(x[i]+1, y[i]);
            S.emplace(x[i],   y[i]+1);
            S.emplace(x[i]+1, y[i]+1);
        }
        g.clear();
        for(auto &p : S) g.emplace_back(p.first, p.second);
        g = andrewScan(g);

        deque<P> a(g.begin(), g.end());
        int k = a.size();
        ld ans = INF;
        rep(i,k){
            P base = a[1] - a[0];
            base /= abs(base);
            ld min_x = +INF, max_x = -INF;
            ld min_y = +INF, max_y = -INF;
            rep(i,k){
                ld x = real(a[i]/base);
                ld y = imag(a[i]/base);
                min_x = min(min_x, x);
                min_y = min(min_y, y);
                max_x = max(max_x, x);
                max_y = max(max_y, y);
            }
            ld dx = max_x - min_x;
            ld dy = max_y - min_y;
            ans = min(ans, dx*dy);
            a.push_back(a.front());
            a.pop_front();
        }
        cout << fixed << setprecision(10) << ans << endl;
    }
}

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

int main(){
    long long x; cin >> x;
    long long count;
    count=x/11*2;
    if (x%11!=0){//余りがあって
        if (x%11<=6) count++;
        else count+=2;
    }
    /*if (x<=6){
        cout << 1 << endl;
    } else if (x<=11){
        cout << 2 << endl;
    } else {
        cout << (x/11)*2+1 << endl;
    }*/
    cout << count << endl;
    return 0;
}

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

const int MOD = (int)1e9+7;

int main(){
	int H,W;
	cin >> H >> W;
	vector<vector<int>> A(H,vector<int>(W));
	vector<vector<int>> B(H,vector<int>(W));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++)	cin >> A.at(i).at(j);
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++)	cin >> B.at(i).at(j);
	}

	vector<vector<int>> C(H,vector<int>(W));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			C.at(i).at(j)=abs(A.at(i).at(j)-B.at(i).at(j));
		}
	}
	vector<vector<vector<bool>>> dp(H,vector<vector<bool>>(W,vector<bool>(82*(H+W),false)));
	dp.at(0).at(0).at(C.at(0).at(0))=true;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			for(int k=0;k<82*(H+W);k++){
				if(dp.at(i).at(j).at(k)==false)	continue;
				if(i+1<H){
					int xx=abs(k-C.at(i+1).at(j));
					dp.at(i+1).at(j).at(xx)=true;
					xx=abs(k+C.at(i+1).at(j));
					dp.at(i+1).at(j).at(xx)=true;
				}
				if(j+1<W){
					int xx=abs(k-C.at(i).at(j+1));
					dp.at(i).at(j+1).at(xx)=true;
					xx=abs(k+C.at(i).at(j+1));
					dp.at(i).at(j+1).at(xx)=true;
				}
			}
		}
	}
	for(int k=0;k<82*(H+W);k++){
		if(dp.at(H-1).at(W-1).at(k)==true){
			cout << k << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 11008
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def f(a, s, n):
    if s[-1] == "1":
        return 1

    X = max(a).bit_length()
    B = [None] * X
    for i in range(n-1, -1, -1):
        ai, si = a[i], s[i]

        if si == "0":
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai: break
                elif B[x] == None:
                    B[x] = ai
                    X -= 1
                    if X == 0:
                        return 0
                    break
                ai ^= B[x]
        else:
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai: break
                elif B[x] == None:
                    return 1
                ai ^= B[x]
    return 0


def resolve():
    T = int(input())

    ans = []
    for i in range(T):
        N = int(input())
        A = list(iim())
        S  = input()

        ans.append(f(A, S, N))

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


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

int main(int argc, char const *argv[])
{
    int n, k;
    cin >> n >> k;
    long long res = k;
    for (int i = 1; i < n; i++)
    {
        res *= (k - 1);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 #include <iomanip>
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

int n,m;
int vis[222222];
void solve(istream& cin, ostream& cout) {
	ll K;
	cin >>n>>K;
	vector<int> A(n);
	memset(vis, -1, sizeof(vis));
	cin >> A;
	REP(i, n) A[i]--;
	int c = 0;
	vector<int> cycle;
	int steps = 0;
	while(vis[c] == -1) {
		vis[c] = steps;
		cycle.pb(c);
	//	cout << c<<endl;
		c = A[c];
		steps++;
		if(steps == K) {
			cout << c+1 <<endl;
			return;
		}
	}
	K -= vis[c];
	int cyclen = steps-vis[c];
	cout <<cycle[(int)cycle.size()-cyclen+(K%cyclen)]+1<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 5468
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;


int main(int argc, char* argv[]) {

	long long D,N;

	cin >> D >> N;

	cout << (long long)(pow((double)100,(double)D)) * (N != 100 ? N : 101) << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int main(){
    int n;
    int c=0;
    bool f=true;
    cin>>n;
    REP(i,n){
        string s;
        cin>>s;
        if(s=="A")c++;
        else c--;
        if(c<0){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    if(c==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
using namespace std;

int main(){
  double N,K;
  cin >> N >> K;

  cout << ( ceil((N-K)/(K-1))+1 ) << endl;



  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int main(int argc, const char * argv[]) {
  string s;
  cin >> s;
  int a[20] = {0};

  for (int i = 0; i < s.size(); i++) {
    a[i] = s[i] - '0';
  }

  int n = s.size() -1;
  ll ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    ll t = a[0];
    for (int j = n - 1; j >= 0; j--) {
      if (i & (1 << j)) {
        ans += t;
        t = a[n - j];
      } else {
        t = t * 10 + a[n - j];
      }
    }
    ans += t;
  }
  cout << ans << endl;
  return 0;
}

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

namespace Favorite_Sound
{
    public class Program
    {
        static void Main(string[] args)
        {
            string[] n = Console.ReadLine().Split(' ');
            int[] num = n.Select(int.Parse).ToArray();
            Console.WriteLine(Solve(num));
        }

        public static int Solve(int[] n)
        {
            int count = 0;
            for (; n[0] <= n[1];)
            {
                n[1] -= n[0];
                ++count;
                if (count == n[2])
                {
                    break;
                }
            }
            return count;
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
 
using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
const int MOD = 1000000007;
double PI = 4*atan(1);

ll get(ll sum) {
	int cur = 0;
	while (sum>0) {
		cur++;
		sum -= cur;
	}
	return cur;
}

int main() {
	ll sum; cin >> sum;
	sum = abs(sum);
	cout << get(sum);
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    ans = 0
    for i in range(n):
        ans += a[a[i] - 1] - 1 == i
    print(ans//2)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 53136
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
long long A[300][300];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) rep(j, N) cin >> A[i][j];
  long long s = 0;
  rep(x, N) {
    rep(y, x) {
      long long m = 1LL<<60;
      rep(t, N) {
        if (t == x || t == y) continue;
        m = min(m, A[x][t] + A[t][y]);
      }
      if (m < A[x][y]) {
        cout << -1 << "\n";
        return 0;
      }
      if (m != A[x][y]) s += A[x][y];
    }
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
 
int main()
{  
  int W, a, b, move_length;
  std::cin >> W >> a >> b;

  int a_end = a + W;
  int b_end = b + W;
  
  if((a <= b && b <= a_end) || (a <= b_end && b_end <= a_end))
  {
     move_length = 0;
  }
  else
  {
    if(a_end < b)
    {
      move_length = b - a_end;
    }
    else
    {
      move_length = a - b_end;    
    }
  }
  
  std::cout << move_length;
  return 0;
}

Measured memory_bytes: 3196
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        int n, k;
        cin >> n >> k;
        vl l(n);
        rep(i, n) cin >> l[i];
        sort(all(l), greater<>());
        ll ans = 0;
        rep(i, k) ans += l[i];
        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 764
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int count,i;
		Set<Character> left=new TreeSet<Character>();
		Set<Character> right=new TreeSet<Character>();
		Set<Character> now=new TreeSet<Character>();
		
		left.add('q');left.add('w');left.add('e');
		left.add('r');left.add('t');left.add('a');
		left.add('s');left.add('d');left.add('f');
		left.add('v');left.add('b');left.add('g');
		left.add('c');left.add('x');left.add('z');
		
		right.add('y');right.add('u');right.add('i');
		right.add('h');right.add('p');right.add('o');
		right.add('j');right.add('k');right.add('l');
		right.add('n');right.add('m');
		
		while(true){
			count=0;
			char[] ch=sc.next().toCharArray();
			if(ch[0]=='#') break;
			if(left.contains(ch[0])){
				now=left;
			}
			else{
				now=right;
			}
			for(i=1;i<ch.length;i++){
				if(now.contains(ch[i])){
					continue;
				}
				else{
					count++;
					if(now.equals(left)){
						now=right;
					}
					else{
						now=left;
					}
				}
			}//for
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 12000
n = int(input())
V = list(map(int, input().split()))

from collections import Counter

v = Counter(V).most_common()

if len(v)==1:
    print(n//2)
    
else:
    even = [V[2*i] for i in range(n//2)]
    odd = [V[2*j+1] for j in range(n//2)]
    
    e = Counter(even).most_common()
    o = Counter(odd).most_common()
    
    if e[0][0]!=o[0][0]:
        print(n-e[0][1]-o[0][1])
    else:
        sec = v[1][0]
        esec = even.count(sec)
        osec = odd.count(sec)
        print(n-max(esec+o[0][1], osec+e[0][1]))

Measured memory_bytes: 28248
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define show(x) cout << #x << " = " << x << endl;
int main(){
    int n;
    cin >> n;
    vector<int>d(n+1);
    rep(i,n){
        cin >> d[i];
    }
    d[n] = 0;
    int cnt[13] = {};
    n++;
    rep(i,n){
        cnt[d[i]]++;
        if(cnt[d[i]]>=3){
            cout << 0 << endl;
            return 0;
        }
    }
    
    if(cnt[0]>=2){
        cout << 0 << endl;
        return 0;
    }
    rep(i,n){
        if(cnt[d[i]]==2){
            cnt[d[i]]--;
            d[i] = 24-d[i];
        }
    }
    int ans = -1;
    rep(i,1<<11){
        vector<int>a = d;
        rep(j,n){
            if(a[j] > 0 and a[j] < 12 and (i &(1<<(a[j]-1)))){
                a[j] = 24 -a[j];
            }
        }
        int temp = 1000;
        rep(j,n){
            rep(k,n){
                if(k!=j)temp = min(temp,min(abs(a[j]-a[k]),24-abs(a[j]-a[k])));
            }
        }
        ans = max(ans,temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int t;
    cin >> t;
    vl l{2, 3, 5};
    while (t--) {
        ll n, a, b, c, d;
        cin >> n >> a >> b >> c >> d;
        vl p{0, 1, a, b, 4, c};
        ll lim = LINF / d;
        map<ll, ll> memo;
        function<ll(ll)> rec = [&](ll m) {
            if (m == 0) return 0LL;
            if (m == 1) return d;
            if (memo.count(m)) return memo[m];
            ll ret = LINF;
            if (m <= lim) ret = d * m;
            for (auto k : l) {
                ll r = m % k;
                chmin(ret, p[k] + d * r + rec(m / k));
                chmin(ret, p[k] + d * (k - r) + rec((m + k - 1) / k));
            }
            return memo[m] = ret;
        };
        cout << rec(n) << endl;
    }
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long a, long long b, long long c){
	int s[3];
	s[0] = a;
	s[1] = b;
	s[2] = c;
	sort(s,s+3);
	if(s[0]+s[1]==s[2]){
		cout << YES << endl;
	}else{
		cout << NO << endl;
	}

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    solve(a, b, c);
    return 0;
}


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

int a[201][201];
int n;

int visited[201] = {0};

int bfs(int k)
{
	memset(visited,0,sizeof(visited));
	visited[k] = 1;
	queue<int> q;
	q.push(k);
	while(!q.empty())
	{
		int l = q.front();
		q.pop();
		for (int i = 0; i < n; i++)
		{
			if(a[l][i] == 1 and visited[i] == 0)
			{
				visited[i] = visited[l] + 1;
				q.push(i);
			}
			if(a[l][i] == 1 and visited[i] != 0)
			{
				if(abs(visited[l] - visited[i]) != 1) return -1;
			}
		}
	}
	// cout<<"a"<<endl;
	int maxi = -1;
	for (int i = 0; i < n; ++i)
	{
		if(visited[i] > maxi) maxi = visited[i];
	}
	return maxi;
}

int main()	
{
	int m = 0;
	cin>>n;
	string s[n];
	memset(a,0,sizeof(a));
	for (int i = 0; i < n; ++i)
	{
		cin>>s[i];
		for(int j = 0; j < n; j++)
		{
			if(s[i][j] == '1')
			{
				a[i][j] = 1;
			}
		}
	}
	// cout<<m<<endl;
	// if(m > n - 1) cout<<-1<<endl;
	// else 	
	int maxi = -1;
	for (int i = 0; i < n; ++i)
	{
		maxi = max(maxi,bfs(i));
	}
	cout<<maxi<<endl;
	
	return 0;
}

Measured memory_bytes: 512
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 10 ** 10
for i in range(n - k + 1):
    left = x[i]
    right = x[i + k - 1]
    ans = min(ans, abs(left) + abs(right - left), abs(right) + abs(right - left))

print(ans)


Measured memory_bytes: 14252
import numpy

def main():
    N = [int(_) for _ in input().split()]
    D = N[0]
    G = N[1]
    Q = [[int(_) for _ in input().split()] for i in range(D)]

    arr = []
    for i in range(2 ** D):
        total_score = 0
        num_kaitou = 0
        #完答した時の合計得点を計算
        for j in range(D):
            if ((i >> j) & 1 == 1):
                total_score += 100 * (j+1) * Q[j][0] + Q[j][1]
                num_kaitou += Q[j][0]
        #目標スコアを満たす場合にはスキップ
        if total_score >= G:
            arr.append([num_kaitou, total_score])
            continue
        #満たない場合には大きい方から得点をつめる
        else:
            for j in reversed(range(D)):
                increment = 100 * (j+1)
                if ((i >> j) & 1 == 0):
                    for k in range(Q[j][0]):
                        total_score += increment
                        num_kaitou += 1
                        if total_score >= G:
                            arr.append([num_kaitou, total_score])
                            break
                    else:
                        continue
                    break
    #全パターンから目標点に到達する中で最小回答数を取得する
    print(numpy.min(arr, axis=0)[0])

if __name__ == "__main__":
    main()


Measured memory_bytes: 13528
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int A, B;
            cin >> A >> B;
                if((A + B) % 2 == 0){
                    cout << (A + B) / 2 << endl;
                }else{
                    cout << "IMPOSSIBLE" << endl;
                }
    return 0;}

Measured memory_bytes: 256
N = int(input())
S = str(input())

alpha2num = lambda c : ord(c) - ord('A') + 1
num2alpha = lambda c : chr(c+64)

change_list = []
for alpha in [i for i in S]:
    num = alpha2num(alpha)
    if num + N > 26:
        num = num + N - 26
    else:
        num = num + N
    change_list.append(num2alpha(num))

print(''.join(change_list))

Measured memory_bytes: 3188
N = int(input())
Hlist = list(map(int,input().split()))

start = Hlist[-1]
for n in range(N-1):
    i = N-2-n
    if start>Hlist[i]:
        start = Hlist[i]
    elif start==Hlist[i]:
        start = Hlist[i]
    elif start>=Hlist[i]-1:
        start = Hlist[i]-1
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 15020
d,g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

for bit in range(1 << d):
    total = 0
    count = 0
    left = set(range(1, d+1))

    for i in range(d):
        if bit & (1 << i):
            total += pc[i][0] * 100 * (i+1) + pc[i][1]
            count += pc[i][0]
            left.discard(i+1)
            #使ったものとして記憶

    if g > total:
        target = max(left)
        n = min(pc[target - 1][0], -(-(g - total) // (target * 100)))#切り上げ
        count += n
        total += n * target * 100
    #この下とはつながっていない

    if g <= total:
        ans = min(ans, count)

print(ans)

Measured memory_bytes: 3064
/*
 * a[i]=2^x[i]
 *
 * sum(x)<=x[i]*b[i]
 *
 * sum(x)>=count(x)
 */

/*
 *
 */

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    string s;

    int n;

    cin >> s;
    cin >> n;

    for (int i =0;i<s.size();i++) {
        int edToA = 'z' - s[i] + 1;
        if (s[i]!='a' && n - edToA >= 0) {
            n -= edToA;
            s[i]='a';
        }
    }

    if (n!=0) {
        char c = (s[s.size()-1] + n%26);
        s[s.size()-1] = c;
    }

    cout << s << endl;

    return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main(){
  int n; cin >> n;
  vi p(n);
  map<int,int> mp;
  rep(i,n){
    cin >> p[i];
    mp[p[i]] = i;
  }
  int ans = 0;
  int prevpos;
  int l = 1;
  for(auto x : mp){
    if(x.fst == 1){
    }else if(prevpos < x.snd){
      l++;
    }else if(prevpos > x.snd){
      l = 1;
    }
    prevpos = x.snd;
    ans = max(ans,l);
    dump(l,ans);
  }
  cout << n - ans << endl;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int k, t, ai;
 
int ans;
 
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> k >> t;
    vector<int> a(t);
    for(auto& i : a) cin >> i;
    sort(a.begin(), a.end(), greater<int>());
    
    int tot = 0;
    for (int i = 1; i < t; i++) tot += a[i];
    cout << max(0, a[0] - 1 - tot);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> w(N),s(N),v(N);
  for(int i=0;i<N;i++){
    cin >> w.at(i) >> s.at(i) >> v.at(i);
  }

  vector<pair<int,int>> xi(N);
  for(int i=0;i<N;i++)  xi.at(i)=mp(s.at(i)+w.at(i),i);
  sort(all(xi));
  vector<vector<ll>> dp(N+1,vector<ll>(1e5,0));
  for(int i=1;i<N+1;i++){
    int now=xi.at(i-1).se;
    int wi=w.at(now);
    int si=s.at(now);
    ll vi=v.at(now);
    //cout << wi << "," << si << "," << vi << endl;
    for(int j=0;j<1e5;j++){
      dp.at(i).at(j)=dp.at(i-1).at(j);
      if(0<=j-wi && j-wi<=si) chmax(dp.at(i).at(j),dp.at(i-1).at(j-wi)+vi);
    }
    //for(int j=0;j<10;j++) cout << dp.at(i).at(j) << " ";cout << endl;
  }
  ll ans=0;
  for(int i=0;i<1e5;i++)  chmax(ans,dp.at(N).at(i));
  cout << ans << endl;

  return 0;
}

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

bool is_prime(int n) {
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (int i = 3; i < pow(n, 0.5) + 1; i+=2) {
        if (n % i == 0) {
            return false;
        }
    }
}

int main() {
    int x;
    cin >> x;  
    int ans = x;
    while (true) {
        if (is_prime(ans))
            break; 
        ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 61;
const long long int MOD = 1000000007;
int A[MAXN];
long long int dp[MAXN][2][2][2][2][2][2];
long long int DP(int pos, int upos, int vpos, bool loU, bool loV, int c_out, int c_in)
{
	if(pos == -1)
	{
		if(!c_out && !c_in && !upos && !vpos)
			return 1;
		return 0;
	}
	if(!loU && upos > A[pos])
		return 0;
	if(!loV && vpos > A[pos])
		return 0;
	// cout<<"enter "<<pos<<": "<<upos<<" "<<vpos<<" "<<loU<<" "<<loV<<" "<<c_out<<" "<<c_in<<"\n";
	long long int& ans = dp[pos][upos][vpos][loU][loV][c_out][c_in];
	if(ans != -1)
		return ans;
	ans = 0;
	for (int apos = 0; apos < 2; ++apos)
	{
		for (int bpos = apos; bpos < 2; ++bpos)
		{
			int temp = apos + bpos + c_in;
			if((temp/2) == c_out && (temp%2) == vpos && (apos^bpos) == upos)
			{
				bool nuU = (loU || (upos < A[pos]));
				bool nuV = (loV || (vpos < A[pos]));
				for (int mask = 0; mask < 8; ++mask)
				{
					int i = ((mask & (1<<0))?1:0);
					int j = ((mask & (1<<1))?1:0);
					int k = ((mask & (1<<2))?1:0);
					ans = (ans + DP(pos-1,i,j,nuU,nuV,c_in,k))%MOD;
				}
			}
		}
	}
	// cout<<"exit "<<pos<<": "<<upos<<" "<<vpos<<" "<<loU<<" "<<loV<<" "<<c_out<<" "<<c_in<<": "<<ans<<"\n";
	return ans;
}
int main()
{
	long long int n;
	cin>>n;
	for (int i = 0; i < MAXN; ++i)
	{
		if(n & (1ll<<i))
			A[i] = 1;
		else
			A[i] = 0;
	}
	memset(dp, -1, sizeof dp);
	// DP(1,1,1,0,0,0,0);
	int sp = MAXN-1;
	long long int ans = (DP(sp,0,0,false,false,0,0) + DP(sp,0,0,false,false,0,1))%MOD;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

constexpr int MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	V[s] = true;
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		out.emplace_back(u);
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]--;
			if (indeg[v] == 0 && !V[v]) {
				V[v] = true;
				q.push(v);
			}
		}
	}
}
void tsort() {
	for (int i = 0; i < N; i++) {
		indeg[i] = 0;
	}

	for (int u = 0; u < N; u++) {
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]++;
		}
	}

	for (int u = 0; u < N; u++) {
		if (indeg[u] == 0 && !V[u])bfs(u);
	}
	for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
		cout << *it << endl;
	}
}

int main() {
	int s, t, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		V[i] = false;
	}
	for (int i = 0; i < M; i++) {
		cin >> s >> t;
		G[s].emplace_back(t);
	}
	tsort();
}

Measured memory_bytes: 6152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  string t;
  rep(qi, q){
    int ty;
    cin >> ty;
    if(ty == 1){
      swap(s, t);
    }else{
      int f;
      char c;
      cin >> f >> c;
      if(f == 1){
        t = t + c;
      }else{
        s = s+c;
      }
    }
  }
  reverse(t.begin(), t.end());
  t = t + s;
  cout << t << endl;
}

Measured memory_bytes: 1708
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    a = LIR(n-1)
    for i in range(n):
        t = 0
        x = i
        while x < n-1:
            if t < a[x][1]:
                t = a[x][1]
            t += (a[x][2]-t)%a[x][2]
            t += a[x][0]
            x += 1
        print(t)

#D
def D():
    def check(n):
        if n == 1:
            return False
        i = 2
        while i*i <= n:
            if n%i == 0:
                return False
            i += 1
        return True
    f = [0 for i in range(100001)]
    for i in range(1,100001):
        f[i] += f[i-1]
        if check(i):
            if check((i+1)//2):
                f[i] += 1
    q = I()
    for i in range(q):
        l,r = LI()
        print(f[r]-f[l-1])

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 40944
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
    string s;cin >> s;
    int w = 0,r = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if(i%2==1){
            if(s[i] == 'g')w++;
        }else{
            if(s[i] == 'p')r++;
        }
    }
    cout<<w-r<<endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[100000], b[100003];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) {
		b[a[i] + 0]++;
		b[a[i] + 1]++;
		b[a[i] + 2]++;
	}
	
	int ans = 0;
	inc(i, 100003) { setmax(ans, b[i]); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  long long int N = 0, ans = 0 ;
  long long int K ;
  cin >> K ;
  if((K % 2 == 0) || (K % 5 == 0) ){
    cout << -1 << endl ;
    return 0 ;
  }
  while(1){
    ans++ ;
    N = (N * 10) % K + 7 ;
    if(N % K == 0) break ;
  }
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 3588
#include  <cmath>
#include  <fstream>
#include  <iostream>
using namespace std;

int main(void)
{
    int N, M;
    cin >> N >> M;
    if(N ==M)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;

}


Measured memory_bytes: 256