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

bool isok(int pret,int t,int px,int py,int x,int y){
    return abs(x-px)+abs(y-py)<=t-pret && ((x-px+y-py+t-pret)%2==0);
}


int main(){
    int n;
    cin>>n;
    int pret=0,px=0,py=0;
    bool ans=true;
    for(int i=0;i<n;i++){
        int t,x,y;
        cin>>t>>x>>y;
        ans&=isok(pret,t,px,py,x,y);
        px=x,py=y;
        pret=t;
    }
    cout<<(ans ? "Yes" : "No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
int a[N];
bool b[N];
int n, sz;
bool check(int x) {
  for (int i = 1; i <= sz; ++ i) {
    b[i] = a[i] <= x;
  }

  int rp = 0;
  for (int i = n + 1; i <= sz; ++ i) {
    if (b[i] == b[i - 1]) {
      rp = i - n;
      break;
    }
  }

  int lp = 0;
  for (int i = n - 1; i; -- i) {
    if (b[i] == b[i + 1]) {
      lp = n - i;
      break;
    }
  }

  if (!rp && !lp) return b[1];

  if (!rp) return b[n - lp];
  if (!lp) return b[n + rp];

  if (rp == lp) return b[n - lp];

  // printf("%d %d\n", lp, rp);
  if (rp < lp) {
    return b[n + rp];
  } else {
    return b[n - lp];
  }

}

int main(int argc, char const *argv[]) {
  // freopen("D:/1_03.txt", "r", stdin);
  n = read(); sz = 2 * n - 1;
  for (int i = 1; i <= sz; ++ i) {
    a[i] = read();
  }

  int l = 1, r = sz;

  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) r = mid - 1;
    else l = mid + 1;
  }

  printf("%d\n", r + 1);

  return 0;
}
/*

1 6 3 7 4 5 2

1 0 0 0 0 0 0 false
1 0 0 0 0 0 1 false
1 0 1 0 0 0 1 false
1 0 1 0 1 0 1 true
1 0 1 0 1 1 1 true
1 1 1 0 1 1 1 true
1 1 1 1 1 1 1 true


*/

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define MAXX 100005
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long 

#define mod  1000000007



int main()
{
	FAST;
	int n;
	cin >> n;
	int a[n+5];
	ll x = 0;
	for(int i = 0; i < n; i ++){
		cin >> a[i];
		if(i % 2 == 0){
			x += a[i];
		}
		else{
			x -= a[i];
		}
		
	}
	cout << x << " ";
	for(int i = 0; i < n-1; i ++){
		x = 2*a[i] - x;
		cout << x  << " ";
	}
	return 0;
	
}

Measured memory_bytes: 4024
#!python3.8
# -*- coding: utf-8 -*-
# abc170/abc170_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    X, N = i2nn()
    if N == 0:
        print(X)
        return
    p = set(i2nn())
    for i in range(101):
        if X - i not in p:
            print(X - i)
            return
        if X + i not in p:
            print(X + i)
            return

    return

main()


Measured memory_bytes: 9228
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
#warning "// FOR has been inclusive now!!!!"
ll n;
vector<vector<ll>> A;
int main()
{
	FAST
	cin>>n;
	A.resize(n+1, vector<ll>(n, 0));
	FOR(i,1,n) FOR(j,1,n-1) cin>>A[i][j];
	FOR(i,1,n) reverse(all(A[i])), A[i].pop_back();
	queue<pi> q; ll ans=0;
	FOR(i,1,n) FOR(j,i+1,n) if(A[i].back()==j&&A[j].back()==i) q.emplace(i,1);
	while(q.size()) {
		ll x=q.front().f; ll y=A[x].back(); ll d=q.front().s; q.pop(); ans=max(ans, d);
		A[x].pop_back(), A[y].pop_back();
		if(A[x].size() && A[A[x].back()].back()==x) q.emplace(x, d+1);
		swap(x,y);
		if(A[x].size() && A[A[x].back()].back()==x) q.emplace(x, d+1);
	}
	FOR(i,1,n) if(A[i].size()) { cout<<"-1\n"; return 0; }
	cout<<ans<<'\n';
}


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

