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

using namespace std;

const int maxn = 123456;
int dp[maxn][3], h[maxn][3];
const int inf = 0x7f7f7f7f;
int main(){
//    freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> h[i][0] >> h[i][1] >> h[i][2];
    }
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= n ; ++i){
        for(int j = 0; j < 3; ++j){
            for(int k = j + 1; k <= j + 2; ++k){
                dp[i][j] = max(dp[i][j], h[i-1][k%3] + dp[i-1][k%3]);
            }
        }
    }
    int res = 0;
    for(int i = 0; i < 3; ++i)res = max(dp[n][i], res);
    cout << res << endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a;
    int max = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        a = 0;
        for (int j = i; j > 0; j=j/2) {
            if (j > 0) {
                a++;
            }
        }
        if (max < a) {
            ans = i;
            max = a;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
        String s2 = sc.next();
        int n = s1.length() - 1;
        for(int i = 0; i < s1.length(); i++){
        	if(s1.charAt(i) != s2.charAt(n)){
            	System.out.println("NO");
                return;
            }
            n--;
        }
        System.out.println("YES");
	}
}

Measured memory_bytes: 35592
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

    int max_k = (n - 1) * (n - 2) / 2;
    if(k > max_k) {
        cout << -1 << endl;
        return 0;
    }

    int m = (n - 1) + (max_k - k);
    cout << m << endl;

    // 0 is center
    FOR(i, 1, n) {
        cout << 1 << " " << i + 1 << endl;
    }

    int cnt = max_k - k;
    FOR(i, 1, n)FOR(j, i + 1, n) {
        if(cnt == 0) break;
        else {
            cout << i + 1 << " " << j + 1 << endl;
            cnt--;
        }
    }

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
    double x,y,a,c,rad;
    a=c=0;
    rad=M_PI/2;
    while(scanf("%lf,%lf",&x,&y),x||y){
        a+=x*sin(rad);
        c+=x*cos(rad);
        rad-=y/180*M_PI;
    }
    cout<<(int)c<<endl<<(int)a<<endl;
    return 0;
}

Measured memory_bytes: 1236
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, m := scanInt(), scanInt()
	a := make([]int, n+1)
	b := make([]bool, n+1)
	for i := range a {
		a[i] = 1
	}
	b[1] = true
	for i := 0; i < m; i++ {
		x, y := scanInt(), scanInt()
		if b[x] {
			if a[x] == 1 {
				b[x] = false
			}
			b[y] = true
		}
		a[x]--
		a[y]++
	}
	ans := 0
	for _, v := range b[1:] {
		if v {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    ll a, b, n; cin >> a >> b >> n;
    ll ret = 0; 
    if (b!=1) { 
        ll x = min(b-1, n);
        ret += a*x/b;
        ret -= a*(x/b);
    } 
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="Yes";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];
        int M=Integer.MIN_VALUE;
        List<Integer> ListX=new ArrayList<>();
        List<Integer> ListY=new ArrayList<>();
        //int x[];
        //int y[];


        //入力
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int A = sc.nextInt();

        if(X<A)
        {
            answer=0;
        }else if(X>=A)
        {
            answer=10;
        }
        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
}

Measured memory_bytes: 22608
#include <stdio.h>

int main(void)
{
  	int N=0;
  	int N1=0,N2=0,N3=0;
  
  	scanf("%d",&N);
  	N1=N/100;
  	N2=(N%100)/10;
  	N3=(N%100)%10;
  
  	if(N1==7){
    puts("Yes");
    }else if(N2==7){
    puts("Yes");
    }else if(N3==7){
    puts("Yes");
    }else{
    puts("No");
    }
  
  	return 0;
  
}


Measured memory_bytes: 2032
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <locale>
#include<set>



using namespace std;

#define MAX 200000
int main() {

    bool ans=true;
long long n,m,i,j,k,fow,pt=0,anns=0,a1,a2,a3;
long long syurui=0;
long long c[3][3];
for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      cin>>c[i][j];
    }
}
    for(i=1;i<3;i++){
        for(j=1;j<3;j++) {
            if (c[i][j] - c[i - 1][j] != c[i][j - 1] - c[i - 1][j - 1]){
                ans=false;
            }
            if (c[j][i] - c[j - 1][i] != c[j][i - 1] - c[j - 1][i - 1]){
                ans=false;
            }
        }
    }
if(ans){
    cout << "Yes" << endl;
}else{
    cout << "No" << endl;
}
 return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

/* プロセスを表す構造体 */
typedef struct pp {
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b) { return a < b ? a : b; } /* 最小値を返す */

