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

using namespace std;
typedef long long llint;

llint x[100002];

int main(void){
  llint n,k;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    llint A,B;
    cin >> A >> B;
    x[A]+=B;
  }
  for(int ans=1;ans<=100001;ans++){
    if(k<=x[ans]){
      cout << ans << endl;
      break;
    }
    k-=x[ans];
  }
  return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  vec<ll_ll> v(N);
  for (int i = 0; i < N; i++) {
    ll p, d;
    cin >> p >> d;
    v[i].fi = p + d;
    v[i].se = p - d;
  }
  sort(all(v));

  ll ans = 1;
  ll_ll cur = v[0];
  rep(i, 1, N) {
    if (v[i].se < cur.fi) continue;
    ans++;
    cur = v[i];
  }

  put(ans);
  return 0;
}


Measured memory_bytes: 1792
//-----------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
//-----------------------------------------------------------------------------

int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    cinsc;
}

//-----------------------------------------------------------------------------
 
int WA[105000]={0};
int AC[105000]={0};

int main(){
   // in_o();
    int n,m,a=0,w=0;
    cin>>n>>m;
    int p;string s;
    while(m--){
        cin>>p>>s;
        if(AC[p]) continue;
        if(s=="AC"){
            AC[p]=1;
            a++;
            w+=WA[p];
        }else if(s=="WA"){
            WA[p]++;
        }  
    }
    cout<<a<<" "<<w<<endl;
    return 0;
}


Measured memory_bytes: 4372
(a, b) = map(int, input().split())

count = 0
for i in range(a, b + 1):
    str_i = str(i)
    half_size = int(len(str_i) / 2)
    is_palindromic = True
    for j in range(half_size):
        front = j
        back = -j - 1
        if str_i[front] != str_i[back]:
            is_palindromic = False
            break
    if is_palindromic:
        count += 1
print(count)

Measured memory_bytes: 3060
s=input()
if(s[0]==s[1] and s[2]==s[3] and s[0]!=s[2]):
  print("Yes")
elif(s[0]==s[2] and s[1]==s[3] and s[0]!=s[3]):
  print("Yes")
elif(s[0]==s[3] and s[1]==s[2] and s[0]!=s[1]):
  print("Yes")
