akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
//#include<cmath>
//#include<algorithm>
//#include<cstring>
//#include<map>
using namespace std;
inline int read()
{
    int p=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}
    return f*p;}
int main()
{
	int A=read(),B=read(),C=read(),D=read();
	if(A+B>C+D)cout<<"Left";
	else if(A+B<C+D)cout<<"Right";
	else cout<<"Balanced";
	return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int k,p;
	for(int i=0; i<n; i++){
		cin>>k>>p;
		while(k>p)
			k-=p;
		cout<<k<<endl;
	}
	return 0;
}

Measured memory_bytes: 3100
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(N)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        L[i] = 0
    else:
        L[i] = gcd(L[i-1], A[i-1])
for i in range(N-1, -1, -1):
    if i == N-1:
        R[i] = 0
    else:
        R[i] = gcd(R[i+1], A[i+1])
for i in range(N):
    T[i] = gcd(L[i], R[i])

print(max(T))

Measured memory_bytes: 14056
float a,b,c,d,p=57.2957795;main(){for(;~scanf("%f%f%f%f",&a,&b,&c,&d);)a+1&&printf("%.0f\n",6378.1*acos(sin(a/p)*sin(c/p)+cos(a/p)*cos(c/p)*cos(b/p-d/p)));}

Measured memory_bytes: 0
module ABC154A
  sub Main(ByVal args() as String)
    Dim H as Long
    Dim A as Long
    Dim arr(2) as String
    arr=Split(Console.ReadLine())
    H = arr(0)
    A = arr(1)
    
    Dim res as Long
    res = H \ A
    If H mod A <> 0 Then
        res = res + 1
    End If

    Console.WriteLine("{0}", res)
  end sub
end module


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

