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

using namespace std;

int main() {
    long long int K;
    cin >> K;
    
    vector<vector<long long int> > memo(10, vector<long long int>(11, 0));
    vector<long long int> s_memo(11, 0);
    for(int i=0; i<memo.size(); i++) {
        memo[i][1] = 1;
        if(i>0) {
            s_memo[1] += memo[i][1];
        }
    }
    for(int j=2; j<11; j++) {
        for(int i=0; i<10; i++) {
            int k=i-1>=0 ? i-1 : 0;
            int mxk=i+1<10 ? i+1: 9;
            for(; k<=mxk; k++) {
                memo[i][j] += memo[k][j-1];
            }
            if(i>0) {
                s_memo[j] += memo[i][j];
            }
        }
    }
    
    int idx=0;
    long long int sm;
    for(int i=1; i<11; i++) {
        s_memo[i] += s_memo[i-1];
        if(s_memo[i]>=K) {
            sm = s_memo[i];
            idx = i;
            break;
        }
    }
    
    string ans;
    for(int j=9; j>0; j--) {
        // cout << sm << ", " << memo[j][idx] << endl;
        if(sm-memo[j][idx]<K) {
            ans += (char)('0'+j);
            // cout << j;
            break;
        } else {
            sm -= memo[j][idx];
        }
    }

    for(int i=idx-1; i>0; i--) {
        int k=(int)(ans[ans.size()-1]-'0');
        // cout << k << endl;
        k = k+1<10 ? k+1 : 9;
        int mnk= k-2>=0 ? k-2 : 0;
        // cout << k << ", " << mnk << endl;
        for(; k>=mnk; k--) {
            // cout << sm << ", " << memo[k][i] << endl;
            if(sm-memo[k][i]<K) {
                ans += (char)('0'+k);
                break;
            } else {
                sm -= memo[k][i];
            }
        }
    }
    // cout << endl;
    
    cout << ans << endl;

    
    return 0;
    
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class C {
    static void Main(string[] args) {
        int N = int.Parse(Console.ReadLine());
        var P = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        //初めからi項目までの最小値を格納する配列
        var min = new int[N];

        min[0] = P[0];

        int ans = 1;

        for (int i = 0; i < N - 1; i++) {
            if (Math.Min(min[i], P[i + 1]) == P[i + 1]) {
                ans++;
                min[i + 1] = P[i + 1];
            } else {
                min[i + 1] = min[i];
            }

        }
        //Console.WriteLine(string.Join(" ", min));
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 36556
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL x,y;
    cin >> x >> y;
    cout << x+(y/2) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
const int MAX = 1000000;
long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// 間隔Gを指定した挿入ソート
void insertionSort(int A[], int n, int g){
    for(int i = g; i < n; i++){
        int v = A[i];
        int j = i - g;
        while( j >= 0 && A[j] > v){
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n){
    // 数列G = {1, 4, 13, 40, 121, 364, 1093, ...}を生成
    for (int h = 1; ; ){
        if(h > n) break;
        G.push_back(h);
        h = 3 * h + 1;
    }

    for(int i = G.size() -  1; i >= 0; i--){ // 逆順にG[i] = gを指定
        insertionSort(A, n, G[i]);
    }
}

int main(){
    cin >> n;
    // より早い入力scanf関数を使用
    for(int i = 0; i < n; i++) scanf("%d", &A[i]);
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for ( int i = G.size() - 1; i >= 0; i--){
        printf("%d", G[i]);
        if( i ) printf(" ");
    }
    printf("\n");
    printf("%lld\n", cnt);
    for(int i = 0; i < n; i++) printf("%d\n", A[i]);

	return 0;
}


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;
const int maxN = 1e4 + 1;

int fact[maxN], rev[maxN];

int mod_pow(int a, int b) {
	if (!b) return 1;
	if (b % 2) return a * mod_pow(a, b - 1) % MOD;
	int q = mod_pow(a, b / 2);
	return q * q % MOD;
}

int C(int n, int k) {
	if (k > n) return 0;
	return (fact[n] * rev[k] % MOD) * rev[n - k] % MOD;
}

void solve() {
	fact[0] = 1;
	for (int i = 1; i < maxN; i++) fact[i] = fact[i - 1] * i  % MOD;
	for (int i = 0; i < maxN; i++) rev[i] = mod_pow(fact[i], MOD - 2);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; i++) {
		int res = C(k - 1, i - 1);
		int q = 0;
		if(i > 1) q = (q + res * C(n - k - 1, i - 2) % MOD) % MOD;
		q = (q + res * C(n - k - 1, i - 1) * 2 % MOD) % MOD;
		q = (q + res * C(n - k - 1, i) % MOD) % MOD;
		if (i == 1 && n == k) q++;
		cout << q << '\n';
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
  int n,p[200001],m[200001],ans=0;
  cin>>n;
  for(int i=1;i<n+1;i++){
    cin>>p[i];
    if(i>1)m[i]=min(p[i],m[i-1]);
    else m[1]=p[1];
    if(p[i]==m[i])ans++;
  }
  cout<<ans<<endl;
  return 0;
} 

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

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

    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        if(s[i] != s[i + 1]) ans++;
    }
    ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    string s;
    cin >> s;
    ll sum = 0;
    int n = s.size();
    rep(i, n) {
        sum += s[i] - '0';
    }
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int n, k;
ll bit[111111];
ll a;

ll sum(int i)
{
  ll s = 0LL;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, ll d)
{
  while(i <= n){
    bit[i] += d;
    i += i & -i;
  }
}

int main()
{
  while(cin >> n >> k, n){
    rep(i, 111111) bit[i] = 0LL;

    rep(i, n){
      cin >> a;
      add(i + 1, a);
    }

    ll res = sum(k);
    erep(i, k + 1, n) maxup(res, sum(i) - sum(i - k));
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 2028
#include<bits/extc++.h>
#ifndef __unix__
#define fread_unlocked fread
#endif
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define pb emplace_back
#define rep(_n) for(int __i = _n;__i--;)
#define rep0(_i, _n) for(int _i = 0; (_i)<(_n) ;++_i)
#define rep1(_i, _n) for(int _i = 1; (_i)<=(_n) ;++_i)
#define yn(i) ((i)?"Yes" : "No")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define multi int _T;for(read(_T);_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
inline char readchar(){static const unsigned bufsize = 1 << 16; static unsigned p = 0, end = 0; static char buf[bufsize]; if (p == end) end = fread_unlocked(buf, sizeof(char), bufsize, stdin), p = 0; return p == end ? EOF : buf[p++]; }
inline void read(char &a){while(isspace(a = readchar()));}
inline void read(char *a){while(isspace(*a = readchar()));++a; while(isgraph(*a = readchar()))++a;}
inline void read(string &a){static char p; while(isspace(p = readchar())); a = p; while(isgraph(p = readchar()))a.push_back(p);}
template<typename T> inline void read(T& a){static char p; static bool b;while (!isdigit(p = readchar()))b = p == '-'; a = p ^ '0'; while (isdigit(p = readchar())) a *= 10, a += p ^ '0'; if(b)a *= -1, b = false; }
template<typename T1, typename T2> inline void read(pair<T1, T2> &a){read(a.first), read(a.second);}
template<typename T> inline void read(T begin, const T &end){while(begin != end)read(*begin), ++begin;}
inline void R(){} template<class T1, class... T2> inline void R(T1 &h, T2 &... e){read(h), R(e...);}
template<typename T> inline void write(T begin, const T &end){while(begin != end)cout << *begin << " \n"[next(begin) == end], ++begin;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 300010;
bool ex[4][maxn];
int n;
char d[maxn];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	R(n);
	read(d, d+n);
	rep0(i, n){
		for(int j = 2;j >= 1;--j){
			for(int v = 0;v <= 99;++v)if(ex[j][v])ex[j+1][v*10 + d[i]-'0'] = true;
		}
		ex[1][d[i]-'0'] = true;
	}
	int cnt = 0;
	rep0(i, 1000)cnt += ex[3][i];
	rout(cnt);
}


Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      cs: [chars; 3],
    }
    let mut ans = vec![];
    for i in 0..3 {
        ans.push(cs[i][i]);
    }
    println!("{}", ans.into_iter().collect::<String>());
}


Measured memory_bytes: 4352
S = input()
f = int(S[:2])
l = int(S[2:])
if f==0 or f>12:
  if l==0 or l>12:
    print("NA")
  else:
    print("YYMM")
else:
  if l==0 or l>12:
    print("MMYY")
  else:
    print("AMBIGUOUS")

Measured memory_bytes: 9100
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        if(n % 500 > a){
            System.out.println("No");
        }
        else System.out.println("Yes");
    }
}

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

#define int long long int
int n, capc;
int dp[102][100005];

int fill_knapsack(int i, int w, int val[], int wt[]){
    if(i < 0)
        return 0;
    if(dp[i][w] != -1)
        return dp[i][w];
    
    if(wt[i] > w) {
        dp[i][w] = fill_knapsack(i-1, w, val, wt);
    } else {
        dp[i][w] = max(val[i]+fill_knapsack(i-1, w-wt[i], val, wt),
                        fill_knapsack(i-1, w, val, wt));
    }
    return dp[i][w];
}

void solve() {
    cin >> n >> capc;
    int val[n];
    int wt[n];

    for(int i=0; i<n; i++)
        cin >> wt[i] >> val[i];

    memset(dp, -1, sizeof(dp));
    cout << fill_knapsack(n-1, capc, val, wt) << endl;
}

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

    solve();
}

Measured memory_bytes: 80000
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N,A,B,C,D,E;cin>>N>>A>>B>>C>>D>>E;
  int a=min({A,B,C,D,E});
  int k=0;
  if(a== A)k=1;
  if(a== B)k=2;
  if(a== C)k=3;
  if(a== D)k=4;
  if(a== E)k=5;
  cout<<(N-1)/a+1+4<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
ll n,m,ans;
ll f(ll x)
{
    ll i,res=1;
    for(i=1;i<=x;i++)
        res=(res*i)%mod;
    return res%mod;
}
int main()
{
    ll i,j,k;
    scanf("%lld%lld",&n,&m);
    if(abs(n-m)>1)
        printf("0\n");
    else
    {
        if(abs(n-m)==0)
            ans=(f(n)*f(m)*2)%mod;
        else
            ans=(f(n)*f(m))%mod;
        printf("%lld\n",ans);
    }
    return 0;
}


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

int main(){
  
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int beg = a.at(0);
  reverse(a.begin(), a.end());
  int end = a.at(0);
  int ans = end - beg;
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 42
using namespace std;
typedef long long int ll;

char mp[SIZE][SIZE];
bool ok[SIZE][SIZE];
ll dp[SIZE][SIZE][SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	n*=2;
	for(int i=0;i<n;i++)
	{
		scanf("%s",&mp[i]);
		for(int j=0;j<n;j++) ok[i][j]=(mp[i][j]=='1');
		//for(int j=0;j<n;j++) ok[i][j]=true;
		//ok[i][i]=false;
	}
	for(int L=1;L<=n;L+=2)
	{
		for(int s=0;s+L<=n;s++)
		{
			int t=s+L-1;
			if(L==1)
			{
				dp[s][s][s]=1;
				continue;
			}
			for(int p=s+1;p<t;p++)
			{
				for(int l=s;l<p;l++)
				{
					for(int r=p+1;r<=t;r++)
					{
						if(!ok[l][r]) continue;
						for(int y=p+1;y<=r;y++)
						{
							for(int x=l;x<p;x++)
							{
								dp[s][p][t]+=dp[s][l][x]*dp[x+1][p][y-1]*dp[y][r][t];
							}
						}
					}
				}
			}
		}
	}
	ll ret=0;
	for(int i=1;i<n;i++)
	{
		if(!ok[0][i]) continue;
		ret+=dp[1][i][n-1];
	}
	printf("%lld\n",ret);
}

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if (b <= a) {
        cout << "delicious" << endl;
    } else if (b <= a + x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from itertools import permutations

n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

order = list(permutations(list(range(1,n+1))))
turn_p = order.index(p)
turn_q = order.index(q)

print(abs(turn_p-turn_q))

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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    long long int N,x,i,tmp=0,ans=0;
    cin >> N >> x;
    long long int a[N+1];
    a[0] = 0;
    for(i = 1; i < N+1; i++) {
        cin >> a[i];
    }

    for(i = 0; i < N; i++) {
        tmp = a[i] + a[i+1];
        if(tmp > x) {
            a[i+1] -= tmp-x;
            ans += tmp-x;
        }
    }

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


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n) 
	{
		int sum[n];
		fill(sum,sum+n,0);
		int ans=0;
		sum[0]=0;
		for(int i = 1; i < n; ++i)
		{
			sum[i]=sum[i-1]+i;
			for(int j = 0; j < i; ++j)
			{
				if(sum[i]-sum[j]==n) ans++;
			}
		}
		cout<<ans<<endl;
	}
  return 0;
}

Measured memory_bytes: 1160
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()

memo = [-1 for _ in range(N+1)]

def rec(n):
    if n == 0: return 0
    if memo[n] != -1: return memo[n]
    res = n
    pow6 = 1
    while pow6 <= n: 
        res = min(res, rec(n-pow6)+1)
        pow6 *= 6
    pow9 = 1
    while pow9 <= n: 
        res = min(res, rec(n-pow9)+1)
        pow9 *= 9
    memo[n] = res
    return memo[n]
print(rec(N))

Measured memory_bytes: 91888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,p=0;
    cin>>n;
    for(int j=1;j<n;j++)
    {
    for(int i=1;i<n;i++)
    {
        if((i*j)>=n)
        break;
    p++;
    }
    }
    cout<<p<<endl;
    return 0;
}

