akhauriyash/Code-Regression huggingface dataset:
n = int(input())
h = list(map(int, input().split()))

f = [0] * n
ans = 0

while h != f:
    flag = 0
    for i in range(n):
        if i == n - 1:
            if f[i] < h[i]:
                f[i] += 1
                ans += 1
            elif f[i] == h[i] and flag == 0:
                ans += 1
        elif i == 0:
            if f[i] < h[i]:
                f[i] += 1
                flag = 0
            elif f[i] == h[i]:
                flag = 1
        elif i != n - 1:
            if f[i] < h[i]:
                f[i] += 1
                flag = 0
            elif f[i] == h[i] and flag == 0:
                ans += 1
                flag = 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
typedef long long ll;
const ll MX = 1e18;

int main(void) {
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a == 0) {
      ans = 0;
      cout << ans << endl;
      return 0;
    }
    if (ng || MX / ans < a) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3612
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    if k == 1:
        print(0)
    elif n < k:
        print(1)
    else:
        print(n - k)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << "-1" << endl;return 0
#define MM <<" "<<
#define Endl endl

signed main(){
    int N,K;
    int A[2020];
    cin >> N >> K;
    REP(i,N){
        cin >> A[i];
    }
    int Ans=0;
    int num=0;
    REP(j,N){
        REP(i,j){
            if(A[i]>A[j])num++;
        }
    }
    Ans+=(num*K)%MOD;
    num=0;
    //cout << Ans << endl;
    REP(i,N){
        num=0;
        REP(j,N){
            if(A[j]<A[i])num++;
        }
        long long t=(K-1)*(K)/2;
        t%=MOD;
        t=(t*num)%MOD;
        Ans=(Ans+t)%MOD;
    }
    cout << Ans << endl;
    return 0;
}   


Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         ll m,n;
         cin>>m>>n;
         if(m==1 || n==1)
          cout<<"1";
        else{
         ll k1 = m*n*1LL;
         k1+=1;
         cout<<k1/2<<endl;}

      }
      






}



























Measured memory_bytes: 256
def dump(dp, max_n, max_w):
    for n in range(max_n + 1):
        for i in range(max_w + 1):
            print('%3d' % dp[n][i], end='')
        print()
    print()

inf = 1 << 60
max_n, max_w = map(int, input().split())
v = [0] * (max_n + 1)
w = [0] * (max_n + 1)
for i in range(1, max_n + 1):
    v[i], w[i] = map(int, input().split())

dp = [[0] * (max_w + 1) for _ in range(max_n + 1)]

for i in range(max_w + 1):
    dp[0][i] = 0

for n in range(1, max_n + 1):
    # if not selected
    for i in range(max_w + 1):
        dp[n][i] = max(dp[n][i], dp[n-1][i])
    # if selected
    for i in range(max_w + 1 - w[n]):
        dp[n][i+w[n]] = max(dp[n][i+w[n]], dp[n-1][i] + v[n])
    #dump(dp, max_n, max_w)

print(dp[max_n][max_w])



Measured memory_bytes: 25512
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, K; cin >> N >> K;
    string s; cin >> s;
    if(s[K-1] == 'A') s[K-1] = 'a';
    if(s[K-1] == 'B') s[K-1] = 'b';
    if(s[K-1] == 'C') s[K-1] = 'c';
    cout << s << endl;
    return 0;
}


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

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

  bool flg = false;
  for (int i = 0; i < 100000; i++) {
    if ((B * i + C) % A == 0) {
      flg = true;
      break;
    }
  }

  cout << (flg ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;

	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();




		System.out.println(a+a*a+a*a*a);
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}
}


