akhauriyash/Code-Regression huggingface dataset:
import numpy as np
import math
N = int(input())
data = {}
total = 1
for i in range(N):
  a_, b_ = map(int, input().split(" "))
  data[i] = np.array([a_,b_])
  total *= (i+1)

distance = 0.
for i in range(N):
  if i == 0:
    continue
  for j in range(i):
    distance += np.linalg.norm(data[i]-data[j])

param = 2 * (math.factorial(N) - math.factorial(N-1))/(N-1)
print(distance * param / total)


Measured memory_bytes: 12504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	int r = 0,b = 0;
	char str[100000];
	scanf("%s",str);
	for (int i = 0; i < strlen(str); ++i)
	{
		if(str[i] == '0')	++r;
		else ++b;
	}
	printf("%d\n", r < b ? 2 * r : 2 * b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

const int MAX = 1000005;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int 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(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}


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

    int N; cin >> N;
    vector<string> s(N);
    vector<int> t(N);
    rep(i, N) cin >> s[i] >> t[i];
    string x; cin >> x;

    int ans = 0;
    bool flg = false;
    rep(i, N) {
        if (flg) ans += t[i];
        if (s[i] == x) flg = true;
    }
    cout << ans << endl;

    
    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll k;
 cin>>k;
 vector< vector<ll> > dp(11,vector<ll>(11,0) );
 for(int i=0;i<10;i++)dp[0][i]++;
 for(int i=1;i<11;i++){
  for(int j=0;j<10;j++){
   if( j-1 >= 0 ) dp[i][j] += dp[i-1][j-1];
   dp[i][j] +=  dp[i-1][j] + dp[i-1][j+1];
  }
 }
 for(int i=0;i<11;i++){
  for(int j=1;j<10;j++){
   dp[i][10] += dp[i][j];
  }
 }
/*
 for(int i=0;i<11;i++){
  for(int j=0;j<11;j++)cout<<dp[i][j]<<' ';
  cout<<endl;
 }
 */

 ll ans = 0;
 ll keta = 0;
 while( k != 0 ){
  if( k > dp[keta][10] ){
   k -= dp[keta][10];
   keta++;
  }else{
   break;
  }
 }
//cout<<keta<<endl;
 ll f=0;
 for(ll i=1;i<10;i++){
  if(  k<=dp[keta][i] ){
   f = i;
   break;
  }else{
   k -= dp[keta][i];
  }
 }

 //cout<<k<<endl;
 
 ans += (ll)( pow(10,keta)*f + 0.1 );
 for(ll i=keta-1;i>=0;i--){
  for(ll j=max(0ll,f-1);j<=f+1;j++){
   if( k<= dp[i][j] ){
    f=j;
    ans += (ll)( pow(10,i)*f + 0.1 );
    break;
   }else{
    k-=dp[i][j];
   }
  }
 }
 cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N,M,X=map(int,input().split())
B=[list(map(int,input().split())) for i in range(N)]
ANS=1<<60
for i in range(1<<N):
    SCORE=[0]*M
    MONEY=0
    for j in range(N):
        if (1<<j) & i != 0:
            MONEY+=B[j][0]
            for k in range(M):
                SCORE[k]+=B[j][k+1]
    if min(SCORE)>=X:
        ANS=min(ANS,MONEY)
if ANS==1<<60:
    print(-1)
else:
    print(ANS)
            


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

int N;
ll A[200010];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    int i = 0;
    int j = N-1;
    ll dif = A[i] - A[j];
    while (i < j) {
        if (dif < 0) {
            i++;
            if (i < j) dif += A[i];
        }
        else {
            j--;
            if (i < j) dif -= A[j];
        }
    }

    cout << abs(dif) << endl; 

    return 0;
}


Measured memory_bytes: 1792
package main

import (
  "fmt"
)

func gcd(a, b int) int {
  if b == 0 {
    return a
  }
  return gcd(b, a%b)
}

func diff(a, b int) int {
  if a < b {
    return b - a
  }
  return a - b
}

