akhauriyash/Code-Regression huggingface dataset:
'use strict'

class Main {
  solve() {
    let n = input.nextIntArr()[0];
    let b = input.nextIntArr();
    let ret = [];
    let order = [];
    for (let i = 0; i < n; ++i) {
      let value = ret.length + 1;
      let cur = ret.length - 1;
      for (let j = n - 1; j >= 0; j--) {
        if (b[j] == value) { 
          ret.splice(cur+1,0,value); 
          order.push(value);
          break;
        }
        if (ret[cur] == b[j]) { 
          --cur;
          --value;
        }
      }
    }
    if (ret.length == b.length) { console.log(order.join('\n')); }
    else { console.log(-1); }
  }
}

class Input {
  constructor() {
	this.cursor = 0;
	this.inputAll();
  }

  inputAll() {
	this.data = (require("fs").readFileSync("/dev/stdin", "utf8")).split('\n');
	return this.data;
  }

  /* 1行 or 複数行文字列 */
  nextLine(n) {
	if (n) {
	  const ret = this.data.slice(this.cursor, this.cursor + n);
	  this.cursor += n;
	  return ret;
	}
	return this.data[this.cursor++];
  }
  /* 一行文字配列 */
  nextStrArr() { return this.nextLine().split(' '); } 
  /* 一行整数配列 */
  nextIntArr() { return this.nextStrArr().map((e) => parseInt(e)); }
  /* 一行浮動小数点配列 */
  nextFloatArr() { return this.nextStrArr().map((e) => parseFloat(e)); }
  /* 複数行整数配列 */
  nextIntLine(n) { return this.nextLine(n).map((e) => parseInt(e)) }
  /* 複数行浮動小数点配列 */
  nextFloatLine(n) { return this.nextLine(n).map((e) => parseFloat(e)) }
  /* 複数行文字列二次元配列 */
  nextStrRange(n) { return this.nextLine(n).map((line) => line.split(' ')); }
  /* 複数行整数二次元配列 */
  nextIntRange(n) {
	return this.nextLine(n).map((line) => line.split(' ').map((e) => parseInt(e)));
  }
  /* 複数行浮動小数点数二次元配列 */
  nextFloatRange(n) {
	return this.nextLine(n).map((line) => line.split(' ').map((e) => parseFloat(e)));
  }
} 
const input = new Input();
(new Main()).solve();


Measured memory_bytes: 7500
n = int(input())
def sumdigits(n):
    n = str(n)
    a = 0
    while(n != ""):
        a += int(n[0])
        n = n[1:]
    return a
