akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

ll gcd(const ll sx, const ll sy) {
    ll x = min(sx, sy);
    ll y = max(sx, sy);
    ll tmp;
    while (x > 0) {
        tmp = y;
        y = x;
        x = tmp % x;
    }
    return y;
}

ll lcm(const ll x, const ll y) {
    return x / gcd(x, y) * y;
}

// ref. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0005
int main(void) {
    char buf[1024];
    int res;
    while (1) {
        if (fgets(buf, 1024, stdin) == NULL) {
            if (feof(stdin)) {
                return 0;
            } else {
                perror("fgets");
                return 1;
            }
        }

        ll x, y;
        sscanf(buf, "%lld %lld", &x, &y);
        cout << gcd(x, y) << " " << lcm(x, y) << endl;
    }
}



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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define bug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

#define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"First\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b) % mo;
}

const int maxn = 1e5+5;

int deg[maxn];
int col[maxn];
int nf[maxn];

main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    vector<vector<int> > g(n);
    REP(i,n-1){
        int a, b; cin>>a>>b; g[a-1].pb(b-1); g[b-1].pb(a-1);
        deg[a-1]++; deg[b-1]++;
    }
    queue<int> cd;
    REP(i,n){
        for (int v : g[i]) {
            if (deg[v]==1) nf[i]++;
        }
        if (nf[i]==1) cd.push(i);
        if (nf[i]>1) GG();
    }
    while (!cd.empty()){
        int t = cd.front(); cd.pop();
        col[t] = 1; 
        // cout<<"Painted "<<t+1<<endl;
        for (int v : g[t]) {
            deg[v]--;
            if (deg[v]==0) col[v] = 2;
            else if (deg[v]==1){
                for (int u : g[v]){
                    if (col[u]) continue;
                    nf[u]++; if (nf[u]>1) GG();
                    cd.push(u);
                }
            }
        }
    }
    REP(i,n){
        if (col[i] == 1){ int mo = 1;
            for (int v : g[i]){
                if (col[v]==2) {
                    mo = 0; break;
                }
            } if (mo) GG();
        }
    }
    cout<<"Second"<<endl;
} 

Measured memory_bytes: 9728
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i ;
	}

}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (k == 0) return 1;
	return n * COM(n - 1, k - 1) / k;
}