func main() {
  var n, initialX int
  fmt.Scan(&n, &initialX)
  xs := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&xs[i])
  }
  result := 0
  for _, x := range xs {
    result = gcd(diff(x, initialX), result)
  }
  fmt.Println(result)  
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  for(int i = 0; i <= (B-A); i++) {
    if((A + i) % K == 0) {
      cout << "OK" << endl;
      break;
    }
    else {
      if(i == (B-A)) {
        cout << "NG" << endl;
      }
      else {
        continue;
      }
    }
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

template<class T> class myQueue {
    list<string> name;
    list<T> que;
public:
    myQueue() {name.resize(0); que.resize(0);}

    void push(const string& n, const T& x) {
        name.push_front(n);
        que.push_front(x);
        }
    void push(const pair<string, T>& x) {
        name.push_front(x.first);
        que.push_front(x.second);
        }
    pair<string, T> get() {
        return pair<string, T>(name.back(), que.back());
        }
    void pop() {name.pop_back(); que.pop_back();}
    pair<string, T> get_pop() {
        pair<string, T> tmp =  get();
        pop();
        return tmp;
        }
    bool empty() {return name.empty();}
};

int main() {
    ll n, q;
    cin >> n >> q;
    myQueue<ll> que;

    rep(i, n) {
        string s;
        ll x;
        cin >> s >> x;
        que.push(s, x);
    }

    ll cnt = 0;
    while(!que.empty()) {
        pair<string, ll> tmp = que.get_pop();
        if (tmp.second <= q) {
            cnt += tmp.second;
            cout << tmp.first << ' ' << cnt << '\n';
        }
        else {
            cnt += q;
            tmp.second -= q;
            que.push(tmp);
        }
    }
}


Measured memory_bytes: 8556
#include<iostream>

int main()
{
    int h;
    int w;
    int n;
    int paintNum = 0;
    std::cin >> h >> w >> n;
    while(n > 0){
        if(w > h){
            paintNum++;
            n -= w;
        }else{
            paintNum++;
            n -= h;
        }
    }
    std::cout << paintNum << std::endl;
    return 0;
}

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

#define STRING(str) #str
#define ll long long

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

const ll mod = 998244353;

long long modpow(long long a, long long x) {
    long long tmp = x;
    long long val = a;
    long long ret = 1LL;
    while (tmp>0) {
        if (tmp%2 == 1) ret = ret*val%mod;
        val = val*val%mod;
        tmp /= 2;
    }
    return ret;
}

int N, Q;

vector<ll> one(600000, 0);

// struct S {
//     int t, x, digit;
//     ll sum;
// };

struct S {
	ll summ, len;
};

// struct F {
    // int t, x, l, r;
// };
struct F {
    int x, l, r;
};

// S e() { return S{-111, 0, 5, 0LL}; }

S e() { return S{0LL, 0LL};}

S op(S l, S r) {
	return S{(l.summ*modpow(10LL, r.len)%mod+r.summ)%mod, l.len+r.len};
}

// S op(S l, S r) {
// 	if (l.t == -111) {
// 		return r;
// 	} else if (r.t == -111) {
// 		return l;
// 	} else {
// 		return S{-1, 0, 0, (l.sum+r.sum+(ll)(l.x)*modpow(10LL, (ll)(l.digit))+(ll)(r.x)*modpow(10LL, (ll)(r.digit)))%mod};
// 	}
// }

// S mapping(F l, S r) {
// 	if (r.t>l.t) {
// 		return r;
// 	} else {
// 		return S{l.t, l.x, r.digit, r.sum};
// 	}
// }

S mapping(F l, S r) {
	if (l.x == 0) {
		return r;
	} else {
		return S{l.x*one[r.len]%mod, r.len};
	}
}

F composition(F f, F g) {
	if (f.x == 0) {
		return g;
	} else {
		return f;
	}
}

F id() {
	return F{0, 0, 0};
}

// F composition(F l, F r) {
// 	if (l.t > r.t) {
// 		return l;
// 	} else {
// 		return r;
// 	}
// }

// F id() { return F{-1000, 0, 0, 0}; }

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

	cin >> N >> Q;
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(N);
	for (int i=0;i<N;i++) {
		seg.set(i, S{1, 1});
	}

	one[0] = 0;
	ll ttt = 1;
	for (int i=0;i<550000;i++) {
		one[i+1] = (one[i]+ttt)%mod;
		ttt = ttt*10%mod;
	}

	for (int i=0;i<Q;i++) {
		int L, R, D;
		cin >> L >> R >> D;
		L--;
		seg.apply(L, R, F{D, L, R});
		cout << seg.all_prod().summ << "\n";
	}
}

Measured memory_bytes: 22252
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
 
using namespace std;
 
const int maxn = 100 + 10;
int dat[maxn], n, x;
 
int main() {
  scanf("%d %d", &n, &x);
  for(int i = 0; i < n; ++i) scanf("%d", &dat[i]);
  int val = 0;
  int i = 0;
  for(; i < n; ++i) {
    val += dat[i];
    if(val > x) { break; }
  }
  printf("%d\n", i + 1);
  return 0;
}

Measured memory_bytes: 256
N,K = map(int, input().split())

if K == 0:
    ans = N**2