int main(){
  int n;
  cin >> n;
  int k,p;

  for(int i=0;i<n;i++){
    cin >> k >> p;
    while((k-p)>0){
      k=k-p;
    }
    cout << k << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>

using namespace std;

long long GCD(long long x, long long y){
    if(y == 0) return x;
    else return GCD( y, x%y );
}

long long solve(int N, long long M, vector<long long> &a){
    //2で割れるだけわる
    while( a[0] %2 == 0 ){
        for(int i=0; i<N; ++i){
            if(a[i] %2 != 0) return 0;
            a[i] /= 2;
        }
        M/=2;
    }

    //ord2が違ったらretur 0
    for (int i = 0; i < N; ++i){
        if (a[i] % 2 == 0) return 0;
    } 

    // lcm
    long long lcm = 1;
    for( int i=0; i<N; ++i){
        long long g = GCD(lcm, a[i]);
        lcm = lcm/g * a[i];
        // if lcm beyond M return zero.
        // if we don't do this lcm might overflow and cause wrong answer.
        if(lcm > M) return 0;
    }
    return (M / lcm +1)/2;
}

int main(){
    int N;
    long long M;
    cin >> N >> M;

    vector<long long> a(N);
    for(int i=0; i<N; ++i) {
        cin >> a[i];
        a[i] /= 2;
    }

    cout << solve(N, M, a) << endl;

}

Measured memory_bytes: 1024
#include<cstring>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n;
while(1)
{
scanf("%d",&n);
if(n==0)break;

char ans[128];

sprintf(ans,"%o",n);
//printf("%s\n",ans);
for(int i=0;ans[i]!='\0';i++)
{
if(ans[i]>='4')ans[i]++;
if(ans[i]>='6')ans[i]++;
}
printf("%s\n",ans);
}
/*while(true)
{
cin>>n;
int ans=0;
for(int i=1;i<=n;i++)
	{
	
	if(i%10==4 || i/10==4)
		{
		//cout<<i<<endl;
		ans+=2;
		
		}
	else if(i%10==6 || i/10==6)
		{
		//cout<<i<<endl;
		ans+=2;
		
		}
	else ans++;

	}
	if(ans%10==4 || ans%10==6)ans++;
cout<<ans<<endl;
}*/
return 0;
}

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

int getDigit(int num){
    int digit = 0;
    while(num != 0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
    int a, b = 0;
    while(cin >> a >> b){
        cout << getDigit(a + b) << endl;
    }
    return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
 
ll power(ll a, ll b){//a^b
    ll res=1;
    while(b>0){
        if(b&1){res=(res*a);b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}
 
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll h;
	cin>>h;
	ll c=1;
	ll sum=0;
	while(h>1){
		sum+=c;
		h=h/2;
		c=c*2;
	}
	sum+=c;
	cout<<sum<<"\n";
}

Measured memory_bytes: 3644
#include <stdio.h>
#define VAR_MAX 9

int main(void){
	int a, b, c, N, count=0;
	
	while(scanf("%d",&N)==1){
		count=0;
		for(a=0;a<=VAR_MAX;a++){
			for(b=0;b<=VAR_MAX;b++){
				for(c=0;c<=VAR_MAX;c++)
					if(0<=N-a-b-c && N-a-b-c<=VAR_MAX) count++;
			}
		}
		printf("%d\n",count);
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
		
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long W = sc.nextInt(), H = sc.nextInt(), x =sc.nextInt(), y=sc.nextInt();
		sc.close();
		
		double ans1 = (double)(W*H)/2;
		
		int ans2 = 0;
		if(2*x==W&&2*y==H) ans2 = 1;
		
		System.out.println(ans1+" "+ans2);
	}
	
}

Measured memory_bytes: 23380
#include <iostream>

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


int main() {

  int n;
  scanf("%d", &n);
  int l[2000];
  rep(i, n) {
    scanf("%d", &l[i]);
  }

  int ans = 0;
  rep(i, n) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        if (l[i] < l[j] + l[k] &&
            l[j] < l[i] + l[k] &&
            l[k] < l[i] + l[j]) {
          ans++;
        }
      }
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
/*
*----------------------------------------------
*   Saurabh Srivastava - SAURASS - andha_koder
*----------------------------------------------
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1e9 + 7

ll fpow(ll a, ll k){
    ll ans = 1;
    while(k) {
        if(k % 2) {
            ans *= a;
            ans %= (ll)MOD;
        }
        a *= a;
        a %= (ll)MOD;
        k /= 2;
    }
    return ans;
}

ll fact(ll n) { 
    ll res = 1; 
    for (ll i = 2; i <= n; i++) {
        res = res * i;
        res %= (ll)MOD; 
    }
    return res; 
}

ll invP(ll a) {
    return fpow(a, MOD - 2);
}

ll nCr(ll n, ll r) {
    ll ans = fact(n);
    ans *= invP(fact(r));
    ans %= (ll)MOD;
    ans *= invP(fact(n - r));
    ans %= (ll)MOD;

    return ans;
}

int main() {

    ll x, y;
    cin >> x >> y;
    ll a = 2 * y - x;
    ll b = 2 * x - y;
    if(a % 3 or a % 3) {
        cout << 0;
    } else {
        a /= 3;
        b /= 3;
        if(a < 0 or b < 0)
            cout << 0;
        else
            cout << nCr(a + b, a);
    }

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  double x[n];
  string u[n];
  for(int i=0;i<n;i++){
    cin >> x[i] >> u[i];
  }
  double cnt=0;
  for(int i=0;i<n;i++){
    if(u[i]=="BTC"){
      cnt+=380000*x[i];
    }else{
      cnt+=x[i];
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
n = onem()

c = l()

c.sort(reverse = True)

po = 1

for i in range(n-1):
    po *= 4
    po %= mod

co = 0

for i in range(n):
    co += (i+2)*c[i]
    co %= mod
    
print((co * po) % mod)





Measured memory_bytes: 104400
#include <bits/stdc++.h>
#define N 205
using namespace std;
int main(){
	long long n,m,r,dist[N][N],i,j,k,a,b,c,d,ans=1e9,res;
	vector<long long> vp,s;
	cin>>n>>m>>r;
	for(i=0;i<N;i++)
	{
		for(j=0;j<N;j++)
		{
			dist[i][j]=1e8;
			if(i==j)
			{
				dist[i][j]=0;
			}
		}
	}
	for(i=0;i<r;i++)
	{
		cin>>d;
		vp.push_back(d);
	}
	for(i=0;i<m;i++)
	{
		cin>>a>>b>>c;
		dist[a][b]=c;
		dist[b][a]=c;
	}
	for(k=1;k<=n;k++)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	s=vp;
	do
	{
		res=0;
		for(i=1;i<vp.size();i++)
		{
			res+=dist[vp[i-1]][vp[i]];
		}
		ans=min(ans,res);
		next_permutation(vp.begin(),vp.end());
	}while(vp!=s);
	cout<<ans<<endl;
	return 0;
}


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

 int main() {
   int N, L;
   cin >> N >>L;
  int  res = 0;
   for (int i = 0; i < N; i++) {
     res += L + i;
   }
   int s = abs(L + N -1) ,a = L + N -1;
   for (int i = 0; i < N; i++) {
     if (abs(L + i) < s) {
      s = abs(L + i);
      a = L + i;
     }
   }
   cout << res - a << '\n';
 }


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


def frog(num, stride, heights):
    """
    Prameters
    ---------
    num : int
        足場の数

    stride : int
        ジャンプステップ

    heights : list
        足場の高さ

    Return
    ------
    min_cost : int
        最小コスト
    """
    dp = np.zeros(num, dtype=int)
    heights = np.array(heights)
    for i in range(1, num):
        start = max(0, i - stride)
        dp[i] = min(dp[start: i] + np.abs(heights[i] - heights[start: i]))
    return dp[-1]

N, K = ds_in()
h_list = ds_in()

print(frog(N, K, h_list))


Measured memory_bytes: 22804
using System;
using System.Linq;

namespace abc126A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int b = a[2];
            for(int i = 0; i < 10; i++)
            {
                Console.WriteLine((b * a[0]) - a[1]);
                b = (b * a[0]) -a[1];
            }
        }
    }
}


Measured memory_bytes: 27920
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A)

if len(c) <= K:
    print(0)
else:
    c = sorted(c.items(), key=lambda x: x[1])
    dif = len(c) - K
    cnt = 0
    for i in range(dif):
        cnt += c[i][1]
    print(cnt)


Measured memory_bytes: 39344
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
typedef pair<int, int> pii;
ll mod=998244353;
ll p=1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; cin>>n>>m;
    int h[n+1];
    vector<int> adj[n+1];
    for(int i=1; i<=n; i++){
        cin>>h[i];
    }
    for(int i=0; i<m ; i++){
        int u,v; cin>>u>>v;
        adj[u].push_back(v); adj[v].push_back(u);
    }
    int ans=0;
    for(int i=1; i<=n; i++){
        ans++;
        for(int u: adj[i]){
            if( h[i]<=h[u]) {
                ans--;
                break;
            }
        }

    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <unordered_set>
#include <queue>

int len[100001] = { 0 };
int len2[100001] = { 0 };
int count[100001] = { 0 };
int count2[100001] = { 0 };
std::vector<int> e[100001];

int main() {
    int n, m, s, t;
    std::cin >> n >> m >> s >> t;
    s; t;

    for (int i = 0; i < m; i++) {
        int x, y;
        std::cin >> x >> y;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    std::queue<std::pair<int, int>> q; // first:今の場所 second:cost
    q.push(std::make_pair(s, 0));

    int minLen = 0;
    bool isGoal = false;
    while (!q.empty() && !isGoal) {
        auto node = q.front(); q.pop();
        node.second++;
        for (auto to : e[node.first]) {
            if (len[to] && len[to] <= node.second || to == s) continue;
            auto next = node;
            len[to] = next.second;
            next.first = to;
            q.push(next);

            if (to == t) {
                minLen = next.second;
                isGoal = true;
                break;
            }
        }
    }

    // 逆方向
    q = std::queue<std::pair<int, int>>();
    q.push(std::make_pair(t, 0));
    isGoal = false;
    while (!q.empty() && !isGoal) {
        auto node = q.front(); q.pop();
        node.second++;
        // 打ち切り
        if (node.second > minLen - 2) {
            break;
        }
        for (auto to : e[node.first]) {
            if ((len2[to] && len2[to] <= node.second) || to == s || to == t) continue;

            auto next = node;
            len2[to] = next.second;
            next.first = to;
            q.push(next);

            if (to == t) {
                isGoal = true;
                break;
            }
        }
    }

    // 距離カウント
    for (auto x : len) {
        count[x]++;
    }
    for (auto x : len2) {
        count2[x]++;
    }

    // 数カウント
    long long num = 0;
    for (int i = 0; i < minLen - 1; i++) {
        long long from = count[i];
        long long to = count2[minLen - (i + 2)];
        if (!i) from = 1;
        if (minLen - (i + 2) == 0) to = 1;

        num += from * to;
    }

    std::cout << num << std::endl;
    return 0;
}


Measured memory_bytes: 10476
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 5000;

int dp[N + 1][N + 1];

int main() {
	int n; cin >> n;
	string s; cin >> s;
	for (int i = n - 1; i >= 0; i--)
		for (int j = i + 1; j < n; j++)
			if (s[i] == s[j])
				dp[i][j] = dp[i + 1][j + 1] + 1;
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = i + 1 + ans; j < n; j++)
			ans = max(ans, min(dp[i][j], j - i));
	cout << ans << '\n';
	return 0;
}


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

void solve(string S){
	int N = S.size();
	int W = 0;
	for(int i = 0; i < S.size(); ++i) {
		if(S[i] == 'W') ++W;
	}
	int t = 0;
	long long res = 0;
	for(int i = 0; i < N; ++i) {
		if(S[i] == 'W'){
			res += abs(i - t);
			++t;
		}
	}
	cout << res << endl;
}

int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;

const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;

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

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問状況

int n;
double p[3000];
double dp[3000][3000];

int main() {
// input
    cin >> n;
    rep(i, n) {
        cin >> p[i];
    }
// solve
    dp[0][0] = 1.0;

    // DP ループ
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }
// output
    double ans = 0;
    for (int i = n; i > n/2; i--) {
        ans += dp[n][i];
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 49892
# 3.4.3

import re
from collections import deque
from functools import reduce
from heapq import *
from itertools import permutations
from math import pi
from operator import itemgetter
from operator import mul
from operator import xor
from os import linesep


def isprime(n: int) -> bool:
    if n <= 1:
        return False
    if n in (2, 3, 5):
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    lst = int(n**0.5)
    f = 5
    while f <= lst:
        if n % f == 0:
            return False
        if n % (f + 2) == 0:
            return False
        f += 6
    return True


def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str:
    return lnsep.join(map(lambda row: fieldsep.join(map(str, row)), matrix))


def strbool(boolval: int) -> str:
    return ['No', 'Yes'][boolval]


def solve() -> None:
    # read here
    n, m, *t = map(int, open(0).read().split())

    # solve here
    d = [[] for i in range(m+1)]
    for i in range(n):
        a, b = t[2*i], t[2*i+1]
        if a > m:
            continue
        d[a].append(b)

    ans = 0
    tasks = []
    for t in range(m + 1):
        # from (m days after) to today
        for tasksize in d[t]:
            heappush(tasks, -tasksize)
        if tasks:
            # do task
            ans -= heappop(tasks)

    # print here
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 25444
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <set>
#include <utility>

int main(){
    long n;
    std::cin >> n;
    std::vector<long> a(n);
    std::vector<long> cnt(n + 1, 0);
    int res = 0;
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        if(a[i] > n){
            ++res;
        }else{
            cnt[a[i]]++;
        }
    }

    /*
    for(auto& x : cnt){
        std::cout << x << std::endl;
    }
    */

    for(int i = 1; i <= n; i++){
        if(cnt[i] < i){
            res += cnt[i];
        }else{
            res += cnt[i] - i;
        }
    }
    std::cout << res << std::endl;
    return 0;
}


Measured memory_bytes: 1792
#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 300014



/**
int marked[M/64 + 2];

#define on(x) (marked[x/64] & (1<<((x%64)/2)))
#define mark(x)  marked[x/64] |= (1<<((x%64)/2))

void bitwiseSieve() {
  for (int i = 3; i * i <=M; i += 2) {
    if (!on(i)) {
      for (int j = i * i; j <= M; j += i + i) {
        mark(j);
      }
    }
  }
}

bool isPrime(int num) {
  return num > 1 && (num == 2 || ((num & 1) && !on(num)));
}
**/


/**
vector<ll>phi(M+2);
bool p[M+2];

void euler_phi(void)
{

    for(ll i=0;i<=M;i++)phi[i]=i;
    memset(p,0,sizeof p);
    p[1]=1;
    p[0]=1;
    phi[1] = 0;

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

        if(!p[i])
        {

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

            }
            p[i]=0;
        }
    }


}
//**/


/**
bool p[M+2];
vector<ll>prime;
void seive(void)
{

    memset(p,0,sizeof p);
    p[1]=1;
    p[0]=1;

    for(ll 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(ll 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 bigmod(ll a, ll b, ll c)
{
    if(b==0)return 1;
    if(b%2)
    {
        ll p = bigmod(a,b-1,c);
        return (a*p)%c;
    }
    else
    {
        ll p = bigmod(a,b/2,c);
        return (p*p)%c;
    }
}
//**/

vector<ll>num,in;
ll N;
void call(ll pos,ll sum)
{
    if(sum>=N)
    {
        num.push_back(sum);
        return;
    }
    for(ll i=0; i<in.size();i++)
    {
        ll temp=sum;
        temp*=10;
        temp+=in[i];
        if(pos==0 && in[i]==0)continue;
        call(pos+1,temp);
    }

}



void solve(ll t)
{


    ll n,k;
    cin>>n>>k;
    N=n;
    map<ll,ll>mp;
    for(int i=0;i<k;i++)
    {
        ll temp;
        cin>>temp;
        mp[temp]++;
    }


    for(ll i=1;i<10;i++)if(!mp[i])in.push_back(i);
    if(!mp[0])in.push_back(0);
    call(0,0);
    sort(num.begin(),num.end());
    if(num.size()>0)
    cout<<num[0]<<endl;
    else cout<<0<<endl;




}


int main()
{
//     freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

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

    /**seive();        //**/
    /** euler_phi();    //**/
    /** show(phi);      //**/
    /** bitwiseSieve(); //**/




    ll t=1;
    //scanf("%lld",&t);
    ll T=t;



    while(t--)
    {


        solve(T-t);

    }
    return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> b(n-1);
    rep(i, n-1) cin >> b[i];

    int ans = 0;

    ans += b[0] + b[n-2];

    for (int i=0; i<=n-3; i++) {
        ans += min(b[i], b[i+1]);
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
import itertools

while True:
    a, b = map(int, input(). split())
    if a == 0 and b == 0:
        break

    s = list(itertools.combinations(range(10), a))

    cnt = 0

    for i in s:
        if sum(i) == b:
            cnt += 1

    print(cnt)

Measured memory_bytes: 7608
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


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

  if(A+B<10) cout<<A+B;
  else cout<<"error";
      
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

#define MAXN 3005

long long dp[MAXN][MAXN][2];
long long as [MAXN];

long long calc(int inicio, int fin, int p){
    if(dp[inicio][fin][p]!=-1){
        return dp[inicio][fin][p];
    }
    if(p==0){
        return dp[inicio][fin][p]=max(as[inicio]+calc(inicio+1,fin,1),as[fin]+calc(inicio,fin-1,1));
    }
    return dp[inicio][fin][p]=min(calc(inicio+1,fin,0),calc(inicio,fin-1,0));
}

int main(){
    int n;
    long long suma =0,X,rta;
    scanf("%d", &n);
    for(int i =0; i<MAXN; i++){
        for(int j =0; j<MAXN; j++){
            dp[i][j][0] = dp[i][j][1]=-1;
        }
    }
    for(int i=0; i<n; i++){
        scanf("%lld", &as[i]);
        suma+=as[i];
        dp[i][i][0]  = as[i];
        dp[i][i][1] = 0;
    }
    X = calc(0,n-1,0);
    rta = 2*X-suma;
    printf("%lld\n",rta );
}

Measured memory_bytes: 141568
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) std::cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) std::cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) std::cout << x << endl;
#define println(x) std::cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    unordered_map<int, int> cnt;
    rep(i, n) cnt[A[i]] = 0; 
    rep(i, n) cnt[A[i]]++;

    ll remove = 0;
    for (auto& kv: cnt) {
        remove += kv.second - 1;
    }

    ll nOp = (remove + 1) / 2;
    ll res = n - nOp * 2;

    put(res);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 7988
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    lint n, p;

    scanf("%lld", &n);
    scanf("%lld", &p);

    std::vector<lint> a(n);

    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
    }

    lint odd, even;
    odd = even = 0;

    for (auto a_e : a)
    {
        if (a_e % 2 == 0)
            even++;
        else
            odd++;
    }

    std::vector<lint> odd_comb;
    odd_comb.push_back(1);

    lint c = 1;

    for (int i = 1; i <= odd / 2; ++i)
    {
        c *= odd - (i - 1);
        c /= i;
        odd_comb.push_back(c);
    }

    lint even_pattern = pow(2, even);

    lint odd_pattern = 0;

    if (p == 0)
    {
        for (int i = 0; i <= odd; i += 2)
        {
            if (i <= odd / 2)
            {
                odd_pattern += odd_comb[i];
            }
            else
            {
                odd_pattern += odd_comb[odd - i];
            }
        }
    }
    else
    {
        for (int i = 1; i <= odd; i += 2)
        {
            if (i <= odd / 2)
            {
                odd_pattern += odd_comb[i];
            }
            else
            {
                odd_pattern += odd_comb[odd - i];
            }
        }
    }

    printf("%lld", odd_pattern * even_pattern);

    return 0;
}


