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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> lb(n+1, vector<ll>(3, -1)), ub(n+1, vector<ll>(3, INF));
  REP(i, m) {
    ll l, r, x;
    cin >> l >> r >> x;
    chmax(lb[r][x-1], l);
    chmin(ub[r][x-1], l);
  }

  ll ret = 0;
  auto dp = make_v<ll>(n+1, n+1, n+1);
  dp[0][0][0] = 1;
  REP(r, n+1) REP(g, n+1) REP(b, n+1) {
    vector<ll> tmp({r, g, b});
    sort(ALL(tmp));

    if(lb[tmp[2]][2] > tmp[0]
      || ub[tmp[2]][1] <= tmp[0]
      || lb[tmp[2]][1] > tmp[1]
      || ub[tmp[2]][0] <= tmp[1])
    {
      dp[r][g][b] = 0;
      continue;
    }

    if(tmp[2] == n) (ret += dp[r][g][b]) %= MOD;
    else {
      (dp[tmp[2]+1][g][b] += dp[r][g][b]) %= MOD;
      (dp[r][tmp[2]+1][b] += dp[r][g][b]) %= MOD;
      (dp[r][g][tmp[2]+1] += dp[r][g][b]) %= MOD;
    }
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 219008
import sys
input=sys.stdin.buffer.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
N = int(input())
A = list(map(int,input().split()))
ans = [0]*N
for i in range(N):
    ans[A[i]-1] = i+1
print(" ".join(map(str,ans)))

Measured memory_bytes: 59164
def resolve():
    S = input()
    K = int(input())
    N = len(S)

    ST = set()
    for i in range(N):
        for j in range(1, K + 1):
            s = S[i:i + j]
            ST.add(s)

    ans = sorted(ST)
    print(ans[K - 1])


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 10332
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);

  int s[n] , k = 0 , min = 101;
  for(int i = 0;i < n;i ++){
    scanf("%d",&s[i]);
    k += s[i];
    if(s[i]%10 == 0){
      s[i] = 101;
    }
    if(min > s[i]){
      min = s[i];
    }
  }

  int ans = k;
  if(k%10 == 0){
    if(min == 101){
    ans = 0;
    }
    else{
      ans = k - min;
    }
  }
  
  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        sc.close();

        if (X == 2) {
            System.out.println(X);
            return;
        }
        int ans = X;
        for (int x = X; x < X * 2; x++) {
            if (x % 2 == 0) continue;
            int sqrt = (int) Math.sqrt(x);
            boolean s = false;
            for (int j = 3; !s && j <= sqrt; j += 2) {
                if (x % j == 0) s = true;
            }
            if (!s) {
                ans = x;
                break;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
#define input(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,p,q,ans=0;
vl v,v1,v2;
vp pp;
string s;
vector<string> ss;
ll solve(){
    a=0;
    rep(i,n){
        a=a^v[i];
    }
    if(a==0){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    input(v,n);
    solve();
}

Measured memory_bytes: 1400
import std.stdio, std.string, std.conv, std.algorithm;
void main()
{
  auto t = readln.chomp.to!int;
  while(t--){
    int u,d;
    auto n = readln.chomp.to!int;
    auto a = readln.split.map!(to!int);
    for(int i;i<n-1;++i){
      int b = a[i+1]-a[i];
      if(b>=0)
	b>u ? u=b:u=u;
      else
	-b>d ? d=-b:d=d;
    }
    writeln(u," ",d);
  }
}

Measured memory_bytes: 2444
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a <= c && c <= b) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    rep(i,n)cin>>in[i];
    int out=0;
    while(1){
      bool h=true;
      rep(i,in.size())if(in[i]!=i+1)h=false;
      if(h)break;
      if(out==12000)break;
      int co=0;
      rep(i,in.size())if(in[i]){in[i]--;co++;}
      in.pb(co);
      rep(i,in.size())if(in[i]==0){in.erase(in.begin()+i);i--;}
      out++;
    }
    if(out>10000)cout<<-1<<endl;
    else cout<<out<<endl;

  }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans;
  cin >> n;
  if (n < 10) ans = n;
  else if (n < 100) ans = 9;
  else if (n < 1000) ans = n - 90;
  else if (n < 10000) ans = 909;
  else if (n < 100000) ans = n - 9090;
  else ans = 90909;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<map>
#include<cctype>
#include<sstream>
using namespace std;
#define N 100005
int n, k;
int le[N],ri[N];
int a;
int lcnt = 1, rcnt = 1;
int x1, x2;
int ans1 = 0, ans = 1<<30;
int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		if (a >= 0)
			ri[rcnt++] = a;
		else
			le[lcnt++] = -a;
	}
	sort(le, le + lcnt);
	for (int i = 0;i < lcnt && i<=k;i++)
	{
		if (k - i < rcnt)
		{
			ans1 = 2 * le[i] + ri[k - i];
			ans = min(ans1, ans);
		}
	}
	for (int i = 0;i < rcnt && i <= k;i++)
	{
		if (k - i < lcnt)
		{
			ans1 = 2 * ri[i] + le[k - i];
			ans = min(ans1, ans);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	

	using namespace std;
	ll t = -1;
	ll dp[105][100005] = {t};

	ll knapsack(vector<vector<ll>> &v, ll n, ll W) {
		if(n<0) {
			return 0;
		}

		if(dp[n][W] != 0) {
			return dp[n][W];
		}

		if(v[n][0] > W) {
			dp[n][W] = knapsack(v,n-1,W);
			return dp[n][W];
		}
		ll f = v[n][1] + knapsack(v,n-1,W-v[n][0]);
		ll s = knapsack(v,n-1,W);
		dp[n][W] = max(f,s);

		return dp[n][W];
	}



	int main()
	{
		std::ios::sync_with_stdio(false);
		
		ll n,W;
		cin>>n>>W;

		vector<vector<ll> > v;

		for(ll i=0; i<n; i++) {
			ll a,b;
			cin>>a>>b;
			v.push_back({a,b});
		}
		cout<<knapsack(v,n-1,W)<<endl;		

		return 0;
	}


Measured memory_bytes: 80128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector<vector<int> > g;
vector<vector<int> > c;
int N, T, S, E;
vector<int>A;
bool found = false;
void dfs1(int a, int p = -1) {
	if (a == S) {
		found = true;
		return;
	}
	for (int i = 0; i < g[a].size(); i++) {
		if (p != g[a][i]) {
			A[a] = g[a][i];
			dfs1(g[a][i], a);
			if (found) {
				break;
			}
		}
	}

}

bool start = false;
bool ok = true;
void dfs2(int a, int p, int C) {
	//cerr << a + 1 << " " << C << endl;
	int times = 0;
	if (!start && a == S) {
		start = true;
	}
	else if(start){
		
		times++;
	}
	vector<pair<int, int> > vp;
	for (int i = 0; i < g[a].size(); i++) {
		if (p != g[a][i]) {
			vp.emplace_back(c[a][i] - T * (g[g[a][i]].size()), i);
		}
	}
	if (!start) {
		for (int i = 0; i < vp.size(); i++) {
			if (g[a][vp[i].second] == A[a]) {
				swap(vp[i], vp.back());
				vp.pop_back();
			}
		}


		for (int i = 0; i < g[a].size(); i++) {
			if(g[a][i] == A[a]){
				dfs2(A[a], a, c[a][i]);
			}
		}
		times++;
	}
	
	sort(vp.begin(), vp.end());
	for (int ii = 0; ii < vp.size(); ii++) {
		int i = vp[ii].second;
		dfs2(g[a][i], a, c[a][i] - T * times);
		times++;
	}
	if (C - T * times <= 0) {
		//cerr << a + 1 << " " << times << endl;
		ok = false;
	}
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> T >> S >> E;
	S--; E--;
	g.resize(N);
	c.resize(N);
	A.resize(N, -1);
	int res = 0;
	int a, b, cost;
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b >> cost; a--; b--;
		g[a].push_back(b);
		c[a].push_back(cost);
		g[b].push_back(a);
		c[b].push_back(cost);
	}
	dfs1(E);

	int INF = (int)1 << 60;
	dfs2(E, -1, INF);
	if (ok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 26548
def cut(N):
    if N % r == 0:
        return N // r - 1
    else:
        return N // r
def solve(l):
    global r
    r = l
    b = list(map(cut, a))
    if sum(b) > k:
        return False
    else:
        return True
n, k = map(int, input().split())
a = list(map(int, input().split()))
u = max(a)
s = 0
while s + 1 < u:
    if solve((u + s) // 2):
        u = (u + s) // 2
    else:
        s = (u + s) // 2
print(u)

Measured memory_bytes: 168372
#include<bits/stdc++.h>
using namespace std;
namespace io{
    const int l=1<<20;
    char buf[l],*s,*t,c;
    inline void gc(){
        if(s==t){
            t=(s=buf)+fread(buf,1,l,stdin);
            c=s==t?EOF:*s++;
        }else c=*s++;
    }
    template<class IT>inline void gi(IT &x){
        x=0;gc();while(c<'0'||c>'9')gc();
        while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);gc();}
    }
    char buf0[20];int a;
    template<class IT>inline void pi(IT x){
        if(x<0){putchar('-');x=-x;}
        do buf0[++a]=x%10+48;while(x/=10);
        while(a)putchar(buf0[a--]);
        putchar('\n');
    }
};
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
typedef vector<int> vi;
typedef vector<ll > vl;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const ll zjc=1000000007ll,pp=zjc*zjc;
const int N=200005;
inline ll expo(ll a,int b=1000000005){
	ll c=1ll;
	while(b){
		if(b&1)c=c*a%zjc;
		b>>=1; a=a*a%zjc;
	}
	return c;
}
ll ifa[N];
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k,i;ll f2,fn=1ll,s=0ll;
    scanf("%d%d",&n,&k);cmin(k,n-1);
	REP(i,2,n)fn=fn*i%zjc;
	f2=fn;
	f2=f2*(fn=fn*i%zjc)%zjc;
	ifa[n]=expo(fn);
	per(i,n,1)ifa[i-1]=ifa[i]*i%zjc;
    rep(i,k==1,k)if((s+=(ifa[i]*ifa[n-i]%zjc)*(ifa[i]*ifa[n-(i+1)]%zjc))>=pp)s-=pp;
	printf("%lld",f2*(s%zjc)%zjc);
    return 0;
}

Measured memory_bytes: 1792
n=int(input())
t,a=list(map(int,input().split(" ")))
h=list(map(int,input().split(" ")))

list_=[]
for count in range(n):
    list_.append(abs(a-t+0.006*h[count]))
i=0
while i<=n-1:
    if list_[i]==min(list_):
        print(i+1)
        break
    else:
        i+=1

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

int main(){
    int n, ary[100], sum = 0;
    cin >> n;
    rep(i, n){
        cin >> ary[i];
        sum += ary[i];
    }
    if(sum % 10 == 0){
        sort(ary, ary + n);
        rep(i, n){
            if(ary[i] % 10){
                sum -= ary[i];
                break;
            }
        }
    }
    cout << (sum % 10 ? sum : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}
/*
範囲が制限されたn個の数字の列が取り得る中央値の数
nが偶数の時、中央二つの数の平均が中央値となる。

中央値に絡む数
ある数が中央値になり得るか？の判定

bの数列を二分探索して

非連結になることはなさそう。
偶数の場合二倍したうえで、最大値－最小値＋1をすれば良さそう



*/

int main()
{
    int n;
    cin >> n;
    vector<ll> a;
    vector<ll> b;
    rep(i, n){ 
        ll ta, tb;
        cin >> ta >> tb; 
        if ((n%2)==0){
            ta*=2, tb*=2;
        }
        a.push_back(ta);
        b.push_back(tb);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    ll amin, bmin;
    if (n%2 == 0){
        amin = a[(n/2)] + a[(n/2)-1];
        bmin = b[(n/2)] + b[(n/2)-1];
        amin /= 2;
        bmin /= 2;    
    } else {
        amin = a[n/2];
        bmin = b[n/2];
    }
    cout << bmin - amin + 1 << endl;

}



Measured memory_bytes: 6636
import numpy as np
A,B,H,M = (int(x) for x in input().split())
argA = 30*H + 0.5*M
argB = 6*M
if argA>argB:
    arg = argA-argB
else:
    arg = argB-argA
    
if arg > 180:
    arg = 360 - arg
    
cc = A**2 + B**2 -2*A*B*np.cos((arg/180)*np.pi)
c = np.sqrt(cc)

print(c)

Measured memory_bytes: 27188
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S, T;
	static int SS[100010] = {}, TS[100010] = {}, Q, A, B, C, D;
	cin >> S >> T >> Q;
	for (int i = 0; i < S.size(); i++) SS[i + 1] = SS[i] + (S[i] == 'B') + 1;
	for (int i = 0; i < T.size(); i++) TS[i + 1] = TS[i] + (T[i] == 'B') + 1;
	for (int i = 0; i < Q; i++) {
		cin >> A >> B >> C >> D;
		if ((SS[B] - SS[A - 1]) % 3 == (TS[D] - TS[C - 1]) % 3) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

int main(){
    int n;
    cin >> n;
    vector<int> number(n);
    for (int i = 0; i < n; i++) {
        cin >> number[i];
    }
    map<int, int> display;
    for (int i = 1; i <= n; i++) {
        display[i] = 0;
    }

    for (int i = 1; i <= n; i++) {
        display[number[i-1]] = i;
    }

    for (int i = 1; i <= n; i++) {
        if(i > 1) cout << " ";
        cout << display.at(i);
    }
    cout << endl;
} 

Measured memory_bytes: 5888
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

   rep(i,s.size()){


      if(ans.size() != 0){
         if(s[i] != 'B') ans.push_back(s[i]);
         else ans.pop_back();
      }else{
         if(s[i] != 'B') ans.push_back(s[i]);
      }

   }
   cout << ans << endl;





   return 0;
}

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

int main() {
  int N, t;
  cin >> N;
  t=0;
  for(int i=0; i<N; i++){
    int li, ri;
  	cin >> li >> ri;
  	t+= (ri-li+1);
}
  cout << t << endl;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int get(int n){
    if(n%2==0)return n/2;
    else return 3*n+1;
}
int main(){
    int n;
    cin>>n;
    for(int i=n;i<n+1000;i++){
        bool f=true;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                f=false;
                break;
            }
        }
        if(f==true){
            cout<<i;
            return 0;
        }
    }
}



Measured memory_bytes: 3608
import math
def find(now,S, F):
    if now<S:
         ans = S
    else:
         ans = math.ceil(now/F)*F
    return(ans)

n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-2):
    ans = csf[i][1];
    for j in range(i,n-2):
        ans = find(ans+csf[j][0],csf[j+1][1],csf[j+1][2])
    print(ans+csf[n-2][0])
if n!=1: print(csf[n-2][0]+csf[n-2][1])
print(0)

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

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	const T init;
	const F f;
	int sz;
	vector<T> seg;
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	void add(int id, T x){
		id += sz;
		seg[id] += x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

int64_t gcd(int64_t x, int64_t y) {
    return (y > 0 ? gcd(y, x % y) : x);
}

int main() {
    int n; cin >> n;
    SegmentTree<int> seg(n, 0, gcd);
    for(int i = 0; i < n; ++i) {
        int a; cin >> a;
        seg.replace(i, a);
    }
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        int l = (i > 0 ? seg.get(0, i) : 0);
        int r = (i < n - 1 ? seg.get(i + 1, n) : 0);
        ans = max(ans, (int)gcd(l, r));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> v(3); cin >> v;
    sort(v.begin(), v.end());
    cout << v[0] + v[1] << '\n';
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main(){
  int pos[5];
  int k;
  for(int i =0 ;i < 5;i++){
   cin>>pos[i]; 
  }
  cin >>k;
  
  for(int i = 0; i <5;i++){
   for(int j = i + 1;j < 5;j++){
     if( pos[j] - pos[i] > k){
       cout << ":(" <<endl;
       return 0;
     }
   }
  }
  cout <<"Yay!"<< endl;
  return 0; 
 
}

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

bool g[10][10];

int main() {
  int n,m;
  cin >> n >> m;
  rep(i,m) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    g[a][b] = true;
    g[b][a] = true;
  }

  std::vector<int> v(n);
  rep(i,n) v[i] = i;

  int res = 0;

  do {
    if (v[0] != 0) break;

    bool ok = true;
    rep(i,n-1) if (!g[v[i]][v[i+1]]) ok = false;
    if (ok) res++;
  } while (next_permutation(v.begin(), v.end()));

  cout << res << endl;
}


Measured memory_bytes: 3632
S = list(input())
K = int(input())
S2 = S[:]

if len(S) == 1:
    print(K//2)
    exit()
cons = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cons += 1
        S[i+1] = '_'
if K == 1:
    print(cons)
    exit()
if S[0] != S[-1]:
    print(cons * K)
    exit()
cons3 = 0
if len(set(S2)) == 1:
    S2 = S2 * 2 + ['']
    for i in range(len(S2) - 1):
        if S2[i] == S2[i+1]:
            cons3 += 1
            S2[i+1] = '_'
    print(cons3 * (K//2) + cons * (K%2))
    exit()
# 最初から何文字連続するか
# この時最後の連続する文字はすでに奇数でかつ最初の文字と一緒
cons2 = 1
j = 0
while True:
    if S2[j] == S2[j+1]:
        cons2 += 1
        j += 1
    else:
        break
if cons2 % 2 == 0:
    minus = 0
else:
    minus = 1
print(cons * K + minus * (K-1) )


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

typedef long long ll;

int main() {
  string s; cin >> s;
  int K; cin >> K;
  char ch;
  int cnt=0;
  for ( int i = 0; i < s.length(); i++ ) {
    if ( s[i] == '1' ) {
      cnt++;
    } else {
      ch = s[i];
      break;
    }
  }

  if ( cnt >= K ) cout << '1' << endl;
  else cout << ch << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
// ミント
const int mod = 1e9+7 ;
  //998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
}  ;
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }
 

int main(){
  ll  n; cin>> n ;
  vector<ll> A(n) ;
  rep(i,n) cin>>A[i] ;
  sort(A.rbegin(),A.rend()) ;
  bool ok=1 ;
  if(A[0]!=n-1) ok=0 ;
  rep(i,n-1){
   if(i%2==0){
    if(A[i]!=A[i+1]) ok= 0 ;
   }
   else{
    if((A[i]-2)!=A[i+1]) ok=0 ;
   }
  }
  if(!ok) cout<<0<<endl ;
  else{
    mint ans= modpow(2ll,(n/2)) ;
    cout<<ans<<endl ;
  }
    return 0;
  }
   



Measured memory_bytes: 3968
from collections import deque
from itertools import product
H,W = map(int,input().split())

S = ["#"*(W+2)]
for i in range(H):
    S.append("#"+ input() + "#")
S.append("#"*(W+2))

H += 2
W += 2

max_dist = 0
for sy,sx in product(range(1,H),range(1,W)):
    dist = [[H*W+1]*W for i in range(H)]
    if S[sy][sx] == "#":
        continue
    dq = deque([(sy,sx)])
    dist[sy][sx] = 0
    while dq:
        py,px = dq.popleft()
        for ny, nx in [(py+1,px),(py-1,px),(py,px+1),(py,px-1)]:
            if S[ny][nx] == "#":
                continue
            if dist[ny][nx] > dist[py][px] + 1:
                dist[ny][nx] = dist[py][px] + 1
                max_dist = max(max_dist, dist[ny][nx])
                dq.append((ny,nx))
    #list(map(lambda x:print(x), dist))
    #print()

print(max_dist)










Measured memory_bytes: 44892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////


int main() {

	long long N, K;
	cin >> N >> K;
	
	N = N % K;

	if (N > K - N)cout << K - N << endl;
	else cout << N << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int A,B;

    cin >> A >> B;

    if(A<=8&&B<=8){
        cout << "Yay!" <<endl;
    }else{
        cout << ":(" <<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
string a;
int q,w;
int main() 
{ 
cin>>a;
for(int i=0;i<a.size();i++)
if(a[i]=='C')q=i+1;
for(int i=q;i<a.size();i++)
if(a[i]=='F')w++;
if(q!=0&&w!=0)cout<<"Yes";
else cout<<"No";
return 0; 
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n1,n2;
    string s,t;
    cin >> s;
    cin >> t;
    n1 = s.length();
    n2 = t.length();
    int dp[n1]={0};
    int nax=0;
    if(n2==0) return 0;
    for(int i=0;i<n1-n2+1;i++){
        int count =0;
        for(int j=0;j<n2;j++){
            if(s[i+j]==t[j]) count++;
        }
        nax = max(nax,count);
    }
    //cout << endl;
    cout << n2-nax;
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(){
	int N,K;
	scanf("%d%d",&N,&K);
	int ans = 1;
	for(int i = 0; i < N; i++){
		if(ans + K < ans * 2)ans += K;
		else ans += ans;
	}
	printf("%d",ans);
}

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

int main(){
  vector<long long> v;
  int n, a, b;
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    long long k;
    cin >> k;
    v.push_back(k);
  }
  sort(v.begin(), v.end());
  long long t = 0;
  long long prev = 0;
  int c = 0; int d = 0; int e = 0;
  for (int i = n-1; i >= 0; i--) {
    if (prev != v[i]) {
      if (d != 0) break;
      prev = v[i];
      c = 1;
    } else {
      c++;
    }
    e++;
    if (i >= n-a) t += v[i];
    if (i == n-a) d = c;
  }
  //cout << c  << " " << d << " " << e << endl;
  printf("%.8f\n", (double) t / a);
  if (c == e) {
    long long ans = 0;
    long long comb = 1;
    for (int i = 0; i < min(b, e); i++) {
      comb *= c - i;
      comb /= i+1;
      if (i >= a-1) ans += comb;
    }
    cout << ans << endl;
  } else {
    long long comb = 1;
    for (int i = 0; i < d; i++) {
      comb *= c - i;
      comb /= i+1;
    }
    cout << comb << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
#a = int(input())
#n,a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
#string1 = input()
#string2 = input()
#ls = [int(input()) for i in range(n)]

ans = []
for i in ls:
  tmpnum = i
  tmp = 0
  for j in range(30):
    if (tmpnum%2 == 0):
        tmpnum = tmpnum//2
        tmp += 1
  ans.append(tmp)
print(min(ans))

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
using namespace std;

const int INF = 1000000000;

int main(){
  int n,m,d[1001],c[1001];
  int dp[1001];
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++) scanf("%d",d+i);
  for(int i=0;i<m;i++) scanf("%d",c+i);
  fill(dp,dp+n+1,INF);
  dp[0] = 0;
  for(int i=1;i<=m;i++){
    for(int j=n;j>=0;j--){
      dp[j] = min(dp[j],dp[j-1]+c[i-1]*d[j-1]);
    }
  }
  printf("%d\n",dp[n]);
  return 0;
}

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

typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 1e5 + 10;
int n, a[N];

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);

    LL s1 = 0, sum = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 2 == 1 && sum + a[i] <= 0) {
            s1 += 1 - sum - a[i];
            sum = 1;
        }
        else if (i % 2 == 0 && sum + a[i] >= 0) {
            s1 += sum + a[i] + 1;
            sum = -1;
        }
        else sum += a[i];
    }
    LL s2 = 0; sum = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 2 == 0 && sum + a[i] <= 0) {
            s2 += 1 - sum - a[i];
            sum = 1;
        }
        else if (i % 2 == 1 && sum + a[i] >= 0) {
            s2 += sum + a[i] + 1;
            sum = -1;
        }
        else sum += a[i];
    }

    cout << min(s1, s2);
    return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline


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

import itertools
PERMUTATIONS = list(itertools.permutations(range(1, n + 1)))

a = PERMUTATIONS.index(p) + 1
b = PERMUTATIONS.index(q) + 1

ans = abs(a - b)
print(ans)


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int count=0;
  string s; cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]=='R') count++;
  }
  if(count==2 &&s[1]=='S') cout<<count-1<<endl;
  else cout<<count<<endl;