else:
    ans = (N-K) * (N-K+1) // 2
    for b in range(K+1, N+1):
        q = (N-b+1) // b
        r = (N-b+1) % b
        ans += q*(b-K) + max(0, r-K)
        
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
    int i,j,n,m;
    int a,b;
    cin>>a>>b;
    for(i=1;i<=100000;i++)
    {
        double q=(int)(i*0.08+0.0000000001);
        double p=(int)(i*0.10+0.0000000001);
        if(q==a&&b==p)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
  int n;
  scanf("%d",&n);
  int posx=0,posy=0,time=0;
  for(int i=0;i<n;i++)
  {
    int t,a,b;
    scanf("%d%d%d",&t,&a,&b);
    int sum=abs(posx-a)+abs(posy-b);
    if(t-time<sum)
    {
      printf("No");
      return 0;
    }
    else
    {
      if((t-time-sum)%2==0)
      {
        time=t;
        posx=a;
        posy=b;
      }
      else
      {
        printf("No");
        return 0;
      }
    }
  }
  printf("Yes");
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 3005
using namespace std;
typedef long long ll;
ll dp[maxn][maxn];
ll a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++) dp[i][i] = a[i];
    for(int i=2;i<=n;i++)
    {
        for(int j=1;i+j-1<=n;j++)
        {
            dp[j][i+j-1]=max(a[j]-dp[j+1][i+j-1],-dp[j][i+j-2]+a[i+j-1]);
        }
    }
    printf("%lld\n",dp[1][n]);

}


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

