akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main{
 public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    int c = sc.nextInt();
    int d = sc.nextInt();
    String j = sc.next();
   if(a.equals(j)){
     c = c - 1;
   } else if(b.equals(j)){
   d = d - 1; 
   }
   System.out.println(c);
   System.out.println(d);
 } 
}

Measured memory_bytes: 23764
def main():
    n, m = map(int, input().split())

    res = [1, n]
    for i in range(m):
        l, r = map(int, input().split())
        res = [max(res[0], l), min(res[1], r)]
    print(max(0, res[1]-res[0]+1))

if __name__ == '__main__':
    main()



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

using namespace std;

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

  int n, k; 
  cin >> n >> k;
  vector<int> x(n);
  for (auto &xx : x) cin >> xx;
  int res = 1e9;
  for (int i = 0; i+k-1 < n; ++i) {
    if (x[i+k-1] <= 0) res = min(res, -x[i]);
    else if (x[i] >= 0) res = min(res, x[i+k-1]);
    else {
      int tmp = 2*min(-x[i], x[i+k-1]);
      tmp += max(-x[i], x[i+k-1]);
      res = min(res, tmp);
    }
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>

#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main()
{
	int H, W;

	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0) {
			break;
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i % 2 == 0) {
					if (j % 2 == 0) {
						cout << "#";
					}
					else {
						cout << ".";
					}
				}
				else {
					if (j % 2 == 0) {
						cout << ".";
					}
					else {
						cout << "#";
					}
				}
			}
			cout << endl;
		}
		cout << endl;
	}
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010,mod=1000000007,inv2=500000004;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,a[maxn],deg[maxn],ans=1,stk[maxn],tp,q[maxn],h,r,len[maxn],seq[maxn],tot,cnt[maxn];
int fac[maxn],inv[maxn],invfac[maxn];
bool vis[maxn],ins[maxn],cyc[maxn];
void dfs(int u){
	if(vis[u]){
		if(ins[u]){
			ROF(i,tp,1){
				cyc[stk[i]]=true;
				if(stk[i]==u) break;
			}
		}
		return;
	}
	vis[u]=ins[u]=true;
	stk[++tp]=u;
	dfs(a[u]);
	ins[u]=false;
}
bool dfs2(int u){
	if(vis[u]) return true;
	vis[u]=true;
	seq[++tot]=len[u];
	return dfs2(a[u]) && !len[u];
}
inline int C(int n,int m){
	return 1ll*fac[n]*invfac[m]%mod*invfac[n-m]%mod;
}
inline int qpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod;
	return ans;
}
int main(){
	n=read();
	FOR(i,1,n) a[i]=read(),deg[a[i]]++;
	FOR(i,1,n) dfs(i);
	FOR(i,1,n) if(cyc[i] && deg[i]>=3|| !cyc[i] && deg[i]>=2) return puts("0"),0;
	h=1;r=0;
	FOR(i,1,n) if(!deg[i]) q[++r]=i;
	while(h<=r){
		int u=q[h++];
		len[a[u]]=len[u]+1;
		if(!cyc[a[u]]) q[++r]=a[u];
	}
	MEM(vis,0);
	FOR(i,1,n) if(cyc[i] && !vis[i]){
		tot=0;
		if(dfs2(i)) cnt[tot]++;
		else{
			int pre=0;
			FOR(j,1,tot) if(seq[j]){
				if(pre){
					int at=j-seq[j];
					if(at<pre) return puts("0"),0;
					if(at>pre && tot>=2) ans=2*ans%mod;
				}
				pre=j;
			}
			FOR(j,1,tot) if(seq[j]){
				int at=j-seq[j]+tot;
				if(at<pre) return puts("0"),0;
				if(at>pre && tot>=2) ans=2*ans%mod;
				break;
			}
		}
	}
	fac[0]=fac[1]=inv[1]=invfac[0]=invfac[1]=1;
	FOR(i,2,n){
		fac[i]=1ll*fac[i-1]*i%mod;
		inv[i]=mod-1ll*(mod/i)*inv[mod%i]%mod;
		invfac[i]=1ll*invfac[i-1]*inv[i]%mod;
	}
	FOR(i,1,n) if(cnt[i]){
		int s=0;
		FOR(j,0,cnt[i]/2){
			int x=1ll*C(cnt[i],2*j)*C(2*j,j)%mod*fac[j]%mod;
			if(j) x=1ll*x*qpow(inv2,j)%mod*qpow(i,j)%mod;
			if(i%2==1 && i!=1) x=1ll*x*qpow(2,cnt[i]-2*j)%mod;
			s=(s+x)%mod;
		}
		ans=1ll*ans*s%mod;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N; cin >> N;
    
    int64 a; cin >> a;
    int64 max=a;
    int64 min=a;
    for(uint i=1; i<N; ++i){
        cin >> a;
        if(a>max){ max=a; }
        if(a<min){ min=a; }
    }
    cout << max-min << endl;
    
    return 0;
}

Measured memory_bytes: 256
// Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0; // unsearched state
static const int GRAY = 1; // ungrouped state
static const int BLACK = 2; // grouped state

int n, M[MAX][MAX];

void dijkstra() {
	int minv;
	int d[MAX], color[MAX];

	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;
	while (1) {
		minv = INFTY;
		int u = -1;
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK && M[u][v] != INFTY) {
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

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

	int u, k, v, c;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}

	dijkstra();

	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif


char s[N];

int main() {
	scanf("%s",s+1);
	int n = strlen(s+1);
	set<int> q;
	REP(i,1,n) q.insert(s[i]);
	int a = q.count('N')+q.count('S');
	int b = q.count('E')+q.count('W');
	puts(a==1||b==1?"No":"Yes");
}








Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	a, b := nextInt(), nextInt()
	if a > b {
		a, b = b, a
	}
	result := 0
	switch a + b {
	case 3:
		result = 3
	case 4:
		result = 2
	case 5:
		result = 1
	}
	fmt.Println(result)
}


Measured memory_bytes: 640
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    vector<int> ss(n);
    int mini = 1000;
    for(int i = 0; i < n; i++){
        cin >> ss[i];
        if(ss[i] % 10){
            mini = min(mini, ss[i]);
        }
    }
    int sum = accumulate(ss.begin(), ss.end(), 0);
    if(sum % 10 == 0){
        cout << (mini != 1000 ? sum - mini : 0) << '\n';
    }else{
        cout << sum << '\n';
    }
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    ld ans = 0.0;
    rep(i,n){
        ld a;
        string s;
        cin >> a >> s;
        if(s == "JPY")ans += a;
        else ans += 380000.0 * a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		StringBuilder builder = new StringBuilder();
	
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 1; i < n - 1; i++) {
				int a = i * i % n;
				if (!list.contains(a)) {
					list.add(a);
				}
			}
			int[] num = new int[(n + 1) / 2];
			for (int i = 1; i < list.size(); i++) {
				for (int j = 0; j < i; j++) {
					num[slove(i, j, list, n)]++;
					num[slove(j, i, list, n)]++;
				}
			}
			for (int i = 1; i < num.length; i++) {
				builder.append(num[i]).append('\n');
			}

		}
		System.out.print(builder);
	}

	private static int slove(int i, int j, List<Integer> list, int n) {
		int t = list.get(i) - list.get(j);
		if (t < 0) {
			t += n;
		}
		if (t > (n - 1) / 2) {
			t = n - t;
		}
		return t;
	}
}