return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <memory.h>

int main()
{
    char S[16];
    int n[26];

    memset( n, 0, 26*sizeof(int) );    

    scanf( "%s", S );

    for ( int i = 0; i < 4; i ++ ) n[S[i]-'A'] ++;

    int c = 0;
    for ( int i = 0; i < 26; i ++ ) {
        
        if ( n[i] == 2 ) c ++;
    }

    if ( c == 2 ) printf( "Yes\n" );
    else printf( "No\n" );


    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S{
  int idx, val;
  double score;
  S(int i, int v, double s) :
    idx(i), val(v), score(s) {}
  bool operator < (const S& st) const {
    if(score != st.score) return score > st.score;
    if(idx != st.idx) return idx < st.idx;
    return val > st.val;
  }
};

int main(){
  int N;
  while(cin>>N && N){
    int a[20];
    REP(i, N) cin>>a[i];
    priority_queue<S> que;
    FOR(v, 1, 200001) que.push(S(1, v, (double)abs(a[0] - v) / a[0]));
    while(!que.empty()){
      S s = que.top(); que.pop();
      if(s.idx == N){
        printf("%.12f\n", s.score);
        break;
      }
      for(int k = 1; k * s.val <= 200000; k++){
        int nv = k * s.val;
        que.push(S(s.idx + 1, nv, max(s.score, (double)abs(a[s.idx] - nv) / a[s.idx])));
      }
    }
  }
  return 0;
}

Measured memory_bytes: 19236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int a; cin >> a;
    pr(a + a*a + a*a*a);
    return 0;}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  int N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;

  int flag = 0;
  //岩が2連続になっていたらNo
  FOR(i,A-1,D){
    if(S.at(i)=='#'&&S.at(i+1)=='#'){
      flag = 1;
      break;
    }
  }

  //C>Dの時にB-1以降D+1以前に...がないとNo
  if(C>D){
    int flag2 = 0;
    FOR(i,B-2,D-1){
      if(S.at(i)=='.'&&S.at(i+1)=='.'&&S.at(i+2)=='.'){
        flag2 = 1;
      }
    }
    if(flag2 == 0){
      flag = 1;
    }
  }

  if(flag == 1){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 640
#include<stdio.h>
int convert(char c){
  if(c == 'a'){
    return 0;
  }else if(c == 'b'){
    return 1;
  }else if(c == 'c'){
    return 2;
  }
}
  
int main(){
  char str[3][200] = {};
  int t[3] = {}; //文字列の数
  int p[3] = {}; //位置
  int turn = 0;
  int i = 0;
  int j = 0;
  int win = -1;
  for(i=0;i<3;i++){
    scanf(" %s",str[i]);
  }
  for(j=0;j<3;j++){
    for(i=0;i<200;i++){
      if(str[i] != '\0'){
        t[j]++;
      }else{
        break;
      }
    }
  }
  while(1){
    p[turn]++;
    turn = convert(str[turn][p[turn]-1]);
    for(i=0;i<3;i++){
      if(p[i] == t[i]){
        win = i;
        break;
      }
    }
    if(win != -1){
      break;
    }    
  }
  if(win == 0){
    printf("A");
  }else if(win == 1){
    printf("B");
  }else if(win == 2){
    printf("C");
  }
  return 0;
}
  
  
      
      
  

Measured memory_bytes: 128
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

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

int main()
{
	int tri[31];
	tri[0] = tri[1] = 1;
	tri[2] = 2;
	reep(i, 3, 31)
		tri[i] = tri[i-1] + tri[i-2] + tri[i-3];
	
	int n;
	while(scanf("%d", &n), n){
		printf("%d\n", (tri[n]+3649)/3650);
	}
	
	return 0;
}

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

int main() {
    string N;
    cin >> N;
    if(N[0] == '7' || N[1] == '7' || N[2] == '7'){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3624
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input!{
        n: usize,
        m: usize,
        h: [usize; n],
        ab: [(Usize1, Usize1); m],
    };
    let mut ma = vec![0; n];
    for i in 0..m{
        let a:usize = ab[i].0;
        let b:usize = ab[i].1;

        ma[a] = std::cmp::max(ma[a], h[b]);
        ma[b] = std::cmp::max(ma[b], h[a]);
    }
    let mut ans = 0;
    for i in 0..n{
        if h[i] > ma[i] {
            ans += 1;
        }
    }
    println!("{}", ans);

}


Measured memory_bytes: 7340
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <set>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
typedef struct Point_Coordinates {
	int i, j;
	friend Point_Coordinates operator+(const Point_Coordinates& l, const Point_Coordinates& r) {
		return { l.i + r.i, l.j + r.j };
	}
} point;

void DFS(point n, int k, vector<string>& s, vector<vector<int>>& d) {
	int i;
	point dn[4] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };
	d[n.i][n.j] = k;
	rep(i, 4) {
		point a = n + dn[i];
		if (s[a.i][a.j] == '.' && d[a.i][a.j] == 0)
			DFS(a, k, s, d);
	}
	return;
}

int Divide(vector<string>& s, vector<vector<int>>& d) {
	int i, j, k = 1;
	for (i = 1; i < s.size(); i++) {
		for (j = 1; j < s[i].size(); j++) {
			if (s[i][j] == '.' && d[i][j] == 0) {
				DFS({ i, j }, k, s, d);
				k++;
			}
		}
	}
	return k;
}

void Solve(int s, int dep, vector<set<int>>& d, vector<int> & ans) {
	queue<int> que;
	ans[s] = 0;
	que.push(s);
	while (!que.empty()) {
		s = que.front();
		que.pop();
		for (auto it = d[s].begin(); it != d[s].end(); it++) {
			if (ans[*it] == INF) {
				ans[*it] = ans[s] + 1;
				que.push(*it);
			}
		}
	}
}

int main(void) {
	int num, i, j, h, w, k;
	point s, e;
	cin >> h >> w;
	cin >> s.i >> s.j >> e.i >> e.j;
	vector<string> m(h + 2, string(w + 2, '#'));
	vector<vector<int>> d(h + 2, vector<int>(w + 2, 0));
	for (i = 1; i <= h; i++) {
		cin >> m[i];
		m[i] = "#" + m[i] + "#";
	}
	k = Divide(m, d);
	vector<set<int>> st(k);
	for (i = 1; i < d.size(); i++) {
		for (j = 1; j < d[i].size(); j++) {
			if (d[i][j]) {
				for (int a = max(1, i - 2); a < min((int)d.size(), i + 3); a++) {
					for(int b = j; b < min((int)d[a].size(), j + 3); b++) {
						if (d[a][b] > 0 && d[a][b] != d[i][j]) {
							st[d[i][j]].insert(d[a][b]);
							st[d[a][b]].insert(d[i][j]);
						}
					}
				}
			}
		}
	}
	vector<int> ans(k, INF);
	Solve(d[s.i][s.j], 0, st, ans);
	if (ans[d[e.i][e.j]] == INF)
		printf("-1\n");
	else
		cout << ans[d[e.i][e.j]] << "\n";
	return 0;
}

Measured memory_bytes: 33896
#include<iostream>

using namespace std;

int main(){
	int H,W,i,j;
	for(;;){
		cin>>H>>W;
		if(H==0 && W==0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(i==0||i==H-1||j==0||j==W-1){
					cout<<"#";
				}else{
					cout<<".";
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ

		int count=0;
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int colors[] = new int[n];
		
		String color[] = br.readLine().split(" ");
		for(int i=0;i<n;i++) {
			colors[i] = Integer.parseInt(color[i]);
		}
		
		for(int i =0; i<n-1; i++) {
			if(colors[i] == colors[i+1]) {
				count++;
				try{
				if(colors[i+1]+1 != colors[i+2]) {
					colors[i+1] += 1;
				}else {
					colors[i+1] += 2;
				}
				}catch(Exception e) {
					colors[i+1]++;
				}
			}
		}
		System.out.println(count);
		
	}


}


Measured memory_bytes: 21204
n, k = gets.chomp.split.map(&:to_f)
res = 0.0
cur = n
i = k
coin = 1.0
while cur > 0
  if i <= cur
    d = cur + 1 - i
    cur -= d
    res += d * coin
  end
  i = (i / 2.0).ceil
  coin /= 2.0
end
puts "%.11f" % [res / n]

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

int main() {
    int k,a,b;
    cin >> k >> a >> b;
    for(int i=a;i<=b;i++){
        if(i%k == 0){
            cout << "OK" << endl;
            break;
        }
        if(i == b){
             cout << "NG" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3608
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
N = int(input())
A = list(map(int,input().split()))

ans = float("inf")
for d in range(-100,101):
    total = 0
    for i in range(N):
        total += (d-A[i])**2
    ans = min(ans,total)

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

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

void empty(int *, int *);
void swap(int *, int *);
int cal();
int dfs(int, int, int, int, int);

int main(){
  int i,j,k;
  int x,y,a;

  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&puzzle[i][j]);
    }
  }

  empty(&x,&y);

  for(k=0;k<100;k++){
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
	tmp[i][j]=puzzle[i][j];
      }
    }

    a=dfs(x,y,-1,0,k);
    if(a!=-1){
      printf("%d\n",a);
      break;
    }

    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
	puzzle[i][j]=tmp[i][j];
      }
    }
    
    a=-1;
    if(k==99) printf("%d\n",a);
  }

  return 0;
}