Measured memory_bytes: 35588
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    string s;
    int r = 0, l = 0;

    vector<int> ans(100010, 0);

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'R')
        {
            r++;
        }
        else
        {
            ans[i - 1] += r - r / 2;
            ans[i] += r / 2;
            r = 0;
        }
    }

    for (int i = s.size() - 1; i >= 0; i--)
    {
        if (s[i] == 'L')
        {
            l++;
        }
        else
        {
            ans[i] += l / 2;
            ans[i + 1] += l - l / 2;
            l = 0;
        }
    }

    for (int i = 0; i < s.size(); i++)
    {
        printf("%d%c", ans[i], i == s.size() - 1 ? '\n' : ' ');
    }
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int k, n; cin >> k >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(), a.end());
    int maxd = 0;
    for(int i=0;i<n-1;i++){
        maxd = max(a[i+1] - a[i], maxd);
    }
    maxd = max(a[0] + (k - a[n-1]), maxd);
    cout << k - maxd << endl;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1000000007

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	xs := make([]int, n+1)
	for i := range xs {
		xs[i] = 1
	}
	var (
		sc = bufio.NewScanner(os.Stdin)
		a  int
	)
	for i := 0; i < m; i++ {
		sc.Scan()
		a, _ = strconv.Atoi(sc.Text())
		xs[a] = 0
	}
	var (
		f2     = 1
		f1, f0 = xs[1], xs[0]
	)
	for i := 2; i <= n; i++ {
		f2 = (f1*xs[i-1] + f0*xs[i-2]) % mod
		f1, f0 = f2, f1
	}
	fmt.Println(f2)
}


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

ll a[10];
ll n;

// claudio van
int main() {
  scanf("%lld", &n);
  for (int i = 0; i < 5; ++i) {
    scanf("%lld", &a[i]);
  }
  ll mn = *min_element(a, a + 5);
  ll ans = 5 + (max(0LL, n - mn) + mn - 1) / mn;
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;
typedef long double ld;
ld pi = 3.141592653589793;
int main(){
    cout.precision(20);
    ld a,b,h,m;
    cin >> a >> b >> h >> m;
    ld thi = (60*h - 11*m)*pi/360;
    thi = max(thi,-thi);
    thi = min(thi,2*pi - thi);
    cout << sqrt(a*a + b*b - 2*a*b*cos(thi)) << endl;
}

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

using namespace std;

int main()
{ 
   
   string s;//substring
   string a;
   while(cin>>a)
   {	
   		if(a=="-")break;
   		
   		int length=a.size();
		int k;
   		cin>>k;
   		
   		for(int i=1;i<=k;i++)
   		{
			int j;
			cin>>j;   
			s=a.substr(j,length-1);
			a=s+a;
			//cout<<a<<endl;
			a=a.substr(0,length);
			
		}
		cout<<a<<endl;
   	
   }
   
	
	
	
	return 0;
}
 


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

int dp[100001][3];
/// dp[i][j] = 第 i 天做 j 的最高總滿足度

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

    int n, a, b, c;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a;
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b;
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c;
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << '\n';

    return 0;
}


Measured memory_bytes: 4752
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;

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

	if ((n[0]==n[1] && n[1]==n[2]) || (n[1]==n[2] && n[2]==n[3])) {
	cout << "Yes" << endl;
	}
	else {
	cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
(n,q),*t=[map(int,t.split())for t in open(0)]
s=[0]
d=s*n
f=s*n
e=[[]for _ in d]
for t in t:
 a,b=t
 if~-n:n-=1;e[a-1]+=b-1,;e[b-1]+=a-1,
 else:d[a-1]+=b
while s:
 v=s.pop();f[v]=-1
 for w in e[v]:
  if~f[w]:d[w]+=d[v];s+=w,
print(*d)

Measured memory_bytes: 207492
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=2e5+5;
int n,k;
ll a[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n>>k;
	ll sum=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<k;i++)sum+=a[i];
	int i=0,j=k;
	ll s=sum;
	while(j<n){
		s=s-a[i]+a[j];
		if(s>sum)sum=s;
		i++;j++;
	}
	printf("%.6lf\n",1.0*(sum+k)/2);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}

template<typename T>
T max(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())maxi(ret, v[i]);
	return ret;
}

template<typename T>
T min(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())mini(ret, v[i]);
	return ret;
}

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