Measured memory_bytes: 25104
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(void) {
    int vec[] = {1, -1, 4, -4};
    queue<string> que;
    que.push("01234567");
    map<string, int> d;
    while (!que.empty()) {
        string str = que.front(); que.pop();
        int zero = str.find("0");
        string str2;
        for (int i = 0; i < 4; i++) {
            int nextz = zero + vec[i];
            if (nextz >= 0 && nextz <= 7 && !((zero == 3 && nextz == 4) || (zero == 4 && nextz == 3))) {
                str2 = str;
                swap(str2[zero], str2[nextz]);
                if (d.find(str2) == d.end()) {
                    que.push(str2);
                    d[str2] = d[str] + 1;
                }
            }
        }
    }
    string num;
    while (getline(cin, num)) {
        string::iterator end_it = remove(num.begin(), num.end(), ' ');
        num.erase(end_it, num.end());
        cout << d[num] << endl;
    }
    return 0;
}

Measured memory_bytes: 3428
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  string s;
  cin>>s;
  int a=0;
  for(int i=0;i<N-1;i++)if(s[i]!=s[i+1])a++;
  cout<<N-1-max(a-2*K,0)<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;

string s1;
string s2;


const int MAXN = 2001;

int l[MAXN], r[MAXN];

pair <int, int> a[MAXN];
int ac = 0;
int n;

int m(int x) {
    x %= n;
    return (x >= 0) ? x : x + n;
}