int main() {
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);

	/* 全てのプロセスをキューに順番に追加する */
	for (i = 1; i <= n; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1; tail = n + 1;

	/* シミュレーション */
	while (head != tail) {
		u = dequeue();
		c = min(q, u.t);  /* q または必要な時間 u.t だけ処理を行う */
		u.t -= c;  /* 残りの必要時間を計算 */
		elaps += c;  /* 経過時間を加算 */
		if (u.t > 0) enqueue(u);  /* 処理が完了していなければキューに追加 */
		else {
			printf("%s %d\n", u.name, elaps);
		}
	}

	return 0;
}


Measured memory_bytes: 12724
#include <iostream>
#include <set>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, m, n) for (int i = m; i <= n; ++i)
using namespace std;

int main() {
    int N, d[110];
    cin >> N;
    REP(i,N) cin >> d[i];

    set<int> values;
    REP(i,N) {
        values.insert(d[i]);
    }

    cout << values.size() << endl;
}

Measured memory_bytes: 256
a= int(input())
liss = [input() for i in range(a)]

lis = sorted(liss)

maxCount = 1
nCount = 1
maxlist = []


for i in range(a):
    if i != a-1:
        if lis[i] == lis[i + 1]:
            nCount += 1
            if nCount > maxCount:
                maxCount += 1
                maxlist.clear()
            continue
        elif maxCount == nCount:
            maxlist.append(lis[i])

        nCount = 1
    else:
        if maxCount == nCount:
            maxlist.append(lis[i])



lis = sorted(lis)

