akhauriyash/Code-Regression huggingface dataset:
#include<iostream>                                        
#include<cmath>                                           
#include<cstdio>                                          
using namespace std;                                      
                                                          
int main(){                                               
  int n,A[1000];                                          
                                                          
  while(1){                                               
    cin >> n;                                             
    if(n == 0) break;                                     
                                                          
    for(int i=0;i<n;i++) cin >> A[i];                     
    int sum = 0;                                          
    for(int i =0;i<n;i++) sum += A[i];                    
    double avg = 1.0*sum/n;                               
    double dist = 0.0;                                    
    for(int i=0;i<n;i++){                                 
      dist += (avg-A[i])*(avg-A[i]);                      
    }                                                     
                                                          
    printf("%f\n",sqrt(dist/n));                          
  }                                                       
}

Measured memory_bytes: 3164
s = input()
t = input()

res = 10**10

for n in range(len(s)-len(t)+1):
    id = n
    ct = 0
    for k in range(len(t)):
        a = t[k]
        b = s[id]
        if a != b:
            ct += 1
        id += 1
    res = min(res, ct)

print(res)


Measured memory_bytes: 67620
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n , m;
    cin>>n>>m;
    priority_queue<int> data;
    for (int i = 0; i < n; ++i) {
        int v;
        cin>>v;
        data.push(v);
    }
    while(m != 0){
        int t = data.top();
        t /= 2;
        data.pop();
        data.push(t);
        m--;
    }
    int sum = 0;
    while(!data.empty()){
        sum += data.top();
        data.pop();
    }
    cout<<sum<<endl;

}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
  int n,i=0,cntr=0,cntb=0;
  string s;
  cin >> n >> s;
  for(;i<n;i++){
    if(s[i]=='B') cntb++;
    else cntr++;
  }
  puts(cntr>cntb?"Yes":"No");
}

Measured memory_bytes: 256
#n=int(input())
n,m=map(int,input().split())
#pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
solved_dic={}
pena_dic={}
for i in range(n):
    solved_dic[i+1]=False
    pena_dic[i+1]=0

pena=0
solved=0

for i in range(m):
    p,s=map(str,input().split())
    p=int(p)
    if s=="WA":
        if not solved_dic[p]:
            pena_dic[p]=pena_dic[p]+1        
    else:
        if not solved_dic[p]:
            solved+=1
            solved_dic[p]=True

for p in range(n):
    if solved_dic[p+1]:
        pena+=pena_dic[p+1]
print("{} {}".format(solved,pena))


Measured memory_bytes: 24212
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int a,b,c,x,y,ans;
  cin >> a >> b >> c >> x >> y;
  if (a+b > c*2){
    if (x<y){
      if (b<c*2) ans=c*2*x+b*(y-x);
      else ans=c*2*y;
    }else{
      if (a<c*2) ans=c*2*y+a*(x-y);
      else ans=c*2*x;
    }
  }else{
    ans=a*x+b*y;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const int mod=1e9+7;

ll a[maxn];
int pow(int x)
{
    ll sum=1;
    for(int i=1; i<=x; i++)
    {
        sum=sum*10;
    }
    return sum;

}
int main()
{
    ll n,num=0;
    cin>>n;
    ll m=n;
    while(n)
    {
        n=n/10;
        num++;
    }
    int s=0;
    if(num==1)
        cout<<m;
    else if(num%2==1)
    {
        for(ll i=num-1; i>=1; i=i-2)
        {
            s+=9*pow(i-2);
        }
    //cout<<s<<endl;
        cout<<m-pow(num-1)+1+s;
    }
    else if(num%2==0)
    {
        for(ll i=num; i>=1; i=i-2)
        {
            s+=9*pow(i-2);
        }
        cout<<s;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, count = 0;
  int D1, D2;
  
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> D1 >> D2;
    if(D1 == D2)count++;
    else count = 0;
    
    if(count == 3)break;
  }
  
  if(count == 3)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
require 'bigdecimal'
require 'bigdecimal/util'

$n = gets.chomp.to_i
$ans=0

def dfs(s)
  return if s.size >=10
  if s.include?('3') &&  s.include?('5') &&  s.include?('7') && s.to_i <= $n
    $ans+=1
  end
  dfs(s + '3')
  dfs(s + '5')
  dfs(s + '7')
end

dfs("")

puts $ans

Measured memory_bytes: 14484
#include<bits/stdc++.h>
using namespace std;
main()
{
	int t,n;
    scanf("%d%d",&n,&t);
    for(int i = 0;i <= n;i++)
    {
        for(int j = 0;j+i <= n;j++)
        {
            int cal=i*10000+j*5000+(n-i-j)*1000;
            if(cal==t)
            {
                printf("%d %d %d",i,j,n-i-j);
                return 0;
            }
        }
    }
    printf("-1 -1 -1");
}


Measured memory_bytes: 256
import itertools
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

l = [i for i in range(1, n + 1)]

v = list(itertools.permutations(l))

print(abs(v.index(p)-v.index(q)))


Measured memory_bytes: 8052
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	
	ans := "NO"
	for i := 1; i <= b; i++ {
		if (a * i) % b == c {
			ans = "YES"
			break
		}
	}
	fmt.Println(ans)
}

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

int main()
{
    unsigned long long n, a, b;
    cin >> n >> a >> b;

    // cout << n << endl;
    unsigned long long times = n / (a + b);
    // cout << times << endl;
    unsigned long long num_a = times * a;
    unsigned long long  c = n - (a + b) * times;
    if (c > a){
        num_a += a;
    } else {
        num_a += c;
    }
    cout << num_a << endl;
    return 0;
}



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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

int main() {
  ll a, b;
  cin >> a >> b;
  ll n = b - a - 1;
  ll small = 0;
  REP(i, n) { small += i + 1; }
  cout << small - a << endl;
}

Measured memory_bytes: 3548
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using Graph=vector<vector<int>>;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}

