akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;
const ll INF = 1LL << 60;

mint dp[10005][2][100]; //[桁数][未満フラグ][余り]

int main(){
  string s;
  int n;
  cin >> s >> n;
  int digit = s.size();
  dp[0][0][0] = 1;
  rep(i,digit){
    int D = s[i] - '0'; 
    rep(j,2){
      for(int d = 0; d <= (j ? 9 : D);d++){ //jが1なら何でも入れられる、0ならDまで入れられる
        rep(k,n){
          dp[i+1][j || (d < D)][(k+d)%n] += dp[i][j][k];
        }
      }
    }
  }
  
  cout << dp[digit][0][0]+dp[digit][1][0]-1 << endl;
  
  return 0;
}

Measured memory_bytes: 15872
import qualified Data.Set as Set

main = do
    s <- read <$> getLine
    print $ solve s (Set.fromList [])

nextCollatz :: Int -> Int
nextCollatz n
    | even n = n `div` 2
    | otherwise = 3 * n + 1

solve :: Int -> Set.Set Int -> Int
solve n set
    | n `Set.member` set = 1
    | otherwise = 1 + solve (nextCollatz n) (Set.insert n set)

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

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

const int MAXN = 1e5;

int par[MAXN];
int rnk[MAXN];
void init(int n) { for(int i = 0; i < n; ++i) { par[i] = i; rnk[i] = 0; }}
int find(int x) { if(par[x] == x) return x; else return par[x] = find(par[x]); }
bool same(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) { x = find(x); y = find(y); if(x == y) return;
    if(rnk[x] < rnk[y]) par[x] = y; else { par[y] = x; if(rnk[x] == rnk[y]) ++rnk[x]; }}


int N, M;
vector<int> p, x, y;
// 数列Pが与えられる。
// x_i, y_iをswapできる。
// 移動可能なindexでグループを作る。
// 5-1, 4-2, 3
// これらのindexがいくつ含まれるかがスコア
// 1-3, 5-4, 2
// => 2


void input_int_array(int n,vector<int> &vec) {
	for (int i=0,tmp=0; i<n && cin >> tmp; i++) vec[i]=tmp;
}

void input() {
	cin >> N >> M;
	cin.ignore();
	p = vector<int>(N+1);
	x = vector<int>(M+1);
	y = vector<int>(M+1);
	// 3という数字が2番目にあるならば、2番目と3番目が交換可能出あってほしい。
	rep(i, N) {
		int index;
		cin >> index;
		p[index] = i+1;
	}
	cin.ignore();
	rep(i, M) {
		cin >> x[i] >> y[i];
		cin.ignore();
	}
}

int solve() {
	int score = 0;
	//これを忘れると、永遠に解けない.
	init(N);
	rep(i, M) unite(x[i], y[i]);
	rep(i, N) {
		int index = i+1;
		//piが、i番目と交換できれば良い。
		if(same(index, p[index])) {
			score += 1;
		}
	}
	return score;
}

int main() {
	input();
	cout << solve() << endl;
}

Measured memory_bytes: 2176
n,k = map(int, input().split())
a = list(map(int, input().split()))

h = set([])

c = 0
for i in range(2 * n):
  c = a[c] - 1
  if n < i:
    if c + 1 in h:
      break
    else:
      h.add(c + 1)

c = 0
d = 0
for i in range(n):
  c = a[c] - 1
  if c + 1 in h:
    break
  else:
    d += 1

c = 0
if d >= k:
  for i in range(k):
    c = a[c] - 1
else:
  for i in range(d + ((k - d) % len(h) + len(h))):
    c = a[c] - 1


print(c + 1)


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

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

  int ans = 0;
  if (N.at(0) != 'C') ans++;
  if (N.at(1) != 'O') ans++;
  if (N.at(2) != 'D') ans++;
  if (N.at(3) != 'E') ans++;
  if (N.at(4) != 'F') ans++;
  if (N.at(5) != 'E') ans++;
  if (N.at(6) != 'S') ans++;
  if (N.at(7) != 'T') ans++;
  if (N.at(8) != 'I') ans++;
  if (N.at(9) != 'V') ans++;
  if (N.at(10) != 'A') ans++;
  if (N.at(11) != 'L') ans++;
  if (N.at(12) != '2') ans++;
  if (N.at(13) != '0') ans++;
  if (N.at(14) != '1') ans++;
  if (N.at(15) != '6') ans++;

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str = sc.next();

        	if((str.charAt(2) == str.charAt(3)) && (str.charAt(4) == str.charAt(5))){
        		System.out.println("Yes");
        	}else{
            	System.out.println("No");
            }

	}
}

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

int bubbleSort(int A[], int N) {
    bool flag = 1;
    int count = 0;
    while(flag) {
        flag = 0;
        for(int i = N - 1; i > 0; i--) {
            if(A[i] < A[i - 1]) {
                swap(A[i], A[i - 1]);
                count++;
                flag = 1;
            }
        }
    }
    return count;
}

int main() {
    int A[100], N, count;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];

    count = bubbleSort(A, N);

    for(int i = 0; i < N; i++) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3088
