akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

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


using namespace std;



int main(){
	bool prime[1000001];
	rep(i, 1000001){
		prime[i] = true;
	}
	prime[0] = prime[1] = false;
	
	loop(i, 2, 1001){
		if (prime[i]){
			for (int j = i * 2; j < 1000001; j += i){
				prime[j] = false;
			}
		}
	}



	int ord;
	while (cin >> ord){
		int cnt=0;
		rep(i, ord + 1){
			if (prime[i]){
				cnt++;
			}
		}
		cout << cnt << endl;
		cnt = 0;
	}


}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int a[200005];
int s[200005];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i=0 ; i<n ; i++) {
		scanf("%d", a+i);
	}
	if (k > 100) {
		for (int i=0 ; i<n ; i++) {
			printf("%d ", n);
		}
		printf("\n");
		return 0;
	}
	while (k--) {
		memset(s, 0, sizeof s);
		for (int i=0 ; i<n ; i++) {
			s[max(0, i-a[i])]++;
			s[min(200004, i+a[i]+1)]--;
		}
		int pos = 0;
		for (int i=0 ; i<n ; i++) {
			pos += s[i];
			a[i] = pos;
		}
	}
	for (int i=0 ; i<n ; i++) {
		printf("%d ", a[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 5344
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;

  /*
  vector <int> times(N + 1);
  for (int i = 1; i <= N; i++){
    int cnt = 0;
    while (i > 0){
      if (i % 2 == 0){
        i / 2;
        cnt ++;
      }else{
        return 0;
      }
    }
    times[i] = cnt;
  }

  vector <int>::iterator iter = max_element(all(times));
  size_t index = distance(times.begin(), iter);
  cout << index << endl;
  */

  int x = 1;
  while (x <= N) x <<= 1; //2をかける
  x /= 2;
  cout << x << endl;

}


Measured memory_bytes: 3560
#include <stdio.h>
using namespace std;
int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}



Measured memory_bytes: 2620
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
string S, T;
vector<string> answer;

void input(){
    cin >> S >> T;
}

void search(){
    for(int i=0; i<S.size(); i++){
        bool judge=true;
        for(int j=0; j<T.size(); j++){
            //cout << S[i+j] << ' ' << T[j] << endl;
            if (S[i+j]!=T[j] && S[i+j]!='?') {
                judge =false;//SとTを比較して
                //cout <<"break"<< endl;
                break;
            }
        }
        string A=S;
        //cout << A << ' ' << judge << endl;
        if (judge) {
            for(int j=0; j<T.size(); j++){
                A[i+j]=T[j];
            }
            //cout << A << endl;
            for(int j=0; j<A.size(); j++){
                if(A[j]=='?') A[j]='a';
            }
            //cout << A << endl; 
            answer.push_back(A);
        }
    }
    sort(answer.begin(), answer.end());
}

void print(){
    if (answer.size()==0) cout << "UNRESTORABLE" << endl;
    else cout << answer.at(0) << endl;
}

int main(){
    input();
    search();
    print();
    return 0;
}

Measured memory_bytes: 256
def Queue(l, nowtime, sec):
	if len(l) == 1:
		print(l[0][0], nowtime + l[0][1])
		return [], 0

	else:
		tl = l.pop(0)

		if tl[1] <= sec:
			nowtime += tl[1]
			print(tl[0], nowtime)
			return l, nowtime

		else:
			nowtime += sec
			l.append([tl[0], tl[1] - sec])
			return l, nowtime



if __name__ == '__main__':
	N, sec = input().split()
	N, sec = int(N), int(sec)
	lists = list()

	for i in range(N):
		obj, times = input().split()
		lists.append([obj, int(times)])

	now = 0
	while lists:
		lists, now = Queue(lists, now, sec)


Measured memory_bytes: 13016
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int ti = clock();
    int D; cin >> D;
    vector<ll> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(i, D)rep(j, 26) cin >> s[i][j];
    vector<ll> t(D);
    rep(i, D) t[i] = 26-i%26;
    ll ans = 0;
    vector<ll> last(26);
    vector<ll> t_ans(ALL(t));
    for (int d = 1; d <= D; d++) {
        for (int i = 1; i <= 26; i++) {
            if (t[d-1] == i) {
                ans += s[d-1][i-1];
                last[i-1] = d;
            }
            else {
                ans -= c[i-1]*(d-last[i-1]);
            }
        }
    }
    ll tmp;
    while ((double)(clock() - ti)/CLOCKS_PER_SEC <= 1.98) {
        t[rand()%D] = rand()%26 + 1;
        last.clear();
        last.resize(26);
        tmp = 0;
        for (int d = 1; d <= D; d++) {
            for (int i = 1; i <= 26; i++) {
                if (t[d-1] == i) {
                    tmp += s[d-1][i-1];
                    last[i-1] = d;
                }
                else {
                    tmp -= c[i-1]*(d-last[i-1]);
                }
            }
        }
        if (tmp > ans) {
            swap(ans, tmp);
            rep(i, D) t_ans[i] = t[i];
        }
    }
    rep(i, D) cout << t_ans[i] << endl;
  	//cout << ans << endl;
}