int main()
{
    string s;
    cin >> s;
    bool bus = true;
    if (s == "AAA")
        bus = false;
    if (s == "BBB")
        bus = false;
    if (bus)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n,k,a[N],b[N];

int main(){
	n=read(),k=read();
	For(i,1,n) a[i]=read();
	For(i,1,min(200,k)){
		For(j,1,n) b[j]=0;
		For(j,1,n){
			int l=max(1,j-a[j]),r=min(n,j+a[j]);
			b[l]++,b[r+1]--;
		}
		For(j,1,n) b[j]+=b[j-1],a[j]=b[j];
	}
	For(i,1,n) printf("%d ",a[i]);
}

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

long long gcd(long x, long y)
{
    if (y == 0)
        return x;

    return gcd(y, x % y);
}
long long lcm(long x, long y)
{
    return x * y / gcd(x, y);
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

int main()
{
    long long A,B,X,ans=0,a,b;
    cin>>A>>B>>X;

    a=(A-1)/X +1;
    b=B/X +1;

    if(A==0)a=0;

    cout<< b - a <<endl;

    return 0;
}

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

def main():
    r,g,b = map(int, input().split())
    k = int(input())
    
    for i in range(k):
        for j in range(k):
            if i+j > k:
                continue
            if r*2**i < g*2**j < b*2**(k-i-j):
                print('Yes')
                return
    print('No')
    
main()

Measured memory_bytes: 9120
package main

import (
	"fmt"
	"math"
)

func main() {
	var d, g int
	fmt.Scan(&d, &g)
	problems := make([]Problem, d)
	for i := 0; i < d; i++ {
		var count, bonus int
		fmt.Scan(&count, &bonus)
		problems[i] = Problem{count, (i + 1) * 100, bonus}
	}
	mn := math.MaxInt32
	for i := 0; i < 1 << uint(d); i++ {
		current, count := 0, 0
		noneCompletes := make([]Problem, 0)
		for j := 0; j < d; j++ {
			if 1 & (uint(i) >> uint(j)) == 1 {
				current += problems[j].CompletePoint()
				count += problems[j].Count
			} else {
				noneCompletes = append(noneCompletes, problems[j])
			}
		}
		for j := len(noneCompletes) - 1; j >= 0; j-- {
			if current >= g {
				break
			}
			p := noneCompletes[j]
			for k := 0; k < p.Count; k++ {
				current += p.Point
				count++
				if current >= g {
					break
				}
			}
		}
		if current >= g && count < mn {
			mn = count
		}
	}
	fmt.Println(mn)
}

type Problem struct {
	Count int
	Point int
	Bonus int
}

func (p *Problem) CompletePoint() int {
	return p.Count * p.Point + p.Bonus
}

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



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

    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int now = -2;
    ll ans = 0;
    vector<vector<int>> v(26);
    bool used[26]={};
    for(int i=0;i<n;i++){
        used[s[i]-'a']=1;
        v[s[i]-'a'].push_back(i);
    }
    for(int i=0;i<m;i++){
        if(!used[t[i]-'a']){
            cout<<-1<<endl;
            return 0;
        }
        int p = t[i] - 'a';
        auto itr = upper_bound(v[p].begin(),v[p].end(),now);
        //cerr<<i<<" "<<*itr<<endl;
        if(itr == v[p].end()){
            //cerr<<*itr<<endl;
            now = v[p][0];
            ans ++;
        }
        else now = *itr;
    }
    ans *= n;
    ans += now+1;
    cout<<ans<<endl;
    

}

Measured memory_bytes: 1228
import java.util.*;
public class Main{
  
 public static void main(String[] args){
      Scanner obj=new Scanner(System.in);
     ArrayList<Integer> a=new ArrayList<>();
       
          for(int i=0;i<3;i++){
               a.add(obj.nextInt());
         }
Collections.sort(a);
int sum=a.get(0)+a.get(1);
System.out.println(sum);
        



      }
}

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

bool check(vector<P> s) {
  int sum = 0;
  for (P p : s) {
    if (sum + p.first < 0) {
      return false;
    } else {
      sum += p.second;
    }
  }
  return true;
}

int main() {
  int n; cin >> n;
  vector<P> ls, rs;
  int sum = 0;

  rep(i,n) {
    string s; cin >> s;
    int b = 0, h = 0;
    for (char c : s) {
      if (c == '(') h++; else h--;
      b = min(h,b);
    }
    if (h > 0) ls.emplace_back(b,h);
    else rs.emplace_back(b-h,-h);
    sum += h;
  }

  sort(ls.rbegin(), ls.rend());
  sort(rs.rbegin(), rs.rend());

  if (sum == 0 && check(ls) && check(rs)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 18924
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(0),cin.tie(0);
int main(void)
{
	AC;
	long long int x[100005];
	set<long long> s;
	priority_queue<long long int> pq;
	int T,n,i;
	long long a;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		if(s.count(a)) pq.push(a), s.erase(a);
		else s.insert(a);
	}
	if(pq.size()>=2){
		a=pq.top();
		pq.pop();
		cout<<pq.top()*a<<"\n";
	}
	else cout<<0<<"\n";
}




Measured memory_bytes: 4992
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int H,N,sum=0;
  cin >> H >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int j=0;j<N;j++){
    sum=sum+A[j];
  }
  if(H > sum){
    cout << "No"<< endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
// ref. https://atcoder.jp/contests/arc089/submissions/2001908

#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

ll n, K;
vector<vector<ll>> mat;

// return the sum of [x, x2), [y, y2)
ll getSum(ll x, ll y, ll x2, ll y2) {
  return mat[x2][y2] + mat[x][y] - mat[x2][y] - mat[x][y2];
}

// (x,y) .. point of left-bottom
ll solve(ll x, ll y) {
  if (x <= K) {
    // left -> right
    return getSum(0, 0, x, y) + getSum(x, y, x+K, K) + getSum(x+K, 0, 2*K, y);
  } else {
    // right -> left
    return getSum(x, y, 2*K, K) + getSum(x-K, 0, x, y) + getSum(0, y, x-K, K);
  }
}

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

  cin >> n >> K;
  mat.assign(2*K+1, vector<ll>(K+1));
  rep(i, n) {
    ll x, y;
    char c;
    cin >> x >> y >> c;
    if (c == 'W') {
      y += K; // covert to black
    }
    x %= 2*K;
    y %= 2*K;
    if (y >= K) {
      x += K;
      y -= K;
    }
    x %= 2*K;
    // Here, y < K
    ++mat[x+1][y+1];
  }
  // mat[x+1][y+1] .. the count of black at (x, y)

  // Here, we calculate the cummulative sum
  rep(x, 2*K) rep(y, K) {
    mat[x+1][y+1] += mat[x][y+1] + mat[x+1][y] - mat[x][y];
  }
  // mat[x][y] .. the cummulative sum of [0, x), [0, y) in x<K, y<K

  ll ans = 0;
  rep(x, 2*K) rep(y, K) {
    ans = max(ans, solve(x, y));
  }
  cout << ans << endl;
}


Measured memory_bytes: 16000
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int a, b;
  readf("%s %s\n", &a, &b);
  auto f = true;
  foreach (k; min(a, b)..max(a, b) + 1) {
    if (abs(a - k) == abs(b - k)) {
      k.writeln;
      f = false;
      break;
    }
  }
  if (f) {
    writeln("IMPOSSIBLE");
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  Int Q = lin();
  Int H = lin();
  Int S = lin();
  Int D = lin();

  S = min(S, min(4 * Q, 2 * H));
  D = min(D, 2 * S);

  Int N = lin();
  printf("%lld\n", (N / 2) * D + (N % 2) * S);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
int main(void){
    // Your code here!
 int i,n,x,y;
 cin >> n;
 vector<int> v;
 while(n--)
 {
  cin >> x >> y;
  v.pb(x==y);
 }
 n=v.size();
 for(i=0;i<(n-2);i++)
 {
  if(v[i] && v[i+1] && v[i+2])
  {
   cout << "Yes";
   return 0;
  }
 }
 cout << "No";
 return 0;
}

Measured memory_bytes: 3628
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
ll gcd(ll a,ll b);
ll lcm(ll a,ll b);
ll modularExponentiation(ll x,ll n,ll M);
ll binpow(ll x,ll n);
void dsp(vector<ll> &V);
void dsp2(vector<pair<ll,ll>>&V);
void dsp3(map<ll,ll>&M);
double fact(double n);
ll nPr(ll n,ll r);
ll nCr(ll n,ll r);
void solve()
{
    ll n,m,t,i,sum=0;cin>>n>>m;
    vi A;
    fo(i,0,n)
    {cin>>t;A.pb(t);sum+=t;}
    
    ll cnt=0;
    fo(i,0,n)
    {
       if(A[i]>=(ceil((ld(sum))/(4*m))))cnt++; 
    }
    if(cnt>=m)cout<<"Yes\n";
    else cout<<"No\n";
}
int main()
{

   fastio
   //Test_cases
   solve();
  return 0;
}
ll gcd(ll a,ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
          
} 
ll lcm(ll a,ll b)  
{  
    return (a*b)/gcd(a, b);  
}  
ll modularExponentiation(ll x,ll n,ll M)
{   
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
        return result;
}
ll binpow(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n&1)res=res*x;
         x=x*x;
         n>>=1;
    }
    return res;
}
void dsp(vector<ll> &V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j]<<" ";
    }
    cout<<endl;
}
void dsp2(vector<pair<ll,ll>>&V)
{
    ull j;
    for(j=0;j<V.size();j++)
    {
        cout<<V[j].first<<" "<<V[j].second<<" ";
    }
    cout<<endl;
}
void dsp3(map<ll,ll>&M)
{
      map<ll,ll>::iterator it=M.begin();
      while(it!=M.end())
      {
        cout<<it->first<<" "<<it->second<<endl;
        it++;
      }
}
double fact(double n)
{
    double i=1;
    double res=1;
    
    if(n==0)
        return 1.00;
    
    while(i<=n)
    {
        res*=i;
        i++;
    }
    
    return res;
}
ll nPr(ll n,ll r)
{
    return (fact(n)/fact(n-r));
}
ll nCr(ll n,ll r)
{
    return (fact(n)/(fact(r)*fact(n-r)));
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>

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

int main() {
  int n,k; string s;
  cin >> n >> k >> s;
  int p = 0;
  rep(i,0,n-1) {
    if (s[i] != s[i+1]) {
      p++;
    }
  }
  p = max(0, p-2*k);
  cout << n-p-1 << endl;
  return 0;
}


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

using namespace std;

#define int long long

signed main()
{
    int a, b; cin >> a >> b;

    int mi = 9e18;

    if ((a >= 0 && b >= 0) || (a < 0 && b <= 0)) {
        if (a < b) {
            mi = min(mi, b - a);
        } else if (a > b) {
            mi = min(mi, 1 + (a - b) + 1);
            if (b == 0) mi--;
        }
    } else {
        if (-a <= b) mi = min(mi, 1 + (b + a));
        else mi = min(mi, (-a - b) + 1);
    }

    cout << mi << endl;
}


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

int main() {
	// your code goes here
	int x;
	cin>>x;
	int n=360;
	int ans=0;
	while(1){
	if(n%x==0){
		ans=ans+n/x;
		cout<<ans;
		break;
	}
	else{
		ans=ans+n/x;
		n=360+n%x;
		
	}
	}
	return 0;
}

Measured memory_bytes: 3572
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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

	final long m = (long) 1e9 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			--A[i];
		}
		int sz = 0;
		for (int i = 0; i < N; ++i) {
			if (A[i] == sz)
				++sz;
		}
		int ans = N - sz;
		if (ans == N)
			ans = -1;
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 84900
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string k;
   cin >> k;
   long sum = 0;
   for(int i = 0 ; i < k.size() ;i++)
   {
       sum += k[i] -'0';
   }
   if(sum%9 == 0)
   {
       cout << "Yes";
   } else{
       cout <<"No";
   }

}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define ll long long int 
#define endl '\n'
#define INF 1000000000
#define MOD 1000000007
#define MAX 200001 
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll ans=0,n=s.length();
    for(int i=0;i<n;i++)
    {
    	int g=s[i]-'0';
    	ans+=g;
    }
    if(ans%9==0)
    {
    	cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <string>

using namespace std;

int n, m;
string s, t;

int gcd(int a, int b) {
	if (a%b == 0)
		return b;

	return gcd(b, a%b);
}

int main() {

	cin >> n >> m;
	cin >> s >> t;

	long long len = n;
	len = len * m;

	int g = gcd(n, m);

	len /= g;

	int a = len/n, b = len/m;

	bool flag = true;
	int idx1 = 0, idx2 = 0, count1 = 0, count2 = 0;
	while (count1 < n && count2 < m) {
		if (idx1 == idx2)
		{
			if (s[count1] != t[count2])
			{
				flag = false;
				break;
			}

			idx1 += a;
			idx2 += b;

			++count1;
			++count2;
		} else 
			if (idx1 < idx2)
			{
				idx1 += a;
				++count1;
			}
			else
			{
				idx2 += b;
				++count2;
			}
	}

	if (flag)
		cout << len << endl;
	else
		cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 640
read N M C
read B

for i in $(seq $N); do
    read A
    SUM=$C
    while read X <&3 && read Y <&4; do
        SUM=$(($SUM+$X*$Y))
    done 3<<<"$(echo $A | tr ' ' '\n')" 4<<<"$(echo $B | tr ' ' '\n')"
    if [ $SUM -gt 0 ]; then
        echo OK
    fi
done | wc -l


Measured memory_bytes: 1052
#include <iostream>
#include <stdio.h>
#define MAX_INPUT 250

using namespace std;

int H[MAX_INPUT+1];
int n;//num of input

int main(){
	int tmp;

	scanf("%d",&n);

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

	for(int i=0;i<n;i++){
		printf("node %d: key = %d, ",(i+1),H[i]);

		if((int)(i+1)/2 > 0) printf("parent key = %d, ",H[(int)(i+1)/2-1]);
		if(2*(i+1) <= n) printf("left key = %d, ",H[2*(i+1)-1]);
		if(2*(i+1)+1 <= n) printf("right key = %d, ",H[2*(i+1)+1-1]);
		printf("\n");
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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 EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector <ll> Size;

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1);
        rank.resize(n + 1);
        Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x) {
        return Size[root(x)];
    }
};

int N, M, K;
int A[100001], B[100001], C[100001], D[100001];
int ans[100001];

void input() {
    cin >> N >> M >> K;
    for (int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i];
    }
    for (int i = 0; i < K; ++i) {
        cin >> C[i] >> D[i];
    }
}