import sys
DBG = not True
DBG2 = not True
n,a,b =      map(int, input().split())
MAXM =  18
r = [0] * MAXM
s = [0] * MAXM
r[0] = [0]
r[1] = [0,1]
s[1] = [0,1]
p1a = [0,1,3,2]
p2a = [3,1,0,2,2,0,1,3]

def swiz(n,z,d):
    xpos = n - len(d)
    ypos = 0
    t = 0
    for i in range(n):
        if DBG2:
            print("sw lp i {} xp {} yp {} t {}".\
               format(i,xpos,ypos,t))
        if i in d:
            t += ((z >> xpos) & 1) << i
            xpos += 1
        else:
            t += ((z >> ypos) & 1) << i
            ypos += 1
    if  DBG2:
        print("sw z {} d {} ret {}".format(z,d,t))
    return t

for m in range(3,MAXM,2):
    s[m] = [0] * (2**m)
    for i in range(2**(m-2)):
        hi = s[m-2][i] << 2
        for j in range(4):
          s[m][4*i+j] = hi + \
            (p1a[j] if i == 0 else p2a[4*(i%2)+j])
          if DBG2:
              print("set s m {} i {} j {} - {}".\
                 format(m,i,j,s[m][4*i+j]))

for m in range(2,MAXM):
    r[m] = [0] * (2**m)
    for i in range(2**(m-1)):
        r[m][i  ] = r[m-1][i]
        r[m][2**m-1-i] = 2**(m-1) + r[m-1][i]

if DBG:
    for m in range(1,6):
        print(s[m])
    print("")
    for m in range(1,6):
        print(r[m])

z = a ^ b
cnt = 0
d = []
for i in range(MAXM):
    if z & (1<<i) != 0:
        cnt += 1
        d.append(i)
if cnt%2 == 0:
    print('NO')
    sys.exit(0)
else:
    print('YES')

sz = len(d)
if DBG:
    print("n {} a {} b {} sz {} d:".format(n,a,b,sz))
    print(d)

for i in range(2**sz):
    for j in range(2**(n-sz)):
        hi = (s[sz][i] << (n-sz))
        lo =  r[n-sz][j] if i%2 == 0 \
                         else r[n-sz][2**(n-sz)-1-j]
        z =  hi + lo
        sw = swiz(n,z,d)
        if DBG:
          print("i {} j {} hi {} lo {} z {} sw {}".\
               format(i,j,hi,lo,z,sw))
        sys.stdout.write(str(a^sw) + ' ')
print('')


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

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    string S, T;
    cin >> S >> T;

    // L U
    int ssr = sr, ssc = sc;
    for(int i=0;i<N;i++){
        if(S[i] == 'L') ssc--;
        if(S[i] == 'U') ssr--;
        if(ssc < 1 || ssr < 1) goto takahashi;
        if(T[i] == 'R' && ssc+1 <= W) ssc++;
        if(T[i] == 'D' && ssr+1 <= H) ssr++;
    }
    // R D
    ssr = sr; ssc = sc;
    for(int i=0;i<N;i++){
        if(S[i] == 'R') ssc++;
        if(S[i] == 'D') ssr++;
        if(ssc > W || ssr > H) goto takahashi;
        if(T[i] == 'L' && ssc-1 > 0) ssc--;
        if(T[i] == 'U' && ssr-1 > 0) ssr--;
    }
    
    cout << "YES" << endl;
    return 0;

    takahashi:
    cout << "NO" << endl;
    return 0;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;

    // a^n mod MOD
    const auto& modpow = [](unsigned long a, unsigned long n) -> unsigned long {
        unsigned long r{1};
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };

    unsigned long N, K;
    cin >> N >> K;

    // calc f_N
    vector<unsigned long> memo_f(K + 1);
    const auto& f = [f_impl = [&N, &memo_f, &modpow](auto func, unsigned long k) -> unsigned long {
        if(memo_f[k])return memo_f[k];
        // f_N(k) = k^N -
        unsigned long r{modpow(k, N)};
        //          \sum f_N(k/i)
        for(unsigned long i{2}; i <= k; ++i)r += MOD - func(func, k / i);
        return memo_f[k] = r % MOD;
    }](unsigned long k){return f_impl(f_impl, k);};

    unsigned long ans{0};
    for(unsigned long i{1}; i <= K; ++i)ans += f(K / i) * i % MOD;
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 4048
// C++ program to find the longest 
// path in the DAG 

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

// Function to traverse the DAG 
// and apply Dynamic Programming 
// to find the longest path 
void dfs(int node, vector<int> adj[], int dp[], bool vis[])
{
    // Mark as visited
    vis[node] = true;

    // Traverse for all its children
    for (int i = 0; i < adj[node].size(); i++) {

        // If not visited
        if (!vis[adj[node][i]])
            dfs(adj[node][i], adj, dp, vis);

        // Store the max of the paths
        dp[node] = max(dp[node], 1 + dp[adj[node][i]]);
    }
}