Measured memory_bytes: 3628
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input!{
    s: chars,
    t: chars
  }
  let mut dp = vec![vec![0; t.len() + 1]; s.len() + 1];
  for (si, sc) in s.iter().enumerate() {
    for (ti, tc) in t.iter().enumerate() {
      dp[si + 1][ti + 1] = cmp::max(
        dp[si][ti] + if sc == tc {1} else {0},
        cmp::max(dp[si + 1][ti], dp[si][ti + 1])
      );
    }
  }
  let mut lcs = Vec::new();
  let (mut si, mut ti) = (s.len(), t.len());
  while (si, ti) != (0, 0) {
    let cur = dp[si][ti];
    if si >= 1 && ti >= 1 && s[si - 1] == t[ti - 1] {
      let prev = dp[si - 1][ti - 1];
      if prev + 1 == cur {
        lcs.push(s[si - 1]);
        si -= 1;
        ti -= 1;
        continue;
      } else if prev == cur {
        si -= 1;
        ti -= 1;
        continue;
      }
    }
    if si >= 1 && dp[si - 1][ti] == cur {
      si -= 1;
      continue;
    }
    if ti >= 1 && dp[si][ti - 1] == cur {
      ti -= 1;
      continue;
    }
  }
  let lcs: String = lcs.iter().rev().map(|&c| c).collect();
  println!("{}", lcs);
}


