akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N;
vector<ll> ht, bt, arr;
ll dp[2*100*1000+5];

ll st[524288];

ll ConstructST(ll ss, ll se, ll si){
	if(se == ss) return st[si] = arr[ss];
	ll mid = ss + (se-ss)/2;
	return st[si] = max(ConstructST(ss, mid, 2*si+1), 
						ConstructST(mid+1, se, 2*si+2));
}

ll getMax(ll ss, ll se, ll si, ll l, ll r){
	if (l<=ss && se<=r) return st[si];
	if (ss > r || se < l) return -1;

	ll mid = ss + (se-ss)/2;
	return max(getMax(ss, mid, 2*si+1, l, r),getMax(mid+1, se, 2*si+2, l, r));
}

void upDate(ll ss, ll se, ll si, ll i, ll v){
	if (ss == se){
		arr[i] = v;
		st[si] = v;
	}
	else{
		ll mid = ss + (se-ss)/2;
		if (ss <= i && i <=mid)
			upDate(ss, mid, 2*si+1, i, v);
		else
			upDate(mid+1, se, 2*si+2, i, v);
		st[si] = max(st[2*si+1], st[2*si+2]);
	}
}

ll getPos(ll x){
	return getMax(0, N-1, 0, 0, x);
}

void updatePos(ll i, ll v){
	upDate(0, N-1, 0, i, v);
}


ll solve(){
	ll ans = 0;
	for(ll i = 0;i<N;i++){
		dp[ht[i]] = bt[i];
		ll hj = getPos(ht[i]);
		if (hj != -1)
			dp[ht[i]] += hj; 
		updatePos(ht[i], dp[ht[i]]);
		
		//cout<<ht[i]<<" "<<hj<<" "<<dp[ht[i]]<<endl;
		
		ans = max(ans, dp[ht[i]]);
	}
	return ans;
}

int main(){
	cin>>N;
	ll e;
	for(ll i = 0;i<N;i++){cin>>e; ht.push_back(e);}
	for(ll i = 0;i<N;i++){cin>>e; bt.push_back(e);}
	
	for(ll i = 0;i<N;i++){arr.push_back(-1);}
	ConstructST(0, N-1, 0);
	
	cout<<solve()<<endl;
}
	
/*ll solve(){
	ll ans = 0;
	for(ll i = 0;i<N;i++){
		dp[i] = arr[i];
		
		for(ll j = 0;j<i;j++){
			if(ht[j] < ht[i]){
				dp[i] = max(dp[j]+arr[i], dp[i]);
				ans = max(ans, dp[i]);
			}
		}
	}
	//for(ll i = 0;i<N;i++)cout<<dp[i]<<" ";
	return ans;
}*/

Measured memory_bytes: 10736
import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val arg = listOfInt()
    val n = arg[0]
    val d = arg[1]
  	val onePerson = 2*d+1
  	val ans = n/onePerson
  	if(ans*onePerson < n){
      println(ans + 1)
    }else{
      println(ans)
    }
}

// 入力取得
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}