int main() {
#ifdef PAUNSVOKNO
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20);
    cin >> s1 >> s2;
    n = s1.length();
    int c1 = 0, c2 = 0;
    for (int i = 0; i < n; i++) {
        if (s1[i] == '1') c1++;
    }

    for (int i = 0; i < n; i++)
        if (s2[i] == '1') c2++;

    if (c1 && !c2) {
        cout << -1 << "\n";
        return 0;
    }

    if (s1 == s2) {
        cout << 0 << "\n";
        return 0;
    }

    for (int i = 0; i < n; i++) {
        for (l[i] = 0; s2[m(i - l[i])] == '0'; l[i]++);
        for (r[i] = 0; s2[m(i + r[i])] == '0'; r[i]++);
    }

    int ans = MAXN * MAXN;

    for (int d = -n; d < n; d++) {
        ac = 0;
        int adc = 0;

        for (int i = 0; i < n; i++) {
            int ni = (i + n + d) % n;
            if (s1[i] == s2[ni]) continue;
            adc++;
            int nl = l[i] - max(-d, 0);
            int nr = r[i] - max(d, 0);
            if ((nl >= 0) && (nr >= 0)) a[ac++] = { nl, nr };
        }

        int cur = MAXN * MAXN;
        sort(a, a + ac);
        int mx = 0;

        for (int i = ac - 1; i >= 0; i--) {
            cur = min(cur, a[i].first + mx);
            mx = max(mx, a[i].second);
        }

        cur = min(cur, mx);

        ans = min(ans, abs(d) + cur * 2 + adc);
    }

    cout << ans << "\n";
}

Measured memory_bytes: 384
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
min_n = 0
max_n = 10**5

for i in range(M):
    min_n = max(min_n, LR[i][0])
    max_n = min(max_n, LR[i][1])

print(max(max_n-min_n+1, 0))


Measured memory_bytes: 60376
n,m,k=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0

sum_a = sum(a)
a_max = -1

for i in range(n)[::-1]:
    if sum_a <= k:
        a_max = i
        break
    else:
        sum_a -= a[i]

ans = a_max + 1

k_dis = max(0,k-sum_a)
i1 = 0

while k_dis >= b[i1]:
    k_dis -= b[i1]
    ans += 1
    i1 += 1
    if i1 > m-1:
        break 

ans1 = ans

if i1 < m-1:
    for i in range(a_max+1)[::-1]:
        k_dis += a[i]
        ans1 -= 1
        while i1 <= m-1 and k_dis >= b[i1]:
            k_dis -= b[i1]
            ans1 += 1
            i1 += 1
            if i1 > m-1:
                break
        ans = max(ans,ans1) 

print(ans)


Measured memory_bytes: 42204
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()

S = [input() for _ in range(H)]

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

for i in range(H):
	for j in range(W):
		if S[i][j] == "#":
			for k in range(4):
				y = i+dy[k]
				x = j+dx[k]
				if 0 <= y <= H-1 and 0 <= x <= W-1 and S[y][x] == "#":
					break
			else:
				print("No")
				exit()
print("Yes")


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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;

const int N = 31;

ll calc(int n,vll& memo){
    if(memo[n] != -1) return memo[n];
    ll ret = 0;
    for(int i=1;i<=3;i++){
        ret += calc(n-i,memo);
    }
    return memo[n] = ret;
}

