akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long 
#define MOD 1000000007
#define MAX_P 1100000
using namespace std;

vector<ll> factn(MAX_P+1);
// n! = factn[i]
void fact(ll n){
    factn[1] = 1;
    for(ll i = 2; i<=n;i++){
        factn[i] = factn[i-1]*i%MOD;
    }
    return;
}

ll extgcd(ll a, ll b, ll& x, ll& y){
    ll d = a;
    if( b!= 0){
        d = extgcd(b, a%b,y,x);
        y -= (a/b) *x;
    }else{
        x=1;y=0;
    }
    return d;
}
ll mod_inverse(ll a, ll m){
    ll x,y;
    x = 1; y =0;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

// n! mod p
ll mod_fact(ll n, ll p, ll& e){
    e = 0;
    if(n == 0) return 1;

    ll res = mod_fact(n/p, p, e);
    e+= n/p;

    if(n/p%2 != 0) return res*(p - factn[n%p]) %p;
    return res*factn[n%p]%p;
}

// nCk %mod p
ll mod_comb(ll n, ll k, ll p){
    if(n<0 || k < 0 || n<k) return 0;

    ll e1,e2,e3;
    e1 = e2 = e3 = 0;
    ll a1 = mod_fact(n,p,e1);
    ll a2 = mod_fact(k,p,e2);
    ll a3 = mod_fact((n-k),p,e3);

    if(e1 > e2+e3) return 0;
    return a1*mod_inverse(a2*a3%p, p)%p;
}


// X = 2a + 1b
// Y = a +2b 

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll xx,yy;
    cin>>xx>>yy;
    ll mm = 0;
    ll nn = 0;
    bool flag = true;
    for(ll b =0; 2*b<=xx; b++){
        ll a = xx-(2*b);
        if(yy == (2*a+b)) {
            nn = a;
            mm =b;
            flag=false;
            break;
        }
    }
    if(flag) {
        cout<< 0 <<endl;
        return 0;
    }
    fact(MAX_P);
    ll ans = 0;
    ans = mod_comb(nn+mm, nn, MOD);
    cout<< ans <<endl;
    
    return 0;
}

Measured memory_bytes: 8960
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  int n, h[MAX_N], k;
  ll dp[MAX_N];
  cin >> n >> k;
  for (int i = 0; i < n; i++){
    cin >> h[i];
    dp[i] = INF;
  }

  dp[0] = 0;

  for (int i = 0; i < n; i++){
    for (int j = 1; j <= k; j++){
      if (i + j < n){
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i + j]));
      }
    }
  }

  cout << dp[n-1] << endl;


}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
	char a[10];
	scanf("%s",a);
	a[3]++;
	if(a[3]>'9')
	{
		a[2]++;
		a[3]='0';
		if(a[2]>'9')
		{
			a[1]++;
			a[3]='0';
			if(a[1]>'9')
			{
				a[0]++;
				a[1]='0';
			}
		}
	}
	printf("%s",a);
	return 0;
}

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

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

    int r, g, b;
    cin >> r >> g >> b;
    r = r * 100;
    g = g * 10;
    int result = r + g + b;
    if (result % 4 == 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
}

Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
    int m;
 
   cin >> n >> m;
   
int flag = 0;
  
for(int i = 2;i<=3;i++){
  
    int ans = n*m*i;
  
    if(ans%2!=0){
      
      cout << "Yes" << endl;
      flag = 1;
    }
    
     

}
   if(flag==0){
     cout << "No" << endl;
   }
   
   //cout << n << endl;
   //cout << m << endl;
  
   
  
  return 0;
}

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