Measured memory_bytes: 3720
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val PList = readInputLine().split(" ").map { it.toInt() }
    var min = Int.MAX_VALUE
    var ans = 0

    for (P in PList) {
        if (P <= min) {
            ans++
            min = P
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 82916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i,j,c,n,a[1010][1010];
  scanf("%d %d\n",&c,&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      char s;
      scanf("%c",&s);
      if(s=='0'){
        a[i][j]=0;
      }
      else{
        a[i][j]=1;
      }
    }
    scanf("\n");
  }
  int sum=0,ans=0;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(a[i][j]!=a[n-i-1][j]){
        sum++;
      }
      if(a[i][j]!=a[i][n-j-1]){
        sum++;
      }
    }
  }
  sum=sum/2;
  if(sum==0){
    ans++;
  }
  int d,r,b;
  for(i=0;i<c-1;i++){
    cin >> d;
    for(j=0;j<d;j++){
      scanf("%d %d\n",&r,&b);
      r--,b--;
      if(a[r][b]==a[r][n-b-1]){
        sum++;
      }
      else{
        sum--;
      }
      if(a[r][b]==a[n-r-1][b]){
        sum++;
      }
      else{
        sum--;
      }
      if(a[r][b]==0){
        a[r][b]=1;
      }
      else{
        a[r][b]=0;
      }
    }
    if(sum==0){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7164
// g++ -std=gnu++1y -O2 xxx.cpp

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

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

    ll d = c-a-b;
    if (d > 0 && 4*a*b < d*d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int a,b,c,d;
int main()
{
   
    cin>>a>>b>>c>>d;
    if(a+b==c+d)
        cout<<"Balanced";
    else if(a+b>c+d)
        cout<<"Left";
    else
        cout<<"Right";
}


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

int n;
int l[2005];
long long ans;

int main(){

    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>l[i];

    sort(l+1,l+n+1);

    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++){

            int s=1,d=n,m;

            while(d-s>1){

                m=(s+d)/2;

                if(l[m]<=l[i]+l[j]-1) s=m;
                else d=m;

            }

            int k;

            if(l[d]<=l[i]+l[j]-1) k=d;
            else k=s;

            if(j+1>k) continue;

            ans+=k-j;

        }

    cout<<ans;

}


Measured memory_bytes: 256
from itertools import *
n=range(55555);a=list(n);a[1]=0
for i in range(2,233):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))

cnt = 0
ans = []
N = int(input())
for x in p:
    if x%5 == 2:
        ans += [x]
        cnt += 1
        if cnt == N: break
print(*ans)

Measured memory_bytes: 5656
#include<stdio.h>
int main(void){
	int X;
	scanf("%d",&X);
	if(X==7){
		printf("YES");
	}else if(X==5){
		printf("YES");
	}else if(X==3){
		printf("YES");
	}else{
		printf("NO");
	}
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int S, m, s;

    scanf("%d", &S);

    s = S % 60;
    S = S / 60;
    m = S % 60;
    S = S / 60;

    printf("%d:%d:%d\n", S, m, s);

    return 0;
}



Measured memory_bytes: 2060
/*input
1 100000
1000000000 100000
*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb                push_back
#define pp                pop_back
#define nl                cout << "\n"
#define MIN(con)          (*min_element(ALL(con)))
#define MAX(con)          (*max_element(ALL(con)))
#define NX(cont)          next_permutation(ALL(cont))
#define PX(cont)          prev_permutation(ALL(cont))
#define prec(n)           cout << fixed << setprecision(n)
#define PI                3.14159265358979323846264338327951
#define all(c)            c.begin(),c.end()
#define rep(i,a,b)        for(ll i=a;i<b;i++)
#define sp                cout << " "
#define mod               1000000007    //9
#define ifalse            ios_base::sync_with_stdio(false),cin.tie(NULL)

using ll = long long;
using ld = long double;
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > T LCM(T a, T b)            { return (a * b) / GCD(a, b); }
template < typename T > string toString(T a)       { return to_string(a); }  // Convert int to string
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}  // Convert string to int

ll add(ll x, ll y) { x += y; if(x >= mod) x -= mod; return x; }
ll sub(ll x, ll y) { x -= y; if(x < 0) x += mod; return x; }
ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod; }

ll powr(ll a, ll b) {
    ll x = 1LL;
    while(b) {
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}

ll inv(ll a) { return powr(a, mod - 2); }
const int inv2 = (mod + 1) >> 1;
const ll INF =  1e18;
const int inf = 1e9;

bool check(ll n)
{
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;
    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}

/*********************************************START**************************************************************/

