akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const int maxn=2e5+10;
const LL inf=1e18;
typedef pair<LL,int> P;
char s[4005];
int n;
LL sum[4005][3];
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++){
       if(s[i]=='R'){
        sum[i][0]=sum[i-1][0]+1;
        sum[i][1]=sum[i-1][1];
        sum[i][2]=sum[i-1][2];
       }
       else
       if(s[i]=='G'){
        sum[i][1]=sum[i-1][1]+1;
        sum[i][0]=sum[i-1][0];
        sum[i][2]=sum[i-1][2];
       }
       else{
        sum[i][2]=sum[i-1][2]+1;
        sum[i][0]=sum[i-1][0];
        sum[i][1]=sum[i-1][1];
       }
    }
   /* for(int i=1;i<=n;i++){
        printf("%lld ",sum[i][0]);
    }
    printf("\n");
    for(int i=1;i<=n;i++){
        printf("%lld ",sum[i][1]);
    }
    printf("\n");
    for(int i=1;i<=n;i++){
        printf("%lld ",sum[i][2]);
    }
    printf("\n");*/
    LL res=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(s[i]!=s[j]){
                    int k=j+(j-i);
                if(s[i]=='R'&&s[j]=='G'||s[i]=='G'&&s[j]=='R'){
                   // int k=j+(j-i);

                    if(k>=1&&k<=n&&s[k]=='B'){
                        res+=max((sum[n][2]-sum[j][2]-1),0LL);
                    }
                    else{
                        res+=(sum[n][2]-sum[j][2]);
                    }
                }
                else
                if(s[i]=='R'&&s[j]=='B'||s[i]=='B'&&s[j]=='R'){
                    if(k>=1&&k<=n&&s[k]=='G'){
                        res+=max((sum[n][1]-sum[j][1]-1),0LL);
                    }
                    else{
                        res+=(sum[n][1]-sum[j][1]);
                    }
                }
                else
                if(s[i]=='G'&&s[j]=='B'||s[i]=='B'&&s[j]=='G'){
                    if(k>=1&&k<=n&&s[k]=='R'){
                        res+=max((sum[n][0]-sum[j][0]-1),0LL);
                    }
                    else{
                        res+=(sum[n][0]-sum[j][0]);
                    }
                }
            }
        }
    }
    printf("%lld\n",res);
    return 0;
}


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

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<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T lcm(T a,T b){return a*b/gcd(a,b);}

const ll INF = 1LL << 60;

