akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
string a,b,c;

int main(){
    cin >> a >> b >> c;
    int x=-1,y=-1,z=-1,turn=111;
    while(1){
        if(turn==111){
            x++;
            if(a[x]=='a'){
                turn =111;
            }else if(a[x]=='b'){
                turn =222;
            }else if(a[x]=='c'){
                turn =333;
            }
        }else if(turn==222){
            y++;
            if(b[y]=='a'){
                turn =111;
            }else if(b[y]=='b'){
                turn = 222;
            }else if(b[y]=='c'){
                turn=333;
            }
        }else if(turn ==333){
            z++;
            if(c[z]=='a'){
                turn=111;
            }else if(c[z]=='b'){
                turn=222;
            }else if(c[z]=='c'){
                turn =333;
            }
        }
        //cout << x << " " <<y<<" "<<z<<"\n";
        if(x==a.length()){
            cout << "A";
            break;
        }else if(y==b.length()){
            cout << "B";
            break;
        }else if(z==c.length()){
            cout << "C";
            break;
        }
        
    }
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll X, Y, Z, K;
ll A[1005];
ll B[1005];
ll C[1005];

vector<ll> v;

int main() {
    cin >> X >> Y >> Z >> K;
    REP(i, X) {
        cin >> A[i];
    }
    REP(i, Y) {
        cin >> B[i];
    }
    REP(i, Z) {
        cin >> C[i];
    }
    sort(A, A + X, [](ll a, ll b) { return a > b; });
    sort(B, B + Y, [](ll a, ll b) { return a > b; });
    sort(C, C + Z, [](ll a, ll b) { return a > b; });

    vector<ll> vv;
    REP(i, X) {
        REP(j, Y) {
            vv.push_back(A[i] + B[j]);
        }
    }
    sort(vv.begin(), vv.end(), [](ll a, ll b) { return a > b; });
    REP(i, std::min(K, (ll) vv.size())) {
        REP(j, Z) {
            v.push_back(vv[i] + C[j]);
        }
    }
    sort(v.begin(), v.end(), [](ll a, ll b) { return a > b; });
    REP(i, K) {
        cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 43236
-- AtCoder My Practice
-- author: Leonardone @ NEETSDKASU
 
-- 解説読後
-- http://agc004.contest.atcoder.jp/data/agc/004/editorial.pdf

import qualified Data.ByteString.Char8 as C
import Data.Maybe

-- fromJustとかいうの初めて知った
 
main = print . solve . map (fst . fromJust . C.readInt) . C.words =<< C.getContents

solve (n:x:a) = ans where
    sm = sum a
    ans = f [2..n] sm a x
    f [] r _  _  = r
    f (_:xs) r ar xx = f xs r2 ar2 (xx + x) where
        ar2 = zipWith min a $ [last ar] ++ ar
        r2 = min r (xx + sum ar2)


Measured memory_bytes: 1148
n, m = map(int, input().split())

a = []
b = []
sa = n-m
ans = 0

for i in range(n):
    a.append(input())

for i in range(m):
    b.append(input())

for i in range(sa+1):
    for j in range(sa+1):
        for p in range(m):
            if a[i+p][j:j+m] != b[p]:
                break
            if p == m-1:
                ans = 1
        if ans == 1:
            break
    if ans == 1:
        break
if ans == 1:
    print('Yes')
else :
    print('No')

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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int l;cin>>l;
  for(int i=1;;i++){
    if((l*i)%360==0)fin(i);
  }
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) {
	a = min(a, b);
}
void mmax(int &a, int b) {
	a = max(a, b);
}
void sor(vel &v) {
	sort(v.begin(), v.end());
}
int ser(vel &v, int tan) {
	int si = v.size() - 1;
	if (tan == v[si]) {
		return si;
	}
	int lo = 0;
	int up = si;
	while (up - lo > 1) {
		int mi = (lo + up) / 2;
		if (v[mi] <= tan) {
			lo = mi;
		}
		else {
			up = mi;
		}
	}
	return lo;
}
int di(int st, int to, vel &sa) {
	return sa[to] - sa[st];
}
int ni(int st, int to, vel &sa) {
	int se = sa[to] - sa[st];
	int lo = st;
	int up = to;
	while (up - lo > 1) {
		int mi = (lo + up) / 2;
		if (di(st, mi, sa) * 2 < se) {
			lo = mi;
		}
		else {
			up = mi;
		}
	}
	int ans = 0;
	if (lo > st) {
		mmax(ans, (sa[lo] - sa[st]));
	}
	if (up < to) {
		mmax(ans,(sa[to] - sa[up]));
	}
	return ans;
}
signed main() {
	int n;
	cin >> n;
	vel a(n);
	vel sa(2*n);
	sa[0] = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < 2 * n; i++) {
		sa[i] = sa[i - 1] + a[(i - 1)%n];
	}
	int sum = sa[n];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int st = i + 2;
		int to = n + i;
		if (ni(i, st, sa) > di(st, to,sa)) {
			mmax(ans, di(st, to, sa));
		}
		else {
			while (to - st > 1) {
				int mi = (to + st) / 2;
				if (ni(i, mi, sa) > di(mi, i + n, sa)) {
					to = mi;
				}
				else {
					st = mi;
				}
			}
			mmax(ans, ni(i, st, sa));
			if (to < n + i) {
				mmax(ans, di(to, n + i, sa));
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 5224
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var N, D, X int
	fmt.Scan(&N)
	fmt.Scan(&D, &X)
	A := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	// first
	sum += N
	for i, v := range A {
		for d := 2; d <= D; d++ {
			if d == A[i]+1 {
				sum++
				A[i] += v
			}
		}
	}
	ans := sum + X

	fmt.Fprintln(wtr, ans)
	_ = wtr.Flush()
}


Measured memory_bytes: 1848
/* be name Khoda */
#include <bits/stdc++.h>
using namespace std;

const int N = 100 * 1001;
int n, a[N];

void solve(int cnt) {
	int odd = 0, odd_n = -1;
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (a[i] % 2) {
			odd++;
			odd_n = a[i];
		}
	}
	if ((sum - n) % 2) {
		if (cnt % 2)
			cout << "Second\n";
		else
			cout << "First\n";
		exit(0);
	}
	else if (odd == 1 && odd_n != 1) {
		int gcd = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] % 2) 
				a[i]--;
			gcd = __gcd(gcd, a[i]);
		}
		for (int i = 0; i < n; i++) 
			a[i] /= gcd;
		solve(cnt + 1);
	}
	if (cnt % 2) 
		cout << "First\n";
	else
		cout << "Second\n";
	exit(0);
}