int main()
{
    ifalse;
    ll n, m;
    cin >> n >> m;
    vector < pair < ll, ll > > v;
    for(int i = 0; i < n; i ++) {
        ll x, y;
        cin >> x >> y;
        v.pb({x, y});
    }   

    sort(all(v));

    ll ans = 0;
    for(auto x: v) {
        if(m > 0) {
            ll d = min(m, x.second);
            m -= d;
            ans += (x.first * d);
        }
        else {
            break;
        }
    }
    cout << ans;
    return 0;
}

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

int a, b, t = 0, u = 0;
int Max = 0;
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return true;
}
void dfs(int p) {
	if (a == p) {
		int c = t*pow(10, a + 1) + b*pow(10, a) + u;
		if (is_prime(c))Max = max(Max, c);
		return;
	}
	rep(i, 10) {
		if (i == 0 && p == 0)continue;
		t = t * 10 + i;
		u += i*pow(10, p);
		dfs(p + 1);
		t /= 10; u -= i*pow(10, p);
	}
}
int main() {
	scanf("%d%d", &a, &b);
	if (b < 0) {
		if (a == 1)puts("11");
		else {
			rep(i, 2*a)printf("9");
			printf("\n");
		}
		return 0;
	}
	dfs(0);
	printf("%d\n", Max);
}

Measured memory_bytes: 3348
def main():
    N, M = map(int, input().split())

    left = 1
    right = N

    for _ in range(M):
        l, r = map(int, input().split())

        if left < l:
            left = l
        if right > r:
            right = r

    ans = right - left

    print(ans + 1 if ans >= 0 else 0)


main()


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

namespace ABC117_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var L = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var longest = L.Max();
            var canDraw = longest < L.Sum() - longest;
            Console.WriteLine(canDraw ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n,s[1000];

  while(cin >> n){
    int sum;
    if(!(n)) break;
    sum = 0;
    for(int i = 0;i<n;i++) cin >> s[i],sum += s[i];
    sort(s,s+n);
    printf("%d\n",(sum - s[0] - s[n-1]) / (n-2));
  }

  return 0;
}

Measured memory_bytes: 0
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back

#define int int64_t

signed main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    auto apply = [](pair<int, int> dim, int val) -> pair<int, int> {
        int lst = dim.second - dim.second % val;

        if (lst < dim.first)
            return {-1, -1};

        int fst = dim.first;
        if (dim.first % val)
            fst += val - (dim.first % val);

        return {fst, lst + val - 1};
    };

    vector<int> lst(input<int>());
    input_seq(ALL(lst));
    pair<int, int> res = {2, 2};

    for (int i = SZ(lst) - 1; i >= 0 and res.first != -1; --i)
        res = apply(res, lst[i]);

    if (res.first == -1)
        cout << "-1\n";
    else
        cout << res.first << " " << res.second << "\n";
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  long n;
  cin >> n;
  
  vector<int> a(n+1);
  vector<bool> history(100001, false);
  
  for (long i=1; i<=n; i++) {
    cin >> a.at(i);
  }
  
  long count=1;
  long j=a.at(1);
  history.at(1)=true;
  for (long i=0; i<=a.size(); i++) {
    if (history.at(j)==true) {
      cout << -1 << endl;
      return 0;
    } else if (j==2) {
    //   count++;
      break;
    }
    history.at(j)=true;
    count++;
    j=a.at(j);
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>

constexpr long long MOD=1000000007;
int N,M;
int main(){
  std::cin>>N>>M;
  
  if(std::abs(N-M)<=1){
    long long ans=1;
    for(int i=2;i<=N;++i)
      ans=ans*i%MOD;
    for(int i=2;i<=M;++i)
      ans=ans*i%MOD;
    if(N==M)
      ans=ans*2%MOD;
    
    std::cout<<ans<<std::endl;
  }
  else
    std::cout<<"0"<<std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 2000000000
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int arr[3][3],a[3],b[3]={-1,-1,-1};
	bool yes=0;
	F(i,0,3) F(j,0,3) getI(arr[i][j]);
	for(a[0]=0;a[0]<=100;a[0]++) for(a[1]=0;a[1]<=100;a[1]++) for(a[2]=0;a[2]<=100;a[2]++){	
		b[0]=-1,b[1]=-1,b[2]=-1;
		F(i,0,3) F(j,0,3){
			if(b[j]==-1) b[j]=arr[i][j]-a[i];
			if(a[i]+b[j]!=arr[i][j]){
				goto bye;
			}
			if(a[i]+b[j]==arr[i][j]&&i==2&&j==2){
				yes=1;
			}
		}
		F(i,0,3) F(j,0,3) if(a[i]+b[j]!=arr[i][j]||b[i]==-1){
			yes=0;
			goto bye;
		} 
		bye:
			if(yes){
				puts("Yes");
				return 0; 
			}
	}
	puts("No");
}


Measured memory_bytes: 256
n = int(input())
temparr = input()
temparr = temparr.split()
dicts = {}
total = 0 
for i in temparr:
    i = int(i)
    if i not in dicts:
        dicts[i] = 1 
    else:
        dicts[i] += 1 
    total += i 
times = int(input())
for i in range(times):
    temparr = input()
    temparr = temparr.split()
    find = int(temparr[0])
    replace = int(temparr[1])
    if find not in dicts:
        print(total)
        continue 
    if find in dicts:
        howmany = dicts[find]
        total -= howmany * find 
        total += howmany * replace 
        if replace not in dicts:
            dicts[replace] = howmany 
        else:
             dicts[replace] += howmany 
        del dicts[find]
        
        print(total)
    
    
    
    

Measured memory_bytes: 84936
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<double,pair<string,int> > mypair;
string re(string a){
	for(int i=0;i<a.size();i++){
		a[i]='a'+('z'-a[i]);
	}
	return a;
	}
	string eq(string a){
		string b;
		for(int i=0;i<20;i++)
         b.push_back('A');
		for(int i=0;i<a.size();i++)
     b[i]=a[i];
		return b;
	}
int main(void){
	int n;
	while(1){
cin>> n;
if(n==0)break;
vector<string> l(n);
vector<int> p(n),a(n),b(n),c(n),d(n),e(n),f(n),s(n),m(n);
for(int i=0;i<n;i++)
cin>>l[i]>>p[i]>>a[i]>>b[i]>>c[i]>>d[i]>>e[i]>>f[i]>>s[i]>>m[i];
vector<mypair> q(n);
for(int i=0;i<n;i++){
	q[i].first=(double)(m[i]*f[i]*s[i]-p[i])/(a[i]+b[i]+c[i]+m[i]*(d[i]+e[i]));
	q[i].second.first=re(eq(l[i]));
	q[i].second.second=i;
}

sort(q.begin(),q.end(),greater<mypair>());

for(int i=0;i<n;i++){
cout<<l[q[i].second.second] <<endl;
}
cout<<'#'<<endl;
	}
	return 0;
}

Measured memory_bytes: 3160
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        hv: [u64; n],
    }

    let mut hv = hv;
    let mut answer = 0;

    loop {
        let mut new_water = true;
        let mut all_zero = true;

        for h in &mut hv {
            if *h > 0 {
                all_zero = false;
                if new_water {
                    answer += 1;
                }
                *h -= 1;
                new_water = false;
            } else {
                new_water = true;
            }
        }

        if all_zero {
            break;
        }
    }

    println!("{}", answer);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long int