Measured memory_bytes: 41212
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */


int main() {
  string s; cin >> s;
  s[3] = '8';
  cout << s << endl;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=2e5+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,q[N],t[N],f[N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) q[gi()]=i;
    for(int i=n-1;i;i--) {
        if(!t[i+1]) {
            if(q[i]>q[i+1]) t[i]=1,f[i]=i+1;
        }
        else {
            if((q[f[i+1]]<q[i])+(q[i]<q[i+1])+(q[i+1]<q[f[i+1]])==2) t[i]=t[i+1],f[i]=f[i+1];
            else t[i]=t[i+1]+1,f[i]=i+1;
        }
    }
    printf("%d\n",t[1]);
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
 
int main()
{
    int H, W, i, j; 
    while (1) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;
        for (i = 0; i < H; i++) {
            for (j = 0; j < W; j++) printf("#");
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1972
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re
s = input()
t = []
for ch in s:
    if ch == 'C' or ch == 'F':
        t.append(ch)
t = "".join(t)
if "CF" in t:
    print("Yes")
else:
    print("No")



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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)


#define LL long long
#define mp make_pair
#define pb push_back
LL max(LL a, LL b) { return (a > b ? a : b); }

#define K 600001

int n, k;
LL a[K], s[K];
LL b[K];

int main() {
	scanf("%d%d", &n, &k);
	FOE(i, 1, n) scanf("%lld", &a[i]);
	FOE(i, 1, n) s[i] = s[i - 1] + a[i];
	FOE(i, 1, n) b[i] = b[i - 1] + max(0, a[i]);
	
	LL ret = s[n];
	
	FOE(i, 1, n - k + 1) {
		LL s1 = s[i + k - 1] - s[i - 1];
		LL s2 = b[i - 1];
		LL s3 = b[n] - b[i + k - 1];
		
	//	printf("dafuq %lld %lld %lld\n", s1, s2, s3);
		
		ret = max(ret, max(s1, 0) + s2 + s3);
	}
	
	printf("%lld\n", ret);
}

Measured memory_bytes: 6188
//no one wants to die,yet death is the destination we all share 
// don't think you are,know you are!!

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

string s[1002];
ll dp[1002][1002];
ll dx[5]={-2,-1,0,1,2};
ll dy[5]={-2,-1,0,1,2};

int main(){
	ll h,w,c1,d1,c2,d2;
	cin>>h>>w>>c1>>d1>>c2>>d2;
	forn(i,h) cin>>s[i];
	c1--,d1--,c2--,d2--;

	forn(i,h) forn(j,w) dp[i][j]=INT_MAX;

	priority_queue <pair<ll,pair<ll,ll>>> q;
	q.push(mp((ll)0,mp(c1,d1)));

	while(!q.empty()){
		ll dis=-(q.top().fi);
		ll x=q.top().se.fi;
		ll y=q.top().se.se;
		q.pop();
		forn(i,5){
			forn(j,5){
				ll cx=x+dx[i];  //current x
				ll cy=y+ dy[j]; // current y
				if((cx<0)||(cy<0)||(cx>=h)||(cy>=w)||(s[cx][cy]=='#')) continue;
				if(((abs(dx[i])==1)&&(abs(dy[j])==0))||((abs(dy[j])==1)&&(abs(dx[i])==0))){
					if(dp[cx][cy]>dis){
						dp[cx][cy]=dis;
						q.push(mp(-dis,mp(cx,cy)));
					}
				}
				else{
					if(dp[cx][cy]>dis+1){
						dp[cx][cy]=dis+1;
						q.push(mp(-dis-1,mp(cx,cy)));
					}
				}
			}
		}
	}
	if(dp[c2][d2]==INT_MAX) cout<<"-1";
	else cout<<dp[c2][d2];
}

Measured memory_bytes: 13496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC173_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int mod = N % 1000;
            if (mod == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1000 - mod);
            }
        }
    }
}