Measured memory_bytes: 512
import copy

H,W,K=map(int,input().split())
C=[]
for i in range(H):
    C.append(list(input()))
Ans=0
for i in range(2**H):
    IDh=format(i,"b").zfill(H)
    for j in range(2**W):
        n=0
        IDw=format(j,"b").zfill(W)
        c=copy.deepcopy(C)
        for k in range(H):
            if IDh[k]=="1":
                c[k]=["!" for i in range(W)]
        for k in range(W):
            if IDw[k]=="1":
                for l in range(H):
                    c[l][k]="!"
        for k in range(H):
            for l in range(W):
                if c[k][l]=="#":
                    n+=1
        if n==K:
            Ans+=1
print(Ans)

Measured memory_bytes: 9308
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	
	map<char, int> counter;
	for (int i = 0; i < s.size(); i++) counter[s[i]]++;

	int ans = s.size() / 2 - counter['p'];
	printf("%d\n", ans); 
	return 0;
}

Measured memory_bytes: 3872
from sys import stdin


def main():
    N, *S = [i.strip() for i in stdin.readlines()]
    N = int(N)
    judge = ["AC", "WA", "TLE", "RE"]
    mul = " x "
    C = [0] * len(judge)
    for Si in S:
        C[judge.index(Si)] += 1
    print("\n".join((judge[i] + mul + str(C[i]) for i in range(len(judge)))))
    return


