akhauriyash/Code-Regression huggingface dataset:
n = int(input())
i = 0
hins = []
while i < n:
    hin = list(map(int, input().split()))
    hins.append(hin)
    i += 1

a = [[0 for i in range(10)] for i in range(3)]
b = [[0 for i in range(10)] for i in range(3)]
c = [[0 for i in range(10)] for i in range(3)]
d = [[0 for i in range(10)] for i in range(3)]

for i in range(n):
    hin = hins[i]
    #print(hin)
    tou = str(hin[0] - 1)
    kai = hin[1] - 1
    hey = hin[2] - 1
    nin = hin[3]
    #print(tou, kai, hey, nin)

    if tou == "0":
        a[kai][hey] = a[kai][hey] + nin
    elif tou == "1":
        b[kai][hey] = b[kai][hey] + nin
    elif tou == "2":
        c[kai][hey] = c[kai][hey] + nin
    elif tou == "3":
        d[kai][hey] = d[kai][hey] + nin
aida = "#" * 20

for i in range(3):
    for j in range(10):
        if j == 9:
            print(" {}" .format(a[i][j]))
        else:
            print(" {}" .format(a[i][j]), end="")
print(aida)
for i in range(3):
    for j in range(10):
        if j == 9:
            print(" {}" .format(b[i][j]))
        else:
            print(" {}" .format(b[i][j]), end="")
print(aida)
for i in range(3):
    for j in range(10):
        if j == 9:
            print(" {}" .format(c[i][j]))
        else:
            print(" {}" .format(c[i][j]), end="")
print(aida)
for i in range(3):
    for j in range(10):
        if j == 9:
            print(" {}" .format(d[i][j]))
        else:
            print(" {}" .format(d[i][j]), end="")


Measured memory_bytes: 5640
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();

    String Ae = A.substring(A.length() - 1);
    String Bs = B.substring(0,1);
    String Be = B.substring(B.length() - 1);
    String Cs = C.substring(0,1);

    if ((Ae.equals(Bs)) && (Be.equals(Cs))) { 
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}

Measured memory_bytes: 25428
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n + 2;
        int[] a = new int[m];
        a[0] = a[m - 1] = 0;
        for(int i=0; i<n; i++) {
            a[i+1] = sc.nextInt();
        }
        int d = 0;
        for(int i=0; i+1<m; i++) {
            d += Math.abs(a[i+1] - a[i]);
        }
        for(int i=0; i<n; i++) {
            System.out.println(d - Math.abs(a[i+2]-a[i+1]) - Math.abs(a[i+1]-a[i]) + Math.abs(a[i+2]-a[i]));
        }
    }

}


Measured memory_bytes: 63244
while gets
  x, y, z = $_.split.map(&:to_i)
  break if x==-1&&x==y&&x==z
  s = 7200 - x*3600 - y*60 - z
  puts "%02d:%02d:%02d"%[s/3600,s%3600/60,s%60]
  s *=3
  puts "%02d:%02d:%02d"%[s/3600,s%3600/60,s%60]
end

Measured memory_bytes: 6104
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
#define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  int l[q],r[q];
  rep(i,q) {
    cin>>l[i]>>r[i];
    l[i]--;r[i]--;
  }
  int a[n],b[n];
  rep(i,n) {
    a[i] = 0;b[i] = 0;
  }
  int now = 1;
  rep(i,n-1) {
    if(s[i] == 'A' && s[i+1] == 'C') {
      a[i] = now;
      now++;
    } else {
      a[i] = now;
    }
  }
  now = 0;
  rep(i,n-1) {
    if(s[i] == 'A' && s[i+1] == 'C') {
      now++;
    }
    b[i+1] = now;
  }
  a[n-1] = b[n-1];
  rep(i,q) {
    cout << b[r[i]] - a[l[i]] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 4176
n = STDIN.gets.to_i
t, a = STDIN.gets.split(' ').map(&:to_i)
heights = STDIN.gets.split(' ').map(&:to_i)

diff = 10**10
index = -1

heights.each_with_index do |h, i|
  average_tempurature = t - h * 0.006
  if diff > (a - average_tempurature).abs
    diff = (a - average_tempurature).abs
    index = i
  end
end

puts index + 1


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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  int n;
  cin >> n;
  vector<bool> is_prime(n + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i * i <= n; i += 2) {
    if (!is_prime[i]) continue;
    for (int j = i * i; j <= n; j += i) {
      is_prime[j] = false;
    }
    if (i == 2) i--;
  }
  vector<int> prime(1, 2);
  for (int i = 3; i <= n; i += 2) {
    if (is_prime[i]) prime.push_back(i);
  }
  vector<int> mp(prime.size());
  for (int i = 1; i <= n; i++) {
    int num = i;
    for (int j = 0; j < prime.size() && prime[j] <= num; j++) {
      while (num % prime[j] == 0) {
        mp[j]++;
        num /= prime[j];
      }
    }
  }
  long long ans = 1;
  for (auto&& i : mp) {
    i %= INF;
    i++;
    i %= INF;
    ans *= i;
    ans %= INF;
  }
  cout << ans << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  hawawa();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
bool f[11];
inline bool check(int n) {
    while(n > 0 && f[n%10] == 0)
      n/=10;
    return n == 0;
}
int main() {
    FILE * fi, * fout;
    int i,n,x,m;
    //fi = fopen("A.in" ,"r");
    //fout = fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d%d" ,&n,&m);
    for(i=1;i<=m;i++) {
      fscanf(fi,"%d" ,&x);
      f[x]=1;
    }
    while(!check(n))
      n++;
    fprintf(fout,"%d\n" ,n);
    //fclose(fi);
    //fclose(fout);
    return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e3,mod=1e9+7,bit=61;

ll power(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b & 1)
		{
			res=(res*a);
		}
		b>>=1;
		a=(a*a);
	}
	return res;
}

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll x;
        cin>>x;
        f(i,-N,N)
        {
            f(j,-N,N)
            {
                ll res=power(i,5)-power(j,5);
                if(res==x)
                {
                    cout<<i<<' '<<j<<endl;
                    return 0;
                }
            }
        }
        assert(0);
    }
    return 0;
}


















Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int L;
  cin >>N>>L;
  int x=N-L+1;
  cout << x<< endl;
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

