akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int> P(N),Q(N);
  rep(i,N) cin>>P[i];
  rep(i,N) cin>>Q[i];

  int p=0,q=0;
  vector<int> v;
  rep(i,N) v.push_back(i+1);
  int num=0;
  do{
    bool isp=true,isq=true;
    rep(i,N){
      if(v[i]!=P[i]) isp=false;
      if(v[i]!=Q[i]) isq=false;
    }
    if(isp) p=num;
    if(isq) q=num;
    num++;
  }while(next_permutation(v.begin(),v.end()));

  cout<<abs(p-q)<<endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = tuple(map(int, input().split()))
c = 0
s = 0
r = 0
for l in range(n):
    while r < n and A[r] ^ s == A[r] + s:
        s = A[r] + s
        r += 1

    c += r- l
    if l == r:
        r += 1
    else:
        s -= A[l]

print(c)


Measured memory_bytes: 24680
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;
 
//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  char c;
  cin >> c;
  if ('a' <= c && c <= 'z') cout << "a" << endl;
  else cout << "A" << endl;
  return 0;
}

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

bool mygreater(int i, int j){
	return i>=j;
}
int main () {
	int N;
	vector<int> ans;
	cin>>N;
	long long A[N];
	for(int i=0; i< N; i++){
		cin>>A[i];
		auto it = lower_bound(ans.begin(), ans.end(), A[i], mygreater);
		if(it != ans.end()){
			*it = A[i];
		}
		else{
			ans.push_back(A[i]);
		}
	}
	cout<<ans.size()<<"\n";

	return 0;
}

Measured memory_bytes: 1660
K, N = map(int,input().split())
A = list(map(int,input().split()))

distance = []
for i in range(N):
  if i != N-1:
    distance.append(A[i+1]-A[i])
  else:
    distance.append(A[0]+K-A[-1])
else:
  print(K-max(distance))

Measured memory_bytes: 25840
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]



n = I()
ans = 0
for i in range(1,n+1):
    for j in range(i,n+1,i):
        ans += j
print(ans)

Measured memory_bytes: 73372
n = int(input())
x = []
y = []
for i in range(n):
    xx, yy = map(int, input().split())
    x.append(xx)
    y.append(yy)
import sys
sys.setrecursionlimit(2000)
import math

def dfs(v, r, visited):
    visited[v] = 1
    global ans
    for i in range(n):
        if visited[i] == 0:
            r += math.sqrt((x[i] - x[v]) ** 2 + (y[i] - y[v]) ** 2)
            dfs(i, r, visited)
            visited[i] = 0
            r -= math.sqrt((x[i] - x[v]) ** 2 + (y[i] - y[v]) ** 2)
        elif visited == [1] * n:
            ans += r
            return
ans = 0
for i in range(n):
    visited = [0 for _ in range(n)]  
    dfs(i, 0, visited)
div = 1
for i in range(1, n+1):
    div *= i
print(ans / div )




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

int main() {
	int n;
	cin>>n;
	int res=2*n,count=0;
	rep(i,n){
		int p;
		cin>>p;
		if(res>=p)count++;
		res=min(res,p);
	}
	
	cout<<count<<endl;
}


Measured memory_bytes: 256
//2009
#include<iostream>
using namespace std;
int main(void){
	int sum=0,a[10]={0},sum2=0;
	while(1){
	cin>>sum;
	if(sum==0){break;}
	for(int i=0;i<9;i++){
		cin>>a[i];
		sum2+=a[i];
	}
	cout<<sum-sum2<<endl;
	sum2=0;}
	return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    int ans = 0;
    for (int i = 1; i <= n; i+=2) {

        ans++;
    }
    if (ans >= k)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}


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

string lcs(string& s, string& t){
    int n = s.size();
    int m = t.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    string res = "";
    int i=n, j=m;
    while(i>0 && j>0){
        if(s[i-1] == t[j-1]){
            res = s[i-1] + res;
            i--;
            j--;
        } else if(dp[i-1][j] > dp[i][j-1]){
            i--;
        } else{
            j--;
        }
    }
    return res;
}

int32_t main(){
    string s, t;
    cin >> s >> t;
    cout << lcs(s, t) << "\n";
}

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

