akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var words = []string{"maerd", "remaerd", "esare", "resare"}

func reverseString(s string) string {
	t := make([]byte, len(s))
	for i := range s {
		t[len(s)-1-i] = s[i]
	}
	return string(t)
}

func f(s string) bool {
	for _, w := range words {
		if w == s {
			return true
		}
		if strings.HasPrefix(s, w) && f(s[len(w):]) {
			return true
		}
	}
	return false
}

func main() {
	s := reverseString(readString())

	if f(s) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}


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

int main(){
    int x, y;
    while(1){
        cin >> x >> y;
        if(x+y == 0)    break;
        
        int r[4], a[4];
        for(int i = 0; i < 4; i++){
            r[3-i] = x%10;  x /= 10;
            a[3-i] = y%10;  y /= 10;
        }
        
        int hit = 0, blow = 0;
        for(int i = 0; i < 4; i++){
            if(r[i] == a[i]){
                hit++;
                r[i] = a[i] = -1;
            }
        }
        
        for(int i = 0; i < 4; i++){
            if(r[i] == -1)  continue;
            for(int j = 0; j < 4; j++){
                if(i == j)  continue;
                if(r[i] == a[j]){
                    blow++;
                    break;
                }
            }
        }
        
        cout << hit << " " << blow << endl;
    }
    return 0;
}