int main(){
  string s;
  cin >> s;
  int n=s.size();
  int count1=0,count0=0;
  ////count 010101
  FOR(i,n){
    if(i%2==0){
      if(s[i]=='1'){
        count0++;
      }
    }else{
      if(s[i]=='0'){
        count0++;
      }
    }

  }

  ////count 101010
  FOR(i,n){
    if(i%2==0){
      if(s[i]=='0'){
        count1++;
      }
    }else{
      if(s[i]=='1'){
        count1++;
      }
    }
  }
  cout << min(count0,count1) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(val) cerr << "Value " << #val << " : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ld epsilon = 10e-9;
const ll nax = 2e5+5;
ll n, m, k, a[nax], b[nax], maks=0, pref[nax];
	
int main(void){
	IOS
	cin >> n >> m >> k;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	pref[0]=0;
	for(int i=1;i<=m;i++){
		cin >> b[i];
		pref[i]=pref[i-1]+b[i];
		if(pref[i]<=k){
			maks=i;
		}
	}
	ll sums=0;
	for(int i=1;i<=n;i++){
		sums+=a[i];
		ll mid, l=0, r=m, ret=-1;
		while(l<=r){
			mid=(l+r)/2;
			if(pref[mid]+sums<=k){
				ret=mid;
				l=mid+1;
			}
			else{
				r=mid-1;
			}
		}
		if(ret==-1) continue;
		maks=max(maks, ret+i);
	}
	cout << maks << '\n';
}


Measured memory_bytes: 8328
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

int n,a,b,cnt=0;
int flag[M];
int dist1[M]={},distn[M]={};
vi g[M];

void __dist(int node,int y[]){
	flag[node]=true;
	for(auto x:g[node])
		if(!flag[x]){
			y[x]=(y[node]+1);
			__dist(x,y);
		}
}

int main(){
	int n;ll m,i,t;
	ll h1[M],h2[M],h3[M],h4[M],x[M],y[M],s;
	cin>>n>>m;
	for (i=1;i<=n;i++)
		cin>>x[i]>>y[i];
	for (i=1,t=0;i<=n;i++)
		t=t+y[i],h1[i]=max(h1[i-1],t-x[i]),h2[i]=max(h2[i-1],t-2*x[i]);
	for (i=n,t=0;i>0;i--)
		t=t+y[i],h3[i]=max(h3[i+1],t-(m-x[i])),h4[i]=max(h4[i+1],t-2*(m-x[i]));
	for (i=0;i<=n;i++)
		s=max(s,max(h1[i]+h4[i+1],h2[i]+h3[i+1]));
	print(s);
	return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int MAX = 1e+5 + 5;
const ll LINF = 1LL << 50;
const int mod = 1e+9 + 7;
/* global variables */
int N;
vector<vector<int>> G(MAX, vector<int>());
vector<vector<ll>> dp(MAX, vector<ll>(2));
vector<bool> used(MAX);
/* funciton */
void dfs(int x) {
    if (used[x]) return ;
    used[x] = true;
    // dp[x][0] = Node-x, White
    // dp[x][1] = Node-x, Black
    dp[x][0] = 1;
    dp[x][1] = 1;
    for (int y : G[x]) {  // y = x.child
        if (used[y]) continue;
        dfs(y);
        // x-(White) -> x.child-(White or Black)
        dp[x][0] = (dp[x][0] * (dp[y][0] + dp[y][1])) % mod;
        // x-(Black) -> x.child-(White)
        dp[x][1] = (dp[x][1] * dp[y][0]) % mod;
    }
}
/* main */
int main() {
    cin >> N;
    for (int i = 0; i < N-1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(0);
    ll ans = (dp[0][0] + dp[0][1]) % mod;
    cout << ans << '\n';
}

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

a.sort()
cnt = 1
ans = 0
key = a[0]

for i in range(1,len(a)):
    if a[i] == key:
        cnt += 1
    else:
        if cnt >= a[i-1]:
            ans += ( cnt - a[i-1] )
        else:
            ans += cnt

        cnt = 1
        key = a[i]

if cnt >= a[len(a)-1]:
    ans += ( cnt - a[len(a)-1] )
else:
    ans += cnt

print(ans)


Measured memory_bytes: 15260
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct obj{
	struct obj *prev;
	struct obj *next;
	int key;
}obj;

typedef struct{
	struct obj *root;
	struct obj *last;
}dlist;

obj *createObj(int key){
	obj *ob;
	mymalloc(ob,1);
	ob->prev=NULL;
	ob->next=NULL;
	ob->key=key;
	return ob;
}

dlist *createDlist(){
	dlist *list;
	mymalloc(list,1);
	list->root=NULL;
	list->last=NULL;
}

void insert(dlist *list,int key){
	obj *input;
	input=createObj(key);
	if(list->root==NULL){
		list->root=input;
		list->last=input;
	}
	else{
		list->root->prev=input;
		input->next=list->root;
		list->root=input;
	}
}

void deleteL(dlist *list){
	if(list->last!=NULL){
		if(list->last->prev==NULL){
			list->last=NULL;
			list->root=NULL;
		}
		else{
			list->last=list->last->prev;
			list->last->next=NULL;
		}
	}
}

obj *deleteF(dlist *list){
	obj *output;
	if(list->root==NULL){
		return NULL;
	}
	else{
		output=list->root;
		if(list->root->next==NULL){
			list->root=NULL;
			list->last=NULL;
		}
		else{
			list->root=list->root->next;
			list->root->prev=NULL;
		}
		return output;
	}
}

void deleteX(dlist *list, int key){
	 obj *ob;
	 if(list->root==NULL){return;}
	 ob=list->root;
	 while(1){
	 	if(ob->key==key){
	 		if(ob->next==NULL){
	 			deleteL(list);
	 		}else{
	 		if(ob->prev==NULL){
	 			deleteF(list);
	 		}else{
				ob->prev->next=ob->next;
				ob->next->prev=ob->prev;
	 		}}
	 		return;
	 	}
	 	else{
	 		if(ob->next==NULL){return;}
	 		else{ob=ob->next;}
	 	}
	 }
}

main(){
	int i,n,m;
	char com[15];
	dlist *list;
	obj *ob;
	list=createDlist();
	scanf("%d ",&n);
	for(i=1;i<=n;i++){
		scanf(" %s",com);
		if(strcmp(com,"insert")==0){
			scanf(" %d",&m);
			insert(list,m);
		}else{
		if(strcmp(com,"delete")==0){
			scanf(" %d",&m);
			deleteX(list,m);
		}else{
		if(strcmp(com,"deleteFirst")==0){
			deleteF(list);
		}else{
		if(strcmp(com,"deleteLast")==0){
			deleteL(list);
		}}}}
		/*ob=list->root;
		while(ob!=NULL){
			printf("%d ",ob->key);
			ob=ob->next;
		}
		printf("\n");*/
	}
	
	ob=deleteF(list);
	while(1){
		printf("%d",ob->key);
		ob=deleteF(list);
		if(ob==NULL){printf("\n");break;}
		else{printf(" ");}
	}
	return 0;
}

Measured memory_bytes: 34976
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k,s;
	cin>>a>>b>>c>>k;
	if ((a+b)>=k)
	{
	if(a>=k)
	cout<<k<<endl;
	else
	cout<<a<<endl;
	}
    else
    {
		k=k-a-b;
		s=a-k;
		cout<<s<<endl;;
	}
  return 0;
}

Measured memory_bytes: 3624
M=998244353;n,A,B,K=map(int,input().split());F=[1];a=0
for i in range(n):F+=[F[-1]*(n-i)*pow(i+1,M-2,M)%M]
for i in range(n+1):
 r=K-i*A;q=r//B
 if(r%B==0)&(0<=q<=n):a+=F[i]*F[q]
print(a%M)

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

ll g(ll a,ll b){
    while(b>0){
        ll y=a;
        a=b;
        b=y%a;
    }
    return a;
}

int main() {
    ll n,x; cin >> n >> x;
    vector<ll> p(n+1);
    rep(i,n) cin >> p[i];
    p[n]=x;
    sort(p.begin(),p.end());
    vector<ll> q(n);
    rep(i,n) q[i]=p[i+1]-p[i];
    ll gcd=0;
    rep(i,n) {
        gcd=g(gcd,q[i]);
    }
    cout << gcd << endl;
}

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

int main() {
	ll N,s=0;
	cin >> N;
	vector<ll> A(N);
	map<ll,ll> m;

	rep(i,N) {
		cin >> A.at(i);
		if(m.count(A.at(i)))
			++m.at(A.at(i));
		else
			m[A.at(i)] = 1;
	}

	for(auto p : m)
		s += p.second*(p.second-1)/2;

	rep(i,N) {
		ll t = s;
		t -= m.at(A.at(i))*(m.at(A.at(i))-1)/2;
		t += (m.at(A.at(i))-1)*(m.at(A.at(i))-2)/2;
		cout << t << endl;
	}
}

Measured memory_bytes: 11920
#include<stdio.h>



#include<string.h>



#include<math.h>



int main(){

long long b,m;

scanf("%lld ",&m);



long long a[m],c[m];

for(b=0;b<m;b++){

 c[b]=0;

 }

long long d;

for(b=1;b<m;b++){

 scanf("%lld",&a[b]);

 d=a[b]-1;

 c[d]++;

 }



for(b=0;b<m;b++)

 printf("%lld\n",c[b]);



return 0;}

Measured memory_bytes: 4852
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int [2];
        int[] b = new int [2];
        for(int i = 0;i < 2;i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;i < 2;i++){
            b[i] = sc.nextInt();
        }
        int ans = Math.min(a[1],b[1]) - Math.max(a[0],b[0]);
        if(ans <= 0){
            System.out.println(0);
            return;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cstdlib>  

using namespace std;

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

const long long INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100100;

int N;
long long W, w[110], v[110];
// long long dp[110][100100] = {0};
long long dp[MAX_N][MAX_V];

int main(){
    cin >> N >> W;
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    for (int i = 0; i < MAX_N; i++){
        for (int j = 0; j < MAX_V; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int sum_v = 0; sum_v < MAX_V; sum_v++){
            // i番目の品物を選ぶとき
            if (sum_v - v[i] >= 0) {
                chmin(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            }
            // i番目の品物を選ばないとき
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    long long res = 0;
    for (int sum_v = 0; sum_v< MAX_V; sum_v++) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}





Measured memory_bytes: 86400
#include<iostream>
#include<algorithm>
using namespace std;
signed main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a<b&&a<c&&b<c){
    cout<<"Yes\n";
  }
  else{
    cout<<"No\n";
  }
  return(0);
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

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

  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  for(int i = 0; i < N; i++) {
    cin >> s[i] >> t[i];
  }
  string X;
  cin >> X;

  int cnt = 0;
  bool judge = false;
  for(int i = 0; i < N; i++) {
    if(judge) {
      cnt += t[i];
    }
    if(s[i] == X) {
      judge = true;
    }
  }

  cout << cnt << endl;

    return 0;
}


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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long M = inputArray[1];

			var menu = new long[N][];

			for (int i = 0; i < N; i++) {
				var inpArray = retreiveLongArray();
				menu[i]= inpArray;
			}

			var patterns = new int[8] [];
			patterns[0] =new int []{ 1, 1, 1 };
			patterns[1] = new int[] { -1, 1, 1 };
			patterns[2] = new int[] { 1, -1, 1 };
			patterns[3] = new int[] { 1, 1, -1 };
			patterns[4] = new int[] { -1, -1, 1 };
			patterns[5] = new int[] { -1, 1, -1 };
			patterns[6] = new int[] { 1, -1, -1 };
			patterns[7] = new int[] { -1, -1, -1 };

			long max = 0;

			foreach (var pattern in patterns) {
				var sortedMenu = menu.Select(x => x[0] * pattern[0] + x[1] * pattern[1] + x[2] * pattern[2]).OrderByDescending(x => x).ToArray() ;
				var maxInPattern = sortedMenu.Take((int)M).Sum();
				max = Math.Max(max, maxInPattern);
			}


			//答えの出力
			var ans = max;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


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

using i64 = int64_t;
template <class T> using Vec = std::vector<T>;
template <class K, class V> using UM = std::unordered_map<K, V>;

using namespace std;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

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

    Vec<int> as(n);
    for (auto &a : as) cin >> a;

    for (int ik = 0; ik < k; ++ik) {
        Vec<int> bs(n + 1);

        for (int i = 0; i < n; ++i) {
            bs[max(0, i - as[i])] += 1;
            bs[min(n, i + as[i] + 1)] -= 1;
        }

        for (int i = 0; i < n; ++i) bs[i + 1] += bs[i];
        bs.pop_back();

        swap(as, bs);
        if (bs == as) break;
    }

    for (auto a : as) cout << a << " ";

    return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000 //10^12
using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;

    ll **dp = new ll *[N + 1];
    dp[0] = new ll[3];
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    FOR(n, 1, N)
    {
        dp[n] = new ll[3];
        ll a, b, c;
        cin >> a >> b >> c;

        dp[n][0] = max(dp[n - 1][1], dp[n - 1][2]) + a;
        dp[n][1] = max(dp[n - 1][0], dp[n - 1][2]) + b;
        dp[n][2] = max(dp[n - 1][0], dp[n - 1][1]) + c;
    }

    cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;
    return 0;
}

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

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

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

#define M 1000000007

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

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

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

int main() {
    fast;
    ll n;
    cin >> n;
    vi par(n-1);
    REP(i, 0, n-1)
        cin >> par[i];
    vi sub(n+1, 0);
    REP(i, 0, n-1)
        sub[par[i]]++;
    REP(i, 1, n+1)
        cout << sub[i] << endl;
}


Measured memory_bytes: 6332
queue = []
sum_prc_time = 0

n, max_time = map(int, input().split())

def main_prc(prc_dat):
  global queue
  global sum_prc_time

  prc_time = int(prc_dat[-1])
  diff = prc_time - max_time

  if diff <= 0:
    sum_prc_time += prc_time
    print(f"{prc_dat[0]} {sum_prc_time}")
  else:
    sum_prc_time += max_time
    queue.append([prc_dat[0], diff])

for i in range(n):
  main_prc(input().split())

while 0 < len(queue):
  main_prc(queue.pop(0))



Measured memory_bytes: 8132
#include <bits/stdc++.h>
using namespace std;
#define removeDuplicate(a) sort(a.begin(), a.end()); a.resize(distance(a.begin(), unique(a.begin(), a.end())));


const long long N = 1e5 + 10; 
long long n; 
long long a[N]; 

int main() {
    #define file "in"
    //freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);

    cin >> n; 
    for (long long i = 0; i < n; i++) cin >> a[i]; 
    long long sum = 0; 
    for (long long i = 0; i < n; i++) {
    	sum += a[i]; 
    }
    if (sum % ((n) * (n + 1) / 2) != 0) {
    	cout << "NO"; 
    	return 0; 
    }
    long long nTurn = sum / ((n) * (n + 1) / 2);
    long long cnt = 0; 
    for (long long i = 0; i < n; i++) {
    	long long j = (i + 1) % n; 
    	if ((a[i] - a[j] + nTurn) % n != 0) {
    		cout << "NO"; 
    		return 0; 
    	}
    	if ((a[i] - a[j] + nTurn) / n < 0) {
    		cout << "NO"; 
    		return 0; 
    	}
    	cnt += (a[i] - a[j] + nTurn) / (n);
    } 
    if (cnt != nTurn) {
    	cout << "NO"; 
    	return 0; 
    }
    cout << "YES"; 
    return 0;
}

Measured memory_bytes: 1024
import java.io._
import scala.io.Source

object Main {
  var size = 0
  var count = 0
  val out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FileDescriptor.out), "ASCII"), 512)

  def swap(a:Array[Int],i:Int,j:Int,ai:Int,aj:Int) =  {
    a(i) = aj
    a(j) = ai
  }

  def up(a:Array[Int], i:Int):Unit = {
    val j = i >> 1
    if(j>0 && a(j-1) < a(i-1)) { swap(a,j-1,i-1,a(j-1),a(i-1)); up(a,j) }
  }

  def down(a:Array[Int], i:Int, temp:Int):Unit = {
    var largest = i
    val j = (i+1) << 1
    if(j>size) a(i) = temp
    else {
       val max = if(j==size) j-1 else if(a(j-1) >= a(j)) j-1 else j
       if(a(max)>temp) { a(i) = a(max); down(a,max,temp) }
       else a(i) = temp
    }
  }

  def extract(a:Array[Int]):Int = {
    val max = a(0)
    if(size>0) {
      a(0) = a(size-1)
      size -= 1
      down(a,0,a(0))
      a(size) = 0
    }
    max
  }

  def insert(a:Array[Int], n:Int) = {
    a(size) = n
    size += 1
    up(a,size)
  }

  def main(args:Array[String]) = {
    val a = new Array[Int](2000000)
    var s = ""
    Source.stdin.getLines.takeWhile(_!="end").foreach { s =>
      val op = s.split(" ")
      if(op(0) == "insert") {
        insert(a, op(1).toInt)
      } else if(op(0) == "extract") {
        val x = extract(a).toString
        out.write(x)
        out.write("\n")
        if(count<100) count += 1
        else {
         out.flush
         count = 0
        }
      }
    }
    out.flush
  }
}