signed main() 
{
int a,b,c,k;
cin>>a>>b>>c>>k;

if(a>=k)
{
          cout<<k<<"\n";
}
else
if((a+b)>=k)
{
          cout<<a<<"\n";
}
else
{
          cout<<(a-(k-(a+b)))<<"\n";
}
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std; 
typedef long long int ll;
const long long int m=pow(10,9)+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,max=-1,sum=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int f[100005]={0};
    for(int i=0;i<n;i++)
    {
        f[a[i]]++;
    }
    for(int i=0;i<100005-2;i++)
    {
        sum=f[i]+f[i+1]+f[i+2];
        if(sum>max)
            max=sum;
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 4828
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <iomanip>
using ll = long long;
using namespace std;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r) { return l.second < r.second; }
bool greaterPair(const ipair& l, const ipair& r) { return l.second > r.second; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define irep(i, n) for (int i = 0; i <= (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rirep(i, n) for (int i = n; i >= 0; --i)
int factorical(int n) {
	int sum = 1;
	for (int i = 1; i <= n; ++i)
	{
		sum *= i;
	}
	return sum;
}

vector<int> divisors(int n) {
	vector<int> res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}
vector<ll> divisors_ll(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}


void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}

bool pal(string s) {
	int n = s.length() / 2;
			rep(i, n) {
			if (s[i] != s[s.length() - 1 - i]) return false;
		}
			return true;
}

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i, n) {
		cin >> s[i];
	};
	std::sort(s.begin(), s.end());
	s.erase(std::unique(s.begin(), s.end()), s.end());
	
	cout << s.size() << endl;

	return 0;
}




Measured memory_bytes: 9544
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 500005;

int main(){
  ll N,P; cin >> N >> P ;
  int odd = 0;
  rep(i,N){
    ll a; cin >> a ;
    if(a%2==1LL) odd++;
  }
  if(P==1LL && odd==0) cout << 0 << endl;
  else if(P==0LL && odd==0) cout << (1LL << N) << endl;
  else cout << (1LL << (N-1)) << endl;
  return 0;
}

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


int main(){
	int n,map[4][3][10];
	cin >> n;
	for(int k=0;k<4;k++){
		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				map[k][i][j]=0;
			}
		}
	}
	while(n--){
		int b,f,r,v;
		cin >> b >> f >> r >> v;
		map[b-1][f-1][r-1]+=v;
	}
	for(int k=0;k<4;k++){
		for(int i=0;i<3;i++){
			for(int j=0;j<10;j++){
				cout << " " << map[k][i][j];
			}
			cout << endl;
		}
		if(k!=3) cout << "####################" << endl;
	}
	return 0;
}