// Function to add an edge 
void addEdge(vector<int> adj[], int u, int v)
{
    adj[u].push_back(v);
}

// Function that returns the longest path 
int findLongestPath(vector<int> adj[], int n)
{
    // Dp array
    int dp[n + 1];
    memset(dp, 0, sizeof dp);

    // Visited array to know if the node
    // has been visited previously or not
    bool vis[n + 1];
    memset(vis, false, sizeof vis);

    // Call DFS for every unvisited vertex
    for (int i = 1; i <= n; i++) {
        if (!vis[i])
            dfs(i, adj, dp, vis);
    }

    int ans = 0;

    // Traverse and find the maximum of all dp[i]
    for (int i = 1; i <= n; i++) {
        ans = max(ans, dp[i]);
    }
    return ans;
}

// Driver Code 
int main()
{
    int n,m,a,b;
    cin>>n>>m;
    vector<int> adj[n + 1];

    for (int i = 0; i < m; ++i) {
        cin>>a>>b;
        addEdge(adj,a,b);
    }
    cout << findLongestPath(adj, n);
    return 0;
} 


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

void show(vector<ll>& vc)
{
    for(auto it:vc)cout<<it<<" ";
    cout<<endl;
}
#define M 10
bool p[M+2];
vector<ll>prime;
void seive(void)
{
    memset(p,0,sizeof p);
    p[1]=1;
    p[0]=1;

    for(int i=4; i<=M; i+=2)
    {
        p[i]=1;

    }

    for(ll i=3; i*i<=M; i+=2)
    {

        if(!p[i])
        {

            for(ll j=i*i; j<=M; j+=2*i)
            {
                p[j]=1;

            }
        }
    }

    prime.push_back(2);
    for(int i=3; i<=M; i+=2)prime.push_back(i);
}
ll dx[] = {-1,-1,0,-1,1,0,1,1};
ll dy[] = {-1,0,-1,1,-1,1,0,1};

typedef pair<ll, ll> pii;
#define x first
#define y second


pii extendedEuclid(ll a, ll b)   // returns x, y | ax + by = gcd(a,b)
{
    if(b == 0) return pii(1, 0);
    else
    {
        pii d = extendedEuclid(b, a % b);
        return pii(d.y, d.x - d.y * (a / b));
    }
}

ll modularInverse(ll a, ll n)
{
    pii ret = extendedEuclid(a, n);
    return ((ret.x % n) + n) % n;
}



ll n,W;
vector<ll>v,w;
ll dp[105][100005];

void solve(ll t)
{

    cin>>n>>W;
    for(int i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        w.push_back(a);
        v.push_back(b);
    }
    for(int i=0;i<=W;i++)dp[0][i]=0;
    for(int i=0;i<=n;i++)dp[i][0]=0;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=W;j++)
        {
            if(j-w[i-1]>=0)
            dp[i][j] = max(dp[i-1][j] , v[i-1] + dp[i-1][j-w[i-1]]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][W]<<endl;




}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //seive();


    ll t=1;
    //cin>>t;
    ll T=t;



    while(t--)
    {


        solve(T-t);

    }
}


Measured memory_bytes: 80128
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n f >>= putStrLn
    main
  where
    f = map read <$> words <$> getLine

solve :: [[Int]] -> String
solve xs = let ys = map sum xs
           in unwords . map show $ [maximum ys,  minimum ys]



Measured memory_bytes: 5484
M,D = map(int,input().split())
from itertools import product

ans = 0

for d,m in product(range(22,D+1),range(1,M+1)):
    d1 = int(str(d)[1])
    d10 = int(str(d)[0])
    if d1*d10 == m and min(d1,d10) >= 2:
        ans+=1
print(ans)


Measured memory_bytes: 40048
import itertools
import sys


N, M = map(int, sys.stdin.readline().split())
x, y, z = [], [], []
for _ in range(N):
    t0, t1, t2 = map(int, sys.stdin.readline().split())
    x.append(t0)
    y.append(t1)
    z.append(t2)

ret = {}
for s in itertools.product(*tuple([[1, -1]] * 3)):
    s0, s1, s2 = s
    scores = ret[s] = []
    for i in range(N):
        scores.append(x[i] * s[0] + y[i] * s[1] + z[i] * s[2])
    scores.sort(reverse=True)


max_sum = 0
for v in ret.values():
    max_sum = max(max_sum, sum(v[0:M]))

print(max_sum)

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

const int N = 100+5, M = 2*N*N;
const double INF_D = 1e100;
double EPS = 1e-6;

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

	int m, d, cnt = 0;
	cin >> m >> d;
	for(int i=1; i<=m; i++)
		for(int j=2; j<=9; j++)
			for(int k=2; k<=9; k++){
				int p = j*10 + k;
				if(p > d) continue; 
				if(j*k == i) cnt++;
			}
	cout << cnt;

	return 0;
}