int dfs(auto &E,int now,int p){
	int ret = 0;
	for(int i=0;i<E[now].size();i++){
		if(E[now][i]==p)continue;
		ret ^= dfs(E,E[now][i],now);
	}
	return ret+1;
}

int main(){
	
	int N;
	cin>>N;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	if(dfs(E,0,-1)==1)cout<<"Bob"<<endl;
	else cout<<"Alice"<<endl;
	
	return 0;
}

Measured memory_bytes: 13568
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(0,n):
	for j in range(i+1,n)[::-1]:
		if a[j]<a[j-1]:
			a[j],a[j-1] = a[j-1],a[j]
			cnt += 1
print(" ".join(map(str,a)))
print(cnt)

Measured memory_bytes: 6724
#include<stdio.h>
#define MAX 5000000
#define NIL 0

/*木*/
int Tree[MAX];

/*プロトタイプ宣言*/
void buildMaxHeap(void);
void maxHeapify(int);

/*グローバル変数*/
int heap_size;


main() {
  int i;//counter

  scanf("%d", &heap_size);

  for(i = 1; i <= heap_size; i++) {
    scanf("%d", &Tree[i]);
  }

  buildMaxHeap();

  for(i = 1; i <= heap_size; i++) {
    printf(" %d", Tree[i]);
  }
  printf("\n");

  return 0;
}


/*
 *    buildMaxHeap関数...iの値を変化させ、ボトムアップで適用させることでmax-heap変換に繋げる
 */
void buildMaxHeap() {

  int i;//counter

  //始めにheap_sizeを2で割る事で構造体ではなく配列でmax-heapを適用させることができる。
  for(i = (heap_size/2); i >= 1; i--) {

    maxHeapify(i);
  }

}



/*
 *    maxHeapify関数...max-heapを行う関数。コメントは随時記載。
 */
void maxHeapify(int u) {

  int left;
  int right;
  int largest;
  int tmp=0;//保存用関数

  //右と左の仕分け。
  left = 2*u;
  right = 2*u +1;

  //左の値が制限内かつ、元々の数より大きければ最大の値として保存する。...1
  if(left <= heap_size && Tree[left] > Tree[u]) {
    largest = left;
  }

  /**/
  else {
    largest = u;
  }

  //1と同じ要領。順番は左→右なのでここで比較するのは右の値。
  if(right <= heap_size && Tree[right] > Tree[largest]) {
    largest = right;
  }

  /**/
  if(largest != u) {
    tmp = Tree[u];
    Tree[u] = Tree[largest];
    Tree[largest] = tmp;

    //buildMaxHeap関数が終わるまで続ける（再起？）
    maxHeapify(largest);
  }

}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'


void solve(){
    string a;
    cin>>a;
    lli sum= 0;
    rep(i, a.size(), 0){
        sum+= a[i] -'0';
    }
    if(sum%9 == 0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


int main()
{
    fastio;
    int t;
    // cin>>t;
    t =1;
    while(t--)solve();

}

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

int main()
{
    int n, t;
    std::cin >> n >> t;
    int mincost = 1001;
    for (int i = 0; i < n; ++i) {
        int ci, ti;
        std::cin >> ci >> ti;
        if (ti <= t && ci < mincost) {
            mincost = ci;
        }
    }
    if (mincost == 1001) {
        std::cout << "TLE" << std::endl;
    } else {
        std::cout << mincost << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        if (i > 0) {
            s << ' ';
        }
        s << vec[i];
    }
    return s << endl;
}
/* Comb：nCk % p の計算のための構造体
    前処理: O(MAX_N*MAX_N)
    nCk(n,k): nCk % p の計算。O(1)
*/
struct Comb {
    const int MAX_N = 51;           // 最大値
    vector<vector<long long>> com;  // 前計算の結果を保存
    Comb() { init(); }
    void init() {  // 動的計画法で前処理
        com.assign(MAX_N, vector<long long>(MAX_N));
        com[0][0] = 1;
        for (int i = 1; i < MAX_N; ++i) {
            com[i][0] = 1;
            for (int j = 1; j < MAX_N; j++) {
                com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]);
            }
        }
    }
    long long nCk(int n, int k) {
        assert(!(n < k));
        assert(!(n < 0 || k < 0));
        return com.at(n).at(k);
    }
};