Measured memory_bytes: 3080
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while(true) {
            int[] kukan = new int[10];
            String line;
            try{
                line = sc.nextLine();
            }catch(Exception e) {
                break;
            }
            int all = 0;
            String[] linesp = line.split(",");
            for(int i = 0; i < 10; i++) {
                kukan[i] = Integer.parseInt(linesp[i]);
                all += Integer.parseInt(linesp[i]);
                
            }
            int a = Integer.parseInt(linesp[10]);
            int b = Integer.parseInt(linesp[11]);
            //すれ違うポイント
            double point = (double)(1000 * a * all / (a+b));
            point /= 1000;

            for(int i = 0; i < 10; i++) {
                point -= kukan[i];
                if(point <= 0) {
                    System.out.println(i+1);   
                    break;
                }
            }
            
        }
    }    
}



Measured memory_bytes: 26064
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=true;
// const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    string s;
    cin >> s;
    int x,y;
    cin >> x >> y;
    int cntx=0,cnty=0,cnt=0;
    vector<int> dx,dy;
    int first_t=0;
    rep(i,s.size()){
        if(s[i]=='F'){
            if(cnt&1)cnty++;
            else cntx++;
            if(i==s.size()-1){
                if(cnt==0){
                    x-=cntx;
                }
                else if (cnt&1){
                    dy.push_back(cnty);
                }else{
                    dx.push_back(cntx);
                }
            }
        }
        if(s[i]=='T'){
            if(cnt==0){
                x -=cntx;
                cntx=0;
            }else if(cnt%2==0){
                dx.push_back(cntx);
                cntx=0;
            }else{
                dy.push_back(cnty);
                cnty=0;
            }
            cnt++;
        }
    }
    // DEBUG{
    //     cout << dx[0] << endl;
    //     cout << dy[0] << endl;
    // }
    sort(dx.begin(),dx.end(),greater<int>()); 
    sort(dy.begin(),dy.end(),greater<int>()); 
    int nowx=x,nowy=y;
    rep(i,dx.size()){
        if(nowx>=0)nowx-=dx[i];
        else nowx+=dx[i];
    }
    rep(i,dy.size()){
        if(nowy>=0)nowy-=dy[i];
        else nowy+=dy[i];
    }
    if(nowx==0&&nowy==0)cout << "Yes" << endl;
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 11e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

    int N;
    cin >> N;
  
    cout << (N+1)/2*1.0/N << "\n";
}

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

    int high;
    cin >>high;

    int count=1;

    for (int i=0;i<n-1;i++) {
        cin >>h;
        if(h>=high){
            count++;
            high=h;
        }
    }

    cout<<count<<endl;
}


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

using namespace std;

int main()
{
  int m;
  vector<unsigned short> count;
  for(int i=0;i<6;i++)
    count.push_back(i);
  for(int i=6;i<10000001;i++)
    {
      if((i%2==0&&count[i/2]-count[(i/2)-1]!=0) || (i%3==0&&count[i/3]-count[(i/3)-1]!=0) || (i%5==0&&count[i/5]-count[(i/5)-1]!=0))
	  count.push_back(count[i-1]+1);
      else
	count.push_back(count[i-1]);
    }
  for(;cin>>m,m;)
    {
      int n;
      cin>>n;
      cout<<count[n]-count[m-1]<<endl;
    }
}

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


#define ll long long
#define ld long double
#define ull unsigned long long
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long ,long long>
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007


 
//     long long power(long long x, long long y, long long p) 
// { 
//     long long res = 1;      
  
//     x = x % p;  
  
//     while (y > 0) 
//     { 
      
//         if (y & 1) 
//             res = (res*x) % p; 

//         y = y>>1; 
//         x = (x*x) % p; 
//     } 
//     return res; 
// } 
  

// long long modInverse(long long n, long long p) 
// { 
//     return power(n, p-2, p); 
// }  

// long long ncrp(long long n, long long r, long long p) 
// { 
   
//    if (r==0) 
//       return 1; 
  
    
//     long long fac[n+1]; 
//     fac[0] = 1; 
//     // for (long long i=1 ; i<=n; i++) 
//     //     fac[i] = fac[i-1]*i%p; 
  