ans = sumdigits(1)+sumdigits(n-1)
for i in range(2,n//2):
    p = sumdigits(i)
    q = sumdigits(n-i)
    if(p+q < ans):
        ans = p + q
print(str(ans))

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
INF = 10**100
r = range

class infix(object):
    def __init__(self, function):
        self.function = function

    def __ror__(self, other):
        self.left = other
        return self

    def __or__(self, other):
        return self.function(self.left, other)

    def __call__(self, value1, value2):
        return self.function(value1, value2)

@infix
def c(f_t_u, f_u_r): return lambda t: f_u_r(f_t_u(t))

class _Ap(object):
    def __rlshift__(self, other):
        self.value = other
        return self

    def __rshift__(self, other):
        return other(self.value)
Ap = _Ap()
A = Ap

#d = {1:2, 3:5, 6:10, 1000043:3814}
#zip(d.keys(), d.values())<<ap>>(list |c| sorted |c| reversed |c| list |c| print)

n=input()<<A>>int
a=map(int,input().split())
if n<=2:
    for i in range(n): 
        print(''.join(str(c)+' ' for c in a))
    exit()

index=[n//2]*n
if n%2:
    for i in range(n):
        index[i] += ((i+1)//2) * (+1 if i%2 else -1);
else:
    for i in range(n):
        index[i] += ((i+1)//2) * (-1 if i%2 else +1);
#print(index)

a=list(a)
ret=[0]*n
for i in range(n): 
    ret[index[i]]=a[i]
print(''.join(str(x)+' ' for x in ret))


Measured memory_bytes: 47624
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr) ;
    ios::sync_with_stdio(false) ;

    string s, t;
    cin >> s >> t;
    ll res = 1LL << 60;
    for (ll i = 0; i <= s.length() - t.length(); i++) {
        ll diff = 0;
        for (ll j = 0; j < t.length();j++){
            if (s[i + j] != t[j]) diff++;
        }
        res = min(diff, res);
    }
    cout << res << "\n";
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
#define long long long
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

string S;


int main(){
	cin >> S;
	long N = S.length();
	//cout << "N" << N << endl;

	//kaibun
	long middle = N/2;
	bool isStrong_kaibun = true;
	rep(i, middle){
		if (S.at(i) != S.at( N-1-i)){
			cout << "No" << endl;
			exit(0);
		}
	}

	//N-1
	if (N == 3){
		cout << "Yes" << endl;
		exit(0);
	}else if(N==5){
		if (S.at(0) == S.at(1) && S.at(4) == S.at(5)){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
		exit(0);
	}
	//cout << "oo" << endl;

	long kai = (N-1)/2;
	middle = (kai)/2;
	//if((kai/2)%2 == 1){
	rep(i, middle){
		if (S.at(i) != S.at(kai - i - 1)){
			cout << "No" << endl;
			exit(0);
		}
	}
	//cout << "oo" << endl;
	//}else{
	/*
		rep(i, middle){
			if (S.at(i) != S.at(i+middle)){
				cout << "No" << endl;
				exit(0);
			}
		}

	}
	*/

	//N+3
	long start = ((N+3)/2);
	middle = ((N - start)/2);

	//if (((N+3)/2)%2 ==1 ){
	for(int i=start-1; i< start-1+middle; i++){
		if (S.at(i) != S.at(N - i - 1)){
			cout << "No" << endl;
			exit(0);
		}
	}
	//}else{
		/*
		for(int i=start; i< N; i++){
			if (S.at(i) != S.at(i+middle)){
				cout << "No" << endl;
				exit(0);
			}
		}

	}
	*/

	cout << "Yes" << endl;
	
} 

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

using namespace std;

const int MAX_N=4*1e5;
int prime[MAX_N];//i??????????´???°
int is_prime[MAX_N+1];//i????´???°??????true

int sieve(int n){//????????????n??\???????´???°?????° ??¨??????????????????
    int p=0;
    for(int i=0;i<n;i++) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++){
        if(i%7!=1 && i%7!=6){
            is_prime[i]=false;
            continue;
        }
        if(is_prime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
        }
    }
    return p;
}

vector<int> divisor(int n){//?´???°??????
    std::vector<int> res;
    for(int i=2;i<=n;i++){
        if(is_prime[i]&&n%i==0){
            res.push_back(i);
           //if(i!= n/i) res.push_back(n/i);
        }
    }
    return res;
}

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

  int n;
  sieve(MAX_N);
  while(cin>>n){
      if(n==1) break;
      std::vector<int> v=divisor(n);
      cout<<n<<":";
      for(int i=0;i<(int)v.size();i++) cout<<" "<<v[i];
      cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 4780
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;
#define PI 3.14159265359
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
const int INF = 1<<31;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int LL;

int n;
string s;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(NULL);
    cout.tie(NULL);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);	

    cin >> n >> s;

    int x=0,mx=0;

    FOR(i,0,n){
        if(s[i]=='I'){
            x++;
        }else if(s[i]=='D'){
            x--;
        }
        mx=max(mx,x);
    }

    cout << mx << endl;

    return 0;
}


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

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;

    int ans = 0;
    vector<int> k(M);
    vector<vector<int>> s(M);
    int temp;
    for(int i = 0; i < M; i++){
        cin >> temp;
        k[i] = temp;
        s[i].resize(temp);
        for(int j = 0; j < temp; j++){
            cin >> s[i][j];
        }
    }

    vector<int> p(M);
    for(int i = 0; i < M; i++){
        cin >> p[i];
    }

    int cnt = (int)pow(2.0, (double)N);
    vector<bool> on(N);
    for(int i = 0; i < cnt; i++){
        int bit = 1;
        for(int j = 0; j < N; j++){
            if(bit & i){
                on[j] = true;
            }
            else{
                on[j] = false;
            }
            bit = (bit << 1);
        }   

        bool isOk = true;
        for(int j = 0; j < M; j++){
            int temp = k[j];
            int onSum = 0;
            for(int q = 0; q < temp; q++){
                if(on[s[j][q] - 1]){
                    onSum++;
                }
            }

            if((onSum % 2) != p[j]){
                isOk = false;
                break;
            }
        }

        if(isOk){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

vector<int> menu(5);

int main() {
    rep(i, 5) cin >> menu.at(i);
    
    int r = 1e9;
    int ans = 0;
    rep(i, 5) {
        if(menu.at(i) % 10 != 0) r = min(r, menu.at(i) % 10);
        ans += ((menu.at(i) + 9)/10) * 10;
    }
    if(r != 1e9) ans += r - 10;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
int inv[100005];
int someinv[100005];

int powmod(int a,int x)
{
    int ans = 1;
    while(x)
    {
        if(x&1) (ans *= a)%=mod;
        (a*=a)%=mod;
        x>>=1;
    }
    return ans;
}

void init()
{
    for(int i = 1; i < 100003; i++)
    {
        inv[i] = powmod(i,mod-2);
        someinv[i] = someinv[i-1] + inv[i]; 
    }
    return;
}

signed main() {
    init();
    int n;cin>>n;
    int kaizyo = 1;
    for(int i = 1; i <= n; i++)
    {
        (kaizyo *= i) %= mod;
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int a;cin>>a;
        int p = someinv[abs(i)+1] + someinv[abs(n-i-1)+1] -1;
        p %= mod;
        (ans += kaizyo*p%mod*a%mod) %= mod;
    }

    cout << ans << endl;    
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	if (n <= k)
		cout << n * x << endl;
	else
		cout << k * x + (n - k) * y << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  uint64_t n,i;
  cin>>n;
  std::vector<double> data(n);

  for(i=0;i<n;i++){
    cin>>data.at(i);
  }

  sort(data.begin(), data.end());

  for(i=0;i<(n-1);i++){
    data.at(i+1)=(data.at(i)+data.at(i+1))/2;
  }

  cout<<data.at(n-1)<<endl;



  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define in              insert
#define pb              push_back
#define mp              make_pair
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n]
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n, k; cin >> n >> k;
	set<int> s;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		s.in(x);
	}

	int dp[k + 2];
	dp[k + 1] = 0;
	for (int i = k ; i >= 1; i--) {
		int cur = 1;
		for (auto it : s) {
			if (i + it <= k + 1)
				cur *= dp[i + it];
			else
				break;
		}

		dp[i] = !cur;
	}

	if (dp[1])
		cout << "First" << endl;
	else
		cout << "Second" << endl;

	return 0;
}

Measured memory_bytes: 4412
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
        sc.close();

        long L = ((long)N*(long)M)/gcd(N, M);

        int n = N/gcd(N, M);
        int m = M/gcd(N, M);

        for(int k = 0; k < gcd(N, M); k++){
            if(S.charAt(k*n) == T.charAt(k*m))
                continue;
            else {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(L);
    }

    static int gcd(int n, int m){
        if(n < m)
            return gcd(m, n);
        else{
            if(m == 0)
                return n;
            else
                return gcd(m, n%m);
        }
    }
}

Measured memory_bytes: 28804
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

D, N = reads()
if N == 100:
  N = 101
print(N * 100**D)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
ll INF = 1000000000;

int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int a,b,t;
  cin >> a >> b >> t;
  int ans = 0;
  for(int i = 1; i <= t; i++){
    if(i % a == 0) ans += b;
  }
  cout << ans << endl;
}

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

int main(){
    int N;
    int sum=0;
    cin >> N;
    int L[2*N];
    for(int i=0; i<2*N; i++) cin >> L[i];
    sort(L, L+2*N);
    for(int i=0; i < N; i++) sum += L[i*2];
    cout << sum;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    dic = {"AC":0, "WA":0, "TLE":0, "RE":0}
    for i in range(N):
        dic[input()]+=1
    for j in dic:
        print("{} x {}".format(j,dic[j]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,m;

ll f(ll x){
	if(m/x>=n) return x;
	return 0;
}

int main(){
	cin>>n>>m;
	ll t=0;
	for(ll i=1;i*i<=m;i++) if(m%i==0){
		t=max(t,f(i));
		if(i*i<m) t=max(t,f(m/i));
	}
	cout<<t<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

//最大公約数
ll gcd(ll a,ll b){
    if(b == 0LL) return a;
    return gcd(b , a % b);
}

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

}

//前後を比較
bool compare(int pos,vector<int>& a){
    if(a[pos] == a[pos + 1]) return true;
    else return false;
}

int main(){
    
    int n;
    cin >> n;
    vector<int> a(n);

    int pos = 0;
    
    for(int i=0; i < n;i++) cin >> a[i];
    //前から順番に見ていく
    int cnt = 0;
    while(pos < n-1){
        if(compare(pos,a)) cnt++,pos += 2;
        else pos += 1;

    }
    
    cout << cnt << endl;
    
}

Measured memory_bytes: 256
import heapq
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

lq = []
rq = []
heapq.heapify(lq)
heapq.heapify(rq)
ans = 0

for q in qs:
    if q[0] == 2:
        print(-lq[0], ans)
        continue
    _,a,b = q
    ans += b
    heapq.heappush(lq, -a)
    heapq.heappush(rq, a)
    if -lq[0] > rq[0]:
        l = -heapq.heappop(lq)
        r = heapq.heappop(rq)
        ans += abs(l-r)
        heapq.heappush(lq,-r)
        heapq.heappush(rq,l)

Measured memory_bytes: 41368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];
	sort(arr,arr+n,greater<ll>());
	ll i=1,ans=0;
	for(;i<=n/2;i++){
		if(i==1){
			ans+=arr[0];
		}
		else{
			ans=ans+2*arr[i-1];
		}
	}
	if(n%2) ans+=arr[i-1];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5180
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	int a;
	std::string s;
	std::cin >> a;
	std::cin >> s;

	if (a >= 3200) std::cout << s << std::endl;
	else std::cout << "red" << std::endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; cin>>k;
  
  cout<<a[k-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void exGcd(int, int);

int main(void){

	int a,b;
	cin >> a >> b;
	exGcd(a, b);

	return 0;
}

void exGcd(int t0, int t1){

	int r0 = t0, r1 = t1;
	int a0 = 1, a1 = 0;
	int b0 = 0, b1 = 1;

	while(r1 > 0){
		int q1 = r0 / r1;
		int r2 = r0 % r1;
		int a2 = a0 - q1 * a1;
		int b2 = b0 - q1 * b1;
		r0 = r1;
		r1 = r2;
		a0 = a1;
		a1 = a2;
		b0 = b1;
		b1 = b2;
	}
	// int gcd = r0;
	int	x = a0;
	int y = b0;
	cout << x << " " << y << endl;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;



const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>xs;
		vector<int>ys;
		xs.emplace_back(0);
		ys.emplace_back(0);
		for (int i = 0; i < N - 1; ++i) {
			int n, d; cin >> n >> d;
			const int nx = xs[n] + dx[d];
			const int ny = ys[n] + dy[d];
			xs.emplace_back(nx);
			ys.emplace_back(ny);
		}
		const int width = *(max_element(xs.begin(), xs.end())) - *(min_element(xs.begin(), xs.end()));
		const int height = *(max_element(ys.begin(), ys.end())) - *(min_element(ys.begin(), ys.end()));
		cout << width+1 << " " << height+1 << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    int n, k;
    int ans = 0;

    cin >> n >> k;

    while (n > 0) {
        n /= k;
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int  n, i, g_cnt = 0, p_cnt = 0;
	char s[100000];
	gets(s);
	for(i = 0; i < 100000; i++){
		if(s[i] == 'g')g_cnt++;
		else if(s[i] == 'p')p_cnt++;
		else break;
		}
		printf("%d\n", (g_cnt - p_cnt) / 2);
		
		
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1073741824
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
   // test
   // {
        ll n;
        cin>>n;
        map<ll,ll>m;
        ll x,y,val,val1;
        x=n;
        for(int i=2;i<=sqrt(x);i++)
        {   
            if(x%i==0)
            {
                while(x%i==0)
                {
                    x/=i;
                    m[i]++;
                }
            }
        }
        if(x>2)
        {
            m[x]++;
        }
        val=0;
        for(auto itr:m)
        {
            x=itr.se;
            val1=-1;
            for(int i=1;i<=60;i++)
            {
                y=(i*(i+1))/2;
                if(x>=y)
                {
                    val1=i;
                }
            } 
            val+=val1;
        }
        cout<<val<<endl;
   // }
}

Measured memory_bytes: 3656
def inpl(): return [int(i) for i in input().split()]
def cookie(A, B, C):
    return((A+B)//2, (B+C)//2, (C+A)//2)
A, B, C = inpl()
ans = 0
while not A%2 and not B%2 and not C%2:
    A, B, C = cookie(A, B, C)
    ans += 1
    if ans == 10000:
        print(-1)
        break
else:
    print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static FastReader input = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);

	static int n;
	static int m = 3;

	static int[][] a, memo;
	static int _INF = (int) -1e9;

	static int solve(int n, int nextActivity) {

		if (n == -1) {
			return 0;
		}

		if (memo[n][nextActivity] != -1)
			return memo[n][nextActivity];

		int max = _INF;

		for (int i = 0; i < m; i++) {
			if (i != nextActivity) {
				max = Math.max(max, a[n][i] + solve(n - 1, i));
			}
		}

		return memo[n][nextActivity] = max;

	}

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

		n = input.nextInt();

		a = new int[n][m];
		memo = new int[n + 10][m+5];

		for (int i = 0; i < n; i++) {
			Arrays.fill(memo[i], -1);
			for (int j = 0; j < m; j++) {
				a[i][j] = input.nextInt();
			}
		}
		
		System.out.println(solve(n-1,4));

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}
	}
}


Measured memory_bytes: 62736
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    String S =sc.next();
    int s =S.length();
    String P[] =S.split("");
    String Q[] ={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    String R[] =new String[s+1];
    R[0]="";
    for(int i=0;i<s;i++){
      for(int j=0;j<26;j++){
      if(P[i].equals(Q[j])){R[i+1]=R[i]+Q[(j+N)%26];}}}
    
    System.out.println(R[s]);
  }
}

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

int main(){
  int N,M;
  cin>>N>>M;
  int A[M];
  int sum=0;
  for(int i=0;i<M;i++){
    cin>>A[i];
    sum+=A[i];
  }
  if(sum<=N) cout<<N-sum<<endl;
  else cout<<"-1"<<endl;
}


Measured memory_bytes: 3676
<?php
/*
    Problem URL : http://arc066.contest.atcoder.jp/tasks/arc066_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */
// define('DEBUG', true);
define('DEBUG', false);
define('MOD', pow(10, 9) + 7);
fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));
$b = array();
$ans = 1;
$c = array();