void solve() {
    UnionFind uni(N+1);
    for (int i = 1; i <= N; ++i) ans[i] = 0;
    for (int i = 0; i < M; ++i) uni.merge(A[i], B[i]);
    for (int i = 1; i <= N; ++i) ans[i] = uni.size(uni.root(i)) - 1;
    for (int i = 0; i < M; ++i) {
        ans[A[i]]--;
        ans[B[i]]--;
    }
    for (int i = 0; i < K; ++i) {
        if (!uni.issame(C[i], D[i])) continue;
        ans[C[i]]--;
        ans[D[i]]--;
    }
    for (int i = 1; i <= N; ++i) {
        if (i != 1) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return;
}

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

Measured memory_bytes: 4352
n = gets.chomp.to_i

if n == 111
  puts 999
elsif n == 119
  puts 991
elsif n == 199
  puts 911
elsif n == 191
  puts 919
elsif n == 999
  puts 111
elsif n == 991
  puts 119
elsif n == 911
  puts 199
elsif n == 919
  puts 191
end

Measured memory_bytes: 1788
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans,n,sum,maxi;
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        ll a;cin>>a;
        maxi=max(a,maxi);   sum+=a;
    }
    cout<<sum-maxi/2<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
    int n;
    cin >> n;
    vector<int> b(n - 1);
    REP(i, n - 1)
    cin >> b[i];
    vector<int> a(n);
    for (int i = 0; i < b.size(); i++)
    {
        if (i == 0)
        {
            a[i] = b[i];
            a[i + 1] = b[i];
        }
        else
        {
            if (a[i] > b[i])
            {
                a[i] = b[i];
                a[i + 1] = b[i];
            }
            else
            {
                a[i + 1] = b[i];
            }
        }
    }

    cout << accumulate(ALL(a), 0) << endl;
}