//     return (fac[n]* modInverse(fac[r], p) % p * 
//             modInverse(fac[n-r], p) % p) % p; 
// }




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


   if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    ll n;
    
    cin>>n;
    vector<double> v[n],p;
    

    ll i;

    for(i=0;i<n;i++)
    {
        double x;
        cin>>x;
        p.pb(x);
    }

    ll j;
    v[0].pb(1-p[0]);
    v[0].pb(p[0]);


    for(i=1;i<n;i++)
    {
        for(j=0;j<=i+1;j++)
        {
            if(j==0)
            {
               v[i].pb((double)v[i-1][j]*(1-p[i]));    
            }
            else if(j==i+1)
            {
               v[i].pb((double)v[i-1][j-1]*(p[i]));
            }
            else{
               v[i].pb(((double)v[i-1][j-1]*p[i])+((double)v[i-1][j]*(1-p[i])));
            }
        }
    }
    ld res=0;

   
       for(j=0;j<v[n-1].size();j++)
       {
           if(j>i-j)
           {
            res+=v[n-1][j];
           }
       }
        // cout<<endl;
    
    cout<<setprecision(11)<<res<<endl;

    






 



  

    return 0;
}

Measured memory_bytes: 43904
#include<stdio.h>
int main()
{
	int a, b, prod;
	int judge = 1; // 1 = odd, 0 = even
	scanf("%d %d",&a,&b);
	if (a % 2 == 0) judge = 0;
	else if (b % 2 == 0) judge = 0; else ;
	if (judge == 0) printf("Even");
	else printf("Odd");
	// ;
	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

      int N = in.nextInt();
      int d[] = new int[N+1];

      int moti = 0;

          for(int cnt = 0; cnt < N; cnt++) {
              d[cnt] = in.nextInt();
          }

          Arrays.sort(d);

          for(int cnt = 0; cnt < N; cnt++) {

              if(d[cnt] < d[cnt+1]) {
                  moti++;
              }
          }



      System.out.println(moti);
  }


}


Measured memory_bytes: 21844
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn min (a: &i64, b: &i64)-> i64{
    if *a <= 0i64 {*b}
    else if *b <= 0i64  {*a}
    else if *a < *b {*a}
    else {*b}
}

fn abs (a: &i64, b: &i64) -> i64{
    if *a - *b <= 0 {*b - *a} else {*a - *b}
}

fn main(){
    input!{
        a: [u64; 2]
    }
    let mut result: u64 = 1;
    while a[0] * (2i64.pow(result as u32) as u64) <= a[1] {
        result += 1;
    }
    print!("{}", result);
}


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


int main()
{
    int n,w;
    cin>>n>>w;
    
    
    ll arr[n+1][w+1];
    
    for(int i=0;i<n+1;i++){
        for(int j=0;j<w+1;j++)
        arr[i][j] =0;
    }
    

    
    for(int i=1;i<=n;i++){
        
        int value,cst;
        cin>>cst>>value;
        
        for(int j = 1;j<=w;j++){
            if(j<cst)
            arr[i][j] = arr[i-1][j];
            else{
                arr[i][j] = max(value + arr[i-1][j-cst],arr[i-1][j]);
            }
        } 
    }
    cout<<arr[n][w];
    
       
}

Measured memory_bytes: 79104
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 999999
#define N 3000003
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll a[N] , c[N] , sum , cur;
int main(){
fcin;	
	int n;
	cin>>n;
	for(int i = 0 ; i <  n; i++) {cin>>a[i]; c[a[i]]++; }
	for(int i = 1 ; i <= n ; i++){
		sum += ( ( c[i] *  ( c[i]-1 ) )  / 2);
	}
	for(int i = 0 ; i < n ; i++){
		cur = sum;
		cur  -=  ( (c[a[i]] * (c[a[i]] - 1))/2);
		cur += (( (c[a[i]] - 1) * ( c[a[i]] - 2 ) ) / 2);
		cout<<cur<<"\n";
	}
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define MAX 1000003

ll mod = (ll)998244353;
ll n,q;
vector<vll> que;
vll mini;

void solve(){
    cin >> n >> q; 
    que.assign(2,vll(n - 1));
    set<ll> s[2];
    s[0].insert(n - 1);
    s[1].insert(n - 1);
    mini.assign(2,n - 1);
    ll ans=0;
    rep(i,0,q){
        ll a,b,tot;
        cin >> a >> b;
        a--;
        b--;
        auto it = s[a].lower_bound(b);
        if(it == s[a].begin()){
            tot = mini[a] - 1;
            // cout << mini[a] << " YES "; 
        }
        else{
            // cout <<"YES ";
            ll last = *prev(it);
            tot = que[a][last];
        }
        // cout << a << " " << b  << " " << " " << tot << br;
        que[a][b] = tot;
        ans += tot;
        mini[!a] = min(b,mini[!a]);
        s[a].insert(b);
    }
    cout << ((n - 2)*(n - 2)) - ans;

}
	

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}	

Measured memory_bytes: 15668
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	long long N, A, B, ans;
	scanf("%lld %lld %lld", &N, &A, &B);
	ans = N / (A + B) * A;
	N %= A + B;
	ans += min(A, N);
	printf("%lld", ans);
	return 0;
}

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