int main(void)
{
  int i,j;
  for(i = 1; i <= 9; i++){
    for(j = 1; j <= 9; j++){
      cout << i << "x" << j << "=" << i*j << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define all(s) s.begin(),s.end()
#define pb push_back
#define pi 3.1415926536
#define dig(a) fixed<<setprecision(a)
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
ll powerm(ll a, ll n, ll m) {
	ll res = 1; 
	while (n) { if (n % 2) {res = (res * a) % m;}
		n >>= 1;
		a = (a * a) % m;
	}
	return res;
}
const int M=1e9+7;
ll mod(ll x){
      return ((x%M + M)%M);
}
ll add(ll a, ll b){
      return mod(mod(a)+mod(b));
}
ll mul(ll a, ll b){
      return mod(mod(a)*mod(b));
}
ll minu(ll a, ll b){
	return mod(mod(a)-mod(b));
}
const int maxx = 2e5;

int main(){
	fast();
	int test=1;
	//cin>>test;
	while(test--){
		int n;cin>>n;
		vector<pair<int,int>> v(n);
		int a,b;
		for(int i=0;i<n;i++){
			cin>>a>>b;
			v[i].first = a;
			v[i].second = b;
		}
		int c=0,f=0;;
		for(int i=0;i<n;i++){
			while(i<n && v[i].first==v[i].second){
				c++;
				i++;
				f=1;
			}
			if(c>=3){
				cout<<"Yes"<<endl;
				return 0;
			}
			c = 0;
			if(f==1){
				i--;
				f=0;
			}
			
		}
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3644
n,m = gets.strip.split.map(&:to_i)
a = []
n.times do
  x = gets.strip.chars
  a << x
end
b = []
m.times do
  y = gets.strip.chars
  b << y
end

t = 0
for i in 0..n-m
  for j in 0..n-m
    #iとjを固定（一番左上）
    s = 0
    for k in 0..m-1
      for l in 0..m-1
        if a[k+i][l+j] == b[k][l]
          s += 1
        end
      end
    end
    if s == m**2
      t += 1
    end
  end
end
if t > 0
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14572
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


# https://atcoder.jp/contests/abc119/tasks/abc119_c


N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
memo1 = {}
def cho(n):
    if n==0:
        return 1
    if n in memo1:
        return memo1[n]
    memo1[n] = 2*cho(n-1)+3
    return memo1[n]
memo2 = {}
def pat(n):
    if n==0:
        return 1
    if n in memo2:
        return memo2[n]
    memo2[n] = 2*pat(n-1)+1
    return memo2[n]
N,X = map(int,input().split())
cnt = 0
k = N
while X>0:
    if X==1:
        if k==0:
            cnt += 1
        break
    elif X<=cho(k)//2:
        k -= 1
        X -= 1
    elif X==cho(k)//2+1:
        cnt += 1+pat(k-1)
        break
    elif X==cho(k):
        cnt += pat(k)
        break
    else:
        cnt += pat(k-1)+1
        X -= cho(k-1)+2
        k -= 1
print(cnt)

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


int main()
{
  ll n;
  cin >> n;
  if (n % 2 == 1)
  {
    puts("0");
    return 0;
  }
  ll d = 2;
  ll ans = 0;
  while (d * 5 <= n)
  {
    d *= 5;
    ans += n / d;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if len(ss) > 1 else [ss]
def Is(): return _Is(I())
 
n, lim = I()
ans = 0
cache = {}
 
def dist(x, y, lim):
  if (x,y) not in cache:
    cache[x,y] = sqrt(x*x + y*y) <= lim
  return cache[x,y]
 
for _ in range(n):
  x, y = I()
  if dist(x, y, lim):
    ans += 1
    
print(ans)

Measured memory_bytes: 64352
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 10000
#define mod 998244353
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char A[MN+5],B[MN+5];
int f[MN+5][MN+5],p[MN+5],g[MN+5],inv[MN+5],n,num1,num2,ans;
inline void R(int&x,int y){x+=y;x>=mod?x-=mod:0;}
inline int C(int n,int m){return 1LL*p[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
    scanf("%s%s",A+1,B+1);n=strlen(A+1);p[0]=inv[0]=p[1]=inv[1]=g[0]=1;
    for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2;i<=n;++i) inv[i]=1LL*inv[i-1]*inv[i]%mod,g[i]=1LL*(i-1)*(g[i-1]+g[i-2])%mod;
    for(int i=1;i<=n;++i) if(A[i]=='1'&&B[i]=='1') ++num2; else if(A[i]=='1') ++num1;
    f[num1][0]=1;
    for(int i=num1;~i;--i) for(int j=0;j<=num2;++j) if(f[i][j])
    {
        if(i) R(f[i-1][j],1LL*f[i][j]*i*i%mod);
        if(i) R(f[i][j+1],1LL*f[i][j]*i%mod);
        R(f[i][j+1],f[i][j]);
    }
    for(int j=0;j<=num2;++j) ans=(ans+1LL*C(num2+num1,num2-j)*C(num2,j)%mod*f[0][j]%mod*p[j]%mod*g[num2-j]%mod*p[num2-j])%mod;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 195200
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;

#define loop(i,n) for(int i=0;i<(n);i++)
#define pool(i,n) for(int i=(n)-1;i>=0;i--)
#define cont(i,n) for(int i=1;i<=(n);i++)
#define tnoc(i,n) for(int i=(n);i>=1;i--)
#define circ(i,a,b) for(int i=(a);i<=(b);i++)
#define cric(i,a,b) for(int i=(b);i>=(a);i--)
#define sub(i,a) for(int i=a;i;i=((i-1)&(a)))
#define subs(i,a) for(int i=a;i>=0;i=(!i?-1:((i-1)&(a))))
#define subt(i,a) for(int i=((a-1)&a);i;i=((i-1)&(a)))
#define subst(i,a) for(int i=((a-1)&a);i>=0;i=(!i?-1:((i-1)&(a))))
#define range(i,a,b,c) for(int i=(a);((c)>0?i<=(b):i>=(b));i+=(c))
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(),_e_D_=(v).end();it!=_e_D_;it++)
#define parse(i,s) for(int i=0;s[i];i++)

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mak make_pair

#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1 y1II11II11III11I1III11II111IIII1II1I1
#define ws WSrAkIoi2333wSraKIoIWSraKiOi
#define left left_jTjTJtJtIoiiOiioIAuaU66666jtIOIau
#define hash whYusEthiSnamE_caNyoUusEothERnaMesliKeHSH

#define Mask(a) (1ll<<(a))
#define Maskx(a,x) ((a)<<(x))
#define Full(a) ((1ll<<(a))-1)
#define Bit(a,x) (((a)>>(x))&1)
#define all(a) (a).begin(),(a).end()
#define SZ(a) ((int)((a).size()))

typedef long long ll;
typedef long double lf;

const int Inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const lf inF=11451419198101145141919810.1145141919810;
const lf pi=acosl(-1);
/* Source code starts here */

const int jt=1000000007;
int n,m,k;
int a[29][29];
int dp[2][1<<20];
int btz[1<<20];

int main(){
	scanf("%d%d%d",&n,&m,&k);n--;
	memset(a,-1,sizeof(a));
	loop(i,k){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		a[--u][--v]=w;
	}
	dp[0][0]=1;
	int now=1,lst=0;
	cont(msk,(1<<n)-1)btz[msk]=(1<<__builtin_ctz(msk));
	loop(i,m)loop(j,n){
		loop(msk,1<<n)dp[now][msk]=0;
		loop(msk,1<<n){
			if(!dp[lst][msk])continue;
			if(a[i][j]!=1&&!Bit(msk,j))(dp[now][msk]+=dp[lst][msk])%=jt;
			if(a[i][j]){
				int nmsk=msk^btz[msk&((1<<n)-(1<<j))]^(1<<j);
				(dp[now][nmsk]+=dp[lst][msk])%=jt;
			}
		}
		swap(now,lst);
	}
	int ans=0;
	loop(msk,1<<n)ans=(ans+dp[lst][msk])%jt;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 12672
#include<bits/stdc++.h>
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define ll long long
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
using namespace std;
const int N=1e5+5;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int a[N],b[N],n,ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),a[i]+=a[i-1];
	for(int i=1;i<=n;i++) b[i]=read(); 
	for(int i=n;i;i--) b[i]+=b[i+1];
	for(int i=1;i<=n;i++) ans=max(ans,a[i]+b[i]);
	cout<<ans<<endl; 
}

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

int main(){
  int n,m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; i++)
  {
    int a;
    cin >> a;
    sum+=a;
  }

  if(sum>n) cout << -1 << endl;
  else cout << n-sum << endl;
  
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        double d = sc.nextDouble();
        double dis = Math.sqrt((c-a)*(c-a) + (d-b)*(d-b));
        System.out.println(dis);
    }
}


Measured memory_bytes: 28004
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define min(a,b) (((a) < (b)) ? (a) : (b))

int main(void ){
	int dataset;

	scanf("%d", &dataset);
	while(dataset--){
		int gx, gy;
		int matatabis;
		int road[17][17];
		int matatabi[17][17];
		int x, y;
		memset(road, 0, sizeof(road));
		memset(matatabi, 0, sizeof(matatabi));

		scanf("%d %d", &gx, &gy);
		scanf("%d", &matatabis);
		while(matatabis--){
			int x1, y1, x2, y2;
			scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
			if (x1==x2) matatabi[x1][min(y1, y2)] += 1;
			else matatabi[min(x1, x2)][y1] += 2;
		}

		road[1][1] = 1;
		for (x=1; x<=gx+1; x++){
			for (y=1; y<=gy+1; y++){
				if (x-1 && !(matatabi[x-2][y-1] & 2)) road[x][y] += road[x-1][y];
				if (y-1 && !(matatabi[x-1][y-2] & 1)) road[x][y] += road[x][y-1];
			}
		}
		if (road[gx+1][gy+1]) printf("%d\n", road[gx+1][gy+1]);
		else printf("Miserable Hokusai!\n");
	}
}

/*
1	ª
2	¨
*/

Measured memory_bytes: 0
n = int(input())
v = list(map(int,input().split()))
v0 = v[0:n-1:2]
v1 = v[1:n:2]
from collections import Counter
V0 = Counter(v0)
V1 = Counter(v1)
if V0.most_common()[0][0] != V1.most_common()[0][0]:
    a = V0.most_common()[0][1]
    b = V1.most_common()[0][1]
else:
    if V0.most_common()[0][1] > V1.most_common()[0][1]:
        if len(V1) > 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        else:
            a = V0.most_common()[0][1]
            b = 0
    elif V0.most_common()[0][1] < V1.most_common()[0][1]:
        if len(V0) > 1:
            a = V1.most_common()[0][1]
            b = V0.most_common()[1][1]
        else:
            a = 0
            b = V1.most_common()[0][1]
    else:
        if len(V0) == 1 and len(V1) == 1:
            a = 0
            b = V0.most_common()[0][1]
        elif len(V0) == 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        elif len(V1) == 1:
            a = V0.most_common()[1][1]
            b = V1.most_common()[0][1]
        else:
            a = V0.most_common()[0][1]
            b = max(V0.most_common()[1][1],V1.most_common()[1][1])
print(n-a-b)


Measured memory_bytes: 24592
#include<iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int count=0;
  int check=0;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }

  while(1){
    for(int i=0;i<N;i++){
      if(a[i]%2==0){
        check++;
      }
    }
    if(check==N){
      count++;
      check=0;
      for(int i=0;i<N;i++){
        a[i] /=2;
      }
    }
    else{
      break;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))
S = input()
ok = False
if S[0] == "A" and S[2:-1].count("C") == 1:
    u = 0
    for s in S[1:]:
        u += s.isupper()
    if u == 1:
        ok = True
if (ok):
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
### スペース区切りの３つの数値を小さい順にならべかえる。

str_in = raw_input()
int_in = map(int, str_in.split())

### i が0 に到達したらループから抜けるよ
for i in range(0, 2):
	for j in range (2, i, -1):
		if(int_in[j-1] > int_in[j]):
			swap = int_in[j-1]
			int_in[j-1] = int_in[j]
			int_in[j] = swap
		
		
print(repr(int_in[0])  + ' ' + repr(int_in[1]) + ' ' + repr(int_in[2]))



Measured memory_bytes: 4652
program main
  implicit none
  integer(8) i,N,min,fumi
  integer(8),allocatable :: A(:)
  read(*, *)N
  allocate(A(N))
  read(*, *) (A(i), i = 1,N)
  fumi = 0
  min = 0

  do i = 1,N
    if (min > A(i)) then
      fumi = fumi + (min - A(i))
    else
      min = A(i)
    end if
  end do
  
  write(*, *) fumi
end program main


Measured memory_bytes: 4584
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        
        long count = 0;
        long sum = 0;
        while (true) {
            n /= 2;
            sum += Math.pow(2,count);
            count++;
            if (n == 0) {
                break;
            }
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 22740
x1,y1,x2,y2=map(int,input().split())
vx=x2-x1#+
vy=y2-y1#+
x3=x2-vy
y3=y2+vx
x4=x1-vy
y4=y1+vx
print(x3,y3,x4,y4)


Measured memory_bytes: 2940
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 250005;
const int P1 = 1000000223, P2 = 1000000433;
const int Q1 = 739777249, Q2 = 759391002;
const int R1 = 886220847, R2 = 804140220;

pii operator-(pii l, pii r){ return pii((l.first + P1 - r.first) % P1, (l.second + P2 - r.second) % P2); }
pii operator+(pii l, pii r){ return pii((l.first + r.first) % P1, (l.second + r.second) % P2); }
pii operator*(pii l, pii r){ return pii((ll)l.first * r.first % P1, (ll)l.second * r.second % P2); }

char D[MX];
pii DB[MX];

int main()
{
	int N;
	scanf("%d", &N);
	scanf("%s", D);
	pii v = pii(0, 0), u = pii(0, 0), w = pii(1, 1);
	pii cur = pii(1, 1);
	map<pii, int> X;
	for(int i = 0; i < N; i++){
		if(D[i] == '<') cur = cur * pii(R1, R2);
		if(D[i] == '>') cur = cur * pii(Q1, Q2);
		if(D[i] == '+') v = v + cur;
		if(D[i] == '-') v = v - cur;
		DB[i] = v;
		X[v] += 1;
	}
	ll ans = 0;
	for(int i = 0; i < N; i++){
		pii x = v*w+u;
		ans += X[x];
		X[DB[i]] -= 1;
		if(D[i] == '<') w = w * pii(R1, R2);
		if(D[i] == '>') w = w * pii(Q1, Q2);
		if(D[i] == '+') u = u + w;
		if(D[i] == '-') u = u - w;
	}
	printf("%lld\n", ans);
}



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

int main() {
 int n;
 cin>>n;
 vector<int> a(n);
//int sum=0;
//int l=INT_MAX;
//int r=INT_MAX;

 for(int i=0;i<n;i++){
     cin>>a[i];
    // l=min(l,a[i]);
    // r=max(r,a[i]);
 }
int ans=INT_MAX;
for(int i=1;i<=100;i++){
    int d=0;
    for(int j=0;j<n;j++){
        d+= (a[j]-i)*(a[j]-i);
    }
    ans=min(ans,d);
}


 cout<<ans;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S, T;
  cin >> S >> T;
  bool flag = false;
  for(int i = 0; i < 26; i++){
    string str = S + (char)(i + 'a');
    if(str == T) flag = true;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3652
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b = il()
    t = [0] * 1000
    t[0] = 1
    for n in range(2, 1000):
        t[n-1] = t[n-2] + n
    for n in range(1000):
        if t[n] - a == t[n+1] - b:
            print(t[n]-a)
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 10044
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f("ABC", X) :- X < 1200, !.
f("ARC", _).

main :-
    get_number(X),
    f(Y, X),
    writeln(Y).


Measured memory_bytes: 8012
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>
#include <functional>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> vs(n);
    for (auto &v : vs)
    {
        cin >> v;
    }
    sort(vs.begin(), vs.end(), greater<>());

    int a = 0;
    int b = 0;
    for (int i = 0; i < n; i++)
    {
        (i % 2 == 0 ? a : b) += vs[i];
    }
    cout << (a - b) << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
	int n;scanf("%d",&n);printf("%d\n",(n-2)*180);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=3e6+5;
const double pi=3.14159265358979323846;
ll f[maxn];
ll C[30][30];
void table_C(){
    memset(C,0,sizeof(C));
    C[0][0]=1;
    for(int i=1;i<=28;i++){
        C[i][0]=1;
        for(int j=1;j<=i;j++) C[i][j]=C[i-1][j]+C[i-1][j-1];
    }
}
void table()
{
    f[0]=1;
    for(ll i=1;i<maxn;i++) f[i]=f[i-1]*i%mod;
}
 
void exgcd( ll a,ll b, ll &x,ll &y,ll &d )
{
    if(!b){ x=1;y=0;d=a; }
    else
    {
        exgcd(b,a%b,x,y,d);
        int t=x;
        x=y;
        y=t-(a/b)*y;
    }
}
ll solve(ll a,ll b) // 求a mod b 下的逆元如ax ≡ 1 mod p 求x 则 solve(a,p)
{
    ll x,y,d;
    exgcd(a,b,x,y,d);
    ll t=b/d;
     x=(x%t+t)%t;//最小正整数解
    return x;
}
ll CC( ll n,ll m,ll p )
{
    if(n<m) return 0;
    return f[n]*(solve(f[m]*f[n-m]%p,p)%p)%p;
}

ll ktl( ll n ) //卡特兰数 
{
	return ( CC(n*2,n,mod)-CC(2*n,n+1,mod)+mod )%mod; 
}

ll h( ll n,ll m ,ll t=1) // n个数中选择 m 个至少相邻 t 个的数，
{
	return CC(n-t*(m-1),m,mod);
} 

ll qpow( ll x,ll y )
{
	ll res=1;
	while( y )
	{
		if( y&1 ) res=res*x%mod;
		y>>=1;
		x=x*x%mod;
	}
	return res;
}

int main()
{
    int n;
	cin>>n;
	ll ans=0;
//	cout<<(qpow(2,n)-2+mod)%mod<<endl;
	table();
	//CC(n,i)*CC(n-i,j)
	for( int i=2;i<=n;i++ )
	{
		ll now=CC(n,i,mod)*(qpow(2,i)-2+mod)%mod;
		now=qpow(8,n-i)*now%mod;
		ans=(ans+now)%mod;
	} 
	cout<<ans<<endl;
}



Measured memory_bytes: 27064
def main():
    counter = 0
    n = int(input())
    l = list(map(int,input().split()))
    l.sort()
    for i in range(n-2):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if l[i]==l[j] or l[j]==l[k] or l[k]==l[i]:
                    continue
                if l[k] < (l[i] + l[j]):
                    #print(l[i],l[j],l[k])
                    counter += 1

    print(counter)




if __name__ == '__main__':
    main()


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

int main() {
	int n,m,l;
	cin>>n>>m>>l;
	long long a[n][m], b[m][l],c[n][l];
	for (int i = 0; i < n; i++)
	{
		for (int j= 0; j < m; j++)
		{
			cin>>a[i][j];/* code */
		}
	}
	for (int i = 0; i < m; i++)
	{
		for (int j= 0; j < l; j++)
		{
			cin>>b[i][j];/* code */
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j= 0; j < l; j++)
		{
			c[i][j]=0;/* code */
		}
	}

	for (int i = 0; i < n; ++i)
	{
		for (int j= 0; j < l; ++j)
		 {
		 	for (int k = 0; k < m; ++k)
		 	 {
		 	 	c[i][j]+=a[i][k]*b[k][j];
		 	 } 
		 } 
	}

	for (int i = 0; i < n; i++)
	{
		for (int j= 0; j < l-1; j++)
		{
			cout<<c[i][j]<<" ";
		}
		cout<<c[i][l-1]<<endl;
	}


	return 0;
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int inf=1e9+5;
int main()
{
	int n,k;
	cin>>n>>k;
int v[n];

	for(int i=0;i<n;i++)
	 cin>>v[i];
	//vector<int> dp(n,inf);
	ll dp[n];
	for(int i=0;i<n;i++)
	    dp[i]=inf;
	dp[0]=0;
	
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
		if(j<n)
		{
		
		
				dp[j]=min(dp[j],dp[i]+abs(v[j]-v[i]));				
	}
}
		
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}


Measured memory_bytes: 1408
N, D = gets.split.map(&:to_i)

X = N.times.map {
  gets.split.map(&:to_i)
}

puts X.combination(2).select {|x, y|
  d = Math.sqrt(D.times.inject(0) {|acc, i|
    acc + (x[i] - y[i]) ** 2
  })

  d == d.to_i
}.size

Measured memory_bytes: 1788
/*
 * 17-05-13_ABC061_B.cpp
 *
 *  Created on: 2017/05/13
 *      Author: ryoma
 */

#include<iostream>

using namespace std;

int N,M;
int ans[60];
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		ans[a]++;
		ans[b]++;
	}
	for(int i=0;i<N;i++){
		cout << ans[i] << endl;
	}
	return 0;
}




Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        String[] str = br.readLine().split("");
        
        int i = 0;
        int j = str.length -1;
        int count = 0;

        while(i <= j){
          if(!(str[i].equals(str[j]))){
            count++;
          }
          i++;
          j--;
        }
        System.out.println(count);
      }
    }
}

Measured memory_bytes: 23252
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  if (a[0] > 0) {
    cout << -1 << endl;
    return 0;
  }
  // Here, a[0] == 0

  ll ans = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i-1] + 1 < a[i]) { // a[i] is too large
      cout << -1 << endl;
      return 0;
    }

    if (a[i-1] + 1 == a[i]) {
      ++ans;
    } else { // a[i-1] + 1 > a[i]
      ans += a[i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    a, b = map(int, input().split())
    if a * b <= 0:
        print("Zero")
    else:
        if a > 0:
            print("Positive")
        else:
            if (b - a) & 1:
                print("Positive")
            else:
                print("Negative")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62236
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
long long a[N], dp[N][2];

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

	cin >> n;
	
	for(int i = 0; i < n; i++) cin >> a[i];
	
	for(int i = n - 1; i >= 0; i--) {
		dp[i][0] = dp[i][1] = -1e18;

		int t = (n - i - 1) / 2;
		if(t == 0) dp[i][0] = a[i];	
		else {
			for(int j = i + 2; j < min(i+25, n); j++) {
				int k1 = (n - j - 1) / 2;
				int k2 = (n - j - 2) / 2;

				if(k1 == t - 1) dp[i][0] = max(dp[i][0], a[i] + dp[j][0]);
				if(k2 == t - 1) dp[i][0] = max(dp[i][0], a[i] + dp[j][1]);
			}
		}

		t = (n - i - 2) / 2;

		if(t == 0) dp[i][1] = a[i];
		else {
			for(int j = i + 2; j < min(i+25, n); j++) {
				int k1 = (n - j - 1) / 2;
				int k2 = (n - j - 2) / 2;
				if(k1 == t - 1) dp[i][1] = max(dp[i][1], a[i] + dp[j][0]);
				if(k2 == t - 1) dp[i][1] = max(dp[i][1], a[i] + dp[j][1]);
			}
		}
		
	}

	long long ans = -1e18;
	for(int i = 0; i < n; i++) {
		if((n-1-i)/2 + 1 == n/2) ans = max(ans, dp[i][0]);
		if((n-2-i)/2 + 1 == n/2) ans = max(ans, dp[i][1]);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 8292
import java.util.*;

public class Main {
    public static void main(String[] args ) throws Exception {
        Scanner sc = new Scanner(System.in);
      	String A = sc.next();
        int i = 1;
        if(A.matches("[A-Z]")){
            System.out.println("A");
        } else {
            System.out.println("a");
        }

    }
}


Measured memory_bytes: 26956
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF 1e9
#define INFL 1e18
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

class DLazyFaith {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll A, B, Q;
        in >> A >> B >> Q;
        vector<ll> s, t;
        s.PB(-INFL);
        t.PB(-INFL);
        REP(i, A) {
            ll a;
            in >> a;
            s.PB(a);
        }
        s.PB(INFL);
        REP(i, B) {
            ll b;
            in >> b;
            t.PB(b);
        }
        t.PB(INFL);
        REP(i, Q) {
            ll x;
            in >> x;
            ll sr = lower_bound(ALL(s), x) - s.begin();
            ll sl = sr - 1;
            ll tr = lower_bound(ALL(t), x) - t.begin();
            ll tl = tr - 1;
//            out << sl << ' ' << sr << ' ' << tl << ' ' << tr << '\n';
            ll ans = INFL;
            ll _s[2] = {s[sl], s[sr]};
//            out << _s[0] << ' ' << _s[1] << '\n';
            ll _t[2] = {t[tl], t[tr]};
//            out << _t[0] << ' ' << _t[1] << '\n';
            REP(j, 2) {
                REP(k, 2) {
                    ll dist = abs(x - _s[j]) + abs(_s[j] - _t[k]);
//                    out << dist << '\n';
                    ans = min(ans, dist);
                    dist = abs(x - _t[j]) + abs(_t[j] - _s[k]);
//                    out << dist << '\n';
                    ans = min(ans, dist);
                }
            }
            out << ans << '\n';
        }
	}
};


int main() {
	DLazyFaith solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

char s[500005];
int a[500005], dp[500005];

int main() {
	int n, lz = -1;
	scanf("%d%s", &n, &s);
	for (int i = 0; i < n; i++)
		a[i] = s[i] - '0';
	for (int i = 0; i < n; i++) {
		dp[i + 1] = max(dp[i], dp[i + 1]);
		if (a[i]) {
			if (lz > 0 && a[lz - 1]) {
				dp[i + 1] = max(dp[i + 1], dp[lz - 1] + i - lz);
			}
		}
		else {
			if (a[i - 1] && a[i + 1]) {
				dp[i + 2] = max(dp[i + 2], dp[lz + 1] + i - lz - 1);
				if (lz < i - 2)
					dp[i + 2] = max(dp[i + 2], dp[lz + 2] + i - lz - 2);
			}
			lz = i;
		}
	}
	printf("%d\n", dp[n]);
}

Measured memory_bytes: 4608
import sys
input = sys.stdin.readline

n = int(input())
v_list = list(map(int, input().split()))

v_list.sort()

ans = 0
for i in range(n):
  if i == 0:
    ans += v_list[i]/(2**(n-1))
  else:
  	ans += v_list[i]/(2**(n-i))
  
print(ans)

Measured memory_bytes: 3060
/*
QUESTION    :

RULE        :

INPUT       :

OUTPUT      :
*/
/*
    int     :10^9
long long   :10^19
*/
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<(n);++i)
#define repeq(i,a,n) for(int i=a;i<=(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    string s;
    vector<int> c(4);
    rep(i,0,n){
        cin >> s;
        if(s=="AC"){
            c.at(0)++;
        }
        if(s=="WA"){
            c.at(1)++;
        }
        if(s=="TLE"){
            c.at(2)++;
        }
        if(s=="RE"){
            c.at(3)++;
        }
    }
    cout << "AC x " << c.at(0) << endl;
    cout << "WA x " << c.at(1) << endl;
    cout << "TLE x " << c.at(2) << endl;
    cout << "RE x " << c.at(3) << endl;

    return 0;
}

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

int main(){
    int n;
    scanf("%d",&n);

    long long sum=0;
    for(int i=1; i<=n; i++){
        if(i%3==0 || i%5==0) continue;
        else sum+=i;
    }
    printf("%lld\n",sum);

    return 0;
}


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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >
int dist(int here, auto p) {
    if (p->first <= here and here <= p->second) return 0;
    if (p->second <= here and here <= p->first) return 0;
    return abs(here - p->first);
}

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vec l(n + 1), r(n + 1);
    rep (i, n)
        cin >> l[i] >> r[i];

    sort(all(l), greater<int>());
    sort(all(r));
    int total = 0;
    rep (i, n + 1)
        if (l[i] > r[i]) total += 2 * (l[i] - r[i]);

    print(total);

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

void insert(int);
void inorder(Node);
void preorder(Node);
Node  find(Node,int);
void delite(Node );
Node getSuccessor(Node);
Node getMinimum(Node);

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
    x = x->left;
    }
    else {
      x = x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else {if(z->key < y->key){
      y->left = z;
    }else {y->right = z;
    }
  }
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
Node find(Node u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)
      u=u->left;
    else
      u=u->right;
  }
  return u;
}
void delite(Node a){
  Node y;
  Node x;
  if(a->left==NIL||a->right==NIL)
    y=a;
  else
    y=getSuccessor(a);
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else{
    if(y==y->parent->left){
      y->parent->left=x;
    }
    else{
      y->parent->right=x;
    }
  }
  if(y!=a){
    a->key=y->key;
  }
  free(y);
}
Node getSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return getMinimum(x->right);
  y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