int main()
{
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int MAX=5e5+10;
const double eps=1e-4;
const int mod=1e9+7;
#define INF 0x7fffffff
#define ll long long
#define edl putchar('\n')
#define useit  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mst(a) memset(a,0,sizeof(a))
#define mstn(a,n) memset(a,n,sizeof(a))
//struct point{int v,l;}a[MAX];
//double cross(point a,point b){return (a.x*b.y-a.y*b.x);}
//double dot(point a,point b){return (a.x*b.x+a.y*b.y);}

int main()
{
	int n,m,ans;
	{
		cin>>n>>m;
		ans=m*1900+(n-m)*100;
		cout<<ans*pow(2,m)<<endl;
	}
	
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List

readInts = map read . words <$> getLine :: IO [Int]

solve hs = sub 0 0 hs
  where
    sub r _ [] = r
    sub r t (x:xs) = sub (if x>=t then r+1 else r) (max t x) xs

main = getLine >> map read . words <$> getLine >>= print . solve


Measured memory_bytes: 508
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	a, b, c, d = map(int, sys.stdin.readline().split())
	turn = 1
	while (a > 0 and c > 0):
		if turn:
			c -= b
		else:
			a -= d
		turn = not turn
	if a <= 0:
		print("No")
	else:
		print("Yes")
	


main()

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, m; read(n, m);
	vector<pair<int, int>> v;
	rep(i, 0, n) { int t; read(t); v.push_back({t, 1}); }
	rep(i, 0, m) { int t; read(t); v.push_back({t, 2}); }
	sort(all(v));
	int a = m + 1, b = n + 1;
	ll ans = 0;
	rep(i, 0, n + m) {
		if (v[i].second == 1) ans += 1ll * v[i].first * a, --b;
		else ans += 1ll * v[i].first * b, --a;
	}
	write(ans);
}


Measured memory_bytes: 5284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(15);
vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	int a,p;
	cin >> a >> p;
	cout << (a*3+p)/2 << endl;
}

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