Measured memory_bytes: 460592
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

int n, t, a;

ld A[1000+2];

void solve(){
	cin >> n >> t >> a;
	ll ans = LLONG_MAX, pans;
	for (int i=1; i<=n; ++i){
		cin >> A[i];
		int temp = t*1000 - A[i]*6;
		if (abs(temp-a*1000) < ans){
			ans = abs(temp-a*1000);
			pans = i;
		}
	}
	cout << pans;
}	

int main(){ FIO;
	solve();
return 0;}

Measured memory_bytes: 256
#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>
#include<functional>
#include<assert.h>
#include<numeric>
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)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int m = 2*n;
    vector<int> a,b;
    if(s[m-1]=='W'){
        cout<<0<<endl;
        return 0;
    }
    int dig = 0;
    for(int i = m-1;i>=0;--i){
        if(s[i]=='W'){
            if(dig)b.push_back(i);
            else a.push_back(i);
        }
        else {
           if(!dig)b.push_back(i);
            else a.push_back(i); 
        }
        dig^=1;
    }
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    ll ans = 1;
    if(a.size()!=n){
        cout<<0<<endl;
        return 0;
    }
    rep(i,n){
        int idx = lower_bound(a.begin(),a.end(),b[i])-a.begin();
        ans = ans * (idx-i) % mod;
        ans = ans * (i+1) % mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1744
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
std::vector<char> S;
int main() {
	for (int i = 0; i < 3; i++) {
		char tmp;
		std::cin >> tmp;
		S.push_back(tmp);
	}
	std::sort(S.begin(), S.end());
	if (S[0] == 'a'&&S[1] == 'b'&&S[2] == 'c') {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;

	}
	return 0;
}

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

/* -------------------------------- Template -------------------------------- */

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/* -------------------------------- Library -------------------------------- */

typedef int Weight;
Weight INF = 1000000000;
struct Edge{
  int src, dest; Weight weight;
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Weight weight) {
  g[src].push_back((Edge){src, dest, weight});
}

void bfs01(Graph &g, vector<int> &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  deque<P> que;
  que.push_back(P(0, s));
  while (!que.empty()) {
    P top = que.front(); que.pop_front();
    Weight dist = top.first; int v = top.second;
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        if (e.weight) que.push_back(P(d[e.dest], e.dest));
        else que.push_front(P(d[e.dest], e.dest));
      }
    }
  }
}