int main() {
    int N, P;
    cin >> N >> P;
    vector<int> A(N);
    vector<ll> cnt(2, 0);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        A.at(i) %= 2;
        cnt.at(A[i])++;
    }

    Comb comb;
    ll ans = 0;
    for (int i = P; i <= cnt[1]; i += 2) {
        ans += comb.nCk(cnt[1], i) * (1LL << cnt[0]);
    }
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;

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

    int now=0, cnt=0;
    while(1){
        if(now==1){
            cout << cnt << endl;
            break;
        }
        if(cnt>=n){
            cout << -1 << endl;
            break;
        }
        cnt++;
        now = v[now];
    }

}

Measured memory_bytes: 892
#include <set>
#include<cmath>
#include <stdio.h>
#include <cstdio>
#include<string.h>
#include <string>
#include <iostream>
using namespace std;
 
 
int main()
{
    int n,num1=0,num2=0;
    string s1;
    string s2;
    long long int result=3;
    cin>>n;
    cin>>s1;
    cin>>s2;
    if (n<3)
    printf("%d",3*n);
    else
    {
        if (s1[0]!=s2[0])
        result=6;
        for (int i=0;i<n-1;i++)
        {
            if (s1[i]==s2[i])
            num1++;
			if ((s1[i]!=s2[i])&&(s1[i+1]!=s2[i+1])&&(s1[i]!=s1[i+1])&&(s2[i]!=s2[i+1]))
            num2++; 
        }
        if(num1!=0)
        {
        for (int i=1;i<=num1;i++)
        {
            result=result*2%1000000007;
        }
        }
        if(num2!=0)
        {
        for (int i=1;i<=num2;i++)
        {
            result=result*3%1000000007;
        }
        }
        printf("%lld",result);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;
const int MAX_V = 10000;
typedef pair<int, int>P;
#define MOD 1000000007
ll dp[100100][2];
bool visited[100100];
vector<vector<int>>G(100100);

void dfs(int from){
  visited[from]=true;
  for(auto t:G[from]){
    if(visited[t]){continue;}
    dfs(t);
    ll w=0ll,b=0ll;
    w=dp[t][0]+dp[t][1];
    b=dp[t][0];  
    dp[from][0]*=w;
    dp[from][1]*=b;
    dp[from][0]%=MOD;
    dp[from][1]%=MOD;
  }
  return;
}

int main() {
  int N;
  cin>>N;
  rep(i,N-1){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  ll ans=0ll;
  rep(i,100100){dp[i][0]=1ll;dp[i][1]=1ll;visited[i]=false;}
  dfs(0);
  ans+=dp[0][0]+dp[0][1];
  ans+=MOD;
  ans%=MOD;
  cout<<ans;
}

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

#define  optimize   ios::sync_with_stdio(0); cin.tie(0);
#define PI  acos(-1.0)
#define RESET(a, b) memset(a, b, sizeof(a))
#define pb push_back

int main()
{
     optimize
     int n,k;
     cin>>n>>k;
     int a[n+2];
     ll sum=0;
     vector<int>v;
     for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
     }
     if(sum<k) cout<<"Impossible\n";
     else{
        for(int i=1;i<n;i++){
            if(a[i]+a[i+1]>=k){
                if(i>1){
                    for(int j=1;j<i;j++) v.pb(j);
                }
                if(i+1 <n){
                    for(int j=n-1;j>i;j--) v.pb(j);
                }
            v.pb(i);
            cout<<"Possible\n";
            for(int i=0;i<v.size();i++) cout<<v[i]<<"\n";
            return 0;
            }
        }
        cout<<"Impossible\n";
        return 0;
     }

}


Measured memory_bytes: 4268
N, M = map(int, input().split())
A = list(map(int, input().split()))

SUM_A = sum(A)
ans = 0

for i in range(N):
    if A[i]>=SUM_A/(4*M):
        ans += 1

if ans >= M :
    print("Yes")
else:
    print("No")

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

#define INF 100000000000

using namespace std;

int main(){
    int A, B, Q;
    cin>>A>>B>>Q;
    vector<long> s(A), t(B);
    long x;
    for(int i=0; i<A; ++i){
        cin>>s[i];
    }
    for(int i=0; i<B; ++i){
        cin>>t[i];
    }
    vector<long> ss(2), tt(2);
    for(int i=0; i<Q; ++i){
        cin>>x;
        
        vector<long>::iterator s_itr = upper_bound(s.begin(), s.end(), x);
        vector<long>::iterator t_itr = upper_bound(t.begin(), t.end(), x);
        
        ss[0] = *(s_itr-1);
        ss[1] = *s_itr;
        tt[0] = *(t_itr-1);
        tt[1] = *t_itr;
        
        if(s_itr == s.begin()){
            ss[0] = -INF;
        }
        if(s_itr == s.end()){
            ss[1] = INF;
        }
        
        if(t_itr == t.begin()){
            tt[0] = -INF;
        }
        if(t_itr == t.end()){
            tt[1] = INF;
        }

        long ans = INF, dist;
        for(int i=0; i<2; ++i){
            for(int j=0; j<2; ++j){
                for(int k=0; k<2; ++k){
                    if(k==0){
                        dist = abs(x - ss[i]) + abs(ss[i] - tt[j]);
                    }else{
                        dist = abs(x - tt[j]) + abs(tt[j] - ss[i]);
                    }
                    if(ans > dist){
                        ans = dist;
                    }
                }
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>

enum face {
  TOP,
  FRONT,
  RIGHT,
  LEFT,
  BACK,
  BOTTOM
};

class dice {
  public:
    dice();
    void setDice(int spot, int eye);
    int getSpot(int top);
    void rollNorth();
    void rollSouth();
    void rollEast();
    void rollWest();

  private:
    void roll(face a, face b, face c, face d);
    std::vector<int> id;
};

dice::dice() {
  id.resize(6);
}

void dice::setDice(int spot, int eye) {
  switch(eye) {
    case TOP:
      id[TOP] = spot;
      break;
    case BOTTOM:
      id[BOTTOM] = spot;
      break;
    case FRONT:
      id[FRONT] = spot;
      break;
    case BACK:
      id[BACK] = spot;
      break;
    case LEFT:
      id[LEFT] = spot;
      break;
    case RIGHT:
      id[RIGHT] = spot;
      break;
  }
}

int dice::getSpot(int top) {
  return id[top];
}

void dice::rollNorth() {
  roll(TOP, FRONT, BOTTOM, BACK);
}

void dice::rollSouth() {
  roll(TOP, BACK, BOTTOM, FRONT);
}

void dice::rollEast() {
  roll(TOP, LEFT, BOTTOM, RIGHT);
}

void dice::rollWest() {
  roll(TOP, RIGHT, BOTTOM, LEFT);
}

void dice::roll(face a, face b, face c, face d) {
  int tmp = id[a];
  id[a] = id[b];
  id[b] = id[c];
  id[c] = id[d];
  id[d] = tmp;
}

int main() {
  int d;
  dice di;
  for(int i = 0; i < 6; ++i) {
    std::cin >> d;
    di.setDice(d, i);
  }

  std::string commands;
  std::cin >> commands;

  for(int i = 0; commands[i] != '\0'; ++i) {
    if(commands[i] == 'N') di.rollNorth();
    if(commands[i] == 'E') di.rollEast();
    if(commands[i] == 'W') di.rollWest();
    if(commands[i] == 'S') di.rollSouth();
  }
  d = di.getSpot(TOP);
  std::cout << d << std::endl;

  return 0;
}

Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
const int INF = 1000000000;

int main(){
	ios_base::sync_with_stdio(false);
	int h0, w0, h1, w1;
	cin >> h0 >> w0;
	vector< vector<int> > a(h0, vector<int>(w0));
	vector< vector<int> > b(h0, vector<int>(w0));
	for(int i = 0; i < h0; ++i){
		for(int j = 0; j < w0; ++j){ cin >> a[i][j]; }
	}
	for(int i = 0; i < h0; ++i){
		for(int j = 0; j < w0; ++j){ cin >> b[i][j]; }
	}
	cin >> h1 >> w1;
	vector< vector<int> > c(h1, vector<int>(w1));
	for(int i = 0; i < h1; ++i){
		for(int j = 0; j < w1; ++j){ cin >> c[i][j]; }
	}
	int answer = -INF;
	for(int y = 0; y + h1 <= h0; ++y){
		for(int x = 0; x + w1 <= w0; ++x){
			int sum = 0;
			bool match = true;
			for(int i = 0; i < h1; ++i){
				for(int j = 0; j < w1; ++j){
					if(b[y + i][x + j] != c[i][j]){ match = false; }
					sum += a[y + i][x + j];
				}
			}
			if(match){ answer = max(answer, sum); }
		}
	}
	if(answer <= -INF){
		cout << "NA" << endl;
	}else{
		cout << answer << endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll n, a, b;
  cin>>n>>a>>b;
  ll ans=n/(a+b)*a+min(a, n-n/(a+b)*(a+b));
  cout<<ans<<'\n';
  return 0;
}


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

A=list(map(int,input().split()))
A.sort()
dc=[]

for i in range(M):
    B,C=map(int,input().split())
    dc.append([B,C])

dc.sort(key=lambda x: x[1],reverse=True)
bf=False
i=0
for l in dc:
    B,C=l
    if bf:
        break
    while B>0:
        if i<N and A[i]<C:
            A[i]=C
            B-=1
            i+=1
        else:
            bf=True
            break


print(sum(A))


Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int n,k;cin>>n>>k;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	sort(ALL(a));
	int ans = 0;
	for(int i = 0; i < k; i++) {
		ans +=a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  string s;
   cin >> a >> b >> s ;
  string ans ="Yes";
 if((s.at(a)!='-')){
   ans ="No";
 }
   for(int i=0;i<s.size();i++){
     if((s.at(i)=='-')&&i!=a){
        ans = "No";
     }
        }
        cout << ans;
        
  
}

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

int main() {

    // 1. input.
    int N;
    cin >> N;
    vector<long long> c(N);
    vector<long long> dp;
    for(int i = 0; i < N; i++) cin >> c[i];
    
    // 2. Longest Increasing Subsequence.
    dp.push_back(c[0]);
    for(int i = 1; i < N; i++){
        // 2-1. dpテーブル末尾 の 要素(last) より大きな値(c[i])であれば, dpテーブル に 追加.
        int last = dp.back();
        if(last < c[i]) dp.push_back(c[i]);
        // 2-2. dpテーブル末尾 の 要素(last) より小さな値(c[i])であれば, 
        // dpテーブル上 の 更新場所 を 探索後, dpテーブル を 更新.
        if(last > c[i]){
            // rep/code.cpp: In function ‘int main()’: rep/code.cpp:22:18: 
            // error: ‘it’ does not name a type auto it = lower_bound(dp.begin(), dp.end(), c[i]); ^ 
            // rep/code.cpp:23:24: error: ‘it’ was not declared in this scope int dist = it - dp.begin(); ^ 
            // auto it = lower_bound(dp.begin(), dp.end(), c[i]);
            vector<long long>::iterator it = lower_bound(dp.begin(), dp.end(), c[i]);
            int dist = it - dp.begin();
            dp[dist] = c[i];
            // for(int i = 0; i < dp.size(); i++) cout << dp[i] << " ";
            // cout << endl;
        }
    }
    // for(int i = 0; i < dp.size(); i++) cout << dp[i] << " ";
    // cout << endl;
    
    // 3. output answer.
    int ans = dp.size();
    cout << ans << endl;
    return 0;
    
}


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

typedef long long ll;

int main(){
	int n;
	while(cin >> n,n){
		vector<int> a(n);
		int sum=0;
		for(int i=0;i<n;i++){
			cin >> a[i];
			sum+=a[i];
		}
		int res=0;
		for(int i=0;i<n;i++){
			if(sum>=n*a[i])res++;
		}
		printf("%d\n",res);
	}
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

typedef long long ll;

ll n, art, a[N], b[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld",&n);
	for(int i = 1; i <= n; i++)
		scanf("%lld %lld",a + i, b + i);
	for(int i = n; i >= 1; i--){
		a[i] += art;
		ll mod = a[i]%b[i];
		if(mod == 0)
			continue;
		art += b[i] - mod;
	}
	printf("%lld\n", art);
	return 0;
}

Measured memory_bytes: 5120
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long INT;
double PI = 3.14159265;

const long long INF = 1LL << 60;
//---//


int main() {
    int n;
    set<string> set;
    string s;

    cin >> n;

    rep(i, n) {
        cin >> s;
        set.insert(s);
    }

    cout << set.size() << endl;

    return 0;
}

Measured memory_bytes: 19224
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

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

#define ll long long
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[N];

int add(int n, int m){
	return (n+m)%mod;
}

void solve()
{    
    ll n, m ;
    cin >> n >> m;
    string grid[n+1] ;
    for(int i = 0 ; i<n; i++){
    	cin>>grid[i] ;
    }

    vector<vector<int>> dp(n+1, vector<int>(m+1,0)) ;
    dp[1][1] = 1;
    for(int i=2; i<=n; i++){
    	if(grid[i-1][0]!='#')dp[i][1] = dp[i-1][1];
    }

    for(int i=2; i<=m; i++){
    	if(grid[0][i-1]!='#')dp[1][i] = dp[1][i-1];
    }

    for(int i=2; i<=n; i++){
    	for(int j=2; j<=m; j++){
    		if(grid[i-1][j-1]!='#'){
    			dp[i][j] = add((grid[i-2][j-1]=='#'?0:dp[i-1][j]), (grid[i-1][j-2]=='#'?0:dp[i][j-1])) ;
    		}
 //   		cout<<i<<j<<dp[i][j]<<" ";
    	}
   // 	cout<<"\n";
    }
    cout<<dp[n][m];

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}


// Xorawar

Measured memory_bytes: 8180
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] array = new String[n];
		for(int i= 0; i < n;i++) {
			array[i] = sc.next();
		}
		Arrays.sort(array);
		List<String> answerList = new ArrayList<String>();
		int count = 1;
		int maxCount = 1;
		for(int i = 1;i < n;i++) {
			if(array[i-1].equals(array[i])) {
				count++;
			}else {
				if(count> maxCount) {
					answerList.clear();
					answerList.add(array[i-1]);
					maxCount = count;
					count = 1;
				}else if(count== maxCount) {
					answerList.add(array[i-1]);
					count = 1;
				}else {
					count = 1;
				}
			}
			if(i == n-1) {
				if(count> maxCount) {
					answerList.clear();
					answerList.add(array[i]);
				}else if(count== maxCount) {
					answerList.add(array[i]);
				}
			}
		}


		for(String answer :answerList) {
			System.out.println(answer);
		}
	}

}

Measured memory_bytes: 77000
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
w = list(li())

ans = 10**18
for i in range(n):
    ans = min(ans, abs(sum(w[:i]) - sum(w[i:])))

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <map>
#include <algorithm>

int main()
{
	int N = 0;
	std::string ans = "APPROVED";

	std::cin >> N;
	std::vector<int> A(N);

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

	for (int i = 0; i < N; i++){
		if (A[i] % 2 == 0)
		{
			if ((A[i] % 3 != 0) && (A[i] % 5 != 0)){
				ans = "DENIED";
				break;
			}
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;
const int MAX = 1010;
ll f[MAX], finv[MAX];

ll mod_pow(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll Comb(int n, int k) {
  if (k < 0 || k > n) {
    return 0;
  }
  return (f[n] * finv[k] % MOD) * finv[n - k] % MOD;
}

void init() {
  f[0] = 1;
  for (int i = 1; i < MAX; i++) {
    f[i] = f[i-1] * i % MOD;
  }
  finv[MAX-1] = mod_pow(f[MAX-1], MOD - 2);
  for (int i = MAX - 2; i >= 0; i--) {
    finv[i] = finv[i+1] * (i + 1) % MOD;
  }
}

int main() {
  init();
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
  dp[A-1][N] = 1;
  for (int k = A; k <= B; k++) {
    for (int n = 0; n <= N; n++) {
      (dp[k][n] += dp[k-1][n]) %= MOD;
      ll t = 1;
      for (int m = 2; m < C; m++) {
        if (n < k * m) {
          break;
        }
        t = t * Comb(k * m, k) % MOD;
      }
      for (int m = C; m <= D; m++) {
        if (n < k * m) {
          break;
        }
        t = t * Comb(k * m, k) % MOD;
        ll coef = (Comb(n, k * m) * t % MOD) * finv[m] % MOD;  
        (dp[k][n-k*m] += dp[k-1][n] * coef % MOD) %= MOD;
      }
    }
  }
  cout << dp[B][0] << endl;
  return 0;
}


Measured memory_bytes: 8192
import sys
import itertools
tokens = itertools.chain.from_iterable(map(str.split, sys.stdin))

yesno = ['NO', 'YES']
n = int(next(tokens))
p = [int(next(tokens)) for _ in range(n)]


s = sum(1 if a != b else 0 for a, b in zip(p, sorted(p)))
print(yesno[s == 2 or s == 0])


Measured memory_bytes: 9092
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
using namespace std;

int main(){

    int a,b;
    cin>>a>>b;

    if(a-2*b<=0){
        cout<<0<<endl;
    }else{
        cout<<a-2*b<<endl;
    }

return 0;
}

Measured memory_bytes: 256
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
def is_prime(t):
    k = 2
    while k*k <= t:
        if t%k == 0:
            return False
        k+=1
    return True

x = int(input())
while True:
    if is_prime(x):
        print(x)
        break
    else:
        x+=1

Measured memory_bytes: 9488
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            List<int> outList = new List<int>();
            string input;
            while ((input = Console.ReadLine()) != null)
            {
                string[] array = input.Split(' ');
                int sum = int.Parse(array[0]) + int.Parse(array[1]);
                outList.Add(GetDigit(sum));

            }

            foreach (int n in outList)
            {
                Console.WriteLine(n);
            }

            
        }

        static int GetDigit(int sum)
        {
            int count = 1;
            int i = 1;
            while (true)
            {
                i *= 10;
                if (sum - i < 0)
                {
                    break;
                }

                count++;
            }

            return count;
        }
    }
        
}

Measured memory_bytes: 5688
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 3e5 + 7;
const long long inf = 1e11;
int n;
long long k;
int edge, fir[maxn], nex[maxn], go[maxn], val[maxn];
int size[maxn], sum[maxn], lc[maxn], rc[maxn];
struct pairs
{
	long long a, b;
};
pairs c[maxn];
vector <pairs> g[maxn];
inline bool rule(pairs u, pairs v)
{
	if(u.a != v.a) return u.a < v.a;
	return u.b < v.b;
}
inline int Get()
{
	char c;
	while(!isdigit(c = getchar()));
	int x = c - '0';
	while(isdigit(c = getchar()))
		x = (x << 3) + (x << 1) + c - '0';
	return x;
}
inline void Ins(int x, int y, int z)
{
	nex[++edge] = fir[x];
	fir[x] = edge;
	go[edge] = y;
	val[edge] = z;
}
void Dfs(int u, int f)
{
	size[u] = 1;
	for(int i = fir[u]; i; i = nex[i])
	{
		int v = go[i];
		if(v != f)
		{
			sum[v] = val[i];
			Dfs(v, u);
			size[u] += size[v];
			if(!lc[u]) lc[u] = v;
			else rc[u] = v;
		}
	}
	if(size[lc[u]] > size[rc[u]])
		swap(lc[u], rc[u]);
}
void Dp(int u)
{
	g[u].clear();
	if(!lc[u])
	{
		g[u].push_back((pairs) {sum[u], sum[u]});
		return;
	}
	Dp(lc[u]), Dp(rc[u]);
	long long v;
	int l, r, mid, ans, num = 0;
	for(int i = 0; i < (int) g[lc[u]].size(); ++i)
	{
		v = g[lc[u]][i].a;
		l = 0, r = g[rc[u]].size() - 1, ans = g[rc[u]].size();
		while(l <= r)
		{
			mid = l + r >> 1;
			if(v + g[rc[u]][mid].b <= k) ans = mid, r = mid - 1;
			else l = mid + 1;
		}
		if(ans != (int) g[rc[u]].size())
		{
			++num;
			c[num].a = g[lc[u]][i].b + sum[u];
			c[num].b = g[rc[u]][ans].a + sum[u];
			++num;
			c[num].a = g[rc[u]][ans].a + sum[u];
			c[num].b = g[lc[u]][i].b + sum[u];
		}
	}
	sort(c + 1, c + 1 + num, rule);
	c[0].a = -1;
	long long minb = inf;
	for(int i = 1; i <= num; ++i)
	{
		if(c[i].a != c[i - 1].a)
			if(c[i].b < minb)
				g[u].push_back(c[i]);
		minb = min(minb, c[i].b);
	}
/*	printf("asd %lld %d\n", k, u);
	for(int i = 0; i < (int) g[u].size(); ++i)
		printf("%lld %lld\n", g[u][i].a, g[u][i].b);*/
}
inline bool Check(long long x)
{
	k = x, Dp(1);
	return !g[1].empty();
}
inline long long Divide()
{
	long long l = 0, r = inf, mid, ans = inf;
	while(l <= r)
	{
		mid = l + r >> 1;
		if(Check(mid)) ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	return ans;
}
int main()
{
	n = Get();
	int x, v;
	for(int i = 1; i < n; ++i)
	{
		x = Get(), v = Get();
		Ins(x, i + 1, v);
		Ins(i + 1, x, v);
	}
	Dfs(1, 0);
	cout << Divide();
}

Measured memory_bytes: 40056
#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

int h,w,n;
char factory[1005][1005];
int vis[1005][1005];
int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};

int bfs(int sx,int sy,int n)
{
    memset(vis,0,sizeof(vis));
    queue<pair<int, int> > q;
    queue<int> qstep;
    q.push(make_pair(sx,sy));
    qstep.push(0);
    char target = '1';
    while(!q.empty()){
        pair<int,int> p = q.front(); q.pop();
        int step = qstep.front(); qstep.pop();
        int x = p.first;
        int y = p.second;
        //cout<<x<<":"<<y<<endl;
        for(int i=0;i<4;++i){
            int xx = x + dir[i][0];
            int yy = y + dir[i][1];
            if(xx<0||xx>=h||yy<0||yy>=w) continue;
            if(factory[xx][yy] == target){
                if(target == ('0'+n)) return step + 1;
                while(!q.empty()) q.pop();
                while(!qstep.empty()) qstep.pop();
                q.push(make_pair(xx,yy));
                qstep.push(step+1);
                //cout<<target<<endl;
                target += 1;
                memset(vis,0,sizeof(vis));
                vis[xx][yy]=1;
                break;
            }else if(factory[xx][yy] != 'X'){
                if(vis[xx][yy]) continue;
                vis[xx][yy] = 1;
                q.push(make_pair(xx,yy));
                qstep.push(step+1);
            }
        }
    }
}

int main()
{
    //freopen("input.in","r",stdin);
    while(cin>>h>>w>>n){
        int sx,sy;
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                cin>>factory[i][j];
                if(factory[i][j]=='S'){
                    sx = i;
                    sy = j;
                }
            }
        }
        cout<<bfs(sx,sy,n)<<endl;
    }
    return 0;
}



Measured memory_bytes: 8084
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
	boxes = []
	while True:
		h, w = [int(i) for i in input().split(" ")]
		if h == 0 and w == 0:
			break
		boxes.append([h, w])
	for i in boxes:
		for j in range(i[0]):
			print(("#." * (i[1] // 2 + 1))[j % 2:i[1]+ j % 2])
		print()
	return
if __name__ == '__main__':
  main()

Measured memory_bytes: 7676
line = input().split(" ")
N = int(line[0])
T = int(line[1])

c = []
t = []
for i in range(N):
    line = input().split(" ")
    if T >= int(line[1]):
        c.append(line[0])
        t.append(line[1])

if len(c) == 0:
    print('TLE')
    exit()
elif len(c) == 1:
    print(int(c[0]))
    exit()
elif len(c) >= 2:
    ans = int(c[0])
    for i in range(len(c)-1):
        if ans > int(c[i+1]):
            ans = int(c[i+1])
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
	double x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	printf("%.10f\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
	return 0;
}


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

using ll = long long;

int main() {
	int n; cin >> n;
	vector<ll>a(n + 1); rep(i, n + 1) { cin >> a[i]; }
	vector<ll>b(n); rep(i, n) { cin >> b[i]; }

	ll c = 0LL;
	for (int i = n; i >= 1; i--) {
		if (b[i - 1] > a[i]) {
			b[i - 1] -= a[i]; c += a[i];
			a[i] = 0LL;
			if (b[i - 1] > a[i - 1]) {
				b[i - 1] = 0LL; c += a[i - 1];
				a[i - 1] = 0LL;
			}
			else {
				a[i - 1] -= b[i - 1]; c += b[i - 1];
				b[i - 1] = 0LL;
			}
		}
		else {
			a[i] -= b[i - 1]; c += b[i - 1];
			b[i - 1] = 0LL;
		}
	}

	cout << c << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int ans = 0;
	int cnt = 0;
	rep(i, s.size()) {
		if(s[i]=='W'){
			ans += i - cnt;
			cnt++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 720
x, y, z = gets.split.map(&:to_i)
if x >= y && y >= z
    printf("%d %d %d",z,y,x)
    else
    if x >= z && z >= y
        printf("%d %d %d",y,z,x)
        else
        if y >= x && x >= z
            printf("%d %d %d",z,x,y)
            else
            if y >= z && z >= x
                printf("%d %d %d",x,z,y)
                else
                if z >= x && x >= y
                    printf("%d %d %d",y,x,z)
                    else
                    if z >= y && y >= x
                        printf("%d %d %d",x,y,z)
                    end
                end
            end
        end
    end
end
puts

Measured memory_bytes: 8712
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    bool flag=true;
    while(a>0&&c>0){
        if(flag) c-=b;
        else a-=d;
        flag=!flag;
    }
    if(a<=0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    double qq;
    if (d%2==1)
        qq=(c*60+d)/2+0.5;
    else
        qq=(c*60+d)/2;
    double ww=d*6;
    double t=min(abs(qq-ww), 360-abs(qq-ww));
    double ca=cos(t*3.1415926535897932*2/360);
    double ou=sqrt(a*a+b*b-2*a*b*ca);
    cout << fixed << setprecision(17) << ou << endl;
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Data
{
    int y;
    int p;
    int i;
};
Data D[100005];
string A[100005];

string create(int p, int n)
{
    string a = "", b = "";
    REP(i, 6)
    {
        a = (char)('0' + p % 10)+a;
        b = (char)('0' + n % 10)+b;
        p /= 10;
        n /= 10;
    }
    return a + b;
}

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, M)
    {
        cin >> D[i].p >> D[i].y;
        D[i].i = i;
    }
    sort(D, D + M, [](Data a, Data b) { return a.p == b.p ? a.y < b.y : a.p < b.p; });
    int pi = 0;
    REP(i, M)
    {
        if (D[pi].p != D[i].p)
        {
            pi = i;
        }
        A[D[i].i] = create(D[i].p, i - pi + 1);
    }
    REP(i, M)
    {
        cout << A[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 8192
N,Y = map(int,input().split())

res = [-1,-1,-1]
for i in range(N+1):
    for j in range(N+1-i):
        total = i*10000+j*5000+(N-i-j)*1000
        if total == Y:
            res = [i,j,N-i-j]
print(*res)

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

int main(){
	int animals,legs;
	cin>>animals>>legs;
	int cranes=animals,turtles=0,stat=0;
	while(cranes>=0){
		if(cranes*2+turtles*4==legs){
			stat=1;
			break;
		}
		cranes--;
		turtles++;
	}if(stat==1)cout<<"Yes\n";
	else cout<<"No\n";
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    cin >> n >> s;
    vl e(n + 10, 0), w(n + 10, 0);

    NREP() {
        if (s[i] == 'E') {
            if (i == 0) {
                e[i] = 1;
                w[i] = 0;
            } else {
                e[i] = e[i - 1] + 1;
                w[i] = w[i - 1];
            }
        } else if (s[i] == 'W') {
            if (i == 0) {
                e[i] = 0;
                w[i] = 1;
            } else {
                e[i] = e[i - 1];
                w[i] = w[i - 1] + 1;
            }
        }
    }

    ans = LLONG_MAX;
    NREP() {
        // 自分より先のE
        ll es = e[n - 1] - e[i];
        // 自分より前のW
        ll ws;
        if (i == 0) ws = 0;
        else ws = w[i - 1];
        ans = min(ans, es + ws);
    }
    MSG(ans)
}


Measured memory_bytes: 5380
x=int(input())
A = 0
B = 0
for a in range(-120, 120):
    a5 = a**5
    for b in range(-120, 120):
        if (a5 < x and b >=0 ) or (a5 > x and b <= 0):
            continue
        if a5 - b**5 == x:
            A = a
            B = b
            break
print(A, B)

Measured memory_bytes: 9124
import Data.Array

propagate::Array Int Int->Int->Array Int Int
propagate ar item_v = let el = elems ar in
                      let nexter = (\i-> (maximum.(\x->0:x).(filter (\x-> (mod x 10) == i))) ([e+item_v|e<-el]++el) ) in
                      listArray (0,9) [nexter i |i<-[0..9]]

solver::[Int]->Int
solver xs = let ini = listArray (0,9) (take 10 (repeat 0)) in
            let dat= foldl propagate ini xs in
            maximum [dat!i|i<-[1..9]]

n_get::Int -> IO [Int]
n_get 0 =return []
n_get n = do
  dc<-getLine
  rest<-n_get (n-1)
  return ((read dc):rest)

main::IO()
main=do
  nc<-getLine
  let n=read nc ::Int
  dat<-n_get n
  print (solver dat)

Measured memory_bytes: 1020