for ($i = 0; $i < $N; $i++) {
    $r = $i;
    $l = $N - $i - 1;
    $ab = abs($r - $l);
    $b[] = $ab;
}
sort($b);
sort($a);

if ($a == $b) {
    foreach ($b as $val) {
        $c[$val]++;
    }

    // var_dump($c);

    foreach ($c as $key => $val) {
        // echo "A {$key} {$val2} {$ans}\n";
        $ans *= $val;
        if ($ans > MOD) {
            $ans %= MOD;
        }
    }

    echo $ans . PHP_EOL;
} else {
    echo "0\n";
}


Measured memory_bytes: 16112
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#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++)
const long long INF =  999999999;

int main(){
  ll N,K,S;

  cin>>N>>K>>S;
  if(S<(ll)1e9){
    REP(i,K)cout<<S<<" ";
    FOR(i,K,N)cout<<S+1<<" ";
    cout<<endl;
  }
  else {
    REP(i,K)cout<<S<<" ";
    FOR(i,K,N)cout<<S-1<<" ";
    cout<<endl;
  }
}


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

#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

int a[2][100];

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

    int N, max_candy=0;
    int tmp=0;
    cin >> N;
    REP(i, 2) REP(j, N){
        cin >> a[i][j];
    }

    REP(i, N){
        REP(j, i+1){
            tmp += a[0][j];
        }
        FOR(k, i, N){
            tmp += a[1][k];
        }
        max_candy = max(max_candy, tmp);
        tmp = 0;
    }

    cout << max_candy << "\n";
    return 0;
}

