akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		
		String array[] = new String[h];
		
		for(int i = 0; i < h; i++){
			array[i] = scan.next();
		}
		for(int i = 0; i < h; i++){
				System.out.println(array[i]);
				System.out.println(array[i]);
		}
	}

}


Measured memory_bytes: 23724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	lint END = 100000000001;
	list<lint>A;
	A.push_back(END);
	lint Q;
	cin >> Q;
	list<lint>::iterator itr;
	itr = A.begin();
	rep(i, Q) {
		lint a;
		cin >> a;
		if (a == 0) {
			lint x;
			cin >> x;
			A.insert(itr, x);
			itr--;
		}
		else if (a == 1) {
			lint d;
			cin >> d;
			if(d>0){
				rep(j, d) {
					itr++;
				}
			}
			else {
				rep(j, abs(d)) {
					itr--;
				}
			}
		}
		else if (a == 2) {
			itr = A.erase(itr);
		}
	}
	A.pop_back();
	for (itr = A.begin(); itr != A.end(); itr++) {
		cout << *itr << endl;
	}
}




Measured memory_bytes: 18608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    
    long int m=arr[0];
    long int s=0;
    for(int i=1;i<n;i++)
    {
        if(arr[i]<m)
        s=s+m-arr[i];
        else if(arr[i]>m)
        m=arr[i];
    }
    cout<<s;
}


Measured memory_bytes: 4312
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string S;
cin>>S;
int N=S.size();
int cnt_0=0,cnt_1=0;
rep(i,N){
    if(S[i]=='0')cnt_0++;
    else if(S[i]=='1')cnt_1++;
}
cout<<2*min(cnt_0,cnt_1)<<endl;
//system("pause");
return 0;
}

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