int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	solve(0);
}

Measured memory_bytes: 4016
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


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

    long ans=0;
    long max=-1;
    long i;
    for(i=1; i<=n; i++) {
        long tmp=i;
        long count=0;
        while(tmp%2==0) {
            tmp /= 2;
            count ++;
        }
        if(max<count) {
            max=count;
            ans = i;
        }
    }
    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[]) {
  ll A, B, C;
  cin >> A >> B >> C;
  if (A + B >= C - 1)
    cout << B + C << endl;
  else {
    cout << B + B + A + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 888
import sys

def solve(h, w):
  res = [((h + 2) // 3 - h // 3) * w]
  for d in [h // 3, (h + 2) // 3]:
    cand = sorted([d * w, (h - d) * (w // 2), (h - d) * ((w + 1) // 2)])
    res.append(cand[-1] - cand[0])
  return min(res)

h, w = map(int, sys.stdin.readline().split())

def main():
  print(min(solve(h, w), solve(w, h)))

if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
    int candy, no;
    while (cin >> candy) {
        no = (candy % 39 != 0) ? candy % 39 : 39;
        cout << "3C"; 
        cout << setw(2) << setfill('0') << no << endl;
    }
    return 0;
}

Measured memory_bytes: 1172
import sys
sys.setrecursionlimit(200000)

N = int(input())
edges = []
connected = [[] for i in range(100010)]
for i in range(N-1):
    x=list(map(int, input().split()))
    x[0] -= 1
    x[1] -= 1
    edges.append(x)
    connected[x[0]].append([x[1], x[2]])
    connected[x[1]].append([x[0], x[2]])

Q,K = map(int, input().split())
K -= 1
depth = [0]*100010
def DFS(v, p, d):
    depth[v] = d
    for child in connected[v]:
        if child[0] == p:
            continue
        DFS(child[0], v, d+child[1])

DFS(K,-1,0)
for i in range(Q):
    xi, yi = map(int, input().split())
    print(depth[xi-1]+depth[yi-1])


Measured memory_bytes: 151232
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;
//---------------------------------------------------------------
using Point = complex<double>;
using Vector = Point;
using Polygon = vector<Point>;
double dot(const Vector &a, const Vector &b) { return real(conj(a) * b); }
double cross(const Vector &a, const Vector &b) { return imag(conj(a) * b); }
struct Segment : public vector<Point> {
    Segment(const Point &a = Point(), const Point &b = Point()) : vector<Point>(2) {
        begin()[0] = a; begin()[1] = b;
    }
};
using Line = Segment;
Point project(Line s, Point p) {
    Vector base = s[1] - s[0];
    double r = dot(p - s[0], base) / norm(base);
    return s[0] + base * r;
}
//---------------------------------------------------------------

#include <cstdio>
int main() {
    double x1, y1, x2, y2, xq, yq;
    while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq)) {
        Line line(Point(x1, y1), Point(x2, y2));
        Point Q(xq, yq);
        Point R = project(line, Q) * 2.0 - Q;
        printf("%.6f %.6f\n", R.real(), R.imag());
    }
    return 0;
}


Measured memory_bytes: 2736
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;
  if(K % 2 == 0){
    cout << A - B << endl;
  }
  else{
    cout << B - A << endl;
  }
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc145/tasks/abc145_d
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

            //a=333333,b=333333
const int MAX = 510000*10;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// int main() {
//     // 前処理
//     COMinit();
//     // 計算例
//     cout << COM(100000, 50000) << endl;
//                 a=333333,b=333333
// }
int main() {
    COMinit();
#if LOCAL&0
    std::ifstream in("./test/sample-3.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll X,Y; cin>>X>>Y;
    ll ans=0;
#if 1
    do{
        ll tmp=2*Y-X;
        if(tmp%3!=0) break;
        ll a=tmp/3;
        ll b=Y-2*a;
        if (a>=0&&b>=0){
			dump(a, b);
			ans = COM(a + b, a);
        }
    }while(0);
#else
    FOR(a,0,max(X+1,Y+1)){
        ll b=Y-2*a;
        if (b>0){
            if(X==a+2*b){
                //ans
                dump(a,b);
                ans+=COM(a+b, a);
            }
        }
    }    
#endif
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 119808
import itertools
N, K = map(int, input().split())
ans = []
max_K = sum([i for i in range(N-1)])
if K > max_K:
    print(-1)
else:
    M = N-1
    for i in range(2, N+1):
        ans.append([str(1), str(i)])
    count = 0
    if K == max_K:
        print(M)
        for a in ans:
            print(' '.join(a))
    else:
        for c in itertools.combinations([str(i) for i in range
        (2, N+1)], 2):
            ans.append([c[0], c[1]])
            count += 1
            if max_K - count == K:
                break
        M += count
        print(M)
        for a in ans:
            print(' '.join(a))


Measured memory_bytes: 3844
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();

        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = l + i;
        }

        int tabeta = Integer.MAX_VALUE;
        int sum = 0;
        for (int a : arr) {
            if (Math.abs(tabeta) > Math.abs(a)) tabeta = a;
            sum += a;
        }
        System.out.println(sum - tabeta);

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

const int N = 2e5 + 100;

int n, q, ans, dex, a[N], cnt[N];
unordered_map<int, int> on;

void del(int num) {
	on[num - cnt[num]]--;
	if(num - cnt[num] >= 0 && on[num - cnt[num]] == 0)
		ans++;
	cnt[num]--;
}

void add(int num) {
	cnt[num]++;
	on[num - cnt[num]]++;
	if(num - cnt[num] >= 0 && on[num - cnt[num]] == 1)
		ans--;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
		on[a[i] - cnt[a[i]]]++;
	}
	for (int i = 0; i < n; i++)
		ans += (on[i] == 0);
	while(q--) {
		cin >> dex;
		dex--;
		int num = a[dex];
		del(num);
		cin >> a[dex];
		add(a[dex]);
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 18932
import java.util.Scanner;

class Main {

	private static final int MINUTE_SEC = 60;
	private static final int HOUR_MIN = 60;
	
	private static final String STR = ":";

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int sec = Integer.parseInt(sc.nextLine());
		
		int hourSec = MINUTE_SEC * HOUR_MIN;
		
		int h = 0;
		int m = 0;
		int s = 0;

		while (sec >= hourSec) {
			sec -= hourSec;
			h++;
		}
		while (sec >= MINUTE_SEC) {
			sec -= MINUTE_SEC;
			m++;
		}
		s = sec;
		
		System.out.println(h + STR + m + STR + s);
	}

}



Measured memory_bytes: 26172
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n; cin >> n;
	vector<vector<int> > a(2, vector<int>(n));
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j < n; ++j)
			cin >> a[i][j];
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int tmp = 0;
		for (int j = 0; j <= i; ++j)
			tmp += a[0][j];
		for (int j = i; j < n; ++j)
			tmp += a[1][j];
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	
	return 0;
}

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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();   
    int a, b; cin >> a >> b;
    --a;
    int ans = 0;
    int cur = 1;
    while(cur < b){
        ++ans;
        cur += a;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3608
#include <iostream>
using namespace std;
long long A[100001];
int main() {
    long long N, sum = 0, k;
    bool ans;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    if (sum % (N * (N + 1) / 2) != 0) {
        cout << "NO" << endl;
    } else {
        k = sum / (N * (N + 1) / 2);
        ans = true;
        for (int i = 1; i < N; i++) {
            if ((k - (A[i] - A[i - 1])) < 0 || (k - (A[i] - A[i - 1])) % N != 0) {
                ans = false;
                break;
            }
        }
        if (ans) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 2000;

int main(){
    
    int n,x,y;
    int num[maxn];
    
    cin >> n>>x>>y;
    rep(i,n){
        cin >> num[i];
    }
    
    if(n==1){
        cout << abs(num[0]-y)<<endl;
    }else{
        cout << max(abs(num[n-1]-y),abs(num[n-1]-num[n-2]))<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

int main(){
  int n;
  while(cin >> n && n){
    for(long long i = 1,t = 3;;i++,t*=3){
      if (t >= n){cout << i << endl;break;}
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    int K;
    cin >> N;
    cin >> K;
    
        string S;
        cin>>S;
        if(S[K-1]=='A'){S[K-1]='a';}
        else if(S[K-1]=='B'){S[K-1]='b';}
        else if(S[K-1]=='C'){S[K-1]='c';}
        cout<<S<<endl;
        return 0;
}


Measured memory_bytes: 256
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
using ll = long long;

int main(){
    string s;cin >> s;
    bool f = true;
    for(int i = 0;i < s.size();i++){
        if(i%2 == 0 && s[i] == 'L')f = false;
        if(i%2 == 1 && s[i] == 'R')f = false;
    }
    cout<<(f ? "Yes" : "No")<<endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int INF = 1<<29;
const int MAX_V = 110;
const int MAX_E = 1100;

int N, M;
int a[MAX_E], b[MAX_E], c[MAX_E]; // 各辺
int dist[MAX_V][MAX_V]; // Floyd-Warshall 用

int main() {
    cin >> N >> M;

    // Floyd-Warshall でよくやる初期化
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            dist[i][j] = INF;
        }
        dist[i][i] = 0; // ここがポイント
    }

    // 入力
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        --a[i], --b[i];
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    // Floyd-Warshall
    for (int k = 0; k < N; ++k)
        for (int i = 0; i < N; ++i)
            for (int j = 0; j < N; ++j)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    // 集計
    int res = 0;
    for (int i = 0; i < M; ++i) {
        bool ok = false;
        for (int p = 0; p < N; ++p) {
            for (int q = 0; q < N; ++q) {
                if (dist[p][q] == dist[p][a[i]] + c[i] + dist[b[i]][q])
                    ok = true;
            }
        }
        if (!ok) ++res;
    }
    cout << res << endl;
}


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

int main(){
  int a,b,c,n,ans=0;
  cin>>a>>b>>c>>n;
  for(int i=0;i<=a;++i)
    for(int j=0;j<=b;++j)
      for(int k=0;k<=c;++k)
        if(500*i+100*j+50*k==n)ans++;
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }
int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

int K;

int solve(int now, int rest) {
    if (!rest) return now;
    return min(solve(2 * now, rest - 1), solve(now + K, rest - 1));
}

int main () {
    int res = 1 << 28;
    int n = getint();
    K = getint();
    cout << solve(1, n) << endl;
    return 0;
}



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

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
int bingo[3][3];
void check(int a){
  rep(i,3){
    rep(j,3){
      if(bingo[i][j]==a)bingo[i][j]=inf;
    }
  }
}
signed main(){
  rep(i,3){
    rep(j,3)cin>>bingo[i][j];
  }
  int n;cin>>n;
  vector<int> b(n);
  rep(i,n){
    cin>>b[i];
    check(b[i]);
  }
  bool flag=false;
  if(bingo[1][1]==inf){
    if(bingo[0][0]==inf&&bingo[2][2]==inf)flag=true;
    if(bingo[0][2]==inf&&bingo[2][0]==inf)flag=true;
    if(bingo[0][1]==inf&&bingo[2][1]==inf)flag=true;
    if(bingo[1][0]==inf&&bingo[1][2]==inf)flag=true;
  }
  else if(bingo[2][0]==inf){
    if(bingo[1][0]==inf&&bingo[0][0]==inf)flag=true;
    if(bingo[2][1]==inf&&bingo[2][2]==inf)flag=true;
  }
  else if(bingo[0][2]==inf){
    if(bingo[0][0]==inf&&bingo[0][1]==inf)flag=true;
    if(bingo[1][2]==inf&&bingo[2][2]==inf)flag=true;
  }
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

using namespace std;
string s;
int MIN = 1000;
int main() {
  cin >> s;

  for(int i = 0; i < 26; i++) {
    string aa = s;
    string tmp(aa.size(),'a'+i);
    int ans = 0;
    while(true) {
      if(tmp == aa) break;

      for(int j = 0; j < aa.size(); j++) {
	if(aa[j+1] == 'a'+i) aa[j] = aa[j+1];
      }
      aa.pop_back();
      tmp.pop_back();
      ans++;
    }
    MIN = min(MIN,ans);
  }
  cout << MIN << endl;
}
			      


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

int main() {
	int n; cin >> n;
	int len[n];
	for (int i = 0; i < n; i++) len[i] = 0;
	vector<int> arr[n];
	for (int i = 0; i < n; i++) {
	    arr[i].push_back(-1);
	}
	int last[n];
	for (int i = 0; i < n; i++) last[i] = -1;
	for (int i = 0; i < n; i++) {
	    int x; cin >> x;
	    int pos = lower_bound(last, last + n, x) - last;
	    pos--;
	    len[pos]++;
	    arr[pos].push_back(x);
	    last[pos] = x;
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
	    if (len[i] != 0) res++;
	}
	cout << res;
}

Measured memory_bytes: 7040
n, k, q = map(int,input().split())
scores = [0 for i in range(n)]

for i in range(q):
    a = int(input())
    scores[a-1] = scores[a-1] + 1
#    print(scores)

for i in range(n):
    if q-scores[i] < k:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 4684
import sys
A="abcdefghijklmnopqrstuvwxyza"
def rot(s):
    x=""
    for c in s:
        if c in A:x+=A[A.index(c)+1]
        else:x+=c
    return x
 
for s in sys.stdin.readlines():
    for i in range(26):
        if "the" in s or "that" in s or "this" in s:break
        s=rot(s)
    print s[:-1]

Measured memory_bytes: 4204
#include <iostream>
#include <vector>

int main () {
  int n;
  std::cin >> n;
  int answer = 0;
  int four = n / 4;
  int seven = n / 7;

  for (int i = 0; i <= four; i++) {
    int sub = n;
    sub = n - i * 4;
    if (sub == 0) {
      answer = 1;  
    }
    for (int j = 0; j <= seven; j++) {
      int subsub = sub - 7 * j;    
      if (subsub == 0) {
        answer = 1;  
      }
    }  
  }

  if (answer) {
    std::cout << "Yes" << std::endl;  
  }
  else {
    std::cout << "No" << std::endl;  
  }
}

Measured memory_bytes: 256
N,Y = list(map(int,input().split()))

flag=False
for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j
        if i*10000 + j*5000 + k*1000==Y:
            flag=True
            break
    if flag:
        break

if flag:
    print(i,j,k)
else:
    print(-1,-1,-1)

Measured memory_bytes: 40684
#include<iostream>
using namespace std;
int n,ans;
int dp[101][76];
bool isp(int a)
{
	for(int i=2;i*i<=a;i++)if(a%i==0)return 0;
	return 1;
}
main()
{
	cin>>n;
	dp[0][1]=1;
	int p=0;
	for(int i=2;i<=n;i++)
	{
		if(!isp(i))continue;
		int cnt=0;
		for(int j=1;j<=n;j++)
		{
			int a=j;
			while(a%i==0)cnt++,a/=i;
		}
		for(int j=0;j<=cnt;j++)
		{
			for(int k=1;k*(j+1)<=75;k++)
			{
				dp[i][k*(j+1)]+=dp[p][k];
			}
		}
		p=i;
	}
	cout<<dp[p][75]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int r;
  cin>>r;
  cout<<3*r*r;

  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll N;
string X;
ll cnt;

ll modpow(ll n, ll r, ll mod) {
    ll ret = 1;
    ll p = n;
    while (r > 0) {
        if (r & 1) {
            ret = (ret * p) % mod;
        }
        p = (p * p) % mod;
        r /= 2;
    }

    return ret % mod;
}

ll np = 0, nm = 0;

ll calc(ll num) {
    ll b = 0;
    ll ret = num;
    while (num > 0) {
        if (num & 1)
            b++;
        num >>= 1LL;
    }
    return ret % b;
}

ll solve(ll n) {
    if (X[n] == '1') {
        //! マイナス
        if (cnt == 1)
            return 0;
        ll num = (cnt - 1 + nm - modpow(2LL, N - 1 - n, cnt - 1)) % (cnt - 1);

        ll ret = 1;
        while (num > 0) {
            ret++;
            num = calc(num);
        }
        return ret;
    }

    {
        ll num = (np + modpow(2LL, N - 1 - n, cnt + 1)) % (cnt + 1);
        ll ret = 1;
        while (num > 0) {
            ret++;
            num = calc(num);
        }
        return ret;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    cin >> X;
    cnt = 0;
    REP(i, N) {
        if (X[i] == '1')
            cnt++;
    }
    np = 0, nm = 0;
    REP(i, N) {
        if (X[N - 1 - i] == '1') {
            np = (np + modpow(2, i, cnt + 1)) % (cnt + 1);
            if (cnt > 1) {
                nm = (nm + modpow(2, i, cnt - 1)) % (cnt - 1);
            }
        }
    }

    REP(i, N) {
        cout << solve(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 3772
#include <stdio.h>
#include <math.h>
main(){
  int i,j,n,code;
  char cm[7],op,dict[262145];
  for(i=0,scanf("%d",&n);i<n;i++){
    scanf("%s",cm);
    j=code=op=0;
    for(;op!='\n';scanf("%c",&op))
      if(op=='A') code+=1*pow(4,j++);
      else if(op=='C') code+=2*pow(4,j++);
      else if(op=='G') code+=3*pow(4,j++);
      else if(op=='T') code+=4*pow(4,j++);
    if(cm[0]=='i') dict[code] = 1;
    if(cm[0]=='f') dict[code] ? printf("yes\n") : printf("no\n");
  }
  return 0;
}

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


int main()
{
	int n, x; cin >> n >> x;
	int a[n];
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a, a+n);
	int c = 0;
	for (int i = 0; i < n; ++i)
	{
		x -= a[i];
		if (x >= 0) c++;
		else break;
	}
	if (x > 0) c--;
	cout << c << endl;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

int n, ar[N], ans;

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);

	cin >> n;
	for(int i = 1; i <= 2 * n; i++)
		cin >> ar[i];

	sort(ar + 1, ar + 2 * n + 1);

	for(int i = 2 * n - 1; i >= 1; i -= 2)
		ans += ar[i];

	cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		if (C<=A+B) {
			System.out.println(C+B);
			return ;
		}
		System.out.println(B+(A+B+1));
	}
}


Measured memory_bytes: 35644
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string k = "CODEFESTIVAL2016";
	int n = s.size();
	int cnt = 0;
	rep(i,n){
		if(s[i] != k[i]) ++cnt;
	}
	cout << cnt << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    string s; cin >> s;
    if (s[0] == 'S') cout << "Cloudy" << endl;
    else if (s[0] == 'C') cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;
     
int main(void)
{
    int a,b;
    cin >> a >> b;
    if(a <= 8 && b <= 8){
        cout << "Yay!";
    }else{
        cout << ":(";
    }

    return 0;

}

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

int main(){
  int N;
  cin >> N;
  vector<string> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W.at(i);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if(i!=j){
        if(W.at(i)==W.at(j)) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  for (int i = 0; i < N-1; i++) {
    if(W.at(i).at(W.at(i).size()-1)!=W.at(i+1).at(0)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
import math


class LinearProbingIntSet:
    def __init__(self):
        self.count = 0
        self.size = 3
        self.keys = [None] * self.size

    def add(self, key):
        i = self._hash(key)
        for j in range(self.size):
            k = (i + j) % self.size
            if self.keys[k] is None:
                self.keys[k] = key
                self.count += 1
                break
            elif self.keys[k] == key:
                break
        else:
            raise RuntimeError('set is full')

        if self.count > self.size // 2:
            self._resize(int(2 ** (math.log2(self.size+1)+1)) - 1)

    def __contains__(self, key):
        i = self._hash(key)
        for j in range(self.size):
            k = (i + j) % self.size
            if self.keys[k] is None:
                return False
            elif self.keys[k] == key:
                return True
        raise RuntimeError('set is full')

    def _hash(self, key):
        return key % self.size

    def _resize(self, size):
        old_keys = self.keys
        self.count = 0
        self.size = size
        self.keys = [None] * self.size

        for key in old_keys:
            if key is None:
                continue
            self.add(key)


def run():
    q = int(input())
    s = LinearProbingIntSet()

    for _ in range(q):
        command, value = [int(x) for x in input().split()]
        if command == 0:
            s.add(value)
            print(s.count)
        elif command == 1:
            if value in s:
                print(1)
            else:
                print(0)
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



Measured memory_bytes: 16116
#include <iostream>
#include <utility>
#include <vector>
#include <cstring>
using namespace std;
#define MAX 100

struct in {
	int c;
	int d;
	pair<int, int> p;
};

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
int w, h, n;
pair<int, int> st, gl;
int map[MAX+2][MAX+2];//map[X][Y]
vector<in> info;
bool f;

bool dfs(int x, int y, int c) {
	if (map[x][y] != c) return false;
	map[x][y] = -1;
	if (x==gl.first&&y==gl.second) return true;
	for (int i=0; i<4; i++) {
		if (x+dx[i]<0 || y+dy[i]<0 || x+dx[i]>=w+2 || y+dy[i]>=h+2) continue;
		if (dfs(x+dx[i], y+dy[i], c)) return true;
	}

	return false;
}

int main() {
	while (cin >> w >> h, w||h) {
		cin >> st.first >> st.second >> gl.first >> gl.second >> n;
		info.clear();
		for (int i=0; i<n; i++) {
			in t;
			cin >> t.c >> t.d >> t.p.first >> t.p.second;
			info.push_back(t);
		}

		memset(map, 0, sizeof(map));
		for (int i=0; i<n; i++) {
			int W=4, H=2;
			if (info[i].d) { int t=W; W=H; H=t; }
			for (int x=0; x<W; x++)
			for (int y=0; y<H; y++)
				map[info[i].p.first+x][info[i].p.second+y] = info[i].c;
		}

		cout << ((dfs(st.first, st.second, map[st.first][st.second])) ? "OK" : "NG") << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    int n, t, ans = 0;
    cin >> n >> t;
    vector<int> v;
    v.emplace_back(0);
    for (int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);
        v.emplace_back(a);
        ans += min(v[i+1]-v[i], t);
    }
    ans += t;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1400
N=10**6+1
mod=10**9+7

inv_l=[0,1]
for i in range(2,N):
    inv_l+=[inv_l[mod%i]*(mod-int(mod/i))%mod]

prime_list=[]
min_prime=[1]*(N+1)
is_prime=[0,0]+[1]*(N-1)
for i in range(2,N+1):
    if is_prime[i]==1:
        prime_list.append(i)
        j=i
        while j<=N:
            is_prime[j]=0
            if min_prime[j]==1:
                min_prime[j]=i
            j+=i

def lcm(l,mod):
    max_count=[0]*(N+1)
    for a in l:
        a_min_prime=min_prime[a]
        a_count=0
        while a>1:
            if min_prime[a]==a_min_prime:
                a_count+=1
                a//=a_min_prime
            else:
                max_count[a_min_prime]=max(max_count[a_min_prime],a_count)
                a_min_prime=min_prime[a]
                a//=a_min_prime
                a_count=1
            if a==1:
                max_count[a_min_prime]=max(max_count[a_min_prime],a_count)
    ret=1
    for i in range(1,N+1):
        if max_count[i]!=0:
            ret=(ret*i**max_count[i])%mod
    return ret

n=int(input())
A=list(map(int,input().split()))
L=lcm(A,mod)
ans=0
for i in range(n):
    ans=(ans+L*inv_l[A[i]])%mod
print(ans)

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

using namespace std;
int main(){
  string s;
  long long k;
  cin >> s >> k;
  long long ans=0, tmp=k;
  for(int i=0;i<s.length() && k>0;i++){
    if(s[i]!='0'){
      long long plus=1;
      for(int j=0;j<k;j++){
        plus *= 9*(s.length()-i-1-j);
      }
      for(int j=0;j<k;j++){
        plus /= j+1;
      }
      ans += plus;
      plus=1;
      for(int j=0;j<k-1;j++){
        plus *= 9*(s.length()-i-1-j);
      }
      for(int j=0;j<k-1;j++){
        plus /= j+1;
      }
      ans += (s[i]-'0'-1)*plus;
      k--;
    }
  }
  cout << ans+(k==0?1:0) << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int h, w, counth, countw = 0;
    while(1){
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0) break;
        for(counth = 0; counth < h; counth ++){
            if(counth % 2 == 0){
                while(countw < w){
                    printf("#");
                    countw ++;
                    if(countw == w) break;
                    printf(".");
                    countw ++;
                }
            }  else  while(countw < w){
                    printf(".");
                    countw ++;
                    if(countw == w) break;
                    printf("#");
                    countw ++;
                }
            printf("\n");
            countw = 0;
        }
        printf("\n");
        }
    return 0;
    }

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int k;
  cin >> k;
  int max;
  if(a >= b) {
    max = a;
  } else {
    max = b;
  }
  if(c >= max) {
    max = c;
  }
  cout << a + b + c + max * pow(2, k) - max << endl;
  return 0;
}


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

typedef long long ll;

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

    sort(a,a+n);
    int swaps = 0;

    for(int i=0;i<n;i++){
        if(a[i]!=b[i]) swaps++;
    }
    if(swaps>2) puts("NO");
    else puts("YES");

}

Measured memory_bytes: 3608
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
char str[4];
long long int t=0;
scanf("%s",str);

    if(str[0]==str[1] && str[2]==str[3])
    t++;
    if(str[0]==str[2] && str[1]==str[3])
    t++;
    if(str[0]==str[3] && str[1]==str[2])
    t++;
    
    if(t==1)
    printf("Yes");
    else
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <chrono>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#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 SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

int min(int a, int b) {
    if (a > b) {
        return b;
    } else {
        return a;
    }
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

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

    int n, a, sum = 0;
    cin >> n;
    vector<int> A;
    A.push_back(0);
    rep(i, n) {
        cin >> a;
        A.push_back(a);
    }
    int f, b;
    for (auto it = A.begin() + 1; it != A.end(); ++it) {
        --it;
        f = *it;
        ++it;
        sum += abs(f - *it);
    }
    sum += abs(A[n]);

    int tmp = sum;
    A.push_back(0);
    for (int i = 1; i < n + 1; i++) {
        tmp = sum - (abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1])) + abs(A[i - 1] - A[i + 1]);
        cout << tmp << endl;
        tmp = sum;
    }
    return 0;
}

Measured memory_bytes: 1784
s = 0
t = 0
while 1:
    try:
        a,b,c = map(int,input().split(","))
        if a**2 + b**2 == c**2:
            s += 1
        elif a == b  :
            t += 1

    except EOFError:
        print(s)
        print(t)
        break


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

int main()
{
    int n,a,b;
    cin>>n;
    if(n==1)
    {
        cout<<"Hello World"<<endl;
    }
    else
    {
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010
#define M 200010
#define INF 1000000000
int n;
struct EDGE{
	int to,c;
	EDGE *las;
} e[M*2+N*4];
int ne;
EDGE *last[N*2];
void link(int u,int v,int c){
	e[ne]={v,c,last[u]};
	last[u]=e+ne++;
}
int S,T;
int gap[N*2],BZ,dis[N*2];
EDGE *cur[N*2];
#define rev(ei) (e+(int((ei)-e)^1))
bool getdis(){
	static int q[N*2];
	memcpy(cur,last,sizeof(EDGE*)*(T+1));
	memset(dis,0,sizeof(int)*(T+1));
	dis[S]=1;
	q[1]=S;
	int head=1,tail=1;
	while (head<=tail){
		int x=q[head++];
		for (EDGE *ei=last[x];ei;ei=ei->las)
			if (ei->c && !dis[ei->to]){
				dis[ei->to]=dis[x]+1;
				q[++tail]=ei->to;
			}
	}
	return dis[T];
}
int dfs(int x,int s){
	if (x==T)
		return s;
	int have=0;
	for (EDGE *&ei=cur[x];ei;ei=ei->las)
		if (ei->c && dis[ei->to]==dis[x]+1){
			int t=dfs(ei->to,min(ei->c,s-have));
			ei->c-=t,rev(ei)->c+=t,have+=t;
			if (have==s) return s;
		}
	cur[x]=last[x];
	return have;
}
int flow(){
	gap[0]=T;
	BZ=1;
	int r=0;
	while (getdis()){
		int tmp;
		do{
			tmp=dfs(S,INF);
			r+=tmp;
		}
		while (tmp);
	}
	return r;
}
int bel[N];
bool vis[N*2];
int ans[N][2];
int cnt;
void dfs(int x){
	vis[x]=1;
	++cnt;
	for (EDGE *ei=last[x];ei;ei=ei->las)
		if (ei->to!=S && !vis[ei->to]){
			vis[ei->to]=1;
			ans[ei->to-n][0]=x;
			ans[ei->to-n][1]=bel[ei->to-n];
			dfs(bel[ei->to-n]);
		}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;++i){
		int k;
		scanf("%d",&k);
		for (int j=0;j<k;++j){
			int x;
			scanf("%d",&x);
			link(x,n+i,1),link(n+i,x,0);
		}
	}
	S=n+n-1+1,T=n+n-1+2;
	for (int i=1;i<=n;++i)
		link(S,i,1),link(i,S,0);
	for (int i=1;i<n;++i)
		link(n+i,T,1),link(T,n+i,0);
	int f=flow();
	if (f!=n-1){
		printf("-1\n");
		return 0;
	}
	for (int i=1;i<n;++i)
		for (EDGE *ei=last[n+i];ei;ei=ei->las)
			if (ei->to!=T && ei->c)
				bel[i]=ei->to;
	int r=0;
	for (int i=1;i<=n;++i)
		for (EDGE *ei=last[i];ei;ei=ei->las)
			if (ei->to==S && !ei->c)
				r=i;
	dfs(r);
	if (cnt<n)
		printf("-1\n");
	else
		for (int i=1;i<n;++i)
			printf("%d %d\n",ans[i][0],ans[i][1]);
	return 0;
}





 










Measured memory_bytes: 24928
A,B=map(int,input().split())
strong =[2,3,4,5,6,7,8,9,10,11,12,13,1]
if strong.index(A)>strong.index(B):
    print('Alice')
elif strong.index(A)<strong.index(B):
    print('Bob')
else:
    print('Draw')

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

int main(){
	int a,ans=0,k,w;
	cin>>a;
	for(int i=1;i<=a;++i){
		k=i,w=1;
		while(k>9)k/=10,w++;
		if(w&1)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

char S[505050]; int N;
int fail[505050], fail2[505050];

int kmp(int *feil)
{
	int m = strlen(S), i, j = feil[0] = -1;
	for (i = 0; i < m; ++i) {
		for (; ~j && S[j] != S[i]; j = feil[j]);
		feil[i + 1] = ++j;
	}
	return m;
}

bool isok(int i, int f)
{
	return i % (i - f) != 0 || f == 0;
}

int main()
{
	scanf("%s", S);
	N = strlen(S);

	kmp(fail);

	if (isok(N, fail[N])) {
		printf("1\n1\n");
		return 0;
	}
	if (N - fail[N] == 1) {
		printf("%d\n1\n", N);
		return 0;
	}
	reverse(S, S + N);
	kmp(fail2);

	int ret = 0;
	for (int i = 1; i < N; ++i) {
		if (isok(i, fail[i]) && isok(N - i, fail2[N - i])) {
			++ret;
		}
	}
	printf("%d\n%d\n", 2, ret);
	return 0;
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    Graph g(n);
    REP(i, n) {
        ll u, k;
        cin >> u >> k;
        u--;
        REP(j, k) {
            ll v;
            cin >> v;
            v--;
            add_edge(g, u, v, 1, false, 1);
        }
    }

    Array d(n, 0);
    Array f(n, 0);
    int id = 1;
    auto dfs = [&](auto &&self, int v) -> void {
        d[v] = id;
        id++;
        for(auto e : g[v]) {
            if(d[e.to])
                continue;
            self(self, e.to);
        }
        f[v] = id;
        id++;
    };
    REP(i, n) {
        if(d[i])
            continue;
        dfs(dfs, i);
    }
    REP(i, n) {
        cout << i + 1 << " " << d[i] << " " << f[i] << en;
    }
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}



Measured memory_bytes: 3156