int main() {
	COMinit();
	ll i, j, k, l, m, n, sum, flag, cc,N,M,X,A,B;
	sum = 0;
	flag = 0;
	cin >> N>>A>>B;
	vector<ll>v(N);
	REP(i, 0, N) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	ll max = v[N - 1];
	i = N - 2;
	k = 1;
	while (i >= 0) {
		if (v[i] == max) {
			k++;
			i--;
		}
		else {
			break;
		}
	}
	ll a_value_pos=0;
	ll a_value_num = 0;
	REP(i, 0, N - 1) {
		if (v[i] == v[N - A]) {
			a_value_num++;
			if (i >= N - A) {
				a_value_pos++;
			}
		}
		
	}
	sum = 0;
	double ans;
	for (i = N - 1; i >= N - A; i--) {
		sum += v[i];
	}
	ans = (double)sum / (double)A;
	if (k < A) {
		printf("%lf", ans);
		cout << endl;
		output(COM(a_value_num,a_value_pos));
		return 0;
	}
	ll sum1;
	sum1 = 0;
	for (i = A; i <= min(B,k); i++) {
		sum1 += COM(k, i);
	}
	printf("%lf", ans);
	cout << endl;
	output(sum1);


	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


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

	int money, year, n;
	int flag, minus;
	double rate;

	//???????????????????????°???????????????
	for(int i=0 ; i<m ; i++){
		cin >> money;
		cin >> year;
		cin >> n;

		int max=0;

		//?????¨???????????°???????????????
		for(int j=0 ; j<n ; j++){
			cin >> flag;
			cin >> rate;
			cin >> minus;

			int A, B;
			A = money;
			B = 0;

			if(flag==0){
				for(int k=0 ; k<year ; k++){
					B += A * rate;
					A -= minus;
				}
				if(max < (A+B)) max = A+B;
			}else if(flag == 1){
				for(int k=0 ; k<year ; k++){
					B = A * rate;
					A = A + B - minus;
				}
				if(max < A) max = A;
			}
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, M, V, P;
  cin>>N>>M>>V>>P;
  vector<ll> A(N);
  for(int i=0;i<N;++i) cin>>A[i];
  sort(A.begin(), A.end());
  ll l=0, r=N-1, m;
  ll score;
  ll vote;
  vector<ll> tmparr(N);
  ll zero = 0;
  int index;
  while(l<r) {
    m = (l+r)/2;
    score = M+A[m];
    vote = M*(V-1);
    for(int i=0;i<N;++i) {
      if(i!=m) vote -= min(M, max(zero, score-A[i]));
      tmparr[i] = max(score, A[i]);
    }
    for(int i=N-1;i>=0;--i) {
      if(vote>0) {
        vote -= M-max(score-A[i], zero);
        tmparr[i] = score+1;
      }
    }
    index = upper_bound(tmparr.begin(), tmparr.end(), score)-tmparr.begin();
    if(N-index<P) r = m;
    else l=m+1;
  }
  cout<<N-l<<endl;
}



Measured memory_bytes: 4804
N, K = [int(i) for i in input().split()]
R,S,P = [int(i) for i in input().split()]
T = input()

def wincard(s):
    if s=="r":
        return "p"
    elif s=="s":
        return "r"
    else:
        return "s"

def score(card):
    if card == "r":
        return R
    elif card == "s":
        return S
    elif card == "p":
        return P

mycard = ""
score_sum = 0
for i in range(N):
    if i-K<0:
        mycard = mycard+wincard(T[i])
        score_sum += score(wincard(T[i]))
    else:
        if wincard(T[i]) != mycard[i-K]:
            mycard = mycard+wincard(T[i])
            score_sum += score(wincard(T[i]))
        else:
            mycard = mycard+"w"

print(score_sum)

Measured memory_bytes: 9452
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, p;
    string s;
    cin >> n >> p >> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        a[i] = s[i] - '0';
    long long ans = 0;
    if(10 % p == 0) {
        for(int i = 0 ; i < n ; i++)
            if(a[i] % p == 0)
                ans += i + 1;
        cout << ans << '\n';
        return 0;
    }
    reverse(a.begin(), a.end());
    vector<int> csum(n + 1, 0);
    int pw = 1;
    for(int i = 0; i < n; i++) {
        csum[i + 1] += (csum[i] + a[i] * pw % p) % p;
        pw = (pw * 10) % p;
    }
    
    // map<int, int> mp;
    // for(int i = 0; i < n + 1; i++)
    //     mp[csum[i]]++;
    // for(auto &iter : mp)
    //     ans += iter.second * (iter.second - 1) /2;
    vector<int> cnt(p);
    for(int i = 0; i < n + 1; i++) {
        ans += cnt[csum[i]];
        cnt[csum[i]]++;
    }
    cout << ans << '\n';

    return 0;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long K;
    cin>>K;
    string lunlun[100010];
    int cnt=0;
    queue<string>q;
    
    
    rep2(i,9){
        string ns="";
        ns+=('0'+i);
        q.push(ns);
        lunlun[cnt++]=ns;
    }
    while(cnt<=K){
        string now=q.front();q.pop();
        int last=now.size()-1;
        char end=now[last];
        int next=-1;
        while(next<=1){
            if('0'>end+next || end+next>'9'){
                next++;
                continue;
            }
            string ns=now;
            ns+=end+next;
            q.push(ns);
            lunlun[cnt++]=ns;
            next++;
        }
    }
    //rep(i,K)cout<<lunlun[i]<<" ";
    //cout<<endl;
    cout<<lunlun[K-1]<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main(){
    int n;  cin >> n;
    string s;   cin >> s;
    vector<ll> fr(10, 0), bc(10, 0);
    REP(i, n)   bc[s[i]-'0'] += 1;
    set<ll> res;
    REP(i, n){
        int x = s[i]-'0';
        bc[x] -= 1;
        REP(j, 10){
            if(fr[j]<=0) continue;
            REP(k, 10){
                if(bc[k]<=0) continue;
                res.insert(100*j+10*x+k);
            }
        }
        fr[x] += 1; 
        //cout << fr[x] << bc[x] << endl;
    }
    //for(auto x: res) cout << x << endl;
    cout << res.size() << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>

using namespace std;
#define long long long

const int N = 1e5 + 10;
const int INF = 1e9 + 7;

int n, k;
long h[N], f[N];

int main()
{
//    freopen("tam.inp", "r", stdin);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> h[i];

    f[1] = 0;
    for (int i = 2; i <= n; ++i) {
        f[i] = INF;
        for (int j = 1; i - j && j <= k; ++j) f[i] = min(f[i], f[i - j] + abs(h[i] - h[i - j]));
    }
    cout << f[n];

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007 
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pii>
#define int long long
using namespace std;
vector<long double>a;
long double ans=0;
long double dp[3000][3000];
long double rec(int x,int val){
    if(x>=a.size()){
        if(val>a.size()/2){
            return 1;
        }
        return 0;
    }
    if(dp[x][val]!=-1){
        return dp[x][val];
    }
    return dp[x][val]=(rec(x+1,val+1)*a[x])+(rec(x+1,val)*((long double)1-a[x]));
}
signed main(){
    SPEED;
   
    int t=1;
    //cin>>t;
    while(t--){
       int n;cin>>n;
       ans=0;
       long double x;
       for(int i=0;i<n;i++){
            cin>>x;a.pb(x);
       }
       for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dp[i][j]=-1;
            }
       }
       ans=rec(0,0);
       cout<<setprecision(9)<<ans<<endl;
    }  
    return 0;
}

Measured memory_bytes: 141184
S = input()

for i in range(len(S)):
    th = i+1
    if (th%2 == 0 and  S[i] == 'R'):
        print('No')
        exit()
    if (th%2 == 1 and S[i] == 'L'):
        print('No')
        exit()
print('Yes')

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a,b,c[3];
  cin >> a >> b;
  c[0] = a + b;
  c[1] = a - b;
  c[2] = a * b;
  sort (c,c+3,greater<int>());
  cout << c[0] << '\n';
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <cstdio>
#include <cstdint>
#include <unistd.h>
#include <queue>

using i64 = std::uint_fast32_t;

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline i64 scan() {
    i64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(i64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

signed main() {
  i64 n = io::scan();
  i64 k = io::scan();
  if (k >= n) {
    puts("0");
    return 0;
  }
  std::priority_queue<i64> que;
  for (int i = 0; i < n; i++) {
    i64 h = io::scan();
    if (que.size() >= n - k) {
      if (que.top() > h) {
        que.pop();
        que.push(h);
      }
    } else {
      que.push(h);
    }
  }
  i64 s = 0;
  for (int i = 0; i < n - k; i++) {
    s += que.top();
    que.pop();
  }
  io::print(s);
  io::flush();
  return 0;
}

Measured memory_bytes: 2548
import math
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

m = [a, b, c, d, e]
max_t = -1
for i in range(5):
  t = math.ceil(n / m[i])
  max_t = max(max_t, t)

print(max_t+4)

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n, m;

int imos[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);

    imos[l] += 1;
    imos[r + 1] -= 1;
  }

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

  int cnt = 0;

  for (int i = 1; i <= n; ++i) {
    if (imos[i] == m) {
      cnt += 1;
    }
  }
  ans = cnt;

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

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    long long a[n], sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i != n-1) sum += a[i];
    }
    long long sunuke = sum, arai = a[n-1];
    long long mi = abs(sunuke - arai);
    for(int i = n-2; i > 0; i--){
        mi = min(mi,abs(sunuke - arai));
        sunuke -= a[i]; arai += a[i];
    }   
    cout << mi << endl;
}