/* ---------------------------------- Main ---------------------------------- */

int N, M;

map<pair<int,int>,int> ma;

int dict(int x, int y) {
  auto p = make_pair(x, y);
  if (ma.count(p)) return ma[p];
  int res = ma.size() + N;
  ma[p] = res;
  return res;
}

int main() {
  Graph g(500000);
  cin >> N >> M;
  REP(i,M) {
    int p, q, c;
    cin >> p >> q >> c;
    --p; --q;
    int from = dict(p, c), to = dict(q, c);
    add_edge(g, from, to, 0);
    add_edge(g, to, from, 0);
  }
  for (auto pi: ma) {
    int p, c, id;
    tie(p, c) = pi.first;
    id = pi.second;
    add_edge(g, p, id, 1);
    add_edge(g, id, p, 1);
  }
  vector<int> dist;
  bfs01(g, dist, 0);
  if (dist[N-1] == INF) cout << -1 << endl;
  else cout << dist[N-1] / 2 << endl;
  return 0;
}


Measured memory_bytes: 59648
s = list(input())

flag = True
if s[0] != "A":
    flag = False

ss = s[2:-1]
if ss.count("C") != 1:
    flag = False
for si in s:
    if si != "A" and si != "C":
        if si.islower() != True: 
            flag = False
            