signed main(){
	int h,w,n;cin>>h>>w>>n;
	vector<P> pos(n);
	rep(i,n) cin>>pos[i].first>>pos[i].second;
	sort(All(pos));
	int ans=h;
	P M=P(1,1);
	rep(i,n){
		if(pos[i].first-M.first+M.second>pos[i].second){
			ans=pos[i].first-1;
			break;
		}
		else if(pos[i].first!=M.first){
			M.second=min(M.second+pos[i].first-M.first,pos[i].second-1);
			M.first=pos[i].first;
		}
	}
	cout<<ans<<endl;
}


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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int kekka = 0;
  
  while(A>=B){
    B = B*2;
  	kekka = kekka +1;
  }
  
  while(B>=C){
  	C = C*2;
  	kekka = kekka +1;
  }
  
  if(kekka<=K) cout << "Yes" << endl;
  
  else cout << "No" << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=600005;

int n,m;
char op[MAXN];
int a[MAXN],res[MAXN][12],temp[MAXN];
bool cf[MAXN];

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	readint(n);scanf("%s",op+1);m=strlen(op+1);
	int cur=1;
	for(int i=0;i<n;++i)
	{
		memset(cf,0,sizeof(cf));
		for(int k=0;k<3*cur;++k)res[k][i]=k/cur;
		bool fl=0;
		for(int j=1;j<=m;++j)
		{
			if(op[j]=='S')
			{
				fl=!fl;
			}
			else
			{
				if(cf[a[j]]!=fl)
				{
					for(int k=0;k<3;++k)
						if(res[a[j]+k*cur][i])
							res[a[j]+k*cur][i]^=3;
					cf[a[j]]=fl;
				}
				for(int k=0;k<3;++k)
					if(res[a[j]+k*cur][i]==2)temp[j]=a[j]+k*cur,res[a[j]+k*cur][i]=0;
					else ++res[a[j]+k*cur][i];
			}
/*for(int j=0;j<cur;++j)
	if(cf[j]!=fl)
	{
		for(int k=0;k<3;++k)
			if(res[j+k*cur][i])
				res[j+k*cur][i]^=3;
		cf[j]=fl;
	}
for(int j=0;j<cur*3;++j)cerr<<res[j][i]<<" ";cerr<<endl;*/
		}
		for(int j=0;j<cur;++j)
			if(cf[j]!=fl)
			{
				for(int k=0;k<3;++k)
					if(res[j+k*cur][i])
						res[j+k*cur][i]^=3;
				cf[j]=fl;
			}
		memcpy(a,temp,sizeof(a));
		cur*=3;
//for(int j=0;j<cur;++j)cerr<<res[j][i]<<" ";cerr<<endl;
	}
	for(int i=0;i<cur;++i)
	{
		int x=i,y=cur,ans=0;
		for(int j=n-1;j>=0;--j)
		{
			y/=3;
			ans+=y*res[x][j];
			x%=y;
		}
		printf("%d ",ans);
	}
	return 0;
}

Measured memory_bytes: 32880
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.ignore(NULL);
    int a,b,i,j,sum=0;
    cin>>a;
    a=a+1;
    int dish[a],sat[a],add[a-1];
    for(i=1;i<a;i++){
        cin>>dish[i];
    }
    for(i=1;i<a;i++){
        cin>>sat[i];
    }
    for(i=1;i<a-1;i++){
        cin>>add[i];
    }
    sum+=sat[dish[1]];
    for(i=2;i<a;i++){
        if(dish[i]==dish[i-1]+1){
            sum=sum+sat[dish[i]]+add[dish[i-1]];
        }
        else sum+=sat[dish[i]];
    }
    cout<<sum;
}


