akhauriyash/Code-Regression huggingface dataset:
//shakyo
using System;
public class Hello{
    public static void Main(){
        var A = Console.ReadLine();
        var B = Console.ReadLine();
        var C = Console.ReadLine();
        
        var pa = 0;
        var pb = 0;
        var pc = 0;
        
        var cur = A[pa++];
        char ans;
        
        while(true){
            if(cur == 'a'){
                if(pa == A.Length){
                    ans = 'A';
                    break;
                }else{
                    cur = A[pa++];
                }
            }else if(cur == 'b'){
                if(pb == B.Length){
                    ans = 'B';
                    break;
                }else{
                    cur = B[pb++];
                }
            }else{
                if(pc == C.Length){
                    ans = 'C';
                    break;
                }else{
                    cur = C[pc++];
                }
            }
        }
        
        Console.WriteLine(ans);
    }
}


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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int n, r;
	cin >> n >> r;
	if(n <= 10){
		cout << r+(10-n)*100 << endl;
	}else{
		cout << r << endl;
	}
}

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

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

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

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

struct edge{
    int to, w;
};

vector<edge> G[100001];
int col[100001];

void dfs( int s, int d, int prev = -1 ){
    for( auto e : G[s] ){
        if( e.to == prev ) continue;

        if( ( e.w + d ) % 2 == 1 ) col[e.to] = 1;
        else col[e.to] = 0;

        dfs( e.to, ( e.w + d ) % 2, s );
    }
}

int main(){
    int N; cin >> N;
    
    REP( i, N - 1 ){
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--;
        G[u].emplace_back( edge{ v, w } );
        G[v].emplace_back( edge{ u, w } );
    }
    
    dfs( 0, 0 );

    REP( i, N ){
        cout << col[i] << endl;
    }
}

/*

*/

Measured memory_bytes: 8320
from sys import stdin
n,k = map(int,stdin.readline().split())
a = []
for _ in xrange(n):
    x,y = map(int,stdin.readline().split())
    a.append( (x,y) )
a.sort()
cur = 0
for x,y in a:
    cur += y
    if cur >=k:
        break
print x

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

#define REP(i, a, b) for (auto i = (a); i < (b); i++)
#define REPR(i, a, b) for (auto i = (a-1); i >= (b); i--)

using namespace std;

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

    int count = 0;
    bool flagR = false;
    int len = s.length();
    int result = 0;
    REP(i, 0, len)
    {
        if (!flagR)
        {
            if (s[i] == 'R')
            {
                flagR = true;
            }
        }

        if (flagR)
        {
            if (s[i] == 'R')
                count++;
            
            if ((i == (len - 1)) or (s[i] == 'S'))
            {
                result = max(count, result);
                count = 0;
                flagR = false;
            }
        }
    }

    cout << result << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1; // cin >> t;

    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 3580
# -*- coding:utf-8 -*-

def solve():
    """解説実装"""
    import sys
    import heapq

    MAX_S = 50*50
    N, M, S = list(map(int, sys.stdin.readline().split()))
    graph = [[] for _ in range(N)]

    for _ in range(M):
        u, v, a, b = list(map(int, sys.stdin.readline().split()))
        u, v = u-1, v-1
        graph[u].append((v, a, b))
        graph[v].append((u, a, b))

    ryogae = []
    for _ in range(N):
        c, d = list(map(int, sys.stdin.readline().split()))
        ryogae.append((c, d))

    # dp[v][s] := 頂点vに所持金sで訪れるときの最小時間
    dp = [[float("inf") for _ in range(MAX_S+1)] for __ in range(N)]

    # ダイクストラ
    s = min(S, MAX_S)
    que = []
    heapq.heappush(que, (0, 0, s))  # (時刻t, 頂点番号v, 所持金s)

    while len(que) != 0:
        t, v, s = heapq.heappop(que)

        # if dp[v][s] != t: continue  # なにこれ？

        # 両替する場合
        c, d = ryogae[v]
        ns = min(s+c, MAX_S)
        if dp[v][ns] > t+d:
            dp[v][ns] = t+d
            heapq.heappush(que, (t+d, v, ns))

        # 移動する場合(v -> uに移動)
        for u, a, b in graph[v]:
            if s-a < 0: continue
            if dp[u][s-a] > t+b:
                dp[u][s-a] = t+b
                heapq.heappush(que, (t+b, u, s-a))

    for v in range(1, N):
        ans = float("inf")
        for s in range(MAX_S+1):
            ans = min(ans, dp[v][s])
        print(ans)


if __name__ == "__main__":
    solve()


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