main()


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

const int kN = 2000 + 5;
int n, a[kN], z, w;

int abs(int x)
{
    return x > 0 ? x : -x;
}

int dp[kN][2];
bool vis[kN][2];

int calc(int at, int turn)
{
    if (at + 1 == n)
        return abs(a[at] - a[n]);
    if (vis[at][turn])
        return dp[at][turn];

    vis[at][turn] = true;
    int ret = abs(a[at] - a[n]);
    if (at == 0)
        ret = 0;
    for (int i = at + 1; i < n; ++ i) {
        int t = calc(i, turn ^ 1);
        if (turn == 0)
            ret = std::max(ret, t);
        else
            ret = std::min(ret, t);
    }
    return dp[at][turn] = ret;
}

int work()
{
    int ret = abs(w - a[n]);
    if (n == 1)
        return ret;

    return std::max(ret, calc(0, 0));
}

int main()
{
    std::cin >> n;
    std::cin >> z >> w;
    for (int i = 1; i <= n; ++ i)
        std::cin >> a[i];
    printf("%d\n", work());
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;  // 初期状態
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  // 1-index

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;  // dist と dt の偶奇は一致する必要あり！
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

#define N 100000
#define K 1000
#define BLACK 0
#define WHITE 1

int a[2][3 * K + 1][3 * K + 1];
long long sum[2][3 * K + 1][3 * K + 1];
int n, k;

long long query(int xi, int yi, int xf, int yf, int color){
	return sum[color][xf][yf] - sum[color][xi - 1][yf] - sum[color][xf][yi - 1] + sum[color][xi - 1][yi - 1];
}

long long solve(int x, int y, int color){
	return query(x, y, x + k - 1, y + k - 1, color);
}

int main(){
	long long ans, cur;
	int x, y, i, j;
	char c;

	scanf("%d%d%*c", &n, &k);

	for (i = 1; i <= n; i++){
		scanf("%d%d%*c%c%*c", &x, &y, &c);

		if (c == 'B'){
			a[BLACK][x % (2 * k) + 1][y % (2 * k) + 1]++;
		}
		else{
			a[WHITE][x % (2 * k) + 1][y % (2 * k) + 1]++;
		}
	}

	for (i = 1; i <= 3 * k; i++){
		for (j = 1; j <= 3 * k; j++){
			a[BLACK][i][j] = a[BLACK][(i - 1) % (2 * k) + 1][(j - 1) % (2 * k) + 1];
			a[WHITE][i][j] = a[WHITE][(i - 1) % (2 * k) + 1][(j - 1) % (2 * k) + 1];
		}
	}

	for (i = 1; i <= 3 * k; i++){
		for (j = 1; j <= 3 * k; j++){
			sum[BLACK][i][j] = sum[BLACK][i - 1][j] + sum[BLACK][i][j - 1] - sum[BLACK][i - 1][j - 1] + (long long)a[BLACK][i][j];
			sum[WHITE][i][j] = sum[WHITE][i - 1][j] + sum[WHITE][i][j - 1] - sum[WHITE][i - 1][j - 1] + (long long)a[WHITE][i][j];
		}
	}

	ans = 0;

	for (i = 1; i <= k; i++){
		for (j = 1; j <= k; j++){
			cur = 0;

			cur += solve(i, j, BLACK);
			cur += solve(i + k, j + k, BLACK);
			cur += solve(i + k, j, WHITE);
			cur += solve(i, j + k, WHITE);

			ans = max(ans, cur);
		}
	}

	for (i = 1; i <= k; i++){
		for (j = 1; j <= k; j++){
			cur = 0;

			cur += solve(i, j, WHITE);
			cur += solve(i + k, j + k, WHITE);
			cur += solve(i + k, j, BLACK);
			cur += solve(i, j + k, BLACK);

			ans = max(ans, cur);
		}
	}

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

	return 0;
}

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

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

	vector<int> inputs(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> inputs[i];
	}

	int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		sum += inputs[i];
	}

	int sum_left = 0;
	for (int i = 0; i < n; ++i)
	{
		sum_left += inputs[i];
		if ((sum + 1)/2 <= sum_left)
		{
			if ((sum_left - (sum + 1)/2) > ((sum + 1) / 2 - sum_left + inputs[i]))
			{
				sum_left -= inputs[i];
			}
			break;
		}
	}

	cout << abs(2 * sum_left - sum) << endl;
}

