akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    
 
  int main(){
      COMinit();
      lint n;
      cin>>n;
      lint a[n+1];
      lint b[n+10];
      lint same;
      fill(b,b+n,0);
      rep(i,n+1){
            cin>>a[i];
            b[a[i]]++;
            if(b[a[i]]==2)same=a[i];
      }
      lint tot=0;
      bool f=false;
      rep(i,n+1){
          if(a[i]==same&&!f){
              tot+=i;
              f=true;
          }else if(a[i]==same){
              tot+=(n-i);
          }
      }
      rep(i,n+1){
        lint ans=COM(n,i+1)+COM(n,i)-COM(tot,i);
        ans+=MOD;
        ans%=MOD;
        cout<<ans<<endl;
      }
  }
  
     


Measured memory_bytes: 26240
package main

import (
	"fmt"
)

func solution(k, x int) bool {
	return 500*k >= x
}

func main() {
	var k, x int
	fmt.Scan(&k, &x)
	if solution(k, x) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
# Makimam Heap
N = int(input())
heap = list(map(int, input().split()))
heap = [0]+ heap

def max_heapify(A, i):
    l = i*2
    r = i*2+1
    largest = i
    if (l <= N and A[l] > A[i]):
        largest = l
    else:
        largest = i
    if (r <= N and A[r] > A[largest]):
        largest = r
    
    if (largest != i):
        A[i],A[largest] = A[largest],A[i]
        max_heapify(A, largest)

def build_maxheap(A):
    for i in range(N//2, 0, -1):
        max_heapify(A, i)

build_maxheap(heap)
print('', *heap[1:])
        


Measured memory_bytes: 63704
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)
	c1 := a + b
	c2 := a - b
	c3 := a * b
	ret := c1
	if ret < c2 {
		ret = c2
	}
	if ret < c3 {
		ret = c3
	}
	fmt.Println(ret)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline int in(){int x=0;char c=getchar();bool neg=false;while(c!='-'&&('0'>c||c>'9')) c=getchar();if(c=='-') neg=true,c=getchar();while('0'<=c&&c<='9') x=10*x+c-'0',c=getchar();if(neg) x=-x;return x;}
#define forinc(a,b,c) for(int a=b,_abc_=c;a<=_abc_;++a)
#define fordec(a,b,c) for(int a=b,_abc_=c;a>=_abc_;--a)
#define forv(a,b) for(auto&a:b)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define task "Y"
const int N=2000010;
const int M=1e9+7;
int m,n,k;
ii a[N];
int G[N],H[N],F[N];
int pw(int a,int i)
{
    if(!i) return 1;
    int b=1;
    for(;i;i>>=1,a=a*a%M) if(i&1) b=b*a%M;
    return b;
}
int C(int n,int k)
{
    if(k>n) return 0;
    return G[n] * H[n-k] %M * H[k] %M;
}
int W(int i,int j){return C(a[j].fi+a[j].se-a[i].fi-a[i].se,a[j].fi-a[i].fi);}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin>>m>>n>>k;
    G[0]=1;
    forinc(i,1,2000000)  G[i]=G[i-1]*i%M;
    H[2000000]=pw(G[2000000],M-2);
    fordec(i,2000000-1,0)H[i]=H[i+1]*(i+1)%M;
    a[0]={1,1};
    forinc(i,1,k) cin>>a[i].fi>>a[i].se;
    a[++k]={m,n};
    sort(a+1,a+k+1);
    forinc(i,1,k)
    {
        F[i]=W(0,i);
        forinc(j,1,i-1) if(a[j].se<=a[i].se)
            F[i]=(F[i] - W(j,i) * F[j] %M )%M;
    }
    cout<<(F[k]+M)%M;
}


Measured memory_bytes: 33024
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define endl "\n"
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define ss second
#define ff first
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
 
