akhauriyash/Code-Regression huggingface dataset:
#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() {
    ll N;
    cin >> N;
    vector<vector<ll>> ans(10e3);
    int j = 0;
    rep(i,2) ans[i].push_back(1);

    for (int i = 2; i * (i - 1) <= 2 * N; ++i) {
        if (i * (i - 1) == 2 * N) {
            cout << "Yes" << endl;
            cout << i << endl;
            for (int j = 2; j < i; ++j) {
                rep(k,j) {
                    ll num = j * (j - 1) / 2 + k + 1;
                    ans[k].push_back(num);
                    ans[j].push_back(num);
                }
            }
            rep(j,i) {
                cout << i - 1 << " ";
                for (int k = 0; k < i - 1; ++k) {
                    cout << ans[j][k];
                    if (k == i - 2) cout << endl;
                    else cout << " ";
                }
            }
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 5284
#include<iostream>
#include<queue>
using namespace std;
int W,H;
int m,n;
int counts;
struct test
{
    char c;
    int flag;
    int x;
    int y;
};
queue<test>Q;
int main()
{
    cin>>W>>H;
    while(W!=0 && H!=0)
    {
        counts=0;
        test A[H][W];
        for(int i=0;i<H;i++)
            for(int j=0;j<W;j++)
            {
                cin>>A[i][j].c;
                A[i][j].flag=0;
                A[i][j].x=i;
                A[i][j].y=j;
                if(A[i][j].c=='@')
                {
                    m=i;
                    n=j;
                }
            }
        Q.push(A[m][n]);
        counts++;
        A[m][n].flag=1;
        while(!Q.empty())
        {
            test p=Q.front();
            if(p.x-1>=0 && p.y>=0 && p.x-1<H && p.y<W && A[p.x-1][p.y].c=='.' && A[p.x-1][p.y].flag==0)
            {
                Q.push(A[p.x-1][p.y]);
                A[p.x-1][p.y].flag=1;
                counts++;
            }
            if(p.x>=0 && p.y-1>=0 && p.x<H && p.y-1<W && A[p.x][p.y-1].c=='.' && A[p.x][p.y-1].flag==0)
            {
                Q.push(A[p.x][p.y-1]);
                A[p.x][p.y-1].flag=1;
                counts++;
            }
            if(p.x+1>=0 && p.y>=0 && p.x+1<H && p.y<W && A[p.x+1][p.y].c=='.' && A[p.x+1][p.y].flag==0)
            {
                Q.push(A[p.x+1][p.y]);
                A[p.x+1][p.y].flag=1;
                counts++;
            }
            if(p.x>=0 && p.y+1>=0 && p.x<H && p.y+1<W && A[p.x][p.y+1].c=='.' && A[p.x][p.y+1].flag==0)
            {
                Q.push(A[p.x][p.y+1]);
                A[p.x][p.y+1].flag=1;
                counts++;
            }
            Q.pop();
        }
        cout<<counts<<endl;
        cin>>W>>H;
    }
    return 0;
}


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

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

int main()
{
	ll a, b, n;
	sl(n);
	sl(a);
	sl(b);
	ll ans = (n/(a+b))*a + min(n%(a+b), a);
	printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
import math
input()
items = list(map(int,input().split()))
d = {}
for i in items:
    if i in d.keys():
        d[i] = d[i]+1
    else:
        d[i] = 1

p = {}
for k in d.keys():
    cnt = d[k]
    p[k] = (cnt*(cnt-1))/2

total = sum(p.values())

for item in items:
    print(int(total - d[item] + 1))

Measured memory_bytes: 33664
s = input()

flg = True
for i in range(len(s)):
    if s[i] == 'U':
        #print(i,'U')
        continue
    elif s[i] == 'D':
        #print(i, 'D')
        continue
    elif i % 2 == 0 and s[i] == 'R':
        #print(i, 'R')
        continue
    elif i % 2 == 1 and s[i] == 'L':
        #print(i, 'L')
        continue
    else:
        #print(i, 'False')
        flg = False
        break

if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
<?php
    fscanf(STDIN, "%d", $N);
    $S = strval($N);
    $arr = str_split($S);

    if ($arr[0] === $arr[1] && $arr[1] === $arr[2]) {
        echo "Yes\n";
        exit;
    }

    if ($arr[1] === $arr[2] && $arr[2] === $arr[3]) {
        echo "Yes\n";
        exit;
    }
    echo "No\n";

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int D, N;
    cin >> D >> N;

    int ans = pow(100, D) * N;
    int POW = pow(100, D+1);
    if ((ans % POW) == 0) ans += pow(100, D);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}



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

const ll INF=1e15;

const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    ll ans=INF;
    for(ll i=1;i<=n/2;i++){
        ll p=i;
        ll q=n-i;
        ll sum_p=0,sum_q=0;
        while(p){
            sum_p+=p%10;
            p/=10;
        }
        while(q){
            sum_q+=q%10;
            q/=10;
        }
        ans=min(ans,sum_p+sum_q);
    }
    cout << ans << endl;
    return 0;
}

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

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    L = 0
    R = sum(A)
    for a in A:
        if L+a <= R-a:
            L += a
            R -= a
        elif L == R:
            c = 0
            break
        else:
            c = a
            R -= a
            break

    res = min(L+c-R, R+c-L)
    return str(res)

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 26220
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

#define INF 1e9

// ????????????????????£?¨?
int prim(int vertex, vector<vector<pair<int, int> > > adjlistv);

// ?????????
int main(void){
  while(true){
    // ???????????°??¨???????????°???????????????
    int n, m;
    cin >> n;
    if(n == 0){ break; }
    cin >> m;

    // ???????????±????????????????????£??\??????????????????
    vector<vector<pair<int, int> > > adjlist(n);
    for(int i = 0; i < m; i++){
      int a, b, d;
      scanf("%d,%d,%d", &a, &b, &d);
      adjlist[a].push_back(make_pair(d, b));
      adjlist[b].push_back(make_pair(d, a));
    }
  
    // ????°???¨?????¨????????????????±??????????????????????
    int length = prim(n, adjlist);
    cout << length / 100 - n + 1 << endl;
  }

  return 0;
}

// ????????????
// v: ????????°, adjlist: ??£??\?????????(first: ???????????????, second: ?????????)
int prim(int v, vector<vector<pair<int, int> > > adjlist){
  priority_queue<pair<int, int> > wait;  // ?????§???????????????????????¨?????§???????°??????????
  vector<int> result(v, INF);  // ??????i??¨??¨?????????????°??????????
  int length = 0;  // ??¨????????????

  // ??¨?????????????????????1?????¨?????????
  result[0] = 0;
  wait.push(make_pair(0, 0));
  
  // ???????????????
  while(!wait.empty()){
    // ????£?????????????????°?????????????????????????
    int newpoint = wait.top().second;
    int newcost = -wait.top().first;
    wait.pop();
    if(result[newpoint] < newcost){ continue; }

    // ???????????????????????¨?????????
    result[newpoint] = -INF;
    length += newcost;

    // ???newpoint????????\?¶???????????????????????????????????????? 
    for(int i = 0; i < adjlist[newpoint].size(); i++){
      int nextpoint =  adjlist[newpoint][i].second;
      int nextcost = adjlist[newpoint][i].first;
      // ????????¨??????????????£????????????????????°?????????????????????queue?????????
      if(result[nextpoint] > nextcost){
        result[nextpoint] = nextcost;
        wait.push(make_pair(-nextcost, nextpoint));
      }
    }
  }

  // ?????????: ??¨????????????
  return length;
}

Measured memory_bytes: 1436
from datetime import datetime
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    H1, M1, H2, M2, K = input().split()

    t1 = datetime.strptime(H1 + ':' + M1, '%H:%M')
    t2 = datetime.strptime(H2 + ':' + M2, '%H:%M')
    ans = int((t2 - t1).total_seconds()) // 60 - int(K)
    print(ans)


main()


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

main(void) {
  ll n,x,m;cin>>n>>x>>m;
  vector<ll> id(m,-1);
  vector<ll> a;
  ll len=0;
  ll tot=0;
  while(id[x]==-1){
    a.push_back(x);
    id[x]=len;
    tot+=x;
    len++;
    x=(x*x)%m;
  }
  ll s=0;
  ll c=len-id[x];
  for(ll i=id[x];i<=len;i++) s+=a[i];
  ll ans=0;
  if(n<=len){
    rep(i,n) ans+=a[i];
  } else {
    ans+=tot;
    n-=len;
    ans+=s*(n/c);
    n%=c;
    rep(i,n) ans+=a[id[x]+i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0 ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
 
}


int32_t main(){
  fastio;
  int x,y,z;
  cin>>x>>y>>z;
  swap(x,y);
  swap(x,z);
  cout<<x<<" "<<y<<" "<<z<<endl;

  // Math -> gcd it all // chack MAXN // check ll
  //did you check N=1? Did you mix up N,M?
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n][3];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    int dp[n][3];
    memset(dp, 0, sizeof dp);
    for(int i = 0; i < 3; i++) {
        dp[0][i] = a[0][i];
    }
    for(int i = 1; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(j == k) continue;
                dp[i][j] = max(dp[i][j], a[i][j] + dp[i - 1][k]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 3; i++) {
        ans = max(ans, dp[n - 1][i]);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <sstream>
using namespace std;



int main() {
	string s;
	cin >> s;
	long long len = (long long)s.length();
	long long sum = 0;
	for (long long bit = 0; bit < (1 << len - 1); ++bit) {
		vector<long long> v;
		string str = s;
		long long ilast = 0;
		for (long long i = 0; i < len - 1; i++) {
			if (bit & (1 << i)) {
				istringstream ss;
				ss = istringstream(s.substr(ilast, i + 1 - ilast));
				long long num;
				ss >> num;
				sum += num;
				ilast = i + 1;
			}
		}
		istringstream sstail;
		sstail = istringstream(s.substr(ilast, len));
		long long numtail;
		sstail >> numtail;
		sum += numtail;
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;
/** problem0123 : Speed Skating Badge Test **/
int main()
{
	double rank500[8] = {35.5, 37.5, 40, 43, 50, 55, 70};
	double rank1000[8] = {71, 77, 83, 89, 105, 116, 148};
	string rank[8] = {"AAA", "AA", "A", "B", "C", "D", "E"};
	double a, b;
	
	while (cin >> a >> b) {
		string ra="NA";
		for (int i=0; i<8; i++) {
			if (a < rank500[i] && b < rank1000[i]) {
				ra = rank[i];
				break;
			}
		}
		cout << ra << endl;
	}
}

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

int counter = 0;

char reVal(int num)
{
	if (num >= 0 && num <= 9)
		return (char)(num + '0');
	else
		return (char)(num - 10 + 'A');
}

void strev(char *str)
{
	int len = strlen(str);
	int i;
	for (i = 0; i < len/2; i++)
	{
		char temp = str[i];
		str[i] = str[len-i-1];
		str[len-i-1] = temp;
	}
}

int fromDeci(char res[], int base, int inputNum)
{
	int index = 0;
	while (inputNum > 0)
	{
		res[index++] = reVal(inputNum % base);
		inputNum /= base;
		counter++;
	}
	res[index] = '\0';
	return 1;
}

// Driver program
int main()
{
    int a,b;
    scanf("%d%d", &a, &b);
	int inputNum = a, base = b;
	char res[100];
	a = fromDeci(res, base, inputNum);
	printf("%d\n", counter);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <sstream>

using namespace std;

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    bool flag = true;

    if (abs(a - b) > k) {
        flag = false;
    }

    if (abs(a - c) > k) {
        flag = false;
    }

    if (abs(a - d) > k) {
        flag = false;
    }

    if (abs(a - e) > k) {
        flag = false;
    }


    if (abs(b - c) > k) {
        flag = false;
    }

    if (abs(b - d) > k) {
        flag = false;
    }

    if (abs(b - e) > k) {
        flag = false;
    }

    if (abs(c - d) > k) {
        flag = false;
    }

    if (abs(c - e) > k) {
        flag = false;
    }

    if (abs(d - e) > k) {
        flag = false;
    }

    if (flag) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n=int(input())
count=0
for i in range(1,n+1,2):
    if len(make_divisors(i))==8:
        # print(i)
        count+=1
print(count)



Measured memory_bytes: 3060
import itertools
N,M=map(int, input().split())
res=[]
for _ in range(N):
  data=list(map(int, input().split()))
  K=data.pop(0)
  A=data
  res.append(A)
flatten_list = list(itertools.chain.from_iterable(res))
cnt=0
for i in range(1, M+1):
  if flatten_list.count(i) == N:
    cnt +=1
print(cnt)


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

int main(){
    int n;
    string s;

    cin >> n >> s;
    rep(i,s.size()) {

        s[i] = (s[i] -'A' + n)%26 + 'A'; 
    }
    cout << s << endl;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

template <typename T>
ostream& operator <<(ostream& ostr, const vector<T>& a) {
	ostr << "(";
	for (size_t i = 0; i < a.size(); ++i) {
		if (i) {
			ostr << ", ";
		}
		ostr << a[i];
	}
	ostr << ")";
	return ostr;
}

const int mod = 1000000007;

long long pw(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1ll) {
			res = res * a % mod;
		}
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}

int main() {
	int n = nxt(), m = nxt();
	vector<pair<int, int>> a(m);
	for (int i = 0; i < m; ++i) {
		a[i].first = nxt() - 1, a[i].second = nxt() - 1;
	}

	vector<char> valid(n, 1);
	vector<vector<int>> alives(n), deads(n);
	for (int i = 0; i < n; ++i) {
		vector<int> alive(n, 0), dead(n, m);
		alive[i] = m;
		for (int j = m - 1; j >= 0; --j) {
			if (alive[a[j].first] && alive[a[j].second]) {
				valid[i] = false;
				break;
			} else if (alive[a[j].first] || alive[a[j].second]) {
				int id = a[j].first;
				if (alive[id]) {
					id = a[j].second;
				}
				alive[id] = j;
				dead[id] = j;
			}
		}
		for (int j = 0; j < m; ++j) {
			if (!valid[i]) {
				break;
			}
			bool isdead[2], shouldbealive[2];
			isdead[0] = (j > dead[a[j].first]);
			isdead[1] = (j > dead[a[j].second]);
			shouldbealive[0] = (j < alive[a[j].first]);
			shouldbealive[1] = (j < alive[a[j].second]);

			if (isdead[0]) {
				if (shouldbealive[1]) {
					valid[i] = false;
				} else {
					dead[a[j].second] = j;
				}
			} else if (shouldbealive[0]) {
				if (isdead[1]) {
					valid[i] = false;
				} else if (shouldbealive[1]) {
					valid[i] = false;
				} else {
					dead[a[j].second] = j;
				}
			} else {
				if (isdead[1] || shouldbealive[1]) {
					dead[a[j].first] = j;
					// don't know otherwise
					// pretty sure it's a bullshit
				}
			}
		}
		alives[i] = alive;
		deads[i] = dead;
	}

	// for (int i = 0; i < n; ++i) {
	// 	cerr << deads[i] << " " << alives[i] << "\n";
	// }

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (!valid[i] || !valid[j]) {
				continue;
			}
			bool ok = true;
			for (int k = 0; k < n; ++k) {
				if (deads[i][k] < alives[j][k] || deads[j][k] < alives[i][k]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				// cerr << i + 1 << " " << j + 1 << "\n";
				++ans;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 2304
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(i64, N, A, B);

    vector<i64> h(N);
    read(h);

    const auto divCeil = [](i64 a, i64 b) {
        return (a + b - 1) / b;
    };

    const auto isOK = [&](i64 n) {
        i64 moreCnt = 0;
        for (i64 e : h) {
            e -= n * B;
            if (e > 0) moreCnt += divCeil(e, A - B);
        }
        return moreCnt <= n;
    };

    i64 ng = 0;
    i64 ok = INF;
    while (ok - ng > 1) {
        const i64 mid = (ok + ng) / 2;
        if (isOK(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    print(ok);

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] num = new long[K];
        for (int i = 1; i <= N; i++) {
            num[i % K]++;
        }
        long sum = 0;
        for (int ar = 0; ar < K; ar++) {
            int br = (K - ar) % K;
            int cr = (K - ar) % K;
            if ((br + cr) % K != 0) {
                continue;
            }
            sum += num[ar] * num[br] * num[cr];
        }
        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 23252
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = Math.min(n * a, b);
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <stdio.h>

int check(int N) {
	int x, y;
	for (x = 0; x < 9; x++) {
		for (y = 0; y < 9; y++) {
			if ((x + 1) * (y + 1) == N) {
				return 1;
			}
		}
	}
	return 0;
}

int main() {
	int N;
	scanf("%d", &N);

	if (check(N) == 1) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from bisect import bisect_left

n, k = getList()
nums = getList()

ans = 0

for num in nums:
    if num >= k:
        ans += 1


print(ans)

Measured memory_bytes: 49904
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k>>x;
  if (n==k)ans=1;
  if (n==x)ans=1;
  if (x==k)ans=1;
  if (n==k){
    if (k==x)
    ans=0;
  }
  if (ans==1){
    cout<<"Yes"<<endl;
    return 0;
  }else{
    cout<<"No"<<endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=[int(i) for i in input().split()]
a=[[int(i) for i in input().split()]for j in range(n)]
sum=0
for i in range(n):
    tmp=0
    for j in range(m):
        tmp+=(a[i][j]*b[j])
        
    if tmp+c>0:
        sum+=1

print(sum)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main() {
    string X;
    cin >> X;

    int N = X.size();
    vector<int> s, t;
    for (int i = 0; i < N; i++) {
        if (X[i] == 'S') s.push_back(i);
        else t.push_back(i);
    }
    
    int left = 0;
    bool flag = false;
    int ans = N;
    for (int i = 0; i < N / 2&&!flag; i++) {
        for (int j = left; j < N / 2; j++) {
            if (s[i] < t[j]) {
                ans -= 2;
                left = j + 1;
                break;
            }
            else if (j == N / 2 - 1) {
                flag = true;
                break;
            }
        }
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 1660
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,K=pin()
    n=1
    for i in range(N):
        if n>=N:
            break
        n+=K-1
    print(i)
#%%submit!
resolve()

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

int main () {
  int N,K,A;
  cin >> N >> K;
  A = 1;
  for (int i=0;i<N;i++) {
    if ( A*2 < A + K ) A = A*2;
    else A = A + K;
  }
  cout << A << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int cnt_digits(ll N){
    int digits=0;

    while(N>0){
        N/=10;
        digits++;
    }
    return digits;
}

int main(void){
    ll N;
    cin >> N;
    int ans=cnt_digits(N);
    for(ll A=1LL;A*A<=N;++A){
        if(N%A!=0) continue;
        const ll B=N/A;
        const int cur=max(cnt_digits(A),cnt_digits(B));

        if(ans>cur){
            ans=cur;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n,k;
    cin>>n>>k;
    char d[k];
    rep(0,i,k)cin>>d[i];
    rep(n,N,100001){
        string nN=to_string(N);
        bool t=true;
        rep(0,i,nN.length()){
            rep(0,j,k){
                if(d[j]==nN[i])t=false;
            }
        }
        //cout<<nN<<" "<<t<<endl;
        if(t==true){
            cout<<nN;
            return 0;
        }
    }
}

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	int cityNum,roadNum;
	int city[20];
	int road[190][2];
	int roadCost[190][2];	//0:0-1 1:1-0

	int i,j;
	int start,goal,money,hashira;
	bool flg;

	cin>>cityNum>>roadNum;
	for(i=0;i<roadNum;i++){
		scanf("%d,%d,%d,%d",&road[i][0],&road[i][1],&roadCost[i][0],&roadCost[i][1]);
		road[i][0]--;road[i][1]--;
	}
	
	scanf("%d,%d,%d,%d",&start,&goal,&money,&hashira);
	start--;goal--;
	
	
	for(i=0;i<cityNum;i++) city[i]=1000000;
	city[start]=0;
	do{
		flg=false;
		for(i=0;i<roadNum;i++){
			for(j=0;j<2;j++){
				if(city[road[i][j]]+roadCost[i][j]<city[road[i][1-j]]){
					city[road[i][1-j]]=city[road[i][j]]+roadCost[i][j];
					flg=true;
				}
			}
		}
	}while(flg);
	hashira+=city[goal];
	
	for(i=0;i<cityNum;i++) city[i]=1000000;
	city[goal]=0;
	do{
		flg=false;
		for(i=0;i<roadNum;i++){
			for(j=0;j<2;j++){
				if(city[road[i][j]]+roadCost[i][j]<city[road[i][1-j]]){
					city[road[i][1-j]]=city[road[i][j]]+roadCost[i][j];
					flg=true;
				}
			}
		}
	}while(flg);
	hashira+=city[start];
	
	cout<<money-hashira<<endl;
	
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
inline void read (int & x) {
	x = 0; char c = getchar ();
	while (c < '0' || c > '9') c = getchar ();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar ();
}
int n, m;
bool d[1010][1010];
int head[1010], to[1000010], nxt[1000010], cnt;
inline void addedge (int u, int v) { cnt++, to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt; }
bool vis[1010], cl[1010];
int num[1010][2], ltk;
inline void dfs (int u, bool c) {
	if (vis[u]) {
		if (cl[u] != c) { printf ("-1\n"); exit (0); }
		return;
	}
	vis[u] = true, cl[u] = c;
	num[ltk][c]++;
	for (int e = head[u]; e; e = nxt[e]) dfs (to[e], !c);
}
int f[1010][1010];
int main () {
	//freopen ("clique.in", "r", stdin);
	//freopen ("clique.out", "w", stdout);
	read (n), read (m);
	for (int i = 1; i <= m; i++) {
		int u, v; read (u), read (v);
		d[u][v] = d[v][u] = 1;
	}
	for (int u = 1; u <= n; u++)
		for (int v = 1; v <= n; v++) if (u != v)
			d[u][v] = !d[u][v];
	for (int u = 1; u <= n; u++)
		for (int v = 1; v <= n; v++) if (u != v && d[u][v])
			addedge (u, v);
	for (int u = 1; u <= n; u++) if (!vis[u]) ltk++, dfs (u, 0);
	f[0][0] = true;
	for (int i = 1; i <= ltk; i++)
		for (int j = 0; j <= n; j++) {
			if (j >= num[i][0]) f[i][j] |= f[i - 1][j - num[i][0]];
			if (j >= num[i][1]) f[i][j] |= f[i - 1][j - num[i][1]];
		}
	int ans = 0;
	for (int i = 0; i <= n; i++) if (f[ltk][i]) ans = max (ans, min (i, n - i));
	printf ("%d\n", ans * (ans - 1) / 2 + (n - ans) * (n - ans - 1) / 2);
	return 0;
}

Measured memory_bytes: 10752
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [input().split() for i in range(n)]
import math
a,b,c = inL()
k = inN()
for i in range(k):
    if a >= b:
        b *= 2
    else:
        if b>=c:
            c *= 2
#print(a,b,c)
if a < b and b < c :
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61932
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

a,b = map(int,input().split())
ans = 0
for i in range(a,b+1):
    s = []
    t = []
    c = str(i)
    for j in range(len(c)):
        s.append(c[j])
        t.append(c[len(c)-j-1])
    if s == t:
        ans+=1
print(ans)


Measured memory_bytes: 12500
#include "bits/stdc++.h"

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? " " : "");
  outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
  cout << head << (sizeof...(tail) ? "\n" : "");
  outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
  return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
  return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  var(int, a, b);
  outl(max({a + b, a - b, a * b}));

  return 0;
}


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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 1; i <= (S.size() - 1) / 2; i++) {
    if (S.substr(0, i) == S.substr(i, i)) ans = i * 2;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    priority_queue<double> pq;
    for (int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        pq.push(tmp);
    }
    for (int i = 0; i < M; i++) {
        double tp = pq.top();
        pq.pop();
        pq.push(tp / 2);
    }
    LL ans = 0;
    while (!pq.empty()) {
          double tp = pq.top();
          pq.pop();
          ans += (LL)tp;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<int>A(N), B(N);
	rep(i, N)cin >> A[i] >> B[i];
	priority_queue<P>q;
	rep(i, N) {
		P p = { A[i] + B[i] ,i };
		q.push(p);
	}
	int ans = 0;
	rep(i, N) {
		P p = q.top();
		q.pop();
		if (i % 2 == 0)ans += A[p.second];
		else ans -= B[p.second];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3956
n=int(input())
d={}
for i in range(1,100):
    if i**2>n: break
    for j in range(i,100):
        if j**2>n: break
        for k in range(j,100):
            tmp=i**2+j**2+k**2+i*j+j*k+k*i
            if tmp>n: break
            if i==k: x=1
            elif i==j or j==k: x=3
            else: x=6
            if tmp in d:
                d[tmp]+=x
            else:
                d[tmp]=x
for i in range(1,n+1):
    if i in d: print(d[i])
    else: print(0)

Measured memory_bytes: 74252
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7  ))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
#define endl '\n'
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi;


int32_t main()
{
	IOS
	int n;cin>>n;
	vector<double>x(n),y(n);
	vector<int>per(n);
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i];
		per[i]=i;
	}
	double sum=0,cnt=0;
	do
	{
		for(int i=0;i<n-1;i++)
		{
			sum+=sqrtl( (x[per[i]] - x[per[i+1]])*(x[per[i]] - x[per[i+1]]) + (y[per[i]] - y[per[i+1]])*(y[per[i]] - y[per[i+1]]) );
		}
		cnt++;
	}while(next_permutation(per.begin(),per.end()));
	 cout << fixed << setprecision(6) << (sum/cnt) <<endl;

	
	
	
	
}



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

using namespace std;
typedef long long ll;
typedef long double ld;

const int N=100000+5;
int n,ma,k;
int v[N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>ma>>k;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    sort(v+1,v+n+1);
    int cost=1;
    int lst=v[1]+k,cur=1;
    for(int i=2;i<=n;i++)
    {
        if(cur==ma || v[i]>lst)
        {
            cost++;
            cur=1;
            lst=v[i]+k;
            continue;
        }
        cur++;
    }
    cout<<cost<<"\n";
    return 0;
}


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

const int N=1e5+10;

int n,A[N];

void Init() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&A[i]);
}

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

bool Dfs(int f) {
	int odd=0,fl=1;
	for (int j=1;j<=n;++j)  { 
		if (A[j]&1) odd++; 
		if (A[j]==1) fl=0;
	}
	if (odd>=2 && !((n-odd)&1)) return f^1;
	if (odd>=1 && (n-odd)&1) return f;
	if (!fl) return (n-odd)&1;
	for (int j=1;j<=n;++j) if (A[j]&1) { A[j]--; break; }
	int g=A[1]; for (int j=2;j<=n;++j) g=gcd(g,A[j]);
	for (int j=1;j<=n;++j) A[j]/=g;
	return Dfs(f^1);
}

void Solve() {
	if (Dfs(1)) printf("First\n");
	else printf("Second\n");
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	int buf[1000];
	buf[0]=0;
	loop(i,1,1001)buf[i]=buf[i-1]+i;
	while(cin>>n,n){
		int cnt=0;
		rep(i,n){
			for(int j=i+1;j<n;j++){
				if(buf[j]-buf[i]==n)cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 3064
from math import ceil

N,A,B = map(int,input().split())
h = sorted([int(input()) for _ in range(N)], reverse=True)

# C回以下の爆発で倒せるか
def is_all_kill(C:int):
    cnt = 0
    for HP in h:
        # あるモンスターに中心ダメージを何回与えるか
        tmp = ceil((HP-B*C)/(A-B))
        # オーバーキルの場合
        if tmp <= 0:
            break
        cnt += tmp
    return cnt <= C

ok = 10 ** 18
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if is_all_kill(mid):
        ok = mid
    else:
        ng = mid

print(ok)

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

int ra[4]={0,1,0,1};
int rb[4]={0,0,1,1};

void rev(string& to, string& from){
    char rstr[73];
    for(unsigned int i=0; i<from.length(); i++){
        rstr[i] = from[from.length()-i-1];
    }
    rstr[from.length()] = 0;
    to = rstr;
}

int main(){
    int n;
    cin >> n;
   
    for(int i=0; i<n; i++){
        string str,rstr;
        cin >> str;
        rev(rstr, str);
        unordered_set<string> train;
        train.insert(str);
        train.insert(rstr);
        
        for(unsigned int j=1; j<str.length(); j++){
            string subA[2],subB[2];
            subA[0] = str.substr(0,j);
            subB[0] = str.substr(j,str.length()-j);
            rev(subA[1], subA[0]);
            rev(subB[1], subB[0]);
            for(int r=1; r<4; r++){
                train.insert(subA[ra[r]]+subB[rb[r]]);
            }
            for(int r=0; r<3; r++){
                train.insert(subB[rb[r]]+subA[ra[r]]);
            }
        }
        cout << train.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const int n = 100010;


struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  int q;
  cin >> q;
  Sieve sieve(n);
  vi s(n,0);
  rep(i,n){
    if((i+1)%2 == 0)s[i+1] = s[i];
    else s[i+1] = s[i]+(sieve.isPrime(i+1)&sieve.isPrime((i+2)/2));
    // show(i+1);
    // show(sieve.isPrime((i+1)/2));
  }
  rep(_,q){
    int l,r;
    cin >> l >> r;
    print(s[r]-s[l-1]);
  }
  return 0;
}

Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int main()
{ int arr[100],N,x=0,s[100],max=0;
char ch;
cin>>N;
for(int i=0;i<N;i++)
{cin>>ch;
if(ch=='D'||ch=='I')
arr[i]=ch;
}
for(int j=0;j<N;j++)
{ if(arr[j]=='I')
{x++;}
if(arr[j]=='D')
{x--;}
if(x>max)
{max=x;
}
}
cout<<max;
return 0;
}


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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<pair<long long, long long>> S(N);
  for (int i = 0; i < N; i++) cin >> S[i].first >> S[i].second;
  sort(S.begin(), S.end());

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += min(S[i].first * S[i].second, S[i].first * M);
    M -= min(S[i].second, M);
    if (M == 0) break;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
# coding: utf-8


def main():
    bingo = []
    bingo.append(list(map(int, input().split())))
    bingo.append(list(map(int, input().split())))
    bingo.append(list(map(int, input().split())))
    
    list1 = [bingo[0][0], bingo[1][0], bingo[2][0]]
    list2 = [bingo[0][1], bingo[1][1], bingo[2][1]]
    list3 = [bingo[0][2], bingo[1][2], bingo[2][2]]
    list4 = [bingo[0][0], bingo[1][1], bingo[2][2]]
    list5 = [bingo[0][2], bingo[1][1], bingo[2][0]]
    
    bingo += list1, list2, list3, list4, list5
    
    n = int(input())
    num = list()
    for _ in range(n):
        num.append(int(input()))
        
    counter = 0   
    for i in range(8):
        for j in range(3):
            if bingo[i][j] in num:
                counter += 1
        if counter == 3:
            print('Yes')
            break
        else:
            counter = 0
            
    if counter != 3:
        print('No')
    
    
    return 0


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#define MAX_N 1299709 + 1
using namespace std;

bool t[MAX_N];

bool isPrime(int x) {
  if(x == 2) return true;
  if(x < 2 || x % 2 == 0) return false;
  int i = 3;
  while(i * i <= x) {
    if(x % i == 0) return false;
    i += 2;
  }
  return true;
}

void table() {
  for(int i = 1; i < MAX_N; ++i) {
    if (isPrime(i)) t[i] = 1;
  }
}

void solve(int k) {
  int p = k, n = k;
  while(t[p] != 1) p--;
  while(t[n] != 1) n++;
  cout << n - p << endl;
}

int main() {
  table();
  int k;
  while(cin >> k && k) {
    solve(k);
  }
  return 0;
}



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

int main() {
    string S;
    cin >> S;

    int ans = S.size();
    for (int i = 0; i < S.size() - 1; i++) {
        if (S[i] != S[i + 1]) {
            ans = min(ans, max(i + 1, (int)(S.size() - i - 1)));
        }
    }

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

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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

map<int, int> ans;

int main () {
	//std::ios::sync_with_stdio(false);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
    int n;
    cin >> n;
    forn(i, n) {
        int p;
        cin >> p;
        p--;
        ans[p] = ans[p - 1] + 1;
    }
    int res = 0;
    forn(i, n) {
        umx(res, ans[i]);
    }
    cout << n - res << endl;


	return 0;
}

Measured memory_bytes: 9600
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

template<typename T1, typename T2>
ostream& operator << (ostream& os, const pair<T1, T2>& p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    os << "{";
    for(int i = 0; i < v.size(); i++)
        os << v[i] << (i+1<v.size()?", ":"");
    os << "}";
    return os;
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
//}}}

int main(){
    iostream_init();
    int N, M;
    cin >> N >> M;
    vector<int> T[10000]; // type
    vector<int> E[10000]; 
    for(int s, t, e; cin >> s >> t >> e;) {
        if(s == 0) break;
        s--; t--;
        T[s].push_back(t);
        E[s].push_back(e);
    }
    int L;
    cin >> L;
    REP(_, L) {
        vector<int> B(M);
        REP(i, M) cin >> B[i];
        REP(i, N) {
            long long sum = 0;
            REP(j, T[i].size()) {
                sum += B[T[i][j]] * E[i][j];
            }
            cout << sum << " \n"[i == N-1];
        }
    }
    return 0;
}

/* vim:set foldmethod=marker: */

Measured memory_bytes: 2704
from operator import itemgetter as ig

N = int(input())
li = []
di = {}
for i in range(N):
    Si, Pi = input().split()
    Pi = int(Pi)
    li.append([Si, Pi, i + 1])

li = sorted(li, key=ig(1), reverse=True)

for sp in li:
    if sp[0] in di:
        di[sp[0]].append(sp[2])
    else:
        di[sp[0]] = [sp[2]]
    
for i, j in sorted(di.items(), key=lambda x:x[0]):
    for k in range(len(j)):
        print(j[k])

Measured memory_bytes: 3064