Measured memory_bytes: 256
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln endl
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inp freopen("input.txt", "r", stdin)
#define outp freopen("output.txt", "w", stdout)
#define dbgm(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 2e5+5, MOD = 1e9+7, EPS = 1e-9;
int t,n,m,k,x,y;
int main(){
	fastio;
	int h,w;
	cin>>h>>w;
	int tab[h][w];
	forn(i,h){
		forn(j,w){
			char x;
			cin>>x;
			if(x=='.') tab[i][j] = 1;
			else tab[i][j] = 0;
		}
	}
//	forn(i,h) forn(j,w) cout<<tab[i][j]; cout<<ln;
	ll dp[h][w];
	forn(i,h){
		forn(j,w) dp[i][j]=0;
	}
	dp[0][0]= 1;
	forn(i,h){
		forn(j,w){
			if(i==0 && j==0) continue;
			ll count=0;
			if(i>0) count+=dp[i-1][j];
			if(j>0) count+=dp[i][j-1];
			if(tab[i][j]) dp[i][j] = count%MOD;
		}
	}
	cout<<dp[h-1][w-1]<<ln;
	return 0;
}

Measured memory_bytes: 12032
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int a, b, k;
  readf("%s %s %s\n", &a, &b, &k);
  int cnt;
  foreach_reverse (i; 1..min(a, b)+1) {
    if (a % i == 0 && b % i == 0) {
      cnt++;
    }
    if (cnt == k) {
      i.writeln;
      break;
    }
  }
}


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