int main() {
 string s;
 unsigned long long int sum=0;
  
  cin >> s;
  
  for(int i=0; i<s.size(); i++)
    sum+=s[i]-'0';
  
  if(sum%9==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3704
#include <vector>
#include <iostream>
#include <algorithm>
template<typename T>
int upperBound(const std::vector<T>& vec, const T& target) {
	int left = 0;
	int right = vec.size();
	while (left < right) {
		auto mid = (left + right) / 2;
		if (vec[mid] <= target) {
			left = mid + 1;
		}
		else {
			right = mid;
		}
	}
	return right;
}
int main() {
	int n; std::cin >> n;
	std::vector<long long int> a(n);
	for (auto& ai : a) std::cin >> ai;
	std::sort(a.begin(), a.end());
	std::vector<long long int> sum(n + 1, 0);
	for (auto i = 1; i < sum.size(); ++i) sum[i] += a[i - 1] + sum[i - 1];
	int m; std::cin >> m;
	std::vector<long long int> b(m), c(m);
	for (auto& bi : b) std::cin >> bi;
	for (auto& ci : c) std::cin >> ci;
	for (auto i = 0; i < m; ++i) {
		if (sum[upperBound(a, b[i])] >= c[i]) std::cout << "Yes\n";
		else std::cout << "No\n";
	}
}


Measured memory_bytes: 11940
<?php
$n = explode(" ", fgets(STDIN));
$count = 0;

for ($i = 0; $i < count($n); $i++) {
    $count += $n[$i];
}

if ($count <= 21) {
    echo "win" . PHP_EOL;
} else {
    echo "bust" . PHP_EOL;
}


Measured memory_bytes: 4604
#
import sys
import math

# ひとつ入力
n = int(input())

# initial state
a = [int(i) for i in input().split()] 
# last state
b = [int(i) for i in input().split()] 

answer = 0
answer_p = -1
while answer >= 0:
    answer_p = answer
    for i in range(n):
        tmp = b[(i-1)%n] + b[(i+1)%n]
        if 0 < tmp < b[i] and a[i] < b[i]:
            res = (b[i]-a[i]) // (b[(i+1)%n]+b[(i-1)%n])
            answer += res
            b[i] -= res * (b[(i+1)%n]+b[(i-1)%n])
        
    if answer == answer_p:
        break
#    print(a,b,answer)

for i in range(n):
    if a[i] != b[i]:
        print(-1)
        exit()
print(answer)


Measured memory_bytes: 119032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b;cin>>a>>b;
    cout<<a*b/gcd(a,b)<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		int K =scan.nextInt();
		String S =scan.next();
		
		if(K>=S.length()) {
			System.out.println(S);
		}
		else {
			for(int i=0;i<K;i++) {
				System.out.print(S.charAt(i));
			}
			System.out.print("...");
		}
		
	}
}


Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int M,D;
	cin>>M>>D;
	int res=0;
	for(int m=1;m<=M;++m)
		for(int d=10;d<=D;++d)
			if(d%10>=2 && d/10>=2 && (d/10)*(d%10)==m)
				++res;
	cout<<res<<endl;
	return 0;
}

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

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	int n, x;
	cin >> n >> x;
	int m = 2 * n - 1;
	if (x == 1 || x == m) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	int add = 0;
	if (x >= n) {
		add = (x - n);
	} else {
		add = n + x - 1;
	}
	for (int i = 0; i < m; i++) {
		cout << (i + add) % m + 1 << "\n";
	}
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <cmath>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
typedef long long ll;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

    int cand = ceil(max(a * 12.5, b * 10.0));

    if (cand < 12.5 * (a + 1) && cand < 10 * (b + 1)) {
        cout << cand << endl;
    } else {
        cout << "-1" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#define MAX_N 200007
typedef long long ll;

int N;
ll res = 1e17;
ll a[MAX_N], sum[MAX_N];

int main () {
    scanf("%d", &N);
    for (int i = 1;i <= N; ++i) scanf("%lld", a + i), sum[i] = sum[i - 1] + a[i];
    for (int i = 2;i <= N - 2; ++i) {
        ll ans1 = 0, ans2 = 1e17, ans3 = 0, ans4 = 1e17;
        ll tmp1, tmp2;
        int l = 1, r = i, mid, ans5 = 0;
        while (l <= r) {
            mid = l + r >> 1;
            tmp1 = sum[mid], tmp2 = sum[i] - sum[mid];
            if (tmp1 < tmp2) std::swap(tmp1, tmp2);
            if (tmp1 - tmp2 < ans2 - ans1) {
                ans1 = tmp2, ans2 = tmp1;
                ans5 = mid;
            }
            if (sum[mid] - sum[i] + sum[mid] > 0) r = mid - 1;
            else l = mid + 1;
        }
        l = i, r = N, mid;int ans6 = 0;
        while (l <= r) {
            mid = l + r >> 1;
            //if (i == 4) printf("%d %d %d\n", l, r, mid);
            tmp1 = sum[mid] - sum[i], tmp2 = sum[N] - sum[mid];
            if (tmp1 < tmp2) std::swap(tmp1, tmp2);
            if (tmp1 - tmp2 < ans4 - ans3) ans3 = tmp2, ans4 = tmp1, ans6 = mid;
            if (sum[mid] - sum[i] > sum[N] - sum[mid]) r = mid - 1;
            else l = mid + 1;
        }/* 
        ans5++;
        tmp1 = sum[ans5], tmp2 = sum[i] - sum[ans5];
        if (tmp1 < tmp2) std::swap(tmp1, tmp2);
        if (tmp1 - tmp2 < ans2 - ans1) ans2 = tmp1, ans1 = tmp2;
        ans5 -= 2;
        tmp1 = sum[ans5], tmp2 = sum[i] - sum[ans5];
        if (tmp1 < tmp2) std::swap(tmp1, tmp2);
        if (tmp1 - tmp2 < ans2 - ans1) ans2 = tmp1, ans1 = tmp2;
        ans6++;
        tmp1 = sum[ans6] - sum[i], tmp2 = sum[N] - sum[mid];
        if (tmp1 < tmp2) std::swap(tmp1, tmp2);
        if (tmp1 - tmp2 < ans4 - ans3) ans4 = tmp1, ans3 = tmp2;
        ans6 -= 2;
        tmp1 = sum[ans6] - sum[i], tmp2 = sum[N] - sum[mid];
        if (tmp1 < tmp2) std::swap(tmp1, tmp2);
        if (tmp1 - tmp2 < ans4 - ans3) ans4 = tmp1, ans3 = tmp2; */
        tmp1 = std::max(ans1, std::max(ans2, std::max(ans3, ans4)));
        tmp2 = std::min(ans1, std::min(ans2, std::min(ans3, ans4)));
        // printf("%lld %lld %lld %lld %lld %lld\n", ans1, ans2, ans3, ans4, tmp1, tmp2);
        res = std::min(res, tmp1 - tmp2);
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	boolean[] submit = new boolean[31];
	
	for(int i = 0;i<28;i++){ submit[sc.nextInt()] = true; }
	
	for(int i = 1;i<31;i++){
	    if(!submit[i]) System.out.println(i);
	}
    }
}

Measured memory_bytes: 17184
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using lint = long long;
using ld = long double;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(lint i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char>(w));
	REP(i, h) REP(j, w) cin >> a[i][j];
	vector<vector<int>> dir(h, vector<int>(w, INF));
	queue<pint> q;
	REP(i, h) REP(j, w) {
		if(a[i][j] == '#') {
			dir[i][j] = 0;
			q.push({i, j});
		}
	}
	while(!q.empty()) {
		pint p = q.front();
		q.pop();
		int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
		REP(i, 4) {
			pint np = {p.first + dx[i], p.second + dy[i]};
			if(np.first >= 0 && np.first < h && np.second >= 0 && np.second < w) {
				if(dir[np.first][np.second] == INF) {
					dir[np.first][np.second] = dir[p.first][p.second] + 1;
					q.push(np);
				}
			}
		}
	}
	int ans = 0;
	REP(i, h) REP(j, w) ans = max(ans, dir[i][j]);
	cout << ans << endl;
	return 0;
}
/* --------------------------------------- */


Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()
 
int main(void) {
    ll n; cin >> n;
    ll rn = sqrt(n);
    ll ans = LONG_MAX;
    rep(i, 1, rn+1) {
        if ((ll)(n % i) == 0) {
            ll j = n / i;
            ans = min(ans, i+j-2);
        }
    }
    cout << ans << endl;
}


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