int main(){
    string S;
    cin >> S;
    vector<int> ans(S.size(), 1);
    int size = S.size(), tmp;

    for(int i=0; i<size-1; i++){
	if(S[i]=='R' && S[i+1]=='R'){
	    ans[i+1]+=ans[i];
	    ans[i]=0;
	}	
	if(S[size-2-i]=='L' && S[size-1-i]=='L'){
	    ans[size-2-i]+=ans[size-1-i];
	    ans[size-1-i]=0;
	}
    }

    

    for(int i=0; i<size-1; i++){
	if(S[i]=='R' && S[i+1]=='L'){
	    tmp = ans[i]+ans[i+1];
	    if(tmp%2==0){
		ans[i]=tmp/2;
		ans[i+1]=tmp/2;
	    }
	    else if(ans[i]>ans[i+1]){		
		if(ans[i]%2==0){
		    ans[i]=tmp/2;
		    ans[i+1]=tmp/2+1;
		}
		else{
		    ans[i]=tmp/2+1;
		    ans[i+1]=tmp/2;
		}		    

		    
	    }
	    else{
		if(ans[i+1]%2==0){
		    ans[i]=tmp/2+1;
		    ans[i+1]=tmp/2;
		}
		else{
		    ans[i]=tmp/2;
		    ans[i+1]=tmp/2+1;
		}		    

	    }
	}
    }

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





Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;

signed main(){
	int N;
	cin >> N;
	vector<int>a(N);
	REP(i,N){
		cin >> a[i];
	}
	int lim = 2,ans = a[0]-1;
	FOR(i,1,N){
		ans+=(a[i]-1)/lim;
		if(lim==a[i])lim++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include  <bits/stdc++.h>
using namespace std;
#define I_AM_SPEED  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define mem(a,v)    memset((a), (v), sizeof (a))
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define anal         '\n'
#define mod 1000000007
//const double PI = acos(-1.0);
typedef long long ll;


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
     


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-


int main(){
I_AM_SPEED;


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
      
      ll a;
      cin >> a;
      long double b;
      cin >> b;
      ll ans = a * b;
      cout << ans << anal;
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
return  0 ;      
}        





Measured memory_bytes: 3748
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        HashSet<Integer> set = new HashSet<>();
        for(int i = 0; i < N; i++){
            set.add(in.nextInt());
        }
        if(set.size() == N){
            println("YES");
        }
        else{
            println("NO");
        }
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 59584
# -*- coding: utf-8 -*-
"""
B - Exchange
https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_b

"""
import sys


def solve(A, B, K):
    turn = 'takahashi'
    for _ in range(K):
        if turn == 'takahashi':
            A -= (A % 2)
            A //= 2
            B += A
            turn = 'aoki'
        else:
            B -= (B % 2)
            B //= 2
            A += B
            turn = 'takahashi'
    return A, B


def main(args):
    A, B, K = map(int, input().split())
    ans = solve(A, B, K)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

int main(){
  //小数点以下12桁を表示させるためのおまじない。
  cout << fixed << setprecision(12);
  
  double r; //rは実数
  cin>>r;

  double PI = acos(-1); //cos(π) = -1 -> acos(-1) = π
  double area = r * r * PI;
  double cir = (r + r) * PI;
  cout<<area<<" "<<cir<<endl;
  
  return 0;
}



Measured memory_bytes: 3244
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int cost[101][101];
int main(){
	int c,N,m,i,j,k,x,y;
	for(;scanf("%d%d%d",&N,&m,&c),N;){
		vector<map<int,int> >dist(N+1);
		vector<map<int,int> >fee(N+1);
		memset(cost,99,sizeof(cost));
		for(k=0;k<m;k++){
			scanf("%d%d%d%d",&i,&j,&x,&y);
			dist[i][j]=dist[j][i]=y;
			fee[i][j]=fee[j][i]=x;
		}
		for(i=0;i<=c;i++)cost[1][i]=0;
		for(;~c;c--){
			vector<bool>used(N+1);
			for(;;){ //dijkstra
				int m=9999999;
				for(i=1;i<=N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c];
				if(m==9999999)break;
				for(j=1;j<=N;j++)if(m==cost[j][c]){
					map<int,int>::iterator it=dist[j].begin();
					for(used[j]=1;it!=dist[j].end();it++){
						if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c];
						if(fee[j][it->first]<=c&&cost[it->first][max(0,c-fee[j][it->first])]>cost[j][c])
							cost[it->first][max(0,c-fee[j][it->first])]=cost[j][c];
					}
				}
			}
		}
		printf("%d\n",cost[N][0]);
	}
}

Measured memory_bytes: 2020
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int N, M, C;
  vector<int> B;

  cin >> N >> M >> C;

  for (int i = 0; i < M; i++) {
    int b;
    cin >> b;
    B.push_back(b);
  }

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int ans = 0;
    for (int j = 0; j < M; j++) {
      int a;
      cin >> a;
      ans += a * B[j];
    }
    ans += C;

    if (ans > 0)
      cnt++;
  }
  cout << cnt << endl;
}


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