Measured memory_bytes: 27384
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int 

//-4%3=-1
int n,m,a,b;
vector <int> edge[100001];
int dp[100001]={0},vis[100001]={0};

/*int dfs(int i)
{
    if(v[i].size()==0)
    return 1;
    for(int j=0;j<v[i].size();j++)
    {
        if(dp[v[i][j]]==-1)
        dp[i]+=1+dfs(v[i][j]);
        else
        dp[i]+=dp[v[i][j]];
    }
}*/

int dfs(int v)
 {
    vis[v]=1;
    for(int i=0;i<edge[v].size();i++)
    {
        if(!vis[edge[v][i]])
        dfs(edge[v][i]);
        dp[v]=max(dp[v],1+dp[edge[v][i]]);
    }
 }
int main() {
	// your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        dp[i]=0;
        while(m--)
        {
            cin>>a>>b;
            edge[a].push_back(b);
        }
        for(int i=1;i<=n;i++)
        if(!vis[i])
        dfs(i);
        cout<<*max_element(dp,dp+1+n);
        //for(int i=1;i<=n;i++)
        //cout<<dp[i]<<" ";
    }
}

Measured memory_bytes: 8576
var GET = (function(){
  function f(s){return new g(s);}
  function g(s){this._s=s.trim().split("\n");this._y=0;}
  g.prototype.a = function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y]=s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  }
  g.prototype.l = function(f){
    var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);
  }
  g.prototype.m = function(n,f){
    var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));
    return f?r:r.map(a=>a.map(a=>+a));
  }
  g.prototype.r = function(n,f){
    var r = this._s.slice(this._y,this._y+=n);
    return f?r:r.map(a=>+a);
  }
  return f;
})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var x = o.a();
  return x===3?"YES":x===5?"YES":x===7?"YES":"NO";
}