Measured memory_bytes: 256
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    ll n,q;
    scanf("%lld",&n);
    vector<ll> s(n);
    rep(i,n) scanf("%lld",&s[i]);
    scanf("%lld",&q);
    vector<ll> t(q);
    rep(i,q) scanf("%lld",&t[i]);    
    ll ans =0;
    rep(i,q){
        if(binary_search(s.begin(),s.end(),t[i])) ans++; 
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 3884
from math import log2
n,k=map(int,input().split())
ar=list(map(int,input().split()))
for i in range(n):
    ar[i]=log2(ar[i])
prod=0
for i in range(k):
    prod+=ar[i]
for i in range(k,n):
    x=prod+ar[i]-ar[i-k]
    if x>prod:
        print('Yes')
    else:
        print('No')
    prod=x


Measured memory_bytes: 94092
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for _ in range(N)]
count = [0]*N
zipped = {x:i for i, x in enumerate(set(A))}
A = [zipped[x] for x in A]

for x in A:
    count[x] += 1

print(sum(x%2==1 for x in count))


Measured memory_bytes: 48128
n = io.read("*n")
a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
table.sort(a)
c = 0
for i = n, 1, -1 do
  if i % 2 == n % 2 then
    c = c + a[i]
  else
    c = c - a[i]
  end
end
print(c)


Measured memory_bytes: 2708
#include<bits/stdc++.h>
#define cometh_the_hour_cometh_the_man ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x); cout<<#x<<"="<<x<<endl;
#define debug2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long
using namespace std;



int32_t main()
{
        cometh_the_hour_cometh_the_man
        int n;
        string s;
        cin>>n>>s;
      
        std::vector<int> g(n+1);
        std::vector<int> r(n+1);
        std::vector<int> b(n+1);
        set<int>rr;
        set<int>gg;
        set<int>bb;
        for(int i=0;i<n;i++){
                g[i+1]=g[i]+(s[i]=='G');
                b[i+1]=b[i]+(s[i]=='B');
                r[i+1]=r[i]+(s[i]=='R');
                if(s[i]=='G')gg.insert(i+1);
                if(s[i]=='R')rr.insert(i+1);
                if(s[i]=='B')bb.insert(i+1);
        }
        s=" "+s;
        int ans=0;
        for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                        //debug2(i,j);
                        //debug(ans);
                        int diff=j-i;
                        if(s[i]=='R' && s[j]=='B'){
                            ans+=g[n]-g[j];
                            if(gg.find(j+diff)!=gg.end())ans--;
                        }
                        else if(s[i]=='B' && s[j]=='R'){
                            ans+=g[n]-g[j];
                            if(gg.find(j+diff)!=gg.end())ans--;
                        }
                        else if(s[i]=='R' && s[j]=='G'){
                               ans+=b[n]-b[j];
                                if(bb.find(j+diff)!=bb.end())ans--;
                        }
                        else if(s[i]=='G' && s[j]=='R'){
                               ans+=b[n]-b[j];
                                if(bb.find(j+diff)!=bb.end())ans--;                        }
                        else if(s[i]=='B' && s[j]=='G'){
                                ans+=r[n]-r[j];
                                if(rr.find(j+diff)!=rr.end())ans--;
                        }
                        else if(s[i]=='G' && s[j]=='B'){
                                ans+=r[n]-r[j];
                                if(rr.find(j+diff)!=rr.end())ans--;
                        }
                        //debug(ans);
                }
        }
        cout<<ans;


     return 0;

}

    

Measured memory_bytes: 3896
def nexthouse(house, cur, delivered):
    dmin = 10**5
    nxt = 0

    for i in range(len(house)):
        if delivered[i] != True:
            if abs( house[cur] - house[i] ) < dmin :
                dmin = abs( house[cur] - house[i] )
                nxt = i
    delivered[nxt] = True
    return nxt

def main():
    N = int(input())
    house = [int(a) for a in input().split()]
    dlist = [None]*N
    
    for i in range(N):
        dm = 10**5
        dtotal = 0
        cur = i
        deliv = [0]*N
        deliv[cur] = True
        
        while deliv.count(0) > 0:
            nxt = nexthouse(house, cur, deliv)
            dtotal += abs(house[nxt] - house[cur])
            cur = nxt

        dlist[i] = dtotal

    print(min(dlist))