void empty(int *x, int *y){
  int i,j;

  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(puzzle[i][j]==0){
	*x=j;
	*y=i;
	return;
      }
    }
  }
}

void swap(int *a, int *b){
  int tmp;
  
  tmp=*a;
  *a=*b;
  *b=tmp;
}


int cal(){
  int i,x;
  int sum=0;

  for(i=0;i<9;i++){
    x=puzzle[i/3][i%3];
    if(x){
      x--;
      sum+=abs((i/3)-(x/3))+abs((i%3)-(x%3));
    }
  }

  return sum;
}

int dfs(int x,int y,int p,int dep,int limit){
  int i,h,nx,ny,res;

  h=cal();
  
  if(h==0) return dep;
  if(dep+h>limit) return -1;

  for(i=0;i<4;i++){
    nx=x+dx[i];
    ny=y+dy[i];

    if(~p && i==(p+2)%4) continue;
    if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;

    swap(&puzzle[y][x],&puzzle[ny][nx]);
    res=dfs(nx,ny,i,dep+1,limit);
    if(~res) return res;

    swap(&puzzle[y][x],&puzzle[ny][nx]);
  }

  return -1;
}



Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
int a[405];
LL dp[405][405];
LL sum[405];
LL getSize(int l, int r){
    return sum[r] - sum[l-1];
}
LL dfs(int s, int e){
    if(dp[s][e] != -1) return dp[s][e];
    if(e-s+1 <= 1) return 0;
    LL ans = 2e18;
    for(int i=s;i<e;i++){
        LL cost = 0;
        cost += dfs(s, i) + dfs(i+1, e);
        cost += getSize(s, i) + getSize(i+1, e);
        ans = min(ans, cost);
    }
    return dp[s][e] = ans;
}
int main(){
    memset(dp, -1, sizeof(dp));
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        sum[i] = sum[i-1] + a[i];
    }
    printf("%lld\n", dfs(1, n));
}


Measured memory_bytes: 1536
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

for i in range(N):
    ans += B[i]

for i in range(N - 1):
    if A[i] + 1 == A[i + 1]:
        ans += C[A[i] - 1]

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int nq;
    while(1){
        cin>>nq;
        if(nq==-1) break;
        double q=nq,x=q/2;
        while(!(abs(x*x*x-q)<0.00001*q)){
            x=x-(x*x*x-q)/(3*x*x);
        }
        printf("%.10f\n",x);
    }
}

Measured memory_bytes: 1176
#include <stdio.h>
#define MAX 101

int main(){
  int i,l,j,k,n,p[MAX],m[MAX][MAX];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
  }

  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=1<<21;
      for(k=i;k<=j-1;k++){
	if(m[i][j]<m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])m[i][j]=m[i][j];
	else m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }}}

  printf("%d\n",m[1][n]);
  return 0;
}



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

int main (void) {
  int N;
  int A[200000];
  unordered_set<int> us;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (us.find(A[i]) == us.end()) us.insert(A[i]);
    else {cout << "NO" << endl; return 0;}
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 9288