Measured memory_bytes: 7372
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

typedef struct naiveVector{
  void *array;
  size_t size;
  int maxLen;
  int len;
} vector;

void push_back(vector *vec,const void *v){
  if(vec->len==vec->maxLen){
    vec->maxLen=vec->maxLen*2+1;
    vec->array=realloc(vec->array,vec->size*vec->maxLen);
  }
  memcpy((char *)vec->array+vec->size*vec->len,v,vec->size);
  vec->len++;
  return;
}

void* getAtRef(const vector *vec,const size_t index){
  return (char *)vec->array+vec->size*index;
}

void getAt(const vector *vec,const size_t index,void *res){
  memcpy(res,getAtRef(vec,index),vec->size);
}

void run(void){
  int n;
  scanf("%d",&n);
  vector *next=(vector *)calloc(n+1,sizeof(vector));
  int i,j;
  for(i=1;i<=n;i++) next[i]=(vector){NULL,sizeof(int),0,0};
  for(i=0;i<n-1;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    push_back(next+a,&b);
    push_back(next+b,&a);
  }
  int *index=(int *)calloc(n,sizeof(int));
  int *parent=(int *)calloc(n+1,sizeof(int));
  int len=0;
  index[len++]=1;
  parent[1]=n+1;
  for(i=0;len<n;i++){
    int k=index[i];
    for(j=0;j<next[k].len;j++){
      int u;
      getAt(next+k,j,&u);
      if(parent[u]) continue;
      parent[u]=k;
      index[len++]=u;
    }
  }
  int *min=(int *)calloc(n+1,sizeof(int));
  int *max=(int *)calloc(n+1,sizeof(int));
  int *cond=(int *)calloc(n+1,sizeof(int));
  const int inf=10000000;
  for(i=1;i<=n;i++){
    min[i]=-inf;
    max[i]=inf;
    cond[i]=3;
  }
  int k;
  scanf("%d",&k);
  while(k--){
    int v,p;
    scanf("%d%d",&v,&p);
    min[v]=max[v]=p;
    cond[v]&=1<<(p&1);
  }
  for(i=n-1;i>0;i--){
    int k=index[i];
    int u=parent[k];
    min[u]=MAX(min[u],min[k]-1);
    max[u]=MIN(max[u],max[k]+1);
    cond[u]&=((cond[k]&1)<<1)|((cond[k]&2)>>1);
  }
  if(cond[1]==0){
    printf("No\n");
    return;
  }
  for(i=0;i<n;i++){
    int k=index[i];
    for(j=0;j<next[k].len;j++){
      int u;
      getAt(next+k,j,&u);
      if(parent[u]!=k) continue;
      min[u]=MAX(min[u],min[k]-1);
      max[u]=MIN(max[u],max[k]+1);
    }
  }
  for(i=1;i<=n;i++){
    if(max[i]<min[i]){
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
  for(i=1;i<=n;i++){
    printf("%d\n",min[i]);
  }
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 8832
S = list(input())
N = len(S)
ans1, ans2 = 0, 0

for i in range(N):
    if i % 2 == 0:
        if S[i] == '0':
            ans1 += 1
    else:
        if S[i] == '1':
            ans1 += 1
for i in range(N):
    if i % 2 == 1:
        if S[i] == '0':
            ans2 += 1
    else:
        if S[i] == '1':
            ans2 += 1

print(min(ans1, ans2))


Measured memory_bytes: 3956
def isPrime(num):
    if num < 2: return False
    if num == 2: return True
    if num % 2 == 0: return False
    sqrtnum = num ** 0.5
    for i in range(3, int(sqrtnum + 1), 2):
        if num % i == 0:
            return False
    return True


def prime_number():
    n = int(input())
    count = 0
    for _ in range(n):
        a = int(input())
        if isPrime(a):
            count += 1
    print(count)

if __name__ == "__main__":
    prime_number()

Measured memory_bytes: 7632
//Coffee
#include <iostream>
#include <string>
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
fun main(args: Array<String>) = yorukatsu19b()

fun yorukatsu19b() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    data class Shop(val price: Long, val stock: Int)

    val shops = (1..n).map {
        readLine()!!.split(' ').map { it.toInt() }.let { Shop(it[0].toLong(), it[1]) }
    }.sortedBy { it.price }

    var need = m
    var answer = 0L

    for ((price, stock) in shops) {
        if (need <= stock) {
            answer += price * need
            break
        } else {
            answer += price * stock
            need -= stock
        }
    }

    println(answer)
}


Measured memory_bytes: 69836
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

tlist = [a,b,c,d,e]

worst = (0,999)
for i in range(5):
	if 0 < (tlist[i] % 10) < worst[1]:
		worst = (i,tlist[i]%10)
#	print (worst)

ans = 0
def kiriage(n):
	if n % 10 != 0 :
		return n + 10 - n%10
	else:
		return n

for j in range(5):
#	print (ans)
	if j != worst[0]:
		ans += kiriage(tlist[j])
	else:
		ans += tlist[j]

print (ans)


Measured memory_bytes: 3064
N=int(input())

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

    # divisors.sort()
    return divisors

divisors=make_divisors(N)

ans=N
for i in range(len(divisors)):
    ans=min(ans,divisors[i]+N//divisors[i]-2)
print(ans)


Measured memory_bytes: 3272
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define vi(v)   vector < int > v;
#define all(v)  v.begin(), v.end()

using namespace std;
int main()
{
   int x,y,z;
   cin>>x>>y>>z;
   swap(x, y);
   swap(x, z);
   cout<<x<<" "<<y<<" "<<z;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main ()
{
int a, b;cin >> a >> b;
int res = max({2 * a - 1, 2 * b - 1, a + b});
cout << res << endl;
    return 0;
}
// ans = 1 + 1 + - 1 + 

Measured memory_bytes: 256
N,K= map(int,input().split())
H = list(map(int,input().split()))

def calc_steps(fromi,toi):
    return abs(H[toi] - H[fromi])


costs = [0 for _ in range(N)]
# N < Kのとき
if N <= K:
    K = N-1
# 最初のK段のコスト
# costs[0] = calc_steps(0,1)
for toi in range(1,K+1):
    onestep = calc_steps(0, toi)
    nsteps = [costs[fromi] + calc_steps(toi,fromi) for fromi in range(1,toi)]
    costs[toi] = min([onestep] + nsteps)

#### この辺のバグから
for lasti in range(K,N):
    cost = 10**9
    for fromi in range(1,K+1):
        nsteps = costs[lasti - fromi] + calc_steps(lasti, lasti - fromi)
        cost = min(cost, nsteps)
    costs[lasti] = cost
    # print(costs)
print(costs[-1])


Measured memory_bytes: 56544
import math

def prime_factorize(n):
    ret = []
    # 小さい素数から順に試し割りしていく
    for i in range(2, int(math.sqrt(n))+1):
        if n % i != 0:
            continue
        e = 0
        while n % i == 0:
            e += 1
            n //= i
        ret += [(i, e)]

    if n != 1:
        ret += [(n, 1)]

    return ret


def extgcd(a, b):
    x,y, u,v = 0,1, 1,0
    while a != 0:
        q, r = b//a, b%a
        m, n = x-u*q, y-v*q
        b,a, x,y, u,v = a,r, u,v, m,n
        g = b
    return x, y, g


def modinv(a, m):
    x, y, g = extgcd(a, m)
    if g != 1:
        print ("[+]Inverse does not exist.")
    else:
        return ((m + x) % m) % m


def calc_comb(n, k, mod):
    if k > n-k:
        return calc_comb(n, n-k, mod)

    ans_mul, ans_div = 1, 1

    for i in range(k):
        ans_mul *= (n-i)
        ans_div *= (i+1)
        ans_mul %= mod
        ans_div %= mod

    return (ans_mul * modinv(ans_div, mod) % mod)


def main():
    N, M = map(int, input().split())
    v = prime_factorize(M)
    MOD = int(10**9+7)
    ans = 1

    for i in v:
        ans *= calc_comb(N+i[1]-1, i[1], MOD)
        ans %= MOD
    print (ans)

main()


Measured memory_bytes: 3188
unittest
{
	assert( [ "2 2" ].parse.expand.solve == 6 );
	assert( [ "5 15" ].parse.expand.solve == 1 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ks = input.front.split.to!( long[] );
	return tuple( ks[ 0 ], ks[ 1 ] );
}

auto solve( long k, long s )
{
	auto ans = 0L;
	
	for( auto x = 0L; x <= k && x <= s; x++ )
	{
		for( auto y = 0L; y <= k && x + y <= s; y++ )
		{
			auto z = s - ( x + y );
			ans += ( z <= k );
		}
	}
	
	return ans;
}


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

int main(){
  int n;
  cin>>n;
  int x=pow(2,n);
  ll vec[x];
  ll slime[x]={};
  for(int i=0;i<x;i++){
    cin>>vec[i];
  }
  sort(vec,vec+x);
  slime[0]=vec[x-1];
  vec[x-1]=0;
  reverse(vec,vec+x-1);
  for(int i=0;i<n;i++){
    int y=pow(2,i);
    int a=0;
    for(int j=0;j<pow(2,i);j++){
      while(slime[j]<=vec[a]){
        a++;
        if(a>=x){
          cout<<"No"<<endl;
          return 0;
        }
        if(vec[a]==0){
          cout<<"No"<<endl;
          return 0;
        }
      }
      slime[y+j]=vec[a];
      vec[a]=0;
      a++;
    }
    sort(slime,slime+x);
    reverse(slime,slime+x);
    sort(vec,vec+x);
    reverse(vec,vec+x);
  }
  if(vec[0]>0){
    cout<<"No"<<endl;
    return 0;
  }
  if(slime[x-1]==0){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 8084
a = input()
b = input()
c = input()
dic = {"a": a, "b": b, "c":c}

next_player = "a"
while True:
  player = next_player
  if dic[player] == "":
    break
  else:
    next_player = dic[player][0]
    dic[player] = dic[player][1:]

print(player.upper())

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

int main(){
    int m,n;
    while(cin>>m,m){
        set<pair<int,int> >s2;
        vector<pair<int,int> >v1;
        vector<pair<int,int> >v2;
        for(int i=0;i<m;i++){
            int a,b;
            cin>>a>>b;
            v1.push_back(make_pair(a, b));
        }
        cin>>n;
        for(int i=0;i<n;i++){
            int a,b;
            cin>>a>>b;
            s2.insert(make_pair(a, b));
            v2.push_back(make_pair(a, b));
        }
        for(int i=0;i<n;i++){
            int dx=v2[i].first-v1[0].first;
            int dy=v2[i].second-v1[0].second;
            int found=true;
            for(int j=1;j<m;j++){
                int tx=v1[j].first+dx;
                int ty=v1[j].second+dy;
                if(!s2.count(make_pair(tx,ty))){
                    found=false;
                    break;
                }
            }
            if(found){
                cout<<dx<<" "<<dy<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1260
###
### atcorder test program
###

### math class
class math:
    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

### input num
i = input()
A, B, C = [int(x) for x in i.split()]
#N = int(input())
#A = [int(x) for x in input().split()]

count = 0
for i in range(A,B+1):
    if C%i == 0 :
        count+=1

print(count)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e6 + 5, MOD = 1e9 + 7;
ll dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, d, h;
    cin >> n >> h >> d;

    ll fac_sum = 0, fac = 1;

    for (int i = 1; i <= n; i++) {
        fac = fac * i % MOD;
        fac_sum = (fac_sum + fac) % MOD;
    }

    dp[1] = fac;

    for (int i = 2; i <= h; i++) {
        dp[i] = (dp[i - 1] - dp[max(0, i - d - 1)] + MOD) * fac_sum % MOD;
        dp[i] = (dp[i] + dp[i - 1]) % MOD;
    }

    ll ans = (dp[h] - dp[h - d] + MOD) % MOD;

    cout << ans << "\n";

    return 0;
}

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

struct food
{
	int w;
	int s;
	string name;

	bool operator < (const food& right) const {
		return w >= right.w;
	}
};

int n;
food fd[10];
string f;
int tw, ts;
bool used[10];

signed main()
{
	while (true)
	{
		cin >> n;
		if (n == 0) break;
 		rep(i,n)
		{
			cin >> f >> tw >> ts;
			fd[i].name = f;
			fd[i].w = tw;
			fd[i].s = ts;
		}

		sort(fd, fd + n);
		int wsum = 0;
		rep(i,n) wsum += fd[i].w;

		rep(i,n) used[i] = false;
		rep(i,n)
		{
			rep(j,n)
			{
				if (!used[j] && fd[j].s >= wsum - fd[j].w)
				{
					//printf("%s\n", fd[j].name);
					cout << fd[j].name << endl;
					wsum -= fd[j].w;
					used[j] = true;
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 1204
#include <iostream>
using namespace std;
#define ll long long

ll n, p;

int ck(ll r)
{
	ll tn = n, s = 1;
	while (tn)
	{
		if (tn % 2LL) s *= r;
		if (s > p) return false;
		if (tn > 1 && (r > 1000000LL || r * r > p)) return 0;
		r = r * r; tn /= 2;
	}
	if (p % s == 0) return 2;
	return 1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> p;
	if (n == 1) {
		cout << p << '\n';
		return 0;
	}
	ll rc = -1, c = 1;
	while (true) {
		int t = ck(c);
		if (t == 0) break;
		if (t == 2) rc = c;
		c++;
	}
	cout << rc << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int i=0,j=0,h=0,k=0,cnt=0;
			for(i=0;i<10;i++){
				//System.out.println("A"+i+" "+j+" "+k+" "+h);
				if(n==(i+j+k+h)&&j!=0&&k!=10&&h!=10){
					//System.out.println("A"+i+" "+j+" "+k+" "+h);
					cnt++;
				}
				for(j=0;j<10;j++){
					//System.out.println("B"+i+" "+j+" "+k+" "+h);
					if(n==(i+j+k+h)&&k!=10&&h!=10){	
						//System.out.println("A"+i+" "+j+" "+k+" "+h);
						cnt++;
					}
					//System.out.println("A"+i+" "+j+" "+k+" "+h);
					for(k=0;k<10;k++){
						//System.out.println("C"+i+" "+j+" "+k+" "+h);
						if(n==(i+j+k+h)&&h!=10){
							//System.out.println("A"+i+" "+j+" "+k+" "+h);
							cnt++;
						}
						for(h=0;h<10;h++){
							//System.out.println("D"+i+" "+j+" "+k+" "+h);
							if(n==(i+j+k+h)){
								//System.out.println("A"+i+" "+j+" "+k+" "+h);
								cnt++;
							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 17132
using System;
using System.Collections.Generic;
using System.Linq;

class Magatro
{
    static string S = Console.ReadLine();
    static void Main()
    {
        int cnt = 1;
        char stone=S[0];
        int l = S.Length;
        for(int i = 1; i < l; i++)
        {
            if (S[i] != stone)
            {
                stone = S[i];
                cnt++;
            }
        }
        Console.WriteLine(cnt - 1);
    }
}

Measured memory_bytes: 3160
program sample
    implicit none

    integer(8):: N, i, j, k, l,z
    integer(8), allocatable::A(:)
    read(*,*) N
    allocate(A(N))
    read(*,*) A
    k = 1

    do i = 1, N
        z = mod(A(i),2)
        if(z == 1) then
            l = 1
        else
            l = 2
        end if
        k = k*l
    end do

    write(*,*) 3**N - k
    deallocate(A)

    stop
end program sample

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
	int h, w, n;
	map<int, set<int>> ma;
	cin >> h >> w >> n;
	rep(i, 0, n){
		int x, y;
		cin >> x >> y;
		ma[x].insert(y);
	}

	int res = h;
	int left = 1, right = 1;
	rep(x, 2, h+1){
		if(!ma.count(x)) right = min(right+1, w);
		else{
			int first = *ma[x].begin();
			if(left <= first and first <= right){
				chmin(res, x-1);
				break;
			}
			if(first != right+1) right = min(right+1, w);
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 28416