int main() {
    io;

    ll n,w;
    cin>>n>>w;
    ll arr[n][2];
    // w=8;
    rep(i,0,n) cin>>arr[i][0]>>arr[i][1];
    ll dp[n+1][w+1]={0};
    rep(i,0,w+2)
    rep(j,0,n+1)
    dp[j][i]=0;
   
    rep(i,1,n+1){
        rep(j,0,w+1){
            // if(j<arr[i][0] ) continue;
            // cout<<"i "<<i<<j;//<<j<<" dp[i-1][j-1] "<<dp[i-1][j-1]<<endl;
            // ll weight = 
            if(j>=arr[i-1][0]){
            dp[i][j]=max(arr[i-1][1]+ dp[i-1][j-arr[i-1][0]],dp[i-1][j]);//max(inlcluding an item , excluding this item)
            // cout<<dp[i-1][j]<<endl;
            }
            else if(j<arr[i-1][0]) {
                dp[i][j] = dp[i-1][j];
                // cout<<"j & weight "<<j<<arr[i-1][0]<<endl;
            };
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }
       cout<<dp[n][w];
//    rep(i,0,n+1){
//     rep(j,0,w+1)
//     cout<<dp[i][j]<<" ";
//     cout<<endl;
//     }
    // cout<<"FAsdfa"<<endl;;
    // cout<<dp[3][8]<<endl;
 
 
 
    
 
    return 0;
}

Measured memory_bytes: 79232
N = int(input())

A_count = B_count = BA_count = 0

ans = 0
for i in range(N):
    line = raw_input().strip()

    if line[0] == 'B':
        B_count += 1
        if line[-1] == 'A':
            BA_count += 1
            A_count += 1
    else:
        if line[-1] == 'A':
            A_count += 1

    for j in range(len(line)-1):
        if line[j:j+2] == 'AB':
            ans += 1


if A_count != 0 and B_count != 0:
    if A_count == B_count:
        ans += A_count
        if B_count == BA_count:
            ans -= 1
    elif A_count > B_count:
        ans += B_count
    else:
        ans += A_count

print(ans)

Measured memory_bytes: 2948
length = STDIN.gets.to_s.to_i
minv = STDIN.gets.to_s.to_i

### i = 1?????¨??? ###
r = STDIN.gets.to_s.to_i
maxv = r - minv
if minv > r then
    minv = r
end

for i in 2..length - 1 do
    r = STDIN.gets.to_s.to_i
    if maxv < r - minv then
        maxv = r - minv
    end
    if minv > r then
        minv = r
    end
end

p maxv

Measured memory_bytes: 8852
import collections
def main():
    N = int(input())
    S = input()
    # (1)Si,Sj,SkはRGB1つずつからなる
    # (2)j-i != k-j
    # (1) - (1)and!(2) を出す方針

    # (1)and!(2)を満たす場合の数
    # (1)を満たすパターン数r*g*b
    c1 = collections.Counter(S)
    meet1 = c1.get("R",0)*c1.get("G",0)*c1.get("B",0)
    # !(2)を満たすものを全探索して(1)を満たせばパターン数を+1する
    notmeet2 = 0
    for i in range(0,N-2):
        for j in range(i+1, N-1):
            k = 2*j-i
            if k<=N-1:
                if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
                    notmeet2 += 1
    print(meet1 - notmeet2)

main()


Measured memory_bytes: 9464
from math import radians, cos, sqrt

a,b,h,m = map(int,input().split())

# 時針の位置
h = h + (m/60)

longAngle = 360 * (h/12)
shortAngle = 360 * (m/60)

angle = abs(longAngle-shortAngle)

if angle > 180:
    angle = 360 - angle

# 余弦定理
ans = (a**2) + (b**2) - (2*a*b*cos(radians(angle)))

print(sqrt(ans))

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define mod (ll)1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, z, w;
  int a[2001];
  cin >> n >> z >> w;

  rep(i, 0, n) cin >> a[i];
  int ans = max(ans, abs(a[n - 1] - w));
  if(n > 1) ans = max(ans, abs(a[n - 1] - a[n - 2]));
  cout << ans << endl;
}


Measured memory_bytes: 256
import math as fr

if __name__ == '__main__':
	 N = int(input())
	 
	 ans = 0

	 MAP = [[-1] * (N+1) for _ in range(N+1)]

	 for P in range(1,N+1):
	 	for q in range(P,N+1):
	 		p = P
	 		if P > q:
	 			p,q = q,p

	 		if MAP[p][q] == -1:
	 			g1 = fr.gcd(p,q)
	 			MAP[p][q] = g1
	 		else:
	 			g1 = MAP[p][q]

	 		for r in range(q,N+1):
	 			g = g1
	 			if g > r:
	 				g,r = r,g

	 			if MAP[g][r] == -1:
	 				g2 = fr.gcd(g,r)
	 				MAP[g][r] = g2
	 			else:
	 				g2 = MAP[g][r]

	 			if P == q and q == r:
		 			ans += g2
		 		elif P == q or q == r or r == P:
		 			ans += 3 * g2
		 		else:
		 			ans += 6 * g2
	 print(ans)