int main(){
  string S;
  cin >> S;
  long long n, r, l;
  r = 0; l = 0;
  n = S.size();
  vector<long long> right(n+1), left(n+1);
  left[0] = 0;
  for(int i=0; i<n; i++){
    if(S[i] == '<') l++;
    else l=0;
    left[i+1] = l;
  }
  right[n] = 0;
  for(int i=n-1; i>=0; i--){
    if(S[i] == '>') r++;
    else r=0;
    right[i] = r;
  }
  long long ans=0;
  for(int i=0; i<=n; i++){
    ans += max(left[i], right[i]);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 8708
{-# LANGUAGE BangPatterns        #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE RankNTypes          #-}
{-# LANGUAGE ScopedTypeVariables #-}
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State
import           Data.Array.IArray
import           Data.Array.ST
import           Data.Array.Unboxed
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.Int              (Int64)
import           Data.List

main :: IO ()
main = do
  [h,w] <- readLnAsListWith unconsInt
  as <- readLnAs2DArrayWith unconsChar h w :: IO (UArray (Int,Int) Char)

  let gd = gridDfs (h,w) (\g (i,j) -> g ! (i,j) == '#') as

  print $ gd ! (h,w)


type Grid a = UArray (Int,Int) a

-- グリッドグラフのDFS
-- 解くべき問題により、シグネチャは変更する
gridDfs :: (Int,Int) -> (Grid Char -> (Int,Int) -> Bool) -> Grid Char -> Array (Int,Int) IntMod
gridDfs (h',w') f g = runSTArray $ do
  dp <- newArray ((1,1),(h',w')) intmodZero :: ST s (STArray s (Int,Int) IntMod)
  writeArray dp (1,1) 1

  forM_ [2..h'] $ \h -> do
    u <- if f g (h-1,1) then return 0 else readArray dp (h-1,1)
    writeArray dp (h,1) $ if f g (h,1) then 0 else u

  forM_ [2..w'] $ \w -> do
    l <- if f g (1,w-1) then return 0 else readArray dp (1,w-1)
    writeArray dp (1,w) $ if f g (1,w) then 0 else l

  forM_ [2..h'] $ \h -> forM_ [2..w'] $ \w -> do
    l <- if f g (h,w-1) then return 0 else readArray dp (h,w-1)
    u <- if f g (h-1,w) then return 0 else readArray dp (h-1,w)
    writeArray dp (h,w) $ if f g (h,w) then 0 else l + u

  return dp

modulus :: Int64
-- modulus = 10^9 + 7
modulus = 1000000007

newtype IntMod = IntMod Int64 deriving Eq

-- fromIntegral_Int64_IntMod :: Int64 -> IntMod
-- fromIntegral_Int64_IntMod n = IntMod (n `mod` modulus)
-- {-# RULES
-- "fromIntegral/Int->IntMod"
--     fromIntegral = fromIntegral_Int64_IntMod . (fromIntegral :: Int -> Int64)
-- "fromIntegral/Int64->IntMod"
--     fromIntegral = fromIntegral_Int64_IntMod
-- #-}

instance Show IntMod where
  show (IntMod x) = show x

instance Num IntMod where
  IntMod x + IntMod y = IntMod ((x + y) `mod` modulus)
  IntMod x - IntMod y = IntMod ((x - y) `mod` modulus)
  IntMod x * IntMod y = IntMod ((x * y) `mod` modulus)
  fromInteger n = IntMod (fromInteger (n `mod` fromIntegral modulus))
  abs = undefined
  signum = undefined

intmodZero :: IntMod
intmodZero = 0 :: IntMod


-- converter
unconsChar :: StateT BS.ByteString Maybe Char
unconsChar = StateT BS.uncons

unconsInt :: StateT BS.ByteString Maybe Int
unconsInt = StateT $ BS.readInt . BS.dropWhile isSpace

-- 1D Data
-- for list
readLnAsListWith :: StateT BS.ByteString Maybe a -> IO [a]
readLnAsListWith !st = unfoldr (runStateT st) <$> BS.getLine

readLnAs2DArrayWith :: IArray a e => StateT BS.ByteString Maybe e -> Int -> Int -> IO (a (Int,Int) e)
readLnAs2DArrayWith !st !n !m = listArray ((1,1),(n,m)) . unfoldr (runStateT st) . BS.concat <$> replicateM n BS.getLine



Measured memory_bytes: 154424
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    D, T, S = mi()
    if D <= S*T:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9568
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
int A,B;
cin >>A>>B ;
if(A>=13){
cout<<B<<"\n";
}else if (A>=6){
cout<<B/2<<"\n";
}else{
cout<<0<<"\n";
}

        
        
        
        return 0;
}


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

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
    int p=0;
	// ユークリッドの方法
	while( m > n )
	{
        m = m/2;
        p+=1;
	}
	return p;
}//gcd

int main()
{
    int n,i;
    string a,b;
    cin >>n ;
    cin >> a >> b;
    for(i=0;i<n;i++){
        cout << a[i] << b[i];
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int N;
ll D, A;
vector<ll> X, H;

ll solve(){
    vector<int> ids(N);
    for(int i = 0; i < N; i++) ids[i] = i;
    sort(ids.begin(), ids.end(), [&](int i, int j) {return X[i] < X[j]; });
    vector<ll> nX(N), nH(N);
    for(int i = 0; i < N; i++) nX[i] = X[ids[i]], nH[i] = H[ids[i]];
    X = nX, H = nH;

    vector<ll> S(N+1, 0);
    ll res = 0;
    for(int i = 0; i < N; i++){
        if(S[i] < H[i]){
            ll need = (H[i] - S[i] + A - 1) / A;
            ll right = X[i] + D * 2;
            int id = upper_bound(X.begin(), X.end(), right) - X.begin();

            S[i] += need * A;
            S[id] -= need * A;
            res += need;
        }
        S[i+1] += S[i];
    }
    return res;
}

int main(){
    cin >> N >> D >> A;
    X.resize(N); H.resize(N);
    for(int i = 0; i < N; i++) cin >> X[i] >> H[i];
    cout << solve() << endl;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,k,ans;
int a[111111],b[111111],c[111111],q;
map<int,int> m;
signed main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		m[a[i]]++;
		ans+=a[i];
	}
	cin>>q;
	rep(i,q)cin>>b[i]>>c[i];
	rep(i,q){
		ans+=(c[i]-b[i])*m[b[i]];
		m[c[i]]+=m[b[i]];m[b[i]]=0;
		cout<<ans<<endl;
	}
	
}

Measured memory_bytes: 11892
# -*- coding: utf-8 -*-
# template: v1.2

import io
import sys
import math

def solve(n,k,x,y):
    # implement process
    higher = n-k
    if higher < 1:
        return n*x
    else:
        return k*x + higher*y



def main():
    # input
    n,k,x,y = map(int,sys.stdin.read().split())
    
    # process
    ans = str( solve(n,k,x,y) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
2
3
10000
9000
"""
_EXPECTED = """\
20000
"""

def logd(str):
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
double EPS = 1e-10;
typedef pair<long long, long long> P;
int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++){
        long double a;
        cin >> a;
        A[i] = a * 1e9 + 0.01;
    }
    vector<P> cnt(N);
    for(int i = 0; i < N; i++){
        long long f = 0, n = 0;
        while(A[i] % 5 == 0){
            f++;
            A[i] /= 5;
        }
        while(A[i] % 2 == 0){
            n++;
            A[i] /= 2;
        }
        cnt[i] = P(f, n);
    }
    vector<vector<long long>> dp(24, vector<long long> (50, 0));
    for(int i = 0; i < N; i++){
        P p = cnt[i];
        dp[p.first][p.second]++;
    }
    for(int k = 0; k < 24; k++){
        for(int j = 1; j < 50; j++){
            dp[23 - k][49 - j] += dp[23 - k][50 - j];
        }
    }
    for(int k = 0; k < 50; k++){
        for(int j = 1; j < 24; j++){
            dp[23 - j][49 - k] += dp[24 - j][49 - k];
        }
    }
    long long ans = 0;
    long long cntf = 18, cntn = 18;
    for(int i = 0; i < N; i++){
        P p = cnt[i];
        if(p.first * 2 >= 18 && p.second * 2 >= 18) ans--;
        ans += dp[max(0LL, cntf - p.first)][max(0LL, cntn - p.second)];
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 8016
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<int>d(n);
	for (int i = 0; i < n; i++)cin >> d[i];
	sort(d.begin(), d.end());
	int count = 1;
	for (int i = 0; i < n; i++) {
		if (i > 0 && d[i] > d[i - 1]) {
			count++;
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<limits.h>
int main()
{
	double V,y,v,t;
	while(scanf("%lf",&V)>0)
	{
		int l=0,r=INT_MAX,m;
		while(l<r)
		{
			m=(l+r)/2;
			y=5.*m-5;
			t=sqrt(y/4.9);
			v=9.8*t;
			if(V<=v)r=m;
			else l=m+1;
		}
		printf("%d\n",l);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i, N) for(int i=0;i<N;++i)
#define REPA(i, N) for(int i=1;i<N;++i)
#define MOD ((int)1e9+7)
using namespace std;
int main(){
    int N, L;
    cin >> N >> L;
    vector<int> sp(N), ran(N);
    REP(i, N){
        cin >> sp[i];
    }
    REP(i, N){
        cin >> ran[i];
    }
    vector<vector<int> > dp(N, vector<int>(L, 0));
    for(int i=sp[0];i<L;i+=ran[0]){
        dp[0][i] = 1;
        if(ran[0]==0)break;
    }
    REPA(i, N){
        for(int j=sp[i];j<L;j+=ran[i]){
            int sum = 0;
            if(ran[i]==0){
                REP(k, sp[i]){
                    sum = (sum + dp[i-1][k])%MOD;
                }
                dp[i][j] = sum;
                break;
            }else if(j==sp[i]){
                REP(k, sp[i]){
                    sum = (sum + dp[i-1][k])%MOD;
                }
                dp[i][j] = sum;
            }else{
                for(int k=j-ran[i];k<j;++k){
                    sum = (sum + dp[i-1][k])%MOD;
                }
                dp[i][j] = (dp[i][j-ran[i]] + sum)%MOD;
            }
        }
    }
    int ans = 0;
    REP(i, L){
        ans = (ans + dp[N-1][i])%MOD;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 100744
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, P;
  cin>>N>>P;
  string A;
  cin>>A;
  for(char &ch:A) ch -= '0';

  if(P == 2 || P == 5){
    Int ans = 0;
    for(Int i=0;i<N;i++){
      if(A[i]%P != 0) continue;
      ans += i + 1;
    }
    cout<<ans<<endl;
    return 0;
  }


  map<Int, Int> cnt;
  vector<Int> B(N);
  vector<Int> k(N);
  k[0] = 1;
  for(Int i=0;i<N-1;i++) k[i+1] = k[i] * 10 % P;

  B[0] = A[0] * k[N-1] % P;
  for(Int i=1;i<N;i++) B[i] = (B[i-1] + A[i] * k[N - 1 - i]) % P;
  for(Int i=0;i<N;i++) cnt[B[i]]++;


  Int ans = 0;
  Int ofset = 0;
  for(Int i=0;i<N;i++){
    ans += cnt[ofset];
    cnt[B[i]]--;
    ofset += A[i] * k[N - 1 - i];
    ofset %= P;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4244
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int A[210000];

int main(){
	long long int N, K;
	cin >> N >> K;
	long long int S = 0, S2 = 0;
	map<long long int, long long int> m;
	long long int ans = 0;
	m[S] = 1;
	for(int i = 0; i < N; i++){
		if(i >= K - 1){
			m[S2] -= 1;
			S2 += A[i - K + 1];
			S2 %= K;
		}
		cin >> A[i];
		A[i] -= 1;
		S += A[i];
		S %= K;
		ans += m[S];
		m[S] += 1;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define eps (1e-10)
struct point{
    double x,y;
    point(){}
    point(double x,double y):x(x),y(y){}
    point operator + (point &p){return point(x+p.x,y+p.y);}
    point operator - (point &p){return point(x-p.x,y-p.y);}
    point operator * (double k){return point(x*k,y*k);}
    point operator / (double k){return point(x/k,y/k);}

    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}

    bool operator < (const point &p){
        return x!=p.x?x<p.x:y<p.y;
    }
    bool operator == (const point &p){
        return fabs(x-p.x)<eps&&fabs(y-p.y)<eps;
    }
};
//内积
double dot(point a,point b)
{
    return a.x*b.x+a.y*b.y;
}
//外积
double cross(point a,point b){
    return a.x*b.y-a.y*b.x;
}

point getcrosspoint(point a,point a1,point b,point b1)
{
    point base=b1-b;
    double d1=abs(cross(base,a-b));
    double  d2=abs(cross(base,a1-b));
    double t=d1/(d1+d2);
    point temp=(a1-a)*t;
    return a+temp;
}

int main()
{
    int q;
    cin>>q;
    point a,a1,b,b1;
    for(int i=0;i<q;i++){
        cin>>a.x>>a.y>>a1.x>>a1.y>>b.x>>b.y>>b1.x>>b1.y;
        point res=getcrosspoint(a,a1,b,b1);
        printf("%.10f %.10f\n",res.x,res.y);
    }
    return 0;
}



Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

long long int dist(P a, P b) {
	return abs(a.first-b.first)+abs(a.second-b.second);
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<P> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	vector<P> c(m);
	for (int i = 0; i < m; i++) {
		cin >> c[i].first >> c[i].second;
	}
	for (int i = 0; i < n; i++) {
		long long int aa, bb;
		aa = 1;
		bb = dist(a[i], c[0]);
		for (int j = 0; j < m; j++) {
			long long int cc = dist(a[i], c[j]);
			if (cc < bb) {
				bb = cc;
				aa = j+1;
			}
		}
		cout << aa << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
set<string>st;
int main()
{
    int n,i,j,k,res;
    int fl=-1;
    string ss[200];
    cin>>n;
    cin>>ss[0];
    int l=ss[0].size();
    char p=ss[0][l-1];
    st.insert(ss[0]);
    for(i=1;i<n;i++)
    {
        cin>>ss[i];
        int ll=ss[i].size();
        if(ss[i][0]!=p){fl=0;}
        p=ss[i][ll-1];
        int pp=st.size();
        st.insert(ss[i]);
        int ppp=st.size();
        if(pp==ppp){fl=0;}
    }
    if(fl==-1)
    {
        cout<<"Yes"<<'\n';
    }
    else cout<<"No"<<'\n';
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>v1,v2,v3;
ll  n;
ll INF = 1e12;
ll dp[100000+10][5];
ll dfs(ll i , ll s){
    if(i == n)return 0 ;
    if(dp[i][s] != -1)return dp[i][s];
    ll ans = -INF;
    if(s != 0){
        ans = max(ans,dfs(i+1,0)+v1[i]);
    }
    if(s != 1){
        ans = max(ans,dfs(i+1,1)+v2[i] );
    }
    if(s != 2){
        ans = max(ans,dfs(i+1,2)+v3[i]  );
    }
    dp[i][s] = ans;
    return dp[i][s];
}
int main(){
    cin>>n;
    v1.resize(n+1);
    v2.resize(n+1);
    v3.resize(n+1);
    for(int i=0;i<n;i++){
        cin>>v1[i]>>v2[i]>>v3[i];
    }
    memset(dp,-1,sizeof dp);
    ll ans = dfs(0,4);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12800
#include<stdio.h>
#define N 100

int main(){
  int a,b[N],c,i,j,count,minj;
  count=0;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<a;i++){
    minj=i;
    for(j=i;j<a;j++){
      if(b[j]<b[minj]){
	minj=j;
      }
    }
      if(i!=minj){
	c=b[i];
	b[i]=b[minj];
	b[minj]=c;
	count++;
    }
  }
  for(i=0;i<a;i++){
    printf("%d",b[i]);
    if(i+1==a)break;
    printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}



Measured memory_bytes: 2072
n = int(input())
l = list(map(int,input().split()))

x = 0
s = l[0]+l[1]
for i in l[2:]:
    x ^= i
if x > s or (s-x)%2 or ((s-x)//2)&x:
    print(-1)
    exit()
a = (s-x)//2
if a > l[0]:
    print(-1)
    exit()
for i in range(50,-1,-1):
    if 1<<i & x:
        if a+ (1<<i) <= l[0]:
            a += 1<<i
if a == 0:
    print(-1)
else:
    print(l[0]-a)

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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
const int mod = 1000000007;

vector<ll> divisor(ll n) {
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            res.push_back(i);
            if(i * i != n) {
                res.push_back(n / i);
            }
        }
    }
    sort(begin(res), end(res));
    return res;
}

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

bool isPrime(ll x) {
    ll i;
    if(x < 2)
        return 0;
    else if(x == 2)
        return 1;
    if(x % 2 == 0)
        return 0;
    for(i = 3; i * i <= x; i += 2)
        if(x % i == 0)
            return 0;
    return 1;
}

int main() {
    ll A, B;
    cin >> A >> B;

    ll ab_gcd = gcd(A, B);
    vector<ll> ab_divisor;
    ab_divisor = divisor(ab_gcd);

    ll cnt = 1;
    for(ll i = 0; i < ab_divisor.size(); i++) {
        if(isPrime(ab_divisor[i])) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3668
n = int(input())
t,a = list(map(int,input().split()))
h = list(map(int,input().split()))
ans = 0
k = 10000000
for i in range(n):
    gap = abs(a-(t-h[i]*0.006))
    if k > gap:
        ans = i+1
        k=gap

print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ans=max({a*c, a*d, b*c, b*d});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int S = sc.nextInt();

    sc.close();

    int f = S / 100;
    int r = S % 100;

    if (f <= 12 && r <= 12 && f != 0 && r != 0) {
      System.out.println("AMBIGUOUS");
    } else if (f <= 12 && f != 0) {
      System.out.println("MMYY");
    } else if (r <= 12 && r != 0) {
      System.out.println("YYMM");
    } else {
      System.out.println("NA");
    }
  }

}


Measured memory_bytes: 23764
# potential union findの問題と聞いて
class PotentialUnionFind:
    # あり本実装
    # rankとrootの配列を1つで賄う方法
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n
        self.weight = [0] * n

    # 根を求める
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            px = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = px
            return px

    # 頂点からのpotential
    def weight(self, x):
        self.find(x)
        return self.weight[x]

    # 同じかどうかの判定
    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    # 集合の大きさ
    def size(self, x):
        return -self.find(x)

    # 　2つの集合の合体
    # 重みが大きい方に小さい方をつけるようにする
    def unite(self, x, y, w):
        w += self.weight[x] - self.weight[y]
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False

        if self.par[x] > self.par[y]:
            x, y = y, x
            w = -w
        self.par[x] += self.par[y]
        self.par[y] = x
        self.weight[y] = w
        return True

    def diff(self, x, y):
        return self.weight[y] - self.weight[x]


n, m = map(int, input().split())
PUF = PotentialUnionFind(n)
flag = 0
for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    if PUF.is_same(l, r):
        if abs(PUF.diff(l, r)) == d:
            continue
        else:
            flag = 1
    else:
        PUF.unite(l, r, d)

print("No" if flag else "Yes")


Measured memory_bytes: 8940
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;

int main()
{
	int N, C, ans = 1000*500*500, res, tmp;

	cin >> N >> C;

	vector<vector<int>> D = vector<vector<int>>(C, vector<int>(C, 0));
	vector<vector<int>> c = vector<vector<int>>(N, vector<int>(N, 0));

	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> tmp;
			c[i][j] = tmp - 1;
		}
	}

	vector<vector<int>> sum = vector<vector<int>>(2*N-1, vector<int>(C, 0));
	for (int i = 0; i < 2 * N - 1; i++) {
		for(int color = 0; color < C; color++){
			for (int j = 0; j <= i; j++) {
				if (j < N && i - j < N) sum[i][color] += D[c[j][i - j]][color];
			}
		}
	}

	for (int x = 0; x < C; x++) {
		for (int y = 0; y < C; y++) {
		if (x == y) continue;
			for (int z = 0; z < C; z++) {
				if (x == z || y == z) continue;
				res = 0;
				for (int i = 0; i < (2 * N - 1); i++) {
					if (i % 3 == 0) {
						res += sum[i][x];
					}
					else if (i % 3 == 1) {
						res += sum[i][y];
					}
					else {
						res += sum[i][z];
					}
				}
				if (ans > res)ans = res;
			}
		}
	}

	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

int main() {

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

  int n;
  cin >> n;
  vector<int> vec;
  bool visited[n];
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    vec.push_back(temp - 1);
    visited[i] = false;
  }

  int count = 0;
  int ptr = 0;
  for (int i = 0; i < n; i++) {
    if (vec.at(ptr) == 1) {
      count++;
      break;
    } else {
      if (visited[ptr] == true) {
        count = -1;
        break;
      } else {
        visited[ptr] = true;
        count++;
      }
      ptr = vec.at(ptr);
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 1652
import numpy as np
a,b=input().split()
# print(a)
# print(b)
a_int =int(a)
b_int = int(b)
# print(a)
# print(b)
c = ""
if(a<b):
    for i in range(b_int):
        c += str(a)
    print(c)

else:
    for i in range(a_int):
        c += str(b)
    print(c)

Measured memory_bytes: 12468
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ n, k ] = readMany(2).map(it => parseInt(it))
    let answer = k
    for (let i = 1; i < n; i += 1) {
        answer *= k - 1
    }
    console.log(answer)
})()


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll,ll> vll;
typedef pair<ll,ll> pll;

//DP[n][w] = max value can have with first n items, and weight w 

const int MAX_W = 100010;
ll DP[101][MAX_W];

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n, W;
	cin >> n >> W;
	vi w(n), val(n);
	M00(i, n) {
		cin >> w[i] >> val[i];
	}
	ll inf = -1e15;
	MOO(i,1,W+1) {
		DP[0][i] = inf;
	}
	DP[0][0] = 0;
	MOO(i, 1, n+1) {
		M00(j, W + 1) {
			DP[i][j] = DP[i-1][j];
			if(j >= w[i-1])
				DP[i][j] = max(DP[i][j], DP[i-1][j-w[i-1]] + val[i-1]);
		}
	}
	ll best = 0;
	M00(i, W+1) {
		best = max(best, DP[n][i]);
	}
	finish(best);
}


Measured memory_bytes: 79232
#include<math.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b && b<c)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 2120
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextLong();
		}
		
		long[]s = new long[n+1];
		for(int i = 0; i < n; i++) {
			s[i+1] = s[i] + a[i];
		}
		Map<Long,Long> map = new HashMap<>();
		
		for(int i = 0; i < n+1; i++) {
			if(!map.containsKey(s[i])) {
				map.put(s[i], 0L);
			}
			map.put(s[i], map.get(s[i])+1);
		}
		long cnt = 0;
		
		/*for(int i = 0; i < map.size(); i++) {
			if(map.get(s[i]) < 2) {
				continue;
			}else {
				cnt += map.get(s[i])*(map.get(s[i])-1)/2;
			}
		}*/
		
		for(long ss: map.keySet()) {
			if(map.get(ss) < 1) {
				continue;
			}else {
				cnt += map.get(ss)*(map.get(ss)-1)/2;
			}
		}
		
		System.out.println(cnt);
		
	}

}


Measured memory_bytes: 101900
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long r, s, p;
string t;

char rsp (char x) {
    if(x == 'r') {
        return 'p';
    }else if(x == 's') {
        return 'r';
    }else {
        return 's';
    }
}

long long rspP (char x) {
    if(x == 'r') {
        return r;
    }else if(x == 's') {
        return s;
    }else {
        return p;
    }
}

int main() {
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    vector<char> pre(k, '!');
    long long ans = 0;
    for(int i = 0; i < n; ++i) {
        char now = rsp(t.at(i));
        long long point = rspP(now);
        if(pre.at(i%k) == now) {
            pre.at(i%k) = '!';
        }else {
            ans += point;
            pre.at(i%k) = now;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{
	static int[] sum=new int[10000];
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		while(true) {
			int N=sc.nextInt();
			int K=sc.nextInt();
			if(N*K==0) {
				System.exit(0);
			}
			int[] cards=new int[N];
			for(int i=0; i<N; i++) {
				cards[i]=sc.nextInt();
			}
			int INF=1000000007;
			Arrays.fill(sum, INF);
			int counter=0;
			if(K==2) {
				for(int i=0; i<N; i++) {
					for(int j=0; j<N; j++) {
						if(i!=j) {
							int a=Integer.parseInt(cards[i]+""+cards[j]);
							boolean find=findnum(a);
							if(find) {
								sum[counter]=a;
								counter++;
							}
						}
					}
				}
			}
			else if(K==3) {
				for(int i=0; i<N; i++) {
					for(int j=0; j<N; j++) {
						for(int k=0; k<N; k++) {
							if(i!=j && j!=k && k!=i) {
								int a=Integer.parseInt(cards[i]+""+cards[j]+""+cards[k]);
								boolean find=findnum(a);
								if(find) {
									sum[counter]=a;
									counter++;
								}
							}
						}
					}
				}
			}
			else if(K==4) {
				for(int i=0; i<N; i++) {
					for(int j=0; j<N; j++) {
						for(int k=0; k<N; k++) {
							for(int l=0; l<N; l++) {
								if(i!=j && j!=k && k!=l && i!=k && i!=l && j!=l) {
									int a=Integer.parseInt(cards[i]+""+cards[j]+""+cards[k]+""+cards[l]);
									boolean find=findnum(a);
									if(find) {
										sum[counter]=a;
										counter++;
									}
								}
							}
						}
					}
				}
			}
			pl(counter);
		}
	}
	public static boolean findnum(int a){
		for(int i=0; i<10000; i++) {
			if(sum[i]==a) {
				return false;
			}
		}
		return true;
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 28376
h,w=map(int,input().split())
grid=[]
for _ in range(h):
    grid.append(list(input()))

row=[]
col=[]
#行探索
for i in range(h):
    flg=0
    for j in range(w):
        if grid[i][j]=='#':
            flg=1

    if flg==0:
        row.append(i)

#列探索
for j in range(w):
    flg=0
    for i in range(h):
        if grid[i][j]=='#':
            flg=1

    if flg==0:
        col.append(j)

ans=[]
for i in range(h):
    arr=[]
    for j in range(w):
        if i in row or j in col:
            continue
        else:
            arr.append(grid[i][j])
    if len(arr)!=0:
        ans.append(arr)

for k in ans:
    t=''.join(k)
    print(t)


Measured memory_bytes: 9208
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();
        int sum = P + Q + R;
        List<Integer> li = new ArrayList<Integer>();
        li.add(sum-P);
        li.add(sum-Q);
        li.add(sum-R);
        Collections.sort(li);
        System.out.println(li.get(0));
    }
}

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

template<class T>
std::vector<T> read_vector(const uint64_t n) {
    auto v = std::vector<T>();
    v.reserve(n);

    for(uint64_t i = 0; i < n; ++i) {
        T t;
        std::cin >> t;
        v.push_back(t);
    }

    return v;
}

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

    const auto as = read_vector<int>(n);

    auto boxes = std::vector<int>(n, 0);

    auto answer = std::vector<int>();

    for(int i = n; i >= 1; --i) {
        int ball_count = 0;
        for(int j = 2; i * j <= n; ++j) {
            ball_count += boxes[i * j - 1];
        }

        if(as[i - 1] != ball_count % 2) {
            boxes[i - 1] = 1;
            answer.push_back(i);
        }
    }

    std::cout << answer.size() << std::endl;
    for(const auto b: answer) {
        std::cout << b << " ";
    }
    if(!answer.empty()) {
        std::cout << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3064
/**
  @date Time-stamp: <2019-06-25 19:56:11 tagashira>
  @file b.cpp
  @title B - K-th Common Divisor
  @brief https://atcoder.jp/contests/abc120/tasks/abc120_b
**/

#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;

  return gcd(b, a % b);
}

int lcm(int a, int b) {
  return a * b / gcd(a, b);
}

template <class T>
void show(vector<T>& v) {
  for (uint i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  if (K == 1) {
    cout << gcd(A, B) << endl;
  } else {
    vector<int> div;
    div.push_back(gcd(A, B));

    for (int i = div[0]-1; i > 0; i--) {
      if ((A % i == 0) && (B % i == 0)) {
        div.push_back(i);
      }
    }

    // show(div);
    cout << div[K - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	char in[5];
	while(~scanf("%s",in)){
		if(in[0]=='A') puts("T");
		if(in[0]=='T') puts("A");
		if(in[0]=='G') puts("C");
		if(in[0]=='C') puts("G");
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=10000000;
const ll INF=1000000001;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int main(){
    ll x,y;cin>>x>>y;
    ll ans=1;
    for(int i=0;i<100;i++){
        x*=2;
        if(x>y)break;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
H,W = map(int, input().split(" "))

HW = [[]]*H
h=0
for _ in range(H):
    Low = input()
    if Low!="."*W:
        HW[h] = list(Low)
        h+=1
        
HW_T = list(zip(*HW[:h]))

hw_t = [[]]*W
w=0

for s in HW_T:
    col= str(''.join(s))
    if col!="."*h:
        hw_t[w] = list(col)
        w+=1

HW = list(zip(*hw_t[:w]))

for l in HW:
    s = str(''.join(l))
    print(s)

Measured memory_bytes: 3316
N, A, B = [int(n) for n in input().split(" ")]

cnt = 0

for n in range(1,N+1):
  temp = 0
  i =n
  while n>0:
    temp += int(n)%10
    n /= 10
  if temp >= A and temp <= B:
    cnt += i

print(cnt)


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N,K;cin >> N >> K;
    deque<int> V;
    rep(i,N){
        int a;
        cin >> a;
        V.push_back(a);
    }

    int res = 0;

    for(int i=0;i<=K;i++){//i回とりだす
        for(int j=0;j<=i;j++){//j個左からi-j個右から
            deque<int> VV = V;
            priority_queue<int,vector<int>,greater<int> > que;
            rep(k,j){
                if(VV.empty())continue;
                que.push(VV.front());
                VV.pop_front();
            }
            rep(k,i-j){
                if(VV.empty())continue;
                que.push(VV.back());
                VV.pop_back();
            }
            rep(k,K-i){
                if(!que.empty())if(que.top()<0)que.pop();
            }
            int tmp=0;
            while(!que.empty()){
                tmp+=que.top();
                que.pop();
            }
            res = max(tmp,res);
        }
    }    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll k,a,b;
ll solve(ll k,ll a,ll b);
main(){
    cin>>k>>a>>b;
   cout<<solve(k,a,b)<<endl;
}
ll solve(ll k,ll a,ll b){
    if(b-a<=2)return k+1;
    if(k<a)return k+1;
    return ((k-(a-1))/2)*(b-a)+1+(k-((k-(a-1))/2)*2);
}

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

int N;
string F[10];
int W[10], S[10];

bool isValid(int id[]) {
  int sumW = 0;
  for(int i = N-1; i >= 0; --i) {
    if(S[id[i]] < sumW) return false;
    sumW += W[id[i]];
  }
  return true;
}

double getG(int id[]) {
  int a, b;
  a = b = 0;
  for(int i = 0; i < N; ++i) {
    a += W[id[i]]*(i+1);
    b += W[id[i]];
  }
  return (double)a/b;
}

void solve() {
  int id[N], ans[N];
  double g = -1;
  for(int i = 0; i < N; ++i) id[i] = i;
  do {
    if(isValid(id)) {
      double newG = getG(id);
      if(g == -1 || newG < g) {
	g = newG;
	for(int i = 0; i < N; ++i) ans[i] = id[i];
      }
    }
  } while(next_permutation(id, id+N));
  for(int i = 0; i < N; ++i) cout << F[ans[i]] << endl;
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i)
      cin >> F[i] >> W[i] >> S[i];
    solve();
  }
  return 0;
}

Measured memory_bytes: 908
#include <iostream>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0)break;
		int P[1001]={0},D[1001]={0},cx=0,count;
		for(int i=0;i<n;++i) cin>>P[i];
		for(int i=0;i<m;++i) cin>>D[i];
		for(count=0;count<m;++count){
			if(cx>=n-1) break;
			cx+=D[count];
			cx+=P[cx];
		}
		cout<<count<<"\n";
	}
	return 0;
}

Measured memory_bytes: 0
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return

    P = list(map(int, input().split()))
    check = 0
    while True:
        if not X-check in P:
            print(X-check)
            return
        if not X+check in P:
            print(X+check)
            return
        check += 1    

main()

Measured memory_bytes: 9184
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
int mod = 1e9+7;

int main(){
	map<int, int> b2;
	int N;
	cin >> N;

	ll tmp, bit;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		bit = 1;
		for (int b = 0; b <= 60; b++) {
			if (tmp & bit) b2[b]++;
			bit <<= 1;
		}
	}

	ll ans = 0;
	bit = 1;
	for (int b = 0; b <= 60; b++) {
		ans = (((((bit * b2[b]) % mod) * (N - b2[b])) % mod) + ans) % mod;
		bit = (bit * 2) % mod;
	}

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


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

ll N;
ll A[10];
ll cnt = 0;

int main() {
    cin >> N;
    ll cnt = 1;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] % 2 == 0) {
            cnt*=2;
        }
    }
    ll ans = (ll)pow(3.0,(long double)N);
    cout << ans-cnt << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846264
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    if (n%10==3){
        cout<<"bon";
    }
    else if (n%10==0 || n%10 == 1 || n%10 ==6 ||n%10==8){
        cout<<"pon";
    }
    else cout<<"hon";
}

Measured memory_bytes: 3648