Node getMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}
    
int main(){
  int n, i, a;
  char com[20];
  Node u;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &a);
      insert(a);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'f' ){
      scanf("%d", &a);
      u=find(root,a);
      if(u!=NIL)printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] == 'd'){
      scanf("%d",&a);
      delite(find(root,a));
  }
  }
  return 0;
}
  



Measured memory_bytes: 20472
def main():
    N, K = map(int, input().split())
    H = sorted(list(map(int, input().split())), reverse=True)
    all = sum(H)
    at = 0
    if (K > N):
        K = N
    for i in range(K):
        at += H[i]
    result = all - at
    if result <= 0:
        result = 0
    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 26180
/*⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄
⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄
⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄
⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄
⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰
⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤
⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗
⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄
⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄
⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄
⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄
⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄
⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴
⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=998244353;

int a,b,c,d;
ll memo[3005][3005];

ll fix(ll i){
	i%=MOD;
	if (i<0) i+=MOD;
	return i;
}

ll dp(int i,int j){
	if (i==a && j==b) return 1;
	if (i<a || j<b) return 0;
	if (memo[i][j]!=-1) return memo[i][j];
	
	return memo[i][j]=fix(dp(i-1,j)*j+dp(i,j-1)*i-dp(i-1,j-1)*((i-1)*(j-1)%MOD));
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	memset(memo,-1,sizeof(memo));
	
	cin>>a>>b>>c>>d;
	
	cout<<dp(c,d)<<endl;
}


Measured memory_bytes: 74584
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

void solve();
int main() {
	solve();
#ifdef DBG
	while (true);
#endif
}

void solve() {
	int A, B, C, K;
	scanf("%d %d %d %d", &A, &B, &C, &K);
	if (A > B && A > C)
		A <<= K;
	else if (B > C)
		B <<= K;
	else
		C <<= K;
	printf("%d\n", A + B + C);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int N = 52;
int n, v[N];
long long a[N];
vector<pair<int, int> > sol;
vector<pair<int, int>>pos, neg;

int32_t main() {
  //  freopen("a.in", "r", stdin);
    cin >> n;
    int mxPozitiv = 0, mxNegativ = 0;
    bool anyNeg = 0;

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

        if(v[i] >= 0) {
            if(v[i] > v[mxPozitiv] || mxPozitiv == 0) mxPozitiv = i;
        } else {
            if(mxNegativ == 0 || v[i] < v[mxNegativ]) mxNegativ = i;
        }
    }
    if(mxPozitiv != 0 && (mxNegativ == 0 or v[mxPozitiv] > abs(v[mxNegativ]))) {
        for(int i = 1; i <= n; ++i) {
            if(i == mxPozitiv) continue;

            sol.emplace_back(mxPozitiv, i);
            v[i] += v[mxPozitiv];
        }

        for(int i = 2; i <= n; ++i)sol.emplace_back(i - 1, i), v[i] += v[i - 1];

    } else {
        for(int i = 1; i <= n; ++i) {
            if(i == mxNegativ)continue;

            sol.emplace_back(mxNegativ, i);
            v[i] += v[mxNegativ];

        }

        for(int i = n - 1; i >= 1; --i) {
            sol.emplace_back(i + 1, i);
            v[i] += v[i + 1];
        }
    }
for(int i=2;i<=n;++i)assert(v[i] >= v[i-1]);
    cout << sol.size() << '\n';
    for(auto itr : sol) cout << itr.first << ' ' << itr.second << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}

//check modulo
int main(){
	IOS;
	cout.precision(50) ;
	int n ; cin >> n ;
	ll dp[n + 1][4][4][4] ;
	int a = 0 , g = 1 , c = 2 ;
	memset(dp , 0 , sizeof dp) ;
	for(int i = 0 ; i < 4 ; i++){
		for(int j = 0 ; j < 4 ; j++){
			for(int k = 0 ; k < 4 ; k++){
				if(i == a && j == g && k == c) continue ;
				if(i == g && j == a && k == c) continue ;
				if(i == a && j == c && k == g) continue ;
				dp[3][i][j][k] = 1 ;
			}
		}
	}
	for(int N = 4 ; N <= n ; N++){
		for(int i = 0 ; i < 4 ; i++){
			for(int j = 0 ; j < 4 ; j++){
				for(int k = 0 ; k < 4 ; k++){
					for(int l = 0 ; l < 4 ; l++){
						if(i == a && k == g && l ==c) continue ;
						if(i == a && j == g && l == c) continue ;
						if(j == a  && k == g && l == c) continue ;
						if(j == a && k == c && l == g) continue ;
						if(j == g && k == a && l == c) continue ;
						dp[N][j][k][l] += dp[N - 1][i][j][k] ;
						dp[N][j][k][l] %= mod;
					}
				}
			}
		}
	}
	ll ans = 0 ;
	for(int i = 0 ; i < 4 ;i ++) for(int j = 0 ; j < 4 ;j++)for(int k = 0 ; k < 4 ; k++) add(ans , dp[n][i][j][k]) ;
	cout << ans << endl; 
	
	return 0;
}


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

int main() {
  int n, a, output;
  vector<int> v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }

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

  output = 0;
  for (int i = n - 1; i >= 0; i--) {
    if ((n - 1) % 2 == 0)
      i % 2 == 0 ? output += v[i] : output -= v[i];
    else
      i % 2 == 0 ? output -= v[i] : output += v[i];
  }
  cout << output << endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  
  int count = 0;
  
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == t.at(i))
      count++;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		
		if( S > W)
		{
			System.out.println("safe");
		}
		
		else
		{
			System.out.println("unsafe");
		}
	}
}

Measured memory_bytes: 35836