int main()
{
    int N;
    vector<int> A;
    scanf("%d", &N);
    int tmp;
    for (int i = 0; i < N; i++) {
        scanf("%d", &tmp);
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());
    printf("%d\n", A.at(N - 1) - A.at(0));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k;
	cin>>n>>k;
	string s="";
	while(n)
	{
		s+=to_string(n%k);
		n/=k;
	}
	cout<<s.length();
	return 0;
}

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

int main() {
  int n, a = 0, b = 0, ans, x;
  cin >> n;
  vector<int> card(n);
  for (int i = 0; i < n; i++) {
    cin >> x;
    card.at(i) = x;
  }
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) a += card.at(i);
    else b += card.at(i);
  }
  ans = a - b;
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N, A, B, C;
int l[10];
vector<int> p;

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

	cin >> N >> A >> B >> C;

	for (int i = 0;i < N;i++){
		cin >> l[i];
	}

	for (int i = 0;i < N;i++){
		p.push_back(i);
	}

	int ans = INT_MAX;

	do{
		for (int i = 1;i <= N-2;i++){
			for (int j = i+1;j <= N-1;j++){
				for (int k = j+1;k <= N;k++){
					int mp = 0;
					int itr = 0;
					int sum = 0;
					for (;itr <= N;itr++){
						if(itr == i){
							mp += abs(sum-A)+10*(i-1);
							sum = 0;
						}
						if(itr == j){
							mp += abs(sum-B)+10*(j-i-1);
							sum = 0;
						}
						if(itr == k){
							mp += abs(sum-C)+10*(k-j-1);
							break;
						}
						sum += l[p[itr]];
					}
					ans = min(mp,ans);
				}
			}
		}
	}while(next_permutation(p.begin(),p.end()));

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=105;
char s[N];int las[26],mx[26],n,res;
int main(){
	scanf("%s",s+1),n=strlen(s+1),res=n;
	fp(i,1,n)s[i]-='a';
	fp(i,1,n)cmax(mx[s[i]],i-las[s[i]]-1),las[s[i]]=i;
	fp(i,0,25)cmax(mx[i],n-las[i]),cmin(res,mx[i]);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc134
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e6 + 5;
const double E = 1e-9;

//------------------------------------------------------------------------------

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/
	int n, d;
	cin >> n >> d;
	int sum = d * 2 + 1;
	if (n % sum)
		cout << (n / sum) + 1;
	else
		cout << (n / sum);
	return 0;
}
//04-08-2020 09:45:52
//------------------------------------------------------------------------------

Measured memory_bytes: 3648
N, K = map(int, input().split())
h_list = []

for _ in range(N):
    h_list.append(int(input()))

h_list.sort()
answer = h_list[N-1] - h_list[0]

for i in range(N-K+1):
    a = h_list[i+K-1] - h_list[i]
    answer = min(a,answer)

print(answer)

Measured memory_bytes: 7384
table = zip "0123456789" ["* = ****",
                          "* =* ***",
                          "* =** **",
                          "* =*** *",
                          "* =**** ",
                          " *= ****",
                          " *=* ***",
                          " *=** **",
                          " *=*** *",
                          " *=**** "]
main :: IO ()
main = do
  ls <- getContents
  let ls' = map to5 . lines $ ls
      ansL = map solve ls'
  loopPut ansL

loopPut :: [[String]] -> IO ()
loopPut l = do
  mapM_ putStrLn (head l)
  if (tail l) == []
    then return ()
    else do
      putStrLn ""
      loopPut (tail l)

to5 :: String -> String
to5 xs = (replicate (5- (length xs)) '0') ++ xs

solve :: String -> [String]
solve xs = spin $ deform xs
  where
    spin :: [String] -> [String]
    spin [[],[],[],[],[]] = []
    spin [(a:as),(b:bs),(c:cs),(d:ds),(e:es)] = [a,b,c,d,e]:(spin [as,bs,cs,ds,es])

    deform :: String -> [String]
    deform = map toA
      where
        toA :: Char -> String
        toA x = toA' x table
          where
            toA' :: Char -> [(Char,String)] -> String
            toA' x ((a,b):r)
              | x == a = b
              | otherwise = toA' x r

Measured memory_bytes: 4180
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

