akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));

int f(int t, int num) {
	if (num == 0)return 1;
	int x = f(t, num / 2);
	x *= x;
	if (num % 2)x *= t;
	return x;
}

std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i * i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

signed main() {
	int X;
	cin >> X;
	std::vector<int> r = enum_div(X);
	int B;
	for (int A = -10000; A <= 10000; A++) {
		for (auto i : r) {
			B = A - i;
			int a = f(A, 5);
			int b = f(B, 5);
			if (a - b == X) {
				cout << A << " " << B;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
using namespace std;
long long n, a, b, c;
int main() {
	cin>>n;
	while(n--) {
		cin>>a>>b;
		c = sqrt(a*b);
		if(a!=b && a*b==c*c) c--;
		cout<<(c*(c+1)>=a*b ? 2*c-2 : 2*c-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

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

using namespace std;

int main(){
	int p,a[3000];
	scanf("%d",&p);

	static int nCr[3000][3000];
	rep(n,3000) nCr[n][0]=1;
	rep(n,2999) rep(r,n+1) nCr[n+1][r+1]=(nCr[n][r+1]+nCr[n][r])%p;

	static int pw[3000][3000]; // pw[i][j] := i^j mod p
	rep(i,3000){
		pw[i][0]=1;
		rep(j,2999) pw[i][j+1]=pw[i][j]*i%p;
	}

	int ans[3000]={};
	rep(i,p){
		int a; scanf("%d",&a);
		if(a==0) continue;

		ans[0]++;
		rep(j,p){
			int tmp=nCr[p-1][j]*pw[(p-i)%p][p-j-1]%p;
			ans[j]=(ans[j]-tmp+p)%p;
		}
	}


	rep(i,p) printf("%d ",ans[i]);

	return 0;
}


Measured memory_bytes: 70528
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int H, W;
int ans = 0;

void Search(int x, int y, vector<vector<bool> >flag, int dis) {
	flag[y][x] = false;
	int d[5] = { 1,0,-1,0,1 };
	for (int k = 0; k < 4; k++) {
		if (flag[y + d[k + 1]][x + d[k]]) {
			Search(x + d[k], y + d[k + 1], flag, dis + 1);
		}
	}
	ans = max(ans, dis);
	return;
}

int main() {
	cin >> W;
	cin >> H;
	while (W&&H) {
		ans = 0;
		vector<vector<bool> >v(H+2);
		for (int i = 1; i <= H; i++) {
			v[i].push_back(0);
			for (int j = 1; j <= W; j++) {
				bool box;
				cin >> box;
				v[i].push_back(box);
			}
			v[i].push_back(0);
		}
		for (int i = 0; i <= W + 1; i++) {
			v[0].push_back(0);
			v[H + 1].push_back(0);
		}
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				if(v[i][j])	Search(j, i, v, 1);
			}
		}
		cout << ans << endl;
		cin >> W;
		cin >> H;
	}
	return 0;
}

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

int main()
{
    char s[1000], t[1000];
    int s_len, t_len;
    int min_counts = 10000, counts = 0;

    cin >> s >> t;
    s_len = strlen(s);
    min_counts = t_len = strlen(t);

    //cout << s_len << " " << t_len << endl;

    for (int i = 0; i <= s_len - t_len; i++)
    {
        for (int j = 0; j < t_len; j++)
        {
            if (s[i + j] == t[j])
            {
            }
            else
            {
                counts++;
            }
        }
        min_counts = min(min_counts, counts);
        // if (counts < min)
        // {
        //     min = counts;
        // }
        counts = 0;
    }

    cout << min_counts << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;

int n;
double v[1010];
double ans;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v, v+n);

    ans = v[0];
    for (int i = 1; i < n; ++i) {
        ans = (ans + v[i])/2;
    }
    cout << ans << 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++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
 
int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> Q;
    for(char c: s) Q.push_back(c);
    bool flip = false;
    int t;
    rep(i,q) {
        cin >> t;
        if(t == 1) {
            flip  = !flip;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if(flip) f = 3 - f;
            if(f == 1) {
                Q.push_front(c);
            } else {
                Q.push_back(c);
            }
        }
    }
    if(flip) reverse(Q.begin(),Q.end());
    string ans = "";
    for(char c: Q) ans += c;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
def main():

    S = input()
    m = dict()
    m['d'] = 'b'
    m['b'] = 'd'
    m['p'] = 'q'
    m['q'] = 'p'

    T = ""
    for i in range(len(S)-1, -1, -1):
        T += m[S[i]]
    if T == S: return "Yes"
    return "No"

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc075.contest.atcoder.jp/tasks/abc075_c>
問題文============================================================
 自己ループと二重辺を含まない N 頂点 M 辺の無向連結グラフが与えられます。
 i(1≦i≦M) 番目の辺は頂点 ai と頂点 bi を結びます。
 
 グラフから辺を取り除いたとき、グラフ全体が非連結になるような辺のことを橋と呼びます。
 与えられた M 本のうち橋である辺の本数を求めてください。
 
=================================================================

解説=============================================================
橋の判定
 
 lowlinkやるだけ
================================================================
*/
class Bridge {
public:
    vector<vector<int>> G;
    vector<int> ord, low;
    vector<pair<int, int>> bridges;
    int k;
    
    Bridge(int N):k(0) {
        G.resize(N); ord.resize(N, -1); low.resize(N, -1);
    }
    void clear() { G.clear();ord.clear();low.clear(); }
    void add_edge(int s, int t) {
        G[s].emplace_back(t);
        G[t].emplace_back(s);
    }
    
    bool is_bridge(int u, int v)const {
        if (ord[u] > ord[v])swap(u, v);
        return ord[u] < low[v];
    }
    
    /* Lowlink */
    void dfs(int u,int rev = -1) {
        ord[u] = low[u] = k;
        k++;
        for (auto v : G[u]) {
            if (v == rev)continue;
            if (ord[v] < 0) {
                dfs(v, u);
                low[u] = min(low[u], low[v]);
            }
            else {
                low[u] = min(low[u], ord[v]);
            }
            if (is_bridge(u, v)) {
                int s = u, t = v;
                if (s > t) swap(s, t);
                bridges.push_back({ s,t });
            }
        }
    }
    
    void solve() {
        dfs(0);
        sort(bridges.begin(), bridges.end());
    }
};
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    Bridge bridge(N);
    for(int i = 0; i < M;i++){
        int s,t; cin >> s >> t;
        bridge.add_edge(s-1,t-1);
    }
    bridge.solve();
    cout << bridge.bridges.size() << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    string s[n];
    map<string,int>m;
    for(int i=0;i<n;++i)
    {
        cin>>s[i];
        m[s[i]]++;
    }
    cout<<m.size()<<"\n";



}

Measured memory_bytes: 25496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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; }
int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    map<ll,ll> comb;
    rep(i,1<<n){
        ll tmp=0;
        rep(j,n){
            if(i>>j & 1) tmp+=a[j];
        }
        comb[tmp]++;
    }
    ll q; cin>>q;
    rep(i, q){
        ll m; cin>>m;
        if(comb[m]>0) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3148
N = int(input())
S = list(input()) + ["!"]
dp = [[0] * N for _ in range(N)]
for j in range(1, N):
  if S[0] == S[j]:
    dp[0][j] = 1
res = 0
for i in range(N):
  for j in range(i, N):
    res = max(dp[i][j], res)
    if i == N - 1 or j == N - 1:
      continue
    if S[i + 1] == S[j + 1] and j - i > dp[i][j]:
      dp[i + 1][j + 1] = dp[i][j] + 1
    else:
      dp[i + 1][j + 1] = 0
print(res)

Measured memory_bytes: 231048
#include <iostream>
using namespace std;
const int MAX=1001;
int lcs(string X,string Y) 
{
	int i=0,j=0,c[MAX][MAX],x=X.length(),y=Y.length();
	for(i=0;i<=x;i++)c[i][0]=0;
	for(i=0;i<=y;i++)c[0][i]=0;
	for(i=1;i<=x;i++) 
	for(j=1;j<=y;j++) 
	if(X[i-1]==Y[j-1])c[i][j]=c[i-1][j-1]+1; 
	else if(c[i-1][j]>c[i][j-1])c[i][j]=c[i-1][j];
	else if(c[i-1][j]<c[i][j-1])c[i][j]=c[i][j-1]; 
	else c[i][j]=c[i][j-1];
	return c[x][y];
}
int main()
{
	int n;cin>>n;
	string X,Y;
	while(n--)
	{
		cin>>X>>Y;
		cout<<lcs(X,Y)<<endl;
	}
}

Measured memory_bytes: 7032
#include <iostream>
#include <string>
int main(int argc,char* argv[])
{
  std::string Raw;
  std::string Register;
  bool isNearly{true};
  std::cin >> Raw;
  std::cin >> Register;
  if(Raw.size() + 1 != Register.size())
  {
    isNearly = false;
  }
    
  for(auto i =0;i< Raw.size();i++ )
  {
    if(Raw[i] != Register[i])
    {
    	isNearly = false;
      	break;
    }
  }
  if(isNearly)
  {
 	std::cout << "Yes" <<std::endl;
  }
  else
  {
 	std::cout << "No" <<std::endl;
  }
	return 0;
}

Measured memory_bytes: 3124
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

bool isprime(int n)
{
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int main()
{
MP;
    //test
    {
        int n;
        cin>>n;
        for(int i=n;;i++){
            if(isprime(i)){cout<<i;End;}
        }
    }

End;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


int main() {
	ll H,W;
	ll sum = 0;
	ll sum1 = 0;
	ll sum2 = 0;
	ll sum3 = 0;
	ll ans = 10000000000;
	cin >> H >> W;
	sum = H*W;
	FOR(i, 1, W) {
		sum1 = H * i;
		sum2 = sum - sum1;
		if (sum2 % 2 == 0) {
			sum2 /= 2;
			ans = min(abs(sum1 - sum2), ans);
		}
		else {
			if (H > W-i) {
				sum2 = (H + 1)/2*(W - i);
				sum3 = H*W - sum1 - sum2;
				if (sum2 > sum1 && sum1 > sum3) {
					ans = min(sum2 - sum3, ans);
				}
				else if (sum2 > sum1 && sum1 < sum3) {
					ans = min(sum2 - sum1, ans);
				}
				else {
					ans = min(sum1 - sum3, ans);
				}
			}
			else {
				sum2 = (W - i + 1) / 2 * H;
				sum3 = H*W - sum1 - sum2;
				if (sum2 > sum1 && sum1 > sum3) {
					ans = min(abs(sum2 - sum3), ans);
				}
				else if (sum2 > sum1 && sum1 < sum3) {
					ans = min(abs(sum2 - sum1), ans);
				}
				else {
					ans = min(abs(sum1 - sum3), ans);
				}
			}
		}
	}
	FOR(i, 1, H) {
		sum1 = W * i;
		sum2 = sum - sum1;
		if (sum2 % 2 == 0) {
			sum2 /= 2;
			ans = min(abs(sum1 - sum2), ans);
		}
		else {
			if (W > H - i) {
				sum2 = (W + 1) / 2 * (H - i);
				sum3 = H*W - sum1 - sum2;
				if (sum2 > sum1 && sum1 > sum3) {
					ans = min(abs(sum2 - sum3), ans);
				}
				else if (sum2 > sum1 && sum1 < sum3) {
					ans = min(abs(sum2 - sum1), ans);
				}
				else {
					ans = min(abs(sum1 - sum3), ans);
				}
			}
			else {
				sum2 = (H - i + 1) / 2 * W;
				sum3 = H*W - sum1 - sum2;
				if (sum2 > sum1 && sum1 > sum3) {
					ans = min(abs(sum2 - sum3), ans);
				}
				else if (sum2 > sum1 && sum1 < sum3) {
					ans = min(abs(sum2 - sum1), ans);
				}
				else {
					ans = min(abs(sum1 - sum3), ans);
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
tree = [[] for i in range(n)]

for i in range(m):
  x, y, z = map(int, input().split())
  tree[x-1].append(y-1)
  tree[y-1].append(x-1)

already = [False]*n
ans = 0
for i in range(n):
  if already[i]:
    continue
  ans += 1
  not_yet = deque(tree[i])
  for value in tree[i]:
    already[value] = True
  while not_yet:
    key = not_yet.popleft()
    for value in tree[key]:
      if already[value]:
        continue
      already[value] = True
      not_yet.append(value)
print(ans)

Measured memory_bytes: 23792
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 998244353
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
const int N = 100005;
vector<vector<pii>> v(2, vector<pii>(N, {0,0}));

int main(){
	fast_io();
	int n;
	cin >> n;
	cu(i,0,n){
		int x;
		cin >> x;
		++v[i&1][x].F;
		v[i&1][x].S = x;
	}
	sort(all(v[0]));
	sort(all(v[1]));
	pii end0 = v[0][v[0].size()-1];
	pii end1 = v[1][v[1].size()-1];
	if(end0.S != end1.S){
		cout << n - end0.F - end1.F << endl;
	}
	else{
		cout << n - max(v[0][v[0].size() - 2].F + end1.F, v[1][v[1].size() - 2].F + end0.F) << endl;
	}
}


Measured memory_bytes: 2560
readlines.each{|data|
  a, b, c, d, e, f = data.split.map(&:to_f)
  x = (c*e - f*b)/(a*e - b*d)
  y = (f*a - c*d)/(a*e - b*d)
  puts sprintf("%.3f %.3f", x + 0.0, y + 0.0)
}

Measured memory_bytes: 8680
#include<cstdio>

int main(){
	int h,w;
	char s[100][101];
	char ans[200][101];
	scanf("%d %d",&h,&w);
	for(int i=0;i<h;i++) scanf(" %s",s[i]);
	for(int i=0;i<2*h;i++){
		for(int j=0;j<w;j++){
			ans[i][j] = s[i/2][j];
		}
		ans[i][w] = '\0';
	}
	for(int i=0;i<2*h;i++){
		printf("%s",ans[i]);
		if(i!=2*h-1) printf("\n");
	}
	return 0;
}


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

int main() {
	int N, A, B, T, ans=0;
	cin >> N >> A >> B;
	for(int i=0; i<N; ++i){
	    cin >> T;
	    if(T<A || T>=B) ++ans;
	}
	cout << ans << endl;
	return 0;
}


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

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

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

int m, n, q;
double s, y, r, d;

int main()
{
  cin >> m;

  while(m--){
    cin >> s >> y >> n;
    int res = 0;
    while(n--){
      cin >> q >> r >> d;
      double ss = s;
      if(q == 0){
        int sum = 0;
        rep(i, y){
          sum += ss * r;
          ss -= d;
        }
        maxup(res, (int)(ss + sum));
      }
      else{
        rep(i, y) ss += floor(ss * r - d);
        maxup(res, ss);
      }
    }
    cout << res << endl;
  }

  return 0;
}

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

// const int N = 1e9+7;
const int N = 2e5 + 5;
ll parent[N];
ll siz[N];
void make() {
    for(ll i=0; i<N; i++) {
        parent[i] = i;
        siz[i] = 1;
    }
}
int find(int x) {
    while (parent[x] != x) {
        x = parent[x];
    }
    return x;
}
void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a != b) {
        if (siz[a] < siz[b]) {
            swap(a, b);
        }
        parent[b] = a;
        // if (siz[a] == siz[b]) {
            siz[a]+=siz[b];
        // }
    }
}


void solve(){
  ll n, m;
  cin>>n>>m;
  vector<pair<ll,ll>>edges(m);
  make();
  for(ll i=0; i<m;i++){
    cin>>edges[i].first>>edges[i].second;
    unite(edges[i].first, edges[i].second);
  }
  ll ans = 0;
  for(ll i=1; i< n+1; i++){
    ans = max(ans,siz[i]);
  }
  cout<<ans;
}
int main(){
  // freopen("input.txt", "r",stdin);
  // freopen("output.txt", "w", stdout);
  ll t;
  // cin>>t;
  t = 1;
  while(t--){
    solve();
  }
}
























/*
  1 2 3 4 5 6 7 8

  6 7 8 1 2 3 4 5


*/


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

constexpr int MAXN = 1e3 + 3;
constexpr double down = 0.996;

int n, cnt[10004][3], vis[3], res; //r g b
string s;

map<char, int>h;

signed main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> s;
	h['R'] = 0, h['G'] = 1, h['B'] = 2;
	s = " " + s;
	for (int i = n; i >= 1; i--) {
		char c = s[i];
		int num = h[c];
		for (int j = 0; j < 3; j++) {
			if (j != num) cnt[i][j] = cnt[i + 1][j];
			else cnt[i][j] = cnt[i + 1][j] + 1;
			//cout << cnt[i][j] << " ";
		}
		//cout << endl;
	}
	for (int i = 1; i <= n - 2; i++) {
		for (int j = i + 1; j <= n - 1; j++) {
			memset(vis, 0, sizeof(vis));
			if (s[i] == s[j]) continue;
			vis[h[s[i]]] = vis[h[s[j]]] = true;
			int lst;
			for (int t = 0; t < 3; t++)
				if (!vis[t]) lst = t;
			res += cnt[j + 1][lst];
			int delta = j - i;
			if (delta + j > n) continue;
			if (h[s[delta + j]] == lst) res--;
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 3744
def main():
  X, Y = map(int, input().split())

  Tsuru = 2*X
  if Tsuru > Y:
    print('No')
  else:
    if Tsuru == Y:
      print('Yes')
    else:
      for i in range(X):
        Tsuru += 2
        if Tsuru == Y:
          print('Yes')
          exit()
        else:
          pass
      print("No")
      

if __name__ == '__main__':
  main()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 0; --i)
#define repBX(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int sum = 0;
    rep(i,3){
        int A;
        cin >> A;
        sum += A;
    }
    cout << (sum >= 22 ? "bust" : "win") << endl;
    
    return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())

def factorize(n):
    from collections import defaultdict
    d = defaultdict(int)
    for i in range(2, int(n**0.5)+1):
        while n%i==0:
            d[i] += 1
            n //= i
        if not n:
            break
    return d

d = factorize(P)
ans = 1
for i, j in d.items():
    ans *= (i ** (j//N))
print(ans if N!=1 else P)

Measured memory_bytes: 3444
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  ll N = S.size();
  S = "2" + S;
  bool ok = true;

  if (S[1] == '0' || S[N - 1] == '0' || S[N] == '1')
    ok = false;

  vector<bool> flag((N / 2) + 1, false);
  bool all = true;
  FOR(i, 1, (N / 2) + 1) {
    if (S[i] != S[N - i])
      ok = false;
    flag[i] = (S[i] == '1');
    all &= flag[i];
  }
  // 無理
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }

  S[N] = '1';
  queue<ll> ones;
  FOR(i, 1, N + 1) {
    if (S[i] == '1')
      ones.push(i);
  }
  FOR(i, 1, N) {
    if (i == ones.front()) {
      ones.pop();
    }
    cout << i << " " << ones.front() << endl;
  }

  return 0;
}


Measured memory_bytes: 2412
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
// 2 6 22 2 1 4 1 4 1

int main() {
	int N;
	cin >> N;
	int two=0, four=0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a % 4 == 0) four++;
		else if (a % 2 == 0)two++;
	}
	if (two > 0) {
		if (N <= two + four * 2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (N <= four * 2 + 1) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = [0] * M
for i in range(M):
    a[i] = int(input())


dp = [0] * (N+1)

for i in range(N+1):
    if i == 0:
        dp[i] = 1
    elif i == 1:
        if len(a) !=0:
            if i == a[0]:
                dp[i] = 0
                a.pop(0)

            else:
                dp[i] = 1
        else:
            dp[i] = 1
    else:
        if len(a) !=0:
            if i == a[0]:
                dp[i] = 0
                a.pop(0)

            else:
                dp[i] = dp[i-1] + dp[i-2]
                dp[i] = dp[i] % 1000000007
        else:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] = dp[i] % 1000000007

ans = dp[N]
print(ans)


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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=1024;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

inline i64 readf(){
    i64 ans=0;
    char c=gc();
    while(c<48||c>57) c=gc();
    ans=c-48;
    c=gc();
    c=gc();
    while(c>=48&&c<=57) ans=ans*10+c-48,c=gc();
    return ans;
}

int main(){
    i64 A=read(),B=readf();
    print(A*B/100);
    output();
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
    long long n, k, a, b, sum;
    cin >> n >> k;
    vector<pair<int, int>> p(n);
    for (int i=0; i<n; ++i){
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    // sort int a
    sort(p.begin(), p.end());
    sum = 0;
    for(int i=0; i<n; ++i){
        sum += p[i].second;
        if(sum >= k){
            cout << p[i].first;
            break;
        }
    }
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n,m;
int ac,pen;
bool done[maxn];
int wa[maxn];

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

  cin>>n>>m;
  while (m--) {
    int id; string res; cin>>id>>res;
    if (done[id]) continue;
    if (res == "AC") {
      done[id]=true; ac++; pen+=wa[id];
    } else {
      wa[id]++;
    }
  }
  
  cout<<ac<<" "<<pen<<endl;
  

  return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

struct mint {
	typedef long long ll;
	ll x, m;
	mint(ll x=0, ll m=1e9+7): x(x%m), m(m) {}
	mint operator-() const { return mint(m-x, m); }
	mint operator+(const mint o) const { return mint(x+o.x, m); }
	mint operator-(const mint o) const { return mint(x-o.x+m, m); }
	mint operator*(const mint o) const { return mint(x*o.x, m); }
	mint& operator+=(const mint o) { x = (x+o.x)%m; return *this; }
	mint& operator-=(const mint o) { x = (x-o.x+m)%m; return *this; }
	mint& operator*=(const mint o) { x = x*o.x%m; return *this; }
	bool operator==(const mint o) const { return x==o.x; }
	bool operator!=(const mint o) const { return x!=o.x; }
	template<typename T> mint& operator=(const T o) { x = o%m; return *this; }
	template<typename T> mint operator+(const T o) const { return mint(x+o, m); }
	template<typename T> mint operator-(const T o) const { return mint(x-((ll)o)%m+m, m); }
	template<typename T> mint operator*(const T o) const { return mint(x*o, m); }
	template<typename T> mint& operator+=(const T o) { x = (x+(ll)o%m)%m; return *this; }
	template<typename T> mint& operator-=(const T o) { x = (x-((ll)o)%m+m)%m; return *this; }
	template<typename T> mint& operator*=(const T o) { x = x*((ll)o%m)%m; return *this; }
	template<typename T> bool operator==(const T o) const { return x==o%m; }
	template<typename T> bool operator!=(const T o) const { return x!=o%m; }

	mint pow(ll k) const {
		if(k==0) return mint(1, m);
		if(k%2) return pow(k-1)*x;
		mint z = pow(k/2);
		return z*z;
	}

	mint inv() const { return pow(m-2); }
};

int main(){
	int N; cin >> N;
	vector<ll> X(N);
	for(int i=0; i<N; i++) cin >> X[i];
	vector<ll> dx(N-1);
	for(int i=0; i<N-1; i++) dx[i] = X[i+1] - X[i];

	vector<mint> coeff(N-1);

	vector<mint> fact(N);
	fact[0].x = 1;
	fact[1].x = 1;
	for(int i=2; i<N; i++) fact[i] = fact[i-1] * i;

	coeff[0] = fact[N-1];
	debug(coeff[0].x);
	for(int i=1; i<N-1; i++){
		coeff[i] = coeff[i-1] + fact[N-1] * mint(i+1).inv();
		debug(coeff[i].x, fact[N-i-1].x);
	}

	mint ans(0);
	for(int i=0; i<N-1; i++){
		ans += coeff[i]*dx[i];
	}

	cout << ans.x << endl;

	return 0;
}


Measured memory_bytes: 4992
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    (a:as) <- getIntList
    let ans | a > 0 = min (snd (foldl' f (-1,1+a) as)) (snd (foldl' f (a,0) as))
            | a < 0 = min (snd (foldl' f (1,1-a) as)) (snd (foldl' f (a,0) as))
            | a == 0 = min (snd (foldl' f (-1,1) as)) (snd (foldl' f (1,1) as))
    print ans

f (s,k) a | s > 0 && s + a < 0 = (s+a,k)
          | s > 0 = (-1, k+s+a+1)
          | s < 0 && s + a > 0 = (s+a,k)
          | s < 0 = (1, k-s-a+1)

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

int main() {
    long long L, R;
    long long Max, Min;
    long long tmp;
    long long kekka = 2020;
    cin >> L >> R;

    Max = max(L, R);
    Min = min(L, R);

    for (long long i = Min; i < Max; i++) {
        for (long long j = i + 1; j <= Max; j++) {
            tmp = (i * j) % 2019;

            if (kekka == tmp) {
                cout << kekka;
                return 0;
            }

            kekka = min(kekka, tmp);
        }
    }

    cout << kekka;
}

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

using namespace std;

int main(){
    int n,l;
    cin>>n>>l;
    vector<string> hoge(n);
    
    for(int i=0;i<n;i++) cin>>hoge.at(i);
    sort(hoge.begin(),hoge.end());
    
    for(auto a:hoge) cout<<a;
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        long Y = sc.nextLong();

        for (int i = 0; i < N + 1; i++) { // 10,000
            for (int j = 0; j < N + 1 - i; j++) { // 5,000
                int k = N - i - j;
                if (k < 0) continue;
                long sum = ((long)i * 10000l) + ((long)j * 5000l) + ((long)k * 1000l);
                if (sum == Y) {
                    System.out.println(i + " " + j + " " + k);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 21844
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = 10 ^^ 5 + 1;
    auto P = new bool[](N);
    foreach (i; 2 .. N)
        P[i] = f(i);
    auto PP = new bool[](N);
    foreach (i; 3 .. N)
        PP[i] = ((i & 1) != 0) && P[i] && P[(i + 1) / 2];
    auto S = new long[](N + 1);
    foreach (i; 0 .. N)
        S[i + 1] = S[i] + PP[i];
    long Q = lread();
    foreach (_; 0 .. Q)
    {
        long l, r;
        scan(l, r);
        writeln(S[r + 1] - S[l - 1]);
    }
}

bool f(long x)
{
    foreach (i; 2 .. x)
    {
        if (x < i * i)
            return true;
        if (x % i == 0)
            return false;
    }
    return true;
}


Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    int c=4;
    int d=7;
    int temp=0;
    while(temp<=n){
        if(0==(n-temp)%7){
            cout<<"Yes"<<endl;
            return 0;
        }
        temp+=4;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.equals("AAA") || s.equals("BBB")) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;
 
ll dp[5][5050],dp2[5][25000001];
ll w[5],w2[5];
ll v[5],v2[5];

int main(){
  ll n;
  cin >> n;
  ll a[2][3];
  rep(i,2){
    rep(j,3)cin >> a[i][j];
  }
  rep(i,3){
    w[i]=a[0][i];
    v[i]=a[1][i];
    w2[i]=a[1][i];
    v2[i]=a[0][i];
  }
  v[3]=1;
  w[3]=1;
  v2[3]=1;
  w2[3]=1;
  for(int i=0;i<4;i++){
    for(int j=0;j<=n;j++){
      if(j<w[i]){
        dp[i+1][j]=dp[i][j];
      }else{
        dp[i+1][j]=max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
      }
    }
  }
  ll m=dp[4][n];
  for(int i=0;i<4;i++){
    for(int j=0;j<=m;j++){
      if(j<w2[i]){
        dp2[i+1][j]=dp2[i][j];
      }else{
        dp2[i+1][j]=max(dp2[i][j],dp2[i+1][j-w2[i]]+v2[i]);
      }
    }
  }
  cout << dp2[4][m] << endl;
return 0;}


Measured memory_bytes: 782464
//Totka hai dosto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int inf=1e18;
int32_t main()
{
	int n;
	cin>>n;
	set<string> s;
	string x;
	while(n--)
	{
		cin>>x;
		s.insert(x);
	}
	
	cout<<s.size();
	
	
	
}

Measured memory_bytes: 19152
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    tmp = input[0].split(" ");
    //文字列から10進数に変換するときはparseIntを使います
    var A = parseInt(tmp[0], 10);
    var B = parseInt(tmp[1], 10);
    var concent = 1;
    var tapNum = 0;

    while (concent < B) {
        concent += A-1;
        tapNum++;
    }
    //出力
    console.log('%d', tapNum);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
using System;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Read();
		var b = Read();

		var p2 = Enumerable.Range(0, n + 1).Select(i => 1 << i).ToArray();
		var rn = Enumerable.Range(0, n).ToArray();

		var m = Enumerable.Range(0, p2[n])
			.Select(x => Array.ConvertAll(rn, i => (x & p2[i]) == 0 ? (a[i], false) : (b[i], true)))
			.Select(Swap)
			.Min();
		Console.WriteLine(m == 1 << 30 ? -1 : m);

		int Swap((int v, bool rev)[] c)
		{
			var g = Array.ConvertAll(c, _ => _.v);
			Array.Sort(g);
			var u = new bool[n];

			var map = new int[n];
			for (int i = 0; i < n; i++)
			{
				map[i] = -1;
				for (int j = 0; j < n; j++)
				{
					if (u[j] || g[i] != c[j].v || (i - j) % 2 != 0 != c[j].rev) continue;
					u[j] = true;
					map[i] = j;
					break;
				}
				if (map[i] == -1) return 1 << 30;
			}

			var t = 0;
			for (int i = 0; i < n; i++)
				for (int j = i + 1; j < n; j++)
					if (map[i] > map[j]) t++;
			return t;
		}
	}
}


Measured memory_bytes: 46916
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
using namespace std;
int main() {
	long long dp[31];
	int n;
	while (cin >> n&&n != 0) {
		for (int i = 0; i <= n; i++) {
			dp[i] = 0;
		}
		dp[0] = 1;

		for (int i = 0; i <= n; i++) {
			for (int j = 1; j <= 3; j++) {
				if (i - j >= 0) {
					dp[i] += dp[i - j];
				}
			}
		}
		long long a = ceil(dp[n] / 10.0);
		int b = a % 365;
		if (b == 0) cout << a / 365 << endl;
		else cout<<a / 365 + 1 << endl;
	}
}

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

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

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


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

int i_dsort(const void* a, const void* b);
int i_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_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

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));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}

#pragma endregion

// ABC 082 C-Together
int main(void) {
	int n,a[100005],i;

	memset(a, 0, sizeof(a));

	scanf("%d", &n);
	int aa;

	for (i = 0; i < n; i++) {
		scanf("%d", &aa);
		a[aa]++;
	}
//	for (i = 0; i <= 100; i++) 
//		printf("%d ", a[i]);

	int tmp,ans=0;
	for (i = 0; i < 100001; i++) {
		if (a[i]==0)continue;
		if(i != 0)
	    	tmp = a[i] + a[i - 1] + a[i + 1];
		else
			tmp = a[i] + a[i + 1];
		ans = _max(tmp, ans);
	}
//	printf("\nans:");
	printf("%d\n",ans);
   return 0;
}







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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int num[3];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    rep(i, s.size()) {
        num[s[i]-'a']++;
    }
    rep(i, 3) rep(j, 3) {
        if (abs(num[i] - num[j]) > 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll MAX = 600000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
	COMinit();
	ll n,k;
	cin >> n >> k;
	vector<ll> a(n);
	for(ll i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	ll ans = 0;
	for(ll i = 0;i<n-k+1;i++)
	{
		ans += ((MOD-a[i])*COM(n-i-1,k-1))%MOD;
		ans %= MOD;
	}
	sort(a.rbegin(),a.rend());
	for(ll i = 0;i<n-k+1;i++)
	{
		ans += (a[i]+MOD)*COM(n-i-1,k-1);
		
		ans %=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 18048
#include<stdio.h>
int main()
{
	char t[200005];
	scanf("%s", t);
	int i, n = 0;
	while (t[n] != '\0')
		n++;
	for (i = 0; i < n; i++)
		if (t[i] == '?')
			t[i] = 'D';
	printf("%s\n", t);
	return 0;
}

Measured memory_bytes: 1800
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int H=gi();
	    int W=gi();
	    int[][] c=new int[10][10];
	    int[][] A=new int[H][W];

	    for (int i=0; i<10;i++) {
	    	for (int j=0; j<10;j++) {
		    	c[i][j]=gi();
		    }
	    }
	    for (int i=0; i<H;i++) {
	    	for (int j=0; j<W;j++) {
		    	A[i][j]=gi();
		    }
	    }

	    for (int i=0; i<10;i++) {
	    	for (int j=0; j<10;j++) {
	    		for (int k=0; k<10;k++) {
                    c[j][k]=Math.min(c[j][k], c[j][i]+c[i][k]);
	    	    }
		    }
	    }

	    int ans=0;
	    for (int i=0; i<H;i++) {
	    	for (int j=0; j<W;j++) {
	    		int a=A[i][j];
	    		if(a!=-1)ans+=c[a][1];
		    }
	    }

        System.out.println(ans);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

#define ll long long
using namespace std;
#define REP(i,j,n) for(int i = j; i < (n); i++)

void sol(int n) {
    vector<int> a(n);
    REP(i,0,n) cin >> a[i];

    int dp[n+1][n+1];
    REP(i,0,n+1) REP(j,0,n+1) dp[i][j] = 0;
    REP(j,1,n+1){
        REP(i,0,j){
            dp[i][j] = dp[i][j-1];
            if(i <= j-2) dp[i][j] = max(dp[i][j],dp[i][j-2]+(abs(a[j-1]-a[j-2])<=1)*2);
            REP(k,i,j){
                dp[i][j] = max(dp[i][j],dp[i][k]+dp[k+1][j-1]+(j-1 != k && (j-1)-(k+1) == dp[k+1][j-1] && abs(a[j-1]-a[k])<=1)*2);
            }
        }
    }

    cout << dp[0][n] << endl;

    return;
}

int main() {
    int n;
    
    while(cin >> n , n){
        sol(n);
    }
    return 0;
}


Measured memory_bytes: 3424