akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
long long n,a,b,ans;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if (a>b){
		printf("0\n");
		return 0;
	}
	if (n==1){
		if (a==b) printf("1\n");else printf("0\n");
		return 0;
	}
	ans=(n-2)*(b-a)+1;
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

int main() {
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double mindegree=m*6,hourdegree=(0.5*m)+(30*h);
    double degree=abs(mindegree-hourdegree);
    
    double ans=(a*a)+(b*b)-(2*a*b*cos((degree*pi/180)));
    cout << setprecision(20) << sqrt(ans) << endl; 
    
	return 0;
}

Measured memory_bytes: 4220
import math
def p(d): print(d)
def i(): return input()

def LI():  # Line Integer
    # 1行 1つの数字
    return int(input())
def LIS():  # Line IntegerS
    # 1行 mつの数字
    return [int(x) for x in input().split()]
def MLIS(n):  # Multi Line IntegerS
    # n行 mつの数字
    return [[int(x) for x in input().split()] for y in range(n)]
def LC():  # Line Character
    # 1行 1つの文字列
    return input()
def LCS(): # Line CharacterS
    # 1行 nつの文字列
    return [x for x in input().split()]
def MLCS(n): # Multi Line CharacterS
    # n行 mつの文字列
    return [[x for x in input().split()] for y in range(n)]

def alp2int(alphabet):
    # アルファベットの番号を返す
    return ord(alphabet) - ord('a')
def int2alp(num):
    # 番号からアルファベットを返す
    return chr(num + ord('a'))
def cnt2dic(lst, dic={}):
    # 同じものをカウントして辞書型にする
    for x in lst:
        key = str(x)
        if key in dic:
            dic[key] += 1
        else:
            dic[key] = 1
    return dic
def dic2lst(dic, key=lambda x:x[1]):
    # 辞書をタプルの配列にする
    return sorted(list(dic.items()), key=key);

def unqlst(lst):
    return list(set(lst))

def A():
    a = LC()
    if a[0] == a[2]:
        print('Yes')
    else:
        print('No')

def B():
    a, b, c, d = LIS()
    s = max(a, c)
    e = min(b, d)
    if s < e:
        p(e-s)
    else:
        p(0)

def C():
    N = LI()
    reds = sorted(MLIS(N), key=lambda x:x[0])
    blues = sorted(MLIS(N), key=lambda x:x[0])

    blueF = [False for x in range(N)]

    count = 0

    for i in range(N):
        for j in range(N):
            if blueF[j] == False and reds[i] < blues[j]:
                blueF[j] = True
                count += 1
                break
    print(count)

def D():
    pass

def E():
    s = LC()
    k = LI()
    words = []
    for b in range(len(s)):
        for e in range(1, 6):
            if s[b:b+e] != '':
                words.append(s[b:b+e])
    words = sorted(unqlst(words))
    print(words[k-1])
def F():
    pass