else:
  print("No")



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define MAX_M 1000000
string str6(int s){
  string strs = to_string(s);
  for(int i = 0; i < 6; i++){
    if(strs.size() == 6){
      break;
    }
    strs = "0" + strs;
  }
  return strs;
}
int main(){
  int N, M;
  int P[MAX_M] = {0}, Y[MAX_M] = {0};
  cin >> N >> M;
  pair < int, pair<int, int> > T[MAX_M];
  for(int i = 0; i < M; i++){
    cin >> P[i] >> Y[i];
    T[i].first = Y[i];
    T[i].second.first = P[i], T[i].second.second = i;
    // first 年, second.first 県, second.second 市
  }
  sort(T, T + M);
  int prefe[MAX_M];
  string ans[MAX_M];
  for(int i = 0; i < M; i++ ){
    ans[i] = "000000000000";
  }
  for(int i = 0; i < M; i++){
    prefe[T[i].second.first]++;
    ans[T[i].second.second] = str6(T[i].second.first) + str6(prefe[T[i].second.first]);
  }
  for(int i = 0; i < M; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 37504
sx, sy, tx, ty = [int(s) for s in input().split(" ")]
diff = [tx - sx, ty - sy]

print("R" * diff[0] + "U" * diff[1] + "L" * diff[0] + "D" * diff[1] + "D" + "R" * (diff[0] + 1) + "U" * (diff[1] + 1) + "L" + "U" + "L" * (diff[0] + 1) + "D" * (diff[1] + 1) + "R")

Measured memory_bytes: 9076
#include<stdio.h>
main()
{
    int a,b;
    scanf("%d %d",&a,&b);
 
    if(a<b)
        printf("a < b\n");
    else if(a>b)
        printf("a > b\n");
    else if(a == b)
        printf("a == b\n");
 
    return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int popcount(int x){
    vector<int> a;
    while(x!=0){
        a.emplace_back(x%2);
        x/=2;
    }
    int res=0;
    for(auto p:a){
        if(p==1){
            res++;
        }
    }

    return res;
}

int f(int x){
    if(x==0){
        return 1;
    }
    int pcnt=popcount(x);
    return f(x%pcnt)+1;
}

int main(){
    int N;
    string S;
    cin>>N>>S;
    vector<int> X(N);
    for(int i=0;i<N;i++){
        X[i]=(int)S[i]-(int)'0';
    }

    long long one=0;
    for(int i=0;i<N;i++){
        one+=X[i];
    }

    vector<int> m(2,0);

    for(int i=0;i<N;i++){
        m[0]=(m[0]*2)%(one+1);
        m[0]+=X[i];
    }
    if(one>1){
        for(int i=0;i<N;i++){
            m[1]=(m[1]*2)%(one-1);
            m[1]+=X[i];
        }
    }
    //cout<<"m:"<<m[0]<<" "<<m[1]<<endl;

    vector<int> ans(N);
    int k0,k1;
    k0=1;k1=1;
    for(int i=N-1;i>=0;i--){
        if(X[i]==0){
            ans[i]=f((m[0]+k0)%(one+1));

        }else{
            if(one==1){
                ans[i]=0;
            }else{
                ans[i]=f((m[1]-k1+(one-1))%(one-1));
            }

        }

        k0=k0*2%(one+1);
        if(one>1){
            k1=k1*2%(one-1);
        }
    }

    for(int i=0;i<N;i++){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N), F(N);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        cin >> F[i];
    }
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());
    
    ll L = -1;
    ll R = 1e12+1;
    while(L+1 < R){
        ll X = (L + R)/2;
        bool flag = true;
        ll cnt = 0;
        rep(i,N){
            ll t = A[i] * F[i];
            if(t > X){
                cnt += ((t-X)+F[i]-1)/F[i];
                if(cnt > K){
                    flag = false;
                    break;
                }
            }
        }
        if(flag){
            R = X;
        }else{
            L = X;
        }
    }
    cout << R << endl;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// マクロ
// forループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x)begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
// 出力
#define PRINT(x) cout<<(x)<<endl
#define PRINTA(x,n) REP(i,n)PRINT(x[i])
// 定数
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
// 略記
#define PB push_back
#define MP make_pair



int main() {
    string S, T;
    cin >> S >> T;
    if (S == T.substr(0, S.size()) && S.size() + 1 == T.size()) {
        PRINT("Yes");
    } else {
        PRINT("No");
    }
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_ARRAY 100

void bubbleSort(int *R, int n) {
	bool flag = true;
	int count = 0;
	while (flag) {
		flag = false;
		for (int j = n - 1; 0 < j; j--) {
			if (R[j] < R[j - 1]) {
				int tmp = R[j];
				R[j] = R[j - 1];
				R[j - 1] = tmp;
				flag = true;
				count++;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (i != 0) {
			cout << ' ';
		}
		cout << R[i];
	}
	cout << endl <<  count << endl;
	return;
}

int main(void) {
	int n = 0, R[MAX_ARRAY] = { 0 };
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> R[i];
	}

	bubbleSort(R, n);
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    map<string, int> cnt;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        cnt[s]++;
    }
    
    long long ans = 0;
    for (auto &p : cnt) {
        ans += 1ll * p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11264
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
from collections import defaultdict
d = defaultdict(int)
for i, a in enumerate(A):
    t = tuple(sorted([i+1, a]))
    d[t] += 1
    if d[t] == 2:
        ans += 1
print(ans)


Measured memory_bytes: 26464
#include<cstdio>
inline int in();
inline void wr(int);
int main(int argc,char**argv){
	register int x=in(),y=in(),z=in();
	x^=y^=x^=y;
	x^=z^=x^=z;
	wr(x),putchar(' '),wr(y),putchar(' '),
	wr(z),putchar('\n');
}
inline int in(){
	register char c=getchar();
	register int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(int x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}

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

int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];

    rep(i, 0, h) {
        rep(j, 0, w) {
            if (s[i][j] == '#') continue;

            int cnt = 0;
            rep(k, 0, 8) {
                int ni = i + dy[k];
                int nj = j + dx[k];

                if (ni < 0 || ni >= h) continue;
                if (nj < 0 || nj >= w) continue;
                if (s[ni][nj] == '#') cnt++;
            }
            s[i][j] = char(cnt + '0');
        }
    }
    rep(i, 0, h) cout << s[i] << endl;

    return 0;
}


Measured memory_bytes: 3548
#c
n,m = map(int,input().split())
res = 0

q = []
for i in range(m):
    q.append(list(map(int,input().split())))
p = list(map(int,input().split()))

#sのX桁目が1ならX個目のスイッチがON
for s in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1,len(q[i])):
            w = q[i][j]
            if s>>(w-1) &1 == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        res += 1
print(res)


Measured memory_bytes: 3064
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
int d;
int a;
long long add[N];
pair < int , int > monster[N];

int main(){
    scanf("%d%d%d" , &n , &d , &a);
    for(int i = 0; i < n; i++){
        int x , h;
        scanf("%d%d" , &x , &h);
        monster[i] = {x , h};
    }
    sort(monster , monster + n);
    long long ans = 0 , cur = 0;
    for(int i = 0; i < n; i++){
        long long need = (monster[i].second + a - 1) / a;
        cur += add[i];
        if(need < cur)
            continue;
        long long extra = need - cur;
        cur += extra;
        int idx = upper_bound(monster , monster + n , make_pair(monster[i].first + 2 * d + 1, -1)) - monster;
        ans += extra;
        add[idx] -= extra;
    }
    printf("%lld\n" , ans);
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include<regex>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
using namespace std;
signed main() {
	string a;
	cin >> a;
	int t;
	cin >> t;
	int flag = 0;
	while (t--)
	{
		int q;
		sc(q);
		if (q == 1)
		{
			if (flag)flag = 0;
			else flag = 1;
		}
		else
		{
			int w;
			sc(w);
			char e;
			cin >> e;
			if (flag)
			{
				if (w == 1)
					a.insert(a.end(), e);
				else
					a.insert(a.begin(), e);
			}
			else
			{
				if (w == 1)
					a.insert(a.begin(), e);
				else
					a.insert(a.end(), e);
			}
		}
	}
	if (flag)
		reverse(a.begin(), a.end());
	cout << a;
}







Measured memory_bytes: 900
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define endl            "\n"
#define pb              push_back
#define ppb              pop_back
#define mp              make_pair
#define pii             pair<int, int>
#define vi              vector<int>
#define all(x)          (x).begin(), (x).end()
#define mii             map<int, int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define sp(x,y)         fixed << setprecision(y) << x
#define w(x)            int x; cin >> x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int M = 1e9 + 7;
inline int ceili(int x, int y) { return (x + y - 1) / y; }
inline int mod(int x) { return ((x % M + M) % M); }
inline int add_mod(int a, int b) { return mod(mod(a) + mod(b)); }
inline int mul_mod(int a, int b){ return mod(mod(a) * mod(b)); }
 
void solve()
{
    int n; cin >> n;
    vector<int> a(n);

    for(auto &it : a) cin >> it;

    vector<int> suf(n + 1);
    for(int i = n - 1; i >= 1; --i) {
        suf[i] = suf[i + 1] + a[i];
    }

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ans += mul_mod(a[i], suf[i + 1]);
    }

    cout << ans % M << endl;
}
 
int32_t main()
{
    FIO;

    solve();

    return 0;
}

Measured memory_bytes: 6388
N = int(input())
W = list(map(int, input().split()))

S1 = 0
S2 = sum(W)
min_diff = 100000
for i in range(1, N):
    S1 += W[i-1]
    S2 -= W[i-1]
    diff = abs(S2-S1)
    min_diff = min(diff, min_diff)
print(min_diff)


Measured memory_bytes: 9152
program ABC162C
    implicit none
    integer(8)::i,j,k,N,ans
    read*,N
    ans=0

    do i=1,N
        do j=1,N
            do k=1,N
                ans=ans+gcd(i,gcd(j,k))
            end do
        end do
    end do

    print'(i0)',ans
contains
    integer(8) function gcd(a,b)
        implicit none
        integer(8),intent(IN)::a,b
        integer(8)::l,m,n

        m=a
        n=b

        do
            l=mod(m,n)
            if(l==0)then
                exit
            end if
            m=n
            n=l
        end do

        gcd=n
        return
    end function gcd
end program ABC162C

Measured memory_bytes: 2796
//
// Created by Akifumi Ohata on 2017/10/03.
//


#include<iostream>
#include <vector>
#include <numeric>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>

using namespace std;

using ll =  long long int;

int main() {
    ios::sync_with_stdio(false);


    int H, W;

    cin >> H >> W;

    std::vector<vector<int>> Mat;
    Mat = vector<vector<int>>(H, vector<int>(W, 0));

    int N;
    cin >> N;


    std::vector<int> Arrays;

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


    int hi = 0;
    int index = 0;
    bool reverse = false;

    int array_color_num=1;
    for (const int &p : Arrays) {

        for (int k = 0; k < p; k++) {

            if (!reverse) {
                Mat[hi][index] = array_color_num;
                if (index == (W-1)) {
                    hi++;
                    reverse = true;
                } else {
                    index++;
                }
            } else if (reverse) {
                Mat[hi][index] = array_color_num;
                if (index == 0) {
                    hi++;
                    reverse = false;
                } else {
                    index--;
                }
            }

        }
        array_color_num++;
    }


    for(const vector<int> &col : Mat){

        for(const int l : col){
            cout << l << " ";


        }
        cout << endl;

    }
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


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

	string check = "abcdefghijklmnopqrstuvwxyz";
	map<char, int> mp;

	rep(i, s.length()) mp[s[i]]++;

	for (auto c : check) {
		if (mp[c]==0) {
			cout << c << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
// Author: Jinhai Chen
#include <bits/stdc++.h>
typedef long long ll;
ll INF = 0x3f3f3f3f3f3f3f3f;
#define mst(a,x) memset(a,x,sizeof(a))
using namespace std;

int a[200];
const int M = 1e9+7;
char s[200000];
int n;
int main() {
#ifdef CJHCJH
	freopen("data.in","r",stdin);
#endif
	scanf("%d",&n);
	scanf("%s",s);	
	for(int i=0;i<n;i++) {
		a[s[i]-'a']++;
	}
	ll ans=1;
	for(int i=0;i<26;i++) {
		ans = ans*(a[i]+1) % M;
	}
	ans = (ans+M-1)%M;
	cout<<ans<<endl;
	return 0;
}















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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807/4;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  ll N, M, L; cin >> N >> M >> L;

  ll dis[N][N]; rep(i,N) fill_n(dis[i],N,LLINF);
  rep(i,M) {
    ll A, B, C; cin >> A >> B >> C;
    A--; B--;
    dis[A][B] = C;
    dis[B][A] = C;
  }

  rep(k,N) rep(i,N) rep(j,N) { dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); }
  rep(i,N) rep(j,N) dis[i][j] = dis[i][j]<=L ? 1 : LLINF;
  rep(k,N) rep(i,N) rep(j,N) { dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); }

  ll Q; cin >> Q;
  rep(i,Q) {
    ll s, t; cin >> s >> t;
    s--; t--;
    ll result = dis[s][t] != LLINF ? dis[s][t]-1 : -1;
    cout << result << endl;
  }
  return 0;
}

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

int main (void){
	int n,i,h[105],max=0,high,nozero=0,water=0;
	cin >> n;
	for(i=1;i<=n;i++) {
		cin >> h[i];
		if(h[i]!=0) nozero=1;
		if(h[i]>max) max=h[i];
	}
	h[n+1]=0;
	if(nozero==0){
		cout << "0" << endl;
		return 0;
	}
	for(high=1;high<=max;high++){
		for(i=1;i<=n;i++){
			if(h[i]>=high&&h[i+1]<high) water++;
		}
	}
	cout << water << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#define ff first
#define ss second
#define M 1000000007
typedef long long int ll;
using namespace std;
ll power(ll a,ll b){
    ll ans = 1;
    while(b>0){
        if(b%2!=0){
            ans = ((ans)*(a));
        }
        a = ((a)*(a));
        b=b/2;
    }
    return ans;
}
ll add(ll a,ll b){
    ll temp = (a%M + b%M)%M;
    if(temp>M){
        temp=temp-M;
    }
    return temp;
}
vector <vector <vector <ll>>> dp;
ll solve(const vector <ll> &a,ll n,const ll &k,ll sum,ll check){
    if(n==0){
        if((sum%k)==0){
            return 1;
        }
        return 0;
    }
    if(dp[n][sum][check]!=-1){
        return dp[n][sum][check];
    }
    if(n==a.size()){
        ll ans = 0;
        for(ll i=0;i<=a[n-1];i++){
            if(i<a[n-1]){
                ans+=solve(a,n-1,k,(sum+i)%k,0);
            }
            else
                ans+=solve(a,n-1,k,(sum+i)%k,1);
            ans=ans%M;
        }
        return dp[n][sum][check]=ans;
    }
    ll t;
    ll ans = 0;
    if(check==0){
        t=9;
    }
    else
        t = a[n-1];
    for(ll i=0;i<=t;i++){
        if(check && i==t){
            ans+=solve(a,n-1,k,(sum+i)%k,1);
        }
        else
            ans+=solve(a,n-1,k,(sum+i)%k,0);
        ans=ans%M;
    }
    return dp[n][sum][check]=ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    ll k;
    cin>>s>>k;
    vector <ll> a;
    for(ll i=0;i<s.length();i++){
        a.push_back(s[i]-'0');
    }
    reverse(a.begin(),a.end());

    ll n = a.size();
    dp.assign(n+1,vector <vector <ll>> (k+1,vector <ll> (2,-1)));
    ll ans = solve(a,n,k,0,0);
    cout<<(ans-1+M)%M<<endl;
    return 0;
}


Measured memory_bytes: 56960
n=int(input())
da=list(map(int ,input().split()))
m=int(input())
di=list(map(int ,input().split()))

def bino(le,ri,k):
    if ri-le<2:
        return False
    x=(ri+le)//2
    if da[x]==k:
        return True
    elif da[x]>k:
        return bino(le,x,k)
    else:
        return bino(x,ri,k)

ans=0
for i in di:
    if da[0]==i or da[n-1]==i:
        ans+=1
        continue
    if bino(0,n-1,i):
        ans+=1
print(ans)


Measured memory_bytes: 16720
// AOJ 1212: Mirror Illusion
// 2018.1.23 bal4u@uu

#include <stdio.h>
#include <string.h>

char mir[9][9][9][9];
int mv[4][2] = {{50,50},{-50,50},{-50,-50},{50,-50}};
int tr[2][4] = {{3,2,1,0},{1,0,3,2}};

int main()
{
	int n, i, v, x, y, d, wall;
	char s[5];

	while (scanf("%d", &n) && n >= 0) {
		memset(mir, 0, sizeof(mir));

		for (i = 0 ; i < n ; i++) {
			scanf("%s%d%d", s, &x, &y);
			if (*s == 'x') mir[x][y][x+1][y] = 1;
			else           mir[x][y][x][y+1] = 1;
		}

		x = 50, y = 0, d = 0, wall = 1;
		for (v = 1, i = 0; ; i++, v = !v) {
			if (i >= 2) {
				if (x == 100 && y == 50 && d == 0) { x = 75, y = 25; break; }
				if (wall && (!x || !y || x == 800 || y == 800)) break;
			}

	        x += mv[d][0], y += mv[d][1], wall = 1;

			if (v) {
				if (mir[x/100][(y-50)/100][x/100][(y+50)/100]) d = tr[v][d], wall = 0;
			} else {
				if (mir[(x-50)/100][y/100][(x+50)/100][y/100]) d = tr[v][d], wall = 0;
			}
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}


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

int main(){
	int H, W;
	while(1){
	cin >> H >> W;
	if( H == 0 && W == 0 ) return 0;
	for( int i = 0; i < H; i++ ){ 
	for( int j = 0; j < W; j++ ){ if( i == 0 || i == H - 1 || j == 0 || j == W - 1 ){ cout << "#"; }else{ cout << "."; }  }
	cout << "\n";
	}
	cout << endl;
	}
return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
int main()
{
    double n,a,b,c;
    cin>>n;
    n=n/3;
    n=n*n*n;
    cout<<showpoint;
    cout<<fixed;
    cout<<setprecision(12);
    cout<<n<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n>>m;
        k = n+m;
        i = n+n-1;
        j = m+m-1;
        q = max(i,j);
        q = max(q,k);
        cout<<q<<endl;
    }
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>

typedef struct{
	int parent; //parent
	int left; //chlid of left
	int right; //sibling of right
}Node;

int main(){
	int n, k, id, ch, sib, dep, p, i, j;
	Node *T;

	scanf("%d", &n);

	T = malloc(sizeof(Node)*n);

	//initialize
	for(i = 0; i < n; i++){
		T[i].parent = -1;
		T[i].left = -1;
		T[i].right = -1;
	}

	for(i = 0; i < n; i++){
		scanf("%d %d", &id, &k);

		for(j = 0; j < k; j++){
			scanf("%d", &ch);
			T[ch].parent = id;

			if(j == 0) T[id].left = ch; //insert left child
			else if(j > 0) T[sib].right = ch; //insert sibling

			sib = ch;
		}
	}

	for(j = 0; j < n; j++){
		dep = 0;
		p = T[j].parent;

		//parent of root = -1
		while(p != -1){
			p = T[p].parent; //p is parent
			dep++;
		}
		if(dep == 0){
			printf("node %d: parent = -1, depth = 0, root, [", j);
		}
		else if(T[j].left == -1){
			printf("node %d: parent = %d, depth = %d, leaf, [", j, T[j].parent, dep);
		}
		else{
			printf("node %d: parent = %d, depth = %d, internal node, [", j, T[j].parent, dep);
		}

		p = T[j].left;
		if(p != -1) printf("%d", p);

		while(p != -1){
			p = T[p].right;
			if(p != -1) printf(", %d", p);
		}
		printf("]\n");
	}

	return 0;
}

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

int a;
int main() {
  cin >> a;
  
  int mx = 1;
  for (int i = 2; i * i <= a; ++i) {
    int base = i * i;
    while (base <= a) {
      mx = max(mx, base);
      base *= i;
    }
  }
  cout << mx << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;


int main(int argc, const char * argv[])
{
    int n;
    while(cin >> n){
        int times[n];
        for(int i = 0; i < n; i++){
            cin >> times[i];
        }
        sort(times, times+n);
        
        int part_sum = 0;
        int all_sum = 0;
        
        for(int i = 0; i < n; i++){
            part_sum += times[i];
            all_sum += part_sum;
        }
        
        cout << all_sum << "\n";
    }
    return 0;
}

Measured memory_bytes: 1176
<?php
$N = trim(fgets(STDIN));
$A = explode(" ",trim(fgets(STDIN)));

--$N;
$c = 0;
while($N >= 0){
    if($A[$N] % 2 == 1){
        ++$c;
    }
    --$N;
}

if($c % 2 == 0){
    echo "YES";
}else{
    echo "NO";
}

?>


Measured memory_bytes: 22064
#include <iostream>
#include <string>
#include <vector>
#include "limits.h"
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>

#define mod 1000000000+7;
typedef long long ll;
using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int a,b;
	cin >> a >> b;
	cout << 6-(a+b) << "\n";
 

}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

int N, M;
long long int a[1004];
int b[1004], c[1004][20];

long long int dis[5000];

int L;

long long int INF = 9999999999999;

int main(void) {

	cin >> N >> M;

	for (int i = 1; i <= M; i++) {
		cin >> a[i] >> b[i];
		for (int j = 1; j <= b[i]; j++) {
			cin >> c[i][j];
		}
	}

	L = (1 << N) - 1;

	for (int i = 0; i <= L; i++) {
		dis[i] = INF;
	}

	dis[0] = 0;

	for (int m = 0; m <= L; m++) {
		for (int i = 1; i <= M; i++) {
			int K = m;
			for (int j = 1; j <= b[i]; j++) {
				K |= ((long long int) 1 << (c[i][j] - 1));
			}
			dis[K] = min(dis[K], dis[m] + a[i]);
		}
	}

	if (dis[L] == INF) { cout << -1 << endl; }
	else { cout << dis[L] << endl; }

	/*for (int m = 0; m <= L; m++) {
		cout << bitset<8>(m) << " " << dis[m] << endl;
	}*/

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    vector<ll> sv(n),tv(n);
    sv[0] = v[0];
    tv[n-1] = v[n-1];
    FOR(i,1,n) sv[i] = sv[i-1] + v[i];
    FOR(i,1,n) tv[n-i-1] = tv[n-i] + v[n-i-1];

    ll ans = 1LL << 60;
    REP(i,n-1) {
        ans = min(ans,abs(sv[i]-tv[i+1]));
    }

    cout << ans << '\n';

    return 0;
}

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

int main() {
	int n,m,a[100],b[100],c[100],d[100],e[100][100],f[100];
	cin >>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		
	}
	for(int i=1;i<=m;i++){
		cin >>c[i]>>d[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			e[i][j]=abs(a[i]-c[j])+abs(b[i]-d[j]); 
		if(j==1)f[i]=e[i][j];	
		else{	f[i]=min(f[i],e[i][j]);
		}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
		
			if(f[i]==e[i][j]){
				cout<<j<<endl;
				break;
			}
			
		}
	}
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n= readLine()!!.toLong()
    val rtn=Math.sqrt(n.toDouble()).toLong()

    var min=111
    for(i in 1..rtn){
        if(n%i==0L){
            min=Math.min(min,
                    Math.max(digit(i),digit(n/i))
            )
//            println("$i,$min")
        }
    }
    println(min)
}

fun digit(a:Long) = a.toString().length


Measured memory_bytes: 31736
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


string s;

int main(){
	cin >> s;
	int n = s.size();
	
	string prev = s.substr(0,1);
	int ans = 1;
	for(int i = 1; i < n; i++){
		int j;
		for(j = 1; j+i <= n; j++){
			if(prev != s.substr(i,j)){
				ans++;
				prev = s.substr(i,j);
				break;
			}
		}
		i += j - 1;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
s = input()

if(s == "SUN"):
    print("7")
if(s == "MON"):
    print("6")
if(s == "TUE"):
    print("5")
if(s == "WED"):
    print("4")
if(s == "THU"):
    print("3")
if(s == "FRI"):
    print("2")
if(s == "SAT"):
    print("1")

Measured memory_bytes: 3064
H = int(input())
L = list(map(int, input().split()))
def maxHeapify(A, i):
    l = i * 2 + 1
    r = i * 2 + 2
    if l < H and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r < H and A[r] > A[largest]:
        largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(A, largest)
def buildMaxHeap(A):
    for i in range(H // 2, -1, -1):
        maxHeapify(A, i)
buildMaxHeap(L)
print("", *L)



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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lep(j, n) for (int j = 0; j < (n); j++)
#define reps(i, n) for (int i = 1; i < (n); i++)
#define leps(i, n) for (int j = 1; j < (n); j++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define int long long
#define gsort(x, n) sort((x), (x) + (n), greater<int>());
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

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

   int a, b;
   int c, d, e;
   cin >> a >> b;
   c = a + b;
   d = a - b;
   e = a * b;

   a = max(c, d);
   cout << max(a, e) << '\n';
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef struct Goods_ {
    u_int value;
    u_int weight;
} Goods;

int main(void)
{
    u_int n, total;
    cin >> n >> total;
    Goods goods[n];
    for (u_int i = 0; i < n; i++) {
        u_int v, w;
        cin >> v >> w;
        goods[i] = Goods{v, w};
    }

    u_int values[total+1];
    for (u_int i = 0; i <= total; i++)
        values[i] = 0;
    
    for (u_int i = 0; i < n; i++) {
        Goods g = goods[i];
        for (u_int w = total; w >= g.weight; w--)
            values[w] = max(g.value + values[w - g.weight], values[w]);
    }

    cout << values[total] << endl;
    
    return 0;
}

Measured memory_bytes: 1188
// http://codeforces.com/contest/1315/problem/D
// Greedy
// time complexity limitation
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <deque>

#define ll long long
#define ull unsigned long long

using namespace std;

const int MOD = 1e9+7;
const int inf = 0x3f3f3f3f;
const int PI = acos(-1.0);

const int N = 2e5+10;


int main() {
	#ifdef local
		if(freopen("/Users/Andrew/Desktop/Problems/data.txt", "r", stdin) == NULL) printf("can't open this file!\n");
	#endif

    int n, k;
    cin >> n >> k;
    int mx = -1;
    int pre = 0;
    int first = 0;
    int tmp;
    for (int i = 0; i < k; ++i) {
        cin >> tmp;
        if (i == 0) {
            first = tmp;
            pre = tmp;
            continue;
        }
        mx = max(mx, tmp-pre);
        pre = tmp;
    }
    mx = max(first+n-tmp, mx);
    cout << n-mx << endl;
	#ifdef local
	fclose(stdin);
	#endif
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int D;
    cin >> D;
    int N = 26;
    vi c(N);
    vvi s(D,vi(N));
    in(N,c);
    rep(i,D) rep(j,N) cin >> s[i][j];
    
    vi ans(D,1);
    
    vi las(N,-1);
    
    
    rep(d,D){
        int los = 0;
        rep(i,N) los += c[i]*(d-las[i]);
        int an = -infi;
        rep(i,N){
            if(chmax(an,s[d][i]-los+c[i]*(d-las[i]))) ans[d] = i+1;
        }
        las[ans[d]-1] = d;
    }









    rep(i,D) cout << ans[i] << endl;
    
    

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    string s, p;
    cin >> s >> p;
    s += s;
    string ans;
    if (s.find(p) != - 1) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
    return 0; 
}



Measured memory_bytes: 3224
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 100001

using namespace std;

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

int main() {
  ll N;
  ll A[MAX_N];
  cin >> N;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  sort(A, A + N);

  ll cur, pre = -1;
  ll count = 0;

  for (ll i = 0; i < N; i++) {
    cur = A[i];
    if (cur == pre) {
      count++;
    }
    pre = cur;
  }

  if (count % 2 == 1) {
    count++;
  }

  cout << N - count << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
string s;
int rez;
int main()
{
    cin >> s;
    rez = s.size();
    for(int i = 0; i < (int)s.size() - 1;i++){
        if(s[i] != s[i + 1]){
            rez = min(rez,max(i + 1,(int)s.size() - 1 - i));
        }
    }
    cout << rez;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    cout << a[n - 1] - a[0];
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>

int main(void){
  int N, M, counter = 0;
  bool is_exist = false;
  std::string line;

  std::cin >> N >> M;
  std::cin.ignore();

  char a[N][N], b[M][M];

  for (int i = 0; i < N; i++) {
    getline(std::cin, line);
    for (int j = 0; j < N; j++) {
      a[i][j] = line[j];
    }
  }
  for (int i = 0; i < M; i++) {
    getline(std::cin, line);
    for (int j = 0; j < M; j++) {
      b[i][j] = line[j];
    }
  }

  for (int i = 0; i <= N-M; i++) {
    for (int j = 0; j <= N-M; j++) {
      counter = 0;
      for (int k = 0; k < M; k++) {
        for (int l = 0; l < M; l++) {
          if (a[i+k][j+l] == b[k][l]) {
            counter++;
            if (counter == M*M) {
              is_exist = true;
            }
          }
        }
      }
    }
  }

  if (is_exist) {
    std::cout << "Yes\n";
  }else{
    std::cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    map<string, vector<ll>> m;
    vector<ll> Ps;
    rep(i, N) {
        string S;
        ll P;
        cin >> S >> P;
        Ps.push_back(P);
        if (m.find(S) == m.end()) {
            vector<ll> tmp;
            tmp.push_back(P);
            m[S] = tmp;
        } else {
            m[S].push_back(P);
        }
    }
    for(pair<string, vector<ll>> v : m) {
        sort(all(v.second));
        reverse(all(v.second));
        rep(i, v.second.size()) {
            rep(j, N) {
                if (v.second[i] == Ps[j]) {
                    print(j+1);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc106/tasks

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

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

	for (int i = 0; i < min((long long)S.size(), K); i++) {
		if (S[i] >= '2') { 
            cout << S[i] << endl;
            return 0; 
        }
	}

	cout << '1' << endl;
    
	return 0;
}

Measured memory_bytes: 256
while True :
    n = int(input())
    if n == 0 :
        break
    
    que = []
    for i in range(n) :
        que.append(int(input()))
    que.sort()
    
    time = 0
    for i in range(n) :
        time += sum(que[0:i])
    print(time)


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

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

const long long MOD = 1000000007;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  bool ans = true;
  rep(i,(n-1)/2){
    if(s.at(i)!=s.at(n-1-i)){ 
      ans=false;
      //cout << 1 << endl;
    }
  }
  rep(i,((n-1)/4)){
    if(s.at(i)!=s.at((n-1)/2 - 1 - i)){
      ans=false;
      //cout << 2 << endl;
    }
  }
  rep(i,((n-1)/4)){
    if(s.at(i+(n-1)/2 + 1)!=s.at((n-1)/2 - i +(n-1)/2)){ 
      ans=false;
      //cout << 3 << endl;
    }
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl; 
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    
    if ((B - A) / 2 + 1 <= K) {
        for (int i = A; i <= B; i++)
            cout << i << endl;
        return 0;
    }
    
    for (int i = A; i < A + K; i++)
        cout << i << endl;
    for (int j = B - K + 1; j <= B; j++)
        cout << j << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n;
	cin>>n;
	long double res = 1.0 * n /3.0;
	cout<<setprecision(18);
	cout<<res*res*res<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A_i = list(map(int, input().split()))
    t = 10**18

    if 0 in A_i:
        print(0)
        return

    acc = 1
    for i in A_i:
        acc *= i
        if t < acc:
            print(-1)
            return

    print(acc)
    return


main()


Measured memory_bytes: 21656
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 200006
#define mo 19491001
using namespace std;
int n,x;char c[N];
long long ans;
int main()
{
	scanf("%s",c+1);n=strlen(c+1);
	for(int i=n;i>=1;i--)
		if(c[i]=='W')x++;else ans=ans+1LL*x;
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#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;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,m;
	cin >> n >> m;
	cout << (n*(n-1))/2 + (m*(m-1))/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K,ans = 1;
  cin >> N >> K;
  for (int i = 0;i < N;++i){
    if (ans*2 > ans+K)
      ans += K;
    else
      ans *= 2;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define BACK(x) prev((x).end())
#define HASK(x, y) ((x).find(y) != (x).end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 19;

int T[maxN];

void solve()
{
	int n, mn = maxN, res = 0;
	scanf ("%d", &n);
	FOR(i, 0, n)
	{
		scanf ("%d", T+i);
		if (T[i] < mn)
		{
			mn = T[i];
			res++;
		}
	}
	printf("%d\n", res);
}
 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}





Measured memory_bytes: 4580
import collections
from functools import lru_cache


def read():
    return input().strip()


def readInt():
    return int(input().strip())


def readList():
    return list(map(int, input().strip().split()))


def solve(n, arr):
    ans = 0

    for i, val in enumerate(arr, 1):
        if i & 1 and val & 1:
            ans += 1

    return ans


n = readInt()
arr = readList()

print(solve(n, arr))


Measured memory_bytes: 66688
#include <bits/stdc++.h>
using namespace std;
int main () {
  vector<int> data(4);
  int a;
  for(int i = 0; i < 6; i++){
    cin >> a;
    data.at(a - 1)++;
  }
  int one = 0, two = 0;
  for(int i = 0; i < 4; i++){
    if(data.at(i) == 2)two++;
    if(data.at(i) == 1)one++;
  }
  int flag = 0;
  if(one == 2 && two == 2)flag = 1;
  cout << (flag ? "YES": "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,flag,count,x,i,tmp;
	count = 0;
	scanf("%d", &n);
	int value[n];
	for(i=0;i<n;i++){
			scanf("%d", &x);
			value[i] = x;
	}
	flag=1;
	while(flag){
		flag = 0;
		for(int j=n-1;j>0;j--){
			if(value[j] < value[j-1]){
				tmp = value[j];
				value[j] = value[j-1];
				value[j-1] = tmp;
				flag = 1;
				count++;
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%d", value[i]);
		if(i==n-1){
			printf("\n");
		} else{
			printf(" ");
		}
	}
	printf("%d\n", count);
}



Measured memory_bytes: 1992