Measured memory_bytes: 256
# ABC 122 B

S = input()

def isValidChar(c):
    if c == 'A' or c == 'C' or c == 'G' or c == 'T':
        return True
    else:
        return False

tmpLen = 0
maxLen = 0

for i in range(len(S)):
    if isValidChar(S[i]):
        tmpLen += 1
        maxLen = max(maxLen, tmpLen)
    else:
        tmpLen = 0

print(maxLen)


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


unsigned long long	mod(unsigned long long n)
{
	return n % (1000000000 + 7);
}

int	main()
{
	int	N;
	unsigned long long ans;
	scanf("%d", &N);
	unsigned long long A[N + 1];
	unsigned long long sum;

	ans = 0;
	sum = 0;
	for (int i = 1; i <= N; i++)
	{
		scanf("%llu", &A[i]);
		A[i] = mod(A[i]);
		sum = sum + A[i];
	}
	for (int i = 1; i < N; i++)
	{
		sum -= A[i];
		ans = mod(ans + A[i] * mod(sum));
	}
	printf("%llu\n", ans);
	return (0);
}


Measured memory_bytes: 3272
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
    int n,m;
    cin >> n >> m;
    int h[n+1];
    LOOP1(i,n) cin >> h[i];
    int bad[100001] = {}; // 0: bad
    LOOP(cnt,m){
      int a,b;
      cin >> a >> b;
      if(h[a] <= h[b]){
        bad[a] = true;
      }if(h[a] >= h[b]){
        bad[b] = true;
      }
    }
    int ans = 0;
    LOOP1(i,n){
      if(!bad[i])ans++;
    }
    cout << ans << endl;
}


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