string uso(){
  string s = "-1 -1 -1";
  return(s);
}

int main(){
  int N, Y;
  cin >> N >> Y;
  int x,y,z;
  bool chk = false;
  vector<int> rel(3);
  // 4y+9z = Y/1000 - N
  for(int y = 0; y<N + 1; y++){
    int pz = (Y/1000 - N - 4*y);
    // if( pz % 9 == 0 && N - y- (pz/9) <= N &&N - y- (pz/9) >= 0){
  if( pz % 9 == 0 && N - y -pz/9 >= 0 && y>=0 && pz/9>=0 && Y%1000==0){
      z = pz/9;
      rel.at(1) = y;
      rel.at(0) = z;
      rel.at(2) = N - y - z;
      chk = true;
    }
  }

  if(chk ){
    for(int i =0; i<rel.size() -1;i++){
      cout << rel.at(i) << " ";
    }
    cout << rel.at(rel.size()-1) << endl;
  }
  else{
    string s = uso();
    cout << s <<endl;
  }

}


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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    double R; cin >> R;
    cout << std::setprecision(3) << 2*M_PI*R << endl;
    return 0;
}


Measured memory_bytes: 3800
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto kn = readln.split.to!(int[]);
    auto K = kn[0];
    auto N = kn[1];
    auto as = readln.split.to!(int[]);
    int max_a = K - as[$-1] + as[0];
    foreach (i; 0..N-1) max_a = max(max_a, as[i+1] - as[i]);
    writeln(K - max_a);
}

Measured memory_bytes: 11340
#include <stdio.h>

int main(void) {
    int n, q, i, j, count = 0, flag = 0;
    scanf("%d", &n);
    int S[n];
    for(i = 0; i < n; i ++) scanf("%d", &S[i]);
    scanf("%d", &q);
    int T[q];
    for(i = 0; i < q; i ++) scanf("%d", &T[i]);

    for (i = 0; i < q; i ++) {
      flag = 0;
      for(j = 0; j < n; j ++) {
        if(S[j] == T[i] && flag == 0) {
          flag ++;
          count ++;
        }
        else if(S[j] == T[i] && flag != 0) continue;
      }
    }

    printf("%d\n", count);
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> t(n);
  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> t[i];
    sum+=t[i];
  }

  int m;
  cin >> m;
  for (int i = 0; i < m; i++)
  {
    int p,x;
    cin >> p >> x;
    p--;
    cout << sum-t[p]+x << endl;
  }  
}

Measured memory_bytes: 256
N = int(input())
BA = []
for _ in range(N):
    a, b = map(int, input().split())
    BA.append((b, a))
BA.sort()
time = 0
is_timeover = False
for i in range(N):
    b, a = BA[i]
    time += a
    if time > b:
        is_timeover = True
        break

if is_timeover:
    print("No")
else:
    print("Yes")

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

using namespace std;

typedef long long int ll;

const int N = (int) 1e5 + 10;

int n, mod;
int par[N];
int memo[N];
vector<int> vs[N];
vector<int> down[N];
vector<int> left_mult[N], right_mult[N];
vector<int> memo2[N];

int mult(ll a, ll b) {
    return (a * b) % mod;
}

void dfs(int node, int p) {
    par[node] = p;
    if(p != -1) down[p].push_back(node);
    for(int v : vs[node]) if(v != p) dfs(v, node);
    left_mult[node].resize(down[node].size());
    right_mult[node].resize(down[node].size());
}

int dp(int node) {
    int &ans = memo[node];
    if(ans != -1) return ans;
    ans = 1;
    for(int v : down[node]) ans = mult(ans, 1 + dp(v));
    for(int i = 0, j = down[node].size() - 1; i < down[node].size(); ++i, --j) {
        {
            int v = down[node][i];
            int v_ans = (1 + dp(v)) % mod;
            left_mult[node][i] = v_ans;
            if(i > 0) left_mult[node][i] = mult(left_mult[node][i - 1], left_mult[node][i]);
        }
        {
            int v = down[node][j];
            int v_ans = (1 + dp(v)) % mod;
            right_mult[node][j] = v_ans;
            if(j + 1 < down[node].size()) right_mult[node][j] = mult(right_mult[node][j + 1], right_mult[node][j]);
        }
    }
    return ans;
}

int get_index(int node, int target) {
    if(target == -1) return down[node].size();
    int lo = 0, hi = down[node].size() - 1;
    while(lo <= hi) {
        int m = lo + hi >> 1;
        if(down[node][m] >= target) hi = m - 1;
        else lo = m + 1;
    }
    return lo;
}

int get_below(int node, int ind) {
    if(ind == down[node].size()) {
        if(down[node].empty()) return 1;
        return right_mult[node][0];
    }
    int l = ind == 0 ? 1 : left_mult[node][ind - 1];
    int r = ind + 1 == down[node].size() ? 1 : right_mult[node][ind + 1];
    return mult(l, r);
}