Measured memory_bytes: 37552
#include<cstdio>
struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	int add(int x,int y){return (x+=y)<mod?x:x-mod;}
	int sub(int x,int y){return (x-=y)>=0?x:x+mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
	int pw(int base, int p) {
		int res = 1, mu = base%mod;
		for(;p>0;p/=2) {
			if (p&1) res = mul(res, mu);
			mu = mul(mu, mu);
		}
		return res;
	}
	int rev(int x) {return pw(x, mod-2);}
};
modular_arithmetic ma;
int n;
int c(int x,int y){
	int res = 1;
	for(int i=1; i<=y; i++){
		res=ma.mul(res, x);
		res=ma.mul(res, ma.rev(i));
		x--;
	}
	return res;
}
int calc(int x){
	return c(n+x-1, n-1);
}
int main(){
	int res = 1, m;
	scanf("%d%d",&n,&m);
	for(int i=2; i*i<=m; i++)if(m%i==0){
		int r = 0;
		while(m%i==0)r++,m/=i;
		res = ma.mul(res, calc(r));
	}
	if(m>1)res = ma.mul(res, calc(1));
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,A,B;
	while(cin>>N>>M) {
		VI H(N);
		REP(i, N) cin>>H[i];
		VVI g(N);
		REP(i, M) {
			cin>>A>>B;
			A--;B--;
			g[A].PB(B);
			g[B].PB(A);
		}
		ll ans=0;
		REP(i, N) {
			ll ok=1;
			REP(j, g[i].size()) {
				if(H[i] <= H[g[i][j]]) ok=0;
			}
			if(ok) ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 9368
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if(A*B<=C) {
			System.out.println(A*B);
		}else {
			System.out.println(C);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int solve() {
    int N, M, a, b, d;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int Q;
    cin >> Q;
    vector<int> V(Q), C(Q);
    priority_queue<pii> D;
    for ( int i = 0; i < Q; i++ ) {
        cin >> V[i] >> d >> C[i];
        V[i]--;
        D.push(pii(d, i));
    }
    int DMAX = 10;
    vector<vector<int>> col(DMAX+1, vector<int>(N, -1));
    int d0 = 0;
    for ( int d = DMAX; d >= 0 ; d-- ) {
        while ( !D.empty() && D.top().first >= d ) {
            int j = D.top().second;
            D.pop();
            if ( col[d][V[j]] < j ) col[d][V[j]] = j;
        }
        if ( d == 0 ) break;
        for ( int v = 0; v < N; v++ ) {
            col[d-1][v] = col[d][v];
        }
        for ( int v = 0; v < N; v++ ) {
            for ( int u : G[v] ) {
                if ( col[d-1][u] < col[d][v] ) col[d-1][u] = col[d][v];
            }
        }
    }
    for ( int v = 0; v < N; v++ ) {
        int a = col[0][v] >= 0 ? C[col[0][v]] : 0;
        cout << a << "\n";
    }
    return 0;
}

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

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

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto x : a) cout << x << " "; cout << "\n";

const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
    int n;
    cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    while(n--)
    {
        string s;
        cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "TLE") tle++;
        if(s == "RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

int32_t main()
{
    DESYNC
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3652
n=int(input())
i=1
l=[]
m=[]
while i<=n**0.5:
    if n%i==0:
        l.append(i)
        m.append(n//i)
        i+=1
    else:
        i+=1
o=len(l)
a=[]
for j in range(o):
    a.append(l[j]+m[j])
print(min(a)-2)


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n;
	cin >> n;
	int x = n % 100, y = n / 100;
	if (1 <= x && x <= 12 && 1 <= y && y <= 12 && x > 0 && y > 0) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (1 <= x && x <= 12){
		cout << "YYMM" << endl;
	}
	else if (1 <= y && y <= 12){
		cout << "MMYY" << endl;
	}
	else cout << "NA" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int age;
	int a_g[7] = {0};
	int i;
	
	while (1) {
		
		scanf("%d", &n);
		
		if (n == 0) {
			break;
		}
		else {
			for (i = 0; i < n; i++) {
				
				scanf("%d", &age);
				
				if ((age >= 0) && (age <= 9)) {
					a_g[0]++;
				}
				
				else if ((age >= 10) && (age <= 19)) {
					a_g[1]++;
				}
				
				else if ((age >= 20) && (age <= 29)) {
					a_g[2]++;
				}
				
				else if ((age >= 30) && (age <= 39)) {
					a_g[3]++;
				}
				
				else if ((age >= 40) && (age <= 49)) {
					a_g[4]++;
				}
				
				else if ((age >= 50) && (age <= 59)) {
					a_g[5]++;
				}
				
				else if (age >= 60) {
					a_g[6]++;
				}
			}
		}
		for (i = 0; i < 7; i++){
			printf("%d\n", a_g[i]);
			a_g[i] = 0;
		}
	}
	
	return (0);
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define MSET(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535 
 
 
int32_t main() {
    fastio;
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll xr = 0;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        xr = (xr ^ a[i]);
    }
    for(ll i=0;i<n;i++) {
        cout<< (xr ^ a[i]) <<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
const int p=31;
const int m=1e9+7;
typedef long long ll;
typedef int in;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");} 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define int ll
ll pw(ll x,ll r){
	ll ans=1;
	while(r>0){
		if(r%2)ans=(ans*x)%m;
		r/=2;
		x*=x;
		x%=m;
	}
	return(ans%m);
}
ll ncr[2002][2002];
in main (){
	
    ll s;
    cin>>s;
    ll n=s/3;
    if(s<=0){
    	cout<<0;
    	return 0;
    }	
    ncr[0][0]=1;
    for(int i=1;i<=2001;++i){
    	ncr[i][0]=1;
    	ncr[i][i]=1;
    	for(int j=1;j<=2001;++j){
    		ncr[i][j]=ncr[i-1][j-1]+ncr[i-1][j];
    		ncr[i][j]%=m;
    	}
    }
    ll ans=0;
    for(int i=1;i<=n;++i){
    	ans+=ncr[s-2*i-1][i-1];
    	ans%=m;
    }
	cout<<ans;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; //check time    
}
    


Measured memory_bytes: 34920
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n, m, p;
int x[100];

int main(){
	while(scanf("%d%d%d", &n, &m, &p), n){
		--m;
		rep(i, n){
			scanf("%d", &x[i]);
		}
		if(!x[m]){
			puts("0");
			continue;
		}
		int s = 0;
		rep(i, n){
			s += x[i];
		}
		printf("%d\n", s * (100 - p) / x[m]);
	}
	return 0;
}

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
int ans[11], cur, pos;
char ch[2];

int query(long long x)
{
	printf("? %lld\n",x);
	fflush(stdout);
	scanf("%s",ch);
	if(ch[0]=='Y') return 1;
	return 0;
}

int main()
{
	int len = 1;
	long long now = 1, res;
	for(;len<=11;len++,now*=10) if(!query(now)) break;
	if(len==12)
	{
		now = 9; res = 1;
		for(;;now=now*10+9, res*=10)
			if(query(now))
			{
				printf("! %lld\n",res); fflush(stdout);
				return 0;
			}
	}
	else -- len;
	long long l = 1, r = 1, mid, ans;
	fo(i,2,len) l *= 10; r = l*10-1;
	while(l<=r)
	{
		mid=l+r>>1;
		if(query(mid*10ll)) {ans = mid; r = mid - 1;}
		else l = mid + 1;
	}
	printf("! %lld\n",ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 596
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		char [] n = sc.next().toCharArray();
		int c = 0;
out:	for(int i = 0;i < n.length;i++) {
			for(int j = i + 1;j < n.length;j++) {
				if(n[i] == n[j]) {
					System.out.println("no");
					c = 1;
					break out;
				}
			}
		}
		
		if(c == 0) {
			System.out.println("yes");
		}
	}
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
/* Properties of modulo:
	(a/b)%m ,where m is prime  = (a%m) * (b^(m-2))%m
*/
    /*ROLLING HASH
    Rabin-Karp algorithm for pattern matching in a string in O(n) time
    Calculating the number of different substrings of a string in O(n2logn)
    Calculating the number of palindromic substrings in a string.
    */
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define ll long long
#define pb push_back
#define gcd __gcd
#define nl cout<<"\n"
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
// o_set(ll) name ; -- defining ordered set
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set - returns iterator
bool compare(ll a, ll b){
    return a > b;
}
ll power(ll x, ll ex ) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x);
        ex >>= 1ll;
        x = (x * x);
    }
    return ans;
}
void solve(){
    ll n;
    cin >> n;
    ll ct =0;
    ll p = 100;
    while(p < n){
        p = p * (1.01);
        ct++;
    }
    cout << ct << endl;
}
int main(){
    IOS;
    ll T=1;
    //cin>>T;
    ll t=0;
    while(t++<T){
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

typedef long long ll;
typedef vector<int> vi;
const int MOD = 1e9+7;
const int maxn = 200010;
int n;
vector<int> a;
string s;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        cin >> n;
        for(int i = 0; i < n; i++)
        {
            int aa; cin >> aa;
            a.push_back(aa);
        }
        int cnt=0;
        for(int i = 0; i < n-2; i++){
            for(int j = i+1; j < n-1 and j!=i; j++){
                for(int k = j+1; k < n and k!=j and k!=i; k++){
                    set<int> S; S.insert(a[i]), S.insert(a[j]), S.insert(a[k]);
                    if(S.size()!=3)continue;
                    vector<int> v;
                    for(auto u : S) v.push_back(u);
                    sort(v.begin(), v.end());
                    if(v[0]+v[1]>v[2]) cnt++;
                }
            }
        }
        cout << cnt << "\n";
    }
}


Measured memory_bytes: 3640
// MAGRANT - GNC19 - TEMPLATE 2.1
// 2017/8/6 - AtCoder Regular Contest 080 - Beta
// Significant Time Tags:
// Algorithm: #, #min/
// Coding: #, #min.
// Overall Summary:

#define _CRT_SECURE_NO_WARNINGS

#define N (1<<7)
#define MODULO (1000000007)
#define HA1 (2420609)
#define HA2 (19260817)

#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <complex>
using namespace std;

namespace MRAND
{
	class MRNDS
	{
	public:
		int ngf;
		unsigned int lgf;
		MRNDS()
		{
			ngf = HA1*HA2;
			lgf = HA1 - HA2*ngf;
		}
		MRNDS(long long rgf)
		{
			lgf = rgf&((1LL << 32) - 1LL);
			ngf = (rgf >> 31);
			ngf += 2LL * lgf;
			ngf *= HA2;
			lgf += HA1;
		}
		MRNDS operator* (const MRNDS &mrs)const
		{
			MRNDS Res;
			Res.ngf += ngf*mrs.lgf;
			Res.ngf -= mrs.ngf*lgf;
			Res.ngf *= HA1;
			Res.lgf *= HA2;
			return Res;
		}
	}curl, curr;
	inline void InitRand(MRNDS &Lmrs, MRNDS &Rmrs)
	{
		curl = Lmrs;
		curr = Rmrs;
		curl = curl*curr;
		curl.ngf += HA2;
	}
	inline int GetRand()
	{
		curl = curl*curr;
		return (curl.lgf*HA1 - curr.ngf*HA2);
	}
}

int h, w, n;
int a[100007];
int Ans[N][N];

int main()
{
	scanf("%d%d%d", &h, &w, &n);
	for (int i = 0;i < n;i++)
	{
		scanf("%d", &a[i]);
	}
	int px = 0, py = 0;
	int dir = 1;
	for (int i = 0;i < n;i++)
	{
		if (dir)
		{
			int nd = w - py;
			if (nd >= a[i])
			{
				for (int j = py;j < py + a[i];j++)
				{
					Ans[px][j] = i + 1;
				}
				py += a[i];
				if (py >= w)
				{
					px++;
					py = 0;
				}
				a[i] = 0;
			}
			else
			{
				for (int j = py;j < w;j++)
				{
					Ans[px][j] = i + 1;
				}
				py = w - 1;
				px++;
				a[i] -= nd;
				dir = !dir;
				i--;
			}
		}
		else
		{
			int nd = py + 1;
			if (nd >= a[i])
			{
				for (int j = py;j > py - a[i];j--)
				{
					Ans[px][j] = i + 1;
				}
				py -= a[i];
				a[i] = 0;
				if (py < 0)
				{
					px++;
					py = w - 1;
				}
			}
			else
			{
				for (int j = py;j >= 0;j--)
				{
					Ans[px][j] = i + 1;
				}
				py = 0;
				px++;
				a[i] -= nd;
				dir = !dir;
				i--;
			}
		}
	}
	for (int i = 0;i < h;i++)
	{
		for (int j = 0;j < w - 1;j++)
		{
			printf("%d ", Ans[i][j]);
		}
		printf("%d\n", Ans[i][w - 1]);
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;
public class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader reader = new BufferedReader( new InputStreamReader(System.in));
    int a = Integer.parseInt(reader.readLine());
    double r = 0.0;
    int[] list =new int[a];
    String[] s =  reader.readLine().split(" ");
    for(int i =0;i<a;i++){
      list[i] = Integer.parseInt(s[i]);}
    Arrays.sort(list);
    r = ((double)list[0]+(double)list[1])/2.0;
    for(int i =2;i<a;i++){
 		r = (r+list[i])/2.0;}
      System.out.println(r);}
  }

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long
#define MOD 1000000007

using namespace std;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

ll gcd(ll a, ll b){
  if(a==1 || b==1)return 1;
  if (a < b)swap(a,b);
  
  return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b){
//  cout<<a * b / gcd(a, b)%MOD<<' '<<a * b / gcd(a, b)<<endl;
  return a * b / gcd(a, b)%MOD;
  return a * b / gcd(a, b);
}

// x^n in mod
ll mod_pow(ll x, ll n){
  if(n==0) return 1;

  if(n%2==0){
    return mod_pow(x*x%MOD, n/2) % MOD;
  }else{
    return x * mod_pow(x, (n-1)) % MOD;
  }
}

ll mod_pow_r(ll x, ll n){
  if(x==0)return 0;
  if(n==0) return 1;

  ll ret = 1;
  while(n){
    if(n&1) ret=ret*x%MOD;
    n /= 2;
    x=x*x%MOD;
  }
  
  return ret;
}

int main(){
  ll n;cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
//  sort(a.begin(), a.end());
//  a.erase(unique(a.begin(),a.end()), a.end());

  map<ll,ll> pm;
  rep(i, a.size()){
    for(auto p:prime_factor(a[i])){
      pm[p.first] = max(pm[p.first], p.second);
    }
  }

  ll all_lcm=1;
  for(auto p: pm){
    all_lcm*=mod_pow(p.first, p.second);
    all_lcm%=MOD;
  }

  ll result=0;
  rep(i, a.size()){
    ll inv = mod_pow_r(a[i], MOD-2);
//cout<<all_lcm<<'*'<<inv<<'='<<(all_lcm*inv)%MOD<<endl;
    result += (all_lcm*inv)%MOD;
    result%=MOD;
//cout<<result<<endl;
  }

  cout<<result;

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

int n, k, c, t[N], ans;

int main() {
	cin>>n>>c>>k;
	rep(i, 1, n) 
	    cin>>t[i];
	sort(t + 1, t + n + 1);
	for(int l = 1, r; l <= n; l = r) {
		r = l;
		ans++;
		while(r - l + 1 <= c && t[r] <= t[l] + k) 
			r++;
	}
	printf("%d\n", ans);
}

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

int main(){
	int p[5],k;
	for(int i = 0; i < 5; i++){
		cin >> p[i];
	}
	cin >> k;
	for(int i = 1; i < 5; i++){
		if(( p[i] - p[0]) <= k){
			continue;
		}
		cout << ":(" << endl;
		return 0;
	}
	cout << "Yay!" << endl;
	return 0;
}


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

int main(){
    int64_t minv = 0, bsum = 0;
    priority_queue<int64_t> left;
    priority_queue<int64_t,vector<int64_t>,greater<int64_t>> right;

    int Q;
    cin >> Q;

    int t, a, b;
    cin >> t >> a >> b;
    left.push(a);
    right.push(a);
    bsum = b;

    for(int q=1;q<Q;q++){
        cin >> t;
        if(t==1){
            cin >> a >> b;
            bsum += b;
            int cprev = left.top(), cent;
            if(left.top()==a || right.top()==a || (left.top()<a && a<right.top())){
                left.push(a);
                right.push(a);
            }else{
                if(left.top()>a){
                    left.push(a);
                    left.push(a);
                    int tp = left.top();
                    left.pop();
                    right.push(tp);
                }else{
                    right.push(a);
                    right.push(a);
                    int tp = right.top();
                    right.pop();
                    left.push(tp);
                }
            }
            cent = left.top();
            if(left.size()%2 == 0) minv += abs(cprev-a);
            else minv += abs(cent-a);
        }else{
            cout << left.top() << " " << minv+bsum << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 4588
def main():
    from math import ceil
    N = int(input())
    A, B = [0] * N, [0] * N
    l, r = 0, 0
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    A.sort(), B.sort()
    # 中央値の最大値、最小値
    c_min, c_max = 0, 0
    ans = 0

    if(N % 2):
        N -= 1
        c_min = A[(N + 1) // 2]
        c_max = B[(N + 1) // 2]
        ans = c_max - c_min + 1

    else:
        N -= 1
        c_min = (A[N // 2] + A[N // 2 + 1]) / 2
        c_max = (B[N // 2] + B[N // 2 + 1]) / 2
        ans = (c_max - c_min) * 2 + 1

    print(int(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 25492
d=[1]+[0]*12
for c in input():
	e=[0]*13
	for k in(range(10)if c>'>'else[int(c)]):
		for j in range(13):t=(j*10+k)%13;e[t]+=d[j];e[t]%=10**9+7
	d=e
print(d[5])

Measured memory_bytes: 42604
#include <stdio.h>

int isprime( int n ) {
  for( int i = 2; i * i <= n; i++ ) {
    if( n % i == 0 ) return 0;
  }
  return 1;
}

int main() {
  int n, i, p1, q1, result, resultt;
  for( ;; ) {
    scanf( "%d", &n );
    if( n == 0 )break;
    for( i = n; i >= 0; i-- ) {
      result = isprime( i );
      resultt = isprime( i - 2 );
      if( result == 1 && resultt == 1 ) {
        q1 = i;
        p1 = q1 - 2;
        break;
      }
    }
    printf( "%d %d\n", p1, q1 );
  }
  return 0;
}

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

bool y(int n){
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(n % i == 0) ans++;
  }
  return ans == 8;
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(y(i) && i % 2 == 1) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3580
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(V) sort((V).begin(),(V).end())
#define pb push_back
#define endl '\n'
#define int long long

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// 変数定義
char s;
//

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  int c = 0;
  for(char i = s; i <= 'z'; i++) {
    s = i;
    if(c==1) break;
    c++;
  }
  cout << s << endl;
}


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



  
int main(){
  
  int64_t  a,b,n;
  cin>>a>>b>>n;
  
  int64_t tmp=min(n,b-1);
  
  cout<<(a*tmp)/b<<endl;
  
  
  
  
}

    












Measured memory_bytes: 3636
import math

h = int(input())

count = 0
while True:
    if h == 1:
        break
    h = int(h / 2)
    count += 1
print(pow(2, count + 1) - 1)
exit(0)


l = math.log(h + 1, 2)
print(pow(2, math.ceil(l)) - 1)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		read();
	}

	private static void read() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		System.out.println(s.substring(0, 3));
		br.close();

	}

}


Measured memory_bytes: 32568
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static int x = 0, y = 0, h = 0, w = 0;
	static int sum;
	public static void main(String[] args) {
		while(read()){

		}
	}
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		for(int i = 0; i < n; i++){
			x = sc.nextInt();
			y = sc.nextInt();
			h = sc.nextInt();
			w = sc.nextInt();
			solve();
		}
		System.out.println(sum);
		sum = 0;
		return true;
	}
	static void solve(){
		int capacity_cost = 0, weight_cost = 0;
		int capacity = x + y + h, weight = w;
		if(60 >= capacity){
			capacity_cost = 600;
		}else if(80 >= capacity){
			capacity_cost = 800;
		}else if(100 >= capacity){
			capacity_cost = 1000;
		}else if(120 >= capacity){
			capacity_cost = 1200;
		}else if(140 >= capacity){
			capacity_cost = 1400;
		}else if(160 >= capacity){
			capacity_cost = 1600;
		}

		if(2 >= weight){
			weight_cost = 600;
		}else if(5 >= weight){
			weight_cost = 800;
		}else if(10 >= weight){
			weight_cost = 1000;
		}else if(15 >= weight){
			weight_cost = 1200;
		}else if(20 >= weight){
			weight_cost = 1400;
		}else if(25 >= weight){
			weight_cost = 1600;
		}

		if( weight > 25 || capacity > 160){
			weight_cost = 0;
			capacity_cost = 0;
		}
		sum += Math.max(capacity_cost, weight_cost);
	}
}

Measured memory_bytes: 0
#include "iostream"
#include "algorithm"
#include "string"
using namespace std;

int main() {
	int n, a[15];
	cin >> n;
	int sum = 0, max = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
		if (max < a[i])max = a[i];
	}
	if (max < sum - max)cout << "Yes";
	else cout << "No";
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(a) (a).rbegin(), (a).rend()

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll d[100][100];
ll h, w, t;
ll sx, sy, gx, gy;

vs maze;

int main() {
    int n, m;
    cin >> n;
    vi t(n);
    rep(i, n) cin >> t[i];
    cin >> m;
    vi p(m), x(m);
    rep(i, m) cin >> p[i] >> x[i];

    rep(i, m) {
        int ans = 0;
        rep(j, n) {
            if(j == p[i] -1) ans += x[i];
            else ans += t[j];
        }
        cout << ans << endl;
    }
}

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

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long Q,H,S,D,N;
	cin>>Q>>H>>S>>D>>N;
	long long t1=min(min(4*Q,2*H),S);
	if(2*t1<=D)
    {
        cout <<N*t1<<endl;
    }
    else
    {
        long long sum=0;
        sum+=(N/2)*D;
        N=N-N/2*2;

        if(N>0)
        {
            sum+=N*t1;
        }
        cout<<sum <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    auto B = aryread();
    auto C = aryread();
    auto ans = B.sum();
    foreach (i; 0 .. N - 1)
    {
        ans += (A[i + 1] - A[i] == 1) ? C[A[i] - 1] : 0;
    }
    writeln(ans);
}


Measured memory_bytes: 256
import sys
import numpy as np

n, t = map(int, input().split())
knapsack = np.zeros(t, dtype=np.int64)
cuisines = [tuple(map(int, line.split())) for line in sys.stdin]
cuisines.sort()
tmp_ans = 0
for a, b in cuisines:
    tmp_ans = max(tmp_ans, knapsack.max() + b)
    knapsack[a:] = np.maximum(knapsack[a:], knapsack[:-a] + b)
print(tmp_ans)


Measured memory_bytes: 12500
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;
int main(){
    ll N, C; cin >> N >> C;
    ll T = 100000;
    vl now(2*T+1, 0);
    vll cnt(C, vl(T+1, 0));
    rep(i, 0, N){
        ll s, t, c;
        cin >> s >> t >> c;
        c--;
        cnt[c][s] += 1;
        cnt[c][t] -= 1;
    }
    rep(c, 0, C){
        rep(i, 0, T){
            cnt[c][i+1] += cnt[c][i];
        }
    }
    rep(c, 0, C){
        rep(i, 1, T+1){
            if(cnt[c][i-1] == 0 && cnt[c][i] > 0){
                now[2*i-1] += 1;
            }
            if(cnt[c][i-1] > 0 && cnt[c][i] == 0){
                now[2*i] += (-1);
            }
        }
    }
    rep(i, 0, 2*T){
        now[i+1] += now[i];
    }
    cout << *max_element(now.begin(), now.end()) << endl;
    return 0;
}




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

int main()
{
    int n;
    cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++)
      cin>>arr[i];
      
     vector<int>help(n-1);
    for(int i=0;i<n-1;i++)
      help[i]=arr[i]^arr[i+1];
      
    int start=arr[1];
    for(int i=2;i<n;i++)
    start=start^arr[i];
    vector<int>ans(n);
    ans[0]=start;
    for(int i=0;i<help.size();i++)
    {
        ans[i+1]=help[i]^ans[i];
    }
    
    for(auto x:ans)
     cout<<x<<" ";
    cout<<endl; 
}

Measured memory_bytes: 5528
n = gets.to_i
as = gets.split.map(&:to_i)
p = as.shift
q = p
cnt = 1

as.each do |a|
  if (p<=>q) * (q<=>a) == -1
    cnt += 1
    p = q = a
  else
    q = a
  end
end

puts cnt

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

long long gcd(long long,long long);
long long lcm(long long,long long);
long long member[20];

int main(){
	long long n;	cin>>n;
	for(long long i=0; i<n; i++){
		cin>>member[i];
	}

	vector<long long> memo(pow(2,n));
	for(long long i=1; i<pow(2,n); i++){
		long long maxLCM=1;
		for(long long j=0;j<n;j++){
			if( (i>>j)&1 )maxLCM=lcm(maxLCM, member[j]);
		}
		memo[i]=maxLCM;
	}

	long long ans=0;
	for(long long i=1; i<pow(2,n); i++){

		bool flag=true;
		for(long long j=0;j<n;j++){
			if( (i>>j)&1 )continue;

			if(memo[i] % member[j]==0){
				flag=false;
				break;
			}
		}
		ans+=flag;
	}

	cout<<ans<<endl;

	return 0;
}



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

	return gcd(x, y%x);
}

long long lcm(long long a, long long b){
	return a/gcd(a,b)*b;
}



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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

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

    loop {
        int a = 0, b = 0, N = next<int>();
        unless(N) break;

        times(N, _) {
            int x = next<int>(), y = next<int>();
            if(x >= y) a += x;
            else       b += x;
            if(x <= y) b += y;
            else       a += y;
        }
        cout << a << " " << b ln;
    }

    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))

int main(void){
    int n;
    cin>>n;
    vector<pair<string,int>> vc(n);
    string s[n];
    int  p[n];
    rep(i,0,n){
        cin>>vc[i].first>>vc[i].second;
        vc[i].second*=-1;
        s[i]=vc[i].first;
        p[i]=vc[i].second;
    }
    sort(vc.begin(),vc.end());
    rep(i,0,n){
        rep(j,0,n){
            if(vc[i].first==s[j]&&vc[i].second==p[j]){
                cout<<j+1<<endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
A, B, C, D, E, F = map(int, input().split())
wdp = [0] * (F + 1)
sdp = [0] * (F + 1)
wdp[0] = 1
sdp[0] = 1
resa = 100 * A
resb = 0
for i in range(F + 1):
  if i + A * 100 <= F: wdp[i + A * 100] += wdp[i]
  if i + B * 100 <= F: wdp[i + B * 100] += wdp[i]
for i in range(F + 1):
  if i + C <= F: sdp[i + C] += sdp[i]
  if i + D <= F: sdp[i + D] += sdp[i]
for i in range(1, F + 1):
  if sdp[i] == 0: continue
  w = 0
  for j in range(1, F + 1):
    if i + j > F: break
    if wdp[j] == 0: continue
    if i <= j * E // 100:
      w = j
      break
  if w == 0: continue
  #print(i, i + w)
  #print(float(i) / float(i + w))
  if resb / resa < float(i) / float(i + w):
    resb = i
    resa = i + w
print(resa, resb)

Measured memory_bytes: 42092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <numeric>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	int c = 0;
	string s;
	getline(cin, s);
	REP(i, s.size()){
		if (s[i] >= 'a'&&s[i] <= 'z'){
			s[i] += 'A' - 'a';
		}
	}
	cout << s << "\n";
}

Measured memory_bytes: 1176
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int M = sc.nextInt();
		int[] A = new int[6];
		int pos, goal;
		for (int i = 0; i < 6; ++i) {
			A[i] = sc.nextInt();
		}
		pos = sc.nextInt() - 1;
		goal = sc.nextInt() - 1;
		ArrayList<ArrayList<Integer>> prev = new ArrayList<ArrayList<Integer>>();
		for (int i = 0; i < M; ++i) {
			prev.add(new ArrayList<Integer>());
		}
		int[] N = new int[M];
		for (int i = 0; i < M; ++i) {
			N[i] = sc.nextInt();
			prev.get(i + N[i]).add(i);
		}
		int[] dist = new int[M];
		Arrays.fill(dist, 9999);
		ArrayList<Integer> cur = prev.get(goal);
		for (int i = 0; !cur.isEmpty(); ++i) {
			ArrayList<Integer> next = new ArrayList<Integer>();
			for (int c : cur) {
				if (dist[c] <= i) continue;
				dist[c] = i;
				for (int j = 0; j < 6; ++j) {
					int n = c - A[j];
					if (n < 0 || M <= n) continue;
					for (int cand : prev.get(n)) {
						if (dist[cand] <= i) continue;
						next.add(cand);
					}
				}
				for (int j = 0; j < 6; ++j) {
					int n = c + A[j];
					if (n < 0 || M <= n) continue;
					for (int cand : prev.get(n)) {
						if (dist[cand] <= i) continue;
						next.add(cand);
					}
				}
			}
			cur = next;
		}
		//				System.err.println(Arrays.toString(dist));
		int cd = dist[pos];
		while (true) {
			int dice = sc.nextInt() - 1;
			int move = A[dice];
			int ld = pos - move < 0 ? 9999 : dist[pos - move];
			int rd = pos + move >= M ? 9999 : dist[pos + move];
			if (ld < cd) {
				System.out.println(-1);
				pos = pos - move + N[pos - move];
				cd = ld;
			} else if (rd < cd) {
				System.out.println(1);
				pos = pos + move + N[pos + move];
				cd = rd;
			} else {
				System.out.println(0);
			}
			System.out.flush();
			//						System.err.println("pos:" + pos + " move:" + move + " cd:" + cd + " ld:" + ld + " rd:" + rd);
			if (pos == goal) return;
		}
	}
}

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

int main(){
	long long int n, time;
	cin >> n >> time;

	long long int t[n];

	for(long long int i = 0; i < n; ++i)
		cin >> t[i];

	long long int sum = 0;

	for(int i = 0; i < n - 1; ++i){
		if(t[i + 1] - t[i] < time)
			sum += t[i + 1] - t[i];
		else
			sum += time;
	}

	sum += time;
	cout << sum << endl;

	return 0;
}
		

Measured memory_bytes: 1792
S = input()

cnt = 0
if S[0] != 'A' or S[-1] == 'C' or S[1] == 'C':
    cnt += 1

A = S.replace('A', '')
A = A.replace('C', '')
if len(S) -2 != len(A) or A.islower() == False:
    cnt += 1
if cnt > 0:
    print('WA')
else:
    print('AC')

Measured memory_bytes: 3064
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    String str;
    int i, res;
    int[] dice;

    dice = new int[6];

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      res = 1;
      for(i = 0;i < 6;i++){
        dice[i] = i + 1;
      }

      for(i = 0;i < n;i++){
        str = sc.next();
        if("North".equals(str)){
          nroll(dice);
        }else if("East".equals(str)){
          eroll(dice);
        }else if("West".equals(str)){
          eroll(dice);
          eroll(dice);
          eroll(dice);
        }else if("South".equals(str)){
          nroll(dice);
          nroll(dice);
          nroll(dice);
        }else if("Right".equals(str)){
          rroll(dice);
        }else{
          rroll(dice);
          rroll(dice);
          rroll(dice);
        }
        res += dice[0];
      }
      System.out.println(res);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static void nroll(int[] dice){ //(1265)
    int tmp;
    tmp = dice[0];
    dice[0] = dice[1];
    dice[1] = dice[5];
    dice[5] = dice[4];
    dice[4] = tmp;
    return;
  }

  private static void eroll(int[] dice){ //(1463)
    int tmp;
    tmp = dice[0];
    dice[0] = dice[3];
    dice[3] = dice[5];
    dice[5] = dice[2];
    dice[2] = tmp;
    return;
  }

  private static void rroll(int[] dice){ //(2354)
    int tmp;
    tmp = dice[1];
    dice[1] = dice[2];
    dice[2] = dice[4];
    dice[4] = dice[3];
    dice[3] = tmp;
    return;
  }

}

Measured memory_bytes: 25356
<?php
$S = trim(fgets(STDIN));
$T = '';

while (1) {
    if (strpos($S, 'eraser')!==false) {
        $S = str_replace('eraser', '', $S);
    }elseif (strpos($S, 'erase')!==false) {
        $S = str_replace('erase', '', $S);
    }elseif (strpos($S, 'dreamer')!==false) {
        $S = str_replace('dreamer', '', $S);
    }elseif (strpos($S, 'dream')!==false) {
        $S = str_replace('dream', '', $S);
    }
    else {
        break;
    }
}

echo $S==$T ? 'YES': 'NO';

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

using namespace std;

typedef long long ll;
const ll mod = 1e9+7;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

char opr(int i) {
  if (i == -1) {
    return '-';
  }
  return '+';
}

int main() {
  string s;
  cin >> s;
  vector<ll> v(4);
  for (int i=0; i<4; i++) {
    v[i] = s[i] - '0';
  }
  for (int i=0; i<2; i++) {
    for (int j=0; j<2; j++) {
      for (int k=0; k<2; k++) {
        int op1 = -2 * i + 1;
        int op2 = -2 * j + 1;
        int op3 = -2 * k + 1;
        if (v[0] + op1 * v[1] + op2 * v[2] + op3 * v[3] == 7) {
          cout << v[0] << opr(op1) << v[1] << opr(op2) << v[2] << opr(op3) << v[3] << "=7" << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
	int N, M, K;
	cin >> N >> M >> K;
	bool ok = false;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= M; ++j) {
			if (i * (M - j) + j * (N - i) == K) {
				ok = true;
			}
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
a = []
for i in range(n):
    a0 = list(input())
    a.append(a0)
b = []
for i in range(m):
    b0 = list(input())
    b.append(b0)
now = [0,0]
ans = "No"
count = 0
while now[0] <= n-m and now[1] <= n-m:
    #print([now[0] + count//m,now[1]+count%m],[count//m,count%m])
    if a[now[0] + count//m][now[1]+count%m] == b[count//m][count%m]:
        count += 1
    else:
        count = 0
        if now[1] < n-m:
            now[1] += 1
        else:
            now[1] = 0
            now[0] += 1
    if count == m*m:
        ans = "Yes"
        break
print(ans)

Measured memory_bytes: 3064