Measured memory_bytes: 3096
def get_input():
    X, Y, Z, K = [int(_) for _ in raw_input().split()]
    A = [int(_) for _ in raw_input().split()]
    B = [int(_) for _ in raw_input().split()]
    C = [int(_) for _ in raw_input().split()]
    return X, Y, Z, K, A, B, C

def solve2():
    X, Y, Z, K, A, B, C = get_input()
    A.sort(reverse = True)
    B.sort(reverse = True)
    C.sort(reverse = True)
    sumABC = []
    for i in range(X):
        for j in range(Y):
            if (i + 1) * (j + 1) > K:
                break
            for k in range(Z):
                if (i + 1) * (j + 1) * (k + 1) > K:
                    break
                sumABC.append(A[i] + B[j] + C[k])
    sumABC.sort(reverse = True)
    for i in range(K):
        print sumABC[i]

if __name__ == '__main__':
    solve2()

Measured memory_bytes: 40092
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int to_dec(string s)
{
    int res = 0, sz = s.size(), k = 1;

    for (int i = 0; i < sz; i++)
    {
        if ('1' < s[i] && s[i] <= '9')
            k = s[i] - '0';
        else
        {
            if (s[i] == 'm')
                res += 1000 * k;
            if (s[i] == 'c')
                res += 100 * k;
            if (s[i] == 'x')
                res += 10 * k;
            if (s[i] == 'i')
                res += 1 * k;
            k = 1;
        }
    }

    return res;
}