main()

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int a, b, n;

  while(cin >> a >> b >> n) {
    int ans = 0;

    while(n--) {
      a *= 10;
      ans += a / b % 10;
      a %= b;

    }

    cout << ans << endl;
  }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  int p[100000], y[100000];
  vector<ll> yd[100001];
  rep(i,m) {
    int pi, yi;
    cin >> pi >> yi;
    p[i] = pi;
    y[i] = yi;
    yd[pi].push_back(yi);
  }
  //rep (i,m) scanf ("%d%d",&p[i],&y[i]), yd[p[i]].push_back(y[i]);
  rep (i,n) sor(yd[i+1]);
  rep (i,m) {
    int index = int (lb(yd[p[i]], y[i]) - yd[p[i]].begin()) + 1;
    printf ("%012lld\n" , ll (p[i])*1000000+index);
  }
    //printf ("%012lld\n", ll(p[i])*1000000+ int(lb(yd[p[i]], y[i]) - yd[p[i]].begin())+1);
  return 0;
}


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

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
int w[100];
int s[100];
int main(void){
    int n;
    scanf("%d", &n);
    int sum = 0;
    for(int i = 0;i < n;i++){
        scanf("%d", &w[i]);
        sum += w[i];
        s[i] = sum;
    }
    int ans = mod;
    for(int i = 0;i < n;i++){
        ans = mi(ans, abs(sum - s[i]*2));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#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++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
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,M;
    string S;
    cin >> N >> M;
    cin >> S;
    vector<ll> vs(N+1),dp(N+1);
    rep(i,N+1){
        if(S[i]=='0'){
            vs[i] = 0;
        }else{
            vs[i] = 1;
        }
    }
    ll cur = N;
    vector<ll> ans;
    while(1){
        bool flag = true;    
        for(ll i = M; i>0;i--){
            if(cur-i <= 0){
                ans.push_back(cur);
                goto  gt;
            }
            if(vs[cur-i] == 0){
                ans.push_back(i);
                cur -= i;
                flag = false;
                break;
            }
        }
        if(flag){
            cout << -1 << endl;
            return 0;
        }
    }
    gt:
    reverse(ans.begin(), ans.end());
    PR(ans, ans.size());
}

Measured memory_bytes: 6676
/*	ex7_3
	suzuto	*/

  #include <stdio.h>
  #include <stdlib.h>

  int main(void){
    char **grid_ptr, ins; /*変数の宣言*/
    int *height_ptr, *width_ptr, height, width, i, j;

    scanf("%d %d", &height, &width); /*縦横の長さを入力*/
    height_ptr = (int*)calloc(height, sizeof(int)); /*圧縮後に残る行を記憶*/
    if(height_ptr == NULL){ /*エラー出力*/
      fprintf(stderr, "Memory allocation error.\n");
      return 1;
    }
    for(i = 0; i < height; i++){
      height_ptr[i] = 0; /*height_ptrを初期化*/
    }
    width_ptr = (int*)calloc(width, sizeof(int)); /*圧縮後に残る列を記憶*/
    if(width_ptr == NULL){ /*エラー出力*/
      fprintf(stderr, "Memory allocation error.\n");
      return 1;
    }
    for(i = 0; i < width; i++){
      width_ptr[i] = 0; /*width_ptrを初期化*/
    }
    grid_ptr = (char**)calloc(height, sizeof(char*)); /*char*型配列を確保*/
    if(grid_ptr == NULL){ /*エラー出力*/
      fprintf(stderr, "Memory allocation error.\n");
      return 1;
    }
    for(i = 0; i < height; i++){
      grid_ptr[i] = (char*)calloc(width, sizeof(char)); /*char型配列を確保し入力を記憶する二次元配列が完成*/
      if(grid_ptr[i] == NULL){ /*エラー出力*/
        fprintf(stderr, "Memory allocation error.\n");
        return 1;
      }
    }
    for(i = 0; i < height; i++){
      for(j = 0; j < width; j++){
        scanf(" %c", &ins); /*入力insに一時的に記憶*/
        grid_ptr[i][j] = ins; /*入力を記憶用の配列に反映*/
        if(ins == '#'){ /*黒のある行、および列は圧縮により消えない*/
          height_ptr[i] = 1;
          width_ptr[j] = 1;
        }
      }
    }
    for(i = 0; i < height; i++){
      if(height_ptr[i] == 1){ /*height_ptrが初期値でないときその行は残る*/
        for(j = 0; j < width; j++){
          if(width_ptr[j] == 1){ /*width_ptrが初期値でないときその列は残る*/
            printf("%c", grid_ptr[i][j]); /*この点は残っているので出力*/
          }
        }
        printf("\n");
      }
    }

    /*各々の使用済みの動的確保した破裂を解放*/
    free(height_ptr);
    free(width_ptr);
    for(i = 0; i < height; i++){
      free(grid_ptr[i]);
    }
    free(grid_ptr);
    return 0;
  }


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int n,m,C,a[21],i,j,x,sum=0,ans=0;
int main(){
	cin>>n>>m>>C;
	for(i=1;i<=m;i++)
		cin>>a[i];
	for(i=1;i<=n;i++){
		sum=0;
		for(j=1;j<=m;j++){
			cin>>x;
			sum+=x*a[j];
		}
		if(sum+C>0) ans++; 
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,h; cin>>n>>h;
    vector<ll> a(n),b(n);
    ll maxa = 0;
    rep(i, n) {
        cin>>a[i]>>b[i];
        chmax(maxa, a[i]);
    }
    sort(b.begin(), b.end());
    ll ans = 0;
    while(h>0 && !b.empty()){
        ll t = b.back();
        if(t <= maxa) break;
        ans++;
        h -= t;
        b.pop_back();
    }
    if(h>0){
        ll cnt = (h+maxa-1)/maxa;
        ans += cnt;
    }
    cout<<ans<<endl;


}
//abc085_d

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,q,now,ans;
string s;
bool memo1[200000],memo2[200000];
char t[200000],d[200000];

signed main() {
    cin >> n >> q >> s;
    rep(i,q) cin >> t[i] >> d[i];
    now = 0;
    repm(i,q) {
        if (t[i] == s[now] && d[i] == 'L') memo1[now] = true,now++;
        if (now) if (t[i] == s[now-1] && d[i] == 'R') now--,memo1[now] = false;
        if (now == s.size()) break;
    }
    now = s.size()-1;
    repm(i,q) {
        if (t[i] == s[now] && d[i] == 'R') memo2[now] = true,now--;
        if (now != s.size()-1) if (t[i] == s[now+1] && d[i] == 'L') now++,memo2[now] = false;
        if(now < 0) break;
    }
    rep(i,n) if (memo1[i] | memo2[i]) ans++;
    cout << n-ans << endl;
}



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

const unsigned long long int inf=1e18;



void solve()
{


ll n,p=1;
cin>>n;
ll a[n];
for(ll i=0;i<n;i++)
{
	cin>>a[i];
	if(a[i]==0)
	p=0;
	
}

if(p==0)
{
	cout<<0;
	return;
}

for(ll i=0;i<n;i++)
{
	
	if(a[i]<=inf/p)
	{
		p*=a[i];
	}
	else
	{
		cout<<-1;
		return;
	}
	
}


cout<<p;


}


int main()
{


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


		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 4400
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n";
using namespace std;
typedef long long int ll;
int main()
{
    
    int n;
    cin>>n;
    if(n>=30){cout<<"Yes"<<endl;}
    else {cout<<"No"<<endl;}
    return 0;
}

Measured memory_bytes: 3632
from heapq import *
n, m = [int(x) for x in input().split()]
As = [int(x) for x in input().split()]
heap = []
[heappush(heap, -a) for a in As]
for _ in range(m):
    big = -heappop(heap)
    heappush(heap, -(big//2))
print(-sum(heap))



Measured memory_bytes: 14180
def max(a, b)
  a > b ? a : b
end

N, W = gets.split.map(&:to_i)
WV = N.times.map{gets.split.map(&:to_i)}.sort_by{|a|[a[0], a[1]]}
#N = 100
#W = 10 ** 5
#WV = N.times.map{[rand(1..W-1), rand(1..10**9)]}.sort_by{|a|[a[0], a[1]]}

dp = Array.new(W + 1, 0)
dp[0] = 0
N.times do |i|
  w, v = WV[i]
  W.downto(w) do |nw|
    nv = dp[nw - w] + v
    dp[nw] = max(dp[nw], nv)
  end
end

p dp.max

Measured memory_bytes: 2556
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defun gene-switch-type (n)
  (let ((line (loop repeat n collect 0))
        (res))
    (labels ((f (lst thunk)
               (if lst
                   (progn
                     (setf (car lst) 0)
                     (f (cdr lst) thunk)
                     (setf (car lst) 1)
                     (f (cdr lst) thunk))
                   (funcall thunk))))
      (f line (lambda () (push (coerce line 'vector) res)))
      res)))

(defun check (lights switch-type sums)
  (let ((n (length lights)))
    (dotimes (i n)
      (unless (= (aref sums i)
                 (mod (loop for j in (aref lights i)
                       sum (aref switch-type j)) 2))
        (return-from check nil))))
  t)

(defun main (n m lights sum)
  (loop for switch-type in (gene-switch-type n)
        sum
        (if (check lights switch-type sum) 1 0)))

(let* ((n (read))
       (m (read))
       (lights (coerce (loop repeat m collect
                                      (loop repeat (read) collect (1- (read))))
                       'vector))
       (sum (coerce (loop repeat m collect (read)) 'vector)))
  (princ (main n m lights sum)))


Measured memory_bytes: 15668
N = int(input())
task = []
for i in range(N):
    a, b = map(int, input().split())
    task.append([a, b])

task = sorted(task, key=lambda x: x[1])

lim = 0
ok = True
for i in range(N):
    lim += task[i][0]
    if lim > task[i][1]:
        ok = False
        break
    if not ok:
        break
if ok:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 39692
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <array>
#include <bitset>
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
using namespace std;

string s, sub;

signed main() {
    fastio;
    cin >> s >> sub;
    // change s so sub is a substr of s
    int res = sub.size();

    for (int i = 0; i + sub.size() - 1 < s.size(); i++) {
        int cnt = sub.size();
        for (int j = 0; j < sub.size(); j++) {
            if (s[i + j] == sub[j]) {
                cnt--;
            }
        }
        res = min (res, cnt);
    }
    cout << res << endl;
}

Measured memory_bytes: 3204
// Always check for base cases
            // Check for overflows and out of index
            // Do something instead of sitting idle
            #include<bits/stdc++.h>
            #define ll long long
            #define f   first
            #define s   second
            #define pb          push_back
            #define mod        1000000007
            #define mod1       1000000009
            #define hell        998244353
            #define inf         1000000000000000000LL
            #define pi          3.14159265358979323
            //#define N           100005 
            const int N=200005;
            using namespace std;
            ll n,k,sum,q,res,m,val,ans;
            ll x,y;
            double p;
            ll xx[]={1,0,-1,0};
            ll yy[]={0,1,0,-1};
            void solve()    
            {   
                cin>>n>>x>>y;
                cout<<y*((n/x)+!(n%x==0));


            }
            int main()  
            {   ios_base::sync_with_stdio(false);
                cin.tie(0);cout.tie(0);
                ll t=1;  
                //cin>>t;
                 for(ll i=1;i<=t;i++)
                    solve();
                

            }            


Measured memory_bytes: 3648
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,ko;
    ll x,y,w,z;
    char hoge,fuga;
    cin>>str>>stra;
    if(str>stra) cout<<">"<<endl;
    else if(stra==str) cout<<"="<<endl;
    else cout<<"<"<<endl;

    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int a[200000];
int main(){
    int n;
    scanf("%d",&n);
    REP(i,n)
        scanf("%d",a + i);
    int cs = 0,c2 = 0,c4 = 0;

    REP(i,n){
        if(a[i] % 4 == 0)
            c4++;
        else if(a[i] % 2 == 0)
            c2++;
        else
            cs++;
    }

    if(c4 + 1 < cs || (c4 + 1 == cs && c2 > 0))
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}



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

using std::set;
using std::min;
using std::swap;

const int N=2e5+10,Node=N<<2,Inf=1e9+10;

int n,p[N],pos[N];

struct SegmentTree{
	#define ls z<<1
	#define rs z<<1|1
	int root,mn[Node][2],cnt,rev[Node];
	
	void Update(int z) {
		mn[z][0]=min(mn[ls][0],mn[rs][0]);
		mn[z][1]=min(mn[ls][1],mn[rs][1]);
	}
	
	void Build(int z,int l,int r) {
		if (l==r) {
			int op=l&1;
			mn[z][op]=p[l];
			mn[z][op^1]=Inf;
			return ;
		}
		int mid=(l+r)>>1;
		Build(ls,l,mid);
		Build(rs,mid+1,r);
		Update(z);
	}
	
	void setrev(int z) {
		rev[z]^=1;
		swap(mn[z][0],mn[z][1]);
	}
	
	void downrev(int z) {
		if (!rev[z]) return ;
		setrev(ls); setrev(rs);
		rev[z]=0;
	}
	
	void Find(int z,int l,int r,int q) {
		if (l==r) {
			mn[z][0]=mn[z][1]=Inf;
			return ;
		}
		downrev(z);
		int mid=(l+r)>>1;
		if (q<=mid) Find(ls,l,mid,q);
		else Find(rs,mid+1,r,q);
		Update(z);
	}
	
	int findMin(int z,int l,int r,int ql,int qr) {
		if (ql<=l && r<=qr) {
			return mn[z][0];
		}
		downrev(z);
		int mid=(l+r)>>1,ret=Inf;
		if (ql<=mid) ret=min(ret,findMin(ls,l,mid,ql,qr));
		if (qr>mid)  ret=min(ret,findMin(rs,mid+1,r,ql,qr));
		return ret;
	}
	
	void reverse(int z,int l,int r,int ql,int qr) {
		if (ql<=l && r<=qr) {
			setrev(z);
			return ;
		}
		downrev(z);
		int mid=(l+r)>>1;
		if (ql<=mid) reverse(ls,l,mid,ql,qr);
		if (qr>mid) reverse(rs,mid+1,r,ql,qr);
		Update(z);
	}
	
}St;

set<int>q;

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

void Solve() {
	St.root=1;
	q.insert(n+1);
	St.Build(St.root,1,n);
	for (int i=1;i<=n;i+=2) {
		if (i!=1) printf(" ");
		int v1=St.mn[St.root][1],v2;
		St.Find(St.root,1,n,pos[v1]); int pos2=*(q.lower_bound(pos[v1]));
		v2=St.findMin(St.root,1,n,pos[v1]+1,pos2-1); St.Find(St.root,1,n,pos[v2]);
		q.insert(pos[v1]); q.insert(pos[v2]);
		if (pos[v2]-pos[v1]>1) St.reverse(St.root,1,n,pos[v1]+1,pos[v2]-1);
		printf("%d %d",v1,v2);
	}
	putchar('\n');
}

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

Measured memory_bytes: 21760
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int A,B,C;

int halt(){
	printf("-1\n");
	return 0;
}

int main(){
	scanf("%d%d%d" , &A , &B , &C);
	int ans = 0;
	while(A%2==0&&B%2==0&&C%2==0){
		++ans;
		int x = min(min(A,B),C);
		A -= x; B -= x; C -= x;
		if(A==0 && B==0 && C==0) return halt();
		x = (B+C)/2;
		int y = (A+C)/2;
		int z = (A+B)/2;
		A = x;
		B = y;
		C = z;
	}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<cmath>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;

inline ll read() { 
	ll s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 1e5+5; 
int n, m, r = 0; ll ans[N], t[N], q[N];
inline int find(ll x) { 
	int L = 1, R = r, mid;
	while( L < R ) { 
		mid = (L + R + 1) >> 1;
		if( q[mid] < x ) L = mid;
		else R = mid - 1;
	} return L;
}

int main() { 
//	freopen("in.txt","r",stdin);
	m = q[++r] = read(), n = read();
	rep(i,1,n) { 
		ll x = read();
		while( r && x <= q[r] ) r--;
		q[++r] = x;
	}
	t[r] = 1;
	dow(i,r,1) { 
		ll x = q[i];
		while( x > q[1] ) { 
			int y = find(x);
			t[y] += t[i] * (x / q[y]);
			x %= q[y]; 
		} ans[x] += t[i];
	}
	dow(i,q[1]-1,1) ans[i] += ans[i+1];
	rep(i,1,m) printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

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

  if(A==1)
    {
      if(B==2)
	cout << 3 << endl;
      if(B==3)
	cout << 2 << endl;
    }
  else if(A==2)
    {
      if(B==1)
	cout << 3 << endl;
      if(B==3)
	cout << 1 << endl;
    }
  else
    {
      if(B==1)
	cout << 2 << endl;
      else
	cout << 1 << endl;
    }


  return 0;
}



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

int main() {
int A,B,C;
  cin >>A>>B>>C;
  if(A==B && B==C){
    cout <<1;
  }
  else if(A!=B &&A!=C && B!=C){
    cout <<3;
  }
  else {
    cout <<2;
  }

}
 

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

int main() {
  char s[10]; for(int i = 0; i < 10; ++i) cin >> s[i];
  s[0] = '2'; s[1] = '0'; s[2] = '1'; s[3] = '8';
  for(int i = 0; i < 10; ++i) cout << s[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
while 1:
    try:
        n=raw_input()
        l=[int(x) for x in n]
        tmp=[]
        while len(l)>1:
            for i in range(len(l)-1):
                tmp.append((l[i]+l[i+1])%10)
            l=tmp[:]
            tmp=[]
        print l[0]


    except:
        break

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

//GCD,LCM
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;}

int main()
{
    int N,A,B,a=0,b=0;
    string S;
    cin>>N>>A>>B;
    cin>>S;

    for(int i=0;i<N;i++){
        if(S[i]=='c'){
            cout<<"No"<<endl;
        }else if(S[i]=='b'){
            if((a+b)<(A+B)&&b<B){
                cout<<"Yes"<<endl;
                b++;
            }else{
                cout<<"No"<<endl;
            }
        }else{
            if((a+b)<A+B){
                cout<<"Yes"<<endl;
                a++;
            }else{
                cout<<"No"<<endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
        s = s[s.size() - 1] + s.substr(0, s.size() - 1);
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline

N, K = map(int, input().split())
l = np.array([list(map(int, input().split())) for _ in range(N)])
a = l[np.argsort(l[:, 0])]

B = 0
for x in a:
  B += x[1]
  if B >= K:
    print(x[0])
    break

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

int main()
{
  bool bb[3][3];
  int a[3][3];
  map<int,int> mp;
  rep(i,3){
    rep(j,3){
      cin >> a[i][j];
      bb[i][j] = false;
    }
  }

  int b,q;
  cin >> b;
  rep(i,b){
    cin >> q;
    rep(j,3){
      rep(k,3){
        if(a[j][k] == q){
          bb[j][k] = true;
          //cout << a[j][k] << endl;
        }
      }
    }
  }
  
  rep(i,3){
    if(bb[0][i] && bb[1][i] && bb[2][i]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  rep(i,3){
    if(bb[i][0] && bb[i][1] && bb[i][2]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if(bb[0][0] && bb[1][1] && bb[2][2]){
    cout << "Yes" << endl;
      return 0;
  }
  if(bb[2][0] && bb[1][1] && bb[0][2]){
    cout << "Yes" << endl;
      return 0;
  }
  cout << "No" << endl;
  return 0;
           
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// abc128c
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> s[11];
    rep(i, m){
        int k;
        cin >> k;
        rep(j, k){
            int ss;
            cin >> ss;
            ss--;
            s[i].push_back(ss);
        }
    }
    int p[11];
    rep(i, m) cin >> p[i];
    int ans = 0;
    for(int bit=0; bit< (1<<n); bit++){
        bool flag = true;
        rep(i, m){
            int tmp=0;
            rep(j, s[i].size()){
                if (bit & 1<<s[i][j]){
                    tmp++;
                }
            }
            if (tmp%2!=p[i]){
                flag = false;
                break;
            }
        }
        if (flag) ans++;

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


Measured memory_bytes: 256
#ifndef ONPC
  #define _FORTIFY_SOURCE 0
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("no-stack-protector")
  #pragma GCC optimize("unroll-loops")
  #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
  #pragma GCC optimize("fast-math")
#endif

#include <bits/stdc++.h>

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int mx = 0;
    for (int i = 1; i < n; i++){
      mx = max(mx, a[i] - a[i-1]);
    }

    mx = max(mx, a[0] + k - a[n-1]);

    cout << k - mx << '\n';

    return 0;
}


Measured memory_bytes: 1024