struct Event{
    ll time;
    ll sign;
    ll position;
};

bool comp(const Event& e1, const Event& e2){
    if(e1.time == e2.time){
        if(e1.position == e2.position) return e1.sign < e2.sign;
        return e1.position < e2.position;
    }
  	return e1.time < e2.time;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, q;
    cin >> n >> q;
    vector<Event> v;
    REP(i, n){
        ll s, t, x;
        cin >> s >> t >> x;
        v.push_back(Event{s - x, 1, x});
        v.push_back(Event{t - x, -1, x});
    }
    sort(v.begin(), v.end(), comp);

    // stops : 各 Event 発生時における暫定通行止めリスト
    // ngpoint : stops の最小値(stops が空なら -1)
    set<ll> stops;
    vll ngpoint(2 * n, -1);
    REP(i, 2 * n){
        if(v[i].sign > 0){
            stops.insert(v[i].position);
            ngpoint[i] = *stops.begin();
        }
        else{
            stops.erase(v[i].position);
            if(stops.empty()) ngpoint[i] = -1;
            else ngpoint[i] = *stops.begin();
        }
    }
    ll d;
    REP(i, q){
        cin >> d;
        if(d < v[0].time || d >= v[2 * n - 1].time){
            cout << -1 << endl;
        }
        else{
            //時刻 d 直前の ngpoint を求める
            //時刻 d のイベントまで消化するので limit を良い感じにとる
            Event limit = Event{d, 10, (ll)1e10};
            ll k = upper_bound(v.begin(), v.end(), limit, comp) - v.begin();
            cout << ngpoint[k - 1] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 23528
import java.util.Scanner;

//Night Market
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), T = sc.nextInt(), S = sc.nextInt();
		int[] a = new int[n], b = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt(); b[i] = sc.nextInt();
		}
		int[][] dp = new int[n][T+1];
		for(int j=b[0];j<=T;j++){
			dp[0][j] = dp[0][j-1];
			if(!(j-b[0]<S&&S<j))dp[0][j] = a[0];
		}
		for(int i=1;i<n;i++)for(int t=1;t<=T;t++){
			dp[i][t] = Math.max(dp[i-1][t], dp[i][t-1]);
			if(b[i]<=t&&!(t-b[i]<S&&S<t))dp[i][t] = Math.max(dp[i][t], dp[i-1][t-b[i]]+a[i]);
		}
		System.out.println(dp[n-1][T]);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-7
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using ti = tuple<int,int,int,int>;

int n, m, q;
vector<ti> quad;
vector<ll> vec;
ll ans = 0;

void solve(int ind, int last = 1) {
    if(last>m) return ;
    if(ind>n) return ;
    if(ind==n) {
        ll cur = 0;
        for(int i = 0; i<quad.size(); ++i) {
            ll d,a,b,c;
            tie(d,a,b,c) = quad[i];
            if(vec[b-1]-vec[a-1]==c)
                cur += d;
        }
        ans = max(ans, cur);
    }

    for(int j = last; j<=m; ++j) {
        vec.push_back(j);
        solve(ind+1, j);
        vec.pop_back();
    }
}

int32_t main() {
    fastio
    cin>>n>>m>>q;
    quad.assign(q, ti());
    for(int i = 0; i<q; ++i) {
        int a, b, c, d;
        cin>>a>>b>>c>>d;
        quad[i] = make_tuple(d, a, b, c);
    }

    solve(0);
    
    cout<<ans<<endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <bits/c++io.h>
#include <vector>
#include <tuple>
#include <queue>
#define N 100
#define INF 1e9 + 5
using namespace std;

#include <iostream>
#include <bits/c++io.h>
#include <vector>
#include <tuple>
#include <queue>
#define N 100
#define INF 1e9 + 5
using namespace std;
 
int solve(int k, vector<int> &c,vector<int> &dp){
    
    if(k==1){
        return 0;
    }
    if(k<1){
        return INF;
    }
    if(dp[k]!=-1) return dp[k];
    
    return dp[k] = min( solve(k-1,c,dp)+abs(c[k]-c[k-1]), solve(k-2,c,dp)+abs(c[k]-c[k-2]));
}
//20          10
//10 30     20

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> c(n+1);
    vector<int> dp(n+1,-1);
    for (int i=1;i<=n;i++){
        scanf("%d", &c[i]);
    }
    //재귀로 풀어봅시다. 
    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 
    dp[0]=INF;
    printf("%d",solve(n, c, dp));
    //선형으로 풀어봅시다.
    // dp[0]=0; 
    // for(int i =0;i<n;i++){
    //     for(auto j:{i+1,i+2}){
    //         dp[j] = min( dp[j], dp[i]+abs(v[j]-v[i]) );
    //     }
    // }
    // cout<<dp[n-1];

    return 0;
}


Measured memory_bytes: 4864