signed main(){
  int N; cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  int ans = 0, right = 0, sum = 0;
  for(int left = 0; left < N; left++){
    while(right < N && (sum ^ a[right]) == (sum + a[right])){
      sum ^= a[right];
      right++;
    }
    ans += (right - left);
    if(right == left) right++;
    else sum -= a[left];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
def slove():
    import sys
    input = sys.stdin.readline
    n, m, x, y = list(map(int, input().rstrip('\n').split()))
    mx = max(list(map(int, input().rstrip('\n').split())))
    my = min(list(map(int, input().rstrip('\n').split())))
    for i in range(x + 1, y + 1):
        if mx < i <= my:
            print("No War")
            exit()
    print("War")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define PI 3.1415926535897932384
#define MAX 100000
#define MOD 10000007
using namespace std;

///OMI
int main()
{

   int m,n,count=0;

   cin>>m>>n;
     m--;n--;
  int even=(m*(m+1))/2;
  int odd=(n*(n+1))/2;

  int res=odd+even;

  cout<<res<<endl;

  

return 0;

   
}


Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())

items = []
for _ in range(M):
	l, r, c = map(int, input().split())
	items.append([l, r, c])

items.sort()
def check():
	queue = []
	index = 0
	data = [None]
	dists = [None, 0]
	for i in range(1, N):
		while index < M:
			l, r, c = items[index]
			if l <= i:
				heapq.heappush(queue, (c + dists[i], -r))
				index += 1
			else:
				break
		while True:
			if len(queue) == 0:
				return None
			c, r = queue[0]
			if -r > i:
				break
			heapq.heappop(queue)
		data.append((c, -r))
		dists.append(c)
	return dists

data = check()
if data != None:
	print(data[N])
else:
	print(-1)


Measured memory_bytes: 98776
N, M, L = map(int, input().split())
INF = 10**12
dp = [[INF]*N for i in range(N)]
fp = [[INF]*N for i in range(N)]
for i in range(N):
  dp[i][i]=0
  fp[i][i]=0
k = [[0]*N for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  dp[a-1][b-1] = c
  dp[b-1][a-1] = c

for i in range(N):
  for j in range(N):
    for h in range(N):
      dp[j][h] = min(dp[j][h], dp[j][i]+dp[i][h])

for j in range(N):
  for h in range(N):
    if dp[j][h]<=L:
      fp[j][h] = 1
for i in range(N):
  for j in range(N):
    for h in range(N):
      fp[j][h] = min(fp[j][h], fp[j][i]+fp[i][h])
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s = s-1
  t = t-1
  if fp[s][t]==INF:
    print(-1)
  else:
    print(fp[s][t]-1)



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

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

  int l = 0;
  int r = k - 1;
  int ans = 1'000'000'000;
  while (r < n) {
    ans = min(ans, h[r] - h[l]);
    l++;
    r++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define bs inline bool scan
ii(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
ii() {return in(gcu());}
bs(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bs(char &c){c=gcu();gcu();return c!=EOF;}
// bs(string &s){int c; s = "";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#undef bs
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
// vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

vector<bool> sieve;

void make_sieve(int m) {
	sieve = vector<bool>(m, true);
	sieve[1] = false;
	for (int i = 3, e = sqrt(m); i <= e; i += 2) {
		if (!sieve[i])
			continue;
		for (int j = i * i; j < m; j += i)
			sieve[j] = false;
	}
}

bool is_prime(int n) {
	return (n % 2) ? sieve[n] : n == 2 ? true: false;
}

int main() {
	make_sieve(1000000);
	for (int a, b, c; a = in(), b = in(), c = in();) {
		for (int i = 0;; a += b)
			if (is_prime(a) && ++i == c)
				break;
		out(a, '\n');
	}
}


Measured memory_bytes: 2524
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  long long N;
  cin >> N;
  string S;
  while(N != 0){
    if(N%2){
      S += '1';
      --N;
    }else S += '0';
    N /= -2;
  }
  reverse(S.begin(), S.end());
  if(S == "") S = '0';
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int ans = 0;
set<PP> S;
void sim(ll A,ll B,ll C){
  if(A%2||B%2||C%2) cout<<ans<<endl,exit(0);
  if(S.count(PP(A,P(B,C)))) cout<<-1<<endl,exit(0);
  S.insert(PP(A,P(B,C)));
  
  ans++;
  ll nA =(B+C)/2;
  ll nB =(A+C)/2;
  ll nC =(A+B)/2;
  sim(nA,nB,nC);
}

int main(){
  ll A,B,C;
  cin>>A>>B>>C;
  sim(A,B,C);
  return 0;
}


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

int main(){
    int k;
    std::cin>>k;
    std::vector<int> v = {0};
    for(int i=0;i<k;++i){
        int t = 0;
        for(;t < v.size(); ++t){
            if(v[t] != 9 && (t+1 == v.size() || v[t] <= v[t+1]  ))
                break;
        }
        if(t  == v.size())
            v.push_back(0);
        v[t]+=1;
        for(int s = t-1 ;s >= 0;--s){
            v[s] = std::max(v[s+1]-1,0);
        }
        
    }

    for(auto it = v.rbegin(); it != v.rend();++it){
        std::cout<<*it;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 100005
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,size[maxn];
struct op{int x,y;};
inline bool com(op x,op y){return x.y>y.y;}
vector<op>G[maxn];
inline void dfs(int u)
{
    reg int i,sz=G[u].size();
    for(i=0;i<sz;++i)
    {
        dfs(G[u][i].x);
        G[u][i].y=size[G[u][i].x];
    }
    sort(G[u].begin(),G[u].end(),com);
    for(i=sz-1;i>=0;--i)
        size[u]=max(size[u],G[u][i].y+i+1);
}
int main()
{
    n=read();reg int i,x;
    for(i=2;i<=n;++i)
        x=read(),G[x].push_back(op{i,0});
    dfs(1);cout<<size[1]<<"\n";
	return 0;
}


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

int main(){
	int n, i, d1, d4;
	cin >> n;
	int x[n], y;
	double d2, d3;
	d1 = 0;
	d2 = 0;
	d3 = 0;
	d4 = 0;
	for (i = 0; i < n; ++i){
		cin >> x[i];
	}
	for (i = 0; i < n; ++i){
		cin >> y;
		d1 += abs(x[i]-y);
		d2 += (x[i]-y)*(x[i]-y);
		d3 += abs((x[i]-y)*(x[i]-y)*(x[i]-y));
		d4 = max(d4,abs(x[i]-y));
	}
	d2 = sqrt(d2);
	d3 = cbrt(d3);
	printf("%d\n%.8lf\n%.8lf\n%d\n", d1, d2, d3, d4);
	return 0;
}

Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    int sum = 0;
    while (n--) {
        int x; cin >> x;
        sum ^= (x & 1);
    }   
    if (sum)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
a = [1] * (N+1)
p = [1] * (N+1)
for i in range(1,N+1):
    a[i] = a[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1
def f(n, x):
    if n == 0:
        return 1
    elif x == 1:
        return 0
    elif 2<= x <= a[n-1] + 1:
        return f(n-1, x-1)
    elif x == a[n-1] + 2:
        return p[n-1] + 1
    elif a[n-1]+3 <= x <= 2*a[n-1]+2:
        return p[n-1]+1+ f(n-1, x-(a[n-1]+2))
    elif x == 2*a[n-1]+3:
        return p[n]
print(f(N,X))

Measured memory_bytes: 3064
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N =I()
_P= LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
P = np.array(_P)
#C = np.zeros(N + 1)


def main():
    # count = 1
    # # if (len(P)==1):
    # #     return count
    # min_array =[P[0]]
    # for i in range(1,N):
    #     if (P[i]<=min_array[i-1]):
    #         count += 1    
    #     if P[i-1]>P[i]:
    #         min_array.append(P[i])
    #     else:
    #         min_array.append(P[i-1])
    # return count
# print(min_array)
    Q = np.minimum.accumulate(P)
    count = np.count_nonzero(P <= Q)
    return count

print(main())
# if ans:
#     print('Yes')
# else:
#     print('No')

Measured memory_bytes: 51020
#include<stdio.h>
int main(){
int a,b,c;
char op;
while(1){
scanf("%d %c %d",&a,&op,&b);
if(op=='+') c = a + b;
if(op=='-') c = a - b;
if(op=='*') c = a * b;
if(op=='/') c = a / b;
if(op=='?') break;
printf("%d\n",c);
}
return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
char ccnt[10010][10010];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
 /*   double t,x;
    cin>>t>>x;
    t=t/x;
    cout<<t*1.0<<'\n';*/
  
   /* int a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b)/2<<'\n';*/

   /* int d;
    cin>>d;
    if(d==22){
        cout<<"Christmas Eve Eve Eve"<<'\n';
    }else if(d==23){
        cout<<"Christmas Eve Eve"<<'\n';
    }else if(d==24){
        cout<<"Christmas Eve"<<'\n';
    }else if(d==25){
        cout<<"Christmas"<<'\n';
    }*/

   /* int x,y;
    cin>>x>>y;
    y=y/2;
    cout<<x+y<<'\n';*/

   /* int n,a,b;
    cin>>n;
    if(n==1){
        cout<<"Hello World"<<'\n';
    }else{
        cin>>a>>b;
        cout<<a+b<<'\n';
    }*/

   /* int n;
    cin>>n;
    if(n==111){
        cout<<999<<'\n';
    }else if(n==119){
        cout<<991<<'\n';
    }else if(n==199){
        cout<<911<<'\n';
    }else if(n==191){
        cout<<919<<'\n';
    }else if(n==999){
        cout<<111<<'\n';
    }else if(n==911){
        cout<<199<<'\n';
    }else if(n==919){
        cout<<191<<'\n';
    }else if(n==991){
        cout<<119<<'\n';
    }*/

  /*  int a[5];
    for(int i=0; i<3; i++){
        cin>>a[i];
    }
    sort(a,a+3,greater<int>());
    a[0]=a[0]*10;
    a[0]=a[0]+a[1]+a[2];
    cout<<a[0]<<'\n';*/

  /*  int a,b;
    cin>>a>>b;
    a=a*b;
    if(a%2==0){
        cout<<"No"<<'\n';
    }else{
        cout<<"Yes"<<'\n';
    }*/

  /*int a,b;
    cin>>a;
    b=a/2;
    if(a%2==0){
        cout<<b*b<<'\n';
    }else{
        cout<<b*(b+1)<<'\n';
    }*/

  /*  int n,i;
    cin>>n>>i;
    cout<<n-i+1<<'\n';*/

    int h,w;
    cin>>h>>w;  
	vector<string> a(h);
	for (int i=0; i<h; i++) {
		    cin>>a[i];
	}   
 
	vector<bool> cnt(h,false); 
	vector<bool> ent(w,false);
	for(int i=0; i<h; i++) {
		for(int j=0; j<w; j++) {
			if(a[i][j]=='#') {
				    cnt[i] = true;
			    	ent[j] = true;
			    }   
		    }
	    }
	for(int i=0; i<h; i++) {
		if(cnt[i]){   
			for(int j=0; j<w; j++) {
				if(ent[j]) {
					cout<<a[i][j];
				    }
			    }
		    	cout<<'\n';
	    	}
	}
}   

Measured memory_bytes: 256
#include <iostream>
#include <array>

int main(){
    std::array<int, 4> a; //player A
    std::array<int, 4> b; //player B
    int hit=0;
    int blow=0;
   
    while(std::cin >> a[0] >> a[1] >> a[2] >> a[3]){
        std::cin >> b[0] >> b[1] >> b[2] >> b[3];      
        //if(a[0] == a[1] == a[2] == a[3] == b[0] == b[1] == b[2] == b[3] == -1)
	//break;

	//    std::cout << b[0];
    
        for(int i=0; i<a.size(); ++i){
            for(int j=0; j<b.size(); ++j){
	        if(a[i] == b[j] && i == j)
	            ++hit;
	        else if(a[i] == b[j] && i != j)
	            ++blow;
	    }
	}

	std::cout << hit << " " << blow << std::endl;

	hit = blow = 0;
    }  
    return 0;
}

Measured memory_bytes: 2936
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <map>
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll maxn = 1e5 + 5;

int f[maxn];
int sum[maxn];
int ans[maxn];
int n,m,k;

void init(){
	for(int i=0;i<=n;i++){
		f[i]=i;
		sum[i]=1;
	}
}

int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}

void merge(int x,int y){
	int a=find(x);
	int b=find(y);
	if(a!=b) f[b]=a,sum[a]+=sum[b];
}

int main(){
	cin>>n>>m>>k;
	init();
	for(int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		ans[a]++,ans[b]++;
		merge(a,b);
	}
	for(int i=1;i<=k;i++){
		int c,d;
		cin>>c>>d;
		if(find(c)==find(d)) ans[c]++,ans[d]++;
	}
	for(int i=1;i<=n;i++){
		cout<<sum[find(i)]-ans[i]-1<<" ";
	}
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>

#define INF 100000001
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	reverse(s.begin() + n, s.end());
	//for (auto itr = s.begin(); itr != s.end(); itr++) {
	//	cout << *itr << " ";
	//}
	//cout << " " << endl;
	map<pair<string, string>, ll> map, map1;
	for (int i = 0; i < (1 << n); i++) {
		string s1, s2, t1, t2;
		for (int j = 0; j < n; j++) {
			if (i&(1 << j)) {
				s1.push_back(s[j]);
				t1.push_back(s[n + j]);
			}
			else {
				s2.push_back(s[j]);
				t2.push_back(s[n + j]);
			}
		}
		map[make_pair(s1, s2)]++;
		map1[make_pair(t1, t2)]++;
	}
	ll ans = 0;
	/*for (auto itr = map.begin(); itr != map.end(); itr++) {
		cout << itr->first.first << " " << itr->first.second << " " << itr->second << endl;
	}
	cout << endl;
	for (auto itr = map1.begin(); itr != map1.end(); itr++) {
		cout << itr->first.first << " " << itr->first.second << " " << itr->second << endl;
	}*/
	for (auto itr = map.begin(); itr != map.end(); itr++) {
		ans += itr->second*map1[itr->first];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 108416
fn solve() {
    let (n, k): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut a: Vec<usize> = (0..n).map(|_| read::<usize>()).collect();
    a.sort();
    let mut ans = 0;
    for i in 0..k {
        ans += a[i];
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 2208
N=int(input())
A=[int(i) for i in input().split()]
C=[]
l=0
C.append(([(0,-1),(A[0],0)]))
for i in range(1,2**N):
  biggest,second=(A[i],i),(0,-1)
  for k in range(l+1):
    if i&(1<<k):
      for a in C[i^(1<<k)]:
        if a[0]>biggest[0]:
          second=biggest
          biggest=a
        elif a[0]>second[0] and biggest!=a:
          second=a
  C.append([second,biggest])
  if i==2**(l+1)-1:
    l+=1
ans=[0]
for i in range(1,2**N):
  a,b=C[i]
  ans.append(max(ans[-1],a[0]+b[0]))
  print(ans[-1])

Measured memory_bytes: 122444
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<set>
#include<list>

using namespace std;



//1
int main(){
	for(int i=0; i<7;i++){
		int a, b;
		cin >> a >> b;
		cout << a- b << endl;

	}

	return 0;
}


/*
//2
int main(){


	return 0;
}
*/

/*
//3
int main(){


	return 0;
}
*/

/*
//4
int main(){


	return 0;
}
*/

/*
//5
int main(){


	return 0;
}
*/

/*
//6
int main(){


	return 0;
}
*/

/*
//7
int main(){


	return 0;
}
*/

/*
//8
int main(){


	return 0;
}
*/

/*
//9
int main(){


	return 0;
}
*/

/*
//10
int main(){


	return 0;
}
*/




Measured memory_bytes: 3104
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)

#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld\n",a)

#define stll(a) stoll(a,nullptr,10)
#define all(a) a.begin(),a.end()
#define PII pair<ll,ll>
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define EL printf("\n")
#define ff first
#define ss second
#define rev(a) reverse(all(a))


#define mem(ar,val) memset(ar,val,sizeof(ar))
#define ssort(ar) sort(ar.begin(),ar.end())
#define csort(ar,comp) sort(ar.begin(),ar.end(),comp)

#define bug1(a) cerr<<"test "<<a<<endl;
#define bug2(a,b) cerr<<"test "<<a<<" "<<b<<endl;
#define bug3(a,b,c) cerr<<"test "<<a<<" "<<b<<" "<<c<<endl;
#define bug4(a,b,c,d) cerr<<"test "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

#define fout freopen("output.txt","w",stdout)
#define fin  freopen("input.txt","r",stdin)

/// unordered_map<int,int>mp;
/// mp.reserve(1024);
/// mp.max_load_factor(0.25);

/// pbds
/// *find_by_order(k) - return k th largest element.. 0 based
/// order_of_key(k) - number of items strictly smaller than k

///  priority_queue <ll, vector<ll>, greater<ll> >

/*
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
*/

typedef long long ll;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

ll stat[20000];
void sieve()
{
    ll n =10005;
    ll sq = sqrt(n);
    for(int i=2;i<=sq;i++)
        if(stat[i]==0)
        for(int j=i*i;j<=n;j+=i)
        stat[j]=1;
    stat[1]=1;
}

int main()
{
    sieve();
    ll n;
    while(cin>>n)
    {
        ll cnt =0;
        for(int i=1,j=n;i<=n;i++,j--)
            if(stat[i]==0 && stat[j]==0)
                cnt++;
        cout<<cnt<<endl;

    }

}





Measured memory_bytes: 3076
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;

	char c = s[0];
	int ans = 1;
	REP(i, n)
	{
		if (c != s[i])
		{
			ans++;
			c = s[i];
		}
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 512
def partition(A, p, r):
    x = A[-1]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    i += 1
    A[i], A[r] = A[r], A[i]
    return i
    
n = input()
x = map(int, raw_input().split())

c = partition(x, 0, n-1)

for i, e in enumerate(x):
    if i == c:
        print '[{0}]'.format(e),
    else:
        print e,

Measured memory_bytes: 12748
def main():
    n, q = [int(x) for x in input().split(' ')]
    arys = []
    for i in range(n):
        arys.append([])
    for i in range(q):
        query = input()
        cmd = int(query[0])
        if cmd == 0:
            _, t, x = [int(x) for x in query.split(' ')]
            arys[t].append(x)
        elif cmd == 1:
            _, t = [int(x) for x in query.split(' ')]
            print(' '.join([str(x) for x in arys[t]]))
        elif cmd == 2:
            _, t = [int(x) for x in query.split(' ')]
            arys[t] = []


if __name__ == '__main__':
    main()



Measured memory_bytes: 60456
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint X;
	cin >> X;
	lint now = 100;
	lint cnt = 0;
	while (1) {
		now = now + now / 100;
		if (now >= X) {
			cout << cnt+1 << endl;
			return 0;
		}
		cnt++;
	}
 }

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, L, T;
    cin >> N >> L >> T;
    vll X(N), W(N), p(N);
    rep(i, N) {
        cin >> X[i] >> W[i];
        if (W[i] == 1) {
            p[i] = X[i] + T;
        } else {
            p[i] = X[i] - T;
        }
        p[i] %= L;
        if (p[i] < 0)p[i] += L;
    }
    ll s = p[0];
    sort(all(p));

    ll id = 0;
    FOR(i, 1, N) {
        if (W[0] != W[i]) {
            ll d = W[0] == 1 ? X[i] - X[0] : X[0] + L - X[i];
            if (T >= (d + 1) / 2) {
                ll y = (2 * T - d) / L + 1;
                if (W[0] == 1)id += y;
                else id -= y;
            }
       }
    }
    id %= N;
    if (id < 0)id += N;
    ll pos = 0;
    rep(i, N)if (s == p[i]) {
        pos = i;
        if (N > 1 && W[0] == 1 && p[i] == p[(i + 1) % N])pos = (i + 1) % N;
        if (N > 1 && W[0] == 2 && p[i] == p[(i + N - 1) % N])pos = (i + N - 1) % N;
        break;
    }

    vll ans(N);
    rep(i, N)ans[(id + i) % N] = p[(pos + i) % N];
    rep(i, N)cout << ans[i] << endl;
}


Measured memory_bytes: 4352
n,Y=map(int,input().split())
Y//=1000

ans=False
for x in range(n+1):
    for y in range(n+1):
        if Y-10*x-5*y==n-x-y and (n-x-y)>=0:
            ans=True
            break
    if ans==True:
        break

if ans is True:
    print(x,y,n-x-y)
else:
    print(-1,-1,-1)

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

#define M 1000000007
char s[100002], t[100002];
int  cnt[128];

int main()
{
	int i, N;

	scanf("%d%s%s", &N, s, t);
	cnt[s[0]] = 1;
	for (N--, i = 1; i < N; i++) {
		cnt[s[i]] += cnt[t[i]];
		if (cnt[s[i]] >= M) cnt[s[i]] -= M;
	}
	printf("%d\n", cnt[t[N]]);
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
using namespace std;
#define MAXN 1010
#define INF 1000000007
map<int,int> ma;
int pre[MAXN],sum[MAXN];
int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int gettime()
{
    int m,d,h,t;
    scanf("%d/%d %d:%d",&m,&d,&h,&t);
    return ((mon[m-1]+d)*24+h)*60+t;
}
int main()
{
    //freopen("/home/moor/Code/input","r",stdin);
    int n,now,ans;
    while(scanf("%d",&n)&&n)
    {
        now=1;
        ma.clear();
        ma[0]=0;
        memset(pre,0x3f,sizeof(pre));
        memset(sum,0,sizeof(sum));
        for(int i=0;i<n;++i)
        {
            char s[2];
            int t,p;
            t=gettime(),scanf("%s%d",s,&p);
            if(ma.find(p)==ma.end())    ma[p]=now++;
            p=ma[p];
            if(s[0]=='I')   pre[p]=t;
            else
            {
                if(p==0)
                    for(int j=1;j<now;++j)  sum[j]+=max(0,t-max(pre[0],pre[j]));
                else    sum[p]+=max(0,t-max(pre[0],pre[p]));
                pre[p]=INF;
            }
        }
        ans=0;
        for(int i=1;i<now;++i)  ans=max(ans,sum[i]);
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= 100000; ++i) {
        int na = i * 108 / 100 - i, nb = i * 110 / 100 - i;
        if (na == a && nb == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  string s;
  int ans;
  
  cin >> s;
  
  sort(s.begin(), s.end());
  
  if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3480
count=0
while True:
    a,b=map(int,raw_input().split(" "))
    if a==0 and b==0:
        break
    if count!=0:
        print ""
    count+=1
    uruu=[]
    for i in [year for year in range(b+1) if year >=a]:
        if i%4==0 and i%100!=0 or i%400==0:
            uruu.append(str(i))
    if len(uruu)!=0:
        print '\n'.join(uruu)
    else:
        print "NA"

Measured memory_bytes: 4340
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;


struct SegT {
private:
	int sz; vector<ld> node;
	const ld init_c = 1;
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	SegT(vector<ld> v) {
		int n = v.size();
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
		rep(i, n) {
			node[i+sz-1] = v[i];
		}
		per(i, sz - 1) {
			node[i] = f(node[2 * i + 1], node[2 * i + 2]);
		}
	}
	ld f(ld a, ld b) {
		return a*b;
	}
	ld query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			ld vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			ld vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};

ld b = 1000000000;

void solve() {
	int n; cin >> n;
	vector<int> t(n);
	vector<ld> a(n);
	rep(i, n) {
		cin >> t[i];
		int p; cin >> p;
		a[i] = (100 - 10 * p) / (ld)100;
	}
	SegT st(a);
	int q; cin >> q;
	rep(i, q) {
		int l, r; cin >> l >> r;
		int idl = lower_bound(t.begin(), t.end(), l) - t.begin();
		int idr = lower_bound(t.begin(), t.end(), r) - t.begin();
		ld ans = b * st.query(idl, idr);
		cout << ans << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(8);
	//init();
	solve();
	stop
		return 0;
}



Measured memory_bytes: 10552
# -*- coding:utf-8 -*-
arr = [[[0 for i3 in range(10)] for i2 in range(3)] for i1 in range(4)]

n = int(input())
for i in range(n):
    b,f,r,v = map(int,input().split())
    arr[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        for k in range(10):
            print(' ',arr[i][j][k],sep = '',end='')
        print('')
    if i != 3:
        print('####################')

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

int main(){
char c;
cin >> c;


if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
  cout << "vowel" <<endl;
}else {
  cout << "consonant" <<endl;
}

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main() {
    int x,y;
    cin >>x>>y;
    if(x==3){
      if(y==3) cout << 200000 << endl;
      else if(y==2) cout << 300000 << endl;
      else if(y==1) cout << 400000 << endl;
      else cout << 100000 << endl;
    }
    else if(x==2){
      if(y==3) cout << 300000 << endl;
      else if(y==2) cout << 400000 << endl;
      else if(y==1) cout << 500000 << endl;
      else cout << 200000 << endl;
    }
    else if(x==1){
      if(y==3) cout << 400000 << endl;
      else if(y==2) cout << 500000 << endl;
      else if(y==1) cout << 1000000 << endl;
      else cout << 300000 << endl;
    }
    else{
      if(y==3) cout << 100000 << endl;
      else if(y==2) cout << 200000 << endl;
      else if(y==1) cout << 300000 << endl;
      else cout << 0 << endl;
    } 


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	vector<bool> put(n + 1);
	int res = 0;
	for(int i = n; i >= 1; i --){
		int cnt = 0;
		for(int j = 2 * i; j <= n; j += i){
			cnt += put[j];
		}
		if((a[i] - cnt) & 1){
			res ++;
			put[i] = true;
		}
	}
	cout << res << "\n";
	for(int i = 1; i <= n; i ++){
		if(put[i]){
			cout << i << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 1792