for s in maxlist:
    print(s)

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

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

  int q;
  cin >> q;
  int t[ q ];
  for( int i = 0; i < q; i++ ) {
    cin >> t[ i ];
  }

  int cnt = 0;
  for( int i = 0; i < q; i++ ) {
    for( int j = 0; j < n; j++ ) {
      if( t[ i ] == s[ j ] ) {
        cnt += 1;
        break;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3128
import  * as fs from 'fs';
const [noUse, inp] = fs.readFileSync("/dev/stdin", "utf8").split("\n");

const a: bigint[] = inp.split(" ").map((s: string) => BigInt(s));
if (a.includes(BigInt(0))) {
    console.log(0);
    process.exit(0);
}

let ans: bigint = BigInt(1);
a.forEach((n: bigint) => {
    ans = BigInt(ans) * BigInt(n);
    if (ans > Math.pow(10, 18)) {
        console.log(-1);
        process.exit(0);
    }
});

console.log(ans.toString());


Measured memory_bytes: 45508
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>

#define int long long int

bool compare(const int &a, const int &b)
{
    return a > b;
}

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

    int x[100010], y[100010];
    for (int i = 0; i < n; ++i)
    {
        std::cin >> x[i] >> y[i];
    }
    x[n] = 0;
    y[n] = 0;

    std::sort(x, x + n + 1, compare);
    std::sort(y, y + n + 1);

    int ans = 0;
    for (int i = 0; i <= n; ++i)
    {
        if (x[i] > y[i])
            ans += 2 * (x[i] - y[i]);
    }

    std::cout << ans;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<vector<int>> A(N, vector<int>(3));
  REP(i, N) REP(j, 3) cin >> A[i][j];

  vector<vector<int>> dp(N+1, vector<int>(3, -INF));
  REP(j, 3) dp[0][j] = 0;

  REP(i, N){
    chmax(dp[i+1][0], A[i][0]+max(dp[i][1], dp[i][2]));
    chmax(dp[i+1][1], A[i][1]+max(dp[i][0], dp[i][2]));
    chmax(dp[i+1][2], A[i][2]+max(dp[i][0], dp[i][1]));
  }

  int ans = 0;
  REP(j, 3){
    chmax(ans, dp[N][j]);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 11264
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
bai,gu = 0,0
for i in 0..n-1
	if a[i]%4 == 0
		bai += 1
	elsif a[i]%2 == 0
		gu += 1
	end
end
res = bai+gu/2
if res >= n/2
	puts 'Yes'
else
	puts 'No'
end

Measured memory_bytes: 11524
#!/usr/bin/env python3

import sys, math, copy
from collections import deque
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def adj_node(path, paths, neighbor):
    for end in [path[0], path[-1]]:
        for node in neighbor[end - 1]:
            if node not in paths:
                is_begin = (end == path[0])
                return node, is_begin
    return None, True

def get_path():
    n, m = map(int, input().split())
    am = []
    bm = []
    for i in range(m):
        a, b = map(int, input().split())
        am.append(a)
        bm.append(b)
    assert len(am) == len(bm) == m

    neighbor = [[] for j in range(n)]
    for i in range(m):
        a, b = am[i], bm[i]
        neighbor[a - 1].append(b)
        neighbor[b - 1].append(a)

    path = deque([am[0], bm[0]])
    paths = set(path)
    for j in range(10 ** 6):
        node, is_begin = adj_node(path, paths, neighbor)
        if node is None:
            return path
        paths.add(node)
        if is_begin:
            path.appendleft(node)
        else:
            path.append(node)

def main():
    path = get_path()
    print(len(path))
    print(" ".join(map(str, path)))

main()


Measured memory_bytes: 30084
#include<bits/stdc++.h>
#define mx(a,b) (a>b?a:b)
#define mn(a,b) (a<b?a:b)
using namespace std;
string s;int ans=1<<30; 
int main()
{
	cin>>s;
	for(int i=1;i<s.length();i++)
		if(s[i]!=s[i-1])
			ans=mn(ans,mx(i,int(s.length())-i));
	printf("%d\n",mn(ans,int(s.length())));
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct node{
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};

typedef struct node *NodePointer;

void insert(int);
int Search(NodePointer, int);
void Preorder(NodePointer);
void Inorder(NodePointer);

NodePointer root = NULL; 


int main () {
  int n = 0, i, x = 0;
  char str[7];


  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    scanf("%s",str);
    if(strcmp(str,"insert") == 0) {
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(str,"print") == 0) {
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
    else {
      scanf("%d",&x);
      if(Search(root, x) == 1) printf("yes\n");
      else printf("no\n");
    }
  }
  

  return 0;
}


int Search(NodePointer p, int x) {
  if(p == NULL) return 0;
  else if(p->key == x) return 1;
  else if(p->key > x) return Search(p->left, x);
  else return Search(p->right, x);
}










void insert(int z) {
  NodePointer p, x = root, y = NULL;
  
  p = (NodePointer)malloc(sizeof(struct node));

  p->key = z;
  
  while(x != NULL) {
  
    y = x;
    
    if(z < x->key) x = x->left;
    else x = x->right; 
  }
  
  p->parent = y; 
  
  if(y == NULL) root = p;
  else if(p->key < y->key) y->left = p;
  else y->right = p; 

  p->left = NULL;
  p->right = NULL;
  

}

void Preorder(NodePointer cur) {

  if(cur != NULL) {
    printf(" %d",cur->key);
    Preorder(cur->left);
    Preorder(cur->right);
  }
  
}


void Inorder(NodePointer cur) {

  if(cur != NULL) {
    Inorder(cur->left);
    printf(" %d",cur->key);
    Inorder(cur->right);
  }
}



Measured memory_bytes: 20516
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;
int main() {
  string s;
  cin >> s;
  if (s == "SUN") {
    cout << 7 << endl;
  } else if (s == "MON") {
    cout << 6 << endl;
  } else if (s == "TUE") {
    cout << 5 << endl;
  } else if (s == "WED") {
    cout << 4 << endl;
  } else if (s == "THU") {
    cout << 3 << endl;
  } else if (s == "FRI") {
    cout << 2 << endl;
  } else if (s == "SAT") {
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
struct state {
	int x, y, cost;
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost < s2.cost;
}
int dir[] = { 0, 1, 0, -1 };
int W, H, a[109][109], x[9], y[9], cnt, dist[7][7], d[109][109], dp[9][135], popcount[135]; string s[109];
int main() {
	for (int i = 0; i < 7; i++) {
		for (int j = 1 << i; j < 2 << i; j++) {
			popcount[j] = popcount[j - (1 << i)] + 1;
		}
	}
	cin >> W >> H;
	for (int i = 0; i < H; i++) fill(a[i], a[i] + W, 1);
	for (int i = 0; i < H; i++) {
		cin >> s[i];
		for (int j = 0; j < W; j++) {
			if (s[i][j] == 'S') x[0] = i, y[0] = j;
			if (s[i][j] == 'G') x[1] = i, y[1] = j;
			if (s[i][j] == 'M') x[cnt + 2] = i, y[cnt + 2] = j, cnt++;
			if (s[i][j] == '#') {
				for (int dx = -2; dx <= 2; dx++) {
					for (int dy = -2; dy <= 2; dy++) {
						int c = max(abs(dx), abs(dy));
						int tx = i + dx, ty = j + dy;
						if (0 <= tx && tx < H && 0 <= ty && ty < W) {
							int r = 2;
							if (c == 0) r = 999999999;
							if (c == 1) r = 3;
							a[tx][ty] = max(a[tx][ty], r);
						}
					}
				}
			}
		}
	}
	int p = cnt + 2;
	for (int i = 0; i < p; i++) {
		for (int j = 0; j < H; j++) fill(d[j], d[j] + W, 999999999);
		d[x[i]][y[i]] = 0;
		priority_queue<state> que; que.push(state{ x[i], y[i], 0 });
		while (!que.empty()) {
			state u = que.top(); que.pop();
			for (int j = 0; j < 4; j++) {
				int tx = u.x + dir[j], ty = u.y + dir[j ^ 1];
				int cost = d[u.x][u.y] + a[u.x][u.y];
				if (0 <= tx && tx < H && 0 <= ty && ty < W && d[tx][ty] > cost) {
					d[tx][ty] = cost;
					que.push(state{ tx, ty, -cost });
				}
			}
		}
		for (int j = 0; j < p; j++) dist[i][j] = d[x[j]][y[j]];
	}
	for (int i = 0; i < p; i++) fill(dp[i], dp[i] + (1 << p), 999999999);
	dp[0][1] = 0;
	for (int i = 3; i < 1 << p; i += 2) {
		for (int j = 0; j < p; j++) {
			if (!(i & (1 << j))) continue;
			int sub = i - (1 << j);
			for (int k = 0; k < p; k++) {
				if (!(sub & (1 << k))) continue;
				int s = sub - (1 << (k - 1));
				dp[j][i] = min(dp[j][i], dp[k][sub] + dist[k][j]);
			}
		}
	}
	cout << dp[1][(1 << p) - 1] << endl;
	return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int A,B,a,b,c,n;
int main()
{
	cin>>n>>A>>B;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		if(x<=A)a++;
		else if(x>A&&x<=B)b++;
		else c++;
	}
	cout<<min(a,min(b,c));
	return 0;
}

Measured memory_bytes: 256
from heapq import heapreplace, heapify


N = int(input())
A = list(map(int, input().split()))

dp = [0] * (N + 1)
q = A[:N]
heapify(q)
dp[0] = sum(q)
for i in range(N, 2 * N):
    a = A[i]
    if a > q[0]:
        dp[i - N + 1] += a - heapreplace(q, a)
    dp[i - N + 1] += dp[i - N]


dp2 = [0] * (N + 1)
q = [-A[i] for i in range(2 * N, 3 * N)]
heapify(q)
dp2[N] = -sum(q)
for i in range(2 * N - 1, N - 1, -1):
    a = A[i]
    if a < -q[0]:
        dp2[i - N] += a - (-heapreplace(q, -a))
    dp2[i - N] += dp2[i - N + 1]

ans = -float('inf')
for i in range(N + 1):
    ans = max(ans, dp[i] - dp2[i])
print(ans)


Measured memory_bytes: 40340
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007 
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<long long> next;
	next.push_back(0);
	REP(i, n) {
		long long a;
		cin >> a;
		next.push_back(a);
	}
	next.push_back(0);
	long long ans = 0;
	for (int i = 1; i <= n+1; ++i) {
		ans += abs(next[i] - next[i - 1]);
	}
	for (int i = 1; i <= n; ++i) {
		long long geko = abs(next[i + 1] - next[i - 1]) - (abs(next[i] - next[i - 1]) + abs(next[i + 1] - next[i]));
		cout << ans + geko << endl;
	}
	return 0;
}

Measured memory_bytes: 2796
s = gets.chomp.split("").map(&:to_s);
t = gets.chomp.split("").map(&:to_s);

n = (s.length) - (t.length)+1
time=Array.new(n,0)

for i in 0..n-1 do
	for j in 0..(t.length-1) do
		if s[i+j] == t[j] then
			time[i]+=1
		end
	end
end

p (t.length) - time.max

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  string s,t;cin>>s>>t;
  ll n=s.size();
  ll m=t.size();
  auto v=vec(n,26,-1);
  vector<ll>a(26,-1);
  rrep(i,n,0){
    rep(j,0,26)v[i][j]=a[j];
    a[s[i]-'a']=i;
  }
  rrep(i,n,0){
    rep(j,0,26)v[i][j]=a[j];
    a[s[i]-'a']=i;
  }
  buf=0;
  //debug(v,n,26);
  ll i=0;
  if(t[0]==s[0]){
    i=1;
  }
  res=1;
  for(;i<m;i++){
    ll d;
    ll p=v[buf][t[i]-'a'];
    if(p==-1){
      judge=false; break;
    }
    if(p<=buf)d=p+n-buf;
    else d=p-buf;
    res+=d;
    buf=p;
  }
  ans(judge,res,-1);
  return 0;
}

Measured memory_bytes: 13776
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */
int ans = 1e6;
int N, K;
set<int> st;
void dfs(string s){
  int num = stoi(s);
  if(num >= N){
    ans = min(ans, num);
    return;
  }
  FOREACH(x, st){
    dfs(s + to_string(x));
  }
}

int main() {
  cin >> N >> K;
  REP(i, 10) st.insert(i);
  REP(i, K){
    int D;
    cin >> D;
    st.erase(D);
  }

  FOREACH(x, st){
    if(x != 0) dfs(to_string(x));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld n,r,i,j,t,c,k,p,q,a,b;string s11,s22;
   cin>>a>>b>>c;
   if((a==7&&b==5&&c==5)||(a==5&&b==7&&c==5)||(a==5&&b==5&&c==7))
   	cout<<"YES";
   else
   	cout<<"NO";

}

Measured memory_bytes: 256
l = input().split()
A = int(l[0])
B = int(l[1])
C = int(l[2])
if B==C:
    print(2*B)
elif B>C:
    print(B+C)
else:
    if A>=C-B:
        print(B+C)
    else:
        print(A+B*2+1)


Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
x=[0]*(n+1)
p=10**9+7
for i in a:
   x[i]+=1
if n%2==0:
    m=n//2
    f=0
    for i in range(m):
        if x[2*i+1]!=2:
            f=1
    if f==1:
        print(0)
    else:
        print(pow(2,m,p))
else:
    m=n//2
    f=0
    if x[0]!=1:
        f=1
    for i in range(m):
        if x[2*i+2]!=2:
            f=1
    if f==1:
        print(0)
    else:
        print(pow(2,m,p))


Measured memory_bytes: 84516
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum,ans, dp[10000][2], a[110000],b[110000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<LL>v;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m;
	rep(i, 4) {
		if (m < pow(10, i)) {
			n *= pow(10, i);
			n += m;
			break;
		}
	}
	if ((int)sqrt(n)*(int)sqrt(n) == n)
		f = 1;
	yn(f);
	return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;

public class Main
{
	public static void main(String[] arg) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s;

		while((s=br.readLine())!=null)
		{
		    int n = Integer.valueOf(s);
  		    System.out.println(numOfPrimes(n));
		}
	}
	
	private static int numOfPrimes(int n)
	{
	    if(n<2)  return 0;
	    if(n==2) return 1;
	    if(n==3) return 2;

	    int i=4;
	    ArrayList<Integer> primes = new ArrayList<Integer>();
	    primes.add(2);
	    primes.add(3);

	    while(i <= n)
	    {
		if(i%2==0) { 
		} else if(i%3==0) {
		} else {
	            boolean found = true;
		    int size = primes.size();
		    for(int j=0; j<size; j++){
			// confirms whether square i has been checked
			int i2 = primes.get(j) * primes.get(j);
			if(i < i2) break;
			// finds i isn't a prime num
			if(i%primes.get(j)==0) {
				found = false;
				break;
			}
		    }
		    if(found) primes.add(i);
		}
		i++;
	    }
	    return primes.size();
	}
}

Measured memory_bytes: 14000
/* 
 * Author: pawanmsr
 */

// #include <iostream>
// #include <iomanip>
// #include <string>
// #include <vector>
// #include <algorithm>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <iterator>
// #include <list>
// #include <stack>
// #include <map>
// #include <set>
// #include <functional>
// #include <numeric>
// #include <utility>
// #include <limits>
// #include <fstream>
// #include <cstring>

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //
ll h, w;

// Functions //


// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    /* code */
    cin >> h >> w;
    if (h==1 || w==1) cout << 1 << endl;
    else if (h%2==0 || w%2==0) cout << h * w / 2 << endl;
    else cout << h * w / 2 + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

int main() {
	int y = 0;
	long long int x, sum = 100;

	scanf("%lld", &x);
	while (1) {
		if (sum >= x) break;
		sum = (long long int)(sum*1.01);
		y++;
	}
	printf("%d",y);

	return 0;
}

Measured memory_bytes: 1732
sx, sy, tx, ty = map(int, input().split())

H = tx - sx
W = ty - sy

r1 = ["U" for i in range(W)]
r2 = ["D" for i in range(W)]
for i in range(H):
    r1 += "R"
    r2 += "L"
STR1 = ''.join(r1)
STR2 = ''.join(r2)
print(STR1+STR2+"LU"+STR1+"RDRD"+STR2+"LU")


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(BigInteger.Parse).ToArray();
        Array.Sort(A);
        BigInteger ans = 1;
        for (int i = 0; i < N; i++)
        {
            ans *= A[i];
            if (ans > 1000000000000000000)
            {
                WriteLine(-1);
                return;
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 65184
#!/usr/bin/env python3
# coding=utf-8

import collections
import sys

n = sys.stdin.readline().strip()
a = sys.stdin.readline().strip().split(" ")
a_count = collections.Counter(a)
ans = 0
for k, v in a_count.items():
    if int(k) > v:
        ans += v
    else:
        ans += v - int(k)
print(ans)

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

namespace Aoj_Learning2
{
    class Program
    {
        static void Main(string[] args)
        {
            Aoj_Learning13();
        }

        private static void Aoj_Learning13()
        {
            string[] str = new string[20000];
            int n, q = 0;
            int[] S = new int[10000];
            int[] T = new int[500];
            int count = 0;

            // 数列Sの個数取得
            n = int.Parse(Console.ReadLine());
            // 数列Sを取得
            str = Console.ReadLine().Split(' ');
            for(int i = 0; i < n; i++)
            {
                S[i] = int.Parse(str[i]);
            }
            // 数列Tの個数取得
            q = int.Parse(Console.ReadLine());
            // 数列Tを取得
            str = Console.ReadLine().Split(' ');
            for (int i = 0; i < q; i++)
            {
                T[i] = int.Parse(str[i]);
            }

            // 数列Sを数列Tで線形探索
            for (int i = 0; i < q; i++)
            {
                for(int j = 0; j < n; j++)
                {
                    if(T[i] == S[j])
                    {
                        count++;
                        break;
                    }
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 15996
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			String str ;
			while(!(str = scan.next()).equals("0")){
				int sum = 0;
				for(int i = 0 ; i< str.length();i++){
					sum += Integer.parseInt(str.substring(i,i + 1));
				}
				System.out.println(sum);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
}

Measured memory_bytes: 17256
package main

import (
	"fmt"
	"math"
)

// 無限大の値
const inf = math.MaxInt64 / 2

// DP テーブル
var dp []int

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var n int
	fmt.Scan(&n)
	h := make([]int, n)
	for i := range h {
		fmt.Scan(&h[i])
	}

	// 初期化 (最小化問題なので INF に初期化)
	dp = make([]int, n)
	for i := range dp {
		dp[i] = inf
	}

	// 初期条件
	dp[0] = 0

	// ループ
	for i := 1; i < n; i++ {
		chmin(&dp[i], dp[i-1]+abs(h[i]-h[i-1]))
		if i > 1 {
			chmin(&dp[i], dp[i-2]+abs(h[i]-h[i-2]))
		}
	}

	// 答え
	fmt.Println(dp[n-1])
}


Measured memory_bytes: 5504
from sys import exit
# A,B,C = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
S1 = str(input())[::-1]
if (S == S1):
    print("YES")
else: 
    print("NO")


Measured memory_bytes: 2940
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 5e5 + 10 , P = 1e9 + 7;
inline void pp(int &x,int d) {if((x+=d)>=P)x-=P;}
inline int mul(int a,int b) {return ll(a)*b%P;}
int n , p[N] , fac[N] , vis[N];

struct Fenwick{
  int n,a[N];
  void add(int x,int d) {for(;x<=n;x+=x&-x)pp(a[x],d);}
  int sum(int x) {int r=0;for(;x>=1;x&=x-1)pp(r,a[x]);return r;}
}f0,f1;

int main(){
  fac[0]=1;rep(i,1,N) fac[i]=ll(fac[i-1])*i%P;
  scanf("%d",&n);
  int zero = 0;
  f0.n=f1.n=n;
  rep(i,1,n+1) {
    scanf("%d",p+i);
    if(p[i]) vis[p[i]] = true;
    else zero++;
  }
  rep(i,1,n+1) if(!vis[i]) f0.add(i,1);
  int ans = 0 , rightzero = zero , leftzero = 0 , sumfac = 0;
  rep(i,1,n+1) {
    if(!p[i]) {
      rightzero--;
      leftzero++;
      // 0 0
      if(zero >= 2)
        pp(ans , mul(fac[zero - 2] , mul(fac[n - i] , mul(rightzero , ll(zero) * (zero - 1) / 2 % P))));
      pp(sumfac , fac[n - i]);
    } else {
      if(zero >= 1) {
        // 0 x
        pp(ans , mul(fac[zero - 1] , mul(sumfac , zero - f0.sum(p[i]))));
        // x 0
        pp(ans , mul(fac[zero - 1] , mul(fac[n - i] , mul(rightzero , f0.sum(p[i])))));
      }
      // x x
      pp(ans , mul(fac[zero] , (f1.sum(n) - f1.sum(p[i]) + P) % P));
      f1.add(p[i] , fac[n - i]);
    }
  }
  pp(ans , fac[zero]);
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 9984
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.range;

void main() {
    size_t n;
    string s;
    readf("%d\n%s\n", &n, &s);
    auto a = s.split.map!(to!int).array;
    assert(a.length == n);
    sort!"a > b"(a);
    int alice, bob;
    foreach (i, e; a) {
        if (i % 2 == 0) alice += e;
        else bob += e;
    }
    writeln(alice - bob);
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift();
   if(n=="0000")break;
   if(n=="1111" || n=="2222" || n=="3333" || n=="4444" || n=="5555"){console.log("NA");continue;}
   if(n=="6666" || n=="7777" || n=="8888" || n=="9999"){console.log("NA");continue;}
   var i=0;
   while(true){
      if(n=="6174")break;
      i++;
      var arr=n.split("").map(Number);
      arr.sort(function(a,b){return b-a;});
      var L=parseInt(""+arr[0]+arr[1]+arr[2]+arr[3],10);
      var S=parseInt(""+arr[3]+arr[2]+arr[1]+arr[0],10);
      n=("0000"+(L-S)).slice(-4);
   }
   console.log(i);
}

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

int n, m;
bool graph[10][10], visited[10];

int dfs(int i){
  int sum = 0;
  bool flag = true;
  rep(j, n){
    if(!visited[j]){
      flag = false;
    }
  }
  if(flag){
    //cerr <<" path"<< endl;
    return 1;
  }
  rep(j, n){
    if(graph[i][j] && !visited[j]){
      //cerr << j << " ";
      visited[j] = true;
      sum += dfs(j);
      visited[j] = false;
    }
  }
  //cerr << endl;
  return sum;
}

int main(){
  cin >> n >> m;
  rep(i, n)rep(j, n) graph[i][j] = false;
  rep(i, n) visited[i] = false;
  visited[0] = true;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    graph[a][b] = graph[b][a] = true;
  }
  //rep(i, n){rep(j, n) cerr << graph[i][j]; cerr << endl;} 
  cout << dfs(0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n,d,a;
  scanf("%d%d",&n,&d);
  a=((n)/(1+2*d))+1;
  if((n)%(1+2*d)==0){
  printf("%d",a-1);}
  else{
  printf("%d",a);}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    int n;
    string s, t;
    cin >> n;
    cin >> s;
    cin >> t;

    for(int i = n; i >= 0; i--){
        if(s.substr(n-i,i) == t.substr(0, i)){
            cout << 2*n-i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int len, x, a = 1, sum = 0, ve;
  scanf("%d %d", &len, &x);
  for(int i = 0; i < len; i++){
    scanf("%d", &ve);
    sum += ve;
    if(sum <= x) a++;
  }
  printf("%d\n", a);
  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "../benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int re[1123][1123];

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	if(0){
		int h=4,w=5;
		rep(st,1<<20){
			rep(i,h)rep(j,w) re[i][j]=(st>>(w*i+j)&1);
			int ok=1;
			vector<int> tmp(2);
			rep(i,h){
				int a=0;
				rep(j,w) a+=re[0][j];
				a=min(a,w-a);
				int b=0;
				rep(j,w) b+=re[i][j];
				if(min(b,w-b)!=a) ok=0;
				tmp[0]=a;
			}
			rep(j,w){
				int a=0;
				rep(i,h) a+=re[i][0];
				a=min(a,h-a);
				int b=0;
				rep(i,h) b+=re[i][j];
				if(min(b,h-b)!=a) ok=0;
				tmp[1]=a;
			}
			if(ok){
				rep(i,h){rep(j,w) cout<<re[i][j]; cout NL;} cout NL;
				out(tmp,1);
			}
		}
		return 0;
	}
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	rep(i,h){rep(j,w) cout<<((i<b)==(j<a));cout NL;}
	return 0;		
	if(min(a,b)==0){
		if(a+b){
			cout<<"No"<<endl;
		}else{
			rep(i,h){rep(j,w) cout<<re[i][j];cout NL;}
		}
		return 0;
	}
	if(a*h!=b*w){
		cout<<"No"<<endl;
		return 0;
	}
	int swp=0;
	if(h<w){
		swap(h,w); swap(a,b);
		swp=1;
	}
	rep(i,h)rep(j,a) re[i][(i+j)%w]=1;
	int ok=1;
	rep(j,w){
		int sum=0;
		rep(i,h) sum+=re[i][j];
		if(min(h-sum,sum)!=b) ok=0;
	}
	if(ok){
		if(swp){
			rep(i,w){rep(j,h) cout<<re[j][i];cout NL;}
		}else{
			rep(i,h){rep(j,w) cout<<re[i][j];cout NL;}
		}
	}else{
		cout<<"No"<<endl;
	}
  return 0;
}


Measured memory_bytes: 1280
N = input()

if(int(N[-1]) == 2 or int(N[-1]) == 4 or int(N[-1]) == 5 or int(N[-1]) == 7 or int(N[-1]) == 9):
    print("hon")
if(int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8) :
    print("pon")
if(int(N[-1]) == 3) :
    print("bon")


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int k = (A + B);
  
  if ((k % 2) ==1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
  cout << k /2 <<endl;
  }
}


Measured memory_bytes: 256
package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution() string {
	return ""
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var xs int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	for x := 1; x < 6; x++ {
		scanner.Scan()
		xs = fastGetInt(scanner.Bytes())
		if xs == 0 {
			fmt.Println(x)
			break
		}
	}

	//======================================================

	//==================== OUTPUT ==========================

}


Measured memory_bytes: 1816
import sys
import math
import bisect

def main():
    A = list(map(int, input().split()))
    B = []
    for i in range(3):
        for j in range(3):
            for k in range(3):
                if j != i and k != i and k != j:
                    val = abs(A[j] - A[i]) + abs(A[k] - A[j])
                    B.append(val)
    print(min(B))

if __name__ == "__main__":
    main()


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

string S;
const int mod = 1000000007;

signed main() {
    int N;
    cin >> N >> S;
    int left = 0, right = 0;
    int ans = 1;
    for (int i = 0; i < 2 * N; ++i) {
        if ((left - right) % 2 == 0) {
            if (S[i] == 'B') {
                left++;
            } else {
                ans *= (left - right);
                right++;
            }
        } else {
            if (S[i] == 'W') {
                left++;
            } else {
                ans *= (left - right);
                right++;
            }
        }
        if (right > left) {
            cout << 0 << endl;
            return 0;
        }
        ans %= mod;
    }
    if (left != right) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 1; i <= N; ++i) {
        ans *= i;
        ans %= mod;
    }
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int m1,d1,m2,d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(m1==m2){
		cout << 0 << endl;
	}
	else{
		cout << 1 << endl;
	}

	return 0;
}



Measured memory_bytes: 888
function Main(input) {
  input = input.trim()
  input = input.split("\n");
  input[0] = input[0].split(" ").map(Number);
  input[1] = input[1].split(" ").map(Number);
  console.log((input[0][0]-input[1][0])*(input[0][1]-input[1][1]))
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    int findRoot(int x) {
        return data[x] < 0 ? x : data[x] = findRoot(data[x]);
    }
    void uniteSet(int x, int y) {
        x = findRoot(x), y = findRoot(y);
        if (x != y) {
            if (data[x] < data[y]) swap(x,y);
            data[x] += data[y];
            data[y] = x;
        }
    }
    int size(int x) {
        return -data[findRoot(x)];
    }
    bool same(int x, int y) {
        return findRoot(x) == findRoot(y);
    }
};

struct State {
    int idx;
    int value;
};

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

    UnionFind uf(N);

    vector<int> ps;
    for (int i=0; i<N; i++) {
        int p;
        cin >> p;
        ps.push_back(p - 1);
    }

    for (int i=0; i<M; i++) {
        int x, y;
        cin >> x >> y;
        uf.uniteSet(x - 1, y - 1);
    }

    // ぐるーぷをまとめる
    vector<vector<State> > group(N);
    for (int i=0; i<N; i++) {
        group.at(uf.findRoot(ps.at(i))).push_back( State{i, ps.at(i)} );
    }
    
    // ぐるーぷごとにマッチする数を数える
    int ans = 0;
    for (int i=0; i<group.size(); i++) {
        map<int,int> iS;
        for (int j=0; j<group.at(i).size(); j++) {
            State s = group.at(i).at(j);
            iS[s.idx] = 1;
        }
        for (int j=0; j<group.at(i).size(); j++) {
            State s = group.at(i).at(j);
            if (iS.count(s.value)) {
                ans++;
            }
        }
    }

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

Measured memory_bytes: 8820
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define ld long double
#define ub upper_bound
#define lb lower_bound
#define pii pair<int,int>
using namespace std;
signed main()
{
    fast;
    int n;
    cin>>n;
    vector<pii> v;
    for(int i = 1;i<=n ; i++){
        int x,l;
        cin>>x>>l;
        v.pb({x+l,x-l});
    }
    sort(all(v));
    int ans = 0;
    int px = -1e18;
    for(auto it:v){
        if(it.second>=px){
            ans++;
            px = it.first;
        }
    }
    cout<<ans;
}   

Measured memory_bytes: 2420