using namespace std;

int main()
{
    int l;
    double v, w, h;
    double ans;

    cin >> l;
    v = w = h = l / 3.0;

    ans = v * w * h;
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000

typedef struct{
	int top;
	int S[MAX];
}Stack;

void initialize(Stack *st)
{
	st->top = 0;
	st->S[st->top] = 0;
}

int isEmpty(Stack *st)
{
	return st->top == 0;
}

int isFull(Stack *st)
{
	return st->top >= MAX -1;
}

void push(int x, Stack *st)
{
	if(isFull(st))
	exit(1);
	
	st->top++;
	st->S[st->top] = x;
}

int pop(Stack *st)
{
	if(isEmpty(st))
	exit(1);
	
	st->top--;
	return st->S[st->top+1];
}

int main(void)
{
	Stack st1;
	Stack st2_j;
	Stack st2_a;
	
	initialize(&st1);
	initialize(&st2_j);
	initialize(&st2_a);
	
	char c;
	int sum = 0;
	
	for(int i = 0; (c = getchar()) != EOF; i++)
	{
		if(c == '\\')
		{
			push(i,&st1);
		}
		else if(!isEmpty(&st1) && c == '/')
		{
			int j=pop(&st1);
			sum += i-j;
			int a = i - j;
			while(!isEmpty(&st2_j)&& st2_j.S[st2_j.top]>j)
			{
				pop(&st2_j);
				a+=pop(&st2_a);
			
			}
			push(j,&st2_j);
			push(a,&st2_a);
		}
	}
		
		printf("%d\n",sum);
		printf("%d",st2_a.top);
		
		for(int i = 1; i<=st2_a.top; i++)
		 printf(" %d",st2_a.S[i]);
			printf("\n");
			
		
		
		return 0;
	}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;
typedef struct{
  int n_q,bonus,point;
}T;

int main(void){
  int D,G;cin >> D >> G; 
  G/=100;
  vector<T> v(D);
  int i,j,k;REP(i,D){
    cin >> v[i].n_q >> v[i].bonus;
    v[i].bonus/=100;
    v[i].point = (i+1);
  }
  //dp[i][j]:i点付けられた問題までを見て合計がjとなる最小の問題数
  int dp[D+1][G+1];
  REP(i,D+1)REP(j,G+1)dp[i][j] = INF;
  REP(i,D+1)dp[i][0] = 0;

  REP(i,D)REP(j,G+1){
    int point = j;
    dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
    REP(k,v[i].n_q){
      point += v[i].point;
      if(k==v[i].n_q-1) point += v[i].bonus;
      point = min(point,G);
      dp[i+1][point] = min(dp[i+1][point],dp[i][j]+k+1);
      if(point==G) break;
    }
  }
  //int ans=INF;
  //REP(i,D+1) ans=min(ans,dp[i][G]);
  //cout << ans << endl;
  cout << dp[D][G] << endl;
  
  return 0;
}


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

using namespace std;

using ll = long long;

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

    map<int, int> memo;
    int n, a;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        ++memo[a];
    }

    ll l1 = -1, l2 = -1;
    for (const auto &it : memo) {
        if (2 <= it.second) {
            if (l2 == -1 || l2 < it.first) l2 = it.first;
            if (l1 < l2) swap(l1, l2);
        }
        if (4 <= it.second) {
            if (l2 == -1 || l2 < it.first) l2 = it.first;
            if (l1 < l2) swap(l1, l2);
        }
    }

    if (l2 == -1) cout << "0\n";
    else cout << l1 * l2 << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main() {
	
	int ans = 0;
	string s;
	cin>>s;
	
	for(int i = 0; i < s.size(); i++)
	{
		int j = i;
		while(s[i] == 'A' or s[i] == 'G' or s[i] == 'T' or s[i] == 'C')
		{
			i++;
		}
		ans = max(ans, i-j);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s;
    cin >> s;
    set<int> st;
    st.insert(s);
    int now = s;
    int m=1;
    while(1){
        int next;
        if(now%2==0){
            next = now/2;
        }else{
            next = 3*now+1;
        }
        m++;
        if(st.find(next)==st.end()){
            st.insert(next);
        }else{
            cout << m << endl;
            return 0;
        }
        now = next;
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())

    l = [[None, None] for i in range(m)]
    for i in range(m):
        a, b = map(int, input().split())
        l[i][0] = a
        l[i][1] = b

    ans = [0] * n
    for i in l:
        ans[i[0] - 1] += 1
        ans[i[1] - 1] += 1

    for i in ans:
        print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n,k = list(map(int,input().split()))
d_ = []
a_ = []
for i in range(k):
    d_.append(int(input()))
    a_.append(list(map(int,input().split())))

sum = []
for i in range(n):
    sum.append(i+1)

res = []
for l in range(k):
    for k in range(d_[l]):
        if( a_[l][k] in res):
            continue
        else:
            res.append(a_[l][k])

resList = set(sum) ^ set(res)
print(len(resList))


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

ll gcd(ll a,ll b){
    if(a>b)swap(a,b);
    if(a==0)return b;
    return gcd(b%a,a);
}


int main(){fastio
    ll a,b;cin>>a>>b;
    ll g=gcd(a,b);
    set<ll>s;
    for(ll i=1;i*i<=g;i++){
        if(g%i==0){
            s.insert(i);
        }
        if(i==1)continue;
        while(g%i==0){
            g=g/i;
        }
    }
    s.insert(g);
    cout<<s.size()<<endl;
    //for(auto ite=s.begin(),ite!=s.end())

    return 0;
}





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

int main(void){
    string str;
    cin >> str;
    long long ans=0;
    int n=str.length();
    int power[11]={1,1,2,4,8,16,32,64,128,256,512};
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(j+n-i>n)break;
           ans+=stoll(str.substr(j,n-i))*power[str.substr(0,j).length()]*power[str.substr(j+n-i).length()];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N = i2n()
    V = i2nn()
    C = i2nn()
    n = 0
    for v, c in zip(V, C):
        xy = v - c
        if xy > 0:
            n += xy
    print(n)

main()


Measured memory_bytes: 38384
a, b, k = list(map(int, input().split()))
ret = []

for i in range(a, a + k):
    if i <= b and ret.count(i) == 0:
        ret.append(i)

for i in range(b - k + 1, b + 1):
    if i >= a and ret.count(i) == 0:
        ret.append(i)

for i in ret:
    print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <queue>

using ll = long long;

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    queue<int> a[n];
    for (int i=0; i<n; i++) for (int j=0, aij; j<m; j++) {
        cin >> aij;
        a[i].push(aij - 1);
    }
    int cnt[m];
    vector<bool> used(m, false);
    int ans = n;
    for (int j=0; j<m; j++) {
        fill(cnt, cnt+m, 0);
        int best = -1;
        for (auto &ai:a) {
            while (used[ai.front()]) ai.pop();
            cnt[ai.front()]++;
            if (best < 0 || cnt[best] < cnt[ai.front()]) {
                best = ai.front();
            }
        }
        ans = min(ans, cnt[best]);
        used[best] = true;
    }
    cout << ans << '\n';
    return 0;
}

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

int dp[100010][3];
int a[100010];
int b[100010];
int c[100010];
int n;

int max3(int a, int b, int c) {
    int d = max(a, b);
    int e = max(b, c);
    return max(d, e);
}

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

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int j = 1; j < n; ++j) {
        dp[j][0] = max(dp[j-1][1], dp[j-1][2]) + a[j];
        dp[j][1] = max(dp[j-1][0], dp[j-1][2]) + b[j];
        dp[j][2] = max(dp[j-1][0], dp[j-1][1]) + c[j];
    }
    cout << max3(dp[n-1][0], dp[n-1][1], dp[n-1][2]) << endl;
}

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