struct state{
	int a[9];
	int num;
};

int count(int a[9]){
	deque<state> q;
	state tmp, work;
	int ret=0, tmptimes;
	for(int i=0;i<9;i++) tmp.a[i] = a[i];
	tmp.num=0;
	q.push_back(tmp);
	while(!q.empty()){
		tmp = q.front();
		ret = max(ret, tmp.num);
		tmptimes = tmp.num;
		for(int i=0;i<9;i++){
			work.a[i] = tmp.a[i];
			//cout << work.a[i];
		}
		//cout << endl;
		q.pop_front();
		for(int i=0;i<=6;i++){
			for(int j=0;j<9;j++) work.a[j] = tmp.a[j];
			work.num = tmp.num;
			if(work.a[i] && work.a[i+1] && work.a[i+2]){
				work.a[i]--; work.a[i+1]--; work.a[i+2]--;
				work.num++;
				q.push_back(work);
			}
		}
		for(int i=0;i<=8;i++){
			for(int j=0;j<9;j++) work.a[j] = tmp.a[j];
			work.num = tmp.num;
			if(work.a[i] >= 3){
				work.a[i] -= 3;
				work.num++;
				q.push_back(work);
			}
		}
	}
	return ret;
}

int main(void){
	int n;
	
	cin >> n;
	while(n--){
		int R[9], G[9], B[9];
		int num[9];
		char color[9];
		memset(R, 0, sizeof(R));
		memset(G, 0, sizeof(G));
		memset(B, 0, sizeof(B));
		
		for(int i=0;i<9;i++) cin >> num[i];
		for(int i=0;i<9;i++) cin >> color[i];
		for(int i=0;i<9;i++){
			if(color[i] == 'R'){
				R[num[i] - 1]++;
			}else if(color[i] == 'G'){
				G[num[i] - 1]++;
			}else{
				B[num[i] - 1]++;
			}
		}
		if(count(R) + count(G) + count(B) >= 3){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,j,n) for((i)=(j) ; (i)<(n) ; (i)++)
#define pl(format,var) p(format "\n",var)
#define p(format,var) printf(format,var)
#define asizeof(array) (sizeof(array)/sizeof(array[0]))

/*
[履歴]
・投下

[メモ3]
入力データを探索する用のインデックスの他に、
移動後の位置を表すインデックスを導入してみた。
んで、両者の対応を紙面上で洗い出して、コードに落とした。

*/

#define YMAX 9
#define XMAX 5

int count=0; //For debugging

typedef enum {
	U=0,
	R,
	D,
	L
} state_t; //状態を表す列挙型

//状態に対応する文字を出力
void printstate(state_t s){
	switch(s){
		case L:
			printf("L");
			break;
		case R:
			printf("R");
			break;
		case U:
			printf("U");
			break;
		case D:
			printf("D");
			break;
		default:
			printf("%d",s);
			break;
	}
}

//RRRRDDDDLLLUUURRDDLURDLURDLURDLURD
//RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL
//                     ~ ~~ ~~

int main(){
	char line[80]; //入力行
	int i,j; //カウンタ変数
	int array[YMAX][XMAX]; //入力データ
	int x,y; //探索先インデックス
	int px,py; //現在の位置
	state_t s; //現状態
	int dir4data[4][2]={
		{-1,0}, /* U */
		{0,0}, /* R */
		{1,0}, /* D */
		{0,-1} /* L */
	};
	int dir4pos[4][2]={
		{-2,0}, /* U */
		{0,1}, /* R */
		{2,0}, /* D */
		{0,-1} /* L */
	};

	//入力データを読み込む
	// 奇数行目の末尾にデータが入ってないが,
	// アクセスすることはないので放置
	rep2(i,YMAX){
		fgets(line, sizeof(line), stdin);
		rep2(j,XMAX){
			array[i][j] = line[j] - '0';
		}
		if(i%2==0)
			array[i][j-1] = 0; //ゴミデータが入っているのでゼロクリアしとく
	}
	
	//スタート地点をセット
	px = py = 0;
	x = y = 0;
	s = R;
	
	while(s==R || px!=0 || py!=0){
		//count++; if(count == 35) break;
		//現在の探索先から各方向を調べる
		for(i=0,j=(s==U)?L:s-1 ; i<4 ; i++,j++){
			//方向配列をループさせる
			if(j>=4)
				j = 0;

// s = r
// py,px = 4,3
// y,x = 4,2

			//次の探索先を計算
			y = py + dir4data[j][0];
			x = px + dir4data[j][1];
			
			//if(count==22) printf("#### y,x = %d,%d\n",y,x), printf("#### j=%d\n",j);
			
			//次の探索先が無効か0なら, スキップ
			if(x<0 || y<0 || x>=XMAX || y>=YMAX || array[y][x]==0){
				continue;
			}
			//探索先と現状態を更新, 状態が移ったのでいったん抜けて新たに探索する
			s = j;
			py += dir4pos[j][0];
			px += dir4pos[j][1];
			printstate(s);
			break;
		}
		/*
		printf("## count:%d s:",count);
		printstate(s); printf("\n");
		printf("## py,px = %d,%d\n",py,px);
		printf("## y,x = %d,%d\n",y,x);		
		printf("\n");
		*/
	}
	printf("\n");
  return 0;
}

/*
[メモ]
進行方向を一つの状態とみなす。
l,r,u,dで状態は四つ。

次状態は、どこに道があるかで決まる。
	(現状態) (次状態 左のものほど優先的に採用, なければ一つ右を採用)
	lのとき d, l, u, r
	rのとき u, r, d, l
	uのとき l, u, r, d
	dのとき r, d, l, u

メモ割り込むよ！--------
u -1,0
r 0,1
d 1,0
l 0,-1
これ配列に。
状態との対応付けはこう → u=0, r=1, d=2, l=3

現状態から順番に配列の方向にある要素が1かどうかを試す。
1を見つけたら, そこに進む。
インデックスの範囲越えには気をつけて。

やること
v	配列定義
v	定数定義(対応付けのとおりに数値を対応付けさせる)
	配列スキャン部分(ループにする)
	インデックス範囲越えを入れる
	1を見つけたら、そこに進むとか、そのへん。

	条件分岐はメンドくさい、規則性無いか？
	→時計回りだね。
	  抽象的なコード書く方がメンドくさそうなんで、直に書いちゃうか。。。
割り込みおわり--------

点Aに戻ってきたら終了。

ある奇数行i番目から直近辿れる偶数行の要素位置
	lのとき i番目
	rのとき i+1番目

ある偶数行i番目から直近辿れる奇数行位置
	次にlに行く i-1番目
	次にrに行く i番目

じゃあコード書くか。
入力データ処理部分おわり。
残りはどう書く？

要るのは表示、状態遷移、インデックス更新。
もっというと
	現状態から、どの要素を探索するかを決める
	要素を探索し、見つかった方向に対応する状態に遷移。
	現座標を遷移後に更新し、遷移後を出力。

[メモ2]
最悪。
入力データの解釈の仕方を間違えていた。。。
2行目からダウンするとき、次に読み込むのは3行目じゃない、「4行目」だ！

修正加えようとしたけど、次から次へと条件分岐が増える増える。
条件自体の修正も何度も行う行う。。。
で、わけがわからない。

いったんやり直そうか。

*/

Measured memory_bytes: 524
N, Z, W = map(int, input().split())
*A, = map(int, input().split())

import sys
sys.setrecursionlimit(10**6)

memo = {}
def dfs(i, turn):
    if (i, turn) in memo:
        return memo[i, turn]
    if turn == 0:
        # X
        if i == 0:
            res = abs(W - A[-1])
        else:
            res = abs(A[i-1] - A[-1])
        for j in range(i+1, N):
            res = max(res, dfs(j, 1))
    else:
        # Y
        if i == 0:
            res = abs(Z - A[-1])
        else:
            res = abs(A[i-1] - A[-1])
        for j in range(i+1, N):
            res = min(res, dfs(j, 0))
    memo[i, turn] = res
    return res
print(dfs(0, 0))


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

using namespace std;
typedef pair<int, int> pii;

int main(void) {
  int m, n;
  while (cin >> m, m) {
    vector<pii> p(m);
    for (int i = 0; i < m; i++) {
      cin >> p[i].first >> p[i].second;
      if (!i) continue;
      p[i].first -= p[0].first;
      p[i].second -= p[0].second;
    }

    cin >> n;
    vector<pii> q(n);
    set<pii> st;
    for (int i = 0; i < n; i++) {
      cin >> q[i].first >> q[i].second;
      st.insert(q[i]);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 1; j < m; j++) {
        pii r = pii(q[i].first + p[j].first, q[i].second + p[j].second);
        if (st.find(r) == st.end()) break;
        if (j != m - 1) continue;
        cout << q[i].first - p[0].first << " " << q[i].second - p[0].second << endl;
        i = n;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3052
<?php
$abc = array(
    0 => "A"
    , 1 => "B"
    , 2 => "C"
    , 3 => "D"
    , 4 => "E"
    , 5 => "F"
    , 6 => "G"
    , 7 => "H"
    , 8 => "I"
    , 9 => "J"
    , 10 => "K"
    , 11 => "L"
    , 12 => "M"
    , 13 => "N"
    , 14 => "O"
    , 15 => "P"
    , 16 => "Q"
    , 17 => "R"
    , 18 => "S"
    , 19 => "T"
    , 20 => "U"
    , 21 => "V"
    , 22 => "W"
    , 23 => "X"
    , 24 => "Y"
    , 25 => "Z"
);
$num = trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$result = "";
for ($i = 0;$i < strlen($str);$i++) {
    $tmp = substr($str,$i,1);
    $key = array_search($tmp,$abc);
    $slide = $key + $num;
    if ($slide > 25) {
        $slide -= 26;
    }
    $result .= $abc[$slide];
}

echo $result;
?>


Measured memory_bytes: 3956
def main():
    s = int(input())
    if s < 3:
        print(0)
        return
    mod = 10**9 + 7
    f = [1] * (s + 1)
    for i in range(s):
        f[i + 1] = (f[i] * (i + 1)) % mod
    inv = [0] * (s + 1)
    for i in range(s + 1):
        inv[i] = pow(f[i], mod - 2, mod)
    c = 0
    for n in range(1, s // 3 + 1):
        m = s - 3 * n
        c = (c + (f[m + n - 1] * inv[m] % mod) * inv[n - 1] % mod) % mod
    print(c)


if __name__ == '__main__':
    main()


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

int main() {
	int k, n,total = 0, mini;
	cin >> k >> n;
	vector<int> a(n),dis(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n - 1; i++) {
		dis[i] = a[i + 1] - a[i];
		total += dis[i];
	}
	dis[n - 1] = k + a[0] - a[n - 1];
	total += dis[n - 1];

	mini = total;

	for (int i = 0; i < n; i++) {
		mini = min(mini, total - dis[i]);
	}
	cout << mini << endl;
}


Measured memory_bytes: 1792
# D - Recording

N, C = map(int, input().split())
max_time = 10**5
gantt = [[0] * (max_time + 1) for _ in range(C+1)]
stc = []

for _ in range(N):
    stc.append(list(map(int, input().split())))
    
stc = sorted(stc, key = lambda x: x[0])
stc = sorted(stc, key = lambda x: x[2])    

for idx in range(N):
    s, t, c = stc[idx][0], stc[idx][1], stc[idx][2]
    try:
        if stc[idx-1][2] == c and stc[idx-1][1] == s:
            gantt[c][s+1] += 1
        else:
            gantt[c][s] += 1
    except IndexError:
        gantt[c][s] += 1
    if t+1 <= max_time:
        gantt[c][t+1] -= 1

for c in range(C+1):
    for idx in range(1, max_time+1):
        gantt[c][idx] += gantt[c][idx-1]

ans = 0
for idx in range(1, max_time+1):
    tmp = 0
    for c in range(C+1):
        tmp += gantt[c][idx]
    ans = max(ans, tmp)
    
print(ans)

Measured memory_bytes: 95192
#include <iostream>
using  namespace std;
int main()
{
	char Result[10000];
	int m, f, r = 0;
	for (int i = 0; i<10000; i++)
	{
		cin >> m >> f >> r;
		if ((m == -1) || (f == -1))Result[i] = 'F';
		else if (m + f >= 80)Result[i] = 'A';
		else if (m + f >= 65)Result[i] = 'B';
		else if ((m + f >= 50) || (r >= 50))Result[i] = 'C';
		else if (m + f >= 30)Result[i] = 'D';
		else Result[i] = 'F';
		if ((m == -1) && (f == -1) && (r == -1))
		{
		r = i;
		break;
		}
	}
	for (int i = 0; i<r; i++)
	{
		cout << Result[i] << endl;
	}
	return 0;
}

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

int main() {

    int N, K;
    cin >> N >> K;

    int ans = 0;

    while (N > 0) 
    {
        N /= K;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace kp
{
    public class Program
    {
        //static long[,] cmb;
        static int MAX_INT = 1000000007;
        static void Main(string[] args)
        {
            //int N = Int32.Parse(Console.ReadLine());
            decimal[] input = Console.ReadLine().Split().Select(p => decimal.Parse(p)).ToArray();
            decimal W = input[0];
            decimal H = input[1];
            decimal x = input[2];
            decimal y = input[3];

            // 面積の最大値 = 半分
            decimal area = W * H / 2;
            Console.Write(area + " ");
            // 分割方法が複数あるかどうか = x,yが中心なら '1' ちがうなら'0'
            bool isCenter = (W / 2 == x && H / 2 == y);

            if (isCenter)
                Console.WriteLine("1");
            else
                Console.WriteLine("0");

 
            
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
    /**
     * x???d?????????????????????
     * d????????¨????????°???
     * @return
     */
    public static boolean contain(int x, int d) {
        String s = String.format("%d", x);
        return s.contains(String.format("%d", d));
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for(int i=3;i<=n;i++) {
            if((i % 3) == 0 || contain(i, 3)) {
                System.out.print(" " + i);
            }
        }
        System.out.println("");
    }
}

Measured memory_bytes: 49604
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": # "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

const double EPS=1e-10;

typedef complex<double> point; // x,y
typedef pair<point,point> line; // pos,dir

int signum(double x)
{
	return abs(x)<EPS?0:x>0?1:-1;
}

double dot(const point& a,const point& b)
{
	return (a*conj(b)).real();
}

double cross(const point& a,const point& b)
{
	return (a*conj(b)).imag();
}

int ccw(const line& l,const point& p)
{
	point d1=l.second;
	point d2=p-l.first;
	double res=cross(d1,d2);
	if(signum(res))
		return signum(res);
	if(signum(dot(d1,d2))==-1) // c-a-b
		return +2;
	if(signum(norm(d2)-norm(d1))==1) // a-b-c
		return -2;
	return 0; // a-c-b
}

bool intersect_ls(const line& l,const line& s)
{
	point p1=s.first;
	point p2=s.first+s.second;
	int res=ccw(l,p1)*ccw(l,p2);
	return res==-1 || res==0;
}

bool intersect_ss(const line& a,const line& b)
{
	return intersect_ls(a,b) && intersect_ls(b,a);
}

bool intersect(double x[],double y[])
{
	point p1[4]={point(x[0],y[0]),point(x[1],y[0]),point(x[1],y[1]),point(x[0],y[1])};
	point p2[4]={point(x[2],y[2]),point(x[3],y[2]),point(x[3],y[3]),point(x[2],y[3])};
	line l1[4];
	line l2[4];
	rep(i,4){
		l1[i]=line(p1[i],p1[(i+1)%4]-p1[i]);
		l2[i]=line(p2[i],p2[(i+1)%4]-p2[i]);
	}
	rep(i,4)
		rep(j,4)
			if(intersect_ss(l1[i],l2[j]))
				return true;
	return false;
}

bool le(double a,double b)
{
	return a<b+1e-10;
}

bool between(double a,double b,double c)
{
	return le(a,b) && le(b,c);
}

string solve(double x[],double y[])
{
	int xi[]={0,1,0,1};
	int yi[]={0,0,1,1};
	rep(k,4)
		//if(le(x[2],x[xi[k]]) && le(x[xi[k]],x[3]) && le(y[2],y[yi[k]]) && le(y[yi[k]],y[3]))
		if(between(x[2],x[xi[k]],x[3]) && between(y[2],y[yi[k]],y[3]))
			return "YES";
	rep(k,4){
		xi[k]+=2;
		yi[k]+=2;
	}
	rep(k,4)
		//if(le(x[0],x[xi[k]]) && le(x[xi[k]],x[1]) && le(y[0],y[yi[k]]) && le(y[yi[k]],y[1]))
		if(between(x[0],x[xi[k]],x[1]) && between(y[0],y[yi[k]],y[1]))
			return "YES";
	if(intersect(x,y))
		return "YES";
	return "NO";
}

int main()
{
	for(double x[4],y[4];cin>>x[0]>>y[0];){
		repi(i,1,4)
			cin>>x[i]>>y[i];
		cout<<solve(x,y)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pairs;

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

    map<int, int> mp;

    rep(i,N){
        int tmp=A[i];
        mp[tmp]++;
        mp[tmp+1]++;
        mp[tmp-1]++;
    }
    int ans=0;
    int len=mp.size();
    for(auto tmp : mp){
        ans = max(ans, tmp.second);
    }

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

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

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

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

        if x == y:
            return

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

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

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def roots(self):
        return [i for i,x in enumerate(self.parents) if x < 0]

N,M = map(int, input().split())
towns = UnionFind(N)
for i in range(M):
    a,b= map(lambda x: int(x)-1, input().split())
    towns.union(a,b)

print(len(towns.roots())-1)


Measured memory_bytes: 13180
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[52];
bool f=false;
inline bool ok() {
	for (int i=1;i<n;++i)
		if (i^a[i]) return false;
	return true;
}
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	if (ok()) {
		puts("YES");
		return 0;
	}
	for (int i=1;i<n;++i) {
		for (int j=i+1;j<=n;++j) {
			swap(a[i],a[j]);
			if (ok()) {
				f=true;
				break;
			}
			swap(a[i],a[j]);
		}
		if (f) break;
	}
	puts(f?"YES":"NO");
	return 0;
}

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

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

  long long N;
  cin >> N;

  map<string, int> mp;
  long long ans = 0;
  for(int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ans += mp[s];
    mp[s]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11452
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  int n, k;cin>>n>>k;
  bool d[11]={};
  for(int i=0;i<k;i++){
    int a;cin>>a;d[a]=true;
  }
  int ans=n;
  while(true){
    bool valid=true;
    int t=ans;
  	while(t>0){
      if(d[t%10]){
      	valid=false;break;
      }
      t/=10;
    }
    if(valid)break;
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] c = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int res = b.Sum();
            for (int i = 0; i < n-1; i++)
            {
                if (a[i+1] - a[i] ==1)
                {
                    res += c[a[i]-1];
                }
            }

            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 13268
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  int A, B, C;
  ci(A, B, C);
  co(A * B / 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  vi d(11);
  rep(i, 3) {
    int a;
    cin >> a;
    d[a]++;
  }
  if (d[5] == 2 && d[7] == 1) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 3568
<?php
$N = fgets(STDIN);
$line = fgets(STDIN);
$a = explode(' ', trim($line));

$answerInt = -1;
$answerValue = 999999999;

for ($t = -100; $t <= 100; $t++) {
  $tmpAnswer = 0;
  foreach ($a as $b) {
    $cost = ($t - $b) * ($t - $b);
    $tmpAnswer = $tmpAnswer + $cost;
  }
  if ($answerValue > $tmpAnswer) {
    $answerValue = $tmpAnswer;
    $answerInt = $t;
  }
}

echo $answerValue;


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

int main() {
    string n;
    int ans=0;
    cin>>n;
    for (int i = 0; i < n.length(); ++i) {
        ans+=n[i]-'0';
    }
    if (ans%9!=0)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    cout << (x % 11 > 6) + (x % 11 != 0) + x / 11 * 2;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include<sstream>
#include <queue>
#include <limits>
#include <cstdlib>
#include <deque>
using namespace std;
int alf[26] ={};
int main() 
{	
string s;
cin>>s;
string ss ="abcdefghijklmnopqrstuvwxyz";
	for(int i=0; i<s.length(); i++)
	{		
	alf[(int)s[i]-97] =1;	
	}	
	int ans =100;	
	for(int i=0; i<26; i++)
	{		
	if(alf[i] ==0)
	{			
	ans =i;			
	break;		
	}	
	}	
	if(ans == 100)
	{		
	cout<<"None";
		}
		else 
		{		
		cout<<ss[ans];	
		}	
		return 0;
		}





Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,i,j=0,ans=0;
  string S;
  
  cin >> N >> K >> S;
  
    for(i=1;i<N;i++){
        if(S[i]!=S[i-1])j++; 
    }

    ans = min(N - j - 1 + 2*K,N-1);
 
  cout << ans << endl;
}


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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i = 0;i<n;i++)
    {
        cin>>arr[i];
    }
    vector<int> ans(n,INT_MAX);
    ans[0] = 0;
    for(int i = 0;i<n;i++)
    {
        for(int j = i+1;j<=i+k;j++)
        {
            if(j<n)
            {
                ans[j] = min(ans[j],ans[i]+abs(arr[i]-arr[j]));
            }
        }
    }
        cout<<ans[n-1];
    cout<<endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i=0; i<N; ++i) {
        long long a;
        cin >> a;
        while(!(a % 2)) {
            a /= 2;
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<int,int>;
using  v = vector<int>;

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

  for (int i = 0; i < n; i++)
  {
     if(i%2==0){
        b.push_back(a[i]);
     }else{
        b.push_front(a[i]);
     }
  }
  
  if(n%2==1){
     reverse(b.begin(),b.end());
  }
  copy(b.begin(),b.end(),ostream_iterator<int>(cout," "));
  
}
  
  

Measured memory_bytes: 3840
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
struct Node{
        int value;
        Node *prev,*next;
};
Node *nil;
void insert(int x){
        Node *now;
        now=(Node *)malloc(sizeof(Node));
        now->value=x;
        now->prev=nil;
        now->next=nil->next;
        nil->next->prev=now;
        nil->next=now;
        return;
}void _delete(int x){
        Node *now=nil->next;
        while(now!=nil){
                if(now->value==x)break;
                now=now->next;
        }
        if(now->value!=x)return;
        now->next->prev=now->prev;
        now->prev->next=now->next;
        free(now);
        return;
}void first(){
        nil->next->next->prev=nil;
        nil->next=nil->next->next;
        return;
}void last(){
        nil->prev->prev->next=nil;
        nil->prev=nil->prev->prev;
        return;
}
int main(){
        nil=(Node*)malloc(sizeof(Node));
        nil->prev=nil->next=nil;
        int N,x;
        string str;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                cin >> str;
                if(str=="deleteFirst"){
                        first();
                }else if(str=="deleteLast"){
                        last();
                }else{
                        cin >> x;
                        if(str=="insert"){
                                insert(x);
                        }else{
                                _delete(x);
                        }
                }
        }
        Node *now=nil->next;
        while(now!=nil){
                cout << now->value;
                now=now->next;
                if(now!=nil)cout<<" ";
        }
        cout << endl;
        return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n,m;cin>>n>>m;
    vector<int>c(m+1);

    rep(i,n){
        int k;cin>>k;
        rep(i,k){
            int a;cin>>a;
            c[a]++;
        }
    }

    int ans=0;
    rep(i,m){
        if(c[i+1]==n){
            ans++;
        }
    }
    cout<<ans<<endl;
}



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

int main(){
  string s;
  cin >> s;
  
  vector<char> A = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  bool x = true;
  for(int i = 0; i < 26; i++){
    if(count(s.begin(), s.end(), A[i]) % 2 == 1){
      x = false;
      break;
    }
  }
  if(x){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
 
}

  
    
      
              
    

Measured memory_bytes: 256
program kadai
implicit none
character(len=6)  ::  S

read(*,*) S

if (S=="Sunny") then
    write(*,*) "Cloudy"
else if (S=="Cloudy") then
    write(*,*) "Rainy"
else if (S=="Rainy") then
    write(*,*) "Sunny"
end if

stop
contains

end program kadai

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

class Program
{
    static int Solve(int[] A)
    {
        int N = A.Length;
        int[] B = A.OrderBy(a => a).ToArray();
        var rank = new Dictionary<int, int>();
        for (int i = 0; i < N; ++i)
        {
            rank[B[i]] = i;
        }
        int count = 0;
        for (int i = 0; i < N; ++i)
        {
            if (((rank[A[i]] ^ i) & 1) != 0) { ++count; }
        }
        return count / 2;
    }
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = new int[N];
        for (int i = 0; i < N; ++i)
        {
            A[i] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine(Solve(A));
    }
}


Measured memory_bytes: 15192
#include<iostream>
using namespace std;
int main(){
    int A[100010],n,i,ans=1;
    cin>>n;
    for(i=1;i<=n;i++) cin>>A[i];
    long long min=2,max=2;
    for(i=n;i>=1;i--){
        max=A[i]*(max/A[i]);
        max=max+A[i]-1;
        min=A[i]*((min-1)/A[i]+1);
        if(max<min){
            ans=0;
            break;
        }
    }
    if(ans==0) cout<<-1<<endl;
    else cout<<min<<" "<<max<<endl;
    return 0;
}



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

using namespace std;

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

  int index;
  for(int i = 0; i < n; i++) {
    if(a[i] == 1) {
      index = i;
      break;
    }
  }

  int ans = 1;
  ans += (n - k) / (k - 1);
  if((n - k) % (k - 1) != 0) {
    ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);


int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  
  int x0 = A[0] / 2;
  int xL = 0;
  int xR = A[0];
  while (true) {
    int nx = A[0] - x0;
    for(int i = 1; i < N; i++) {
      nx = A[i] - nx;
    }

    if (nx == x0) {
      break;
    } else if (nx > x0) {
      xL = x0;

      int tmp = (xR + x0) / 2;
      if (tmp == x0) x0 = tmp + 1;
      else x0 = tmp;


    } else {
      xR = x0;
      x0 = (xR+xL) / 2;
    }
  }

  cout << 2*x0 << " ";
  int nx = A[0] - x0;

  for (int i = 1; i < N; i++) {
    int ans = 2 * nx;
    if (i == N-1) {
      cout << ans << endl;
    } else {
      cout << ans << " ";
    }
    nx = A[i] - nx;
  }



  return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        // 主処理
        boolean isSiritori = (a.charAt(a.length() - 1) == b.charAt(0)) && (b.charAt(b.length() - 1) == c.charAt(0));
        String result = isSiritori ? "YES" : "NO";

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 21844
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0

a.sort()

for i in a:
  x-=i
  if x>0:
    ans+=1
    continue
  
  elif x==0:
    ans+=1
    break
    
  else:
    break
    
if ans==n:
  if x!=0:
    ans-=1


print(ans)


Measured memory_bytes: 61976
N = int(input())
a = list(map(int,input().split()))

count = 0

while True:
    #リストの中をすべて2で割る
    odd_cnt = 0
    for i in range(N):
        if a[i] % 2 == 1:
            odd_cnt += 1
        a[i] = a[i] / 2
    
    #奇数が一つでもあればbreak. そうでなければカウント追加してループ続行
    if odd_cnt > 0:
        break
    else:
        count += 1

print(count)


Measured memory_bytes: 38512
import java.lang.reflect.Array;
import java.util.*;
public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();



        if(n == 1){
            System.out.println("Hello World");

        }else{

            int a = sc.nextInt();

            int b = sc.nextInt();
            System.out.println(a+b);
        }

    }
}

Measured memory_bytes: 21844
N = int(input())
h = list(map(int, input().split()))

dp=[0]*N

for i in range(1,N):
	if i==1:
		dp[i] = abs(h[i] - h[i-1])
	else:
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])

Measured memory_bytes: 13928
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int num[10];

int cmp(const void *a, const void *b) {
	return *(int *)b - *(int *)a; 
}

int main() {
	while (scanf("%d", &num[0]) != EOF) {
		for (int i=1; i<10; ++i) scanf ("%d", &num[i]);
		qsort(num, 10, sizeof(int), cmp);
		printf ("%d\n%d\n%d\n", num[0], num[1], num[2]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;


int main(){
   int s;
   cin>>s;
   int a[1000000]={0};
   int i=1;
   a[0]=s;
   int flag=1;
   while(flag<2){
      if(a[i-1]%2==0){
         a[i]=a[i-1]/2;
      }
      else{
         a[i]=3*a[i-1]+1;
      }
      flag=count(a,a+i+1,a[i]);
      i++;
   }
   cout<<i<<endl;

   

}

Measured memory_bytes: 4096
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
    std::cin >> N;
    std::vector<int64_t> t(N + 1), x(N + 1), y(N + 1);
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    for (int64_t i = 1; i < N + 1; i++)
    {
        std::cin >> t[i] >> x[i] >> y[i];
    }

    bool ok = true;

    for (int64_t i = 0; i < N; i++)
    {
        int64_t time = t[i + 1] - t[i];
        int64_t dist = std::abs(x[i + 1] - x[i]) + std::abs(y[i + 1] - y[i]);
        if (dist > time) ok = false;
        else if (dist < time)
        {
            time = time - dist;
            if (time % 2 != 0) ok = false;
        }    
    }

    std::string ans = ok ? "Yes" : "No";
    std::cout << ans << std::endl;
}

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


Measured memory_bytes: 5492
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define f1(i,n) for(int i=1 ; i<=n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)

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

int n ,ans,a[mx2],b[mx2],c[mx2];

int main() {
    ios::sync_with_stdio(false);
    int t;
    //cin>>t;while(t--)
    {
        cin>>n;
        fo(i,n)cin>>a[i];
        Fo(i,1,n+1)cin>>b[i];
        Fo(i,1,n)cin>>c[i];
        ans+=b[a[0]];
        Fo(i,1,n)
        {
            if(a[i-1]+1==a[i])
            {
                ans+=b[a[i]]+c[a[i-1]];
            }
            else
            {
                ans+=b[a[i]];
            }
        }
        cout<<ans;
        
    }
    
    
    return 0;
}


Measured memory_bytes: 256