int main(){
    vll memo(N,-1);
    memo[1] = 1;
    memo[2] = 2;
    memo[3] = 4;
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        cout << calc(n,memo) / 3650 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
#include<stdio.h>
int main(){
	int h1;
	int m1;
	int h2;
	int m2;
	int k;
	int result = 0;
	int x = 0;
	int y = 0;
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	x = h2 - h1;
	y = m2 - m1;
	result = (x*60) + y - k;
	printf("%d", result);
	return 0;
	
}

Measured memory_bytes: 1732
n, k = map(int, input().split())
H = []
for i in range(n):
  H.append(int(input()))
H.sort()
m = 10**9
for i in range(0, n-k+1):
  if H[i+k-1] - H[i] < m:
    m = H[i+k-1] - H[i]
print(m)

Measured memory_bytes: 7384
#include <iostream>

using namespace std;

int main()
{
    int  a = 1, b = 2, c = 3;
    int e,f;
    cin >> e >> f ;
    if(((e == a) && (f == b))|| ((e == b) && (f == a)))
        cout << c << endl;
    if(((e == a) && (f == c))|| ((e == c) && (f == a)))
        cout << b << endl;
    if(((e == c) && (f == b))|| ((e == b) && (f == c)))
        cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2-(y2-y1) << " " << y2+(x2-x1) << " " << x1-(y2-y1) << " " << y1+(x2-x1) << "\n";
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int>A(N);
  for (int i = 0; i < N-1; i++) {
    cin >> A.at(i);
  }
  
  vector<int>count(N-1,0);
  for (int i = 0; i < N-1; i++) {
    count.at(A.at(i)-1)++;
  }
  
  for (int i = 0; i < N-1; i++) {
    cout << count.at(i) << endl;
  }
  cout << 0 << endl;
}



Measured memory_bytes: 4824
def main():
    price = list(map(int, input().split()))
    a = [None]*4
    for i in range(4):
        a[i] = (2**i, price[i]*4/2**i, price[i])
    n = int(input())*4
    a = sorted(a, key=lambda x:x[1])
    res = 0
    # print(a, n)
    for q, c, p in a:
        res+=(n//q)*p
        n = n%q
    print(int(res))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;

int main() {

    ll x, k, d;
    cin >> x >> k >> d;
    if(x < 0) x = -x;
    if(x/d >= k) {
        return printf("%lld", x - d*k) * 0;
    }
    ll temp = x/d, remain = k - x/d;

    if(remain&1) cout << abs(x - temp*d - d);
    else cout << (x - temp*d);

    return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#define s(n) scanf("%d",&n);
#define sl(n) scanf("%lld",&n);
#define p(n) printf("%d",n);
#define pl(n) printf("%lld",n);
#define pr printf("\n");
#define LL long long
using namespace std;

const int maxn=1e5+5;
int num[maxn];

int main(){
    string a,b;
    cin>>a>>b;
    int i=0,j=0;
    while(i!=a.length() && j!=b.length()){
        cout<<a[i]<<b[j];
        i++;
        j++;
    }
    if(i!=a.length()){
        cout<<a[i];
    }
    if(j!=b.length()){
        cout<<b[j];
    }
    return 0;
}


Measured memory_bytes: 256
import Foundation
import CoreFoundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    func reversed() -> Array {
        return self.reverse()
    }
    func enumerated() -> EnumerateSequence<[Element]> {
        return self.enumerate()
    }
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}
//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}
//func lcm(x: Int, _ y: Int) -> Int {
//    return x * y / gcd(x, y)
//}

/*************** テストスペース ***************/

//arr.sort{$0.0==$1.0 ? $0.1<$1.1 : $0.0<$1.0}  // 2つの条件に優先順位をつけてソート

/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (X, A) = (input[0], input[1])
print(X<A ? 0 : 10)


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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

vector <int> g[N];
int dp[N];

void dfs(int node){
    dp[node] = 0;
    for(auto it : g[node]){
        if(dp[it] == -1){
            dfs(it);
        }
        dp[node] = max(dp[node], 1 + dp[it]);
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, m, x, y, ans, i;
    cin>>n>>m;
    memset(dp, -1, sizeof dp);
    for(i=0; i<m; i++){
        cin>>x>>y;
        g[x].pb(y);
    }
    for(i=1; i<=n; i++){
        if(dp[i] == -1) dfs(i);
    }
    ans = *max_element(dp, dp+n+1);
    cout<<ans;
    return 0;
}

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

int main() {
    int a, b, c, d, e, f;
    int sum=1, maxsug=0;
    cin >> a >> b >> c >> d >> e >> f;
    for (int i=0; i*a*100<=f; i++)
        for (int j=0; j*b*100+i*a*100<=f; j++)
            for (int k=0; k*c+i*a*100+j*b*100<=f; k++)
                for (int l=0; l*d+k*c+i*a*100+j*b*100<=f; l++) {
                    int sugar = k*c+l*d, wat = (i*a+j*b)*100;
                    if (wat != 0 && 
                            1.0 * 100 * sugar / wat <= e &&
                            1.0 * sugar / (sugar+wat) >= 1.0 * maxsug / sum) {
                        sum = wat + sugar; maxsug = sugar;
                    }
                }
    cout << sum << ' '<< maxsug << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    ll n;
    cin >> n;
    vector<ll> divs;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            divs.push_back(i);
            divs.push_back(n / 1);
        }
    }
    ll ans = 0;
    for (ll a : divs)
    {
        ll b = (n - a) / a;
        if (a < b)
        {
            ans += b;
        }
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define REP(i,n) for(int i = 0 ; i < n ; i ++) 
#define ms(a,c) memset(a,c,sizeof a)
#define INF 1e10
void min_self(int&x , int y) {x = min(x,y);}
int N , W , *w , *v ;
int dp[101][100001];
int f(int i , int cap) {
    if(i==N) {
        return 0;
    }
    int &ret = dp[i][cap];
    if(ret!=-1) {
        return ret;
    }
    int op1 = -INF , op2 = -INF ;
    if(cap - w[i] >= 0) {
        op1 = v[i] + f(i+1 , cap-w[i]);
    }
    op2 = f(i+1,cap);
    return ret = max(op1,op2);
}
int32_t main() {
    cin >> N >> W ;
    w = new int[N] ;
    v = new int[N] ;
    REP(i,N) {
        cin >> w[i] >> v[i] ;
    }
    ms(dp,-1);
    cout << f(0,W) << endl ;
    return 0;
}

Measured memory_bytes: 79104
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   char a;
   cin>>a;
   if(a=='A')cout<<'T'<<endl;
   if(a=='T')cout<<'A'<<endl;
   if(a=='G')cout<<'C'<<endl;
   if(a=='C')cout<<'G'<<endl;
}


Measured memory_bytes: 256
n=int(input())
p=list(map(float,input().split()))
dp=[[0]*(n+1) for _ in range(n+1)]
dp[1][0]=1-p[0]
dp[1][1]=p[0]
for i in range(2,n+1):
    for j in range(n+1):
        dp[i][j]=dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1]
print(sum(dp[n][(n//2+1):]))

Measured memory_bytes: 203216
#include <bits/stdc++.h>
using namespace std;
string s[2222];
int val[2222][2222];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<n;i++)
	{
		int cur=0;
		for(int j=0;j<m;j++)
		{
			val[i][j]+=cur;
			if(s[i][j]=='.')
				cur++;
			else
				cur=0;
		}
		cur=0;
		for(int j=m-1;j>=0;j--)
		{
			val[i][j]+=cur;
			if(s[i][j]=='.')
				cur++;
			else
				cur=0;
		}
	}
	for(int j=0;j<m;j++)
	{
		int cur=0;
		for(int i=0;i<n;i++)
		{
			val[i][j]+=cur;
			if(s[i][j]=='.')
				cur++;
			else
				cur=0;
		}
		cur=0;
		for(int i=n-1;i>=0;i--)
		{
			val[i][j]+=cur;
			if(s[i][j]=='.')
				cur++;
			else
				cur=0;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(s[i][j]=='.')
				ans=max(ans,val[i][j]);
		}
	}
	cout<<ans+1<<"\n";
	return 0;
}


Measured memory_bytes: 22784
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    string s;
    cin >> s;

    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2])cout << "Yes";
    else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1])cout << "Yes";
    else if(s[0] == s[3] && s[1] == s[2] && s[0] != s[1])cout << "Yes";
    else cout << "No";
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MOD = 1000000007;


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

    string ans = "Three";
    rep(i,N){
        if (S[i] == 'Y') {
            ans = "Four";
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
	return 0;
}

#define PRIMES 25
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int factors[PRIMES];

int count_factors(int n, int c){
	int r = n / c;
	if(r == 0) return 0;
	return count_factors(r, c) + r;
}

int count_comb(int c){
	int ret = 0;
	rep(i,PRIMES){
		ret += (factors[i] >= c);
	}
	return ret;
}

void Main(){
	int n; cin >> n;
	rep(i, PRIMES){
		factors[i] = count_factors(n, primes[i]);
	}

	auto v3 = count_comb(2);
	auto v5 = count_comb(4);
	auto v15 = count_comb(14);
	auto v25 = count_comb(24);
	auto v75 = count_comb(74);
	ll ans = v75;
	//ans += v25 * (v25 - 1) + (v3 - v25) * v25;
	ans += max(0, v25 * (v3 - 1));
	ans += max(0, v15 * (v5 - 1));
	ans += max(0, v5 * (v5 - 1) * (v5 - 2) / 2 + (v3 - v5) * (v5 - 1) * v5 / 2);
	cout << ans << endl;
}

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

int main(){
    
    int h, w;
    cin >> h >> w;
    while (h!=0 || w!=0){
        for (int i=0;i<h;i++){
            for (int j=0;j<w;j++){
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
        cin >> h >> w;
    }
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define MAX 1000000
typedef long long ll;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

//1-indexed
vector<int> xfields(MAX);
vector<int> yfields(MAX);
ll dp[MAX];

void solve(void){
    int H, W, D; scanf("%d %d %d\n", &H, &W, &D);
    rep(H, i) {
        rep(W, j) {
            int num;
            scanf("%d ", &num);
            xfields[num] = j;
            yfields[num] = i;
        }
        scanf("\n");
    }
    Rep(0, D-1, i){
        for (int d = 0; d < H*W; d+=D) {
            dp[i+d+D] = dp[i+d] + abs(xfields[i+d+D]-xfields[i+d]) + abs(yfields[i+d+D]-yfields[i+d]);
        }
    }
    int Q; scanf("%d\n", &Q);
    rep(Q, k){
        int l, r; scanf("%d %d\n", &l, &r);
        if (r == l) {
            printf("0\n"); continue;
        }
        printf("%lld\n", dp[r] - dp[l]);
    }
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

string change_to_s(int n){
    stringstream ss; ss<<n;
    return ss.str();
}

signed main(){
    int n;
    cin >> n;
    int MIN = 1e9;
    for(int i = 1; i * i <= n; i++){
        if(n % i == 0){
            int tmp = n / i;
            string s, t;
            s = change_to_s(i);
            t = change_to_s(tmp);
            MIN = min(MIN, max((int)s.size(), (int)t.size()));
        }
    }
    o(MIN);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

int main()
{
    int N,X;
    std::cin >> N >> X;
    int L[N];
    int count = 1;
    int D = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> L[i];
    }

    for (int i = 0; i < N; i++) {
        D = D + L[i];
        if (D <= X) {
            count = count + 1;
        } else {
            break;
        }
    }

    std::cout << count << '\n';
    return 0;
}

Measured memory_bytes: 256
/*
    to amy
    https://atcoder.jp/contests/abc133/tasks/abc133_c
*/

#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define F first
#define S second
#define MAX 2005

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main() {
    IOS
    int l,r;
    while(cin>>l>>r){
        r = min(r, l+2019);
        int ans = 2019,x,y;
        for(int i=l;i<=r;i++){
            for(int j=i+1;j<=r;j++){
                ans = min(1LL * ans, (1LL * i * j) % 2019);
            }
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	ll ans = 0;
	char prev = s[0];
	if (prev == 'R')
		ans++;
	if (s[1] == 'R') {
		if (s[0] == 'R')
			ans++;
		else
			ans=max(ans,1LL);
	}
	if (s[2] == 'R') {
		if (s[1] == 'R')
			ans++;
		else
			ans=max(ans,1LL);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3648
#include <cmath>
#include <iostream>

bool isPrime(int x) {
  int j = 3;
  float rt = std::sqrt(x);

  if (x == 2) {
    return true;
  }
  if (x < 2 || x % 2 == 0) {
    return false;
  }
  while (j <= rt) {
    if (x % j == 0) {
      return false;
    }
    j = j + 2;
  }
  return true;
}

int main() {
  int n, x, count;
  std::cin >> n;
  count = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> x;
    if (isPrime(x)) {
      count++;
    }
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            String S = sc.next();

            int[] card = new int[5];
            for (int i = 0; i < 5; i++) {
                card[i] = Integer.parseInt(S.split(",")[i]);
            }

            Arrays.sort(card);

            String ans;
            if (card[1] == card[4] || card[0] == card[3]) {
                ans = "four card";
            } else if ((card[0] == card[2] && card[3] == card[4]) || (card[0] == card[1] && card[2] == card[4])) {
                ans = "full house";
            } else if ((card[0] == card[2]) || (card[1] == card[3]) || (card[2] == card[4])) {
                ans = "three card";
            } else if ((card[0] == card[1] && card[2] == card[3]) || (card[0] == card[1] && card[3] == card[4]) || (card[1] == card[2] && card[3] == card[4])) {
                ans = "two pair";
            } else if ((card[0] == card[1]) || (card[1] == card[2]) || (card[2] == card[3]) || (card[3] == card[4])) {
                ans = "one pair";
            } else if ((card[0] + 4 == card[1] + 3 && card[1] + 3 == card[2] + 2 && card[2] + 2 == card[3] + 1 && card[3] + 1 == card[4]) || (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 && card[4] == 13)) {
                ans = "straight";
            } else {
                ans = "null";
            }

            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 25788
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[110000];
int sum[110000];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){scanf("%d",c+i);c[i]--;}
	for(int i=0;i<b-1;i++){
		int L=min(c[i],c[i+1]);
		int R=max(c[i],c[i+1]);
		sum[L]++;
		sum[R]--;
	}
	for(int i=1;i<a;i++){
		sum[i]+=sum[i-1];
	}
	long long ret=0;
	for(int i=0;i<a-1;i++){
		int p,q,r;
		scanf("%d%d%d",&p,&q,&r);
		ret+=min((long long)p*sum[i],(long long)q*sum[i]+r);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1808
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[0]*M
y=[0]*M
c=[0]*M
for i in range(M):
    x[i],y[i],c[i]=map(int,input().split())
mn=min(a)+min(b)
for i in range(M):
    if mn>(a[x[i]-1]+b[y[i]-1]-c[i]):
        mn=a[x[i]-1]+b[y[i]-1]-c[i]
print(mn)

Measured memory_bytes: 23340
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

score = 0
last_i = -2
for index in range(N):
  i = A[index]
  score += B[i - 1]
  if i == last_i + 1:
    score += C[last_i - 1]
  last_i = i
print(score)

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

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

vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

//複数個の最大公約数
ll ngcd(vector<ll> a)
{
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size() && res != 1; i++)
  {
    res = gcd(a[i], res);
  }
  return res;
}

//最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

//素因数分解
map<ll, ll> prime_factor(ll n)
{
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}

void Main()
{
  ll n;
  cin >> n;
  vll a(n + 2);
  a[0] = 0;
  rep(i, n)
  {
    cin >> a[i + 1];
  }
  a[n + 1] = 0;
  ll S = 0;
  for (ll i = 1; i < n + 2; i++)
  {
    S += abs(a[i - 1] - a[i]);
  }
  for(ll i = 1;i <= n;i++)
  {
    ll s = S;
    s = s - abs(a[i - 1] - a[i]) - abs(a[i + 1] - a[i]) + abs(a[i - 1] - a[i + 1]);
    cout << s << endl;
  }
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


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

int main(){
  int n;
  while(cin>>n,n){
    string str[50];
    for(int i=0;i<n;i++)cin>>str[i];

    int num[]={5,7,5,7,7},ans=1000000;
    for(int i=0;i<n;i++){
      for(int j=i,idx=0,cnt=0;j<n;j++){
	cnt+=str[j].size();
	if(cnt==num[idx]) idx++,cnt=0;
	if(cnt>num[idx])break;
	if(idx==5) ans=min(ans,i);
      }    
    }
    cout <<ans+1<<endl;
  }
  return 0;
}

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

void solver() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;

  if (!s.compare(u)) a--;
  if (!t.compare(u)) b--;

  cout << a << " " << b  << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll maxtime(ll x) {
    return (x+9) / 10 * 10;
}
 
ll remtime(ll x) {
    return maxtime(x) - x;
}
 
int main() {
    ios::sync_with_stdio(false);
    ll n = 5;
    //cin >> n;
    ll a[n];
    ll sum=0;
    ll remmax = -987654321;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += maxtime(a[i]);
        remmax = max(remmax, remtime(a[i]));
    }
    cout << sum - remmax << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL<<60;

void YN(bool x){
  if(x) cout<<"Yes";
  else cout<<"No";
  return;
}

int main() {
  int N,H,K; cin>>N>>H>>K;
  bool finish=false;
  rep(i,N){
    if(K-i*H==0) finish=true;
    else if(i==N-i) continue;
    else{
      if(K-i*H>0 && N-i-i>0){
        if((K-i*H)%(N-i-i)==0&&(K-i*H)/(N-i-i)<=H) finish=true;
      }
      else if(K-i*H<0 && N-i-i<0){
        if((H*i-K)%(i+i-N)==0&&(H*i-K)/(i+i-N)<=H) finish=true;
      }
    }
  }
  YN(finish);   
}


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

int main(){
    long long A, B, K;
    cin >> A >> B >> K;
    if (K > (A+B)) cout << 0 << " "<< 0 << endl;
    else if (K > A) cout << 0 << " " << B-(K-A) << endl;
    else cout << A-K << " " << B << endl;

    return 0;

}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>

int main(void) 
{
	int i,n,k=0;
	long seisuu[210]={0};	
	int hantei = 0;
	
	scanf("%d", &i );
	
	for (n = 0 ; n < i ; n++)
		scanf("%ld",&seisuu[n]);
		

	while (hantei == 0)	
	{
		
		for (n = 0 ; n < i ; n++)
		{
			if (seisuu[n] % 2 != 0) 
			{hantei = 1;
			break;}
			else	seisuu[n] /= 2	;	
		} 
		if (hantei == 0)
			k++;	
	}
	
	printf("%d",k);
	return 0;
}

/*配列の中の数字を全部2で割った後入れなおす*/

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

int degit(long long int n){
    int i = 0;
    while (n > 0){
        n /= 10;
        i++;
    }
    return i;
}

int main() {
    long long n;
    cin >> n;
    long long a = 1; //max
    long long b = 1; //min
    int ans = degit(n);
    long long int qans = 0;
    long long i = 1;

    for(i = 1; i * i <= n; i++){
        if(n % i == 0){
            b = n /a;
            qans = max(degit(a),degit(b));
            if(qans < ans) ans = qans;
        }
        a = i;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;

long long a,b,c,d,A,B,C,D,n,m;
long long min(long long a,long long b){return a<b?a:b;}
int main(){
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&n);n*=4;
	A=a*8;B=b*4;C=c*2;D=d;
	if (A>B) A=B;
	if (A>C) A=C;
	if (A>D) A=D;
	
	printf("%lld\n",n/8*A+(n%8==4?min(a*4,min(c,min(a*2+b,b*2))):0));
}

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

using namespace std;

int main() {

	int n, a, b;
	
	cin >> n >> a >> b;
	
	// 電車：
	if (n * a > b) { 
		cout << b;
	} else {
		cout << n * a;
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
    int N; cin >> N;
    vector<int> x(N), y(N), h(N);
    int s = -1;
    rep(i, N) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] > 0) s = i;
    }

    int Cx = 0, Cy = 0, Ch = 0;
    rep(X, 101) rep(Y, 101) {
        int H = h[s] + abs(X - x[s]) + abs(Y - y[s]);

        bool flg = true;
        rep(i, N) {
            int hi = max(H - abs(X - x[i]) - abs(Y - y[i]), 0);
            if (h[i] != hi) flg = false;
        }
        if (flg) Cx = X, Cy = Y, Ch = H;
    }
    cout << Cx << ' ' << Cy << ' ' << Ch << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

while (len(a) > 1):
   a.sort()
   a = [a[i] if i==0 else a[i]%a[0] for i in range(len(a))]
   a = [x for x in a if x != 0]

print(a[0])


Measured memory_bytes: 14252
#include <stdio.h>

int main() {
    int N, M, C;
    scanf("%d%d%d", &N, &M, &C);
    int B[M];
    for (int i=0; i<M; i++) {
      scanf("%d", &B[i]);
    }
    int res = 0;
    int temp;
    int A;
    for (int i=0; i<N; i++) {
      temp = C;
      for (int j=0; j<M; j++) {
        scanf("%d", &A);
        temp += A*B[j];
      }
      if (temp > 0) {
        res++;
      }
    }
    printf("%d", res);
}


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

typedef long long ll;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H + 2);
    rep(i, W + 2) {
        s[0].push_back('#');
        s[H + 1].push_back('#');
    }
    rep(i, H) {
        cin >> s[i + 1];
        s[i + 1] = "#" + s[i + 1] + "#";
    }
    //rep(i, H + 2) cout << s[i] << "\n";
    vector<vector<vector<bool>>> grid(H + 2, vector<vector<bool>>(W + 2, vector<bool>(6, false)));
    queue<vector<int>> q;
    q.push({1, 1, 4, 0, 5, 4, 1, 3, 2});//xyzUDFBLR
    grid[1][1][5] = true;
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int x = p[0], y = p[1], z = p[2];
        if (!grid[x - 1][y][p[3]] && s[x - 1][y] - '1' == p[5]) {
            q.push({x - 1, y, p[3], p[6], p[5], p[3], p[4], p[7], p[8]});
            grid[x - 1][y][p[3]] = true;
        }
        if (!grid[x + 1][y][p[4]] && s[x + 1][y] - '1' == p[6]) {
            q.push({x + 1, y, p[4], p[5], p[6], p[4], p[3], p[7], p[8]});
            grid[x + 1][y][p[4]] = true;
        }
        if (!grid[x][y - 1][p[5]] && s[x][y - 1] - '1' == p[7]) {
            q.push({x, y - 1, p[5], p[8], p[7], p[5], p[6], p[3], p[4]});
            grid[x][y - 1][p[5]] = true;
        }
        if (!grid[x][y + 1][p[5]] && s[x][y + 1] - '1' == p[8]) {
            q.push({x, y + 1, p[5], p[7], p[8], p[5], p[6], p[4], p[3]});
            grid[x][y + 1][p[5]] = true;
        }
    }
    rep(i, 6) {
        if (grid[H][W][i]) {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
}


Measured memory_bytes: 3980