string to_mcxi(int a)
{
    string s = "";
    int k = 0;
    while (a > 0)
    {
        k++;
        int c = a % 10;
        a /= 10;
        if (k == 1)
        {
            if (c == 0)
                continue;
            else if (c == 1)
                s += 'i';
            else
                s += "i" + to_string(c);
        }

        if (k == 2)
        {
            if (c == 0)
                continue;
            else if (c == 1)
                s += 'x';
            else
                s += "x" + to_string(c);
        }

        if (k == 3)
        {
            if (c == 0)
                continue;
            else if (c == 1)
                s += 'c';
            else
                s += "c" + to_string(c);
        }

        if (k == 4)
        {
            if (c == 0)
                continue;
            else if (c == 1)
                s += 'm';
            else
                s += "m" + to_string(c);
        }
    }

    reverse(s.begin(), s.end());
    return s;
}

int main()
{
    int N;
    cin >> N;
    while (N--)
    {
        string s, t;
        cin >> s >> t;
        int res = to_dec(s) + to_dec(t);
        cout << to_mcxi(res) << "\n";
    }
}


Measured memory_bytes: 3256
// review
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;
const int MAXN = 110;
const double INF = 300;

int n;
double t[MAXN], v[MAXN];

double calc(double x) {
  double retV = INF;
  double currentT = 0;
  for (int i=0;i<=n+1;i++) {
    if (x <= currentT) {
      retV = min(retV, v[i] + currentT - x);
    } else if (currentT <= x && x <= currentT + t[i]) {
      retV = min(retV, v[i]);
    } else {
      retV = min(retV, v[i] + x - currentT - t[i]);
    }
    currentT += t[i];
  }
  if (x >= currentT) {
    retV = 0;
  }
  return retV;
}

void solve() {
  double currentT = 0;
  double currentV = 0;
  double sum = 0;
  for (int i=1;i<=n;i++) {
    for (double x = 0;x<t[i];x+=0.5) {
      double nextV = calc(x + currentT + 0.5);
      sum += 0.25 * (currentV + nextV);
      currentV = nextV;
    }
    currentT += t[i];
  }
  cout << setprecision(10) << sum << endl;
}

int main() {
  cin >> n;
  for (int i=1;i<=n;i++) {
    cin >> t[i];
  }
  for (int i=1;i<=n;i++) {
    cin >> v[i];
  }
  solve();
}


Measured memory_bytes: 768
#include<cstdio>
#define SQ(x) ((x)*(x))
int x1, y1, x2, y2;
void solve(int x, int y){
	const int x2m1 = x2 - x1;
	const int y2m1 = y2 - y1;
	int xm1 = x-x1;
	int ym1 = y-y1;
	int x2m = x2-x;
	int y2m = y2-y;
	double temp1 = SQ(xm1)+SQ(ym1)+SQ(x2m1)+SQ(y2m1)-SQ(x2m)-SQ(y2m);
	double temp2 = SQ(x2m1)*2+SQ(y2m1)*2;
	double res = temp1/temp2;
	double xMid = x2m1*res+x1, yMid = y2m1*res+y1;
	printf("%.10f %.10f\n", 2*xMid-x, 2*yMid-y);
}
int main(){
	int x, y, q;
	scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &q);
	while(q--){
		scanf("%d%d", &x,&y);
		solve(x, y);
	}
}


Measured memory_bytes: 2696
//
//  main.cpp
//  four
//
//  Created by deepaz on 8/10/20.
//  Copyright © 2020 deepaz. All rights reserved.
//
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <iterator>
#include <cstring>
#include <algorithm>
#include <fstream>
#include <typeinfo>
#define ll long long
//deepaz
using namespace std;
//int num = stoi(a); -> str to int
//a = to_string(num); -> int to str
//total += c-48; -> char to int
//cout<<typeid(variable).name(); -> finding datatype of variable
 
//comparison func
bool comp(int x,int y){
    return x<y;
}
//char to int
int to_int(char c){
    return c;
}
//minimum in array
ll getMin(ll arr[], ll n){
    long long res = 1e6;
    for (int i = 0; i <= n; i++){
        res = min(res, arr[i]);
    }
    return res;
}
//get divisors of number
ll divisors(ll n){
    ll cnt = 0;
    for(int i=2;i*i<n;){
        if(n%i==0){
            cnt+=i+(n/i);
        }
        i++;
        if(i*i==n){
            cnt += i;
        }
    }
    if(cnt==0){
        return 0;
    }
    cnt++;
    return cnt;
}
//find if prime
bool isPrime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
//display prime in faster way
void dispPrime(ll n){
    ll num = 1e6;
    bool prime[num+num+num];
    memset(prime,true,sizeof(prime));
    for(int i=2;i*i<num+num+num;i++){
        if(prime[i]){
            for(int j=i*2;j<num+num+num;j+=i){
                //cout<<"i: "<<i<<"j: "<<j<<"\n";
                prime[j] = false;
            }
        }
    }
    ll k = 2;
    ll cnt = 0;
    ll upto = n; //for summing prime upto certain number
    //ll tot = 0;
    while(true){
        if(k<num+num+num){
            if(prime[k]){
                //tot += k;
                cnt++;
                if((k*k) == n){
                    cout<<"YES"<<"\n";
                    return;
                }
                //cout<<k<<" ";
            }
        }
        //if(cnt==n){break;}
        if(k>=upto){
            cout<<"NO"<<"\n";
            break;
        }
        k++;
    }
    //cout<<tot<<"\n";
}