Measured memory_bytes: 1792
s = input()
s1 = int(s[0:2])
s2 = int(s[2:4])
ans = [False, False]
if 1 <= s2 <= 12:
    ans[0] = True
if 1 <= s1 <= 12:
    ans[1] = True
if ans == [False, False]:
    print("NA")
elif ans == [True, True]:
    print("AMBIGUOUS")
elif ans == [True, False]:
    print("YYMM")
elif ans == [False, True]:
    print("MMYY")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1&&b==2||a==2&&b==1)
        puts("3");
    else if(a==3&&b==2||a==2&&b==3)
        puts("1");
    else if(a==1&&b==3||a==3&&b==1)
        puts("2");
    return 0;
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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 run() {
    input! {
        n: usize,
        p: [f64; n],
    }
    let mut dp = vec![0.0; n + 1];
    dp[0] = 1.0;
    for (i, p) in p.iter().enumerate() {
        let q = 1.0 - p;
        for j in (1..(i + 2)).rev() {
            dp[j] = q * dp[j] + p * dp[j - 1];
        }
        dp[0] *= q;
    }
    let mut ans = 1.0;
    for i in 0..(n / 2 + 1) {
        ans -= dp[i];
    }
    println! ("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;

    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner(Stream source)
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(source);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray(int index = 0)
    {
        Next();
        Index = S.Length;
        return S.Skip(index).ToArray();
    }
    public int[] IntArray(int index = 0)
    {
        return StringArray(index).Select(int.Parse).ToArray();
    }
    public long[] LongArray(int index = 0)
    {
        return StringArray(index).Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

public class Magatro
{
    private Scanner Cin;

    private int N;
    private void Scan()
    {
        Cin = new Scanner(Console.OpenStandardInput());
        N = Cin.NextInt();
    }

    public void Solve()
    {
        Scan();
        for (int i = 0; i < N; i++)
        {
            Anser(Cin.IntArray());
        }
    }

    private void Anser(int[] input)
    {
        int loop = 1024;
        for (int i = 0; i < loop; i++)
        {
            if (check(i, input))
            {
                Console.WriteLine("YES");
                return;
            }
        }
        Console.WriteLine("NO");
    }

    private bool check(int i,int[] input)
    {
        int b = 0, c = 0;
        for (int j = 0; j < 10; j++)
        {
            switch (i % 2)
            {
                case 1:
                    if (b > input[j]) return false;
                    b = input[j];
                    break;
                case 0:
                    if (c > input[j]) return false;
                    c = input[j];
                    break;
                default:
                    throw new Exception();
                   
            }
            i /= 2;
        }
        return true;
    }
}

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

int days[2][12] = {
	{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
	{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}
};

int isLeapYear(int y){
	if(y % 400 == 0) return 1;
	if(y % 100 == 0) return 0;
	if(y % 4 == 0) return 1;
	return 0;
}

int main(){
	int y1, m1, d1, y2, m2, d2;
	
	while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2, y1 >= 0){
		int sum = 0;
		
		for(int i = y1; i < y2; ++i){
			sum += (isLeapYear(i) ? 366 : 365);
		}
		
		sum += days[isLeapYear(y2)][m2-1] + d2;
		sum -= days[isLeapYear(y1)][m1-1] + d1;	
		
		cout << sum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef  long long ll;
typedef unsigned long long ull;
const ll LIM =1e9+7;

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}
template<typename S>
void print(S a){
    cout<<a<<endl;
}


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

    ll n,k;cin>>n>>k;
    n++;

    ll ans=0;
    for(int i=k;i<=n;i++){
//        ull mn = (i-1)*i/2;
//        ull mx = (n-1+n-i)*i/2;
        ull tmp = i*(n-i);
        if(tmp/i!=n-i){
            tmp =(i%LIM)*((n-i)%LIM);
        }
        ans+=tmp+1;
        if(ans>=LIM)ans%=LIM;
    }


/*
//    vector<vector<ll>> dp(n, vector<ll>(n));
    vector<ll> dp(n);

    dp.at(0) = 1;
    for(ll i=1;i<n;i++){
        for(ll j=1;j<=i;j++){
//            ll tmp = (dp.at(j-1)+(j-1)*(j-2)/2+i)-(dp.at(j)+j*(j-1)/2)+dp.at(j);
            ll tmp = dp.at(j)+dp.at(j-1);
            if(tmp>=LIM){tmp %=LIM;}
            dp.at(j) = tmp;

        }
    }
    ll ans = 0;
    for (ll i = k ; i < n; i++) {
        ans+=dp.at(i);
        if(ans>=LIM)ans%=LIM;
    }
*/
    fin(ans);
}


Measured memory_bytes: 3640
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  int m;
  cin >> m;
  cout << 48 - m << endl;
  return 0;
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int A, B;
    cin >> A >> B;
    cout << 6 - A - B << endl;
}

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

int main() {
  int N;
  cin >> N;
  long m[5]={0,0,0,0,0};
  long sum=0;
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    if(S[0]=='M')m[0]+=1;
    else if(S[0]=='A')m[1]+=1;
    else if(S[0]=='R')m[2]+=1;
    else if(S[0]=='C')m[3]+=1;
    else if(S[0]=='H')m[4]+=1;
  }
  for(int i=0;i<5;i++){
    for(int j=0;j<i;j++){
      for(int k=0;k<j;k++){
        sum+=m[i]*m[j]*m[k];
      }
    }
  }
  cout << sum;
}



Measured memory_bytes: 256
from collections import Counter

n, m = map(int, input().split(" "))
r = zip(*[list(map(int, input().split(" "))) for i in range(m)])
r = list(r)
c1 = dict(Counter(r[0]).most_common())
c2 = dict(Counter(r[1]).most_common())
for i in range(1, n + 1):
    print((c1[i] if i in c1 else 0) + (c2[i] if i in c2 else 0))


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

#define ll long long
#define fr first
#define se second

using namespace std;

const long long N = 2e6 + 7;

ll res, n, m, cnt, q = 1;
string s, str;
vector< string > v;
int main()
{
    /// freopen( "input.txt", "r", stdin );
    /// freopen( "output.txt", "w", stdout );
    cin >> s;
    if ( s == "ABC" )
        cout << "ARC";
    else
    cout << "ABC";
}


Measured memory_bytes: 3636
import numpy as np
N,M=map(int, input().split())  
sc=np.array([list(map(int,list(input().split()))) for i in range(M)])

ans = np.zeros(N)
checked=False
for i in range(M):
  s=sc[i][0]
  c=sc[i][1]
  if N!=1 and s==1 and c==0:
    checked=True
    break
  for j in range(i):
    if s==sc[j][0] and c!=sc[j][1]:
      checked=True
      break
  ans[s-1] = c

if checked:
  print(-1)
else:
  if N!=1 and ans[0]==0:
    ans[0]=1
  res = ''
  for i in ans:
    res += str(int(i))
  print(int(res))

Measured memory_bytes: 13816
#include <bits/stdc++.h>
#define REP(i, a) for(int i=0; i<int(a); i++)
#define ALL(x) begin(x), end(x)
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int MAX_N=100005;
const int INF = 1e9;
vector<PII> edges[MAX_N];
LL dist[MAX_N];

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    REP(i, m) {
        int a, b, w;
        scanf("%d %d %d", &a, &b, &w);
        edges[a].push_back({b, w});
        edges[b].push_back({a, -w});
    }

    REP(i, n+1) dist[i] = INF;
    for(int i=1; i<=n; i++) {
        if(dist[i] == INF) {
            queue<int> q;
            q.push(i);
            dist[i] = 0;
            while(q.size()) {
                int from = q.front();
                q.pop();
                for(auto p:edges[from]) {
                    int to = p.first;
                    LL cost = p.second;
                    if(dist[to] == INF) {
                        dist[to] = dist[from] + cost;
                        q.push(to);
                    } else if(dist[to] != dist[from] + cost) {
                        cout << "No" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0; 
}



Measured memory_bytes: 9728
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



inline int toint(string s) {int v;istringstream sin(s);sin>>v;return v;}
vector<string> split(const string &str, char delim) {
    vector<string> res;
    size_t current = 0, found;
    while ((found = str.find_first_of(delim, current)) != string::npos){
        res.push_back(string(str, current, found - current));
        current = found + 1;
    }
    res.push_back(string(str, current, str.size() - current));
    return res;
}


string data[4] = {"A", "B", "AB", "O"};

int main() {
    map<string,int> res;
    string str;
    while (cin >> str) {
        vector<string> vst = split(str, ',');
        res[vst[1]]++;
    }
    for (int i = 0; i < 4; ++i) {
        cout << res[data[i]] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1200
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <climits>
#include <bitset>
#include <cassert>

using namespace std;

const int SIZE = 1 << 17;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0, sign = 1;
    char ch = Advance();
    while (!isdigit(ch) && ch != '-')
        ch = Advance();
    if (ch == '-') {
        sign = -1;
        ch = Advance();
    }
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer * sign;
}

char ReadCh() {
    char ch = Advance();
    while (!isalpha(ch))
        ch = Advance();
    return ch;
}

char start[20], finish[20], now[20];

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n;
    scanf("%d", &n);
    printf("0\n");
    fflush(stdout);
    scanf("%s", start);
    if (start[0] == 'V')
        return 0;
    printf("%d\n", n - 1);
    fflush(stdout);
    scanf("%s", finish);
    if (finish[0] == 'V')
        return 0;
    int left = 2, right = n - 1;
    while (left <= right) {
        int middle = (left + right) / 2;
        printf("%d\n", middle - 1);
        fflush(stdout);
        scanf("%s", now);
        if (now[0] == 'V')
            return 0;
        if (((middle - left) % 2 == 1 && now[0] == start[0]) || ((middle - left) % 2 == 0 && now[0] != start[0])) {
            start[0] = now[0];
            left = middle + 1;
        }
        else {
            finish[0] = now[0];
            right = middle - 1;
        }
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    if (n == 1) cout << "Hello World" << endl;
    else {
        int a, b;
        cin >> a >> b;
        cout << a+b << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

#define N 8

using namespace std;

int main(void)
{
  int num[N];
  while(true)
  {
    for(int i = 0; i < N; i++)
    {
      if(!(cin >> num[i])) goto END;
    }
    int hit = 0, blow = 0;
    for(int i = 0; i < 4; i++)
    {
      if(num[i] == num[i+4]) hit++;
      else if(   num[i] == num[4]
	      || num[i] == num[5]
	      || num[i] == num[6]
	      || num[i] == num[7])
	blow++;
    }
    cout << hit << " " << blow << endl;
  }

 END:
  return 0;
}

Measured memory_bytes: 1160
gets.to_i.times{
	x1,y1,x2,y2,x3,y3 = gets.split.map(&:to_f)
	a,b,c,d,e,f = 2*(x1-x2), 2*(y1-y2), x1**2+y1**2-x2**2-y2**2, 2*(x1-x3), 2*(y1-y3), x1**2+y1**2-x3**2-y3**2
	x = (b*f-c*e)/(b*d-a*e)
	y = (c*d-a*f)/(b*d-a*e)
	puts "#{sprintf("%.3f %.3f %.3f",x+0.0,y+0.0,((x-x1)**2+(y-y1)**2)**0.5+0.0)}"
}

Measured memory_bytes: 8828
# coding: utf-8
# Your code here!
work_num = int(input())
work_list = []
for i in range(work_num):
    work_list.append(tuple(int(i) for i in input().split(" ")))


def ret_1th_element(tup):
    return tup[1]


work_list.sort(key=ret_1th_element)
time = 0
for i in work_list:
    time += i[0]
    if time > i[1]:
        print("No")
        break
else:
    print("Yes")


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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int minv = min(A, B);
  vector<int> ans;
  for (int i = 1; i <= minv; i++) {
    if (A % i == 0 && B % i == 0) {
      ans.push_back(i);
    }
  }
  cout << ans[ans.size() - K] << endl;
  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<long long> X(N), Y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(X.begin(), X.end());
    int lm = X[N / 2 - 1];
    int rm = X[N / 2];
    for (int i = 0; i < N; i++)
    {
        if (Y[i] < rm)
            cout << rm << endl;
        else
            cout << lm << endl;
    }
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int a,b,k; cin>>a>>b>>k;
    //最大公約数
    int ans[min(a,b)]={};
    int an=0;
    for(int i=min(a,b);i>0;i--){
        if(a%i==0 && b%i==0){
            ans[an] = i;
            an++;
        }
    }
    //for(int i=0;i<min(a,b);i++) cout<<ans[i]<<endl;
    cout<<ans[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

LL gcd(LL x, LL y){
  LL sm, la, work;
  if(x<y) {
    la = y;
    sm = x;
  }
  else{
    la = x;
    sm = y;
  }

  while(1){
    work= la%sm;
    if(work==0)break;
    la=sm;
    sm=work;
  }
  return sm;
}

LL lcm(LL a, LL b){
  return a/gcd(a, b)*b; //順序変えるとオーバーフローする
}

int main(){
  LL n, m;
  cin>>n>>m;
  string s, t;
  cin>>s>>t;
  if(m==1){
    bool check=true;
    REP(i, n) check=check&(s[i]==t[0]);
    if(check) cout<<n<<endl;
    else cout<<-1<<endl;
    return 0;
  }
  if(n==1){
    bool check=true;
    REP(i, m) check=check&(s[0]==t[i]);
    if(check) cout<<m<<endl;
    else cout<<-1<<endl;
    return 0;
  }
  LL g=gcd(n, m);
  LL l = lcm(n, m);
  bool check=true;
  for(int i=0; i<g; ++i){
    check=check&(s[i*n/g]==t[i*m/g]);
  }
  if(check) cout<<l<<endl;
  else cout<<-1<<endl;




  return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n,i,m,j;
		boolean flg;
		n = sc.nextInt();
		int cnt =0;
		for(i=0;i<n;i++){
			flg = true;
			m = sc.nextInt();
			if(m<2) flg = false;
			if(m==2){
				cnt++;
				continue;
			}
			if(m%2==0) flg =false;
			double sqrtM = Math.sqrt(m);
			for(j=3;j<=sqrtM;j+=2){
				if(m%j==0) {
					flg = false;
					break;
				}
			}
			if(flg==true) cnt++;
	}
    System.out.println(cnt);

}}




Measured memory_bytes: 41256
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

//Card Game is Fun
public class Main{

	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt();
		List<Integer>[] l = new List[1001];
		for(int i=0;i<1001;i++)l[i]=new LinkedList<Integer>();
		int[] a = new int[A], b = new int[B];
		for(int i=0;i<A;i++){
			a[i] = sc.nextInt();
			l[a[i]].add(i);
		}
		for(int i=0;i<B;i++)b[i]=sc.nextInt();
		int[][] e = new int[A][1001];
		int[] h = new int[1001];
		for(int j=1;j<1001;j++)h[j]=l[j].isEmpty()?-1:l[j].get(0);
		for(int i=0;i<A;i++){
			l[a[i]].remove(0);
			for(int j=1;j<1001;j++)e[i][j] = l[j].isEmpty()?-1:l[j].get(0);
		}
		int res = 0;
		for(int i=0;i<B;i++){
			int v = i, p = h[b[i]], k = 0;
			if(p==-1)continue;
			k = 1;
			res = Math.max(res, k);
			v++;
			for(;v<B;v++){
				p = e[p][b[v]];
				if(p==-1)break;
				res = Math.max(res, ++k);
			}
		}
		System.out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 32000
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int visit[101];
int main(){
	int N, K;
	cin >> N >> K;
	for(int i=1; i<=K; i++){
		int d1, v;
		cin >> d1;
		for(int j=1; j<=d1; j++){
			cin >> v;
			visit[v] = 1;
		}
	}
	int ans = 0;
	for(int i=1; i<=N; i++){
		if(!visit[i]) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3164
# -*- coding: utf-8 -*-
"""
Dividing Students
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0218

"""
import sys


def solve(n):
    ans = []
    for _ in range(n):
        m, e, j = map(int, input().split())
        if max([m, e, j]) == 100 or m + e >= 180 or m + e + j >= 240:
            ans.append('A')
        elif m + e + j >= 210 or (m + e + j >= 150 and (m >= 80 or e >= 80)):
            ans.append('B')
        else:
            ans.append('C')
    return ans


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        ans = solve(n)
        print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n;
int arr[100100];
map<int,int> mi;

int main() {
    scanf("%d",&n);
    int fl = 1;
    for (int i=0;i<n;i++) {
        scanf("%d",&arr[i]);
        if (arr[i]) fl = 0;
        if (mi.find(arr[i])==mi.end()) mi[arr[i]] = 1;
        else mi[arr[i]]++;
    }
    if (n%3) {
        puts(fl?"Yes":"No");
        return 0;
    }
    if (fl) puts("Yes");
    else {
        fl = 1;
        int x = 0;
        auto it = mi.begin();
        while(it!=mi.end()) {
            pii t = *it;
            if (t.y%(n/3)) fl = 0;
            else {
                if (t.y/(n/3)%2) x ^= t.x;
            }
            it++;
        }
        puts((fl&&x==0)?"Yes":"No");
    }

    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  if(n==1&&m==1) pr(1);
  else if(n==1) pr(m-2);
  else if(m==1) pr(n-2);
  else pr(max(0LL,n-2)*max(0LL,m-2));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

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

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    map <int, int> cnt;
    ll ans = 0;
    if (p == 2) {
        for (int i = n - 1; i >= 0; i--) {
            if ((s[i] - '0') % 2 == 0) {
                ans += i + 1;
            }
        }
        cout << ans << '\n';
        rr;
    }
    if (p == 5) {
        for (int i = n - 1; i >= 0; i--) {
            if ((s[i] - '0') % 5 == 0) {
                ans += i + 1;
            }
        }
        cout << ans << '\n';
        rr;
    }

    ++cnt[0];
    int sum = 0, t = 1;
    for (int i = n - 1; i >= 0; i--) {
        sum = (t * (s[i] - '0') + sum) % p;
        t = (t * 10) % p;
        ans += cnt[sum];
        ++cnt[sum];
    }
    cout << ans << '\n';
}


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

int cnt[100010] = {0};

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[a - 1]++;
    cnt[a]++;
    cnt[a + 1]++;
  }
  int ans = 0;
  for (int i = 0; i < 100010; i++) {
    if (ans < cnt[i]) {
      ans = cnt[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

class my_stack
{
private:
    int value[200];
    int top;

public:
    my_stack()
    {
        top = 0;
    }

    bool isEmpty()
    {
        return top == 0;
    }

    bool isFull()
    {
        return top >= 200 - 1;
    }

    void push(int n)
    {
        if(isFull())
        {
            cout << "Error: Stack is full." << endl;
            return;
        }
        value[++top] = n;
    }

    int pop()
    {
        if(isEmpty())
        {
            cout << "Error: Stack is empty." << endl;
            return -1;
        }
        return value[top--];
    }
};

int main(void)
{
    my_stack stack;
    string input;

    while(cin >> input)
    {
        if(input == "+")
        {
            int n1 = stack.pop();
            int n2 = stack.pop();
            stack.push(n1 + n2);
        }
        else if(input == "-")
        {
            int n1 = stack.pop();
            int n2 = stack.pop();
            stack.push(n2 - n1);
        }
        else if(input == "*")
        {
            int n1 = stack.pop();
            int n2 = stack.pop();
            stack.push(n1 * n2);
        }
        else
        {
            stack.push(atoi(input.c_str()));
        }
    }

    cout << stack.pop() << endl;

    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  rep(snip_i, n) cin >> l.at(snip_i);
  int now = 0;
  int ans = 1;
  rep(i, n){
    now += l.at(i);
    if(now <= x)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# Binary Indexed Tree (Fenwick Tree)
class BIT:
  def __init__(self, n):
    self.n = n
    self.bit = [0]*(n+1)
    self.el = [0]*(n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.bit[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.bit[i] += x
      i += i & -i

N, K = map(int, input().split())
A = [int(input())-K for _ in range(N)]
from itertools import groupby, accumulate, product, permutations, combinations
cum = [0]+list(accumulate(A))
comp = lambda arr: {e: i+1 for i, e in enumerate(sorted(set(arr)))}
compcum = comp(cum)
for i in range(N+1):
  cum[i] = compcum[cum[i]]
bit = BIT(N+1)
ans = 0
for i in range(N+1):
  ans += bit.sum(cum[i])
  bit.add(cum[i],1)
print(ans)



Measured memory_bytes: 170152
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll n, X;
ll x[200000];
ll sum[200000];

int main() {
    cin >> n >> X;
    rep(i,n) cin >> x[i];
    rep(i,n) {
        sum[i] = (i==0?0:sum[i-1]) + x[i];
    }
    ll ans = linf;
    for (ll i = n; i >= 1; i--) {
        ll cnt = 1;
        ll now = (sum[n-1] - (i==n?0:sum[n-1-i]))*2;
        for (ll j = n-1; j >= 0; j -= i) {
            now = now + (sum[j]-(j<i?0:sum[j-i])) * ((cnt+1)*(cnt+1)-cnt*cnt);
            if (now > ans) break;
            cnt++;
        }
        ans = min(ans, now+i*X+n*X);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


k = int_input()
s = input()

if len(s) > k:
    print(s[0:k]+"...")
else:
    print(s)

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

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

	int en = n % 100 % 10;

	if (en == 3) {
		cout << "bon" << endl;
	}
	else if (en == 0 || en == 1 || en == 6 || en == 8) {
		cout << "pon" << endl;
	}
	else {
		cout << "hon" << endl;
	}

}

Measured memory_bytes: 3600
#include <iostream>
#include <map>
#include <string>


int main(int argc, char *argv[]) {
	std::string input;
	std::cin >> input;

	std::map<char, int> appearance_map;
	for (auto i = input.begin(); i != input.end(); i++) {
		if (appearance_map.find(*i) == appearance_map.end()) {
			appearance_map[*i] = 1;
		} else {
			appearance_map[*i]++;
		}
	}

	bool is_beautiful_sting(true);
	for (auto const pair: appearance_map) {
		if (pair.second % 2 != 0) {
			is_beautiful_sting = false;
			break;
		}
	}

	std::cout << ((is_beautiful_sting) ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++) cin>>A[i];
  bool ans=true;
  for(int i=0;i<N;i++){
    if(A[i]%2==1)continue;
    else{if(A[i]%3==0) continue;
         else if(A[i]%5==0) continue;
         else ans=false;
        }
  }
  if(ans==true)cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
}
      



Measured memory_bytes: 256