Measured memory_bytes: 256
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef pair<int, int> II;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		int h = -1, w, k, sx, sy, gx, gy, ans = -1;
		cin >> h >> w >> k >> sy >> sx >> gy >> gx;
		--sx, --sy, --gx, --gy;
		if (h < 0) return 0;
		vector<string> b(h);
		for (int i = 0; i < h; ++i) {
			cin >> b[i];
		}
		queue<II> q;
		vector<vector<int>> dist(h, vector<int>(w, 1 << 30));
		q.push(II(sy, sx));
		dist[sy][sx] = 0;
		while (!q.empty()) {
			int y = q.front().first, x = q.front().second;
			q.pop();
			if (x == gx && y == gy) {
				ans = dist[y][x];
				break;
			}
			int cost = dist[y][x] + 1;
			const int dx[4] = { -1,1,0,0 };
			const int dy[4] = { 0,0,-1,1 };
			for (int dir = 0; dir < 4; ++dir) {
				for (int d = 1; d <= k; ++d) {
					int nx = x + dx[dir] * d, ny = y + dy[dir] * d;
					if (nx < 0 || nx >= w || ny < 0 || ny >= h) break;
					if (b[ny][nx] != '.') break;
					if (cost > dist[ny][nx]) break;
					if (cost < dist[ny][nx]) {
						dist[ny][nx] = cost;
						q.push(II(ny, nx));
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

using namespace std;

int main(){
	int N;
	while(cin >> N){
		char c; int a;
		vector<int> v;
		for(int i=0;i<2*N;i++){
			cin >> c >> a; --a;
			v.push_back(c == 'W' ? a : a + N);
		}
		vector<vector<int>> cntW(N, vector<int>(N+1, 0));
		vector<vector<int>> cntB(N, vector<int>(N+1, 0));
		vector<int> flipW(N, 0);
		vector<int> flipB(N, 0);
		for(int i=0;i<2*N;i++){
			if(v[i] < N){
				for(int j=0;j<i;j++){
					if(v[j] < N){
						if(v[j] > v[i]) ++flipW[v[i]];
					} else {
						++cntW[v[i]][v[j]-N];
					}
				}
				for(int j=N-2;j>=0;j--) cntW[v[i]][j] += cntW[v[i]][j+1];
			} else {
				for(int j=0;j<i;j++){
					if(v[j] < N){
						++cntB[v[i]-N][v[j]];
					} else {
						if(v[j] > v[i]) ++flipB[v[i]-N];
					}
				}
				for(int j=N-2;j>=0;j--) cntB[v[i]-N][j] += cntB[v[i]-N][j+1];
			}
		}
		vector<vector<int>> dp(N+1, vector<int>(N+1, 4*N*N));
		dp[0][0] = 0;
		for(int i=0;i<=N;i++){
			for(int j=0;j<=N;j++){
				if(i < N){
					dp[i+1][j] = min(dp[i+1][j], dp[i][j] + flipW[i] + cntW[i][j]);
				}
				if(j < N){
					dp[i][j+1] = min(dp[i][j+1], dp[i][j] + flipB[j] + cntB[j][i]);
				}
			}
		}
		cout << dp[N][N] << endl;
	}
}

Measured memory_bytes: 47360
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

l = [i+1 for i in range(N)]
m = [i+1 for i in range(N)]

nnn = 1
for i in range(1, N+1):
    nnn *= i


aaa = nnn
a = 0
for i in range(N-1):
    x = P.pop(0)
    idx = m.index(x)
    m.pop(idx)
    aaa //= N-i
    a += idx*aaa

bbb = nnn
b = 0
for i in range(N-1):
    x = Q.pop(0)
    idx = l.index(x)
    l.pop(idx)
    bbb //= N-i
    b += idx*bbb
    

print(abs(a-b))

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

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

		String[] str = br.readLine().split(" ");
		double a = Double.parseDouble(str[0]);
		double b = Double.parseDouble(str[1]);
		double marge = Integer.parseInt(str[2]);
		double c = Math.toRadians( marge );

		 Double h = Math.sin( c ) * b;
         Double menseki = ( a * h )/2;
		double syui = a + b + Math.sqrt((a * a)+(b * b) - 2 * ((a * b) * Math.cos(c)));
		double height = b * Math.sin(c);

		System.out.println(menseki +" "+ syui +" "+ height );

	}
}

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

#define int long long

using pii = pair<int, int>;

int N;
vector<pii> G[111111];
vector<int> ans;

// 親ノード, 現在地のノード, 現在地までの距離
void rec(int from, int cur, int dist) {
  if (dist % 2 == 1) {
    ans[cur] = 1;
  }

  for (pii p : G[cur]) {
    int to = p.first;
    int tDist = p.second;
    // 逆戻りを防ぐ
    if (to == from) continue;

    rec(cur, to, dist + tDist);
  }
}

signed main() {
  cin >> N;
  ans.resize(N);
  for (int i = 0; i < N-1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }

  rec(-1, 0, 0);

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

  return 0;
}

Measured memory_bytes: 10496
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
array<int,4> a[N];
int r, c, n, ok[N], onSt[N];

int onB(int x, int y) {
  return x == 0 || x == r || y == 0 || y == c;
}

int dist(int x, int y) {
  if (y == 0 || x == r)
    return x+y;
  return r+c + c-y + r-x;
}

int main() {
  scanf("%d %d %d", &r, &c, &n);
  int m = 0;
  vector<array<int,3>> tmp;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 4; j++)
      scanf("%d", &a[i][j]);
    ok[i] = 1;
    for (int j = 0; j < 4; j += 2)
      ok[i] &= onB(a[i][j], a[i][j+1]);
    m += ok[i];
    if (ok[i]) {
      for (int j = 0; j < 4; j += 2)
        tmp.pb({a[i][j], a[i][j+1], i});
    }
  }
  if (m <= 1)
    return !printf("YES\n");
  sort(all(tmp), [](array<int,3> lhs, array<int,3> rhs) {
    return dist(lhs[0], lhs[1]) < dist(rhs[0], rhs[1]);
  });
  stack<int> st;
  trav(x, tmp) {
    if (!onSt[x[2]])
      onSt[x[2]] = 1, st.push(x[2]);
    else if (st.top() != x[2])
      return !printf("NO\n");
    else
      onSt[x[2]] = 0, st.pop();
  }
  printf("YES\n");
  return 0;
}


