akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(void){
	int n,p,can[55],bowl,i;
	while(true){
		cin >> n >> p;
		if(n==0 && p==0){
			break;
		}
		for(i=0; i<n; i++){
			can[i]=0;
		}
		bowl=p;
		i=0;
		while(true){
			if(bowl==0){
				bowl = can[i];
				can[i] = 0;
			}else{
				bowl--;
				can[i]++;
				if(can[i]==p){
					break;
				}
			}
			i++;
			i%=n;
		}
		cout << i << endl;
	}
	return 0;
}

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

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

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

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

ll N;
string S;
//! 1番目がa,2番目がbとなるような並べ方が存在するかどうか
bool solve(int a, int b)
{
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    FOR(i, N - 1, 1)
    {
        if (v[i] == 0)
        {
            //! 狼
            if (S[i] == 'o')
                v.push_back((v[i - 1] + 1) % 2);
            else
                v.push_back(v[i - 1]);
        }
        else
        {
            //! 羊
            if (S[i] == 'o')
                v.push_back(v[i - 1]);
            else
                v.push_back((v[i - 1] + 1) % 2);
        }
    }

    //! 0とN-1の生合成が取れているか?
    if (S[0] == 'o')
    {
        if (v[0] == 0)
        {
            if (v[1] == v[N - 1])
                return false;
        }
        else if (v[1] != v[N - 1])
            return false;
    }
    else
    {
        if (v[0] == 0)
        {
            if (v[1] != v[N - 1])
                return false;
        }
        else if (v[1] == v[N - 1])
            return false;
    }

    if (S[N - 1] == 'o')
    {
        if (v[N - 1] == 0)
        {
            if (v[0] == v[N - 2])
                return false;
        }
        else if (v[0] != v[N - 2])
            return false;
    }
    else
    {
        if (v[N - 1] == 0)
        {
            if (v[0] != v[N - 2])
                return false;
        }
        else if (v[0] == v[N - 2])
            return false;
    }

    REP(i, N)
    {
        if (v[i] == 0)
            cout << 'W';
        else
            cout << 'S';
    }
    cout << endl;
    return true;
}

