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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = 998244353;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

typedef pair<int, int> p_ii;

struct SegTree {
  int n_count;
  vector<ll> pos;

  SegTree(int N, const ll d_num) {
    n_count = 1; while(n_count<N) n_count<<=1;
    pos.assign(2*n_count, 0);
  }

  ll operator[](const int &k) const { return pos[k+n_count]; }

  void set(int k, const ll x) { pos[k+n_count] = x; }
  void build() { for (int i=n_count-1; i>=0; i--) pos[i] = pos[i*2] + pos[i*2+1]; }
  void update(int k, const ll x) { set(k,x); k += n_count; while(k >>= 1) pos[k] = pos[k*2] + pos[k*2+1]; }
  ll query(int a,int b) {
    ll L = 0, R = 0;
    for ( a+=n_count, b+=n_count; a<b; a>>=1, b>>=1 ) {
      if (a&1) { L+=pos[a]; a++; }
      if (b&1) { b--; R+=pos[b]; }
    }
    return L + R;
  }

};

int main() {
  int N; cin >> N;
  p_ii A[N];
  rep(i,N) { int x, y; cin >> x >> y; A[i] = make_pair(x,y); }

  sort(A,A+N, [](const p_ii& x, const p_ii& y){return x.first<y.first;});
  rep(i,N) A[i].first = i;
  sort(A,A+N, [](const p_ii& x, const p_ii& y){return x.second<y.second;});
  rep(i,N) A[i].second = i;

  int lx[N];
  SegTree segx(N,0); segx.build();
  rep(i,N) { lx[i] = segx.query(0,A[i].first); segx.update(A[i].first,1); }
  // rep(i,N) cout << "(" << A[i].first << "," << A[i].second << "):" << lx[i] << endl;

  ll result = 0;
  ll p2[N+1] = {}; rep(i,N+1) { p2[i] = (i==0) ? 1 : p2[i-1]*2; p2[i] %= MOD; }
  rep(i,N) {
    ll tmp = p2[N]-1;
    tmp -= p2[A[i].first]; tmp %= MOD;
    tmp -= p2[(N-1)-A[i].first]; tmp %= MOD;
    tmp -= p2[A[i].second]; tmp %= MOD;
    tmp -= p2[(N-1)-A[i].second]; tmp %= MOD;
    tmp += p2[lx[i]]; tmp %= MOD;
    tmp += p2[A[i].first-lx[i]]; tmp %= MOD;
    tmp += p2[A[i].second-lx[i]]; tmp %= MOD;
    tmp += p2[(N-1)-(A[i].first+A[i].second-lx[i])]; tmp %= MOD;
    // cout << "(" << A[i].first << "," << A[i].second << "):" << tmp << endl;
    result += tmp; result %= MOD;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 8192
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;
void afs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v =0;v<n;v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      afs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}
void dfs(){
  int u;
  for(u =0;u<n;u++){
    if(color[u] == WHITE) afs_visit(u);
  }
  for(u =0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i =0;i<n;i++){
    for(j = 0;j<n;j++) M[i][j] = 0;
  }
  for(i =0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j =0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int main() {
     int a,b;
     cin >> a >> b;

     if(a % 3 == 0) cout << "Possible" << endl;
     else if(b % 3 == 0) cout << "Possible" << endl;
     else if((a + b) % 3 == 0) cout << "Possible" << endl;
     else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ppb pop_back()
#define fi first
#define se second
#define pi pair<int, int>
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define REP(i, a, n) for(int i = a; i < n; i++)
#define Y "YES"
#define N "NO"
using namespace std;

string n;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	if (n == "RRR") cout << 3;
	else if (n == "RRS" || n == "SRR") cout << 2;
	else if (n == "SSS") cout << 0;
	else cout << 1; 
}


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

int main(){
	char t;
	int d, a;
	double x = 0, y = 0, rad = M_PI/2.0;
	while(cin >> d >> t >> a){
		if(!d && !a)break;
		x += cos(rad) * (double)d;
		y += sin(rad) * (double)d;
		rad -= a / 180.0 * M_PI;
	}
	cout << (int)x << endl << (int)y << endl;
	return 0; 
}

Measured memory_bytes: 3316
#include<stdio.h>

int main()
{
    int N,K,i,h,a=0;
    int polje[100000];
    scanf("%d", &N);
    scanf("%d", &K);
    for(i=0;i<N;i++)
        scanf("%d", &polje[i]);
    for(i=0;i<N;i++)
    {
        if(polje[i]>=K)
            a=a+1;
    }
    printf("%d", a);           
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int N;
int main(){
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    rep(i,N)cin >> A[i];
    rep(i,N)cin >> B[i];
    rep(i,N)cin >> C[i];
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    long long ans = 0;
    for(ll i=0;i<N;++i){
        ll k = upper_bound(C.begin(),C.end(),B[i])-C.begin();
        k = N-k;
        ll l = lower_bound(A.begin(),A.end(),B[i])-A.begin();
        ans += k*l;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
n = int(input())
cont = [0 for i in range(10050)]

for x in range(1,105):
  for y in range(1,105):
    for z in range(1,105):
      v = x**2 + y**2 + z**2 + z*x + y*z + x*y
      if v <= 10001:
        cont[v]+=1

for i in range(1,n+1):
  print(cont[i])

Measured memory_bytes: 9304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			int in = Integer.parseInt(br.readLine());

			 System.out.println(in%2==0?in:in*2);
		}
	}
}

Measured memory_bytes: 25352
def main():
    while 1:
        w, h = map(int, input().split())
        if w == 0: break
        fld = [[] for i in range(h)]
        for i in range(h):
            readline = input()
            for j in range(w):
                item = readline[j]
                fld[i].append(item)
                if item == '@': sy, sx = i, j
        solve(fld, sy, sx)
        count = 0
        for i in range(h):
            for j in range(w):
                if fld[i][j] == 'A': count += 1
        print(count)

def solve(fld, cy, cx):
    vy = [1,-1,0,0]
    vx = [0,0,1,-1]
    fld[cy][cx] = 'A'
    for i in range(4):
        ny = cy + vy[i]
        nx = cx + vx[i]
        if ny < 0 or nx < 0 or ny >= len(fld) or nx >= len(fld[0]):continue
        elif fld[ny][nx] == '.': solve(fld, ny, nx)
main()



Measured memory_bytes: 5776
import Control.Applicative
import Text.Printf

area :: Double -> Double
area r = pi * r * r

cir :: Double -> Double
cir r = 2.0 * pi * r

main :: IO()
main = do
  r <- (read :: String -> Double) <$> getLine
  printf "%.6f %.6f\n" (area r) (cir r)

Measured memory_bytes: 3976
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

int simulate(int j, const std::string &arrayChar,
             const std::vector<char> &queryChar,
             const std::vector<char> &queryDirection) {
  const int numArray = arrayChar.length() - 1;
  const int numQuery = queryChar.size() - 1;
  assert(numQuery == static_cast<int>(queryDirection.size()) - 1);
  assert(1 <= j and j <= numArray);
  // move j by queries
  for (int i = 1; i <= numQuery; ++i) {
    // query hit
    if (queryChar[i] == arrayChar[j]) {
      switch (queryDirection[i]) {
      case 'L': // move left
        if (j == 1)
          return -1;
        --j;
        break;
      case 'R': // move right
        if (j == numArray)
          return +1;
        ++j;
        break;
      default:
        assert(false);
      }
    }
  }
  return 0;
}

int main() {
  // Input
  int numArray; // index: j
  int numQuery; // index: i
  std::cin >> numArray >> numQuery;
  assert(1 <= numArray and numArray <= 2 * 1.0e+5);
  assert(1 <= numQuery and numQuery <= 2 * 1.0e+5);
  std::string arrayChar;
  std::cin >> arrayChar;
  arrayChar.insert(arrayChar.begin(), '-');
  assert(static_cast<int>(arrayChar.length()) == 1 + numArray);
  std::vector<char> queryChar(1 + numQuery);
  std::vector<char> queryDirection(1 + numQuery);
  for (int i = 1; i <= numQuery; ++i) {
    std::cin >> queryChar[i] >> queryDirection[i];
    assert(queryDirection[i] == 'L' or queryDirection[i] == 'R');
  }

  // left drop
  int lb = 0;        // left drop index
  int ub = numArray + 1; // not left drop index
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (simulate(mid, arrayChar, queryChar, queryDirection) == -1)
      lb = mid;
    else
      ub = mid;
  }
  assert(lb + 1 == ub);
  const int leftDrop = lb;
  // std::cout << lb << std::endl;

  // right drop
  lb = 0;            // right drop index
  ub = numArray + 1; // not right drop index
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (simulate(mid, arrayChar, queryChar, queryDirection) == +1)
      ub = mid;
    else
      lb = mid;
  }
  assert(lb + 1 == ub);
  const int rightDrop = ub;
  // std::cout << ub << std::endl;

  std::cout << rightDrop - leftDrop - 1 << std::endl;

  return 0;
}


Measured memory_bytes: 900
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:16:28 2020

@author: Kanaru Sato
"""

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

sat = sum(b)
for i in range(n-1):
    if a[i+1] == a[i]+1:
        sat += c[a[i]-1]

print(sat)

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  string s;
  cin >> s;
  for (int i = 0; i < n - 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
def keisan(numlist):
  ans=1
  if "0" in numlist:
    return "0"
  for i in numlist:
    ans *= int(i)
    if ans > max:
      return "-1"
  return ans

  
  

num = input()
numlist = input().split()

max=10**18
print(keisan(numlist))


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

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

  if(n%2 == 0){
    cout << 0.5 << endl;
    return 0;
  }else{
    int hoge;
    hoge = (n+1) / 2;
    double ans = (double)hoge / n;
    cout << ans <<endl;
    return 0;
  }
  return 0;
}


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

#include <cassert>
#include <climits>

#include <string>

#include <vector>
#include <map>
#include <deque>
#include <stack>

#include <algorithm>

#include <utility>

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    assert(h >= 1 && h <= 1400);
    assert(w >= 1 && w <= 1400);

    vector< vector<int> > dp      = vector< vector<int> >(h + 1, vector<int>(w + 1, 0));
    vector< vector<int> > tiles   = vector< vector<int> >(h + 1, vector<int>(w + 1, 0));

    for (int i = 1; i <= h; ++i)
    {
        for (int j = 1; j <= w; ++j)
        {
            // 汚れているなら1, 綺麗なら0.
            int is_dirty;
            cin >> is_dirty;
            assert(is_dirty == 0 || is_dirty == 1);

            tiles[i][j] = is_dirty;
        }
    }

    int max_width = 0;
    for (int i = 1; i <= h; ++i)
    {
        for (int j = 1; j <= w; ++j)
        {
            if (tiles[i][j] == 0)
            {
                dp[i][j] = min(dp[i-1][j-1], min(dp[i-1][j], dp[i][j-1])) + 1;
            }
            else
            {
                dp[i][j] = 0;
            }
            max_width = max(max_width, dp[i][j]);
        }
    }

    cout << max_width * max_width << endl;
}



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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll h, w;
    cin >> h >> w;
    vector<string> mat(h);
    REP(i, 0, h)
        cin >> mat[i];
    vvi dp(h, vi(w, LLONG_MAX));
    dp[h-1][w-1] = 0;
    if (mat[h-1][w-1] == '#')
        dp[h-1][w-1] = 1;
    RREP(i, h-1, -1) {
        RREP(j, w-1, -1) {
            if (i == h-1 && j == w-1)
                continue;
            if (i+1 < h) {
                if (mat[i+1][j] == '#')
                    dp[i][j] = min(dp[i][j], dp[i+1][j]);
                else {
                    if (mat[i][j] == '#')
                        dp[i][j] = min(dp[i][j], dp[i+1][j] + 1);
                    else
                        dp[i][j] = min(dp[i][j], dp[i+1][j]);
                }
            }
            if (j+1 < w) {
                if (mat[i][j+1] == '#')
                    dp[i][j] = min(dp[i][j], dp[i][j+1]);
                else {
                    if (mat[i][j] == '#')
                        dp[i][j] = min(dp[i][j], dp[i][j+1] + 1);
                    else
                        dp[i][j] = min(dp[i][j], dp[i][j+1]);
                }
            }
        }
    }
    cout << dp[0][0] << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int a[1010],b[1010];
int main()
{
	int t,h;
	char l;
	string s;
	while(getline(cin,s)&&s.size()!=0)
	{
		istringstream is1(s);
		is1 >> t >> l >> h;
		a[t]++;
	}
	while(getline(cin,s))
	{
		istringstream is2(s);
		is2 >> t >> l >> h;
		b[t]++;
	}
	for(int i=0;i<1010;i++)
	{
		if(a[i]&&b[i])
		{
			cout << i << ' ' << a[i]+b[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 200007;
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;
    char c[MAX];
    long long count = 0;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        if (c[i] == 'R') {count++;}
    }
    long long res = count;
    for (int i = 0; i < count; i++) {
        if (c[i] == 'R') {res--;}
    }
    cout << res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("rental.in", "r", stdin); freopen("rental.out", "w", stdout);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}


Measured memory_bytes: 3808
L = [int(i) for i in input().split()]
W = L[0]
H = L[1]
x = L[2]
y = L[3]
r = L[4]
if x <=W and y < H:
    if ( x - r >= 0 and x + r <= W )  and ( y - r >= 0 and y +r <= H ):
        print("Yes")
    else:
        print("No")
else:
    print("No")



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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int dx = tx - sx;
  int dy = ty - sy;

  string ans = "";
  for (int i = 0; i < dx; i++) ans += "R";
  for (int i = 0; i < dy; i++) ans += "U";
  for (int i = 0; i < dx; i++) ans += "L";
  for (int i = 0; i < dy; i++) ans += "D";
  ans += "D";
  dx++; dy++;
  for (int i = 0; i < dx; i++) ans += "R";
  for (int i = 0; i < dy; i++) ans += "U";
  ans += "LU";
  for (int i = 0; i < dx; i++) ans += "L";
  for (int i = 0; i < dy; i++) ans += "D";
  ans += "R";

  cout << ans << endl;
}

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

int main()
{
	int a, b, c,i, count;
	a = 0;
	b = 0;
	c = 0;
	count = 0;

	cin >> a >> b >> c;
	if ((1 <= a) && (a <= 10000) && (1 <= b) && (b <= 10000) && (1 <= c) && (c <= 10000))  //a,b,cが1から10000以内
	{
		if (a <= b) 
		{
			for (i = a; i <= b; i++)       //cの約数を求めるのでc割るiの余りが0ならカウンタを増やす
			{
				if (c % i == 0) 
				{
					count++;
				}
			}

		}
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ll a, b;
	scanf("%lld%lld", &a, &b);
	if(a % 2 != b % 2) printf("IMPOSSIBLE\n");
	else {
		int ans = (a + b) / 2;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3724
S = str(input())
s=len(S)
x=[0]*2
y=[0]*2

for i in range(s):
    if i%2==0 :
        if S[i]=="1":
            x[0]+=1
        else:
            x[1]+=1
    else:
        if S[i]=="1":
            y[0]+=1
        else:
            y[1]+=1
print(min(x[0]+y[1],x[1]+y[0]))



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll p[m+5];
	string s[m+5];
	bool visited[n+5];
	memset(visited,false,sizeof(visited));
	ll a[n+5];
	memset(a,0,sizeof(a));
	for(ll i=0;i<m;i++)
	{
		cin>>p[i]>>s[i];
		if (visited[p[i]]==false)
		{
			if (s[i]=="AC")
			{
				visited[p[i]]=true;
			}
			else 
			{
				a[p[i]]++;
			}
		}
	}
	ll ans1=0,ans2=0;
	for(ll i=1;i<=n;i++)
	{
		if (visited[i])
		{
			ans1++;
			ans2+=a[i];
		}
	}
	cout<<ans1<<" "<<ans2;
}

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

using namespace std;

typedef long long ll;

int L,R,v1,v2;

bool query(int x,int k) {
  if (x<=L*(k+1)) return (x%(k+1)==0)?1:0;
  else if (x<=L*(k+1)+v1) return 0;
  else if (x<=L*(k+1)+v1+v2) return 1;
  else return ((x-L*(k+1)-v1-v2)%(k+1)==1)?0:1;
} 

bool check(int a,int b,int k,int d) {
  int t=(d-1)/k;
  if (t>b) return 0;
  return (ll)(a-d+1)*k>=b-t;
}

int main() {
  int cases;
  scanf("%d",&cases);
  for(;cases;cases--) {
  	int a,b;
  	scanf("%d%d",&a,&b);
  	int k=(max(a,b)+min(a,b))/(min(a,b)+1);
  	int l=0,r=a;
  	while (l<r) {
  		int m=((l+r)>>1)+1;
  		if (check(a,b,k,m)) l=m; else r=m-1;
	  }
	L=((l%k==0)?l/k-1:l/k);
	v1=l-L*k;
	v2=b-L-(a-l)*k;
	R=a-l;
	int x,y;
	scanf("%d%d",&x,&y);
	for(int i=x;i<=y;i++) putchar((query(i,k))?'B':'A');
	printf("\n");
  }
  return 0;
}

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

using namespace std;

char s[111111];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%s",&s);
	int n = strlen(s);
	int an = 0;
	for(int i = 0; i < n; ++i){
		if (i % 2){
			if (s[i] == 'g') ++an;
		}
		else if (s[i] == 'p') --an;
	}
	printf("%d",an);
	return 0;
}

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

vector < int > nxt[103]; int N;
#define int long long
int mx[103] , sum[103] , ans , mndep;
void dfs1(int x , int p , int dep){
	int cnt = 0;
	for(auto t : nxt[x]) if(t != p){++cnt; dfs1(t , x , dep + 1);}
	sum[dep] += cnt; mx[dep] = max(mx[dep] , cnt);
}

signed main(){
	cin >> N;
	for(int i = 1 ; i < N ; ++i){int a , b; cin >> a >> b; nxt[a].push_back(b); nxt[b].push_back(a);}
	ans = (1ull << 63) - 1; mndep = N + 1;
	for(int i = 1 ; i <= N ; ++i){
		memset(mx , 0 , sizeof(mx)); memset(sum , 0 , sizeof(sum));
		dfs1(i , 0 , 0); long long cnt = 1 , dep = 0;
		for(int j = 0 ; mx[j] ; ++j){cnt *= mx[j]; dep = j + 1;}
		if(mndep > dep){mndep = dep; ans = cnt;}
		else if(mndep == dep) ans = min(ans , cnt);
	}
	for(int i = 1 ; i <= N ; ++i)
		for(auto t : nxt[i]){
			memset(mx , 0 , sizeof(mx)); memset(sum , 0 , sizeof(sum));
			dfs1(i , t , 0); dfs1(t , i , 0); long long cnt = 2 , dep = 0;
			for(int j = 0 ; mx[j] ; ++j){cnt *= mx[j]; dep = j + 1;}
			if(mndep > dep){mndep = dep; ans = cnt;}
			else if(mndep == dep) ans = min(ans , cnt);
		}
	cout << mndep + 1 << ' ' << ans << endl; return 0;
}

Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    X,Y,Z,K = LMIIS()
    A = LMIIS()
    B = LMIIS()
    C = LMIIS()
    
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    from heapq import heappush,heappop
    from collections import defaultdict
    d = defaultdict(lambda:False)
    h = []
    ai = bi = ci = 0
    heappush(h,(-(A[ai]+B[bi]+C[ci]),ai,bi,ci))
    d[(0,0,0)] = True
    for _ in range(K):
        v,ai,bi,ci = heappop(h)
        print(-v)
        if ai+1 < X and d[(ai+1,bi,ci)] == False:
            heappush(h,(-(A[ai+1]+B[bi]+C[ci]),ai+1,bi,ci))
            d[(ai+1,bi,ci)] = True
        if bi+1 < Y and d[(ai,bi+1,ci)] == False:
            heappush(h,(-(A[ai]+B[bi+1]+C[ci]),ai,bi+1,ci))
            d[(ai,bi+1,ci)] = True
        if ci+1 < Z and d[(ai,bi,ci+1)] == False:
            heappush(h,(-(A[ai]+B[bi]+C[ci+1]),ai,bi,ci+1))
            d[(ai,bi,ci+1)] = True


    
    


if __name__ == '__main__':
    main()

Measured memory_bytes: 57820
#include <iostream>
#include <cstring>

using namespace std;

char a[7][7]={"abc","acb","bac","bca","cab","cba"};
char b[10];

int main()
{
    cin>>b;
    for(int i=0;i<6;i++)
    {
        if(strcmp(a[i],b)==0)
            {cout<<"Yes"<<endl;return 0;}

    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int group[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x,y;
  cin >> x >> y;
  if(group[x] == group[y]) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = np.array([int(x) for x in readline().rstrip().split()])
A_sum = A.sum()
A_sum //= 2
ans = []
x1 = A_sum
j = 1
for i in range((N-1)//2):
    x1 -= A[j]
    j += 2
ans.append(2 * x1)
for k in range(1, N):
    x = A[k-1] - (ans[k-1] // 2)
    ans.append(2 * x)
print(* ans)

Measured memory_bytes: 23528
#include<stdio.h>
int main()
{
	long long int h, w;
	scanf("%lld %lld", &h, &w);
	if (h == 1 || w == 1)
		printf("1\n");
	else
		printf("%lld\n", (h * w + 1) / 2);
	return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N; char C;

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    scanf("%c", &C);
    if (C == 'Y'){
      printf("Four\n");
      return 0;
    }
  }
  printf("Three\n");

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

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

  cout << c * a / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      	int d = sc.nextInt();
      	int e = sc.nextInt();
      	int k = sc.nextInt();
      	boolean go = true;
      
      	if(Math.abs(a-b) > k) go = false;
        if(Math.abs(a-c) > k) go = false;
        if(Math.abs(a-d) > k) go = false;
        if(Math.abs(a-e) > k) go = false;
        if(Math.abs(b-c) > k) go = false;
        if(Math.abs(b-d) > k) go = false;
        if(Math.abs(b-e) > k) go = false;
        if(Math.abs(c-d) > k) go = false;
        if(Math.abs(c-e) > k) go = false;
        if(Math.abs(d-e) > k) go = false;
      
      	if(go){
        	System.out.println("Yay!");
        }else{
        	System.out.println(":(");
        }
    }
}

Measured memory_bytes: 35640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  int b;
  int c;
  int d;
  int e;
  int count;
  e = a % 10;
  d = (a-e) % 100 /10;
  c = (a-e-10*d) % 1000 /100;
  b = (a-e-10*d-100*c)%10000/1000;
  if(b == c && c == d){
    cout << "Yes" << endl;
  }else if(c == d && d == e){
    cout << "Yes" << endl;
  }else{
        cout << "No" << endl;
  }
 
}

Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if k % 7 == 0 else k)
    if l % 2 == 0 or l % 5 == 0:
        return '-1'

    r = phi = l
    for i in range(2, int(-pow(l, 1/2))):
        if r % i == 0:
            phi = phi//i*(i-1)
            while r % i:
                r //= i

    a = 10 % l
    ret = 1
    while(a != 1):
        a = a*10 % l
        ret += 1
        if phi < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main()
{
    int flag=0;
    while(1)
    {
	int sum,price,coin[4]={0},exchange[4]={0},value[4]={10,50,100,500};
	cin >> price;
	if (price == 0)
	    break;
	if (flag == 0)
	{
	    flag = 1;
	} else {
	    cout << endl;
	}
	sum = 0;
	for(int i=0; i<4; i++)
	{
	    cin >> coin[i];
	    sum += coin[i]*value[i];
	}
	sum -= price;
	for (int i=3; i>=0; i--)
	{
	    while(value[i] <= sum)
	    {
		sum -= value[i];
		exchange[i]++;
	    }
	}
	for (int i=0; i<4; i++)
	{
	    while(coin[i] > 0 && exchange[i] > 0)
	    {
		coin[i]--;
		exchange[i]--;
	    }
	    if (coin[i] > 0)
	    {
		cout << value[i] << " " << coin[i] << endl;
	    }
	}
    }
}

Measured memory_bytes: 868
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    int N,x,l[101],ans=0,cnt=0;
    cin>>N>>x;
    rep(i,N){
        cin>>l[i];
        ans+=l[i];
        if(ans<=x) cnt++;
    }
    cnt++;
    cout<<cnt<<endl;

}

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

int main(){
    string N;
    cin >> N;
    int L = N.size();
    int S = 0;
    for(int i=0;i<L;i++){
        int n = N[i] - '0';
        S += n;
        S %= 9;
    }

    if(S == 0)cout << "Yes" << endl;
    else cout << "No" << endl;

    
}

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

const int M=100010;
bool stu[410][410];
int n,m,a[M],b[M];
bool cant[410];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d%d",a+i,b+i);
	for(int i=1;i<=n;i++)
	{
		stu[i][i]=1;
		for(int j=m;j>=1;j--)
		{
			bool x=stu[i][a[j]],y=stu[i][b[j]];
			if(x&&y){cant[i]=1;break;}
			else if(x) stu[i][b[j]]=1;
			else if(y) stu[i][a[j]]=1;
		}
	}
	int ans=0;
	for(int i=1;i<n;i++)
	{
		if(cant[i]) continue;
		for(int j=i+1;j<=n;j++)
		{
			if(cant[j]) continue;
			bool flag=1;
			for(int k=1;k<=n;k++)
				if(stu[i][k]&&stu[j][k]) flag=0;
			ans+=flag;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int l,r;
  int s=0;
  for(int i=0;i<N;i++){
    cin >> l >> r;
    s+=r-l+1;
    if(i==N-1){
      cout << s <<endl;
    }
  }
}


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

struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
};
struct node *head;


void pre(struct node *u){
  if(u->key == -1){
    return;
  }
  printf(" %d", u->key);
  pre(u->l);
  pre(u->r);
}

void in(struct node *u){
  if(u->key == -1){
    return;
  }
  in(u->l);
  printf(" %d", u->key);
  in(u->r);
}

void insert(int u){
  struct node *z;
  z = (struct node *)malloc(sizeof(struct node));
  z->key = u;
  z->l = (struct node *)malloc(sizeof(struct node));
  z->r = (struct node *)malloc(sizeof(struct node));
  z->l->key = -1;
  z->r->key = -1;
  struct node *y;
  struct node *x;
  x = head;
  y = head->p;

  while(x->key != -1){
    y = x;
    if(u < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
    
  z->p = y;
  if(y->key == -1){
    head = z;
  }else if(z->key < y->key){
    y->l = z;
  }else{
    y->r = z;
  }
}

void print(void){
  in(head);
  printf("\n");
  pre(head);
  printf("\n");
}

int main(void){
  int i, n, x;
  head = (struct node *)malloc(sizeof(struct node));
  head->key = -1;
  head->l = (struct node *)malloc(sizeof(struct node));
  head->r = (struct node *)malloc(sizeof(struct node));
  head->p = (struct node *)malloc(sizeof(struct node));
  head->p->key = -1;
  head->l->key = -1;
  head->r->key = -1;
  char s[16];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", s);
    if(!strcmp(s, "insert")){
      scanf("%d", &x);
      insert(x);
    }else if(!strcmp(s, "print")){
      print();
    }
  }
  return 0;
}


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

int main() {

    int K, N;
    cin >> K >> N;

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    A.push_back(K+A[0]);

    int l = 0;

    rep(i, N) {
        l = max(l, A[i + 1] - A[i]);
    }

    cout << K - l << endl;

    return 0;
}

Measured memory_bytes: 4840
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
for i in range(N):
  c1 = min(A[i], B[i])
  c2 = min(A[i+1], max(0, B[i]-A[i]))
  A[i+1] -= c2
  count += c1+c2
print(count)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(2*1e5)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll MOD = 1e9+7;

ll fat[MAXN], inv[MAXN];

ll expo(ll a, ll b){
    if(b == 0) 
		return 1;
    ll x = expo(a, b/2);
    return (b & 1 ? ((x*x)%MOD*a)%MOD : (x*x) % MOD);
}

ll c(ll n, ll k) {
	ll res = 1;
	for(int i = n; i >= n-k+1; i--)
		res = (res*i)%MOD;
	return (res*inv[k])%MOD;
}

int main() {
	
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = expo(2, n)-1;
	
	fat[1] = 1;
	inv[1] = 1;
	
	for(int i = 2; i < MAXN; i++) {
		fat[i] = (fat[i-1]*i)%MOD;
		inv[i] = expo(fat[i], MOD-2);
	}
	
	ll kk = (ans - c(n, a) - c(n, b))%MOD;
	if(kk < 0) kk += MOD;
	cout << kk << endl;
}


Measured memory_bytes: 3456
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      money=500*i+100*j+50*k
      if money == x:
        count+=1
      
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <map>

using namespace std;

int n,m;

int kx,ky;
int field[11][11];
int home;
const int INF=1000000000;

int cnt=0;

int psize;
pair<int,int> path[200];

void dfs(int x,int y){
	if(home==0){
		if(x==kx||y==ky){
			cnt++;
			//for(int i = 0; i < psize; i++){
			//	cout<<path[i].first<< " "<<path[i].second<<endl;
			//}
			//cout<<endl;
			return;
		}
	}
	else{
		for(int i = y-1; i >= 0; i--){
			if(field[i][x]==1){
				field[i][x]=0;
				home--;
				path[psize]=make_pair(i,x);
				psize++;
				dfs(x,i);
				psize--;
				home++;
				field[i][x]=1;
				break;
			}
		}
		for(int i = y+1; i < n; i++){
			if(field[i][x]==1){
				field[i][x]=0;
				home--;
				path[psize]=make_pair(i,x);
				psize++;
				dfs(x,i);
				psize--;
				home++;
				field[i][x]=1;
				break;
			}
		}

		for(int i = x-1; i >= 0; i--){
			if(field[y][i]==1){
				field[y][i]=0;
				home--;
				path[psize]=make_pair(y,i);
				psize++;
				dfs(i,y);
				psize--;
				home++;
				field[y][i]=1;
				break;
			}
		}
		for(int i = x+1; i < m; i++){
			if(field[y][i]==1){
				field[y][i]=0;
				home--;
				path[psize]=make_pair(y,i);
				psize++;
				dfs(i,y);
				psize--;
				home++;
				field[y][i]=1;
				break;
			}
		}
	}

}

int main(){

	while(cin>>m>>n&&!(n==0&&m==0)){
		psize=0;
		home=0;
		cnt=0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				cin>>field[i][j];
				if(field[i][j]==2){
					kx=j;
					ky=i;
				}
				else if(field[i][j]==1)
					home++;
			}
		}
		dfs(kx,ky);
		cout<<cnt<<endl;
	}
	return 0;
}

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

int main(){
	int N;
	string S,T;
	string R;

	cin >> N >> S >> T;

	for(int i = 0; i< N ; i++){
		R += S[i];
		R += T[i];
	}
	cout << R << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int x, y, z;
int n;
int e[51];
int a[51];
int l[4];
const int MAX_M = 5001;
double table[51][MAX_M];

int main() {
	while(cin>>x>>y>>z, x|y|z) {
		memset(e, 0, sizeof(int) * 51);
		memset(a, 0, sizeof(int) * 51);
		memset(&table[0][0], 0, sizeof(double) * 51 * MAX_M);

		rep(i,x) cin>>l[i];
		rep(i,z) {
			cin>>n;
			cin>>e[n]>>a[n];
		}

		table[0][0] = 1.0;
		rep(i,y) {
			rep(m, MAX_M) {
				if(table[i][m] == 0.0) continue;

				rep(j,x) {
					int np = min(y, i+l[j]);
					int nm = m;
					if(e[np] == 1) {
						np = min(y, np+a[np]);
					} else if(e[np] == 2) {
						nm = nm + a[np];
					} else if(e[np] == 3) {
						nm = max(0, nm - a[np]);
					} 

					table[np][nm] += table[i][m] / x;
				}
			}
		}

		double s = 0.0;
		rep(m,MAX_M) {
			s += m * table[y][m];
		}
		printf("%d\n", (int)s);
	}
}

Measured memory_bytes: 3144
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int k;
    cin >> k;
    queue<long long> q;
    for (int i = 1; i <= 9; i++) { q.push(i); }
    while (true) {
        if (k == 1) {
            cout << q.front() << endl;
            break;
        }
        long long front;
        front = q.front();
        q.pop();
        k--;
        if (front % 10 == 9) {
            q.push(10 * front + 8);
            q.push(10 * front + 9);
        } else if (front % 10 == 0) {
            q.push(10 * front);
            q.push(10 * front + 1);
        } else {
            long long x = front % 10;
            q.push(10 * front + x - 1);
            q.push(10 * front + x);
            q.push(10 * front + x + 1);
        }
    }
    return 0;
}

Measured memory_bytes: 1792
H,W=list(map(int,input().split()))
l=list(map(int,input().split()))
l=[i*-1 for i in l]
import heapq
B=0
heapq.heapify(l)
for i in range(H):
   A=heapq.heappop(l)
   A+=1
   heapq.heappush(l,B)
   B=A
   l=[i for i in l if i!=0]
   if len(l)==0:
      print(H-1-i)
      exit()

Measured memory_bytes: 9224
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
  ll n,k; cin>>n>>k;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n,greater<int>());
  ll an = 0;
  for(int i=k; i<n; i++) {
    an += a[i];
  }
  cout<<an<<endl;
}

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

int h,n;
int a[100005];

int main(){

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

    cin>>h>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        h-=a[i];
    }
    if(h>0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

    return 0;
}

Measured memory_bytes: 640
from bisect import bisect_left
A, B, Q, *L = map(int, open(0).read().split())
s = L[:A]
t = L[A:A+B]
x = L[A+B:]

s = [-float('inf')]+s+[float('inf')]
t = [-float('inf')]+t+[float('inf')]
for c in x:
  br = bisect_left(t,c)
  ar = bisect_left(s,c)
  bl = br-1
  al = ar-1
  print(min(s[ar]-t[bl]+min(s[ar]-c,c-t[bl]),t[br]-s[al]+min(t[br]-c,c-s[al]),
            c-min(t[bl],s[al]),max(s[ar],t[br])-c))

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

using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> mp(n + 10, 0);
    mp[0] = 1;
    for (int i = 0; i <= n; i++) {
      for (int k = 1; k <= 3; k++) {
	mp[i + k] += mp[i];
      }
    }
    cout << (mp[n] + 3649) / 3650 << endl;
  }
  return 0;
}

Measured memory_bytes: 3040
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// const int MAXN = 55;
// int n,m,q,cnt=0,ans;
// int a[MAXN],b[MAXN],c[MAXN],d[MAXN];

// void rec(int pos, int pre, vi &v){
//   if(v.size()==n){
//     cnt++;
//     int score = 0;
//     for(int i=1;i<=q;i++){
//       if(v[b[i]]-v[a[i]]==c[i])score+=d[i];
//     }
//     ans = max(ans,score);
//     return;
//   }
//   for(int i=pre;i<=m;i++){
//     v.pb(i);
//     rec(pos+1,i,v);
//     v.pop_back();
//   }

// }

int a,b,n;

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

  cin >> a >> b >> n;
  int best = min(b-1,n);
  int a1 = (a*best)/b;
  int a2 = (a*(best/b));
  cout << (a1-a2) << endl;

return 0;
}
///....


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
#include <cmath>
int A[200000];

int main()
{
int N;
cin >> N ;
for (long long i=0;i<N;i++)
{
	cin >> A[i];
}	
long long b=A[0];
long long c=0;
for (int i=1;i<N;i++)
{
	c = c+A[i]; 
}
long long min = abs(c-b);	
for (int i=1;i<N-1;i++){
b= b+A[i];
c= c-A[i]; 
if(abs(c-b)<min) min=abs(c-b); 
} 
cout << min << endl; 
return 0;	
}

Measured memory_bytes: 1024
n = int(input())
A = list(list(map(int, input().split())) for _ in range(n))

dp = [[0] * 3 for _ in range(n + 1)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + A[i][k])

print(max(dp[n]))


Measured memory_bytes: 50128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int pre[100005];
int main()
{
   	int a , b;
  	cin >> a >> b;
  	if(b % a == 0)
      cout << a + b << endl;
  	else
      cout << b - a << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int a, b;
  cin >> a >> b;
  if (a < 9 && b < 9)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;

  return 0;
}

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100005
#define INF 0x3f3f3f3f 
#define mod 1000000007
using namespace std;
typedef long long ll;
ll ans, res; 

void print(bitset<64> bs){
    ll res = 0;
    for(int i=0; i<64; i++) if(bs[i] == 1) res+=pow(2,i);
    cout << res << endl;
}

int main(){
    int n, k;
    cin >> n >> k;
    ll arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    vector <ll> v;
    for(int i=0; i<n; i++){
        ll cntr = arr[i];
        v.push_back(cntr);
        for(int j=i+1; j<n; j++){
            cntr+=arr[j];
            v.push_back(cntr);
        }
    }
    for(int i=40; i>=0; i--){
        ans+=(1ll<<i);
        int cntr = 0;
        for(int j=0; j<v.size(); j++) if((v[j]&ans) == ans) cntr++;
        if(cntr < k) ans-=(1ll<<i);
    }
    cout << ans;
    return 0;
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code
int co[100];

int main()
{
  int n, m;
  cin>>n>>m;
  rep(i, 0, m)
  {
    int a, b;
    cin>>a>>b;
    co[a]++;
    co[b]++;
  }
  repn(i, 1, n)
  {
    cout<<co[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 12160
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    ret = min(B // A, C)
    print(ret)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
using graph = vector<vector<int>>;

int main(){
    vector<int> memo(102);
    int x, n; cin >> x >> n;
    for(int i=0; i<n; ++i){
        int p; cin >> p;
        memo[p]++;
    }
    int res = x, d = 1000;
    for(int i=0; i<102; ++i){
        if(memo[i]==1){continue;}
        if(memo[i]==0){
            if(d>abs(x-i)){d = min(d, abs(x-i)); res = i;}
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
from operator import itemgetter

N = int(input())
T, A = map(int,input().split())
H = list(map(int, input().split()))

L = []
for i in range(N):
    L.append([i+1,abs(T-H[i]*0.006-A)])
L = sorted(L, key=itemgetter(1))

print(L[0][0])


Measured memory_bytes: 3188