Measured memory_bytes: 3004
#include<iostream>
using namespace std;
int main(){
    int a[101][101],g,r;
    cin>>g>>r;
    for(int i=0;i<g;i++)
       for(int j=0;j<r;j++)cin>>a[i][j];
    for(int i=0;i<=g;i++)a[i][r]=0;
    for(int j=0;j<=r;j++)a[g][j]=0;
    for(int i=0;i<g;i++){
        for(int j=0;j<r;j++){
            a[i][r]+=a[i][j];
            a[g][j]+=a[i][j];
            a[g][r]+=a[i][j];
        }
    }
    for(int i=0;i<=g;i++){
        for(int j=0;j<=r;j++){
            if(j)cout<<" ";
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;    
}


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

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

int main() {
  int c;
  cin >> c;
  if(c>=400&&c<=599){
    cout << 8 << endl;
  }
  else if(c>=600&&c<=799){
    cout << 7 << endl;
  }
  else if(c>=800&&c<=999){
    cout << 6 << endl;
  }
  else if(c>=1000&&c<=1199){
    cout << 5 << endl;
  }
  else if(c>=1200&&c<=1399){
    cout << 4 << endl;
  }
  else if(c>=1400&&c<=1599){
    cout << 3 << endl;
  }
  else if(c>=1600&&c<=1799){
    cout << 2 << endl;
  }
  else if(c>=1800&&c<=1999){
    cout << 1 << endl;
  }



  return 0;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b;
    cin >> a >> b;
    if(a*b<=0){
        cout << "Zero" << endl;
    }else{
        if(a>0){
            cout << "Positive" << endl;
        }else{
            int64_t diff = abs(b-a);
            if(diff%2==0){
                cout << "Negative" << endl;
            }else{
                cout << "Positive" << endl;
            }
        }
    }
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    deque<char> a,b,c;
    char s[100] = {};
    char t[100] = {};
    char u[100] = {};

    Scs(s);
    Rep(i,strlen(s))
        a.push_back(s[i]);
    Scs(t);
    Rep(i,strlen(t))
        b.push_back(t[i]);
    Scs(u);
    Rep(i,strlen(u))
        c.push_back(u[i]);

    char n = 'a';
    int f = 1;
    while(f){
//        printf ("%c\n", n);
        switch(n){
        case 'a' :
        if( a.empty() ){ 
            printf ("A\n");
            f = 0;
            break;
        }
            n = a.front();
            a.pop_front();
            break;
        case 'b' :
        if( b.empty() ){ 
            printf ("B\n");
            f = 0;
            break;
        }
            n = b.front();
            b.pop_front();
            break;
        case 'c' :
        if( c.empty() ){ 
            printf ("C\n");
            f = 0;
            break;
        }
            n = c.front();
            c.pop_front();
            break;
        }
    }

    return 0;
}



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

const int N = 1010;
const int MOD = 1000000007;

int f[N][N];
string a[N];

int main() {
	memset(f, 0, sizeof(f));
	int n, m; cin >> n >> m;
	for(int i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	f[0][0] = (a[0][0] == '.' ? 1 : 0);
	for(int i = 1 ; i < n ; i++) {
		f[i][0] = f[i - 1][0];
		if(a[i - 1][0] == '#') {
			f[i][0] = 0;
			break;
		}
	}
	for(int j = 1 ; j < m ; j++) {
		f[0][j] = f[0][j - 1];
		if(a[0][j - 1] == '#') {
			f[0][j] = 0;
			break;
		}
	}
	for(int i = 1 ; i < n ; i++) {
		for(int j = 1 ; j < m ; j++) {
			if(a[i - 1][j] == '.') {
				f[i][j] = f[i - 1][j];
			}
			if(a[i][j - 1] == '.') {
				f[i][j] = (f[i][j] + f[i][j - 1]) % MOD;
			}
		}
	}
	cout << f[n - 1][m - 1] << "\n";
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,q,f[N];
ll m;
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
vector<pair<int,int> >vc;
int main()
{
    scanf("%d%lld%d",&n,&m,&q);
    for(int i=1;i<=n;i++) f[i]=i;
    for(int i=1;i<=q;i++)
    {
        int u,v,c;scanf("%d%d%d",&u,&v,&c);
        u++;v++;
        if(!c) f[getf(u)]=getf(v);
        else vc.push_back({u,v});
    }
    for(int i=0;i<vc.size();i++)
        if(getf(vc[i].fi)==getf(vc[i].se)){printf("No\n");return 0;}
    int tot=0;
    for(int i=1;i<=n;i++) if(getf(i)==i) tot++;
    m-=n-tot;
    if((tot<=2||m==n-1)&&vc.size()) {printf("No\n");return 0;}
    if(m<=(ll)tot*(tot-1)/2) printf("Yes\n");
    else printf("No\n");
}


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

int main(){
  int N; cin >> N;
  int A[N]; rep(i,N) cin >> A[i];

  bool flag = true;
  int cnt = 0;

  while (flag) {
    flag = false;
    for (int j=N-1;j>=1;j--){
      if (A[j]< A[j-1]){
        swap(A[j], A[j-1]);
        cnt++;
        flag = true;
      }
    }
  }

  rep(i,N){
    cout << A[i];
    if (i<N-1) cout << " ";
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}

 


Measured memory_bytes: 3088
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]

def check_bomb(x, y):
    cnt = 0
    if S[y][x] == '#':
        return '#'
    if x-1 >= 0:
        if S[y][x-1] == '#':
            cnt += 1
    if x+1 < W:
        if S[y][x+1] == '#':
            cnt += 1
    if y-1 >= 0:
        if x-1 >= 0:
            if S[y-1][x-1] == '#':
                cnt += 1
        if x+1 < W:
            if S[y-1][x+1] == '#':
                cnt += 1
        if S[y-1][x] == '#':
                cnt += 1
    if y+1 < H:
        if x-1 >= 0:
            if S[y+1][x-1] == '#':
                cnt += 1
        if x+1 < W:
            if S[y+1][x+1] == '#':
                cnt += 1
        if S[y+1][x] == '#':
                cnt += 1
    return str(cnt)

for y in range(H):
    for x in range(W):
        print(check_bomb(x, y), end='')
    print('')

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int N, M;
  cin >> N >> M;

  long long sum = (long long)N * M;
  if (N > 1 && M > 1) {
    sum -= 4;  // corners
    sum -= 2 * ((long long)N - 2 + M - 2);  // edges
  } else {
    if (N == 1 && M == 1) sum = 1;
    else {
      sum -= 2;  // edges
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let input_string = '';

process.stdin.on('data', (chunk) => {
    input_string += chunk;
});

process.stdin.on('end', () => {
    let lines = input_string.split('\n');

    const input = lines[0].split(' ').map(x => parseInt(x));
    console.log(input.every((x, i, arr) => arr.length <= (i+1) || x < arr[i+1]) ? 'Yes' : 'No');
});


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> cntAC(n,0), cntWA(n,0);
  int p;
  string s;
  rep(i,m){
    cin >> p >> s;
    p--;
    if(cntAC[p]==1)continue;
    if(s=="AC")cntAC[p]++;
    else cntWA[p]++;
  }
  int totalAC=0, totalWA=0;
  rep(i,n){
    totalAC += cntAC[i];
    if(cntAC[i]==1){
      totalWA += cntWA[i];
    }
  }
  cout << totalAC << ' ' << totalWA << endl;
  return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>

#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
using namespace std;


int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		string s;
		int num_min = 0,num_max = 0;
		cin >> s;
		vector<int> a;

		rep(i,s.size())
		{
			a.pb((int)(s[i] - '0'));
		}

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

		
		int count = 1;
		rep(i,a.size())
		{
			num_max += a[i]*count;
			num_min += a[a.size() - i - 1]*count;
			count *= 10;
		}

		cout << num_max - num_min << endl;
	}
	return 0;
}

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

using namespace std;

long long int  num,w;
int wat[100000+5];
int val[100000+5];
long long  dp[100010][105];

long long knapsack(long long  wt,long long  n)
{
    long long  &ret = dp[wt][n];
    if(wt ==0 || n==0)
        return 0;

    if(ret!=-1)
        return ret;
    ret = 0;

    if(wat[n-1]>wt)
         ret = knapsack(wt,n-1);

    else
    {
         ret = max(ret,max((val[n-1] + knapsack(wt - wat[n-1],n-1)),knapsack(wt,n-1)));
    }
    return ret;
}

int main()
{
    cin>>num>>w;
    for(int i=0;i<num;i++)
    {
        scanf("%lld %lld",&wat[i],&val[i]);
    }
    memset(dp,-1,sizeof dp);
    long long  ans = knapsack(w,num);
    cout<<ans<<endl;
}


Measured memory_bytes: 82304
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll t; cin >> t;
    vector<string> s(10);
    s[1] = ".,!? ";
    s[2] = "abc";
    s[3] = "def";
    s[4] = "ghi";
    s[5] = "jkl";
    s[6] = "mno";
    s[7] = "pqrs";
    s[8] = "tuv";
    s[9] = "wxyz";
    while(t--){
        string a; cin >> a;
        ll now = -1;
        ll id = 0;
        ll n = a.size();
        rep(i,n){
            ll u = a[i] - '0';
            if(u == 0){
                if(now != -1) cout << s[now][id];
                now = -1;
                continue;
            }
            if(now != u){
                now = u;
                id = 0;
            }else{
                id = (id + 1) % s[now].size();
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3176
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define PI acos(-1)
#define eps 1e-10
#define mem(x) memset(x,0,sizeof(x))
#define _for(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define __for(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}

const int INF=0x3f3f3f3f;
const int MAX=1e4+5;
const int MOD=1e9+7;

int n;
int a[MAX],b[MAX];

int main(){
    std::ios::sync_with_stdio(false);
    cin>>n;
    _for(i,1,n) cin>>a[i];
    _for(i,1,n) cin>>b[i];
    //sort(a+1,a+1+n);
    //sort(b+1,b+1+n);
    ll _1=0,_2=0;
    _for(i,1,n){
        b[i]-=a[i];
        if(b[i]<0){
            _1-=b[i];
        }
        else{
            if(b[i]%2==0) _2+=b[i]/2;
            else{
                _1++;
                _2+=b[i]/2+1;
            }
        }
    }
    if(_2>=_1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}





















Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int n,a;
    scanf("%d %d",&n,&a);
    int i,j,k;
    int x[55];
    for(i=0;i<n;i++)
        scanf("%d",&x[i]);
    long long int dp[55][3003];
    for(i=0;i<55;i++)
        for(j=0;j<3003;j++)
            dp[i][j]=0;
    for(i=0;i<n;i++)
    {
        for(j=54;j>0;j--)
            for(k=0;k<3003;k++)
                if(dp[j][k]>0)
                    dp[j+1][k+x[i]]+=dp[j][k];
        dp[1][x[i]]++;
    }
    long long int ans=0;
    for(i=1;i<=n;i++)
        ans+=dp[i][i*a];
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;

int main()
{
	int n;
	pair<int, int> tmp;
	cin >> n;
	int now = 0;
	priority_queue<pair<int, int>> task;
	for (int i = 0; i < n; i++) {
		cin >> tmp.second >> tmp.first;
		tmp.first *= -1;
		task.push(tmp);
	}

	while (!task.empty()) {
		now += task.top().second;
		if (now > -task.top().first) {
			printf("No");
			return 0;
		}
		task.pop();
	}
	
	printf("Yes");

	return 0;
}

Measured memory_bytes: 2420
//package volume_02;
// Railway Ticket


import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			boolean b1 = sc.nextInt() == 1;
			boolean b2 = sc.nextInt() == 1;
			boolean b3 = sc.nextInt() == 1;

			System.out.println(
					b1&&b2 || b3 ? "Open" : "Close");
		}
	}
}

Measured memory_bytes: 26148
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Point2D point = new Point2D.Double(0, 0);
        double D = 0.0;

        while (true) {
            String S = sc.next();

            int d = Integer.parseInt(S.split(",")[0]);
            int r = Integer.parseInt(S.split(",")[1]);

            if (d == 0 && r == 0) break;

            point.setLocation(point.getX() +(double)d * Math.sin(D * (Math.PI / 180)), point.getY() + (double)d * Math.cos(D * Math.PI / 180));
            D += (double)r;
        }

        System.out.println((int) point.getX());
        System.out.println((int) point.getY());
    }
}

Measured memory_bytes: 26044
#include <stdio.h>
int main()
{
     int i, a, b, cnt=0;
     scanf("%d %d", &a, &b);
     for(i=1;i<=3;i++)
     {
          if((a*b*i)%2==1) cnt++;
     }
     if(cnt>=1) printf("Yes");
     else printf("No");
     return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007
#define BOX 200000

typedef long long ll;

#define rep(i, s, e) for(unsigned int i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define uni(a) a.erase(unique(begin(a), end(a)), end(a))
#define sum(a) accumulate(begin(a), end(a), 0)


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; }

int main() {
    ll N;
    vector<ll> A;
    A.reserve(100000);
    cin >> N;
    rep(i, 0, N) {
        ll temp;
        cin >> temp;
        A.push_back(temp);
    }

    ll pattern = 1;
    ll cnt[3] = { 0, 0, 0 };
    rep(i, 0, N) {
        ll tempCnt = A[i];
        if (cnt[0] == tempCnt && cnt[1] == tempCnt && cnt[2] == tempCnt) {
            pattern = pattern * 3 % MOD;
            cnt[0]++;
        }
        else if (cnt[0] == tempCnt && cnt[1] == tempCnt && cnt[2] != tempCnt) {
            pattern = pattern * 2 % MOD;
            cnt[0]++;
        }
        else if (cnt[0] != tempCnt && cnt[1] == tempCnt && cnt[2] == tempCnt) {
            pattern = pattern * 2 % MOD;
            cnt[1]++;
        }
        else if (cnt[0] == tempCnt) {
            cnt[0]++;
        }
        else if (cnt[1] == tempCnt) {
            cnt[1]++;
        }
        else if (cnt[2] == tempCnt) {
            cnt[2]++;
        }
        else {
            pattern = 0;
            break;
        }
    }
    cout << pattern << endl;
    return 0;

}

Measured memory_bytes: 1024
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    if 4*h*n-N*n-N*h>0:
      if (N*h*n)%(4*h*n-N*n-N*h)==0:
        print(h,n,(N*h*n)//(4*h*n-N*n-N*h))
        exit()

Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> a(N);
    vector<ll> S(N+1);
    REP(i, N){
        cin >> a[i];
        S[i+1]=S[i]+a[i];
    }
    ll ans=1e18;
    rep(i,1,N){
        ans=min(ans,llabs(S[N]-2*S[i]));
    }
    cout<<ans<<endl;
}

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

int main() {
    unsigned int a = 0, b = 0, m = 0, x = 0, y = 0, c = 0;
    unsigned int min = 0, amin = 0, bmin = 0;
    unsigned int arra[100001] = {};
    unsigned int arrb[100001] = {};
    int i = 0;
    scanf("%d%d%d", &a, &b, &m);

    amin = bmin = 100000;
    for (i = 0; i < a; i++) {
        scanf("%d", &arra[i]);
        if (amin > arra[i])
            amin = arra[i];
    }
    for (i = 0; i < b; i++) {
        scanf("%d", &arrb[i]);
        if (bmin > arrb[i])
            bmin = arrb[i];
    }
    min = amin + bmin;

    unsigned int premin;
    for (i = 0; i < m; i++) {
        x = y = c = 0;
        scanf("%d%d%d ", &x, &y, &c);
        premin = arra[x - 1] + arrb[y - 1] - c;
        if (premin < min)
            min = premin;
    }

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

    return 0;
}


Measured memory_bytes: 896
/**
 * ?????\?????????
?????\????????????Insertion Sort?????????????????????????????????????????????????????¨??????????????????????????¶??§???????????????????????¢?????´????????????????????§????????????????????£????????????????????????????°????????????????????????´???????????????????????????????????????????????????????????????????????§?????§???????????????????????????????????????????????????????????\?????????????????¨????????£??????????????????????????????????????¨?????§????????????

?????\?????????????¬???????????????¢?????´???????????????????????????

1 insertionSort(A, N) // N??????????´??????????0-?????????????????????A
2   for i ??? 1 ?????? N-1 ?????§
3     v = A[i]
4     j = i - 1
5     while j >= 0 ?????? A[j] > v
6       A[j+1] = A[j]
7       j--
8     A[j+1] = v
N ??????????´????????????°??? A ????????????????????????????????\????????????????????°????????????????????????????????????????????????????????????????????¢?????´????????????????£????????????????????????¢?????´??????????????????????¢???????????????????????¨??????????????????§??????????????\?????´??????????????¨?????? i ??????????????????????????´?????????????????????????????????????????????

??\???
??\??????????????????????????°?????????????????¨?????´??° N ????????????????????????2 ????????????N ????????´??°????????????????????§?????????????????????

??????
????????? N ?????????????????????????????\????????????????¨??????????????????§?????????????????? 1 ??????????????????????????????????????????????´?????????????????????§????????£???????????????????????????????????????????´?????????????????????????????¨?????????????????????????????????¨ Presentation Error ??¨?????????????????§??¨????????????????????????

??¶?´?
1 ??? N ??? 100
0 ??? A ???????´? ??? 1,000
??\?????? 1
6
5 2 4 6 1 3
??\?????? 1 ??????????????????
5 2 4 6 1 3
2 5 4 6 1 3
2 4 5 6 1 3
2 4 5 6 1 3
1 2 4 5 6 3
1 2 3 4 5 6
??\?????? 2
3
1 2 3
??\?????? 2 ??????????????????
1 2 3
1 2 3
1 2 3
 */

#include <iostream>
#include <sstream>

void printArray(unsigned int Array[], unsigned int length);

int main(int argc, char const *argv[]) {
  unsigned int N = 1;
  std::string param;

  while (true) {

  getline(std::cin, param);
  std::istringstream iss(param);
  iss >> N;

  if (N < 1 || N > 100) {
    std::cout << "Error: 1 <= N <= 100" << std::endl;
  } else {
    break;
  }
}

unsigned int A[N];

while (true) {
  bool isValid = true;

  getline(std::cin, param);
  std::istringstream iss(param);
  for (size_t i = 0; i < N; i++) {
    iss >> A[i];
    if (A[i] > 1000) {
      std::cout << "Error: 1 <= A <= 1000" << std::endl;
      isValid = false;
      break;
    }
  }
  if (isValid == true) {
    break;
  }
}
unsigned int v;
int j;
v = j = 0;

printArray(A, N);

for (size_t i = 1; i < N; i++) {
  v = A[i];
  j = i - 1;
  while (j >= 0 && A[j] > v) {
    A[j + 1] = A[j];
    j--;
  }
  A[j + 1] = v;

  printArray(A, N);

}

  return 0;
}

void printArray(unsigned int Array[], unsigned int length) {
  std::ostringstream oss;
  for (size_t i = 0; i < length - 1 ; i++) {
    oss << Array[i] << " ";
  }
  oss << Array[length - 1];
  std::cout << oss.str() << std::endl;
}

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

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int>> v;
    vector<int> v1, v2;
    for (int i = 0; i <= w + 1; i++) {
        v1.push_back(-2);
        v2.push_back(-2);
    }
    v.push_back(v1);
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        vector<int> t;
        t.push_back(-2);
        for (uint32_t j = 0; j < s.size(); j++) {
            if (s[j] == '.') {
                t.push_back(0);
            } else {
                t.push_back(-10);
            }
        }
        t.push_back(-2);
        v.push_back(t);
    }
    v.push_back(v2);
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (v[i][j] < 0) {
                for (int k = -1; k <= 1; k++) {
                    for (int l = -1; l <= 1; l++) {
                        if (k != 0 || l != 0) {
                            v[i+k][j+l]++;
                        }
                    }
                }
            }
        }
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (v[i][j] < 0) {
                cout << "#";
            } else {
                cout << v[i][j];
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main(void){
    int n; cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ans+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3648
#include<bits/stdc++.h> 
using namespace std;
string s[100005];
int n;
map<string,int> ss;
long long  cmd(int m){
	long long x=0;
	for(int i=m-1;i>0;i--) x += i;
	return x;
}
int main()
{
	long long ans=0;
	cin >>n;
	getchar();
	for(int i=0;i<n;i++){
		getline(cin,s[i]);
		sort(s[i].begin(),s[i].end());
		ss[s[i]]++;
	}
	map<string ,int>::iterator it;
	for(it=ss.begin();it != ss.end();it++){
		if(it -> second > 1){
			ans =ans+cmd(it -> second);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	string S; cin >> S;
	int l = S.length();
	using P = pair<int, int>;
	using PP = pair<int, P>;
	priority_queue<PP> que;
	char tmp = S[0];
	int cnt = 1;
	FOR(i, 1, l) {
		if (S[i] == tmp) {
			++cnt;
		} else {
			// push
			if (tmp == '<') {
				que.push(make_pair(cnt, make_pair(i - cnt,i)));
			} else {
				que.push(make_pair(cnt, make_pair(i, i - cnt)));
			}
			tmp = S[i];
			cnt = 1;
		}
	}
	if (tmp == '<') {
	    que.push(make_pair(cnt, make_pair(l - cnt, l)));
	} else {
		que.push(make_pair(cnt, make_pair(l, l - cnt)));
	}
	vi vec(l + 1, -1);
	while (!que.empty()) {
		auto p = que.top(); que.pop();
		REP(i, p.first + 1) {
			if (p.second.first < p.second.second) {
				if (vec[p.second.second - i] != -1) continue;
				vec[p.second.second - i] = p.first - i;
			} else {
				if (vec[p.second.second + i] != -1) continue;
				vec[p.second.second + i] = p.first - i;
			}
		}
		// cout << p.first << " " << p.second.first << " " << p.second.second << endl;
	}
	// debug(vec);
	ll res = 0;
	for (int num : vec) {
		res += num;
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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



const int N = 200005; 

const long long mod = 1000000007; 



using namespace std;



int n, T; 



bool oncir[N], vis[N]; 

int num, sum, cir[N], cur[N]; 



int tp, sta[N]; 

bool insta[N]; 



int match[N], ind[N], siz[N]; 

long long f[N]; 



vector< int > G[N]; 

vector< int > S[N]; 



long long fac[N], inv[N]; 



long long Pow(long long a, long long e) {

	long long ret=1, cnt=a%mod;

	while(e) {

		if(e & 1) ret = ret * cnt % mod;

		cnt = cnt * cnt % mod; 

		e >>= 1; 

	} 

	return ret; 

}



void prepare() {

	fac[1] = 1; 

	for(int i=2; i<=n; ++i) fac[i] = fac[i-1] * i % mod; 

	inv[n] = Pow(fac[n], mod-2); 

	for(int i=n-1; i>=0; --i) inv[i] = inv[i+1] * (i+1) % mod;  

}



long long C(int n, int m) {

	return fac[n] * inv[n-m] % mod * inv[m] % mod; 

}



void dfs_Circle(int u, int f) {

	if(insta[u]) {

		int now; 

		do {

			now = sta[tp--];

			insta[now] = 0; 

			cir[++num] = now; 

			oncir[now] = 1; 

		}while(now != u); 

		++T; 

		return ; 

	}

	vis[u] = 1; 

	insta[u] = 1; 

	sta[++tp] = u; 

	cur[++sum] = u; 

	int size = G[u].size();  

	for(int k=0; k<size; ++k) {
		int v = G[u][k]; 
		if(oncir[v] || v == f) continue; 

		dfs_Circle(v, u); 

	}
	if(insta[u]) {
		sta[tp--] = 0;

		insta[u] = 0;  
	}

}



void dfs_Tree(int u, int f) {

	match[u] = f; 

	int size = G[u].size();  

	for(int k=0; k<size; ++k) {
		int v = G[u][k]; 

		if(oncir[v] || v == f) continue; 

		dfs_Tree(v, u); 

	}

}



void dfs_calc(int u) {

	f[u] = 1; 

	siz[u] = 0; 

	int size = S[u].size(); 
	for(int k=0; k<size; ++k) {
		int v = S[u][k]; 

		dfs_calc(v);

		siz[u] += siz[v]; 

		f[u] = 1ll * f[u] * f[v] % mod * C(siz[u], siz[v]) % mod; 

	}

	++siz[u]; 

}



long long calc() {

	for(int i=1; i<=sum; ++i) ind[cur[i]] = 0; 

	for(int i=1; i<=sum; ++i) {

		int u = cur[i];

		S[u].clear();
		int size = G[u].size();  

		for(int k=0; k<size; ++k) {
			int v = G[u][k]; 

			if(v == match[u]) break; 

			S[u].push_back(v); 

			++ind[v]; 

		}

	}

	S[0].clear();

	for(int i=1; i<=sum; ++i) 

		if(!ind[cur[i]]) S[0].push_back(cur[i]);

	dfs_calc(0);

	return f[0];  

}



int main() {

	

	int u, v; 

	

	int psum=0; 

	long long ans = 1; 

	

	cin >> n; 

	for(int i=1; i<=(n<<1); ++i) {

		cin >> u >> v;  

		G[u].push_back(v+n); 

		G[v+n].push_back(u); 

	}

	

	n <<= 1; 

	for(int i=1; i<=n; ++i) sort(G[i].begin(), G[i].end()); 

	

	prepare(); 

	

	for(int i=1; i<=n; ++i) {

		

		if(vis[i]) continue; 

		

		T = sum = num = tp = 0; 

		dfs_Circle(i, 0); 

		

		if(T != 1) {

			ans = 0; 

			break; 

		}

		

		for(int j=1; j<=num; ++j) dfs_Tree(cir[j], 0); 

		

		long long tmp = 0; 

		

		for(int j=2; j<=num; ++j) match[cir[j]] = cir[j-1]; 

		match[cir[1]] = cir[num]; 

		tmp += calc(); 

		

		for(int j=1; j<num; ++j)  match[cir[j]] = cir[j+1];

		match[cir[num]] = cir[1];

		tmp += calc(); 

		

		psum += sum; 

		ans = 1ll * ans * tmp % mod * C(psum, sum) % mod; 

		

	}

	

	cout << ans << endl; 

	

	return 0; 

	

}

Measured memory_bytes: 32000
program kk
	implicit none
    integer :: n, i, ac, wa, tle, re
    character, allocatable :: s(:)
    
    read(*,*) n
    allocate(s(n))
    read(*,*) s
    !print *, s
    ac = 0
    wa = 0
    tle = 0
    re = 0
    do i = 1, n
    	if (s(i) == 'A') then
        	ac = ac + 1
        else if(s(i) == 'W') then
        	wa = wa + 1
        else if(s(i) == 'T') then
        	tle = tle + 1
        else if (s(i) == 'R') then
        	re = re + 1
        end if
    end do
    print *, 'AC x ', ac
    print *, 'WA x ', wa
    print *, 'TLE x ', tle
    print *, 'RE x ', re
end program kk

Measured memory_bytes: 3088
A,B = map(int, input().split())

def F0(n):
    if n%4 == 1:
        return 1
    if n%4 == 2:
        return n + 1
    if n%4 == 3:
        return 0
    if n%4 == 0:
        return n
    if n == 0:
        return 0


print(F0(A-1)^F0(B))

Measured memory_bytes: 38256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars
    }
    let mut ans = 0;
    let mut l = 0;
    for c in s {
        if is_acgt(c) {
            l += 1;
        } else {
            ans = std::cmp::max(ans, l);
            l = 0;
        }
    }
    ans = std::cmp::max(ans, l);
    println!("{}", ans);
}

fn is_acgt(c: char) -> bool {
    c == 'A' || c == 'C' || c == 'G' || c == 'T'
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;


namespace Test1 {

    class ClassMain {

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int w = ints[0];
                int q = ints[1];
                if (w == 0) { break; }
                //int n = int.Parse(line);
                //if(n==0){break;}
                int[] hei = Enumerable.Repeat(-1, w).ToArray();

                for (int i = 0; i < q; i++) {
                    string[] strs = Console.ReadLine().Split(' ');
                    if (strs[0][0] == 's') {
                        //sleep.
                        int id = int.Parse(strs[1]);
                        int haba = int.Parse(strs[2]);
                        int startX = -1;
                        for (int j = 0; j < w; j++) {
                            if (hei[j] == -1) {
                                bool suceeded = true;
                                for (int dd = 0; dd < haba; dd++) {
                                    if (j + dd >= w) { suceeded = false; break; }
                                    if (hei[j + dd] != -1) { suceeded = false; break; }
                                }
                                if (suceeded) { startX = j; break; }
                            }
                        }
                        if (startX != -1) {
                            for (int len = 0; len < haba; len++) {
                                hei[startX + len] = id;
                            }
                            Console.WriteLine(startX);
                        }
                        else {
                            Console.WriteLine("impossible");
                        }
                    }
                    else { 
                        //wakeup
                        int id = int.Parse(strs[1]);
                        for(int j=0; j<w; j++){
                            if (hei[j] == id) { hei[j] = -1; }
                        }

                    }

                }
                Console.WriteLine("END");
            }   
        }   
    }
}

Measured memory_bytes: 5968
import qualified Data.ByteString.Char8 as B
import Data.List
import qualified Data.Vector.Unboxed as UV

a#b = abs$a-b

main = do
    [n,k] <- map read.words<$>getLine
    h <- UV.unfoldr(B.readInt.B.dropWhile(<'!'))<$>B.getLine
    print $ f n k h

inf = (maxBound::Int) `div` 2
f n k vh=UV.head $ foldl' proc (UV.cons 0 $ UV.replicate (k-1) inf) [1..n-1] where
    proc v0 i = UV.zipWith p (UV.drop i vh) (UV.snoc (UV.tail v0) inf)
        where p h = min (UV.head v0 + h # (vh UV.! (i-1)))


Measured memory_bytes: 5116
#include<stdio.h>
int main(void){
	int m,x,y,w,h;
	scanf("%d",&m);
	int i,j;
	for(i=0;i<m;i++){
		int X,Y;
		int g=0;
		scanf("%d%d%d%d",&x,&y,&w,&h);
		int n;
		scanf("%d",&n);
		for(j=0;j<n;j++){
			scanf("%d%d",&X,&Y);
			if(x<=X&&X<=(x+w)&&y<=Y&&Y<=(y+h))g++;
		}
		printf("%d\n",g);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl
#define MOD  998244353

int main() {
	lint N;
	while (cin >> N, N != 0) {
		vector<lint>P(N);
		vector<lint>J(N - 1);
		rep(i, N) {
			cin >> P[i];
		}
		rep(i, N - 1) {
			cin >> J[i];
		}
		sort(P);
		sort(J);
		lint cnt = 0;
		lint ans = 0;
		lint SP = 0;
		lint SJ = 0;
		rep(i, N) {
			SP += P[i];
		}
		rep(i, N - 1) {
			SJ += J[i];
		}
		cnt = SP + SJ;
		ans = max(ans, cnt);
		for (lint i = 1; i <= N - 1; i++) {
			cnt = (cnt / i - J[i - 1]) * (i + 1);
			ans = max(ans, cnt);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3864
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N=10005;
int n;
int a[N];
bool isprime[N];
int prime[N],tot;
void init(int n=10000)
{
	memset(isprime,true,sizeof(isprime));
	isprime[1]=false;
	for(int i=2;i<=n;i++)
	{
		if(isprime[i]) prime[++tot]=i;
		for(int j=1;j<=tot&&i*prime[j]<=n;j++)
		{
			isprime[i*prime[j]]=false;
			if(i%prime[j]==0) break;
		}
	}
	return;
}
bool check(int p)
{
	if(a[0]%p!=0) return false;
	static int sum[N];
	for(int i=0;i<=p-2;i++)
		sum[i]=0;
	for(int i=0;i<=n;i++)
		sum[i%(p-1)]=(sum[i%(p-1)]+a[i])%p;
	for(int i=0;i<=p-2;i++)
		if(sum[i]) return false;
	return true;
}
int main()
{
	init();
	scanf("%d",&n);
	for(int i=n;i>=0;i--)
		scanf("%d",&a[i]);
	int k=a[0];
	for(int i=1;i<=n;i++)
		k=__gcd(k,a[i]);
	k=abs(k);
	vector<int>res;
	for(int i=1;i<=tot&&prime[i]<=sqrt(k);i++)
		if(k%prime[i]==0)
		{
			res.push_back(prime[i]);
			while(k%prime[i]==0) k/=prime[i];
		}
	if(k>1) res.push_back(k);
	for(int i=1;i<=tot&&prime[i]<=n;i++)
	{
		int p=prime[i];
		if(check(p)) res.push_back(p);
	}
	sort(res.begin(),res.end());
	res.erase(unique(res.begin(),res.end()),res.end());
	for(int p:res)
		printf("%d\n",p);
	return 0;
}

Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
#define coutd if(DEBUG) cout 
#define ff first
#define ss second
#define debug(x) cout << "> x:" << x << endl;
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vii = vector<ii>;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(){
	ios::sync_with_stdio(0);
	ll n;
	cin >> n;
	vector<ii> vs(n);
	for(ll i=0; i<n; ++i) vs[i].ss=i+1, cin >> vs[i].ff;
	sort(all(vs));
	for(ll i=0; i<n; ++i)
		cout << vs[i].ss << (i==n-1?'\n':' ');
}


Measured memory_bytes: 2432
import copy
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
B = copy.copy(A)
B.sort()
A_max = B[-1]
A_max2 = B[-2]

for i in range(n):
    if A[i] < A_max:
        print(A_max)
    elif A[i] == A_max:
        print(A_max2)


Measured memory_bytes: 19296
import java.util.*;

class Main {

    static Stack<Integer> cars;

    static void treat (int car) {
        
        if(car != 0) {
            cars.push(car);
        } else {
            System.out.println(cars.pop());
        }
    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);
        cars = new Stack<Integer>();

        while (sc.hasNext()) {
            int car = sc.nextInt();
            treat(car); 
        }

    }
}

Measured memory_bytes: 12000
object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {
    val n = Scanner.nextInt
    val k = Scanner.nextInt
    val log2k = scala.math.log10(k)/scala.math.log10(2)
    var p = BigDecimal(0)
    (1 to n).foreach(i => {
        val coin_up = scala.math.ceil(log2k - scala.math.log10(i)/scala.math.log10(2))
        if (coin_up < 1) {
            p += BigDecimal(1)/n
        } else {
            p = p + scala.math.pow(0.5,coin_up)/n
        }
    })
    println(p)
}

Measured memory_bytes: 116200
#include<bits/stdc++.h>
using namespace std;
const int nax=305;
double p[nax][nax][nax],ev[nax][nax][nax];

int main(){
    int n;
    cin>>n;
    int cont[4]={0,0,0,0};
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        cont[x]++;
    }
    p[cont[1]][cont[2]][cont[3]]=1;
    for(int c=n;c>=0;c--){
        for(int b=n;b>=0;b--){
            for(int a=n;a>=0;a--){
                if(a==0&&b==0&&c==0){
                    continue;
                }
                if((a+b+c)>n)continue;

                double p_waste = (double)(n-(a+b+c))/n;
                double ev_waste = p_waste/(1-p_waste)+1;
                ev[a][b][c]+=ev_waste*p[a][b][c];

                if(a!=0){
                        double pa=(double)a/(a+b+c);
                    p[a-1][b][c]+=p[a][b][c]*(pa);
                    ev[a-1][b][c]+=ev[a][b][c]*pa;
                }

                if(b!=0){
                    double pb=(double)b/(a+b+c);
                    p[a+1][b-1][c]+=p[a][b][c]*pb;
                    ev[a+1][b-1][c]+=ev[a][b][c]*pb;

                }
                if(c!=0){
                    double pc=(double)c/(a+b+c);
                    p[a][b+1][c-1]+=p[a][b][c]*pc;
                    ev[a][b+1][c-1]+=ev[a][b][c]*pc;
                }

            }
        }
    }
    cout<<setprecision(10)<<ev[0][0][0]<<endl;
    //printf("%.10lf",ev[0][0][0]);

}


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

int main() {
  int n,m,a;
  cin >> n >> m;
  priority_queue<int> q;
  r(i,n){
    cin >> a;
    q.push(a);
  }
  r(i,m){
    int a=q.top();
    a/=2;
    q.pop();
    q.push(a);
  }
  ll sum=0;
  r(i,n){
    sum+=q.top();
    q.pop();
  }
  cout<<sum<<endl;
}

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

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

  if (x/10%111 == 0) {
    cout << "Yes" << endl;
  }
  else if (x%1000%111 == 0) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
    
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    string S;
    cin >> S;

    vector<ll> cnt(26, 0);
    cerr << cnt << endl;
    REP(i, N) cnt[S[i]-'a']++;
    ll res = 1;
    REP(i, 26){
    	res *= (cnt[i]+1);
    	res %= mod;
    }
    res -= 1;
    res += mod;
    res %= mod;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

struct Graph {
    static constexpr int64_t C = -1LL << 60;
    struct Edge { int i, c; };
    struct Vertex { int64_t c; };
    Graph(int n) : n(n), e(n), v(n, { C }) {}
    void add_edge(int i, int j, int c) {
        e[i].push_back({ j, c });
    }
    bool bellman_ford(int64_t& r) {
        v[0].c = 0;
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                if (v[i].c == C) continue;
                for (auto o : e[i]) {
                    int64_t t = v[i].c + o.c;
                    if (t > v[o.i].c) {
                        v[o.i].c = t;
                        if (k == n - 1 && o.i == n - 1) return true;
                    }
                }
            }
        }
        r = v[n - 1].c;
        return false;
    }
    vector<vector<Edge>> e;
    vector<Vertex> v;
    int n;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g.add_edge(a, b, c);
    }

    int64_t r;
    bool b = g.bellman_ford(r);
    if (b) cout << "inf"; else cout << r;
    cout << endl;

    return 0;
}

Measured memory_bytes: 384