int main()
{
  string a, b, c;
  char resulta, resultb, resultc, resultd;
  cin >> a >> b >> c;

  resulta = a[a.length() - 1];
  resultb = b[0];
  resultc = b[b.length() - 1];
  resultd = c[0];

  if (resulta == resultb && resultc == resultd)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	ll MOD = 1000000007;

	int N;
	cin >> N;

	ll x = 1;
	ll y = 1;
	ll z = 1;
	for (int i = 0; i < N; ++i)
	{
		x *= 10;
		y *= 9;
		z *= 8;
		x %= MOD;
		y %= MOD;
		z %= MOD;
	}
	y *= 2;
	y %= MOD;
	ll ans = x;
	ans -= y;
	ans %= MOD;
	ans += z;
	ans %= MOD;
	while (ans < 0)
		ans += MOD;
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 3632
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<d,int>
#define pb push_back
#define cases int tc;cin>>tc;while(tc--)
#define N 100003
#define M 1003
int mod=1e9+7;
//int mod=998244353;

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n,m;
    cin>>n>>m;
    d a[n+1],b[n+1];
    int i,j;
    pii p[n+1];
    for(i=1;i<=n;++i)
    {
        cin>>a[i]>>b[i];
        p[i]={a[i],b[i]};
    }
    sort(p+1,p+n+1);
    int ans=0;
    i=1;
    while(m>0)
    {
        if(m>=p[i].second)
        {
            m-=p[i].second;
            ans+=p[i].second*p[i].first;
        }
        else
        {
            ans+=m*p[i].first;
            m=0;
        }
        ++i;
    }
    cout<<ans;




    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

typedef struct restaurant_t{
    int id;
    string city;
    int score;
} res_t;

bool comp(const res_t & x, const res_t & y) {
    if (x.city == y.city) return x.score > y.score;
    else return x.city < y.city;
}

int main()
{
    int n;
    cin >> n;
    vector<res_t> r;
    for (int i = 0; i < n; i++) {
        res_t _r;
        _r.id = i + 1;
        cin >> _r.city >> _r.score;
        r.push_back(_r);
    }
    sort(r.begin(), r.end(), comp);

    for (int i = 0; i < n; i++) {
        cout << r[i].id << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/range/irange.hpp>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/algorithm/string/classification.hpp>
#include<boost/algorithm/string/split.hpp>
#include<boost/algorithm/string/join.hpp>
using namespace std;
using boost::irange;
using boost::multiprecision::cpp_int;
using boost::algorithm::split;
using boost::is_any_of;
using boost::algorithm::join;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int main(){
    int n, l;
    cin >> n >> l;
    vector<string>a(n);
    for(int i: irange(0, n))cin >> a[i];
    sort(a.begin(), a.end());
    string ans = join(a, "");
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
int isprime(int v) {
    for(int i = 2; i * i <= v; i++) {
        if(v % i == 0)return 0;
    }
    return 1;
}
int main(){
    int i,v;
    int max=0;
    while(scanf("%d", &v) != EOF) {
        for(i=v; i>0; i--){
            if(isprime(i)==1){
                if(isprime(i-2)==1){
                    max=i;
                    break;
                }
            }
        }
        if(v==0)break;
        printf("%d %d\n",max-2,max);
    }
    return 0;
}

Measured memory_bytes: 1804
n = int(input())
nums = list(map(int,input().split()))
nums.sort()
N = nums[-1]
work = 0
resind = 0
for i in range(n):
    if work < min((N-nums[i]),nums[i]):
        work = min((N-nums[i]),nums[i])
        resind = i
print(N,nums[resind])

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    map<int,int>mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    int ans=0;
    rep(i,n){
        bool ok=true;
        mp[a[i]]--;
        for(int j=1; j<=sqrt(a[i]); ++j){
            if(a[i]%j==0){
                if(mp[a[i]/j]!=0||mp[j]!=0)ok=false;
            }
        }
        mp[a[i]]++;
        if(ok)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 32724
while True:    
    (H, W) = [int(i) for i in input().split()]
    if H == 0 and W == 0:
        break
    else:
        while H > 0:
            i = W
            while i > 1:
                print("#",end="")
                i -= 1
            print("#")
            H -= 1
        print("")

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

int main() {
	string S;
	cin>>S;
	set<char> st;
	bool flag=true;
	for(int i=0;i<4;i++){
		st.insert(S[i]);
	}
	if(st.size()!=2) flag=false;
	int cnt=0;
	for(int i=1;i<4;i++){
		if(S[i]==S[0]) cnt++;
	}
	if(cnt!=1) flag=false;
	cout<<(flag? "Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t,a[110];
int main()
{
	cin>>n;
	a[0]=1;a[1]=2;t=1;
	while(1)
	{
		if(a[t]>n) break;
		a[++t]=a[t-1]*2;
	}
	cout<<a[t-1];
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,a,b,j=0,j2=0;
    cin>>n>>a>>b;
    a+=b;
    string s;
    cin>>s;
    f(i,0,n){
        if(s[i]=='a'){
            if(j<a){
                cout<<"Yes"<<endl;
                j++;
            }
            else{
                cout<<"No"<<endl;
            }
        }
        else if(s[i]=='b'){
            if(j<a&&j2<b){
                cout<<"Yes"<<endl;
                j++;
                j2++;
            }
            else{
                cout<<"No"<<endl;
            }
        }
        else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 896
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main(){
    input! {
        alpha: char,
    }

    if alpha.is_uppercase() {
        println!("A")
    } else {
        println!("a")
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;
 
 int main(){
	 int a,b;
	 cin >> a >> b;
	 if((a+b)%2) cout << "IMPOSSIBLE" << endl;
	 else cout << (a+b)/2 << endl;
   return 0;
 }

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	4 * MAX5;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;
const int N = 1e4;

ll vis[N]; vll adj[N];

// <------------- Declare Variables Here ------------> //

ll t = 1;
ll n, m, s, cnt = 1, sum, u, v;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	ll x,l;
	cin >> n>> x;
	for(ll i=0;i<n;i++) {
		cin >> l;
		sum += l;
		cnt += (sum <= x);
	} 
	cout<<cnt;
}

int main() {
	fastio; randomINT;
	//cin >> t;
	while (t--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    int odd = 0;
    forn(i, n) {
        int x;
        cin >> x;
        odd += x % 2;
    }
    cout << (odd % 2 ? "NO" : "YES") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

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

int main()
{   
    int n, c, k;
    cin >> n >> c >> k;

    vector<int> t(n);
    REP(i, n)   cin >> t[i];

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

    int bus_time = t[0], bus_cnt = 1, ppl = 0;

    REP(i, n) {

        if (bus_time <= t[i] && t[i] <= (bus_time+k) && ppl < c) {
            ppl++;
        }

        else {
            ppl = 1;
            bus_cnt++;
            bus_time = t[i];
        }
    }

    cout << bus_cnt << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
using namespace std;
int main()
{
    int N, Y;
    cin >> N >> Y;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            if (10000 * i + 5000 * j + 1000 * (N-i-j) == Y) {
                cout << i << ' ' << j << ' ' << N-i-j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,k,d=0;
    cin>>a>>b>>c>>k;
    for(int i=0;i<k;i++){
        if(i<a){
            d++;
        }
        else if(a<=i&&i<a+b){
            
        }
        else{
            d-=1;
        }
    }
    cout<<d;
}


Measured memory_bytes: 3632
#![allow(non_snake_case, unused_mut)]
use std::collections::HashMap;
fn main() {
    proconio::input! {
        n:usize,
        A:[usize;n]
    }
    let mut B = HashMap::new();
    for i in 0..n {
        *B.entry(A[i]).or_insert(0) += 1;
    }
    let mut sum = 0usize;
    for (_, &v) in B.iter() {
        sum += v * (v - 1) / 2;
    }
    for i in 0..n {
        let val = B.get(&A[i]).unwrap();
        let ans = sum + 1 - val;
        println!("{}", ans);
    }
}


Measured memory_bytes: 11548
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let N = parseInt(xs[0]);
   let W = parseInt(xs[1]);
   let H = parseInt(xs[2]);
   console.log((N - H + 1) * (N - W + 1));
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 29632
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;
bool debug = false;
const int NIL = -1;
const int INF = 1000000000;
const int NUM = 100010;
clock_t START, END;
int T[50001];

struct Node {
	int v, w;
};
Node items[101];
int C[101][10001];

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in29.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	};
	int N, W;
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		cin >> items[i].v >> items[i].w;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= W; j++) {
			if (items[i].w <= j)
				C[i][j] = max(C[i - 1][j], C[i - 1][j - items[i].w] + items[i].v);
			else
				C[i][j] = C[i - 1][j];
		}
	}
	cout << C[N][W] << endl;
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


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

int main() {
    int N,max=2,ret=0,i,j;
    cin>>N;
    vector<int> a(N);
    for(i=0;i<N;i++){
        cin>>a[i];
        if(max<a[i]) max=a[i];
    }
    vector<bool> p(max+1,true);
    for(i=2;i*i<=max;i++){
        if(p[i])for(j=i*2;j<=max;j+=i)p[j]=false;
    }
    for(i=0;i<N;i++){
        if(p[a[i]])ret++;
    }
    cout<<ret<<endl;
    return 0;
}


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

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    vector <string> a = {"hon", "pon", "bon"};
    vector <int> get = {1, 1, 0, 2, 0, 0, 1, 0, 1, 0};
    int t;
    cin >> t;
    cout << a[get[t % 10]];
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;

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();    
    int d = sc.nextInt();    
    int e = sc.nextInt();    
    int K = sc.nextInt();    

	if(K>=b-a && K>=c-a && K>=d-a && K>=e-a && K>=c-b && K>=d-b && K>=e-b && K>=d-c && K>=e-c && K>=e-d){
		System.out.println("Yay!");
	}else{
		System.out.println(":(");
	}
	}
}

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

typedef long long ll;

const int N_MAX = 100000;
int N;

ll T;
int Q;

vector<ll> meet;

ll A[N_MAX];
int D[N_MAX];
int E[N_MAX];

int swi;
ll againster;
int x;
int main()
{
	cin >> N >> T >> Q;
	swi = 2;
	for(int i = 0;i < N;i++)
	{
		cin >> A[i];
		cin >> D[i];
		if(D[i] == 1)
		{
			swi = 1;
			againster = A[i];
		}
		else if (swi == 1 && D[i] == 2)
		{
			meet.push_back((againster + A[i]) / 2);
			swi = 2;
		}
		E[i] = meet.size();
	}
	for(int i = 0;i < Q;i++)
	{
		cin >> x;
		x--;
		if(D[x] == 1)
		{
			if(E[x] == meet.size())
			{
				cout << A[x] + T;
			}
			else
			{
				cout << min(A[x] + T,meet[E[x]]);
			}
		}
		else
		{
			if(E[x] == 0)
			{
				cout << A[x] - T;
			}
			else
			{
				cout << max(A[x] - T,meet[E[x] - 1]);
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 4792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUF_SIZE 400

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

// u k v_1 v_2
int fget_array(int *arr, int* size, int *id) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    int i;
    char *tmp;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    tmp = strtok(line, " ");
    int u = strtol(tmp, NULL, 10);
    tmp = strtok(NULL, " ");
    int k = strtol(tmp, NULL, 10);
    for(i = 0; i < k; i++) {
        tmp = strtok(NULL, " ");
        arr[i] = strtol(tmp, NULL, 10);
    }
    *id = u; *size = k;
#else
#error
#endif
    return 0;
}

#define VERTEX_MAX 100

static int start = 0;
static int end = 0;
int queue[VERTEX_MAX+1];

void enqueue(int v) {
    queue[end++] = v;
}

int dequeue(void) {
    return queue[start++];
}

int is_empty(void) {
    return start == end;
}

int main(void) {
    int vs = get_int();
    int i, j;
    int buf[VERTEX_MAX];
    static int map[VERTEX_MAX+1][VERTEX_MAX+1];
    for(i = 0; i < vs; i++) {
        int size, id;
        fget_array(buf, &size, &id);
        for(j = 0; j < size; j++) {
            // directed graph
            map[id][buf[j]] = 1;
        }
    }

    int dist[VERTEX_MAX+1];
    for(i = 1; i <= vs; i++) {
        dist[i] = -1;
    }

    int start = 1; int steps = 0;
    int nv;
    // we can merge dist variable, but simple is best choice.
    int checked[VERTEX_MAX+1] = {0};
    enqueue(start);
    checked[start] = 1; dist[start] = steps;
    while(!is_empty()) {
        int v = dequeue();
        steps++;
        for(nv = 1; nv <= vs; nv++) {
            if(map[v][nv] && !checked[nv]) {
                dist[nv] = dist[v] + 1;
                checked[nv] = 1;
                enqueue(nv);
            }
        }
    }

    for(i = 1; i <= vs; i++) {
        printf("%d %d\n", i, dist[i]);
    }
    return 0;
}


Measured memory_bytes: 2132
import bisect

def cumsum(a):
    s = 0
    sums = [0]
    for a_i in a:
        s+=a_i
        sums.append(s)

    return sums

def main():
    n,m,k = tuple([int(t)for t in input().split()])

    a = [int(t)for t in input().split()]
    b = [int(t)for t in input().split()]

    acusum = cumsum(a)
    bcusum = cumsum(b)

    a_index = bisect.bisect(acusum,k)
    b_index = bisect.bisect(bcusum,k-acusum[a_index-1])

    ans = a_index+b_index-2

    while a_index > 0:
        a_index -= 1
        b_index = bisect.bisect(bcusum,k-acusum[a_index-1])

        ans = max(a_index+b_index-2,ans)
    
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 47548
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, a[1003] = {}, b[1003] = {}, c[1003] = {}, d[1003] = {}, e[1003] = {}, f[1003] = {}, o = 0, p = 0, u[3030] = {}, v[3030] = {};
    ll z = 0;
    bool g[3030][3030] = {}, h[3030][3030] = {}, l[3030][3030] = {};
    set<int> s, t;
    s.insert(0); t.insert(0);
    map<int, int> q, r;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i], s.insert(a[i]), s.insert(b[i]), t.insert(c[i]);
    for (int i = 0; i < m; i++) cin >> d[i] >> e[i] >> f[i], s.insert(d[i]), t.insert(e[i]), t.insert(f[i]);
    for (int i : s) q[i] = ++o, u[o] = i;
    for (int i : t) r[i] = ++p, v[p] = i;
    //cout << o << ' ' << p << '\n';
    for (int i = 0; i < n; i++) a[i] = q[a[i]], b[i] = q[b[i]], c[i] = r[c[i]];
    for (int i = 0; i < m; i++) d[i] = q[d[i]], e[i] = r[e[i]], f[i] = r[f[i]];
    //for (int i = 0; i < n; i++) cout << a[i] << ' ' << b[i] << ' ' << c[i] << '\n';
    //for (int i = 0; i < m; i++) cout << d[i] << ' ' << e[i] << ' ' << f[i] << '\n';
    for (int i = 0; i < n; i++) for (int j = a[i]; j < b[i]; j++) h[j][c[i]] = 1;
    for (int i = 0; i < m; i++) for (int j = e[i]; j < f[i]; j++) g[d[i]][j] = 1;
    queue<pii> k;
    k.push({q[0], r[0]});
    l[q[0]][r[0]] = 1;
    while (!k.empty()) {
        int x = k.front().first, y = k.front().second;
        if (x == 0 || x == o + 1 || y == 0 || y == p + 1) {
            cout << "INF";
            return 0;
        }
        k.pop();
        if (!g[x][y] && !l[x - 1][y]) l[x - 1][y] = 1, k.push({x - 1, y});
        if (!g[x + 1][y] && !l[x + 1][y]) l[x + 1][y] = 1, k.push({x + 1, y});
        if (!h[x][y] && !l[x][y - 1]) l[x][y - 1] = 1, k.push({x, y - 1});
        if (!h[x][y + 1] && !l[x][y + 1]) l[x][y + 1] = 1, k.push({x, y + 1});
    }
    for (int i = 0; i <= o + 1; i++) {
        for (int j = 0; j <= p + 1; j++) if (l[i][j]) {
            z += 1ll * (u[i + 1] - u[i]) * (v[j + 1] - v[j]);
        }
    }
    cout << z;
}


Measured memory_bytes: 31148
use text_io::*;
// use std::collections::*;
// use std::process::exit;

fn main() {
    let mut x:i128 = read!();
    let k:i128 = read!();
    let d:i128 = read!();
    if x.abs()-(k*d)<=0 {
        if x.abs()/d%2==k%2 {
            println!("{}",x.abs()%d);
        }
        else {
            if (x.abs()%d-d).abs()<(x.abs()%d+d).abs() {
                println!("{}",(x.abs()%d-d).abs());
            }
            else {
                println!("{}",(x.abs()%d+d).abs());
            }
        }
    }
    else {
        println!("{}",x.abs()-(k*d));
    }
}

Measured memory_bytes: 2192
#include <stdio.h>

int main(void) {
   
   int A,B;
   scanf("%d%d",&A,&B);
   
   if ((A + B)%2 == 1) {
      printf("IMPOSSIBLE\n");
   }
   else {
      printf("%d\n", (A + B)/2);
   }
   
   return 0;
   
}


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

int Digits_count(int number){
  int x = 0;
  int Dig = 0;
  while(number != 0){
    Dig = number % 10;
    x += Dig;
    number /= 10;
  }
  return x;
}
int main(void){
  int n,a,b;
  cin >> n >> a >> b;
  int ans = 0;
  for(int i = 0;i <= n;i++){
    if(a <= Digits_count(i) && Digits_count(i) <= b){
      ans += i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// Problem : C - Dubious Document
// Contest : AtCoder - AtCoder Beginner Contest 058
// URL : https://atcoder.jp/contests/abc058/tasks/arc071_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;

string check(string s1, string s2){
    string ans = "";
    int n1 = s1.size(), n2 = s2.size();
    for(int i = 0; i < n1; i++){
        for(int j = 0; j < n2; j++){
            if(s1[i]==s2[j]){
                s2[j] = '?';
                ans+=s1[i];
                break;
            }
        }
    }
    return ans;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	string ans,s;
	unordered_map<int, int> m;
	for(int i = 0; i < n; ++i){
	    cin >> s;
	    if(i==0){
	        ans = s;
	    }
	    else{
	        ans = check(ans, s);
	    }
	}
	sort(ans.begin(), ans.end());
	cout << ans;
	//cout << check("aaa","aa");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;

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

const ll MX = 200005;
ll N, A[MX], B[MX];

bool cmp(ll&a, ll&b){
    return a > b;
}

bool solve(){
    sort(B, B+N, cmp);
    int b = MX, e = -1;
    for(int i=0; i<N; i++){
        if(A[i] == B[i]){
            b = min(b, i);
            e = max(e, i);
        }
    }
    if(e < 0) return true;

    int t = A[b];
    int ab = MX, ae = -1, bb = MX, be = -1;
    for(int i=0; i<N; i++){
        if(A[i] == t){
            ab = min(ab, i);
            ae = max(ae, i);
        }
        if(B[i] == t){
            bb = min(bb, i);
            be = max(be, i);
        }
    }
    int b1 = min(ab, bb), e1 = max(ae, be);
    int sn = (b1 + N - e1 - 1);
    if(sn < e - b + 1) return false;

    int j = b;
    for(int i=0; i<b1 && j<=e; i++, j++){
        swap(B[i], B[j]);
    }   

    for(int i=e1+1; i<N && j<=e; i++, j++){
        swap(B[i], B[j]);
    }
    return true;

}

int main(){
   // freopen("in.txt", "r", stdin);
    cin>>N;
    for(int i=0; i<N; i++){
        cin>>A[i];
    }
    for(int i=0; i<N; i++){
        cin>>B[i];
    }
    if(solve()){
        cout<<"Yes"<<endl;
        for(int i=0; i<N; i++){
            cout<<B[i]<<" ";
        }
        cout<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  int N;
  cin >> N;
  int odd=0;
  int four=0;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    if(A[i]%2==1){
      odd++;
    }else if(A[i]%4==0){
      four++;
    }
  }

  if(odd-1<=four){
    if(odd<=four){
      cout << "Yes" << endl;
    }else{
      if(odd+four==N){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }
  }else{
    cout << "No" << endl;
  }
  
  
}

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

int main(){

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

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

    if((n-1)%(k-1) ==0){
        cout << (n-1)/(k-1) << endl;
    }else{
        cout << (n-1)/(k-1) + 1 << endl;
    }
    
}

Measured memory_bytes: 256
S = input()
T = input()

d1 = {}
d2 = {}

flag = 1

for s,t in zip(S,T):
    if not s in d1:
        d1[s] = t
    elif d1[s] != t:
        print('No')
        flag = 0
        break
    if not t in d2:
        d2[t] = s
    elif d2[t] != s:
        print('No')
        flag = 0
        break

if flag:
    print('Yes')

Measured memory_bytes: 3632
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
	ll n=read(),ans=0;
	rep(i,0,n) ans+=(n-i)*(i+1);
	rep(i,1,n-1)
	{
		ll l=read(),r=read(); if(l>r) swap(l,r);
		ans-=l*(n-r+1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    ll N, *A, *L, *R;
    cin >> N;
    A = new ll[N], L = new ll[N], R = new ll[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        L[i] = A[i] + i;
        R[i] = i - A[i];
    }

    map<ll,ll> m;
    ll ans = 0;
    for (ll i = N-1; i >= 0; i--) {
        ans += m[L[i]];
        m[R[i]]++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 30944
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var ansu = Math.Ceiling(N / 1.08);
            var ansl = Math.Floor(N / 1.08);
            if (N == (long)Math.Floor(ansu * 1.08))
            {
                WriteLine(ansu);
            }
            else if(N == (long)Math.Floor(ansl * 1.08))
                    {
                WriteLine(ansl);
            }
            else
            {
                WriteLine(":(");
            }
            //Out.Flush();
        }
    }
}

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

using ll=long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define ALL(v) v.begin(),v.end()


const ll MOD=(int)(1e9)+7;
vector<ll> fact;
vector<ll> invfact;

const int SIZE=4*(int)(1e6);

ll powm(ll x,ll k){
  ll res=1;
  while(k){
    if(k&1) res*=x;
    res%=MOD;
    x*=x;
    x%=MOD;
    k>>=1;
  }
  return res;
}

ll mod_inverse(ll x){
  return powm(x,MOD-2);
}

void init(){
  fact.assign(SIZE,0);
  fact[0]=1;
  for(int i=0;i+1<SIZE;i++){
    fact[i+1]=(i+1)*fact[i];
    fact[i+1]%=MOD;
  }
  invfact.assign(SIZE,0);
  for(int i=0;i<SIZE;i++){
    invfact[i]=mod_inverse(fact[i]);
  }
  return;
}


ll comb(ll n,ll k){
  return (((fact[n]*invfact[n-k])%MOD)*invfact[k])%MOD;
}
ll bunpai(ll x,ll n){
  if(n==0){
    assert(x==0);
    return 1;
  }
  return comb(x+n-1,n-1);
}

ll solve(ll a,ll b,ll c,ll sx,ll sy){
  ll n=a+b+c;
  ll res=0;

  for(ll buf=0;buf<=min(sx-a,sy-b);buf++){
    ll bufcomb=bunpai(buf,n);
    if(a==0 && sx-buf-a>0) continue;
    ll acomb=bunpai(sx-buf-a,a);
    if(b==0 && sy-buf-b>0) continue;
    ll bcomb=bunpai(sy-buf-b,b);
    res+=(((bufcomb*acomb)%MOD)*bcomb)%MOD;
    res%=MOD;
  }

  ll ord=fact[n];
  ord*=invfact[a];
  ord%=MOD;
  ord*=invfact[b];
  ord%=MOD;
  ord*=invfact[c];
  ord%=MOD;
  res*=ord;
  res%=MOD;
  return res;

}

int main(){
  init();
  ll a,b,c,sx,sy;
  while(cin>>a>>b>>c>>sx>>sy,!(a==0 && b==0 && c==0 )){
    cout<<solve(a,b,c,sx,sy)<<endl;
  }

  return 0;
}


Measured memory_bytes: 65152
import math

n,k = map(int,input().split())
a = tuple(map(int,input().split()))
l = 0
r = max(a)
count = 0
while(count < 100):
  m = (l+r)/2
  kk = 0
  for ai in a:
    kk += math.ceil(ai/m-1)
  #print(l,m,r,kk)
  if kk <= k:
    r = m
  else:
    l = m
  count += 1
print(math.ceil(l))

Measured memory_bytes: 104748
#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;
vector<ll > vec;
vector<vector<ll > > vec2;

ll sum(ll a, ll b){
    ll ans = 0;

    for(ll i = a; i <= b; i++){
        ans+=i;
    }

    return ans;
}

int main(){

    string s;
    cin >> s;
    
    for(ll i = 0; i < s.length();){
        ll j = i;
        //一緒の間ループを回し続けて，切れ目を探す
        while(j < s.length() && s[j] == s[i]){
            ++j;
        }
        vec.push_back(j - i);
        //次の始点へすっ飛ばす
        i = j;
    }

    ll ans = 0;
    ll idx = 0;

    if(s[0] == '>'){
        ans += sum(0, vec[0]);
        idx = 1;
    }

    if((vec.size() + idx) % 2 != 0){
        vec.push_back(1);
    }
    for(ll i = 1 + idx; i < vec.size(); i+=2){
        //cout << vec[i] << " " << vec[i-1]  << endl;
        if(vec[i] >= vec[i-1]){
            ll e1 = vec[i];
            ans += sum(0, vec[i-1]-1);            
            ans += sum(0 , e1);
            //cout << sum(s1, e1) <<endl;
            //cout << sum(0, vec[i] - 1) << endl;
        }else{
            ans += sum(0, vec[i-1]);
            ll e2 = vec[i] - 1;
            ans += sum(0, e2);
            //cout << sum(0, vec[i-1]) + sum(0, e1) <<endl;
        }
        //cout << ans << endl;
    }


    cout << ans << endl;
}

Measured memory_bytes: 3068
#include <stdio.h>
#include <string.h>

int x[1500 * 1000 + 1];
int y[1500 * 1000 + 1];

int main(void)
{
	int N, M;
	int H, W;
	int h[1501], w[1501];
	int i, j;
	int cnt;

	while (1){
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0){
			break;
		}
		
		h[0] = 0;
		for (i = 1; i <= N; i++){
			scanf("%d", &H);
			h[i] = h[i - 1] + H;
		}
		
		w[0] = 0;
		for (i = 1; i <= M; i++){
			scanf("%d", &W);
			w[i] = w[i - 1] + W;
		}
		
		memset(y, 0, sizeof(y));
		for (i = 0; i <= N - 1; i++){
			for (j = i + 1; j <= N; j++){
				y[h[j] - h[i]]++;
			}
		}
#if 0
for (i = 1; i < 10; i++){
	printf("%d ", y[i]);
}
printf("\n");
#endif		
		memset(x, 0, sizeof(x));
		for (i = 0; i <= M - 1; i++){
			for (j = i + 1; j <= M; j++){
				x[w[j] - w[i]]++;
			}
		}
#if 0
for (i = 1; i < 10; i++){
	printf("%d ", x[i]);
}
printf("\n");
#endif
		cnt = 0;
		for (i = 1; i <= 1500 * 1000; i++){
			if (x[i] > 0 && y[i] > 0){
				cnt += (x[i] * y[i]);
			}
		}
		
		printf("%d\n", cnt);
	}
		
	return (0);
}

Measured memory_bytes: 12336
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		long N = long.Parse(str);
		string[] str2 = Console.ReadLine().Split();
		long[] A = new long[N];
		int[] B = new int[N];
		long sum = 0;
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str2[i]);
			B[i] = (int)A[i] - (i+1);
		}
		Array.Sort(B);
		long c1 = (long)B[N/2];
		long c2 = (long)B[Math.Min(N/2+1,N-1)];
		for(var j=0;j<N;j++){
			sum += Math.Abs(A[j] - (j+1) - c1);
		}
		long sum2 = 0;
		for(var j=0;j<N;j++){
			sum2 += Math.Abs(A[j] - (j+1) - c2);
		}
		long ans = Math.Min(sum,sum2);
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 32732
# -*- coding: utf-8 -*-
import sys
from itertools import combinations
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    while True:
        N,X=map(int,input().split())
        if N==X==0:
            exit()
        c=combinations(range(1,N+1),3)
        ans=0
        for x in c:
            if sum(x)==X:
                ans+=1
        print(ans)


if __name__ == '__main__':
    main()



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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    string s[n];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    sort(s, s + n);
    for (auto &i : s) {
        cout << i;
    }
    cout << endl;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define llinf 1e17
#define nllinf -4e18
 
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll,ll> 
#define vpll vector<pair<ll,ll > >
 
#define repup(a,b,i) for(i=a;i<=b;i++)
#define repdown(a,b,i) for(i=b; i>=a; i--)
#define repupx(a,b,i,x) for(i=a;i<=b;i+=x)
	
#define repit(v,it) for(it=v.begin(); it!=v.end(); it++)
#define itall(v) v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first
#define sc second

#define err(n) cout<<n<<" ";
#define t1 cout<<",";

 ll MOD= 1e9 +7;

void add_self (ll& a, ll b){
	a+= b;
	if(a>=MOD)a-=MOD;
}

void sub_self (ll& a, ll b){
	a-=b;
	a= ((a%MOD)+MOD)%MOD;
}

int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll i,j,k;
ll f;

ll n;cin>>n>>k;
ll dp[k+4]={0};
dp[0]=1;
repup(0,n-1,i){
	ll b[k+2]={0};
	
	ll x;
	cin>>x;
	repdown(0, k,j){
		sub_self(b[j+ min(k-j,x)+1], dp[j]);
		add_self (b[j+1],dp[j]);
	}
	repup(1,k+1,j){
		add_self(b[j],b[j-1]);
		add_self(dp[j-1], b[j-1]);
	}
}
cout<<dp[k];

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
long long dp[101][22];
int data[101];
int main(void)
{
	int n;
	int i,j;
	int value_first,value;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<=20;j++){
			dp[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>data[i];
	}
	dp[0][data[0]]=1;
	for(i=0;i<n-1;i++){
		for(j=0;j<=20;j++){
			int p=j+data[i+1];
			int m=j-data[i+1];
			if(p<=20)	dp[i+1][p]+=dp[i][j];
			if(0<=m)	dp[i+1][m]+=dp[i][j];
		}
		
	}
	cout<<dp[n-1][0]<<endl;
	return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main()
{
    int n, num, i, j;
    char mark;
    int card[4][13];
    
    for(i=0; i<4; i++){
        for(j=0; j<13; j++){
            card[i][j] = 0;
        }
    }
    
    scanf("%d", &n);
    
    for(i=0; i<n; i++){
        scanf(" %c %d", &mark, &num);
        
        switch(mark){
            case 'S': card[0][num-1] = 1; break;
            case 'H': card[1][num-1] = 1; break;
            case 'C': card[2][num-1] = 1; break;
            case 'D': card[3][num-1] = 1; break;
        }
    }
    
    for(i=0; i<4; i++){
        for(j=0; j<13; j++){
            if(card[i][j] != 1){
                switch(i){
                    case 0: printf("S %d\n", j+1); break;
                    case 1: printf("H %d\n", j+1); break;
                    case 2: printf("C %d\n", j+1); break;
                    case 3: printf("D %d\n", j+1); break;
                }
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int x;
    cin >> x;
    if(x >= 1200) cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

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

using namespace std;

typedef long long ll;

int main() 
{
    int n, q;
    ll x, y, z;
    scanf("%d %d", &n, &q);
    
    vector<stack<ll> > s(n);
    
    for(int i = 0; i < q; i++)
    {
        scanf("%lld %lld", &x, &y);
        
        if(x == 0)
        {
            scanf("%lld", &z);
            s[y].push(z);
        }
        else if(x == 1)
        {
            if(s[y].size() > 0)
            {
                printf("%lld\n", s[y].top());
            }
        }
        else if(x == 2)
        {
            if(s[y].size() > 0)
            {
                s[y].pop();
            }
        }
    }
    
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    ll ans = 0;
    for (ll i = 1; i < s.size(); i++) {
        if (s[i] != '9') {
            break;
        }
        if (i == s.size()-1) {
            rep (i, s.size()) {
                ans += s[i]-'0';
            }
            cout << ans << endl;
            return 0;
        }
    }

    if (s.size() == 1) {
        cout << s << endl;
        return 0;
    }

    if (s[0] == '1') {
        rep (i, s.size()-1) {
            ans += 9;
        }
    } else {
        ans += s[0]-'1';
        for (ll i = 1; i < s.size(); i++) {
            ans += 9;
        }
    }

    cout << ans << endl;
    return 0;
}

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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            long ans = 0;

            for (int bef = 0; bef < s.Length; bef++)
            {
                for (int len = 1; bef +len <= s.Length; len++)
                {
                    string substr = s.Substring(bef, len);
                    int aft = s.Length - bef - len;
                    long num = (long)(Math.Max(1, Math.Pow(2, bef - 1)) * 
                        Math.Max(1, Math.Pow(2, aft - 1)));
                    ans += long.Parse(substr) * num;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 2776
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main(){
		new AO1148().doIt();
	}
	
	class AO1148{
		int pc,student;
		
		void solve(){
			Data data[] = new Data[student+1];
			int dm = in.nextInt();
			boolean used[] = new boolean[student+1];
			for(int i=0;i<dm;i++){
				int t = in.nextInt();
				int n = in.nextInt();
				int m = in.nextInt();
				int s = in.nextInt();
				if(used[m]==false){
					data[m] = new Data(t, n, m, s);
					used[m] = true;
				}else{
					if(s==1)data[m].logIn(t);
					else if(s==0)data[m].logOut(t);
				}
			}
			int q = in.nextInt();
			for(int i=0;i<q;i++){
				int start = in.nextInt();
				int end = in.nextInt();
				int target = in.nextInt();
				if(used[target])System.out.println(data[target].whatTime(start, end));
				else System.out.println("0");
//				data[target].print();
			}
		}
		
		void doIt(){
			while(in.hasNext()){
				pc = in.nextInt();
				student = in.nextInt();
				if(pc+student==0)break;
				solve();
			}
		}
		class Data{
			boolean[] time;
			int before;
			int pc;
			public Data(int t,int n,int m,int s){
				time = new boolean[1261];
				before = -1;
				pc = 0;
				logIn(t);
			}
			
			int whatTime(int start ,int end){
				int result = 0;
				for(int i=start;i<end;i++)if(time[i])result++;
				return result;
			}
			
			void logIn(int t){
				if(before == -1)before = t;
				pc++;
			}
			
			void logOut(int t){
				pc--;
				if(pc==0){
					for(int i=before;i<t;i++)time[i] = true;
					before = -1;
				}
			}
			
			void print(){
				for(int i=0;i<=1260;i++)if(time[i])System.out.println(i);
			}
			
		}
	}
}

Measured memory_bytes: 54912