int go(int node, int prev) {
    if(node == -1) return 0;
    int ind = get_index(node, prev);
    int &ans = memo2[node][ind];
    if(ans != -1) return ans;
    ans = 1;
    int below = get_below(node, ind);
    ans = mult(ans, below);
    ans = mult(ans, 1 + go(par[node], node));
    return ans;
}

void solve() {
    cin >> n >> mod;
    for(int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        vs[u].push_back(v);
        vs[v].push_back(u);
    }
    for(int i = 0; i < n; ++i) {
        sort(vs[i].begin(), vs[i].end());
        memo2[i].resize(vs[i].size() + 1, -1);
    }
    dfs(0, -1);
    memset(memo, -1, sizeof(memo));
    dp(0);
    for(int i = 0; i < n; ++i) {
        cout << go(i, -1) << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    solve();
    return 0;
}

Measured memory_bytes: 34816
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = INF; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	cin >> N;
	vl C(N - 1), S(N - 1), F(N - 1);
	for (i = 0; i < N-1; i++) cin >> C[i] >> S[i] >> F[i];
	for (i = 0; i < N; i++) {
		ans = 0;
		for (j = i; j < N-1; j++) {
			ans = max(ans, S[j]);
			ans += (F[j] - ans % F[j])%F[j];
			ans += C[j];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
/*last edited at 27.8.2015 by charis
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
*/

#include<iostream>
using namespace std;

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	int c=0;
	for(int i=0; i<N; i++){
		for(int j=N-1; j>=i; j--){
			if(A[j]<A[j-1]) {
				int t=A[j-1]; A[j-1]=A[j]; A[j]=t; c++;
			}
		}
	}
	
	for(int i=0; i<N-1; i++){
		cout << A[i] << " ";
	}	
	cout << A[N-1] << endl;
	cout << c << endl;
	
	return 0;
}

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

int main(void){
	int n;
	scanf("%d",&n);
	set<long long> ss;
	long long cnt;
	for(int i=0;i<n;i++){
		cin>>cnt;
		if(ss.find(cnt)!=ss.end()) ss.erase(cnt);
		else ss.insert(cnt);
	}
	printf("%d",ss.size());
	return 0;
}

Measured memory_bytes: 4864
import Control.Arrow
import Control.Monad
import Data.List
main = readLn >>= main'
    where
        main' n = getLine >>= print . solve n . map length . group . sort . map (read :: String -> Int) . words

solve :: Int -> [Int] -> Int
solve n xs
    | odd m = s - 1
    | otherwise = s
    where
        (s, m) = foldl' (\(acc, d) x -> (acc + 1, d + x - 1)) (0, 0) xs


Measured memory_bytes: 39292
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
int n;
long long D[6020][2010], res, Mod;
int main() {
	int i, j, k, s;
	scanf("%d%lld", &n, &Mod);
	D[0][0] = 1;
	for (i = 0; i <= 3 * n; i++) {
		for (j = 0; j <= n; j++) {
			D[i][j] %= Mod;
			D[i + 1][j] += D[i][j];
			D[i + 2][j + 1] += D[i][j] * (i+1);
			D[i + 3][j + 1] += D[i][j] * (i+1) * (i + 2);
		}
	}
	for (i = 0; i <= n; i++)res = (res + D[3*n][i]) % Mod;
	printf("%lld\n", res);
}

Measured memory_bytes: 94464
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <string.h>
using namespace std;

int dfs(int i, vector<bool> &visited, std::map<int, std::set<int> > &friends){
  int result = 1;
  for(std::set<int>::iterator it = friends[i].begin(); it != friends[i].end(); ++it){
    if(!visited[*it]){
      visited[*it] = true;
      result += dfs(*it, visited, friends);
    }
  }
  return result;
}

int main()
{
  int n = 0;
  int m = 0;
  int a = 0;
  int b = 0;
  scanf("%d %d", &n, &m);
  vector<bool> visited(n, false);
  std::map<int, std::set<int> > friends;
  for(int i=0; i<m; i++){
    scanf("%d %d", &a, &b);
    friends[a-1].insert(b-1);
    friends[b-1].insert(a-1);
  }
  int max_size = 1;
  for(int i=0; i<n; i++){
    if(!visited[i]){
      visited[i] = true;
      int size = dfs(i, visited, friends);
      max_size = std::max(size, max_size);
//      printf("%d\n", i);
    }
  }
  printf("%d\n", max_size);
  
//  for(int i=0; i<n; i++){
//    for(int j=0; j<k+1; j++){
//      printf("%lld ", arr[i][j]);
//    }
//    printf("\n");
//  }
//  printf("%lld\n", (arr[n-1][k] - arr[n-1][k-1] + base) % base);
}


Measured memory_bytes: 63124