akhauriyash/Code-Regression huggingface dataset:
from sys import stdin, stdout, stderr

mod = 10**9 + 7

def solve():
    def binom(n, k):
        res = (modfact[n] * factinv[k]) % mod
        res = (res * factinv[n - k]) % mod
        return res

    h, w, a, b = map(int, input().split())
    ans = 0
    modfact = [1] * (h + w)
    factinv = [1] * (h + w)
    inv = [1] * (h + w)

    for i in range(2, h + w):
        modfact[i] = (i * modfact[i - 1]) % mod

    factinv[h + w - 1] = pow(modfact[h + w - 1], mod - 2, mod)

    for i in range(h + w - 2, 0, -1):
        factinv[i] = (factinv[i + 1] * (i + 1)) % mod

    for i in range(h - a):
        ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 20340
ac,tle,wa,re=0,0,0,0
for _ in range(int(input())):
  s = input()
  if(s=="AC"):
    ac+=1
  elif s=="WA":
    wa+=1
  elif s=="TLE":
    tle+=1
  else:
    re+=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int A[N];
  int max1 = 0;
  int max2 = 0;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (max1 < A[i]) {
      max1 = A[i];
    } else if (max2 < A[i]) {
      max2 = A[i];
    }
  }

  for (int i = 0; i < N; i++) {
    if (max1 == A[i]) {
      cout << max2 << endl;
    } else {
      cout << max1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <deque>
#include <iostream>
#include <vector>

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

int N, K;
VI H;

int main() {
    LL ans = 0;
    cin >> N >> K;
    REP(i, N) {
        int tmp;
        cin >> tmp;
        H.push_back(tmp);
    }
    sort(H.begin(), H.end(), greater<int>());
    REP(i, N) {
        if (i < K) {
            // ans++;
        }
        else {
            ans += H[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>

using namespace std;

int main() {
    long long int N, M;
    cin >> N >> M;
    
    if(N>=2 && M>=2) {
        cout << (N-2)*(M-2) << endl;
    } else if(N==1 && M==1) {
        cout << 1 << endl;
    } else {
        if(N==1) {
            cout << M-2 << endl;
        } else {
            cout << N-2 << endl;
        }
    }

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL h,w;
  cin >> h >> w;
  vector<string> fi(h);
  for(auto &s:fi) cin >> s;
  vector<vector<int>> c(h,vector<int>(w, 0)), r(h,vector<int>(w,0));
  REP(i, h) REP(j, w) {
    if(fi[i][j] == '.') {
      int pre = 0;
      if(i) pre = c[i-1][j];
      c[i][j] = pre + 1;
      pre = 0;
      if(j) pre = r[i][j-1];
      r[i][j] = pre + 1;
    }
  }
  for(LL i = h-1;i >= 0; --i) for(LL j = w-1;j >= 0; --j) {
      if(fi[i][j] == '.') {
        if(i!=h-1) c[i][j] = max(c[i][j], c[i+1][j]);
        if(j!=w-1) r[i][j] = max(r[i][j], r[i][j+1]);
    }
  }
  int answer = 0;
  REP(i,h) REP(j,w) answer = max(answer, c[i][j] + r[i][j] - 1);
  cout << answer << endl;
  return 0;
}


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

int main()
{
  int64_t N;
  cin >> N;
  int64_t S[1000010];
  S[0] = 0;
  for (int i = 1; i <= 1000000; i++)
  {
    if (i % 3 == 0 || i % 5 == 0)
      S[i] = S[i - 1];
    else
      S[i] = S[i - 1] + i;
  }
  cout << S[N] << endl;
}

Measured memory_bytes: 11452
#include <cstdio>

typedef long long ll;

int main()
{
    // freopen("a.in", "r", stdin);

    ll h, w; scanf("%lld%lld", &h, &w);
    if(h == 1 || w == 1) printf("1\n");
    else printf("%lld\n", (h * w + 1LL) / 2);
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

const int MAX_V=100005;

struct edge{int to; ll cost;};
typedef pair<ll,int> P;

vector<vector<edge>> G(MAX_V);
vector<ll> d(MAX_V);

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d.begin(),d.end(),INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    int N, M; cin >> N >> M;
    string s; cin >> s;
    FOR(i,1,N+1) G[i-1].push_back((edge){i,0LL});
  FOR(i,1,M+1){
  	if(i<N+1 && s[i]!='1') G[i].push_back((edge){0,1LL});
  }
    REP(i,N){
        if (i+M<N+1 && s[i+M]!='1'){
            G[i+M].push_back((edge){i,1LL});
        }
    }
    dijkstra(N);
  //REP(i,N+1) cout << d[i] << " ";cout << endl;
    if (d[0]==INF) cout << -1 << endl;
    else{
        vector<int> res;
        int cnt=0;
        ll dist = d[0];
        REP(i,N+1) {
            if (d[i]==dist-1 && s[i]!='1'){
                res.push_back(cnt);
                dist--;
                cnt=0;
            }
          cnt++;
        }
        REP(i,res.size()){
            if(i) cout << " ";
            cout << res[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 9132
/*    BAJUKA     */
#include<bits/stdc++.h>
#define lld long long int
#define ve vector
#include<ios>
#define rep(i,a,b) for(i=a;i<b;i++) 
#define per(i,a,b) for(i=b;i>=a;i--)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define Max 10000000000000000
#define M 1000000007
using namespace std;




int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
    lld a,b,c;
    cin>>a>>b;
    if((a*b)%2==1 || (a*b*2)%2==1 ||(a*b*3)%2==1)
    	cout<<"Yes";
    else
    	cout<<"No";


	return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    A[i] -= i;
  }

  sort(ALL(A));

  int ans = 0;
  REP(i, N){
    ans += abs(A[i]-A[N/2]);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <unistd.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#define PI 3.14159265358979323846

using namespace std;

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

	cin >> N >> S >> K;

	for(int i=0;i<N;i++)
	{
		if(S[i]!=S[K-1])
			S[i]='*';
	}
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int A[24][24];
int get_bit(int x,int v){return (x>>v)&1;}
int main(){
    int N,M,X;
    R(N,M,X);
    VI C(N);
    REP(i,N){
        R(C[i]);
        REP(j,M)R(A[i][j]);
    }
    int mi=2e9;
    REP(i,1<<N){
        VI now(M);
        int need=0;
        REP(j,N){
            if(get_bit(i,j)){
                need+=C[j];
                REP(k,M)now[k]+=A[j][k];
            }
        }
        bool suc=1;
        REP(j,M)
            if(now[j]<X){
                suc=0;
            }
        if(suc)mi=min(mi,need);
    }
    if(mi>1e9)W(-1);
    else W(mi);
    return 0;
}


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

int main()
{
   int N;
   scanf("%d",&N);
   int n[10001]={0};
   int x,y,z;
   for(x=1;x<N-3;x++){
    for(y=1;y<N-(x*x)-x;y++){
        for(z=1;z<N-(x*x)-(y*y)-(x*y);z++){
            int sum=(x*x)+(y*y)+(z*z)+(x*y)+(x*z)+(y*z);
            if(sum>N)
                break;
            else
                n[sum]++;
        }
    }
   }
   for(int i=1;i<=N;i++){
    printf("%d\n",n[i]);
   }
    return 0;
}

Measured memory_bytes: 1764
#include<bits/stdc++.h>
#include<algorithm>
 
#define  pb push_back
#define  mp make_pair
#define ll long long
#define vi vector<ll>
#define ff first
#define ss second
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORR(i,a,b) for(ll i=a-1;i>b;i--)
#define MOD 10e9+7
#define fastScan ios_base::sync_with_stdio(0); cin.tie(NULL)
#define s(v) sort(v.begin(),v.end())

 
using namespace std;
 
//vector<bool> s(1000000,true);

//vector<ll> a;
 
/*void prime(){
    FORor(ll i=2;i<1000000;i++){
        if(s[i] == true) a.pb((ll)i);
        ll j=2*i;
        while(j<1000000){
            if(s[j]!=FORalse) s[j]=FORalse;
            j+=i;
        }
    }
}
ll bs(ll s, ll l,ll h){
    ll m;
    while(l<=h){
        m = (l+h)>>1;
        if(a[m] < s) l= m+1;
        else h = m-1;
    }
    return l;
}
 
bool isprime(ll s, ll l,ll h){
    ll m;
    while(l<=h){
        m = (l+h)>>1;
        if(a[m]==s)return true;
        if(a[m] < s) l= m+1;
        else h = m-1;
    }
    return FORalse;
}
 
bool comp(pair<ll,ll> a, pair<ll,ll> b) {
    if(a.FORirst == b.FORirst)  return a.second<b.second;
    else return a.FORirst < b.FORirst;
}
 
ll FORact(ll n){
    if(n==1) return 1;
    else return n*FORact(n-1);
}

ll gcd(ll a,ll b){
    if(a==0)return b;
    return (b%a,a);
}*/

void solve(){
   ll n,k;
   cin >> n >> k;
   vector<ll> a(n),dp(n);
    for(ll i=0;i<n;i++)cin >> a[i];
    
    dp[0] = 0;
    for(ll i=1;i<n;i++){
        dp[i]=1e18;
        for(ll j=1;j<=k;j++){
            if(i-j < 0) break;
            else{
                dp[i] = min(dp[i] , dp[i-j] + abs(a[i] - a[i-j]));
            }
        }
    }
    cout << dp[n-1]<<endl;
    return;
}
 
int main(){
    fastScan;
    ll T=1;
    //cin >> T;
    while(T--){
        solve();
    }
    
    return 0;
}  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int A, B;
	cin >> A >> B;
	int ans = A * B - A - B + 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type ll int64


func main() {

	var N,K int
	fmt.Scan(&N,&K)

	slice := make([]int,N)

	for i:= 0;i < N  ;i++  {
		fmt.Scan(&slice[i])
	}

	//sort
	sort.Sort(sort.IntSlice(slice))

	//out

	var ans_min int = 10e9
	var buf int = 0

	for i:=0;i<N-K+1 ;i++  {
		buf = slice[K+i-1] - slice[i]
		if buf < ans_min {
			ans_min = buf
		}
	}

	fmt.Println(ans_min)
}

Measured memory_bytes: 7552
#include<iostream>
#include<map>
#include<cstdio>

using namespace std;

int n,ans;
map<string,bool>mp;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        if(!mp[s])
        {
            ans++;
            mp[s]=true;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 18728
import math


def cmb(n,r):
    return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))

def main():
    
    n,k = map(int, input().split())

    c = 10**9+7

    for i in range(k):
        try:
            print(((cmb(k-1,i)*cmb(n - k+1,i+1))%c))
        except:
            print(0)
            
if __name__ == "__main__":
    main()

Measured memory_bytes: 73304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1007;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;
	string s;
	cin>>n;
	list<ll> li;
	FOR(i,0,n){
		cin>>s;
		if(s[0]=='i'){
			cin>>k;
			li.push_front(k);
		}else{
			if(s=="delete"){
				cin>>k;
				for(list<ll>::iterator itr = li.begin(); itr != li.end(); ) {
       				if( *itr == k ){        //  要素が k ならば
            			itr = li.erase(itr);
            			break;
            		}
        			else
           	 			++itr;           // itr をひとつ進める
    			}
			}else{
				if(s[6]=='F')li.pop_front();
				else li.pop_back();
			}
		}
	}
	ll p=0;
	for(list<ll>::iterator itr = li.begin(); itr != li.end(); ){
		if(p==0){
			p++;
			cout<<*itr;
		}else{
			cout<<" "<<*itr;
		}
    	++itr;
    }
    cout<<endl;
}


Measured memory_bytes: 34456
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 100010
int n,T,num,ans,a[N];
int main(){
	scanf("%d%d",&n,&T);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	int mn=a[1];
	for(int i=2;i<=n;++i){
		if(mn<a[i]) ans=max(ans,a[i]-mn);
		mn=min(mn,a[i]); 
	}
	mn=a[1];
	for(int i=2;i<=n;++i){
		if(a[i]-mn==ans) num++;
		mn=min(a[i],mn);
	}
	printf("%d\n",num);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
    #define sz size()
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
    ll n;
    cin >> n;
    vector<P> p(n);
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        p[i] = P(a, b);
    }
    sort(ALL(p));
    cout << p[n - 1].first + p[n - 1].second << endl;
}



Measured memory_bytes: 4388
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] h = new int[n];
        for (int i = 0; i< n; i++){
            h[i] = scanner.nextInt();
        }

        int[] Table = new int[n];
        Table[0] = 0;
        Table[1] = Math.abs(h[0]-h[1]);

        for (int i = 2; i < n; i++){
            int a = Table[i-2] + Math.abs(h[i-2]-h[i]);
            int b = Table[i-1] + Math.abs(h[i-1]-h[i]);
            
            if (a < b){
                Table[i] = a;
            }
            else {
                Table[i] = b;
            }
        }
        System.out.println(Table[n-1]);
    }
}


Measured memory_bytes: 49628
<?php
class main {
    var $word = array();
    var $ans = array();
    function run () {
        fscanf(STDIN, "%d", $n);
        $line = trim(fgets(STDIN));
        $this->word = str_split($line);
        for ($a = 0; $a < 2; $a++) {
            for ($b = 0; $b < 2; $b++) {
                $this->ans[0] = $a;
                $this->ans[1] = $b;
                for ($i = 1; $i <= $n; $i++) {
                    if ($this->word[$i%$n] == "o") {
                        if ($this->ans[$i%$n]) {
                            $this->ans[($i + 1)%$n] = $this->ans[$i - 1];
                        } else {
                            $this->ans[($i + 1)%$n] = !$this->ans[$i - 1];
                        }
                    } else {
                        if ($this->ans[$i%$n]) {
                            $this->ans[($i + 1)%$n] = !$this->ans[$i - 1];
                        } else {
                            $this->ans[($i + 1)%$n] = $this->ans[$i - 1];
                        }
                    }
                }
                if ($this->ans[0] == $a && $this->ans[1] == $b) {
                    foreach ($this->ans as $k => $v) {
                        echo $v?"S":"W";
                    }
                    exit;
                }
            }
        }
        echo "-1";
    }
}

$obj = new main();
$obj->run();

Measured memory_bytes: 33164
cv=lambda r,a,b:chr(((ord(r)-97)*a+b)%26+97) if 97<=ord(r)<=122 else r
cv2=lambda x:cv(x,i,j) if 97<=ord(x)<=122 else cv(x.lower(),i,j).upper()

for _ in range(int(input())):
    l=input()
    for i in [1,3,5,7,9,11,15,17,19,21,23,25]:
        for j in range(1,27):
            s="".join(map(cv2,l))
            if "this" in s or "that" in s:
                break
        if "this" in s or "that" in s:
            break
    print(s)



Measured memory_bytes: 5592
import java.util.Scanner

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    val a: Int = scan.nextInt()
    val b: Int = scan.nextInt()

    if ( a < b ) println("a < b")
    else if ( a > b ) println("a > b")
    else println("a == b")
}



Measured memory_bytes: 25556
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
using namespace std;
using ll=int64_t;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
int main(){
    int h,w,n;
    cin>>h>>w>>n;
    if(n%max(h,w)==0){
        cout<<n/max(h,w)<<endl;
        return 0;
    }
    else{
        cout<<n/max(h,w)+1<<endl;
        return 0;
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001

int main(void) {
	int h,w; cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	vvi cnt(h,vi(w,0));
	rep(i,h){
		vector<bool> done(w,false);
		rep(j,w){
			if( s[i][j]=='#' || done[j] ) continue;
			int l = 0;
			while( j+l<w && s[i][j+l]!='#' )l++;
			rep(k,l){
				cnt[i][j+k] += l;
				done[j+k] = true;
			}
		}
	}
	rep(j,w){
		vector<bool> done(h,false);
		rep(i,h){
			if( s[i][j]=='#' || done[i] ) continue;
			int l = 0;
			while( i+l<h && s[i+l][j]!='#' )l++;
			rep(k,l){
				cnt[i+k][j] += l;
				cnt[i+k][j]--;
				done[i+k] = true;
			}
		}
	}
	int ans = 0;
	rep(i,h)rep(j,w) ans = max(ans,cnt[i][j]);
	cout << ans << endl;
}




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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int n, m;
	sf("%d %d", &n, &m);
	while (m--) {
		int x;
		sf("%d", &x);
		n -= x;
	}
	if (n < 0) puts("-1");
	else printf("%d\n", n);

	return 0;
}


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

int main(){
	int n;
	while(cin >> n){
		if(n == 0) break;
		int field[105][105] = {{0}};
		int w, h;
		cin >> w >> h;
		for(int i = 0; i < n; i++){
			int x, y;
			cin >> x >> y;
			field[y][x] = 1;
		}
		int s, t;
		cin >> s >> t;

		int ans = 0;
		for(int i = 1; i <= w - s + 1; i++){
			for(int j = 1; j <= h - t + 1; j++){
				int count = 0;
				for(int k = 0; k < s; k++){
					for(int l = 0; l < t; l++){
						if(field[j + l][i + k]){
							count++;
						}
					}
				}
				ans = max(ans, count);
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (decltype(k) i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
template <class F>
class fixed_point {
    F f;
public:
    fixed_point(F&& f_) : f(f_) {}
    template <class... Args> auto operator()(Args... args) { return f(f, args...); }
};
template <class F> auto make_fixed_point(F&& f) { return fixed_point<F>(std::forward<F&&>(f)); }

void err() {
    std::cout << "First" << '\n';
    exit(0);
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u32 n; std::cin >> n;
    if (n%2) err();
    vec<vec<u32>> g(n);
    LOOP (n-1) {
        u32 u, v; std::cin >> u >> v; u--, v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }

    vec<u32> a(n);
    make_fixed_point(
        [&](auto&& dfs, u32 x, u32 p) -> bool {
            bool found = false;
            for (u32 y: g.at(x)) if (y!=p) {
                if (dfs(dfs, y, x) && std::exchange(found, true)) err();
            }
            return !found;
        }
    )(0, 0);

    std::cout << "Second" << '\n';
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, p=2, pp=1, x=1;
  cin >> n;
  if (n == 0)
	cout << 2 << endl;
  else if (n == 1)
	cout << 1 << endl;
  else{
	forll(i, 2, n + 1){
	  pp = p;
	  p = x;
	  x = p + pp;
	}
	cout << x << endl;
  }
}

Measured memory_bytes: 256
/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 1e6+7,mod = 1e9+7;
ll frq[N];
int main()
{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);

    ll n,k;cin>>n>>k;
    ll Arr[n+2];
    for(int i=1;i<=n;i++)
        cin>>Arr[i];
    vector<int>pos,neg;
    pos.pb(0);
    for(int i=1;i<=n;i++)
    {
        if( Arr[i]>=0 )
            pos.pb(Arr[i]);
        else
            neg.pb(Arr[i]);
    }
    ll Res = 1e17;
    neg.pb(0);
    reverse(neg.begin(),neg.end());
    int lft = 0;
    ll now = 0;
    for(int i=0;i<neg.size()-1;i++)
    {
        now = abs(neg[i]-neg[i+1]);
        frq[i] = now;
        if(i)frq[i]+=frq[i-1];
    }
    if( neg.size()-1>=k )
    {
        Res = frq[k-1];
    }
    ll tmp = 0;
    while(lft<pos.size()-1)
    {
        tmp += abs(pos[lft]-pos[lft+1]);
        if( lft+1>k )break;
        {
            int rem = k-lft-1;
            if( rem>neg.size()-1 )
            {
                lft++;continue;
            }
            now = frq[rem-1];
        }
        lft++;
        Res = min( Res,min(2*now+tmp,now+2*tmp) );
    }
    cout<<Res<< "\n";












    return 0;
}



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

print(" ".join(str(x) for x in A))


for i in range(1,len(A)):
    v = A[i]
    j = i -1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
        
    A[j+1] = v
    print(" ".join(str(x) for x in A))



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

struct Node{
    int parent = -1;
    int depth;
    vector<int> child;
};

class Tree{
    int root = -1;
    vector<Node> node;
    void calc_root(){
        int i = 0;
        for (int i = 0; ; i++) {
            if (node[i].parent == -1) {
                root = i;
                return;
            }
        }
    }
    void calc_all_depth(int id, int depth){
        node[id].depth = depth;
        for (int i = 0; i < node[id].child.size(); i++) {
            calc_all_depth(node[id].child[i], depth + 1);
        }
    }
public:
    Tree(int n){
        node.resize(n);
    }
    void input_child(int id, int c){
        node[id].child.push_back(c);
        node[c].parent = id;
    }
    void calc_depth(){
        calc_root();
        calc_all_depth(root, 0);
    }
    void print_node(){
        for (int i = 0; i < node.size(); i++) {
            cout << "node " << i << ": parent = " << node[i].parent;
            cout << ", depth = " << node[i].depth << ", ";
            if (node[i].parent == -1) {
                cout << "root";
            } else if (!node[i].child.empty()) {
                cout << "internal node";
            } else {
                cout << "leaf";
            }
            cout << ", [";
            for (int j = 0; j < node[i].child.size(); j++) {
                cout << node[i].child[j];
                cout << (j < node[i].child.size() - 1 ? ", " : "");
            }
            cout << "]" << endl;
        }
    }
};

int main(){
    int n;
    cin >> n;
    Tree T(n);
    for (int i = 0; i < n; i++) {
        int id;
        cin >> id;
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int c;
            cin >> c;
            T.input_child(id, c);
        }
    }
    T.calc_depth();
    T.print_node();
    return 0;
}

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

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

	sort(veclen.begin(), veclen.end());
	int ct = 0;
	for (int i = 0; i < N - 2; ++i)
		for (int j = i + 1; j < N-1; ++j)
		{
			int tmp = veclen[i] + veclen[j];
			auto iter = lower_bound(veclen.begin() + j + 1, veclen.end(), tmp);
			ct += (iter - (veclen.begin() + j + 1));
		}

	cout << ct << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll rem = m - 2 * n;
    if (rem <= 0)
        cout << m / 2;
    else 
        cout << n + rem / 4;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

a = [0] + list(map(int,input().split()))

explored = [0] * (n+1)
t = 1
cycle = 0
while True:
    if explored[t] == 2:
        k %= cycle
        if k == 0:
            k = cycle
        explored[t] += 1
    elif explored[t] == 1:
        explored[t] += 1
        cycle += 1
    elif explored[t] == 0:
        explored[t] += 1

    k -= 1
    if k == 0:
        break
    else:
        t = a[t]
    

print(a[t])

Measured memory_bytes: 32376
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz size()
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

#define ll long long

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

	int n,k;
	cin>>n>>k;

	std::vector<int> a(n);
	int i;
	for (i=0;i<n;i++) cin>>a[i];

	ll lo = 1, hi = *max_element(all(a));

	while (lo<hi) {
		ll mid = lo+(hi-lo)/2;

		ll br=0ll;
		for (i=0;i<n;i++)
		if (a[i]>mid) {
			br += ceil((double)a[i]/mid);
          
			if (br>n+k) {
				break;
			}
		} else
			br++;

		if (br>n+k) {
			lo = mid+1;
		} else
			hi = mid;
	}

	cout<<hi<<"\n";

    return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;//(cost,to)
using vP = vector<P>;
using vvP= vector<vP>;

const int INF = 1001001001;


int main(){
    int n,m;cin>>n;
    
    n %= 1000;
    if(n==0)cout << 0 << endl;
    else cout << 1000-n << endl;
    return 0;
}

Measured memory_bytes: 3620
import sys

A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = -1

for i in range(3):
    for j in range(3):
        if A[i][j] != -1:
            break
    else:
        print('Yes')
        sys.exit(0)

for i in range(3):
    for j in range(3):
        if A[j][i] != -1:
            break
    else:
        print('Yes')
        sys.exit(0)

for i in range(3):
    if A[i][i] != -1:
        break
else:
    print('Yes')
    sys.exit(0)

for i in range(3):
    if A[i][2-i] != -1:
        break
else:
    print('Yes')
    sys.exit(0)

print('No')

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

int main(){
    //入力部
    int N,M;
    cin>>N>>M;
    vector<int>a(M);
    vector<int>b(M);
    vector<int>c(N);
    for(int i = 0;i < M; i++){
        cin>>a.at(i)>>b.at(i);
    }
    //上下の文字列
    for(int i = 0;i < N; i++){
      for(int j=0;j < M; j++){
        if (i + 1== a[j]|| i+1==b[j])
          c[i]++;
      }
    }
    for(int i =0;i<N;i++)
      cout<<c.at(i)<<endl;

    }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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



    System.out.println(longestRepeatedSubstring(S).length());

   }
  static
  String longestRepeatedSubstring(String str) {
    int n = str.length();
    int LCSRe[][] = new int[n + 1][n + 1];

    String res = ""; // To store result
    int res_length = 0; // To store length of result

    // building table in bottom-up manner
    int i, index = 0;
    for (i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        // (j-i) > LCSRe[i-1][j-1] to remove
        // overlapping
        if (str.charAt(i - 1) == str.charAt(j - 1)
            && LCSRe[i - 1][j - 1] < (j - i)) {
          LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1;

          // updating maximum length of the
          // substring and updating the finishing
          // index of the suffix
          if (LCSRe[i][j] > res_length) {
            res_length = LCSRe[i][j];
            index = Math.max(i, index);
          }
        } else {
          LCSRe[i][j] = 0;
        }
      }
    }

    // If we have non-empty result, then insert all
    // characters from first character to last
    // character of String
    if (res_length > 0) {
      for (i = index - res_length + 1; i <= index; i++) {
        res += str.charAt(i - 1);
      }
    }

    return res;
  }


}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
T next_combination(T sub) {
    T x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    cout << n-k+1 << endl;


    return 0;
}


Measured memory_bytes: 256
/* -------------------------------------------------

Author :- Vaibhav Pal
College :- Northern India Engineering College, New Delhi
Coding Handle :- underdog_eagle
Title :-

----------------------------------------------------*/
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000000000000         
#define nl '\n'
#define sp ' '
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define bg begin()
#define en end()
#define fo(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)

inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int main()
{
	FAST_IO
    /*#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
    #endif*/

	int n;
	cin >> n;
	ll ans = LLONG_MAX;
	fo(i, 1, n){
		ll num, x = 0;
		cin >> num;
		while(num % 2 == 0){
			num /= 2;
			x++;
		}
		ans = min(ans, x);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for ( int i = 0 ; i < n ; ++i )
using namespace std;
 
int main() {
  std::string s = "" ;
  cin >> s ;
  
  map<char, int> ch_map ;
  int size = s.size() ;
  rep( i, size ) {
    ch_map[ s[i] ] += 1 ;
  }
  if ( ch_map.size() != 2 ) {
    cout << "No" ;
    return 0 ;
  }
  for ( const auto& p : ch_map ) {
    if ( p.second != 2 ) {
      cout << "No" ;
      return 0 ;
    }
  }
  cout << "Yes" ;
  
  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;

void main() {
	auto ip = readln.split.to!(int[]),
	A=ip[0],B=ip[1],C=ip[2],D=ip[3];
	if(A+B>C+D) {
		writeln("Left");
	}
	else if(A+B==C+D){
		writeln("Balanced");
	} else {
		writeln("Right");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define all(c) (c).begin(),(c).end()
#define endl '\n'
using namespace std;

//                                          mdsaqib
signed main(){
    fast;
    int n;
    cin >> n;
    int ans=n*(n+1)/2;
    for(int i=2;i<=n;i++){
        // for(int j=i;j<=n;j+=i){
        //     ans+=j;
        // }
        int k=n/i;
        ans+=i*k*(k+1)/2;
    }
    cout << ans;
}

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

int selectionSort(int*, int);
void printArray(int*, int);

int main(void) {
    int n, *a, i = 0, count;
    scanf("%d", &n);
    a = malloc(sizeof(int) * n);
    while (i < n) {
        scanf("%d", &a[i]);
        i++;
    }
    count = selectionSort(a, n);
    printArray(a, n);
    printf("%d\n", count);
    return 0;
}

int selectionSort(int *a, int n) {
    int i, j, minj, w, count = 0;
    for (i = 0; i < n; i++) {
        minj = i;
        for (j = i; j < n; j++) {
            if (a[j] < a[minj])
                minj = j;
        }
        if (a[i] != a[minj]) {
            count++;
            w = a[i];
            a[i] = a[minj];
            a[minj] = w;
        }
    }
    return count;
}

void printArray(int *a, int n) {
    int i = 0;
    while (i < n - 1) {
        printf("%d ", a[i]);
        i++;
    }
    printf("%d\n", a[i]);
}



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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    ll n, k, ans = 0;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    while(k > 0){
        if(k & 1 == 1){
            ans = a[ans];
        }
        vector<int> na(n);
        for(int j = 0; j < n; j++){
            na[j] = a[a[j]];
        }
        a.swap(na);
        k >>= 1;
    }
    ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5108
#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 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());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
	char c;
	REP(i, 3){
		cin >> c;
		if(c=='1') cout << 9 << flush;
		else cout << 1 << flush;
	}
	cout << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int dp[101][4][2];

int main(){
  std::string N;
  int K;
  std::cin >> N;
  scanf("%d",&K);
  std::vector<int > num;
  for (int i=0; i<N.length(); i++){
    num.push_back(int(N[i])-int('0'));
  }
  std::reverse(num.begin(), num.end());

  for (int i=0; i<101; i++){
    for (int j=0; j<4; j++){
      dp[i][j][0] = 0;
      dp[i][j][1] = 0;
    }
  }

  dp[0][0][1] = 1;
  for (int i=0; i<N.length(); i++){
    dp[i+1][0][1] = 1;
    for (int j=1; j<=3; j++){
      int val = num[i];
      //printf("val=%d\n",val);
      //printf("dp[%d][%d][1]=%d\n",i,j-1,dp[i][j-1][1]);
      //printf("dp[%d][%d][0]=%d\n",i,j-1,dp[i][j-1][0]);
      if (val!=0){
        dp[i+1][j][1] = (dp[i][j][1]+dp[i][j][0])+(val-1)*(dp[i][j-1][1]+dp[i][j-1][0])+dp[i][j-1][1];
        dp[i+1][j][0] = (9-val)*(dp[i][j-1][0]+dp[i][j-1][1])+dp[i][j-1][0];
      } else {
        dp[i+1][j][1] = dp[i][j][1];
        dp[i+1][j][0] = dp[i][j][0] + 9*(dp[i][j-1][0]+dp[i][j-1][1]);
      }
      //printf("dp[%d][%d][1]=%d+%d+%d=%d\n",i+1,j,dp[i][j][1],(val-1)*(dp[i][j-1][1]+dp[i][j-1][0]),dp[i][j-1][1],dp[i+1][j][1]);
      //printf("dp[%d][%d][0]=%d\n",i+1,j,dp[i+1][j][0]);
    }
  }
  printf("%d\n",dp[N.length()][K][1]);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] T = new int[N];
		for(int i=0;i<N;i++){
			T[i] = sc.nextInt();
		}
		
		int M = sc.nextInt();
		int[] P = new int[M];
		int[] X = new int[M];
		for(int i=0; i<M; i++){
			P[i] = sc.nextInt();
			X[i] = sc.nextInt();
		}
		
		int TotalTime = 0;
		for(int t:T){
			TotalTime += t;
		}
		
		for(int i=0; i<M; i++){
			int tmpTime = TotalTime + X[i] - T[P[i]-1];
			System.out.println(tmpTime);
		}
	}
}


Measured memory_bytes: 10312
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int amt;
	cin >> amt;
	long long int c1, c2;
	c1 = c2 = 0;
	c1 = (long long int)floor((long double)amt/500);
	c2 = (amt-c1*500)/5;
	long long int ans = c1*1000 + c2*5;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n; cin >> n;
  	char c[n];
  	for(int i = 0; i < n; i++) cin >> c[i];
  	int cnt = 0;
  	for(int i = 0; i < n - 2; i++)
    	if (c[i] == 'A' && c[i + 1] == 'B' && c[i + 2] == 'C') cnt++;
  	cout << cnt << endl;
  	return 0;
}

Measured memory_bytes: 256
/*
Come feed the rain
'cause I'm thirsty for your love dancing underneath the skies of lust
Yeah, feed the rain
'cause without your love my life ain't nothing but this carnival of rust!
*/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define LOG1(a)			  cerr<< #a << " = " << (a) << "\n"
#define LOG2(a, b)		  cerr<< #a << " = " << (a) << ", " << #b << " = " << (b) << "\n"
#define LOG3(a, b, c)     cerr<< #a << " = " << (a) << ", " << #b << " = " << (b) << ", "<< #c << " = " << (c) << "\n"
#define LOG4(a, b, c, d)  cerr<< #a << " = " << (a) << ", " << #b << " = " << (b) << ", "<< #c << " = " << (c) << ", " << #d << " = " << (d) << "\n"
#define endl "\n"

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<long long int> vll;

const double EPS = 1e-9;
const double pi = acos(-1);
const ll INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;

int n, arr[nax];
int main()
{
    ios::sync_with_stdio(0);
    vi v;
    int n, k;
    cin >> n >> k;
    map<int, int> map1;
    for(int i = 1; i <= n; i++)
    {
        int num; cin >> num;
        map1[num]++;
    }
    for(auto x: map1) v.pb(x.ss);
    sort(v.begin(), v.end(), greater<int>());
    ll ans = 0;
    for(int i = k; i < v.size(); i++)
        ans += v[i];
    cout << ans;
    return 0;
}



Measured memory_bytes: 10744
int m,n,p,i,l[1000],t,f;char s[1000],a[10];main(){for(;scanf("%d%d",&m,&n),m;){memset(l,0,sizeof(l));t=0;p=m;for(i=1;i<=n;i++){scanf("%s",s);*a=0;if(i%3==0)strcat(a,"Fizz");if(i%5==0)strcat(a,"Buzz");if(!*a)sprintf(a,"%d",i);if(strcmp(s,a)&&p>1)l[t]=1,p--;for(;t=(t+1)%m,l[t];);}f=0;for(t=0;t<m;t++)if(!t[l]){if(f)putchar(' ');f=printf("%d",1+t);}puts("");}{int n;for(n=990000;n--;)getchar();}exit(0);}

Measured memory_bytes: 440