print("AC" if flag else "WA")


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

int main()
{
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if((r<=x)&&(x<=W-r)&&(r<=y)&&(y<=H-r)) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e7 * 2, S2 = 1e7 * 2;

int main() {
    fastInp;

    ll s, c, c2, ans = 0;
    cin >> s >> c;

    ll l = 0, r = c + 1;

    while (r - l > 2) {
        ll mid = (l + r) / 2, mid2 = (l + r) / 2 + 1;
        ll s1 = s + (mid), c1 = c - mid * 2, s2 = s + mid2, c2 = c - (mid2 * 2);
        if (c2 < 0 || c1 < 0) {
            r = mid;
            continue;
        }
        if (min(s1, c1 / 2) < min(s2, c2 / 2)) {
            l = mid;
        }
        else {
            r = mid;
        }
        ans = max(ans, min(s1, c1 / 2));
        ans = max(ans, min(s2, c2 / 2));
    }

    for (ll mid = l; mid <= r; mid++) {
        ll s1 = s + (mid), c1 = c - mid * 2;
        if (c1 >= 0) {
            ans = max(ans, min(s1, c1 / 2));
        }
    }

    cout << ans;
    return 0;
}



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

int main(){
	int n,ans=0,minj;
	int a[N];
	cin >> n;
	for(int i=0;i<n;i++){
		int k;
		cin >> k;
		a[i]=k;
	}	
	for(int i=0;i<n;i++){
		minj = i;
		for(int j=i;j<n;j++){
			if(a[j]<a[minj]){
				minj = j;
			}
		}
		if(minj!=i){
			int k = a[i];
			a[i] = a[minj];
			a[minj] = k;
			ans++;
		}
	}
	for(int i=0;i<n;i++){
		cout << a[i];
		if(i != n-1){
			cout << " ";
		}
	}
	cout << endl << ans << endl;
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;

int main(){
    ll h; cin >> h;
    ll ans = 0, cnt = 1;
    while(h != 0){
        ans += cnt;
        h = floor(h/2);
        cnt *= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
K = int(input())

def block(d, digits, count):
    if d == 1:
        return (digits if count == 1 else None), (count-1)
    s = digits[-1]
    for i in range(max(s-1, 0), min(s+2, 10)):
        answer, count = block(d-1, digits + [i], count)
        if answer:
             return answer, count
    return None, count

def solve():
    if K <= 9:
        return [K]
    count = K - 9
    for d in range(2,10**9):
        for i in range(1,10):
            answer, count = block(d, [i], count)
            if answer:
                return answer

print(''.join(str(d) for d in solve()))


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

const int N = 550000;
const int mod = 1e9 + 7;

int a[N], s[N], f[N], sum[N], fsum[N], zero[N];
vector<int> v[N*2];

int main() {
#ifdef Hwang_Baek_I
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) s[i] = s[i - 1] ^ a[i];
	for (int i = 1; i <= n; i++) {
		zero[i] = zero[i - 1];
		if (s[i] == 0) zero[i]++;
	}
	v[0].push_back(0);
	for (int i = 1; i <= n; i++) {
		v[s[i]].push_back(i);
		if (s[i] == 0) continue;
		int cnt = v[0].back();
		cnt = lower_bound(v[s[i]].begin(), v[s[i]].end(), cnt) - v[s[i]].begin();
		if (cnt == 0) {
			f[i] = 1;
			sum[i] = v[s[i]].size();
			fsum[i] = 0;
			continue;
		}
//		f[i] = (sum[v[s[i]][cnt - 1]] + 1) % mod;
//		sum[i] = (sum[v[s[i]][v[s[i]].size() - 2]] + f[i]) % mod;
		f[i] = (fsum[v[s[i]][cnt - 1]] + (long long)sum[v[s[i]][cnt - 1]] * (zero[i] - zero[v[s[i]][cnt - 1]]) + 1) % mod;
		cnt = v[s[i]][v[s[i]].size() - 2];
		sum[i] = (sum[cnt] + f[i]) % mod;
		fsum[i] = (fsum[cnt] + (long long)sum[cnt] * (zero[i] - zero[cnt])) % mod;
	}
//	for (int i = 1; i <= n; i++) cerr << s[i] << " "; cerr << endl;
//	for (int i = 1; i <= n; i++) cerr << f[i] << " "; cerr << endl;
//	for (int i = 1; i <= n; i++) cerr << sum[i] << " "; cerr << endl;
//	for (int i = 1; i <= n; i++) cerr << fsum[i] << " "; cerr << endl;
	if (s[n]) {
		cout << f[n] << endl;
	}
	else {
		int ans = 0;
		for (int i = 1; i <= n; i++) if (s[i]) (ans += f[i]) %= mod;
		int cur = 1;
		for (int i = 2; i < v[0].size(); i++) cur = cur * 2 % mod;
		ans += cur;
		ans %= mod;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 48372
import fractions

n = int(input())
P = list(map(int, input().split()))
a = 1
for i in range(n):
    a = a * P[i] // fractions.gcd(a, P[i])

a -= 1
ans = 0
for i in range(n):
    ans += a % P[i]

print(ans)

Measured memory_bytes: 5304
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> p(n);

	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	sort(p.begin(), p.end());



	printf("%d", p[n / 2] - p[n / 2 - 1]);

	return 0;
}

Measured memory_bytes: 640
#include<iostream>

int n,c[20],v[50],res;

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

    for(int i=0;i<n;i++)
    std::cin>>v[i];

    for(int i=0;i<n;i++){
    std::cin>>c[i];
    if(c[i]<v[i])
    res+=v[i]-c[i];
    }

    std::cout<<res<<std::endl;

    return 0;
}

Measured memory_bytes: 256
def ha(mm,x):
    mm=[1  if i//x >=1 else 0 for i in mm]
    if sum(mm)>=len(mm):
        return 0
    else:
        return 1

def so(hr,ca,m,an):
    wk = 0
    mm = [0]*m
    for i in range(len(hr)):
        if hr[i] == 1:
            wk += ca[i][0]
            hr[i] = 1
            for j in range(m):
                mm[j] += ca[i][j+1]
        else:
            i += 1
    if ha(mm,x)==0:
        an=min(wk,an)
        return an
    return an

n,m,x = map(int, input().split())

ca=[]
an = 0
for i in range(n):
    ca.append(list(map(int,input().split())))
    an += ca[i][0]

an += 1
han = an
hr = [0]*n
for ka in range(1,2**n):
    hr = [int(i) for i in list(format(ka, 'b').zfill(n))]
    an = so(hr,ca,m,an)
if an == han:
    print('-1')
else:
    print(an)

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

int main(){
  int n,k;
  cin>>n>>k;
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  string s;
  cin>>s;
  int a=0;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1]){
      a++;
    }
  }
  a=max(0,a-2*k);
  cout<<n-a-1<<endl;
}

Measured memory_bytes: 512
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 5e3 + 10;

int wt[N];
ll dp[N][N];

int main() {
	fast_cin();
	int n, mod;
	cin >> n >> mod;
	int k = (n - 1) / 2;
	for (int i = 2; i <= n; ++i) {
		if (i < n - k + 1) {
			wt[i] = i - 1;
		} else {
			wt[i] = n + 2 - i;
		}
	}
	dp[1][n] = 1;
	for (int i = 1; i < n; ++i) {
		for (int val = 1; val <= n; ++val) {
			dp[i][val] %= mod;
			int max_x = val / wt[i + 1];
			for (int x = 0; x <= max_x; ++x) {
				dp[i + 1][val - x * wt[i + 1]] += dp[i][val];
			}
		}
	}
	ll ans = 0;
	for (int val = 1; val <= n; ++val) {
		dp[n][val] %= mod;
		ans += val * dp[n][val];
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=2e5+5;
const int mod=1e9+7;
vector<int>g[maxn];
int vis[maxn];
ll dp[maxn];
queue<int>q;
int main(){
    int n,Q,ai,bi,pj,xj;
    scanf("%d%d",&n,&Q);
    for(int i=1;i<n;i++){
        scanf("%d%d",&ai,&bi);
        g[ai].push_back(bi);
        g[bi].push_back(ai);
    }
    memset(dp,0,sizeof(dp));
    memset(vis,0,sizeof(vis));
    while(Q--){
        scanf("%d%d",&pj,&xj);
        dp[pj]+=xj;
    }
    q.push(1);
    vis[1]=1;
    while(!q.empty()){
        int now=q.front();
        q.pop();
        for(auto c:g[now]){
            if(!vis[c]){
                vis[c]=1;
                dp[c]+=dp[now];
                q.push(c);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(i==1) printf("%lld",dp[i]);
        else printf(" %lld",dp[i]);
    }
    printf("\n");
}


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

int main() {
    int Y, C[6] = {500, 100, 50, 10, 5, 1};
    while (cin >> Y) {
        if (Y == 0) break;
        int ans = 0, charge = 1000 - Y;
        for (int i = 0; i < 6; ++i) {
            int t = charge / C[i];
            charge -= t * C[i];
            ans += t;
        }
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
from collections import Counter
n,*a=map(int,open(0).read().split())
C=Counter(a)
s=sum(x*(x-1)//2 for x in C.values())
ans=[]
for x in a:
	c=C[x]
	t=s-c*(c-1)//2+(c-1)*(c-2)//2
	ans.append(t)
print(*ans,sep="\n")

Measured memory_bytes: 30964
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] A = new int[N+1];
    int[] B = new int[N+1];
    int[] C = new int[N];
    for(int i = 1; i <= N; i++){
      A[i] = Integer.parseInt(sc.next());
    }
    for(int i = 1; i <= N; i++){
      B[i] = Integer.parseInt(sc.next());
    }
    for(int i = 1; i <= N-1; i++){
      C[i] = Integer.parseInt(sc.next());
    }
    
    int sum = 0;
    int bef = -1;
    for(int i = 1; i <= N; i++){
      int n = A[i];
      sum += B[n];
      if(bef+1 == n){
        sum += C[bef];
      }
      bef = n;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 21844
/**
  *  Worg
  */
#include <cstdio>
#include <vector>
#include <algorithm>

//FILE *fin = freopen("main.in", "r", stdin); FILE *fout = freopen("main.out", "w", stdout);

int N;
int dp[20][2];

int main() {
    dp[0][1] = 1;
    scanf("%d", &N);
    for(int i = 1; i <= N; i++) {
        int x; scanf("%d", &x);
        if(x % 2 == 1) {  //  1 odd 2 even
            dp[i][1] = dp[i - 1][1];
            dp[i][0] = dp[i - 1][0] * 3 + dp[i - 1][1] * 2;
        } else {          //  2 odd 1 even
            dp[i][1] = dp[i - 1][1] * 2;
            dp[i][0] = dp[i - 1][0] * 3 + dp[i - 1][1] * 1;
        }
    }
    printf("%d\n", dp[N][0]);
	return 0;
}


Measured memory_bytes: 128
using System;

class Program
{
    static void Main()
    {
        int[] height = new int[10];
        for (int i = 0;i < 10; i++)
        {
            height[i] = int.Parse(Console.ReadLine());
        }

        int counter = 0;
        while (true)
        {
            for(int i = counter;i < 10; i++)
            {
                if(height[counter] < height[i])
                {
                    int tmp = height[counter];
                    height[counter] = height[i];
                    height[i] = tmp;
                }
            }
            counter++;
            if (counter == 9)
                break;
        }

        Console.WriteLine(height[0]);
        Console.WriteLine(height[1]);
        Console.WriteLine(height[2]);
    }
}

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

int main()
{
    int n, count = 0;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }

    for (int i = 0; i < n; i++)
    {
        if (p[i] == i + 1)
        {
            swap(p[i], p[i + 1]);
            count++;
        }
    }

    cout << count;
}


Measured memory_bytes: 640
for _ in range(int(input())):
    X, Y = map(int,input().split())
    m = int(input())
    Judge = [[[0] * 2 for i in range(Y+1)] for j in range(X+1)]
    # Judはある点(x, y)において左から通路があるか、また上から通路あるかを判定するための配列
    # 形式は
    # [x座標][y座標][0] = 0：点(x, y)において左からの通路あり
    # [x座標][y座標][0] = 1：点(x, y)において左からの通路なし
    # [x座標][y座標][1] = 0：点(x, y)において上からの通路あり
    # [x座標][y座標][1] = 1：点(x, y)において上からの通路なし
    for i in range(Y+1):
        Judge[0][i][0] = 1
    for j in range(X+1):
        Judge[j][0][1] = 1
    # 端っこの点は上から、または左からの通路が絶対にない
    Tot = [[0] * (Y+1) for i in range(X+1)] #Tot[x座標][y座標]が、点(x, y)まで行ける道の数
    Tot[0][0] = 1

    for i in range(m):
        A = list(map(int, input().split()))
        x1 = A[0]
        y1 = A[1]
        x2 = A[2]
        y2 = A[3]
        if x1 == x2:
            if y2 > y1:
                Judge[x2][y2][1] = 1
                # (x,y)→(x,y+1)にマタタビがあるということだからJudge[x][y+1][0]＝1
            else:
                Judge[x2][y1][1] = 1
        if y1 == y2:
            if x2 > x1:
                Judge[x2][y2][0] = 1
            else:
                Judge[x1][y2][0] = 1
                
    # print(Judge)→デバックで使いました。
        
    for i in range(X+1):
        for j in range(Y+1):
            if Judge[i][j][0] == 0:
                Tot[i][j] += Tot[i-1][j]
            if Judge[i][j][1] == 0:
                Tot[i][j] += Tot[i][j-1]

    if Tot[X][Y] == 0:
        print("Miserable Hokusai!")
    else:
        print(Tot[X][Y])


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	ll f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int n=read(),m=read();
	ll ans=0;
	REP(i,m+1,n){
		ans+=1ll*(i-m)*(n/i);
		ans+=max(n%i-m+1,0);
		if(m==0) ans--;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  double ans = 0.0;
  for (int i = 0; i < N; i++)
  {
    std::cin >> A.at(i);
    ans += 1.0/A.at(i);
  }
  std::cout << std::fixed;
  std::cout << std::setprecision(20) << 1.0/ans << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int n; cin >> n;
    vint s;
    int sum = 0;
    rep(i,n) {
        int x; cin >> x;
        if (x % 10 != 0) s.push_back(x);
        sum += x;
    }
    sort(all(s));
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    } else {
        if (s.size() != 0) {
            cout << sum - s[0] << endl;
            return 0;
        } else {
            cout << 0 << endl;
            return 0;
        }
    }
}

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

typedef long long ll;

int main(void) {
    ll n, m;
    cin >> n >> m;
    ll ans = min(n, m / 2);
    m -= 2 * n;
    if (m > 0)
        ans += m/4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while 1:
    a, b, c = map(int, raw_input().split())
    if not a:
        break
    n = input()

    I = []; J = []; K = []
    res = [2]*(a+b+c)
    for p in xrange(n):
        i, j, k, r = map(int, raw_input().split())
        i -= 1; j -= 1; k -= 1
        if r:
            res[i] = res[j] = res[k] = 1
        else:
            I.append(i); J.append(j); K.append(k)
    for p in xrange(len(I)):
        i, j, k = I[p], J[p], K[p]
        if res[i]==res[j]==res[k]==1:
            continue
        if res[i]==res[j]==1:
            res[k] = 0
        elif res[j]==res[k]==1:
            res[i] = 0
        elif res[k]==res[i]==1:
            res[j] = 0
    for i in xrange(a+b+c):
        print res[i]

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

#define ll long long int
#define pb push_back
#define f(i,x,y) for(i=x;i<y;i++)
#define vll vector<ll>
#define fast    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define mod 1000000007

ll cnt=0;

void dfs(vll adj[], int u, vector<bool> &visited)
{
    visited[u]=true;
    cnt++;
    ll i;
    
    f(i,0,adj[u].size())
    {
        if(visited[adj[u][i]]==false)
            dfs(adj,adj[u][i],visited);
    }
}

int main()
{
    fast;
    ll n,m,i,u,v;
    cin>>n>>m;
    
    vll adj[n];
    
    f(i,0,m)
    {
        cin>>u>>v;
        u--;
        v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    
    ll ans=0;
    vector<bool> visited(n,false);
    
    f(i,0,n)
    {
        cnt=0;
        if(visited[i]==false)
            dfs(adj,i,visited);
        if(cnt>ans)
            ans=cnt;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 23940
n=int(input())
l=list(map(int,input().split()))
g=[1]
for i in range(n):
  #葉となるノード以外のノードの最大個数を作っていく。
  #各深さの限界がgとなる。
  g+=[(g[-1]-l[i])*2]
a=0
t=0
#後ろノードから見ていく。
for i in range(n,-1,-1):
  #-1出力のための限界値
  if l[i]>g[i]:
    print(-1)
    break
  #計算する前のtは、前のノードの個数
  #最大個数より小さくなることはない。
  t=min(l[i]+t,g[i])
  #このtが各深さによるノードの個数となっている。
  a+=t
else:
  print(a)



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

vector<int> ans;
vector<vector<int> > g;

void dfs(int a, int b){
    for(int i = 0; i < g[a].size(); i++){
        int k = g[a][i];
        if(k == b){
            continue;
        }
        ans[k] += ans[a];
        dfs(k, a);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    g.resize(n);

    int a, b;
    
    for(int i = 0; i < n - 1; i++){
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int p, x;
    ans.resize(n,0);
    for(int i = 0; i < q; i++){
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0, -1);
    for(int i = 0; i < n; i++){
        cout << ans[i];
        if(i != n - 1){
            cout << " ";
        }else{
            cout << endl;
        }
    }


}

Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
int main(){
   double a,b,x;
   cin>>a>>b>>x;
   double s= x/a;
   double rad;
   if(s >= a*b/2){
       double h = (a*b - s )*2/a;
       rad = atan2(h,a);
   }
   else{
       double w=2*s/b;
       rad = atan2(b,w);
   }
   double pi= acos(-1);
      double deg = rad*180/pi;
   printf("%10f\n",deg);
}

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

using namespace std;

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

    int s, c;
    vector<int> num(n, 0);
    vector<bool> flag(n, false);
    for (int i = 0; i < m; i++) {
        cin >> s >> c;
        s--;
        
        if ((n != 1 && s == 0 && c == 0) || (flag.at(s) && num.at(s) != c)) {
            cout << -1 << endl;
            return 0;
        }
        else {
            num.at(s) = c;
            flag.at(s) = true;
        }
    }

    if (n != 1 && num.at(0) == 0) {
        num.at(0) = 1;
    }

    for (int i = 0; i < n; i++) {
        cout << num.at(i);
        if (i == n - 1) {
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256