int judge(int n){
    int sum = 0 , largest = 0;
    
    for(int i = 2 ; i <= n ; i++){
        if(n%i==0){
            sum += i;//2
            largest = i;
            while(n%i==0){
                n /= i;
            }
        }
    }
    sum -= largest;
    return largest-sum;
}

int main(){
    int a,b;
    
    while(cin >> a >> b ,a+b){
        bool flg;
        
        if(judge(a) > judge(b)) flg = true;
        else flg = false;
        
        if(flg) cout << 'a' << endl;
        else cout << 'b' << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
import java.util.*;


public class Main {
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int P = K;
		int i = 0;
		while(P <= N) {
			P = P*K;
			i++;
		}
		System.out.println(i+1);
	}
}

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

class Union_Find{
private:
  vector<int> par; vector<int> rank; vector<int> num;
public:
  Union_Find(int n); 
  int number(int x); int find(int x); void unite(int x, int y); bool same(int x, int y);
};

Union_Find::Union_Find(int n){
  par = vector<int>(n); rank = vector<int>(n); num = vector<int>(n);
  rep(i,n) par[i] = i, rank[i] = 0, num[i] = 1; 
}

int Union_Find::find(int x){
  if(par[x] == x) return x;
  else  return par[x] = find(par[x]);
}

int Union_Find::number(int x){
  return num[find(x)];
}

void Union_Find::unite(int x, int y){
  x = find(x); y = find(y);
  if (x == y) return;
  if (rank[x] < rank[y]) swap(x, y);
  if (rank[x] == rank[y]) rank[x]++;
  par[y] = x;
  num[x] += num[y];
}

bool Union_Find::same(int x, int y){
  return find(x) == find(y);
}

int main(){
  int n, m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) cin >> a[i];
  Union_Find uf(n);
  rep(i,m) {
    int x, y;
    cin >> x >> y;
    uf.unite(x,y);
  }
  vector<vector<ll>> v(n);
  rep(i,n) {
    v[uf.find(i)].push_back(a[i]);
  }
  priority_queue<P> p;
  rep(i,n) {
    if(v[i].size() > 0) p.push(P(v[i].size(),i));
  }
  vector<priority_queue<ll,vector<ll>,greater<ll>>> vec;
  while(!p.empty()) {
    P q = p.top();
    p.pop();
    priority_queue<ll,vector<ll>,greater<ll>> pq;
    for(auto k : v[q.second]) pq.push(k);
    vec.push_back(pq);
  }
  int l = vec.size();
  ll ans = 0;
  for(int i = 1; i < l; i++) {
    if(vec[0].empty()) {
      cout << "Impossible" << endl;
      return 0;
    }
    ll d = vec[0].top(); vec[0].pop();
    ll e = vec[i].top(); vec[i].pop();
    ans += d + e;
    while(!vec[i].empty()) {
      ll f = vec[i].top(); vec[i].pop();
      vec[0].push(f);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	string S;
	cin >> S;
	int ans = 700;
	for(int i = 0; i < 3; i++) {
		if (S[i] == 'o')
			ans += 100;
		else
			continue;
	}
	
	cout << ans << endl;
	return 0;
	
}


Measured memory_bytes: 256