Measured memory_bytes: 13044
n = int(input())
li = list(map(int,input().split()))
cnt = 0
new_li = []
for l in li:
    if l<0:
        cnt += 1
    new_li.append(abs(l))
if cnt%2 == 0:
    print(sum(new_li))
else:
    print(sum(new_li)-(2*(min(new_li))))

Measured memory_bytes: 65184
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (int)1000000007
// Big two primes 
#define X 1011001110001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int int
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vii vector<pi>
const int MAXN = (int)((1e5) + 10);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
bool compare(const pair<int, int> &a, const pair<int, int> &b)
{
  return (a.second < b.second);
}
int main()
{
    fio;
 
    int n;
    unordered_map<int, int> m;
    cin>>n;

    vi a(n-1);
    vi b(n, 0);

    for(int i=0;i<n-1;i++)
     cin>>a[i];

    for(int i=0;i<n-1;i++)
    {
      m[a[i]]++;
    }

    for(int i=1;i<=n;i++)
    {
      cout<<m[i]<<endl;
    } 

    rr;
}

Measured memory_bytes: 13064
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  bool b = true;
  for (int i = 0; i < S.size() / 2; i++) {
    if (S.at(i) != S.at(S.size() - 1 - i)) {b = false;}
  }
  for (int i = 0; i < S.size() / 2 / 2; i++) {
    if (S.at(i) != S.at(S.size() / 2 - 1 - i)) {b = false;}
  }
  if (b) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 3624
N = int(input())
dic = {}

for i in range(N):
  S = input()
  if S in dic:
    dic[S] += 1
  else:
    dic[S] = 1
    
max_N = max(list(dic.values()))
keys = sorted([k for k, v in dic.items() if v == max_N])

print("\n".join(keys))

Measured memory_bytes: 111448
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

int main() {

	boost;
	int n, k; cin>>n>>k;

	ll ans = 0;
	ll c = n / k;
	ans += c * c * c;

	if(k & 1); else {
		k >>= 1;
		c = n / k - c;
		ans += c * c * c;
	}

	cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 256
import sys
def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    count = [0] * N
    for _ in range(M):
        a, b = map(int, input().split())
        a, b = min(a, b), max(a, b)
        if a > 1: count[a-1] += 1
        count[b-1] += 1
    
    for i, a in enumerate(count):
        if a % 2 > 0: 
            print("NO")
            break
    else: print("YES")

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL


ll modPow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n-1, p)) % p;
  ll t = modPow(a, n/2, p);
  return (t * t) % p;
}


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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());

  vector<ll> fact(n+1); //階乗
  vector<ll> fact_inv(n+1); //階乗の逆元
  fact[0] = 1;
  for (int i = 0; i < n; i++) fact[i+1] = (fact[i] * (i+1)) % MOD;
  fact_inv[n] = modPow(fact[n], MOD-2, MOD);
  for (int i = n-1; i >= 0; i--) fact_inv[i] = (fact_inv[i+1] * (i+1)) % MOD;

  auto comb = [&](ll n0, ll r) { //MODで
    if ((n0 < r) || (n0 < 0) || (r < 0)) return 0LL;
    return (((fact[n0] * fact_inv[n0-r]) % MOD) * fact_inv[r]) % MOD;
  };

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i] * comb(i, k-1); //これが最大であるような
    ans -= a[i] * comb(n-1-i, k-1); //これが最小であるような
    ans = (ans + MOD) % MOD;
    //cout << a[n-1-i] * comb(i, k-1) << " " << a[i] * comb(n-1-i, k-1) << endl;
  }
  cout << ans << endl;  
}


Measured memory_bytes: 5572
# input
X = int(input())

# process
a, b = 0, 0

nl = []
i = 0
np = 0
n = i**5
while n - np <= 10**9:
    nl.append(n)
    i += 1
    np = n
    n = i**5