int main()
{
    cin >> N;
    cin >> S;
    REP(i, 2)
    {
        REP(j, 2)
        {
            if (solve(i, j))
                return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1392
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7;

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

int main() {
  ll x,y; cin>>x>>y;
  ll ans;
  // ナイトの動き方はi,jの合計値が3の倍数になるように動く
  // かつx,yうち大きいほうが小さいほうの2倍以内でなければならない
  if((x+y)%3!=0) ans=0;
  else {
    if(max(x,y)>min(x,y)*2) ans=0;
    else {
      // 答えが存在するのであれば、移動の合計回数は求められる
      int numMove = (x+y)/3;
      int numMove12 = 2*numMove-x;
      // (1,2)で移動する回数を、移動合計回数の組み合わせで考えれば良い
      // n!
      ll fac=1;
      vector<ll> inv(numMove+1);
      for(int i=1; i<=numMove; i++) (fac*=i)%=MOD;
      inv[numMove]=q_pow(fac,MOD-2);
      for(int i=numMove-1; i>=0; i--) inv[i]=inv[i+1]*(i+1)%MOD;
      ans = (fac*inv[numMove-numMove12])%MOD*inv[numMove12]%MOD;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 8520
#include <cstdio>

using namespace std;

int main()
{
        int n, n2;
        char op;

        scanf("%d %c %d", &n, &op, &n2);
        switch (op) {
        case '+':
                printf("%d\n", n + n2);
                break;
        case '-':
                printf("%d\n", n - n2);
                break;
        }

        return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
map<P,bool> mp;
map<P,int> res;
V<ll> d={-1,1,0};
int main(){
    ll h,w,n;
    cin>>h>>w>>n;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        mp[P(a,b)]=1;
    }
    V<ll> ans(10,0);
    for(auto p:mp){
        int y=p.fi.fi,x=p.fi.se;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                int ny=d[i]+y,nx=d[j]+x;
                if(ny>=h||ny<=1||nx>=w||nx<=1)continue;
                res[P(ny,nx)]++;
            }
        }
    }
    ans[0]=h*w-ll(res.size())-(h-1)*2-(w-1)*2;
    for(auto p:res){
        ans[p.se]++;
    }
    for(int i=0;i<10;i++)cout<<ans[i]<<"\n";
}


Measured memory_bytes: 66152
#include <stdio.h>
#include <algorithm>

using namespace std;

int a[200000], b[200000], n;
int x[200000], y[200000];

int num(int t) {
	if (y[0] >= t) return n;
	if (y[n - 1] < t) return 0;
	int lo = 0, hi = n - 1;
	while (lo + 1 < hi) {
		int mid = (lo + hi) / 2;
		if (y[mid] >= t) hi = mid;
		else lo = mid;
	}
	return n - hi;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &b[i]);
	int res = 0;
	for (int k = 0; k < 29; k++) {
		for (int i = 0; i < n; i++) {
			x[i] = a[i] % (1 << (k + 1));
			y[i] = b[i] % (1 << (k + 1));
		}
		sort(y, y + n);
		int b = 0;
		for (int i = 0; i < n; i++) {
			int cnt = num((1 << (k + 1)) + (1 << k) - x[i]) + num((1 << k) - x[i]) - num((1 << (k + 1)) - x[i]);
			b ^= cnt & 1;
		}
		res |= (1 << k)*b;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#define ll long long
int main(){
    ll n;
    scanf("%lld",&n);
    if(n % 2 == 1){
        puts("0");
        return 0;
    }
    ll ans = 0;
    for(ll i = 10; i <= n; i *= 5)
        ans += n / i;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define P pair<int,int>
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);
int main(){
  ll N,ans=0;
  cin>>N;
  for(ll i=1;i<N;i++){
    if((N-i)/i<1 || i*i+i>=N){
      break;
    }
    if((N-i)%i==0){
      ans+=(N-i)/i;
    }
  }
  cout <<ans<<endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    string S;
    cin >> S;

    int l = 0, r = (int)S.length() - 1;
    int ans = 0;
    while (r - l > 0)
    {
        ans += (S[l] != S[r]);
        l++;
        r--;
    }
    std::cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int i,c;
  int a[1000000];
  c=n/2;
  for(i=0;i<n;i++){
    if(n%2==0){
      if(i%2==0)c+=i;
      else c-=i;
    }
    else{
      if(i%2==0)c-=i;
      else c+=i;
    }
    scanf("%d",&a[c]);
  }
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i==n-1)puts("");
    else printf(" ");
  }
  return 0;
}


Measured memory_bytes: 4608
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""042-a"""


import sys


def main():
    """Main function."""
    phrases = sys.stdin.readline()[:-1].split(" ")

    print('YES') if sorted(phrases) == sorted(['5', '7', '5']) else print('NO')


if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 2940
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int sum = 0;
		int cnt = 1;
		for(int i = 0; i < n;i++){
				int l = sc.nextInt();
				sum += l;
				if(sum<=x){
				cnt += 1;
			}
		}
		System.out.print(cnt);
	}
}


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

int main(){
	int N, H, W;
	cin >> N >> H >> W;
	int A[N], B[N];
	int cnt = 0;
	for(int i=0; i<N; i++){
		cin >> A[i] >> B[i];
		if(A[i]>=H && B[i]>= W){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  ll a, b; cin >> a >> b;
  // string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  // ll ans = 0;
  bool ok = (a < 9)&& (b < 9);

  // cout << ans << endl;
  cout << (ok?"Yay!":":(") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3660
import java.util.*;

class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int ans[] = new int[6];
		for(int i=0; i<n; i++){
			double d = in.nextDouble();
			ans[(d<165)?0:(d<170)?1:(d<175)?2:(d<180)?3:(d<185)?4:5]++;
		}
		for(int i=0; i<6; i++){
			System.out.print((i+1) + ":");
			for(int j=0; j<ans[i]; j++)
				System.out.print('*');
			System.out.println();
		}
	}
	
}

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

long long A[100000];

long long gcd(long long a,long long b){
  if(a>b)return gcd(b,a);
  if(a==0)return b;
  return gcd(b%a,a);
}

int main(){
  int N;
  std::cin>>N;
  for(int i=0;i<N;++i){
    std::cin>>A[i];
  }
  long long ans=A[0];
  for(int i=1;i<N;++i){
    ans=gcd(ans,A[i]);
  }
  std::cout<<ans<<std::endl;
  return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
/* Notations
 * 1) 'v' stands for vertex
 * 2) 'low[v]' and 'high[v]' represents the interval the vertex 'v' is controlling
 * 3) 'left' and 'right' represents the interval that we are dealing with
 * 4) Always pass 'v' as the last argument to enable function function overloading 
 */

class SegTree
{
public:
	vector<int> low, high;
	vector<long long> tree;
public:
	SegTree(int n);
	void init(int left, int right, int v);
	void build(vector<long long> &a, int v);
	void update(int ind, long long new_val, int v);
	long long query(int left, int right, int v);
};

SegTree :: SegTree(int n)
{
	low.resize(4*n + 1);
	high.resize(4*n + 1);
	tree.resize(4*n + 1);
	init(0, n-1, 1);
}

void SegTree :: init(int left, int right, int v = 1)
{
	low[v] = left;
	high[v] = right;

	if(left == right)
		return;

	int mid = (left + right)/2;
	init(left, mid, 2*v);
	init(mid + 1, right, 2*v + 1);
}

void SegTree :: build(vector<long long> &a, int v = 1)
{
	if(low[v] == high[v])
	{
		tree[v] = a[low[v]];
		return;
	}

	build(a, 2*v);
	build(a, 2*v + 1);

	tree[v] = max(tree[2*v], tree[2*v + 1]);
}

void SegTree :: update(int ind, long long new_val, int v = 1)
{
	if(ind < low[v] or high[v] < ind)
		return;
	
	if(low[v] == high[v])
	{
		tree[v] = new_val;
		return;
	}

	update(ind, new_val, 2*v);
	update(ind, new_val, 2*v + 1);

	tree[v] = max(tree[2*v], tree[2*v + 1]);
}

long long SegTree :: query(int left, int right, int v = 1)
{
	/* Completely Disjoint */
	if(right < low[v] or high[v] < left)
		return 0;

	/* Completely Contained. */
	if(left <= low[v] and high[v] <= right)
		return tree[v];

	long long left_res = query(left, right, 2*v);
	long long right_res = query(left, right, 2*v + 1);

	return max(left_res, right_res);
}

void Flowers(vector<long long> &a, vector<int> &h)
{
	int n = a.size();

	vector<long long> dp(n, 0);

	SegTree segtree(n);
	segtree.build(dp);

	/* dp[height] represents the maximum beauty of a subsequence which ends with height 'height' */
	for(int i = 0; i < n; i++)
	{
		int curr_height = h[i];

		// Always update the seg tree parallely
		dp[curr_height] = a[i];
		segtree.update(curr_height, dp[curr_height]);

		long long prefix_max = 0;

		/*
		for(int j = 0; j < curr_height; j++)
			prefix_max = max(prefix_max, dp[j]);
		*/
		
		if( curr_height == 0)
			continue;
		
		prefix_max = segtree.query(0, curr_height - 1);

		dp[curr_height] += prefix_max;
		segtree.update(curr_height, dp[curr_height]);
	}

	cout << *max_element(dp.begin(), dp.end()) << endl;
}

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

	vector<int> h(n);
	for(auto &ele : h)
	{
		cin >> ele;
		ele--;
	}
	
	vector<long long> a(n);
	for(auto &ele : a)
		cin >> ele;

	Flowers(a, h);
	return 0;
}



Measured memory_bytes: 16640
N=int(input())
from collections import Counter,defaultdict
s=input()
ddict=defaultdict(int)
for c in s:
  ddict[c]+=1
for i in range(N-1):
  s=input()
  cnt=Counter(s)
  for k in cnt.keys():
    ddict[k]=min(ddict[k],cnt[k])
  for k in ddict.keys():
    if not k in cnt.keys():
      ddict[k]=0
ans=""
for k in range(26):    
  c =chr(ord("a")+k)
  ans+=c*ddict[c]
print(ans)
  


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

int v, e;
bool edge[10010][10010];
bool visited[10010];
stack<int> st;

void dfs(int now){
    visited[now]=true;
    for(int i=0; i<v; i++){
        if(edge[now][i] && !visited[i]){
            dfs(i);
        }
    }
    st.push(now);
    return ;
}

int main(void){
    cin >> v >> e;
    for(int i=0; i<v; i++){
        visited[i]=false;
        for(int j=0; j<v; j++){
            edge[i][j]=false;
        }
    }
    
    
    for(int i=0; i<e; i++){
        int s, t;
        cin >> s >> t;
        edge[s][t]=true;
    }
    
    for(int i=0; i<v; i++){
        if(!visited[i]){
            dfs(i);
        }
    }
    while(!st.empty()){
        cout << st.top() << "\n";
        st.pop();
    }
    
    return 0;
}



Measured memory_bytes: 100860
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c || a + c == b || b + c == a)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
cnt=0
P=[]
for i in range(N):
    a,b=map(int,input().split())
    P.append((a,b))

P=sorted(P)
for i in range(N):
    cnt+=P[i][1]
    if cnt>=K:
        print(P[i][0])
        break

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

char mat[3][3];

int main() {
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j <3; j++){
            cin >>mat[i][j];
        }
    }
    bool flag = false;
    if (mat[0][2] != mat[1][0]) flag = true;
    if (mat[0][0] !=mat[1][2]) flag = true;
    if (mat[0][1] != mat[1][1]) flag = true;;
    if (flag) cout <<"NO" <<endl;
    else cout <<"YES" <<endl;
}


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

using namespace std;

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

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

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

ll dp[2005][2005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll S;
    cin >> S;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    ll ans = 0;
    REP(i, S) {
        if ((i + 1) * 3LL > S)
            break;
        FOR(j, S + 1, i * 3) {
            FOR(k, S + 1, 3) {
                if (k + j > S)
                    break;
                dp[i + 1][k + j] += dp[i][j];
                dp[i + 1][k + j] %= MOD;
            }
        }

        ans = (ans + dp[i + 1][S]) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    int x;
    cin>>x;
    if(x>=30)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String[] arare = new String[N];
    int counterP = 0;
    int counterW = 0;
    int counterG = 0;
    int counterY = 0;
    for(int i = 0; i < N; i++){
      String color = sc.next();
      arare[i] = color;
    }

    for(int j = 0; j < N; j++){
      if(arare[j].equals("P")){
        counterP++;
      }else if(arare[j].equals("W")){
        counterW++;
      }else if(arare[j].equals("G")){
        counterG++;
      }else if(arare[j].equals("Y")){
        counterY++;
      }
    }

    int count = 0;
    if(counterY == 0){
      System.out.println("Three");
    }else{
      System.out.println("Four");
    }

  }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

//* calculate primes using sieve
ll sieve(ll n, vll &prime, vector<bool> &isprime){
    //* return the number of primes <= n
    //* prime[0]~ prime[p-1] record the primes
    //* isprime[0] ~ isprime[n] records the sieve
    ll p = 0;
    rep(i, n+1)
        isprime[i] = true;
    isprime[0] = isprime[1] = false;
    for(ll i=2; i <= n; i++){
        if(isprime[i]){
            prime[p++] = i; 
            for(ll j= 2*i; j <= n; j+= i)
                isprime[j] = false;
        }
    }
    return p;
}
int main(){
    vll prime(1000000);
    vector<bool> isprime(1000000);
    ll num = sieve(999999LL, prime, isprime);
    vll rec(1000000, 0);
    for(ll i=2; i< 1000000; i++){
        if(isprime[i])
            rec[i] = 1;
    }
    for(ll i=1; i< 1000000; i++){
        rec[i]+= rec[i-1];
    }

    ll n;
    while(cin >> n){
        cout << rec[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 18448
a_list = list(input())
b_list = list(input())
c_list = list(input())
x=a_list.pop(0)
while True:
    if x=="a":
        if len(a_list)==0:
            print("A")
            break
        else:
            x = a_list.pop(0)
    elif x == "b":
        if len(b_list)==0:
            print("B")
            break
        else:
            x = b_list.pop(0)
    else:
        if len(c_list)==0:
            print("C")
            break
        else:
            x = c_list.pop(0)
    

Measured memory_bytes: 3064
a, b = gets.split(" ").map(&:to_i)

ary_a = []
a.times do |i|
  ary_a << i 
end

ary_b = []
b.times do |i|
  ary_b << i 
end

p_a = ary_a.combination(2).to_a
p_b = ary_b.combination(2).to_a

puts p_a.size + p_b.size


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
ll inf=1e10;

int main(){
  int N,t[100000],x[100000],y[100000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>t[i]>>x[i]>>y[i];
  int nx(0),ny(0),nt(0);
  for (int i(0);i<N;i++){
    int time=t[i]-nt,dis=abs(nx-x[i])+abs(ny-y[i]);
    if ((dis-time)%2!=0||dis>time){
      cout<<"No"<<endl;
      return 0;
    }
    nx=x[i];ny=y[i];nt=t[i]; 
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

using ll = long long;

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

  vector <ll> a;
  vector <ll> b;
  ll tmp;

  for (int i = 0; i < n + 1; i++){
    cin >> tmp;
    a.push_back(tmp);

  }
  for (int i = 0; i < n; i++){
    cin >> tmp;
    b.push_back(tmp);
  }

  ll cap;
  ll remain = a[0];
  ll cnt = 0;
  for(int i = 0; i < n; i++){
    cap = b[i];

    if(cap >= remain){
      cap -= remain;
      cnt += remain;

      remain = a[i + 1];
      if(cap >= remain){
        cnt += remain;
        remain = 0;
        continue;
      } else {
        cnt += cap;
        remain -= cap;
        continue;
      }
    } else {
      cnt += cap;
      remain = a[i + 1];
      continue;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 2548
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
using namespace std;

//const int mod=1000000007;
const int mod=998244353;



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,m,k,q,x,a,b,c,d,y;
    cin>>x>>y>>a>>b>>c;
    multiset<long long int> C;
    vector<int> v1(a),v2(b),v3(c);
    for (int i=0; i<a; i++) {
        cin>>v1[i];
    }
    for (int i=0; i<b; i++) {
        cin>>v2[i];
    }
    for (int i=0; i<c; i++) {
        cin>>v3[i];
    }
    sort(v1.begin(), v1.end(),greater<int>());
    sort(v2.begin(), v2.end(),greater<int>());
    sort(v3.begin(), v3.end(),greater<int>());
    for (int i=0; i<x; i++) {
        C.insert(v1[i]);
    }
    for (int i=0; i<y; i++) {
        C.insert(v2[i]);
    }
    for (int i=0; i<c; i++) {
        if (v3[i]>*C.begin()) {
            C.erase(C.begin());
            C.insert(v3[i]);
        }
        else{
            break;
        }
    }
    long long int sum=0;
    for (auto it : C){
        sum+=it;
    }
    cout<<sum<<"\n";
    return 0;
    
    
}
    


Measured memory_bytes: 9856
use v5.18; # strict say state

chomp (my ($n, $m) = split / /, <STDIN>);
my %h;
for my $i (1..$m) {
  chomp (my $in = <STDIN>);
  my @c = split ' ', $in;
  $h{$c[1]}++ if $c[0] == 1;
  $h{$c[0]}++ if $c[1] == $n;
}

if (grep {$_ == 2} values %h) {
  say "POSSIBLE";
} else {
  say "IMPOSSIBLE";
}

Measured memory_bytes: 24960
import scala.io.{StdIn => in}

object Main extends App {
  val Array(r, g, b, n) = in.readLine.split(" ").map(_.toInt)

  var cnt = 0
  for {
    i <- 0 to n/r
    j <- 0 to n/g
  } {
    val k = n - r*i - g*j
    if(0 <= k && k%b == 0) {
      cnt += 1
      // debug(i,j,k)
    }
  }

  val ans = cnt
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString != "class Main$")
      println(any.mkString(" "))
  }
}

Measured memory_bytes: 25520
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    intl a = 1;
    while(a <= 100){
        a *= 2;
        if(n < a)break;
    }
    cout << a / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#define ll long long
#define M 100010
#define in(a) scanf("%lld",&a)
using namespace std;
bool visit[M];
ll q,l,r,sum[M];
void s()
{
    memset(visit,true,sizeof(visit));
    visit[1]=0;visit[0]=0;
    for(ll i=2; i<=M; i++)
    {
        if(visit[i]==true)
        {
            for(ll j=2; j*i<M; j++)
            {
                visit[i*j]=false;
            }
        }
    }
    for(ll i=0;i<=M;i++){
    	sum[i]=sum[i-1];if(visit[i]&&visit[(i+1)/2])sum[i]++;
	}
	return;
}
int main(){
	s();
	in(q);
	ll i,j;
	for(i=1;i<=q;i++){
		in(l);in(r);
		printf("%lld\n",sum[r]-sum[l-1]);
	}
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
int main(){
	int N,a[100000];
	vector<int> L;
	scan(N);
	rep(i,N){
		scan(a[i]);
		if(i!=0){
			if(L.back()<a[i]){
				L.push_back(a[i]);
			}
			else{
				L.at(lower_bound(L.begin(),L.end(),a[i])-L.begin())=a[i];
			}
		}
		else{
			L.push_back(a[i]);
		}
	}
	prin(L.size());
	return 0;
}



Measured memory_bytes: 3784
#include<stdio.h>

int main(){
	int i,a,b,c,d;
	a=0;
	b=0;
	c=0;
	for(i=1;i<=10;i++){
		scanf("%d",&d);
		if(d>c)
			if(d>b)
				if(d>a){
					c=b;
					b=a;
					a=d;
				}
				else {
					c=b;
					b=d;
				}	
			else c=d;
	}
	printf("%d\n%d\n%d\n",a,b,c);

	return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << (N - 2) * 180 << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

def main():
    import itertools
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    ans = 0
    for i in itertools.combinations(l, 3):
        if len(set(i)) == 3 and abs(i[0] - i[1]) < i[2] < i[0] + i[1]:
            ans += 1
    print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 73784
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"):
    xmin = W
    xmax = 0
    ymin = H
    ymax = 0
    for i in range(N):
        if a[i] == 1:
            xmax = max(xmax, x[i])
        elif a[i] == 2:
            xmin = min(xmin, x[i])
        elif a[i] == 3:
            ymax = max(ymax, y[i])
        else:
            ymin = min(ymin, y[i])
    print((max(ymin - ymax, 0))* max(xmin - xmax, 0))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    a = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        a[i] = int(next(tokens))
    solve(W, H, N, x, y, a)

if __name__ == '__main__':
    main()


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

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    auto F = factorize(accumulate(A.begin(), A.end(), 0));
    sort(F.begin(), F.end(), greater<int>());

    for (const auto &f: F){
        vector<int> B(n);
        for (int i = 0; i < n; i++)
            B[i] = A[i] % f;
        auto S = accumulate(B.begin(), B.end(), 0);
        auto i = S / f;
        nth_element(B.begin(), B.begin() + (n - i), B.end());
        if (max(accumulate(B.begin(), B.begin() + (n - i), 0), i * f - accumulate(B.begin()+ (n - i), B.end(), 0)) <= k){
            printf("%d\n", f);
            return 0;
        }
    }

    puts("0");
}

Measured memory_bytes: 256
local n = io.read("*n", "*l")
local sum = 0
for i = 1, n do
  local str = io.read()
  local xs, u = str:match("([%d%.]+) (%w+)")
  local x = tonumber(xs)
  if(u == "BTC") then
    sum = sum + 380000 * x
  else
    sum = sum + x
  end
end
print(string.format("%.8f", sum))


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int B[n-1];
    for (int i = 0; i < n - 1; i++){
        cin >> B[i];
    }
    long long res = 0;
    res += B[0];
    res += B[n-2];
    for (int i = 0; i < n - 2; i++){
        if (B[i] <= B[i+1]){
            res += B[i];
        }else {
            res += B[i+1];
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll unsigned long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    set<int>st;
    f1 (9) {
        fr (j,1,10) {
            st.insert(i * j);
        }
    }
    while (cin >> n) {
        if (st.count(n)) {
            cout << "Yes\n";
        }
        else {
            cout << "No\n";
        }
    }
}


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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  int A,B,C;
  cin >> A >> B >> C;
  int out = 0;
  if(A == B){
	if(A == C) cout << "No";
    else cout << "Yes";
    return 0;
  }
  else if(A == C){
	if(A == B) cout << "No";
    else cout << "Yes";
    return 0;
  }
  else if(B == C){
	if(B == A) cout << "No";
    else cout << "Yes";
    return 0;
  }
  else cout << "No";
  return 0;
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
#define SENTINEL 2000000000

struct Card {
  char mark;
  int number;
};

int partition(Card A[], int p, int r){
  int x = A[r].number;
  int i = p - 1;
  for (int j = p; j < r; j++){
    if ( A[j].number <= x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1], A[r]);

  return i+1;
}

void quickSort(Card A[], int p, int r){
  if (p < r){
    int q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}

void merge(Card A[], int left, int mid, int right){
  Card L[100000], R[100000];
  int n1 = mid - left;
  int n2 = right - mid;
  for ( int i = 0; i < n1; i++) L[i] = A[left + i];
  for ( int i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1].number = R[n2].number = SENTINEL;

  int i = 0, j = 0;
  for ( int k = left; k < right; k++){
    if ( L[i].number <= R[j].number ) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(Card A[], int left, int right){
  if (left + 1 < right){
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(){
  int n, val, stable = 1;
  char mark;

  Card A[100000], B[100000];

  cin >> n;
  for ( int i = 0; i < n; i++){
    cin >> mark >> val;
    A[i].mark = B[i].mark = mark;
    A[i].number = B[i].number = val;
  }

  quickSort(A, 0, n-1);
  mergeSort(B, 0, n);

  for ( int i = 0; i < n; i++){
    if (A[i].mark != B[i].mark) stable = 0;
  }
  if (stable) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  for ( int i = 0; i < n; i++) cout << A[i].mark << " " << A[i].number << endl;

  return 0;
}


Measured memory_bytes: 5308
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL)

ll find_minenergy(vector < int > &v , int &k){
	int n = v.size();
	vector < ll > dp(n);
	dp[0] = 0 , dp[1] = abs(v[1] - v[0]);
	for(int i = 2;i < n;i++){
		dp[i] = abs(v[i] - v[i - 1]) + dp[i - 1];
		for(int j = 2;j <= k;j++){
			if(j <= i){
				dp[i] = min(dp[i] , abs(v[i] - v[i - j]) + dp[i - j]);
			}
			else
				break;
		}
	}
	ll ans = dp[n - 1];
	return ans;
}

int main(){
	FastIO;
	int n , k;
	cin >> n >> k;
	vector < int > v;
	for(int i = 0;i < n;i++){
		int element;
		cin >> element;
		v.push_back(element);
	}
	ll ans = find_minenergy(v , k);
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 4544
#include <stdio.h>

int main(void) {
	int a,b,c;
	int max;
	scanf("%d%d%d",&a,&b,&c);
	if((a+b+1)>=c)
		max=b+c;
	else
		max=a+b*2+1;
	printf("%d\n",max);
	return 0;
}


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

const long long mod = 1000000007; 

using namespace std;

int r, b, mx; 
long long c[2005][2005]; 

int main() {

	scanf("%d%d", &r, &b); 
	mx = max(r, b); ++mx;  

	for(int i=0; i<=mx; ++i) 
		for(int j=0; j<=i; ++j) {
			if(j == 0) c[i][j] = 1; 
			else c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod; 
		}

	long long ans = r + 1; 
	for(int s=1; s<=r; ++s) 
		for(int t=0; s+t<=r; ++t) {
			if(s > b-1) continue; 
			if(t > s-1) continue; 
			long long w = 1; 
			w = w * c[b-1][s] % mod; 
			w = w * c[s-1][t] % mod; 
			w = w * c[r - s - t + 2][2] % mod; 
			ans = (ans + w) % mod; 
		}

	printf("%lld\n", ans); 

	return 0; 

}

Measured memory_bytes: 30208
// https://atcoder.jp/contests/abc121/tasks/abc121_c

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    ll sum = 0;
    cin >> n >> m;
    vector<PII> v;
    v.resize(n);

    for (int i = 0; i < n; i++) {
        // 金額、本数
        cin >> v[i].first >> v[i].second;
    }
    //昇順ソート
    sort(ALL(v));

    for (const auto& e : v) {
        int price = e.first;
        int count = e.second;
        if (m <= count) {
            sum += (ll)price * m;
            break;
        } else {
            sum += (ll)price * count;
            m -= count;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1024
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, W = iim()
    S = [list(iim()) for i in range(N)]
    NV = N * 100 + 1

    Inf = float("inf")
    dp = [Inf] * (NV+1)
    dp[0] = 0

    ans = 0
    for v, w in S:
        for i in range(ans, -1, -1):
            j = i + v
            w2 = dp[i] + w
            if dp[i] == Inf: continue
            if w2 > W: continue
            dp[j] = min(dp[j], w2)
            ans = max(ans, j)

    print(ans)

if __name__ == "__main__":
    resolve()



Measured memory_bytes: 5680
w=input()

dict={}
alh="abcdefghijklmnopqrstuvwxyz"
for i in alh:
  dict[i]=0
for i in w:
  dict[i]+=1
flag=True
for i in alh:
  if dict[i]%2==1:
    flag=False
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9000
//abc172_d.cpp
//Sat Jun 27 20:54:56 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

	ll ans = 1;
	for (int i=1;i<=n;i++){
		ll kousu = n/i;
		ll tmp = kousu * (2*i+(kousu-1)*i)/2;
		// cout << i << " " << kousu << " " << tmp << endl;
		ans += tmp;
	}


	cout << ans-1 << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
int main(){
	using namespace std;
	int mor=200,aft=300;
	for(int i=0;i<9;i++){
		string a;
		int b,c;
		cin>>a>>b>>c;
		int goukei=b+c;
		int m=b*200+c*300;
		cout<<a<<" "<<goukei<<" "<<m<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#define sd(x) scanf("%d",&x)
#define ss(x) scanf("%s",x)
#define sc(x) scanf("%c",&x)
#define sf(x) scanf("%f",&x)
#define slf(x) scanf("%lf",&x)
#define slld(x) scanf("%lld",&x)
#define me(x,b) memset(x,b,sizeof(x))
#define pd(d) printf("%d\n",d);
#define plld(d) printf("%lld\n",d);
#define eps 1.0E-8
// #define Reast1nPeace

typedef long long ll;

using namespace std;

const int INF = 0x3f3f3f3f;

int mapp[15][15];

int main(){
#ifdef Reast1nPeace
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n && n){
		memset(mapp,INF,sizeof(mapp));
		
		int m = -1;
		for(int i = 0 ; i<n ; i++){
			int a,b,c; cin>>a>>b>>c;
			mapp[a][b] = mapp[b][a] = c;
			m = max(m , max(a,b));
		}
		
		for(int k = 0 ; k<=m ; k++){
			for(int i = 0 ; i<=m ; i++){
				for(int j = 0 ; j<=m ; j++){
					if(i==j) continue;
					if(mapp[i][j] > mapp[i][k]+mapp[k][j]){
						mapp[i][j] = mapp[i][k]+mapp[k][j];
					}
				}
			}
		}
		
		int id; int minn = INF;
		for(int i = 0 ; i<=m ; i++){
			int sum = 0;
			for(int j = 0 ; j<=m ; j++){
				if(i==j) continue;
				sum += mapp[i][j];
			}
			if(minn > sum){
				minn = sum;
				id = i;
			}
		} 
		cout<<id<<" "<<minn<<endl;
	}
	return 0;
}



Measured memory_bytes: 3032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC087A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, a, b, c;

            x = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            c = (x - a) % b;

            Console.WriteLine(c);

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	int n;
	int ans = 0;
	std::cin >> n;
	std::vector<int> vec;

	for (int i = 0; i < n; ++i) {
		int a;
		std::cin >> a;
		vec.push_back(a);
	}

	std::sort(vec.begin(), vec.end());

	for (int i = 0; i < n - 1; ++i) {
		ans += vec[i];
	}

	ans += vec[vec.size() - 1] / 2;

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

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <set>
#include <queue>
#include <stack>

using namespace std;

#define maxN 100
#define maxM 1000
#define maxC 1000

int main(){
  int a;
  string s;

  cin >> a;
  cin >> s;

  if(a>=3200) cout << s << endl;
  else        cout << "red" << endl;
  return 0;
}


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

int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> ab(m+1);
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        if(a > m) continue;
        ab.at(a).push_back(b);
    }
    priority_queue<int> que;
    int ans = 0;
    for(int i = 1; i <= m; i++){
        for(auto x: ab.at(i)){
            que.push(x);
        }
        if(!que.empty()){
            ans += que.top(); que.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
template<class T,class C> T max(T a,C b){ return ((a)>(T)(b) ? (a) : (T)(b)); }
template<class T,class C> T min(T a,C b){ return ((a)<(T)(b) ? (a) : (T)(b)); }
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0;
  int a[200010]={0};
  string s;
  
  cin >> s;
  n = s.size();
  if(s[n-1]=='s'){
    s += "es";
  }else{
    s += "s";
  }

  cout << s << endl;
  return 0;
}

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

int main() {
  int N,B=0;
  cin >> N;
  
	for(int i=0;i<N;i++){
      int m,A=0;
    	cin>>m;
      while(m%2==0){
		  m/=2;
          A++;	
      }
      if(i==0)B=A;
      if(B>A)B=A; 
    }
cout<<B;
  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define N 300
int main(){
	int n,l;
	cin >> n >> l;
	int sum=0,min=10000,key=0;
	for(int i=0;i<n;i++){
		int temp=l+i;
		sum+=temp;
		int abs=(temp>0)?temp:-temp;
		if(abs<min){
			min=abs;
			key=temp;
		}
	}
	sum-=key;
	cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;
 /*temp*/
 
 
int main(){
	int s;
	cin >> s;
	cout << s/3600		<< ":"
		 << (s/60)%60	<< ":"
		 << s%60		<< "\n";

	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define ll long long
#define l long
#define all(x) x.begin(),x.end()
#define pb push_back
#define len(x) x.len
int main()
{ char c;
cin>>c;
if(isupper(c))cout<<"A";
else cout<<"a";





return 0;
    
}

Measured memory_bytes: 3648
s = input()

def main(string):
    c = "keyence"
    head = string[:7]

    idx = 0
    for s in head:
        if s == c[idx]: idx += 1
        else: break
    if idx == 7:
        print("YES")
        return

    tail = string[-7+idx:]
    for s in tail:
        if s == c[idx]: idx += 1
        else: break        
    
    if idx == 7:
        print("YES")
    else:
        print("NO")

main(s)

Measured memory_bytes: 3060
a, b, c, d = map(int, input().split())
x = c - a
y = d - b
ans = "R" * x + "U" * y + "L" * x + "D" * (y + 1) + \
    "R" * (x + 1) + "U" * (y + 1) + "L" + \
    "U" + "L" * (x + 1) + "D" * (y + 1) + "R"
print(ans)


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

int main() {
	int a, b; cin >> a >> b;
	if (a == b) {
		for (int i = 0; i < a; i++) {
			cout << a;
		}
	}
	else if (a < b) {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
	}
	else {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
    int N,D,x,i;
    scanf("%d",&D);
    scanf("%d",&N);
    if(N==100)
    {
        N++;
    }
    x=N;
    for(i=1;i<=D;i++)
    {
        x*=100;
    }
    printf("%d",x);
    
    
    return 0;
    
}

Measured memory_bytes: 128
while True:
    try:
        N, L = map(int, input().split())
        flavor = [i+L-1 for i in range(1, N+1)]
        mini = 2**31-1
        eaten = -1
        for i in range(N):
            tmp = abs(flavor[i])
            if tmp < mini:
                mini = tmp
                eaten = i
        print(sum(flavor) - flavor[eaten])
    except:
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
template <typename T>
inline void read(T &x)
{
	x = 0;bool b = 0;char c;
	for (c = getchar();!isdigit(c);b |= (c == '-'), c = getchar());
	for (;isdigit(c);x = (x << 1) + (x << 3) + (c ^ 48), c = getchar());
	if (b) x = -x;
}
template <typename T>
inline void write(T x, int base = 10)
{
	if (x < 0) putchar('-'), x = -x;
	static int stk[70];
	int top = 0;
	while (x)
	{
		stk[top++] = x % base;
		x /= base;
	}
	while (top > 0)
	{
		putchar(stk[--top] ^ 48);
	}
}
map<string ,int> mp;
int mx;
int main()
{
	ios::sync_with_stdio(0);
	int n;cin >> n;
	for (int i = 0;i < n;++i)
	{
		string s;cin >> s;
		++mp[s];
	}
	for (map<string, int>::iterator it = mp.begin();it != mp.end();++it)
	{
		mx = max(mx, it->second);
	}
	for (map<string, int>::iterator it = mp.begin();it != mp.end();++it)
	{
		if (it->second == mx)
		{
			cout << it->first << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 23808