signed main() {
	vi ans;
	makei(n);
	makev(v, n);
	for (int a : v) {
		bool flag = true;
		if (a == 1) {}
		else if (a == 2)ans.push_back(a);
		else {
			Rep(2, sqrt(a) + 1) {
				if (a % i == 0)flag = false;
			}
			if (flag)ans.push_back(a);
		}
	}
	say(ans.size());
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

template<class T>
struct ModInt {
    T x;
    ModInt(T x = 0) :x(x% mod) {}
    ModInt& operator+=(const ModInt a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(const ModInt a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator*=(const ModInt a) {
        (x *= a.x) %= mod;
        return *this;
    }
    ModInt operator+(const ModInt a) const {
        ModInt res(*this);
        return res += a;
    }
    ModInt operator-(const ModInt a) const {
        ModInt res(*this);
        return res -= a;
    }
    ModInt operator*(const ModInt a) const {
        ModInt res(*this);
        return res *= a;
    }
    ModInt pow(T t) const {
        if (!t) return 1;
        ModInt a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    ModInt inv() const {
        return pow(mod - 2);
    }
    ModInt& operator/=(const ModInt a) {
        return (*this) *= a.inv();
    }
    ModInt operator/(const ModInt a) const {
        ModInt res(*this);
        return res /= a;
    }
};
using mint = ModInt<long long>;


int n;
ll a[300005];
void solve() {
    cin >> n;
    rep(i, n) cin >> a[i];

    mint ans = 0;
    rep(i, 62) {
        ll s = 0, t = 0;
        rep(j, n) if (((a[j] >> i) & 1) == 1) ++s; else ++t;
        ans += mint(s * t) * mint(2).pow(i);
    }

    cout << ans.x << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 2560
while True:
    p,n = raw_input().split()
    n = int(n)
    N = n
    p = int(p)
    if n==0:
        break
    list = [0 for x in range(p)]
    while True:
        flag = False
        for i in range(p):
            if n==0:
                n += list[i]
                list[i] = 0
            else:
                n -= 1
                list[i] += 1
            if list[i]==N:
                print i 
                flag = True
                break
        if flag == True:
            break

Measured memory_bytes: 6252
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int MOD = 1e9 + 7;

int K;
string N;
ll dp[10005][2][5];

int main() {
    cin >> N >> K;
    int n = N.size();

    /*
    REP(i, n) {
        REP(s, 2) { dp[i][s][0] = 1; }
    }
    */
    dp[0][0][0] = 1;

    REP(i, n) {
        REP(k, K + 1) {
            // i桁目まででNより小さいならi+1桁目は何でも良い
            dp[i + 1][1][k + 1] += dp[i][1][k] * 9;  // i+1桁目が0以外
            dp[i + 1][1][k] += dp[i][1][k];          // i+1桁目が0

            int ni = (N[i] - '0');

            // i桁目までNと同じで、i+1桁目はNより小さい数の時
            if (ni > 0) {
                dp[i + 1][1][k + 1] += dp[i][0][k] * (ni - 1);  // i+1桁目が0以外
                dp[i + 1][1][k] += dp[i][0][k];                 // i+1桁目が0
            }

            //  i桁目までNと同じで、i+1桁目もNと同じ数の時
            if (ni > 0) {
                dp[i + 1][0][k + 1] = dp[i][0][k];  // i+1桁目が0以外
            } else {
                dp[i + 1][0][k] = dp[i][0][k];  // i+1桁目が0
            }
        }
    }
    /*
    REP(i, n + 1) {
        REP(k, K + 1) { cout << "(i,0,k):(" << i << ",0," << k << ") " << dp[i][0][k] << endl; }
    }
    REP(i, n + 1) {
        REP(k, K + 1) { cout << "(i,1,k):(" << i << ",1," << k << ") " << dp[i][1][k] << endl; }
    }
*/
    cout << dp[n][0][K] + dp[n][1][K] << endl;

    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int s;
  foreach (t; 0 .. 3) {
    int n;
    readf (" %d", &n);
    s += n;
  }
  writeln (s >= 22 ? "bust" : "win");
}



Measured memory_bytes: 256
h,w=map(int,input().split())
li=[]
mod=10**9+7
for i in range(h):
  li.append(input())
dp=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
  if(li[i][0]=="#"):
      break
  dp[i][0]=1
for j in range(w):
    if(li[0][j]=="#"):
        break
    dp[0][j]=1
for i in range(1,h):
  for j in range(1,w):
    if li[i][j]==".":
      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod
print(dp[h-1][w-1]%mod) 

Measured memory_bytes: 53852
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

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

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

  ll ans = 0;
  orep(i,n) orep(j,n) orep(k,n) {
    ll t = gcd(i,j);
    t = gcd(t,k);
    ans += t;
  }
  cout << ans << endl;

  return 0;
}


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



class Program
{
    static void Main()
    {
        var x = Utility.ReadIntArray();

        long H = x[0];
        long W = x[1];
        long N = x[2];
        var ans = new long[10];

        var d = new Dictionary<long, long>();


        for (long i = 0; i < N; ++i)
        {
            var y = Utility.ReadLongArray();
            long a = y[0]-1;
            long b = y[1]-1;

            for (long j = 0; j <= 2; ++j)
            {
                for (long k = 0; k <= 2; ++k)
                {
                    long Y=a-j;
                    long X=b-k;

                    long Key=X*1000000000+Y;
                    
                    if (X < 0 || X>=W-2 || Y< 0 || Y>=H-2) continue;
                    if (!d.ContainsKey(Key))
                    {
                        d.Add(Key, 0);
                    }
                    d[Key]++;
                }
            }


        }


        foreach (var i in d)
        {
            ans[i.Value]++;
        }
        ans[0] = (H-2) * (W-2);

        for (int i = 1; i < 10; ++i)
        {
            ans[0] -= ans[i];
        }
        for (int i = 0; i < 10; ++i)
        {
             Console.WriteLine(ans[i]);
        }

    }
}



public static class Utility
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }

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

int main(){
  int a,b,c; float k; std::cin >> a >> b >> c >> k;
  int target = std::max({a,b,c});
  int total; total += a + b + c - target;
  total += target * std::pow(2, k);;
  printf("%d\n", total);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;


template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}


bool is_ok(string name,string sign){
    int nlen = name.length();
    int nsign = sign.length();
    // nlen >= 3
    for(int space=0;nlen+(nlen-1)*space <= nsign;space++){
        for(int start=0;start+nlen+(nlen-1)*space<=nsign;start++){
            bool ok = true;
            for(int mozi=0;mozi<nlen;mozi++){
                if(sign[start+mozi+mozi*space] != name[mozi]){
                    ok = false;
                    break;
                }
            }
            if(ok) return true;
        }
    }

    return false;
}

int main(){
    int n;
    string name;
    cin >> n >> name;
    int cnt = 0;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        if(is_ok(name,s)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1212
const   fi='TAP.inp';
        fo='TAP.out';
var maxx,minx,x,kq,i,n:longint;

procedure nhap;
begin
        read(n);
        maxx:=0;
        minx:=maxlongint;
        for i:=1 to n do
        begin
                read(x);
                if x>maxx then maxx:=x;
                if x<minx then minx:=x;
        end;
end;


procedure xuly;
begin
        kq:=maxx-minx;
        write(kq);
end;

begin

        nhap;
        xuly;
end.

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

signed main(){
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int ans = 0;

    for(int i = 0;i*r <= n;i++){
        for(int j = 0;i*r+j*g <= n;j++){
            if((n-(i*r)-(j*g))%b == 0){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}





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


int main(){
    int n, d, x;
    cin >> n >> d >> x;
    rep(i,n){
        int tmp;
        cin >> tmp;
        int k = 0;
        while(d >= 1 + tmp*(k++)) x++;
    }
    cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	string word;
	map< string, set<int> > m;
	while(cin >> word) {
		int page;
		cin >> page;
		m[word].insert(page);
	}

	for(auto& p: m) {
		cout << p.first << endl;
		for(auto it = p.second.begin(); it != p.second.end(); ++it) {
            if(it != p.second.begin()) {
                cout << ' ';
            }
            cout << *it;
        }
        cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <string>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

int n,k;
string s;

int main() {
	cin >> n >> k >> s;
	/*
	{
		string temp;
		char pre = '\0';
		for(int i = 0; i < n; i++) {
			if(s[i]=='0'&&pre=='0') continue;
			pre = s[i];
			temp += pre;
		}
		s = temp;
		n = s.size();
	}
	*/
	//cout << s << endl;
	int l = 0;
	int r = 0;
	/*
	int zc = 0;
	while(r<n) {
		if(s[r]=='0') {
			if(zc==k) break;
			zc++;
		}
		r++;
	}
	*/
	while(r<n&&s[r]=='1') r++;
	for(int i = 0; i < k; i++) {
		while(r<n&&s[r]=='0') r++;
		while(r<n&&s[r]=='1') r++;
	}
	int ans = 0;
	while(true) {
		ans = max(ans,r-l);
		//cout << l << "," << r << "," << ans << endl;
		if(r==n) break;
		while(l<n&&s[l]=='1') l++;
		while(l<n&&s[l]=='0') l++;
		while(r<n&&s[r]=='0') r++;
		while(r<n&&s[r]=='1') r++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
import sys
def checkPrime(n):
    if n%2 == 0:
        return False
    for i in range(1, int(n**(1/2))//2+1):
        if n%(i*2+1) == 0:
            return False
    return True

X = int(input())
if X == 2:
    print(2)
    sys.exit()
if X%2 == 0:
    X += 1
while not checkPrime(X):
    X += 2
print(X)

Measured memory_bytes: 3060
"""
13:56
"""
import os
import sys
from collections import defaultdict
from fractions import Fraction

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N, MA, MB = list(map(int, sys.stdin.readline().split()))
A, B, C = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

A = np.array(A)
B = np.array(B)
C = np.array(C)

# dp[a][b]: 薬品を a と b 揃えるときの最小のコスト
SUMMAX = 400
dp = np.full((SUMMAX + 1, SUMMAX + 1), IINF)
dp[0, 0] = 0
for a, b, c in zip(A, B, C):
    dp[a:, b:] = np.minimum(dp[a:, b:], dp[:-a, :-b] + c)

# MA / MB のやつを探す
ans = IINF
ma, mb = MA, MB
while ma <= SUMMAX and mb <= SUMMAX:
    ans = min(dp[ma, mb], ans)
    ma += MA
    mb += MB
if ans < IINF:
    print(int(ans))
else:
    print(-1)


Measured memory_bytes: 16920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 * N 人の社員からなる会社があり、各社員には 1, ..., N の社員番号が割り当てられています。 社員番号 1
 * の社員以外の全ての社員には、自分より社員番号が小さい直属の上司がちょうど 1 人います。 X さんが Y さんの直属の上司であるとき、Y さんは X
 * さんの直属の部下であるといいます。 社員番号 i の社員の直属の上司の社員番号が A_i
 * であることが与えられます。各社員について直属の部下が何人いるか求めてください。 Input: N A_2 ... A_N
 */
public final class Main {
  public static void main(final String[] args) throws Exception {
    final StringBuilder result = new StringBuilder();
    try (final BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
      execute(in, result);
    }
    try (final PrintWriter out = new PrintWriter(System.out)) {
      out.print(result);
      out.flush();
    }
  }

  private static void execute(final BufferedReader in, final StringBuilder result) throws Exception {
    int n = readInt(in);
    int[] a = readIntArray(in); // A_2 ... A_N
    int[] r = new int[n];
    for (int an : a) {
      r[an - 1]++;
    }
    for (int rn : r) {
      result.append(rn).append('\n');
    }
  }

  public static int readInt(final BufferedReader in) throws IOException {
    return Integer.parseInt(in.readLine());
  }

  public static int[] readIntArray(final BufferedReader in) throws IOException {
    return Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  }
}


Measured memory_bytes: 64232
def get_wall_index(ary, key, side):
  left = 0
  right = len(ary) - 1
  while left <= right:
    mid = (left + right) // 2
    if ary[mid] < key:
      left = mid + 1
    elif key < ary[mid]:
      right = mid - 1
    else:
      return mid + side
  return left

def main():
  input()
  input_data = list(map(int,input().split()))
  hash_list = {}
  for i,num in enumerate(input_data):
    if num not in hash_list:
      hash_list[num] = []
    hash_list[num].append(i)
  
  query_size = int(input())
  for _ in range(query_size):
    begin, end, index = map(int,input().split())
    if index in hash_list:
      left_wall = get_wall_index(hash_list[index],begin,0)
      right_wall = get_wall_index(hash_list[index],end-1,1)
      print(right_wall - left_wall)
    else:
      print(0)

if __name__ == '__main__':
  main()


Measured memory_bytes: 5832
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
  let n = read::<i32>();
  let d = read::<i32>();

  let mut ans = n / (2 * d + 1);
  let amari = (n % (2 * d + 1));
  if amari != 0 {
    ans += 1;
  }
  println!("{}", ans);
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll x;
    cin >> x;
    ll d = x/500;
    ll ans = d*1000;
    x = x%500;
    d = x/5;
    ans+=d*5;
    cout << ans << endl;
}


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);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(i+1==a.at(i)){
      if(i+1==n)ans++;
      else if(i+2==a.at(i+1)){
        ans++;
        i++;
      }
      else ans++;
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[105];
    int k=1;
    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++)
    {
        if((i+1)%2==1&&s[i]=='L')
        {
            k=0;
            break;
        }
        if((i+1)%2==0&&s[i]=='R')
        {
            k=0;
            break;
        }
    }
    if(k==0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int f(string a,string b){
  int ta=a.length(),tb=b.length();
  return (ta>tb)?ta:tb;
}
int main(){
  long min=10000000000,n,temp;
  cin >> n;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0){
      temp=f(to_string(i),to_string(n/i));
      min=(min<temp)?min:temp;
    }
  }
  cout << min << endl;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    /* 2 2 6
     2 6 2
     6 2 2
    */
    if(a == b && b != c || b == c && a != c || c == a && a != b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read

H, W, *S = read().split()
H, W = int(H), int(W)
ABC = [chr(i) for i in range(65, 65 + 26)]

for i in range(H * W):
    if S[i] == 'snuke':
        print(ABC[i % W] + str(i // W + 1))

Measured memory_bytes: 3060
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 998244353
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return sol;
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
void solve()
{
	ll a;
	long double b;
	cin >> a >> b;
	long double ans = a * b;
	ans = floor(ans);
	ll t = (ll)ans;
	cout << t;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
}


Measured memory_bytes: 3728
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int w = scanner.nextInt(),a = scanner.nextInt(),b = scanner.nextInt();
		int dw = 0;
		while(true){
			if(a < b && a + w < b){
				if(a + w + dw == b){
					break;
				}
				dw++;
			}else if(a < b && a + w >= b){
				break;
			}else if(a > b && b + w < a){
				if(b + w + dw == a){
					break;
				}
				dw++;
			}else if(a > b && b + w >= a){
				break;
			}else{
				break;
			}
		}
		System.out.println(dw);
	}

}


Measured memory_bytes: 21076
N, K  = map(int, input().split())
a = list(map(int, input().split()))

s = sum(a)
dl = []
k = 1
while k ** 2 <= s:
  if s % k == 0:
    dl.append(k)
    dl.append(s // k)
  k += 1
  
cand = []
for d in dl:
  op = 0
  b = [n % d for n in a]
  b.sort()
  b.reverse()
  summod = sum(b)
  for i in range(summod // d):
    op += d - b[i]
  if op <= K:
    cand.append(d)
    
print(max(cand))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

//二部グラフか確かめる. 二部グラフならtrue.
bool check(int p, int** s, char* checker, int n) {
	rep(i, n) {
		if (s[p][i] == 1) {
			if (checker[i] == -1) {
				checker[i] = checker[p] ^ 1;
				if (!check(i, s, checker, n)) {
					return false;
				}
			}
			else {
				if (!(checker[i] ^ checker[p])) {
					return false;
				}
			}
		}
	}

	return true;
}

//ワーシャルフロイド法で連続グラフの各ノード間の距離を求める.
void warshallFloyd(int** graph, int n) {
	rep(i, n) {
		rep(j, n) {
			rep(k, n) {
				graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);
			}
		}
	}
}

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

	int n;
	cin >> n;
	int** s;
	s = new int*[n];
	rep(i, n) s[i] = new int[n];

	char c;
	rep(vertical, n) {
		rep(horizontal, n) {
			cin >> c;
			if (c == '0') {
				if (vertical == horizontal) {
					s[vertical][horizontal] = 0;
				}
				else {
					s[vertical][horizontal] = n;	//どのノード間でもその距離はnより小さい.
				}
			}
			else {
				s[vertical][horizontal] = 1;
			}
		}
	}

	char* checker;
	checker = new char[n];
	memset(checker, -1, sizeof(char)*n);
	checker[0] = 0;
	if (!check(0, s, checker, n)) {
		cout << -1 << "\n";
		return 0;
	}

	warshallFloyd(s, n);
	
	int ans = 0;
	rep(vertical, n) {
		REP(horizontal, vertical, n) {
			ans = max(ans, s[vertical][horizontal]);
		}
	}

	cout << ans + 1 << "\n";

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>

using namespace std;

int k, s, ans;

int main(){
  cin >> k >> s;
  for(int x = 0;x <= k;x++){
    for(int y = 0;y <= k;y++){
      int z = s - x - y;
      if(0 <= z && z <= k)ans++;
    }
  }
  cout << ans << endl;
}

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

struct Tree{
    int parent;
    int child;
    int brother;
    int depth;
    string type;
};


int main(){
    int n;
    cin >> n;
    struct Tree tree[n];

    int id;//節点の番号
    int k;//次数

    for(int i=0; i<n; i++){//parentの初期化
        tree[i].parent = -1;
        tree[i].depth = 0;
    }

    //最初の根の情報だけ別で処理
    cin >> id;
    tree[id].depth = 0;
    //tree[id].parent = -1;
    tree[id].brother = -1;
    cin >> k;
    if(k==0){
        tree[id].type = "leaf";
        tree[id].child = -1;
    }
    else {
        tree[id].type = "internal node";
        int c[k];
        for(int j=0; j<k; j++){
            cin >> c[j];
        }
        tree[id].child = c[0];
        tree[c[0]].parent = id;
        tree[c[0]].depth = 1;
        for(int l=1; l<k; l++){
            tree[c[l]].parent = id;
            tree[c[l]].depth = 1;
            tree[c[l-1]].brother = c[l];
        }
        tree[c[k-1]].brother = -1;
    }

    for(int i=0; i<n-1; i++){//2つ目以降の情報をみていく
        cin >> id;
        //depthの決定
        if(tree[id].parent != -1){
            tree[id].depth = tree[tree[id].parent].depth + 1;
        }
        cin >> k;
        if(k==0){//子供がいないとき
            tree[id].type = "leaf";
            tree[id].child = -1;
        } 
        else {//こどもが1人以上いるとき
            tree[id].type = "internal node";
            int c[k];//子供たちを入れる配列
            for(int j=0; j<k; j++){
                cin >> c[j];
            }
            tree[id].child = c[0];//左の子を先に登録
            tree[c[0]].parent = id;//左の子の親を先に登録
            tree[c[0]].depth = tree[id].depth + 1;
            for(int l=1; l<k; l++){//このループには、兄弟がいるときにしか入れない
                tree[c[l]].parent = id;
                tree[c[l]].depth = tree[id].depth + 1;
                tree[c[l-1]].brother = c[l];
            }
            tree[c[k-1]].brother = -1;
        }
    }

    //rootの判断
    for(int i=0; i<n; i++){
        if(tree[i].parent == -1){
            tree[i].type = "root";
        }
    }

    //ここから出力
    for(int i=0; i<n; i++){
        //cout <<  i << ":: Type " << tree[i].type << ", Parent " << tree[i].parent << ", Child " << tree[i].child << ", Brother " << tree[i].brother << ", Depth " << tree[i].depth << endl; 
        cout << "node " << i << ": parent = " << tree[i].parent
        << ", depth = " << tree[i].depth 
        << ", " << tree[i].type << ", [" ;

        if(tree[i].child != -1){
            int C;
            cout << tree[i].child ;
            C = tree[i].child;
            while(1){
                if(tree[C].brother == -1){
                    break;
                }
                cout << ", " << tree[C].brother ;
                C = tree[C].brother;
            }
        }
        cout << "]" << endl;
    }

    return 0;
}


Measured memory_bytes: 10584
#!/usr/bin/env python3

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

minimum = min(a,b,c,d,e)

ans = 5+n//minimum

if n%minimum == 0:
  ans -=1

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>


#define PI 3.14159265358979323846264

typedef long double ld;
typedef long long ll;

using namespace std;

ld a, b;
ld h, m;
ld f1, f2;

pair<ld, ld> point(ld r, ld f) {
	return make_pair(r * cosl(f), r * sinl(f));
}

ld len(ld x, ld y) {
	return sqrt(x * x + y * y);
}

void print(pair<ld, ld> p) {
	cout << p.first << " " << p.second << endl;
}

int main() {
	cin >> a >> b >> h >> m;
		
	f1 = 2 * PI * (h + m / 60) / 12;
	f2 = 2 * PI * m / 60;

	pair<ld, ld> p1 = point(a, -f1);
	pair<ld, ld> p2 = point(b, -f2);

//	print(p1);
//	print(p2);

	printf("%.20Lf\n", len(p1.first - p2.first, p1.second - p2.second));

	return 0;
}


Measured memory_bytes: 4124
s = input()

a = int(s[:2])
b = int(s[2:])
if 1<= a <=12 and 1<=b<=12:
	print("AMBIGUOUS")
elif 1<=a<=12 and (b ==0 or b>=13):
	print("MMYY")
elif (a == 0 or a>=13) and  1<=b<=12:
	print("YYMM")
else:
	print("NA")


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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  int n , k;
  cin>>n>>k;
  int a[n];
  for(int i = 0; i < n; ++i){
    cin >>a[i];
  }
  int dp[n];
  dp[0] = 0;
  for(int i =1; i < n; ++i){
    int m = 1e9+7;
    for(int j = 1; i -j >= 0 && j <= k; ++j){
      m = min(m,dp[i-j]+abs(a[i-j]-a[i]));
    }
    dp[i] = m;
  }
  cout<<dp[n-1]<<"\n";
	      
}


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

using namespace std;
using LL = long long;
using pii = pair<int, int>;

int n;

signed main() {
  // freopen("in", "r", stdin);
  while (~scanf("%d", &n)) {
    map<pii, int> vis;
    double tmp;
    LL x;
    for (int i = 1; i <= n; i++) {
      cin >> tmp;
      x = llround(tmp * 1E9);
      int two = 0, five = 0;
      while (x % 2 == 0) {
        x /= 2;
        two++;
      }
      while (x % 5 == 0) {
        x /= 5;
        five++;
      }
      vis[{two, five}]++;
    }
    LL ret = 0;
    for (auto x : vis) {
      for (auto y : vis) {
        if (x.first.first + y.first.first >= 18 && x.first.second + y.first.second >= 18) {
          if (x < y) {
            ret += (LL)x.second * y.second;
          } else if (x == y) {
            ret += (LL)x.second * (y.second - 1) / 2LL;
          }
        }
      }
    }
    printf("%lld\n", ret);
  }
  return 0;
}

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

count=0
lis=[]


for i in range(1,N+1):
	if N/i < i:
		break
	if N/i==N//i:
		lis.append(i)

llis=[]
for x in lis:
	y = N / x
	mm=max([x,y])

	ketasuu=len(str(int(mm)))
	llis.append(ketasuu)


print(min(llis))

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!

    // 問題毎に計算していたら間に合わない
    // 全組み合わせに対して計算するのも間に合わない
    // 漸化式的に計算して計算量を落とせないか？？
    // 文字列から AC 以外を落として処理すれば？？ 最悪のケースでは失敗するので ☓
    // 事前に全体とそれより右，左で計算する

    var left_count = IntArray(size=100000)
    var right_count = IntArray(size = 100000)
    var total = 0

    var cnt = 0
    for(i in 1 until s.length) {
        if (s.substring(i-1, i+1) == "AC") {
             cnt += 1
        }
        left_count[i] = cnt
    }

    total = cnt
    for (i in 0 until right_count.size) {
        right_count[i] = total - left_count[i]
    }

    for (i in 0 until q) {
        val (l, r) = readLine()!!.split(" ").map { it.toInt() }
        println(total - left_count[l-1] - right_count[r-1])
    }
}

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

def main():
    S = input()
    cnt = 0
    ret = len(S)
    for a in S:
        if a == 'S':
            cnt += 1
        else:
            if cnt>0:
                cnt-=1
                ret-=2
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9112