Measured memory_bytes: 9532
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		long[]A = new long[N];
		string[]str = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str[i]);
		}
		long n1 = 1000;
		long f1 = 0;
		f1 = n1/A[0];
		n1 = 1000-f1*A[0];
		for(var i=1;i<N;i++){
			if(A[i]<A[i-1]){
				n1 += f1*A[i-1];
				f1 = 0;
			}
			long f2 = n1/A[i];
			n1 -= f2*A[i];
			f1 += f2;
		}
		n1 += f1*A[N-1];
		Console.WriteLine(n1);
	}
}

Measured memory_bytes: 17888
import java.util.Scanner;
import java.util.Arrays;

class Main{
    public static void main(String[] a){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] inputs = new int[3];

        String result;
        for(int i = 0;i < n;i++) {
            for (int j = 0; j < 3; j++) {
                int m = s.nextInt();
                inputs[j] = m * m;
            }
            Arrays.sort(inputs);
            result = inputs[0] + inputs[1] == inputs[2] ? "YES" : "NO";

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

Measured memory_bytes: 23348
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int n;
vector<int> d;
bool ok = false;
void dfs(int k, vector<int> vec, int val) {
    if (k==n) {
        ok = true;
    } else {
        rep(i, 2) {
            vector<int> a = vec;
            int next = abs(24*i-d[k+1]) % 24;
            if (next==12 && i==1) continue;
            a.push_back(next);
            sort(all(a));
            bool check = true;
            rep(i, sz(a)-1) {
                if (min(a[i+1]-a[i],24-(a[i+1]-a[i]))<val) {
                    check = false;
                    break;
                }
            }
            if (min(abs(a.back()-a.front()),24-(a.back()-a.front()))<val) check = false;
            if (check) {
                dfs(k+1, a, val);
            }
        }
    }
}

int main() {
    cin >> n;
    d.resize(n+1);
    d[0] = 0;
    rep(i, n) cin >> d[i+1];
    map<int, int> mp;
    rep(i, n+1) mp[d[i]]++;
    for(const auto& m: mp) {
        // cout << m.fi << " " << m.se << endl;
        if ((m.fi==12||m.fi==0) && m.se>=2) {
            cout << 0 << endl;
            return 0;
        }
        if (m.se>2) {
            cout << 0 << endl;
            return 0;
        }
    }
    if (sz(d) > 12) {
        cout << 1 << endl;
        return 0;
    }
    for(int i=12; i>=0; i--) {
        ok = false;
        vector<int> vec = {0};
        dfs(0, vec, i);
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 1<<20|3,mo=1e9+7;
inline void add(int &x, int y){x=x+y<mo?x+y:x+y-mo;}
inline void sub(int &x, int y){x=x-y>=0?x-y:x-y+mo;}
inline int power(int a, int n) {
	int res=1;
	while (n) {
		if (n&1) res=1LL*res*a%mo;
		a=1LL*a*a%mo; n>>=1;
	}
	return res;
}

int fac[N],ifac[N];
void iniC(int n){
	fac[0]=1;rep(i,1,n)fac[i]=1LL*fac[i-1]*i%mo;
	ifac[n]=power(fac[n],mo-2);
	per(i,n-1,0)ifac[i]=1LL*ifac[i+1]*(i+1)%mo;
}
int n,m;vector<Pii> e[26];int d[26][26],a[N];
void dfs(int s, int u, int fa, int S){
	d[s][u]=S;
	rep(i,0,SZ(e[u])-1)if(e[u][i].fi!=fa)
		dfs(s,e[u][i].fi,u,S|(1<<e[u][i].se-1));
}
struct node{
	int ways,ans,b,n;
	inline void upd(int x, int y, int z, int w){
		add(ways,x);add(ans,y);b=z;n=w;
	}
}dp[N];
int main() {
	iniC(66666);read(n);read(m);
	rep(i,1,n-1){
		int u,v;read(u);read(v);m--;
		e[u].pb(Pii(v,i));e[v].pb(Pii(u,i));
	}
	rep(i,1,n)dfs(i,i,0,0);
	while(m--){
		int u,v;read(u);read(v);a[d[u][v]]++;
	}
	int all=(1<<n-1)-1;
	rep(j,0,n-2)rep(i,0,all)a[i]+=i>>j&1?a[i^(1<<j)]:0;
	dp[0]=(node){1,0,0,0};
	rep(s,0,all-1)rep(i,1,n-1)if(!(s>>i-1&1)){
		int k=a[all^s]-a[all^s^(1<<i-1)];
		int n=dp[s].n,b=dp[s].b;
		int x=1LL*dp[s].ways*fac[n+k]%mo*ifac[n]%mo;
		dp[s|(1<<i-1)].upd(x,(1LL*dp[s].ans*fac[n+k+1]%mo*ifac[n+1]+1LL*x*(b+1))%mo,b+1,n+k+1);
	}
	printf("%d\n",dp[all].ans);
	return 0;
}


Measured memory_bytes: 18688
import java.util.*

fun main(args: Array<String>) {
    var taroPoint = 0
    var hanakoPoint = 0

    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    (1..n).forEach {
        val card1 = scanner.next()
        val card2 = scanner.next()
        if (card1 > card2) {
            taroPoint += 3
        } else if (card1 < card2) {
            hanakoPoint += 3
        } else {
            taroPoint++
            hanakoPoint++
        }
    }
    println("${taroPoint} ${hanakoPoint}")
}


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

typedef long long lint;
typedef long double louble;
template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return b<a?a:b;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	char buf[bufl],*s=buf,*t=buf;
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007 , inf = 0x3f3f3f3f;

struct sgt
{
#define lc (x<<1)
#define rc (x<<1|1)
#define mid ((l+r)>>1)

	static const int _t = _<<2;

	int t[_t];

	void up(int x){t[x]=max(t[lc],t[rc]);}

	void plant(int x,int l,int r,int val)
	{
		t[x]=val;
		if(l==r)return;
		plant(lc,l,mid,val),plant(rc,mid+1,r,val),up(x);
	}

	void change(int x,int l,int r,int tar,int dlt)
	{
		if(l==r){t[x]=dlt;return;}
		if(tar<=mid)change(lc,l,mid,tar,dlt);
		else change(rc,mid+1,r,tar,dlt);
		up(x);
	}

	int finder(int x,int l,int r,int tl,int tr)
	{
		if(tl<=l && r<=tr)return t[x];
		if(tr<=mid)return finder(lc,l,mid,tl,tr);
		if(tl>mid)return finder(rc,mid+1,r,tl,tr);
		return max(finder(lc,l,mid,tl,tr),finder(rc,mid+1,r,tl,tr));
	}

#undef lc
#undef rc
#undef mid
}t0,t1;

int n,val[_],xval[_],sxval[_]={0},ans[_];

inline int able(int now,int amx,int acnt,int bmx,int bcnt)
{
	int aval=acnt-bcnt+sxval[now],bval=bcnt-acnt+sxval[now];
	if(aval>=0 && (aval&1?t1:t0).finder(1,1,n,bmx,n)>=aval)return 1;
	if(bval>=0 && (bval&1?t1:t0).finder(1,1,n,amx,n)>=bval)return 1;
	return 0;
}

int main()
{
	n=ty();
	for(int i=1,a=0;i<=n;i++)val[i]=ty(),xval[i]=(val[i]>a),a=max(a,val[i]);
	for(int i=n;i>=1;i--)sxval[i]=sxval[i+1]+xval[i];
	
	t0.plant(1,1,n,0),t1.plant(1,1,n,-inf);
	for(int i=n;i>=1;i--)
	{
		int a=t0.finder(1,1,n,val[i],n),b=t1.finder(1,1,n,val[i],n);
		if(xval[i])a+=2,b+=2;
		else swap(a,b),a++,b++;
		t0.change(1,1,n,val[i],a),t1.change(1,1,n,val[i],b);
	}

	int amx=1,bmx=1,acnt=0,bcnt=0;
	for(int i=1;i<=n;i++)
	{
		t0.change(1,1,n,val[i],0),t1.change(1,1,n,val[i],-inf);
		if(able(i+1,max(amx,val[i]),acnt+(amx<=val[i]),bmx,bcnt))
			acnt+=amx<=val[i],amx=max(amx,val[i]),ans[i]=0;
		else bcnt+=bmx<=val[i],bmx=max(bmx,val[i]),ans[i]=1;
	}

	if(acnt!=bcnt){puts("-1");return 0;}
	for(int i=1;i<=n;i++)putchar(ans[i]+'0');
	puts("");

	return 0;
}


Measured memory_bytes: 8704
while True :
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == "?" :
        break
    elif op == "+" :
        print(a + b)
    elif op == "-" :
        print(a - b)
    elif op == "/" :
        print(int(a / b))
    elif op == "*" :
        print(a * b)


Measured memory_bytes: 5596
MOD = 10**9+7
def modpow(a, n, mod)
  exp = Math.log(n, 2).floor
  rep = modpow_cl(a, n, exp, mod)
  return rep[0]
end

def modpow_cl(a, n, exp, mod)
  if exp < 0
    rep = [1, a]
  else
    if n >= 2**exp
      rep = modpow_cl(a, n-2**exp, exp-1, mod)
      rep[0] = rep[0]*rep[1] % mod
    else
      rep = modpow_cl(a, n, exp-1, mod)
    end
    rep[1] = rep[1]**2 % mod
  end
  return rep
end

def modcomb(n, k, mod)
  return 1 if k < 1 || n <= k
  nume = deno = 1
  for i in 1..k
    nume = nume*(n-i+1) % mod
    deno = deno*i % mod
  end
  return nume*modpow(deno, mod-2, mod) % mod
end

s = gets.to_i

maxln = s/3
ans = 0
for i in 1..maxln
  ln = maxln-i+1
  use = s-ln*3
  #(use+ln-1)C(ln-1)
  tmp = modcomb(use+ln-1, ln-1, MOD)
  ans = (ans+tmp)%MOD
end
puts ans

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

const long long MOD = 1e9+7;
const long long MAX = 1e6;
long long fact[MAX + 1] = {0};

void fact_init(){
    fact[0]  = 1;
    for(long long i = 1; i <= MAX;i++){
        fact[i] = (fact[i - 1] * i % MOD) % MOD;
    }
}

long long repeat_fact(long long N,long long P){
    if(P == 0) return 1;
    if(P % 2 == 0){
        long long t = repeat_fact(N,P/2);
        return (t%MOD * t % MOD ) % MOD;
    }else return (N % MOD * repeat_fact(N,P-1)) %MOD;
}

long long combination(long long n,long long k){
    long long fact1 = fact[n];
    long long fact2 = repeat_fact(fact[k],MOD - 2);
    long long fact3 = repeat_fact(fact[n - k],MOD - 2);
    long long ans = ((fact1 * fact2) % MOD * fact3) % MOD;
    return ans;
}

void solve(long long N, long long K){
    for(long long i = 1;i <= K; i++){
        if(i > N - K + 1){
            cout << 0 << endl;
        }else{
            cout << combination(N - K + 1,i) * combination(K -1,i - 1) % MOD << endl;
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;cin >> N;
    long long K;cin >> K;
    fact_init();
    solve(N, K);
    return 0;
}


Measured memory_bytes: 8064
/**So..a**/
#include<bits/stdc++.h>
//#include <chrono>
// Success after trying 5 hour 11 minute :(


using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define PB(x, v) x.push_back(v);
#define M_P(a, b) make_pair(a, b)
#define pll pair<ll, ll>
#define ll long long
#define mll map<ll, ll>
#define vl vector<ll>
#define fa(x, v) for(auto x: v)
#define fr(i, a, b) for(ll i= a;i <=b; i++)
#define TEST  int test; cin >> test; while(test--)
#define FTEST int TesT; cin >> TesT; for(int test = 1; test<=TesT; test++)

#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define NL_ "\n"
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define MOD 1000000007
#define  ull unsigned long long

ll POW(ll b, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p%2)
        {
            res*=b;
            res%=MOD;
        }
        b*=b;
        b%=MOD;
        p/=2;
    }
    return res%MOD;
}

int main()
{

    ll n;
    scanf("%lld", &n);
    ll  ans = POW(10, n) - POW(9, n);
    ans += MOD;
    ans  = ans - POW(9, n);
    ans+=MOD;
    ans%=MOD;
    ans+=POW(8, n);

    ans%=MOD;
    printf("%lld" , ans);

    return 0;
}


Measured memory_bytes: 3824
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		sc.close();

		BigInteger N = new BigInteger(n);
		BigInteger nine = new BigInteger("9");
		if (N.remainder(nine).equals(BigInteger.ZERO)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 42052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int ans = 0;

      int offset=0, next=0;
      char regex = ' ';
      boolean isContinue = true;
      for( ; isContinue; ) {
        if((next = line.indexOf(regex, offset)) == -1) {
          next = line.length();
          isContinue = false;
        }

        ans += Integer.numberOfTrailingZeros(
          Integer.parseInt(line.substring(offset, next)) );

        offset = ++next;
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 24660
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int ans = 0;
            for(int i = 0; i < 4; i++)
            {
                if(S[i]== '+')
                {
                    ans++;
                }
                else
                {
                    ans--;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	vector <int> W(N);
	ll leftSum = 0, rightSum = 0;
	for(int i=0; i<N; i++){
		cin >> W[i];
		rightSum+=W[i];
	}
	ll ans = 100000000;
	for(int T = 0; T<N-1; T++){
		leftSum += W[T];
		rightSum -= W[T];
		ans = min(ans, abs(leftSum - rightSum));
	}
	cout << ans << '\n';
	return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int a, b;   cin >> a >> b;
    int cnt = 0;
    for(int i = a; i <= b; i++){
        string str, str2;
        str = to_string(i);
        str2 = str;
        reverse(str.begin(), str.end());
        if(str == str2) cnt++;
    }
    cout << cnt <<'\n';
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,M; cin >> N >> M;
	const LL mod = 998244353;
	vector<bitset<300>> b(N,bitset<300>(0));
	repp(i,0,N) repp(j,0,M){
		int a; cin >> a;
		b[i][j] = a;
	}
	int k = 0;
	repp(j,0,M){
		int i = k;
		while(i < N && !b[i][j]) ++i;
		if(i == N) continue;
		swap(b[k],b[i]);
		repp(p,k+1,N) if(b[p][j]) b[p] ^= b[k];
		++k;
	}
	LL z = 1;
	repp(i,k,N) z = z*2%mod;
	LL ans = 1;
	repp(i,0,N) ans = ans*2%mod;
	ans = (ans+mod-z)%mod;
	repp(i,1,M) ans = ans*2%mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

//#define N 20

using namespace std;


int main(void)
{
	int n;
	int m;
	int x,y;
	int dx,dy;

	int i1,i2,i3;
	int temp;



	while(1) {

		vector<int> vx;
		vector<int> vy;


		cin >> n;
		if (n==0) break;

		cin >> m;

		cin >> dx;
		cin >> dy;

		vx.push_back(0);
		vy.push_back(0);

		for(i1=1;i1<m;i1++){
				
			cin >> x;
			cin >> y;

			vx.push_back(x-dx);
			vy.push_back(y-dy);
		}

		for(i1=0;i1<n;i1++){
			vector<int> wx;
			vector<int> wy;
			vector<int> rx;
			vector<int> ry;

			cin >> m;

			cin >> dx;
			cin >> dy;

			wx.push_back(0);
			wy.push_back(0);
			
			for(i2=1;i2<m;i2++){
				cin >> x;
				cin >> y;

				wx.push_back(x-dx);
				wy.push_back(y-dy);

			}

			rx = wx;
			ry = wy;

			reverse(rx.begin(),rx.end());
			reverse(ry.begin(),ry.end());




			dx = rx[0];
			dy = ry[0];

			rx[0] = 0;
			ry[0] = 0;

			for(i2=1;i2<m;i2++){
				rx[i2] -= dx;
				ry[i2] -= dy;
			}

			for(i3=0;i3<3;i3++){
				

				if( (vx==wx && vy==wy) || (vx==rx && vy==ry)) {
					cout << i1+1 << endl;
				}
				for(i2=1;i2<m;i2++){
					temp=wx[i2];
					wx[i2]=wy[i2];
					wy[i2]=-temp;
					
					temp=rx[i2];
					rx[i2]=ry[i2];
					ry[i2]=-temp;
					
				}

			}

			if( (vx==wx && vy==wy) || (vx==rx && vy==ry)) {
					cout << i1+1 << endl;
			}

		}

		cout  << "+++++" << endl;
	}

	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int n,k;
int a[5000];

const int N=10101;

int dp[5001];

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

    int l=0, r=n+1;
    while(r-l>1)
    {
        int m = (l+r)/2;

        bool valid = false;
        if(a[m-1]<k)
        {
            valid = true;

            memset(dp,0,sizeof(dp));
            dp[0]=1;
            rep(i,n)
            {
                if(i==m-1) continue;

                for(int j=k; j>=0; --j)if(dp[j])
                {
                    int nx=min(k,j+a[i]);
                    dp[nx]=1;
                }
            }


            for(int i=k-a[m-1]; i<k; ++i)
            {
                if(dp[i])
                {
                    valid = false;
                    break;
                }
            }
        }

        if(valid) l=m;
        else r=m;
    }

    cout << l << endl;
    return 0;
}


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

using namespace std;

int main()
{
    unsigned long n;
    cin>>n;
    unsigned long a[n],b[n],c[n],dp[3][n];
    for(unsigned long i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(unsigned long i=1;i<n;i++)
    {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max(max(dp[0][n-1], dp[1][n-1]), dp[2][n-1]);
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i,a,b) for( int i=a;i<b;i++)
#define REPR(i,a,b) for(int i=a;i>=b;i--)
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 998244353
#define PI 3.14159265358979323846
const ll N = 200001;

struct LessSecond
{
    template<typename T, typename U>
    bool operator()(const std::pair<T, U> &x, const std::pair<T, U> &y) const
    {
        return x.second < y.second;
    }
};

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }

vi g[100001];
int ans[100001];

int main()
{


    fastIO;
    int test = 1;
    //cin >> test;
    while (test--)
    {
        int n, m;
        cin >> n >> m;
        REP(i, 0, m) {
            int u, v;
            cin >> u >> v;
            g[u].PB(v);
            g[v].PB(u);
        }
        mem(ans, 1000001);
        ans[0] = 0;
        ans[1] = 0;
        queue<int>q;
        q.push(1);
        bool vis[n + 1];
        int gates[n + 1];
        mem(gates, 1000001);
        gates[1] = 0;
        mem(vis, 0);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            vis[v] = 1;
            for (auto u : g[v]) {
                if (vis[u] == 1) continue;
                if (gates[u] > gates[v]) {
                    ans[u] = v;
                    gates[u] = gates[v];
                }
                q.push(u);
                vis[u] = 1;
            }
        }
        REP(i, 1, n + 1) {
            if (ans[i] >= 1000001) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        REP(i, 2, n + 1) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}



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

using namespace std;

#define rep(i, a) for(int i = 0; i < a; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
#define MP(a, b) make_pair(a, b)

int x[4];

int main()
{
  rep(i, 4) cin >> x[i];
  cout << min(x[0], x[1]) + min(x[2], x[3]) << endl;
  return 0;
}

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

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

using namespace std;



int main( )
{
    int n;

    scanf("%d",&n);

    int arr[n],brr[n];

    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&brr[i]);
    }

    int ans=0;

    for(int i=0;i<n;i++)
    {
        if(arr[i]>brr[i])
        {
            ans+=arr[i]-brr[i];
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 998244353ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef float ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	doin();
	ll n, a, b, c, r = INT_MAX;
	vi l, res;
	cin >> n >> a >> b >> c;
	getv(l, n);
	for(int i = 1; i < (1 << (2*n)); i++) {
		res.assign(4, 0);
		ll ans = 0;
		for(int j = 0; j < 2*n; j+=2) {
			int c = (i>>j)&3;
			int p = j/2;
			if(c && res[c]) ans += 10;
			res[c] += l[p];
		}
		if(!res[3]||!res[1]||!res[2]) continue;
		ans += abs(res[1]-a);
		ans += abs(res[2]-b);
		ans += abs(res[3]-c);
		r = min(r, ans);
	}
	cout << r;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
typedef long long ll;
ll a[200005],b[200005];
int main()
{
    memset(a,0,sizeof(a));
    int n;
    ll ans=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&b[i]);
        a[b[i]]++;
    }
    for(int i=1; i<=n; i++)
        ans+=a[i]*(a[i]-1)/2;
    for(int i=1; i<=n; i++)
    {
        if(a[b[i]]>=2)
            printf("%lld\n",ans-a[b[i]]*(a[b[i]]-1)/2+(a[b[i]]-1)*(a[b[i]]-2)/2);
        else
            printf("%lld\n",ans-a[b[i]]*(a[b[i]]-1)/2+(a[b[i]]-1));
    }
    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m-1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main(){
	int n;
	cin >> n;
	hei(llint) a(n + 2);
	a[0] = 0;
	a[n + 1] = 0;
	llint s = 0;
	rep(i, 1, n + 1) {
		cin >> a[i];
	}
	rep(i, 0, n + 1)s += abs(a[i] - a[i + 1]);

	rep(i, 1, n+1) {
		llint ans = s + abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1]-a[i]) + abs(a[i] - a[i + 1]));
		cout << ans << endl;
	}
	
	return 0;
}




  


Measured memory_bytes: 2424
N = int(input())
nums = [int(input()) for _ in range(N)]

visited = [False]*N
ind = 1
count = 1

for _ in range(N):
    visited[ind - 1] = True
    v = nums[ind -1]
    if v == 2:
        break
    if visited[v-1]:
        count = -1
        break
    ind = v
    count += 1

print(count)

Measured memory_bytes: 7980
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

// FAIL
void fail(){ print(-1); std::exit(0); }
//void fail(){ print("No"); std::exit(0); }

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

  ll N;
  std::cin >> N;
  std::vector< std::vector< ll > > vvd(N, std::vector<ll>(N, -1LL));
  for (auto& vd : vvd) {
    ll A;
    std::cin >> A;

    for (ll i = 0; i < A; i++) {
      ll x, y;
      std::cin >> x >> y;
      vd[x-1] = y;
    }
  }

  ll ans = 0LL;

  // bitが立っているのが正直者 (bit内容が真実)
  for (ll bit = 0; bit < (1<<N); bit++) {
    bool is_true = true;

    // i は証言者
    for (ll i = 0; i < N; i++) {
      if ( ((bit >> i) & 1) == 0 ) continue; // 嘘つきの証言者は検証しない

      // 証言内容を検証 (j は名指しされた人)
      for (ll j = 0; j < N; j++) {
        ll y = (bit >> j) & 1; // j が正直者かどうか(真実)

        // 正直者の証言が嘘なら、矛盾していることになる
        if (vvd[i][j] >= 0 && vvd[i][j] != y) is_true = false;
      }
    }

    if (is_true) ans = std::max( ans, static_cast<ll>(__builtin_popcount(bit)) );
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define int long long
int minimumCost(int price[], int n) 
{ 
	sort(price, price + n); 
	int totalCost = 0; 
	for (int i = n - 1; i > 1; i -= 2) { 
		if (i == 2) { 
			totalCost += price[2] + price[0]; 
		} 
		else { 
			int  price_first = price[i] + price[0] + 2 * price[1]; 
			int  price_second = price[i] + price[i - 1] + 2 * price[0]; 
			totalCost += min(price_first, price_second); 
		} 
	} 
	if (n == 1) { 
		totalCost += price[0]; 
	} 
	else { 
		totalCost += price[1]; 
	} 

	return totalCost; 
} 
int32_t main() 
{ 
	int s; cin>>s;
    int n; cin>>n;
	int  price[n];
	int tp=0;
	for(int i=0;i<n;++i)
	{cin>>price[i]; tp+=price[i];}	
	if(tp>=s)
		cout<<"Yes";
	else
		cout<<"No";

	return 0; 
} 


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin >> s >> t;
	int ans = 1e9+7;
	for(int i = 0; i < (int)s.length()-t.length()+1;++i){
		int cnt = 0;
		for(int j = i; j < (int)t.length()+i;++j){
			if(t[j-i] != s[j])
				++cnt;
		}
			ans = min(ans,cnt);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3652
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;


public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String s = sc.next();

		int N = 0;
		int W = 0;
		int S = 0;
		int E = 0;
		for (char c : s.toCharArray()) {
			if (c == 'N') {
				N = 1;
			} else if (c == 'W') {
				W = 1;
			} else if (c == 'S') {
				S = 1;
			} else if (c == 'E') {
				E = 1;
			}
		}
		System.out.println((N ^ S) == 0 && (W ^ E) == 0 ? "Yes" : "No");
	}
}



class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 8020
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    
    if(k==1){
      System.out.println(0);
    }else{
      System.out.println(n-k);
    }
  }
}

Measured memory_bytes: 21204
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int a,b;
    cin>>a>>b;

    string s1 = "";
    for(int i=0;i<b;i++) s1+=a+'0';
    string s2 = "";
    for(int i=0;i<a;i++) s2+=b+'0';

    cout<<min(s1, s2);
} 

Measured memory_bytes: 256