int mltply(int n,int f[],int sz){
    int carry = 0;
    for(int i=0;i<sz;i++){
        int prod = f[i]*n + carry;
        f[i] = prod%10;
        carry = prod/10;
    }
    while(carry){
        f[sz] = carry%10;
        carry /= 10;
        sz++;
    }
    return sz;
}
//factorial of large numbers
void factorial(int n){
    int f[500];
    f[0] = 1;
    int sz = 1;
    for(int i=2;i<n+1;i++){
        sz = mltply(i, f, sz);
    }
    int ans = 0;
    for(int i=sz-1;i>=0;i--){
        //cout<<f[i];
        ans += f[i];
    }
    cout<<ans<<"\n";
}
//cout<<"Case #"<<cnt<<": "<<solve()<<"\n";
vector<int> arr(28123);
int calc(){
    int cnt = 0;
    for(int i=0;i<28124;i++){
        if(divisors(i)>i){
            arr[cnt] = i;
            cnt++;
            //cout<<arr[i]<<"\n";
        }
    }
    return cnt;
}

int main(){
    int x;
    cin>>x;
    if(x==1){
        cout<<0<<"\n";
    }
    else{
        cout<<1<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3708
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

bool check(int n, int k) {
    while (n >= k && n > 1) {
        if (n%k == 0) {
            n /= k;
        } else {
            n -= k;
        }
    }

    return n == 1;
}

int main() {
    long long N;
    long long tmp;
    cin >> N;

    // for (int k = 2; k <= N; ++k) {
    //     if (check(N, k)) {
    //         cout << "OK " << k << endl;
    //     }
    // }

    // factorization
    tmp = N-1;
    long long sq = sqrt(N-1);
    long long ans = 1;

    for (int n = 2; n <= sq; ++n) {
        int cnt = 0;
        while (tmp%n == 0) {
            tmp /= n;
            ++cnt;
        }

        if (cnt) {
            ans *= (cnt+1);
        }
    }

    if (tmp != 1) {
        ans *= 2;
    }

    // no 1
    --ans;

    tmp = N;
    // N/K... - K = 1
    // N = (K)*K*K*(K+1)
    sq = sqrt(N);

    for (int n = 2; n <= sq; ++n) {
        if (N%n == 0) {
            long long tmp2 = N;

            while (tmp2 % n == 0) {
                tmp2 /= n;
            }

            if (tmp2%n == 1) {
                ++ans;
            }
        }
    }

    cout << ans + 1 << endl;

    return 0;
}

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

#define MAX_N (100001L)
#define NUM_MOD (1000000007L)

int main(int argc, char *argv[]) {
  // read inputs
  char cs[MAX_N + 1];
  scanf("%s", cs);
  const int N = strlen(cs);
  // printf("N = %d\n", N);
  // printf("cs = %s\n", cs);

  // prepare powers
  long pow3s[MAX_N + 1];
  pow3s[0] = 1;
  for (int i = 0; i < N; i++) {
    pow3s[i + 1] = (3L * pow3s[i]) % NUM_MOD;
  }

  // solve dp
  long dps[MAX_N + 1];
  dps[N] = 1;
  for (long i = N - 1; i >= 0; i--) {
    if (cs[i] == '1') {
      dps[i] = (2L * dps[i + 1] + pow3s[N - (i + 1)]) % NUM_MOD;
    } else {
      dps[i] = dps[i + 1];
    }
  }
  printf("%ld\n", dps[0]);

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e6;
const ll inf = 1e9;
const double pi = acos(-1);

int main(){
    ll a;
    double b;
    cin>>a>>b;
    ll temp = b*100+0.5;
    ll pro = (a*temp);
    pro /= 100;
    cout<<fixed<<pro<<endl;
   return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<ll> spots(n);
    rep(i, n) cin >> spots[i];

    ll sum = 0;
    rep(i, n - 1) {
        sum += abs(spots[i] - spots[i + 1]);
    }
    sum += abs(spots.front());
    sum += abs(spots.back());

    auto left = [&](int i) -> ll {
        if (i == 0) return 0;
        else return spots[i - 1];
    };

    auto right = [&](int i) -> ll {
        if (i == n - 1) return 0;
        else return spots[i + 1];
    };

    auto sub = [&](int i) -> ll {
        ll now = spots[i];
        ll l = left(i);
        ll r = right(i);
        return abs(now - l) + abs(now - r);
    };

    auto diff = [&](int i) -> ll {
        ll now = spots[i];
        ll l = left(i);
        ll r = right(i);
        return abs(l - r);
    };

    rep(i, n) {
        cout << sum - sub(i) + diff(i) << endl;
    }

}


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

int main() {
  int n;
  cin >> n;
  int arr[n];
  for(int &i : arr) cin >> i;
  for(int i = n-2, _min = arr[n-1]; i >= 0; i--) {
    if(arr[i]-_min > 1) return cout << "No", 0;
    _min = min(_min, arr[i]);
  }
  cout << "Yes";
}


Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def main():
    N = int(input())

    nums = set()
    for _ in range(N):
        a = int(input())
        if a in nums:
            nums.remove(a)
        else:
            nums.add(a)

    print(len(nums))

if __name__ == "__main__": main()


Measured memory_bytes: 11884
//tree walk
//木の巡回
//2分木にのみ
//参考：https://onlinejudge.u-aizu.ac.jp/solutions/problem/ALDS1_7_C/review/1911331/emine/C%23
using System;

namespace tst
{
    class Program
    {
        public struct Node{
            public int index;
            public int left;
            public int right;
        }
        public static void Print(string type, Node[] nodes, int rootindex)
        {
            Console.WriteLine(type+"order");
            if (type == "Pre") Pre(nodes, rootindex);
            if (type == "In") In(nodes, rootindex);
            if (type == "Post") Post(nodes, rootindex);
            Console.WriteLine();

        }
        public static void Pre(Node[] nodes, int index)
        {
            if (index == -1) return;
            Console.Write(" " + index);
            Pre(nodes, nodes[index].left);
            Pre(nodes, nodes[index].right);
        }
        public static void In(Node[] nodes, int index)
        {
            if (index == -1) return;
            In(nodes, nodes[index].left);
            Console.Write(" " + index);
            In(nodes, nodes[index].right);
        }
        public static void Post(Node[] nodes, int index)
        {
            if (index == -1) return;
            Post(nodes, nodes[index].left);
            Post(nodes, nodes[index].right);
            Console.Write(" " + index);
        }
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            Node[] nodes = new Node[n];
            //子供をtrueにすることでrootがわかる
            bool[] Ischild = new bool[n];
            for(int i = 0; i < n; i++)
            {
                string[] In = Console.ReadLine().Split(' ');
                nodes[int.Parse(In[0])].index = int.Parse(In[0]);
                nodes[int.Parse(In[0])].left = int.Parse(In[1]);
                nodes[int.Parse(In[0])].right = int.Parse(In[2]);
                if (int.Parse(In[1]) != -1)//leafにはchildはいない
                {
                    Ischild[int.Parse(In[1])] = true;
                }
                if (int.Parse(In[2]) != -1)
                {
                    Ischild[int.Parse(In[2])] = true;
                }
            }
            //Ischildを参考にrootindexを特定
            int rootindex = Int32.MaxValue;
            for (int i=0; i<n; i++)
            {
                if (!Ischild[i])
                {
                    rootindex = i;
                    break;
                }
            }
            Print("Pre", nodes, rootindex);
            Print("In", nodes, rootindex);
            Print("Post", nodes, rootindex);
        }
    }
}


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

int main() {
  
  int S;
  cin >> S;
  
  int L = S / 100;
  int R = S % 100;
    
  if ( L > 0 && L < 13 && R > 0 && R < 13 ) cout << "AMBIGUOUS" << endl;
  else if ( R > 0 && R < 13 ) cout << "YYMM" << endl;
  else if ( L > 0 && L < 13 ) cout << "MMYY" << endl;
  else cout << "NA" << endl;
    
}

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

int a,b,c;
int main() {
	cin>>a>>b>>c;
	if(a==b){
		cout<<c<<endl;
	}else if(a==c){
		cout<<b<<endl;
	}else if(b==c){
		cout<<a<<endl;
	}
}//.

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n;
    while(~scanf("%d",&n)){
        int flag=0;
        while(n){
            int rem=n%10;
            if(rem==7) flag=1;
            n/=10;
        }
        if(flag) puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 3764
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
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 fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  ll n;
  cin >> n;
  if(n % 2 != 0)puts("0");
  else{
    ll ans = 0;
    n /= 2;
    while(n){
      ans += n / 5;
      n /= 5;
    }
    cout << ans << endl;
  }
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

Measured memory_bytes: 256