for i in range(len(nl)):
    t = X-nl[i]
    if t in nl:
        a = i
        b = -(nl.index(t))
        break

    if -t in nl:
        a = i
        b = nl.index(-t)
        break

# output
print("{} {}".format(a, b))


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

int main(){
	int n;
	cin >> n;
	if(n%2 ==0)
		cout << n/2 << endl;
	else
		cout << (n/2)+1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
 
using namespace std;
 
int main(){
  int h,w,n;
  cin>>h>>w>>n;
 
  map<pair<int,int>,int> cnt;
  while(n--){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    for(int i=-1;i<2;i++){
      for(int j=-1;j<2;j++){
        if(a+i>0&&a+i<h-1&&b+j>0&&b+j<w-1){
          cnt[make_pair(a+i,b+j)]++;
        }
      }
    }
  }
  long long ans[10] = {(long long)(h-2)*(w-2)};
  for(auto& elem : cnt){
    ans[0]--;
    ans[elem.second]++;
  }
 
  for(int i=0;i<10;i++){
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 56448
#include <stdio.h>
long long p = 1000000007;
long long n, k;
long long d;
long long s[50000], sn[50000];
long long l[50000], ln[50000];
long long cc[50000];
long long t;
int main() {
	scanf("%lld%lld", &n, &k);
	while (d * d <= n)d++;
	d--;
	for (long long i = 1; i <= d; i++) {
		s[i] = 1;
		t = n / (i + 1);
		if (t < d)t = d;
		l[i] = ((n / i) - t) % p;
		cc[i] = ((n / i) - t) % p;
	}
	for (int i = 1; i < k; i++) {
		for (int j = 0; j < 50000; j++) {
			sn[j] = 0;
			ln[j] = 0;
		}
		t = 0;
		for (int j = 1; j <= d; j++) {
			t += s[j];
			t %= p;
		}
		sn[d] = l[d] + t;
		sn[d] %= p;
		for (int j = 1; j <= d - 1; j++) {
			sn[d - j] = sn[d - j + 1] + l[d - j];
			sn[d - j] %= p;
		}
		ln[1] = s[1];
		for (int j = 1; j <= d - 1; j++) {
			ln[j + 1] = ln[j] + s[j + 1];
			ln[j + 1] %= p;
		}
		for (int j = 1; j <= d; j++) {
			l[j] = ln[j] * cc[j] % p;
			s[j] = sn[j];
		}
	}
	t = 0;
	for (int i = 1; i <= d; i++) {
		t += s[i]; t %= p;
		t += l[i]; t %= p;
	}
	printf("%lld", t);
}

Measured memory_bytes: 1664
import collections

n = int(input())
v = input().split()

e = [v[i] for i in range(n) if i % 2 == 0]
o = [v[i] for i in range(n) if i % 2 == 1]

c_e = collections.Counter(e).most_common()
c_o = collections.Counter(o).most_common()

e_0 = c_e[0]
o_0 = c_o[0]

if e_0 != o_0:
    print(len(e) - e_0[1] + len(o) - o_0[1])
else:
    if len(c_e) == 1:
        e_1 = [0, 0]
    else:
        e_1 = c_e[1]
    if len(c_o) == 1:
        o_1 = [0, 0]
    else:
        o_1 = c_o[1]
    print(min(len(e)-e_0[1]+len(o)-o_1[1], len(e)-e_1[1]+len(o)-o_0[1]))


Measured memory_bytes: 23528
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()

"""========main code==============="""

x,y,z=ml()
x,y=y,x
x,z=z,x
print(x,y,z)
"""for _ in range(t):
    x=ii()"""
    #a=ll()
    
    

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
int m;
int l;

struct edge{
	int to;
	int cost;
	int damage;
};

int main(){
	while(cin >> n >> m >> l,n || m || l){
		vector<vector<int>> dist(n,vector<int>(l + 1,1e9));
		int s = 0;
		int t = n - 1;
		dist[s][l] = 0;

		vector<vector<edge>> edges(n);
		for(int i = 0;i < m;i++){
			int a,b,d,e;
			cin >> a >> b >> d >> e;
			a--;
			b--;
			edges[a].push_back({b,d,e});
			edges[b].push_back({a,d,e});
		}
		using P2 = pair<int,P>;
		priority_queue<P2,vector<P2>,greater<P2>> que;
		que.push({0,{s,l}});

		while(!que.empty()){
			int d = que.top().first;
			int v = que.top().second.first;
			int c = que.top().second.second;
			que.pop();
			if(dist[v][c] < d) continue;

			for(auto& e : edges[v]){
				//can use?
				if(c - e.cost >= 0 && dist[e.to][c - e.cost] > d){
					dist[e.to][c - e.cost] = d;
					que.push({dist[e.to][c - e.cost] , {e.to,c - e.cost}});
				}
				//dont use?
				if(dist[e.to][c] > d + e.damage){
					dist[e.to][c] = d + e.damage;
					que.push({dist[e.to][c] , {e.to,c}});
				}
			}
		}
		int result = 1e9;

		for(int i = 0;i <= l;i++){
			result = min(result , dist[t][i]);
		}

		cout << result << endl;
	}
}



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

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

  if (S.size() != A + B + 1 || S[A] != '-') {
    cout << "No" << endl;
    return 0;
  }

  set<char> st;
  for (char c = '0'; c <= '9'; c++) st.insert(c);
  for (int i = 0; i < S.size(); i++) {
    if (i == A) continue;
    if (st.find(S[i]) == st.end()) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()
MOD = 10**9 + 7
threads = 0
M = 1
for s in S:
    if (threads + int(s=='B')) % 2:
        threads += 1
    else:
        M *= threads
        M %= MOD
        threads -= 1

if threads > 0:
    print(0)
    exit()

K = 1
for i in range(1,N+1):
    K *= i
    K %= MOD

print((M*K)%MOD)

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    
    int isDenied = 0;
    rep(i, n) {
        if(a[i] % 2 == 0) {
            if(a[i] % 3 != 0 && a[i] % 5 != 0) isDenied = 1;
        }
    }

    if(isDenied) {
        cout << "DENIED" << endl;
    } else {
        cout << "APPROVED" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <algorithm>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const int E = numeric_limits<int>::min();

int main(void)
{
    int N, X, T;
    cin >> N >> X >> T;

    int totalTime = 0;
    do{
        N -= X;
        totalTime += T;
    } while (N > 0);

    printf("%d\n", totalTime);

    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x) ans++;
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
S = input()
one = True
zero = True
for i in range(len(S)):
    if (i + 1) % 2 == 1:
        if S[i] not in ["R", "U","D"]:
            one = False
    else:
        if S[i] not in ["L","U","D"]:
            zero = False
if one and zero:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
n, k = gets.chomp.split(" ").map{|i| i.to_i}

sunuke = Array.new(n, 0)

k.times do |i|
  d = gets.to_i
  gets.chomp.split.map{|s| s.to_i - 1}.each do |a|
    sunuke[a] = 1
  end
end

puts sunuke.count{|s| s == 0}


Measured memory_bytes: 14268
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

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

  if (sum >= 22)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
string s;
int n,r,ans;
int main()
{
	cin>>n>>s;
	int sz=s.size();
	for(int i=0;i<sz;i++)
		if(s[i]=='R')
			r++;
	for(int i=0;i<r;i++)
		if(s[i]!='R')
			ans++;
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int N;
    cin >>N;
    vector<long long>vec(87);
    vec.at(0)=2;
    vec.at(1)=1;
    for(int i=2;i<=N;i++){
        vec.at(i)=vec.at(i-1)+vec.at(i-2);
    }
    cout << vec.at(N) <<endl;

}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+1;
bool isred[maxn]={false};
int ball_num[maxn];
int main(){
	isred[1]=true;
	fill(ball_num,ball_num+maxn,1);
	int N,M,x,y;
	scanf("%d%d",&N,&M);
	while(M--){
		scanf("%d%d",&x,&y);
		ball_num[x]--;ball_num[y]++;
		if(isred[x]==true)	isred[y]=true;
		if(ball_num[x]==0)	isred[x]=false;
	}
	int sum=0;
	for(int i=1;i<=N;i++){
		if(isred[i]==true)	sum++;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans;

signed main(){
	int n;
	string s;
	cin>>n;
	if(n==0)s="0";
	while(n!=0){
		if(n%2!=0){
			s+="1";
			n--;
		}
		else s+="0";
		n/=-2;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;

	
}


Measured memory_bytes: 256
function *main() {
  
  // ここにコードを書く
  mint.mod = 1000000007n;
  
  const [n, k] = (yield).split(" ").map(BigInt);
  
  console.error(n, k);
  
  const t = n - k;
  
  const ans = ( -mint.div((n+1n)*(n+2n)*(2n*n+3n) - k*(k-1n)*(2n*k-1n), 6n) + (n+1n)*mint.div((k+n+1n)*(n-k+2n), 2n) + (n-k+2n) )%mint.mod;
  
  console.log(ans.toString());
  
}

// ここにライブラリを書く
// set mint.mod
const mint = {
	mod: 0n, //replace this
	add: (x, y) => {
		let r = (x + y) % mint.mod;
		if (r < 0n) r -= (r / mint.mod - 1n) * mint.mod;
		return r;
	},
	sub: (x, y) => mint.add(x, -y),
	mul: (x, y) => x * y % mint.mod,
	pow: (x, y) => {
		let r = 1n;
		while (y > 0n) {
			if (y & 1n) r *= x % mint.mod;
			x = x * x % mint.mod;
			y >>= 1n;
		}
		return r;
	},
	inv: x => mint.pow(x, mint.mod-2n),
	div: (x, y) => mint.mul(x, mint.inv(y)),
};

const iter = main();
iter.next();
require("readline").createInterface({input: process.stdin}).on("line", s => iter.next(s));


Measured memory_bytes: 30096
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
int a[114514];
signed main(){
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;){
		if(a[i]==i&&a[i+1]==i+1){
			i+=2;ans++;
		}
		else if(a[i]==i){
			i++;ans++;
		}
		else i++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}




int main(){
    int N, D;
    cin >> N >> D;

    vector<vector<int>> x (N,vector<int>(D));

    rep(i,N){
        rep(j,D){
            cin >> x[i][j];
        }
    }

    int ans = 0;
    rep(i,N-1){
        for(int j = i+1; j<N; j++){
            
            int kyori = 0;
            rep(a,D){
                kyori += pow(x[i][a]-x[j][a],2);
            }

            for(int b = 1; b*b < 20000; b++){
                if(b*b == kyori){
                    ans +=1;
                    break;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

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

typedef long long ll;

int main(){
	int A,B,C,D;
	int t = 0;
	cin >> A >> B >> C >> D;
	rep(i,100){
		if(A <= i && B > i && C <= i && D > i){
			t++;
		}
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long n,k,jk;
long a[200001]={0},lk[200001]={0};
int main(void){
    cin>>n>>k;
    for(long i=0;i<n;i++){
        cin>>jk;
        a[jk]++;
    }
    jk=0;
    for(long i=1;i<200001;i++){
        if(a[i]!=0){
            jk++;
            lk[a[i]]++;
        }
    }
    long ans=0;
    for(long i=1;i<200001;i++){
        if(jk<=k){break;}
        if(lk[i]>jk-k){
            ans+=i*(jk-k);
            jk-=jk-k;
        }
        else if(lk[i]>0){
            ans+=i*lk[i];
            jk-=lk[i];
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	map<int, int> s;
	s[0] = 1;
	int a, b = 0;
	long r = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		b += a; b %= m;
		r += s[b]++;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 3200
D, G = map(int, input().split())
Problems = []
Complete_Bonus = []
for i in range(D):
    p, c = map(int, input().split())
    Problems.append(p)
    Complete_Bonus.append(c)

ans = sum(Problems)

for i in range(2**D):
    a = 0
    solved_num = 0
    for j in range(D):
        if (i >> j) & 1:
            a += Complete_Bonus[j] + Problems[j] * (j + 1) * 100
            solved_num += Problems[j]
    if a >= G:
        ans = min(ans, solved_num)
    else:
        flag = False
        for j in range(D):
            if flag:
                break
            if not ((i >> (D - j - 1)) & 1):
                for k in range(Problems[D-j-1]):
                    a += 100 * (D-j)
                    solved_num += 1
                    if a >= G:
                        ans = min(ans, solved_num)
                        flag = True
                        break

print(ans)

Measured memory_bytes: 3064
#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 in[31]={1,1,2};
  loop(i,3,31)in[i]=in[i-1]+in[i-2]+in[i-3];

  int n;
  while(cin>>n,n){
    cout<<(in[n]-1)/3650+1<<endl;
  }

}

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

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;
    set<int> ss[26];
    
    for (int i=0; i<N; i++) {
        ss[S[i]-'a'].insert(i);
    }
    
    for (int q=0; q<Q; q++) {
        int ty; cin >> ty;
        
        if (ty==1) {
            int i; cin >> i;
            i--;
            char c; cin >> c;
            if (S[i]==c) continue;
            ss[S[i]-'a'].erase(i);
            ss[c-'a'].insert(i);
            S[i]=c;
        }
        else {
            int l, r; cin >> l >> r;
            l--;
            r--;
            int ans = 0;
            
            for (int i=0; i<26; i++) {
                if (ss[i].size()==0) continue;
                if (l>*--ss[i].end()) continue;
                int m = *ss[i].lower_bound(l);
                //cout << l << " " << m << endl;
                if (m<=r) ans++;
            }
            
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
int n;
ll dp[55][2];
string a, b, c;

ll solve(int i, int j)
{
	if (dp[i][j] >= 0) return dp[i][j];
	char l = a[i], m = b[i], r = c[i];
	int x = l - '0', y = m - '0', z = r - '0';
	ll res;
	if (i == 0)
	{
		if (l == '?'&&m == '?'&&r == '?')	   // ?+?=?
		{
			if (j == 0) res = 36;
			else res = 28;
		}
		else if (l != '?'&&m != '?'&&r != '?') // x+y=z
		{
			if (j + x + y == z) res = 1;
			else res = 0;
		}
		else if (l == '?'&&m == '?'&&r != '?') // ?+?=z
		{
			if (j == 0) res = z - 1;
			else res = max(0, z - 2);
		}
		else if (l != '?'&&m != '?'&&r == '?') // x+y=?
		{
			if (x + y + j < 10) res = 1;
			else res = 0;
		}
		else if (r == '?')					   // x+?=? || ?+y=?
		{
			if (l == '?') swap(x, y);
			if (j == 0) res = 9 - x;
			else res = max(0, 8 - x);
		}
		else								   // x+?=z || ?+y=z
		{
			if (l == '?') swap(x, y);
			if (j + x < z) res = 1;
			else res = 0;
		}
	}
	else
	{
		if (l == '?'&&m == '?'&&r == '?')	   // ?+?=?
		{
			if(j==0) res = solve(i - 1, 0) * 55 + solve(i - 1, 1) * 45;
			else res = solve(i - 1, 0) * 45 + solve(i - 1, 1) * 55;
		}
		else if (l != '?'&&m != '?'&&r != '?') // x+y=z
		{
			if ((j + x + y) % 10 == z) res = solve(i - 1, (j + x + y) / 10);
			else res = 0;
		}
		else if (l == '?'&&m == '?'&&r != '?') // ?+?=z
		{
			if(j==0) res = solve(i - 1, 0)*(z + 1) + solve(i - 1, 1)*(9 - z);
			else res = solve(i - 1, 0)*z + solve(i - 1, 1)*(10 - z);
		}
		else if (l != '?'&&m != '?'&&r == '?') // x+y=?
		{
			if (x + y + j < 10) res = solve(i - 1, 0);
			else res = solve(i - 1, 1);
		}
		else if (r == '?')					   // x+?=? || ?+y=?
		{
			if (l == '?') swap(x, y);
			if (j == 0) res = solve(i - 1, 0)*(10 - x) + solve(i - 1, 1)*x;
			else res = solve(i - 1, 0)*(9 - x) + solve(i - 1, 1)*(x + 1);
		}
		else								   // x+?=z || ?+y=z
		{
			if (l == '?') swap(x, y);
			if (j == 0)
			{
				if (x <= z) res = solve(i - 1, 0);
				else res = solve(i - 1, 1);
			}
			else
			{
				if (x+1 <= z) res = solve(i - 1, 0);
				else res = solve(i - 1, 1);
			}
		}
	}
	return dp[i][j] = res%MOD;
}

int main()
{
	while (cin >> a >> b >> c, a != "0")
	{
		n = a.size();
		MS(dp, -1);
		cout << solve(n - 1, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion

static int a[200001], x[200001];

int main(void)
{
	int  n;
	int  i, n1, n2;

	i_cin(n);
	i_cins(n, a);
	memcpy(x, a, sizeof(int) * 200000);
	qsort(x, n, sizeof(int), s_dsort);
	
	n1 = x[0]; n2 = x[1];

	for (i = 0; i < n; i++) {
		if (a[i] != n1) i_cout(n1);
		else i_cout(n2);
	}
	return 0;
}



Measured memory_bytes: 3120
#include<stdio.h>
int main()
{
    int m,mi;
    int a[40],b[40],c[40],d[40];
    char ac[40],bc[40],t;
    while(scanf("%d",&m)!=EOF)
    {
        int i,j,x;
        int r=1,flag=1;
        getchar();
        for(i=0; i<m; i++)
        {
            c[i]=i;
            d[i]=i;
            scanf("%c%d",&ac[i],&a[i]);
            getchar();
            b[i]=a[i];
            bc[i]=ac[i];
        }
        for(i=0; i<m; i++)
        {
            for(j=m-1; j>=i+1; j--)
                if(a[j]<a[j-1])
                {
                    x=a[j-1];
                    a[j-1]=a[j];
                    a[j]=x;
                    x=c[j-1];
                    c[j-1]=c[j];
                    c[j]=x;
                    t=ac[j-1];
                    ac[j-1]=ac[j];
                    ac[j]=t;
                }
        }
        for(i=0; i<m-1; i++)
        {
            printf("%c%d ",ac[i],a[i]);
            if(a[i]==a[i+1]&&c[i]>c[i+1])
                r=0;
        }
        printf("%c%d\n",ac[i],a[i]);
        if(flag)
            printf("Stable\n");
        else
            printf("Not stable\n");
        for(i=0; i<m; i++)
        {
            mi=i;
            for(j=i; j<m; j++)
                if(b[j]<b[mi])
                {
                    mi=j;
                }
            if(b[i]>b[mi])
            {
                x=b[i];
                b[i]=b[mi];
                b[mi]=x;
                x=d[i];
                d[i]=d[mi];
                d[mi]=x;
                t=bc[i];
                bc[i]=bc[mi];
                bc[mi]=t;
            }
        }
        for(i=0; i<m-1; i++)
        {
            printf("%c%d ",bc[i],b[i]);
            if(b[i]==b[i+1]&&d[i]>d[i+1])
                flag=0;
        }
        printf("%c%d\n",bc[i],b[i]);
        if(flag)
            printf("Stable\n");
        else
            printf("Not stable\n");
    }
}


Measured memory_bytes: 2100
import java.util.Scanner;
//import java.util.Random;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		
		String s=stdIn.next();
		
		int idx=s.indexOf("7");
		if(idx==-1) System.out.println("No");
		else System.out.println("Yes");
	}
}

Measured memory_bytes: 35656