def G():
    n = LI()
    A = LIS()
    B = [A[i] - (i+1) for i in range(n)]
    B = sorted(B)

    b = B[n//2]

    count = 0
    for i in range(n):
        kana = abs(A[i] - (b + i + 1))
        count += kana
    print(count)

def H():
    pass

G()


Measured memory_bytes: 27052
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int s[210][210];
int que[210],dep[210];
int n,k;

inline int read()
{
	register char ch=getchar();
	register int sum(0);
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') sum=sum*10+(ch^48),ch=getchar();
	return sum;
}

int work(int v)
{
	memset(dep,0,sizeof(dep));
	memset(que,0,sizeof(que));
	int head(0),tail(1);
	dep[v]=1,que[1]=v;
	while(head<tail)
	{
		++head;
		int u=que[head];
		for(int i=1;i<=n;++i)
		if(s[u][i])
			{
				if(!dep[i]) que[++tail]=i,dep[i]=dep[u]+1;
				else if((dep[i]-1!=dep[u])&&(dep[i]+1!=dep[u])) return 0;
			}
	}
	for(int i=1;i<=n;++i) k=max(k,dep[i]);
	return 1;
}

int main()
{
	n=read();
	for(int i=1;i<=n;++i)
	{
		char ch=getchar();
		while(ch!='0'&&ch!='1') ch=getchar();
		for(int j=1;j<=n;++j)
			s[i][j]=ch-'0',ch=getchar();
	}
	int flag(0);
	for(int i=1;i<=n;++i) 
	flag|=work(i);
	if(flag) cout<<k;
	else cout<<-1;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>   // popen, pclose, fgets
#include <cstdlib> 
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; //long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
const double PI=3.14159265358979323846;
//小数点以下を指定したい時　　→→→→  cout << fixed << setprecision();
//int→string
//string→int   int num = atoi(numStr.c_str());

int main() {
    int x,n,p[n],a,b,ans;cin>>x>>n;
    rep0(i,n){
        cin>>p[i];
    }
    rep0(i,100){
        a=x+i;
        b=x-i;
        bool A=true;
        bool B=true;
        for(int j=0;j<n;j++){
            if(p[j]==a){
                A=false;
            }
        }
        rep0(j,n){
            if(p[j]==b){
                B=false;
            }
        }
        if(A){
                ans=a;
            }
            if(B){
                ans=b;
            }
            if(A){
                break;
            }
            if(B){
                break;
            }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include<iostream>
#define M 1000000007
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

P parse(string s){
  P res = P(0,0);
  for(int i=0;i<2;i++){
    //cout << s << endl;
    int k = 0,pos = 0;
    while(pos<s.size()){
      if(s[pos] == '(')k++;
      if(s[pos] == ')')k--;
      if(!k && s[pos] == '|'){
	P a = parse(s.substr(0,pos));
	P b = parse(s.substr(pos+1,(int)s.size()-pos-1));
	res.first = (res.first + a.first * b.first) % M;
	res.first = (res.first + a.second * b.first) % M;
	res.first = (res.first + a.first * b.second) % M;
	res.second = (res.second + a.second * b.second) % M;
	//cout << res.first << " " << res.second << endl;
	return res;
      }
      pos++;
    }
    k = 0,pos = 0;
    while(pos<s.size()){
      if(s[pos] == '(')k++;
      if(s[pos] == ')')k--;
      if(!k && s[pos] == '&'){
	P a = parse(s.substr(0,pos));
	P b = parse(s.substr(pos+1,(int)s.size()-pos-1));
	res.first = (res.first + a.first * b.first) % M;
	res.second = (res.second + a.second * b.first) % M;
	res.second = (res.second + a.first * b.second) % M;
	res.second = (res.second + a.second * b.second) % M;
	//cout << res.first << " " << res.second << endl;
	return res;
      }
      pos++;
    }
    
    if(s[0] == '(' && s[(int)s.size()-1] == ')'){
      s.erase(s.begin());
      s.erase(s.end()-1);
    }else break;
  }


  if(s[0]=='~'){
    P a = parse(s.substr(1,(int)s.size()-1));
    res.first = a.second;
    res.second = a.first;
  }else{
    res.first = 1;
    res.second = 1;
  }
  //cout << res.first << " " << res.second << endl;
  return res;
}

int main(){
  string s;
  cin >> s;
  P p = parse(s);
  cout << p.first << endl;
}

Measured memory_bytes: 7044
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 100;

int n, k;
int h[MAXN];
int DP[MAXN];

int rek(int pos) {
	if (pos == n - 1) return 0;
	int &ret = DP[pos];
	if (ret != -1) return ret;
	ret = INF;
	FOR(i, 1, k) {
		if (pos + i < n) ret = min(ret, rek(pos + i) + abs(h[pos] - h[pos + i]));
	}
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	memset(DP, -1, sizeof DP);
	cin >> n >> k;
	REP(i, n) cin >> h[i];
	cout << rek(0) << '\n';
}

Measured memory_bytes: 5760
def check():
    N,K = map(int, input().split())
    total = 0
    
    if K == 0: return N**2
    
    for b in range(1,N+1):
        if b <= K:
            continue
        
        amari = N-b*(N//b)        
        test = amari-K+1 if amari >= K else 0           
        total += (b - K) * (N//b) + test
    return total
print(check())

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

unsigned long long numAttacks(long long H)
{
	if(H == 0)
		return 0;
		
	if(H == 1)
		return 1;
		
	return numAttacks(H / 2) * 2 + 1; 
}

int main()
{
	long long H;
	scanf("%lld", &H);
	
	printf("%llu", numAttacks(H));
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int R = scan.nextInt();
    int rate = 0;
    if (N >= 10) {
      rate = R;
    }
    else{
      int a = 100 * (10 - N);
      rate = R + a;
    }
    System.out.println(rate);
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
#define MAX 500000
#define SEN 2000000000

int c=0;

void merge(int A[], int n, int left, int mid, int right){
	int n1=mid-left;
	int n2=right-mid;
	int L[MAX/2+2],R[MAX/2+2];
	
	for(int i=0;i<n1;i++){
		L[i]=A[left+i];
	}
	for(int i=0;i<n2;i++){
		R[i]=A[mid+i];
	}
	L[n1]=SEN;
	R[n2]=SEN;
	
	int i=0,j=0;
	
	for(int k=left;k<right;k++){
		if(L[i]<=R[j]){
			A[k]=L[i];
			i++;
		}else{
			A[k]=R[j];
			j++;
		}
		c++;
	}
}

void mergesort(int A[], int n, int left, int right){
	int mid;
	
	if(left+1<right){
		mid=(left+right)/2;
		mergesort(A,n,left,mid);
		mergesort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int main(void){
	int A[MAX];
	int n;
	
	scanf("%d",&n);
	for(int i;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	mergesort(A,n,0,n);
	
	printf("%d",A[0]);
	for(int i=1;i<n;i++){
		printf(" %d",A[i]);
	}
	printf("\n");
	
	printf("%d\n",c);
	
	
	return 0;
}


Measured memory_bytes: 5700
N = int(input())
A = [int(_) for _ in input().split()]

#positive
pos_count = 0
sign = 1
cumsum = 0
for a in A:
    cumsum += a
    if cumsum * sign <= 0:
        pos_count += abs(sign - cumsum)
        cumsum = sign
    sign *= -1

#negative
neg_count = 0
sign = -1
cumsum = 0
for a in A:
    cumsum += a
    if cumsum * sign <= 0:
        neg_count += abs(sign - cumsum)
        cumsum = sign
    sign *= -1

print(min(pos_count, neg_count))


Measured memory_bytes: 14332
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int a, b, ans;
	scanf("%d %d", &a, &b);

	ans = max({ a + b, a - b, a*b });

	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  string A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  string C[n];
  for(int i=0;i<n;i++) C[i]=A[i];
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(C[j][1]<C[j-1][1]){
	swap(C[j],C[j-1]);
      }
    }
  }
  string x[10],y[10];
  for(int i=0;i<n;i++){
    x[A[i][1]-'0']+=A[i][0];
    y[C[i][1]-'0']+=C[i][0];
  }
  ans=1;
  for(int i=0;i<10;i++) ans&=x[i]==y[i]; 
  for(int i=0;i<n;i++) cout<<C[i]<<" \n"[i==n-1];
  cout<<(ans?"Stable":"Not stable")<<endl;
  
  for(int i=0;i<n;i++) C[i]=A[i];
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(C[j][1]<C[minj][1]){
	minj=j;
      }
    }
    if(i!=minj) swap(C[i],C[minj]);
  }
  
  for(int i=0;i<10;i++) x[i]=y[i]="";
  for(int i=0;i<n;i++){
    x[A[i][1]-'0']+=A[i][0];
    y[C[i][1]-'0']+=C[i][0];
  }
  ans=1;
  for(int i=0;i<10;i++) ans&=x[i]==y[i]; 
  for(int i=0;i<n;i++) cout<<C[i]<<" \n"[i==n-1];
  cout<<(ans?"Stable":"Not stable")<<endl;
  
  return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int main() {
	int n, t;
	vector<P> pa;
	int rc = INF;
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		P t3;
		cin >> t3.first >> t3.second;
		if (t3.second <= t ) {
			if (t3.first < rc) {
				rc = t3.first;
			}
		}
	}
	if (rc == INF) {
		cout << "TLE" << endl;
	} else {
		cout << rc << endl;
	}
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N; cin>>N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	VL b(N);
	FOR(i, 0, N) {
		cin >> b[i];
	}
	VL c(N);
	FOR(i, 0, N) {
		cin >> c[i];
	}
	SORT(a), SORT(b), SORT(c);
	LL ans = 0;
	for (auto bi : b) {
		auto ac = lower_bound(ALL(a),bi) - a.begin();
		auto cc = N - (upper_bound(ALL(c), bi) - c.begin());
		DD(de(ac, cc));
		ans += ac * cc;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 2560
n, x = map(int, input().split())

t = [1]
p = [1]

for i in range(1, n+1):
    t.append(3+2*t[i-1])
    p.append(1+2*p[i-1])

def pathi(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= t[n-1] + 1:
        return pathi(n-1, x-1)
    else:
        return p[n-1] + 1 + pathi(n-1, x-t[n-1]-2)

print(pathi(n, x))

Measured memory_bytes: 61564
MOD = 1_000_000_007
m, n = map(int, input().split())

def modpower_rec(a, b, M=MOD):
    # compute a^b (mod M)
    if b <= 8:
        return (a ** b) % M
    else:
        if b % 2 == 0:
            return modpower_rec(a ** 2, b // 2, M)
        else:
            return (modpower_rec(a ** 2, b // 2, M) * a) % M


def modpower_rec2(a, b, M=MOD):
    if b == 0:
        return 1
    elif b % 2 == 0:
        return modpower_rec2((a ** 2) % M, b // 2) % M
    else:
        return (modpower_rec2((a ** 2) % M, b // 2) * a) % M


def mpower(a, b, M=MOD):
    rem = 1
    while b > 0:
        if b % 2 == 1:
            rem = rem * a % M
        a = a ** 2 % M
        b //= 2
    return rem % M

# print(modpower_rec(m, n, MOD))
# print(modpower_rec2(m, n, MOD))
print(mpower(m, n, MOD))


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
const int MOD = 1000000007;
// long long a;
int main(){
  char a;
  cin >> a;
  if(a == 'a'||a == 'i'||a == 'u'||a == 'e'||a == 'o') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}


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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;

void solve() {
        int n, m; cin >> n >> m;
        LL ar[n + 7], sum = 0;
        for (int i = 0; i < m; i++) {
                cin >> ar[i];
                sum += ar[i];
        }
        if (n - sum < 0) cout << "-1\n";
        else cout << n - sum << "\n";
}

int main(){

        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);

 //       int t; cin >> t;
//        while (t--) {
                solve();
//        }
        return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    bool F[N][5][2];
    rep(i, N){
        rep(j, 5){
            ll a, b; cin >> a >> b;
            F[i][j][0] = (a == 1) ? true : false;
            F[i][j][1] = (b == 1) ? true : false;
        }
    }
    ll P[N][11];
    rep(i, N){rep(j, 11){cin >> P[i][j];}}

    // bit全探索
    ll ans = -INF;
    for (int bit = 0; bit < (1<<10); ++bit) { // 1を左に2回シフトすると100
        vector<int> S;
        for (int i = 0; i < 10; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S.push_back(i);
            }
        }
        if (S.size() == 0){continue;}

        ll tmp = 0;
        rep(i, N){
            ll cnt = 0;
            for (auto s: S){
                if (F[i][s % 5][s / 5]){cnt += 1;}
            }
            tmp += P[i][cnt];
        }
        if (tmp > ans){ans = tmp;}
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;

ll euclid(ll a, ll b)
{
	ll temp;

	if (a < b) { temp = a; a = b; b = temp; }
	if (b < 1) return -1;

	if (a % b == 0) return b;
	return euclid(b, a % b);
}


int main()
{
	ll N,X;
	cin >> N >> X;
	ll x[N],t1,t2,D;
	if (N == 1) {
		cin >> t1;
		cout << abs(t1 - X) << endl;
		return 0;
	}
	for (ll i = 0; i < N; i++) {
		cin >> t1;
		t1 = t1 - X;
		if (i==1) {
			D = euclid(abs(t2), abs(t1));
		}
		else if(i>1) {
			D = euclid(D, abs(t2 - t1));
		}
		t2 = t1;
	}
	cout << D << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int n = s.length();
        int half = n / 2;
        boolean flag = true;

        for (int i = 0; i < half; i++) {
            if(s.charAt(i) != s.charAt(half - 1 - i) || s.charAt(i) != s.charAt(n - 1 -i)){
                flag = false;
            }
        }
        if(flag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n, m;
	while(cin >> n >> m) {
		vector<LL> a(n);
		REP(i, n) cin >> a[i];
		priority_queue<LL> qu;
		REP(i, n) qu.push(a[i]);
		REP(i, m) {
			LL t = qu.top();
			qu.pop();
			t /= 2;
			// DEBUG(t);
			qu.push(t);
		}
		LL ans = 0;
		while(!qu.empty()) {
			ans += qu.top();
			qu.pop();
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2168
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    if (N == 1)
        cout << "Hello World" << endl;
    else
    {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math

N,K=map(int,input().split())

S=input()
zerostart=0

if S[0]=='0':
  zerostart=1

continouslist=[]

nowchar=S[0]
nowcon=1
for i in range(1,len(S)):
  if nowchar!=S[i]:
    continouslist.append(nowcon)
    nowcon=1
    nowchar=S[i]
  else:
    nowcon+=1
continouslist.append(nowcon)

if zerostart:
  #print('Zero')
  if K>=math.ceil(len(continouslist)/2):
    print(N)
    exit()
  else:
    now=0
    ans=0
    for i in range(len(continouslist)):
      now+=continouslist[i]
      if K<=int(i/2) and i%2==0:
        now-=continouslist[i-2*K]
        if (i-2*K)!=0:
          now-=continouslist[i-2*K-1]
      #print(now)
      ans=max(now,ans)
  
else:
  #print('ONe')
  if K>=math.floor(len(continouslist)/2):
    print(N)
    exit()
  else:
    now=0
    ans=0
    for i in range(len(continouslist)):
      now+=continouslist[i]
      if K<int(i/2)+1 and i%2==1:
        now-=continouslist[i-2*K]
        now-=continouslist[i-2*K-1]
      #print(now)
      ans=max(now,ans)
#print(continouslist)
print(ans)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





int main(){

    ll a,b,c,d;
    cin>>a>>b>>c>>d;



  
    ll answer=a*c;
    answer=max(answer,a*d);
    answer=max(answer,b*c);
    answer=max(answer,b*d);

    cout<<answer<<endl;


    





}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 100000
vi d(N, inf);
vii M(N, vi());

/*
void dfs(int s) {
	d[s] = 0;
	stack<int> st;
	st.push(s);
	while (!st.empty()) {
		int u = st.top();
		st.pop();
		for (int i = 0; i < M[u].size(); i++) {
			int v = M[u][i];
			d[v] = d[u] + 1;
			st.push(v);
		}
	}
}
*/

int dfs(int s) {
	vi a;
	for (int i = 0; i < M[s].size(); i++) {
		a.push_back(dfs(M[s][i]) + 1);
	}
	sort(a.begin(), a.end());
	int res = 0;
	for (int i = 0; i < a.size(); i++) {
		res = max(res, a[i] + (int)a.size() - 1 - i);
	}
	return res;
}


int main() {
	int n, i;
	cin >> n;
	for (i = 1; i < n; i++) {
		int a;
		cin >> a;
		a--;
		M[a].push_back(i);
	}
	cout << dfs(0) << endl;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll f[M],inv[M];
void precompute(ll m)
{
	f[0] = 1;
	inv[0] = pwr(1,md-2,md);
	for(ll i=1;i<=m;++i)
	{
		f[i] = 1ll*f[i-1]*i%md;
		inv[i] = pwr(f[i],md-2,md);
	}
}
ll ncr(ll n,ll r)
{
	ll v = f[n];
	v = 1ll*v*inv[r]%md;
	v = 1ll*v*inv[n-r]%md;
	return v;
}

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

	ll n,m,i,ans,v;

	cin >> n >> m;
	precompute(m);

	ans = 0;
	for(i=0;i<=n;++i)
	{
		v = ncr(n,i);
		v = 1ll*v*f[m-i]%md;
		if(i%2)
			ans = (ans + md - v)%md;
		else
			ans = (ans + v)%md;
	}

	ans = 1ll*ans*f[m]%md;
	ans = 1ll*ans*inv[m-n]%md;
	ans = 1ll*ans*inv[m-n]%md;
	cout << ans << "\n";
}

	

Measured memory_bytes: 11360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int n = s.size();
    bool flag = true;

    string f = s.substr(0,(n-1)/2);
    string b = s.substr((n+3)/2-1,n);
    
    if(f!=b) flag = false;
    string fr = f, br = b;
    reverse(ALL(fr));
    reverse(ALL(br));
    if(br!=b || fr!=f) flag = false;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
int const mod = 1e9+7;
#define END {cout<<(ans)<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define fi first
#define se second
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,(n)-1)cout<<a[i]<<' '; cout<<a[(n)-1]<<'\n';
#define prip(p) cout<<(p).first<<' '<<(p).second<<'\n'
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

Int n,m,q,_,x,y;
string s,sb;
bool ok;
char ch;

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

  cin>>n>>q; Int a[n+1]; rep(i,n)cin>>a[i]; a[n]=0;
  rep(i,q){
    cin>>x; int l=0,r=1; Int su=a[0],ans=0;
    while(r<=n){
      if(r==l){r++; su+=a[l]; continue;}
      if(su>x){su-=a[l]; l++;}
      else{ans+=r-l; su+=a[r]; r++;}
    }
    pri1(ans);
  }
}


Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
int n, K, ans;
int main() {
    scanf("%d%d", &n, &K);
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        ans += min(x, K - x);
    }
    printf("%d\n", ans * 2);    
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace ConsoleApp15
{
    class Class108
    {
        static void Main()
        {
            string G = "GREATER";
            string L = "LESS";
            string E = "EQUAL";

            string A = ReadLine();
            string B = ReadLine();
            if(A.Length>B.Length) WriteLine(G); 
            else if(A.Length<B.Length) WriteLine(L);
            else
            {
                for(int i = 0; i < A.Length; i++)
                {
                    int a = int.Parse(A[i].ToString());
                    int b = int.Parse(B[i].ToString());
                    if (a > b) { WriteLine(G);return; }
                    else if (a < b) { WriteLine(L);return; }
                }
                WriteLine(E);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
 
#define INF 1234567890
#define ll long long

ll X, K, D;

int main()
{
	scanf("%lld %lld %lld", &X, &K, &D);
	X = abs(X);
	ll cnt = X / D;
	if (cnt >= K) return !printf("%lld", X-D*K);
	K -= cnt; X %= D;
	if (K%2 == 0) return !printf("%lld", X);
	else return !printf("%lld", abs(X-D));
	return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int counta = 0;
  int countb = 0;
  int countc = 0;
  int countd = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == "AC") {
      counta++;
    }
    if (a[i] == "WA") {
      countb++;
    }
    if (a[i] == "TLE") {
      countc++;
    }
    if (a[i] == "RE") {
      countd++;
    }
  }
  cout << "AC" << " " << "x" << " " << counta << endl;
  cout << "WA" << " " << "x" << " " << countb << endl;
  cout << "TLE" << " " << "x" << " " << countc << endl;
  cout << "RE" << " " << "x" << " " << countd << endl;
}

Measured memory_bytes: 6424
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
import math
from functools import reduce
import numpy as np

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]

k = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)

count = 0
a = []
for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i,j)
        for l in range(1,k+1):
            count += math.gcd(a,l)
print(count)

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

int main(){
	int s;
	cin>>s;
	int b=s%100,a=(s-b)/100;
	if(a<=12&&a>0&&b<=12&&b>0) cout<<"AMBIGUOUS";
	if(a<=12&&a>0&&(b>12||b==0)) cout<<"MMYY";
	if((a>12||a==0)&&(b<=12&&b>0)) cout<<"YYMM";
	if((a>12||a==0)&&(b>12||b==0)) cout<<"NA"; 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double eps = 1e-10;
  
int main() {
  string s;
  cin >> s;
  bool ok=true;
  int slen = sz(s);
  rep(i,slen) {
    if(s[i] != s[slen-1-i]) {
      ok = false;
    }
  }
  rep(i,slen/2) {
    if(s[i] != s[i+slen/2+1]) {
      ok = false;
    }
  }
  if(ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// cpp219 - the 712534
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fs first
#define sc second
#define mp make_pair
using namespace std;
const ll base = 7;
const ll N = 2e5 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,k;
ll sum[N],i;

int main(){
    ios_base::sync_with_stdio(false);
   	cin.tie(0); cout.tie(0);
    //freopen("test.inp", "r", stdin);
    cin>>n>>k;
    //fac[1] = fac[0] = 1;
    for (i=1;i<N;i++) sum[i] = sum[i - 1] + i;
    ll ans = 0;
    for (i = k;i <= n + 1;i++){
        ll minsum = sum[i - 1];
        ll maxsum = sum[n] - sum[n - i];
        ans = ans + (maxsum - minsum + 1);
        ans %= mod;
    }
    cout<<ans%mod;
}


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

int main(){
  int n, t, a;
  cin >> n >> t >> a;
  double ans = 100000000;
  int number = 0;
  for(int i = 1; i <= n; i++){
    int h;
    cin >> h;
    double x;
    double y;
    x = t - h * 0.006;
    y = abs(a - x);
    if(y < ans){
      ans = y;
      number = i;
    }
  }
  cout << number << endl;
}


Measured memory_bytes: 256
#include<stdio.h>


int coordinate[100];

void getData(int *n){
	fscanf(stdin,"%d",n);
}

int getDigit(int n, int k){
	int loop = 0;
	int buf = n;
	while(1){
		if(buf < k){
			loop++;
			return loop;
		}
		buf /= k;
		loop++;
	}

}

void solv(){
	int n,k;
	int digit;
	int avg = 0;
	int hp = 0;
	int buf;
	getData(&n);
	for(int i = 0; i < n; i++){
		getData(&coordinate[i]);
		avg += coordinate[i];
	}
	avg = avg/(float)n + 0.5;
		
	for(int i = 0; i < n ; i++){
		buf = coordinate[i] -avg;
		hp += buf*buf;
	}
	printf("%d\n",hp);
}	


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


Measured memory_bytes: 128
X,Y=list(map(int,input().split()))
if X==1 and Y==1:
  print(1000000)
elif X==1 and Y==2:
  print(500000)
elif X==1 and Y==3:
  print(400000)
elif X==1 and Y>=4:
  print(300000)
elif X==2 and Y==1:
  print(500000)
elif X==3 and Y==1:
  print(400000)
elif X>=4 and Y==1:
  print(300000)
elif X==2 and Y==3:
  print(300000)
elif X==3 and Y==2:
  print(300000)
elif X==2 and Y==2:
  print(400000)
elif X==3 and Y==3:
  print(200000)
elif X==2 and Y>=4:
  print(200000)
elif X==3 and Y>=4:
  print(100000)
elif X>=4 and Y==2:
  print(200000)
elif X>=4 and Y==3:
  print(100000)
else:
  print(0)



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


int main(){
    int a[3];
    for(int i=0;i<3;i++){
        cin >> a[i];
    }
    //降順ソート
    sort(a, a + 3, greater<int>());
    cout << a[0]*10 + a[1] + a[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	int a[100002];
	a[0] = a[n + 1] = 0;
	rep1(i, n) {
		cin >> a[i];
	}
	int sum = 0;
	rep(i, n+1) {
		sum += abs(a[i + 1] - a[i]);
	}
	rep1(i, n) {
		int x = abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]);
		cout << sum + x << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
const int LEN = 1e2 + 10;
int arr[LEN];

int main() {
    int n, cnt = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    for (int i = 1; i <= n; i++) {
        int minPos = i;
        for (int j = i + 1; j <= n; j++) {
            if (arr[minPos] > arr[j]) {
                minPos = j;
            }
        }
        if (minPos != i) {
            swap(arr[i], arr[minPos]);
            cnt += 1;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << arr[i] << " ";
    }
    cout << arr[n] << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define pb push_back
#define ef(i,u) for(int i=b[u];i;i=nxt[i])
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define PII pair<int,int>
#define ull unsigned long long
#define ll long long
#define fi first
#define se second
#define INF 0x3f3f3f3f
using namespace std;
const int N=2005;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n;
ll dp[N][N];
PII a[N];
bool cmp(PII x,PII y){
    return x.fi>y.fi;
}
ll cal(int now,int l,int r){
    if(l>r)return 0;
    if(dp[l][r]!=-1)return dp[l][r];
    ll res=1ll*a[now].fi*abs(a[now].se-l)+cal(now+1,l+1,r);
    res=max(res,1ll*a[now].fi*abs(r-a[now].se)+cal(now+1,l,r-1));
    return dp[l][r]=res;
}
int main(){
    cin>>n;
    int x;
    rep(i,1,n){
        read(x);
        a[i]=PII(x,i);
    }
    sort(a+1,a+1+n,cmp);
    MEM(dp,-1);
    ll ans=cal(1,1,n);
    cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 35148
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define PI acos(-1)
#define eps (1e-8)
#define INF ((int)1e18)
//ifstream cinn("in.in");ofstream coutt("out.out");


signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    vi v(n);for(int &i:v)cin>>i;
    
    int ans=0;
    for(int i=1;i<n;i++){
        if(v[i]>=v[i-1])continue;
        int d=v[i-1]-v[i];
        v[i]=v[i-1];
        ans+=d;
    }
    cout<<ans;
    
}

Measured memory_bytes: 4760
#include<iostream>
using namespace std;
int main()
{
	string n;
	cin>>n;
	if(n.size()==1){cout<<n<<endl;return 0;}
	for(int i=1;i<n.size();i++)
		if(n[i]!='9'){cout<<((n[0]-1)-'0'+9*(n.size()-1))<<endl;return 0;}
	cout<<n.size()*9+(n[0]-'0'-9)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define irep(i,a,b) for(typeof(i) i = (a); i < (b); ++i)
#define itrep(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)

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

	int N;
	ll K;
	cin >> N >> K;
	vector<int> A(N, -1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	vector<ll> B(N, -1);
	int p = 0;
	while (K > 0) {
		if (B[p] == -1) {
			B[p] = K;
		}
		else {
			ll l = B[p] - K;
			K = K % l;
			B[p] = K;
			break;
		}
		p = A[p] - 1;
		K--;
	}
	while (K > 0) {
		B[p] = K;
		p = A[p] - 1;
		K--;
	}
	cout << p + 1 << endl;
	return(0);
}


Measured memory_bytes: 5576
import numpy as np
n=int(input())
values=[int(i)  for  i  in  input().split()]
costs=[int(i)  for  i  in  input().split()]
score=0
benefits=np.sort([values[i]-costs[i]  for  i  in  range(n)])[::-1]
for  i  in  range(n):
    if  benefits[i]>0:
        score+=benefits[i]
    else:
        break

print(score)
        

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

#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout)

int main() {
	ioso;
	#ifndef ONLINE_JUDGE
	ffe;
	#endif

	ll n; cin >> n;
	ll a, b; cin >> a >> b;

	ll f = (a%n==0) ? a/n : (a/n)+1;

	if(f*n >=a and f*n<=b) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}
	
		
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}

ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}

int main(){
    string s;
    cin >> s;
    for (ll i=0;i<s.size();i++){
        if (s[i]=='?')cout << 'D';
        else cout << s[i];
    }
    cout << endl;
    return 0;
}
 
 



Measured memory_bytes: 3756
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int q = in.nextInt();
		int[] m = new int[q];
		for (int i = 0; i < q; i++) {
			m[i] = in.nextInt();
		}

		// solve
		boolean[][] dp = new boolean[n+1][2001];
		dp[0][0] = true;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2001; j++) {
				if (a[i] <= j) {
					dp[i+1][j] = dp[i][j-a[i]] | dp[i][j];
				} else {
					dp[i+1][j] = dp[i][j];
				}
			}
		}

		for (int i = 0; i < q; i++) {
			if (dp[n][m[i]]) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}

	}

}



Measured memory_bytes: 26532
N = int(input())
ans = 0
for i in range(1, N+1):
    cnt = 0
    for j in range(1, i + 1):
        if (i % j == 0):
            cnt += 1
    if (cnt == 8 and ((i % 2) == 1)):
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		lint ct=0;
		int s[13]={};
		rep(i,0,n){
			cin>>s[i];
		}
		int ans[13]={};
		for(ct=0;;ct++){
			rep(i,0,13){
				ans[i]=0;
			}
			int d[10000]={};
			rep(i,0,n){
				d[s[i]]++;
			}
			rep(i,0,n){
				ans[i]=d[s[i]];
			}
			int c=0;
			rep(i,0,n){
				if(ans[i]==s[i]) c++;
			}
			if(c==n) break;
			rep(i,0,n){
				s[i]=ans[i];
			}
		}
		o(ct);
		rep(i,0,n){
			if(i==0) cout<<ans[i];
			else cout<<" "<<ans[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1204