akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define MAX_HEAP 500000     // 最大ヒープサイズ

#define right(i) (i*2)      // ヒープにおけるノードiの右の子のインデックス
#define left(i)  (i*2+1)    // ヒープにおけるノードiの左の子のインデックス

void maxHeapify(int h, int a[],int i);
void buildMaxHeap(int h, int a[]);

/*
ヒープは配列として持つ。
インデックスの考え方を問題文に合わせるため、インデックス0は使用しない。
よって、サイズhのヒープaはa[1]～a[h]を使用する。
*/


// サイズhのヒープaにおいて、iのノードを根とするツリーを最大ヒープにする
void maxHeapify(int h, int a[],int i){
    int l,r,largest,tmp;
    l = left(i);
    r = right(i);
    // 左の子、自分、右の子で値が最大のノードを選ぶ
    if( (l <= h) && (a[l] > a[i])){
        largest = l;
    }else{
        largest = i;
    }

    if( (r <= h) && (a[r] > a[largest]) ){
        largest = r;
    }

    if( largest != i ){ // i の子の方が値が大きい場合
        tmp         = a[i];
        a[i]        = a[largest];
        a[largest]  = tmp;
        maxHeapify(h, a, largest); // 再帰的に呼び出し
    }
}

// サイズhのヒープaを最大ヒープにする
void buildMaxHeap(int h, int a[]){
    int i;
    for( i = h/2; i > 0; i-- ){
        maxHeapify(h, a, i);
    }
}

int main(){
    int a[MAX_HEAP+1];
    int h;
    int i;

    // 入力
    scanf("%d",&h);
    for( i = 1; i <= h; i++ ){
        scanf("%d",&(a[i]));
    }

    // 最大ヒープ化
    buildMaxHeap(h, a);

    // 出力
    for( i = 1; i <= h; i++ ){
        printf(" %d",a[i]);
    }
    printf("\n");

    return 0;
}




Measured memory_bytes: 3752
from itertools import accumulate, count, islice, takewhile
 
def eratosthenes():
    d = {}
    for q in count(2):
        p = d.pop(q, None)
        if p:
            x = next(x for x in count(q + p, p) if x not in d)
            d[x] = p
        else:
            yield q
            d[q*q] = q

def likes():
    xs = set()
    for p in eratosthenes():
        if p in xs:
            yield p
        xs.add(2*p - 1)

likeset = set(takewhile(lambda n: n <= 100000, likes()))
onehot = (i in likeset for i in range(100001))
likecounts = list(accumulate(onehot))

q = int(input())
lrs = [[int(x) for x in input().split()] for _ in range(q)]

for l, r in lrs:
    print(likecounts[r+1] - likecounts[l-1]) 

Measured memory_bytes: 25228
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int n,a,b;cin>>n>>a>>b;
    int ans=(n/(a+b))*a;
    ans+=min(n%(a+b),a);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque

def dfs(edge, s):
    used = {s}
    que = deque([s])
    while que:
        v = que.pop()
        for u in edge[v]:
            if u in used:
                continue
            used.add(u)
            que.append(u)
    return used

def bellmanFord(edges):
    coins = [float('inf')] * N
    coins[0] = 0
    for _ in range(len(U)):
        f = True
        for u, v, c in edges:
            if coins[u] + c < coins[v]:
                coins[v] = coins[u] + c
                f = False
        if f:
            return max(0, -coins[-1])
    return -1

N, M, P = map(int, input().split())
A = [[] for _ in range(N)]
A_rev = [[] for _ in range(N)]
E = [tuple()] * M
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    c = P - c
    A[a].append(b)
    A_rev[b].append(a)
    E[i] = (a, b, c)
U = dfs(A, 0) & dfs(A_rev, N-1)
F = [(a, b, c) for (a, b, c) in E if a in U and b in U]
print(bellmanFord(F))

Measured memory_bytes: 5356
ARG_N, ARG_K = gets.split.map(&:to_i)
ARG_H = gets.split.map(&:to_i)

dp = Array.new(ARG_N)
dp[0] = 0
n = 1
while(n<ARG_N) do
  k = 1
  while((k<=ARG_K)&&((n-k)>=0)) do
    d = dp[n-k]+(ARG_H[n] - ARG_H[n-k]).abs
    dp[n] = d if !dp[n] || d < dp[n]
    k+=1
  end
  n+=1
end

puts dp[ARG_N-1]

Measured memory_bytes: 10756
#include <bits/stdc++.h>    
#define pb push_back

#define FOR(x,to) for(int x=0;x<(to);x++)
#define F0R(x,in,to) for(int x=(in);x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))

typedef long long ll;
using namespace std;
ll MOD = 998244353;

typedef pair<int,int> ii;
typedef struct {int a,b,c;}iii;
typedef vector<int> vi;

void mosA(vector<ll> a){
	for(int i=0; i<a.size(); i++) printf("%lld ",a[i]);
	printf("\n");
}
void mosP(vector<ii> a){
	for(int i=0; i<a.size(); i++) printf("%d %d\n",a[i].first,a[i].second);
	printf("\n");
}

ll min_especial(ll a, ll b){
  if(a!=-1 && b!=-1) return min(a,b);
  else return max(a,b);
}
/*
bool ord(ii a, ii b){
	if(a.first == b.first){
		return a.second < b.second;
	}
	return a.first < b.first;
}*/

bool ord(ll a, ll b){
	return a>b;
}

ll ans = 0;
int a,n,w,t,k,m,z,q,l,r,x,b;
ll A[200005];
char S[200005];
double P2[100];



int main(){
	scanf("%d%d",&n,&k);
	double pS = 0;

	P2[0] = 1;
	for(int i=1; i<20; i++)
		P2[i] = 2*P2[i-1];
	
	
	F0R(i,1,n+1){
		int cont = 0;
		int x = i;
		double p = 1/(n*1.0);
		while(x<k){
			x*=2;
			cont++;
		}
		pS+=(1/(n*P2[cont]));
	}

	printf("%0.13lf\n", pS);

}




// REVISATE ESTO:
// - memset(A,-1,SIZEOF()*n)
// - (x-y+MOD)%MOD
// - int o ll?

Measured memory_bytes: 256
N=int(input())
L=[list(map(int,input().split())) for _ in range(N)]
s=0
p=True
L=sorted(L,key=lambda x: x[1])
for l in L:
    s+=l[0]
    if l[1]>=s:
        continue
    else:
        p=False
        break
print("Yes" if p else "No")


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

int main() {
    ll l,r;cin>>l>>r;
    ll dif=r-l;
    if(dif>3000){
        cout<<0<<endl;
    }else{
        ll min=2020;
        for(ll i=l;i<=r;i++){
            for(ll k=i+1;k<=r;k++){
                if(min>(i*k)%2019) min=(i*k)%2019;
            }
        }
        cout<<min<<endl;
    }
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>k;
      rrep(b,k+1,n+1){
        pos=n/b;
        cmp=b;
        cmp-=k;
        pos*=cmp;
        ans+=pos;
        pos=n%b;
        cmp=max(k-1,0LL);
        if(pos>=cmp){
        ans+=pos-cmp;
        }
      }
      Cout(ans);
     

       
return 0;
}


Measured memory_bytes: 256
// Author : Chi
// created :
// Sawal : Practice

//header files
#include <bits/stdc++.h>
#include "cmath"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

//macros
#define ll 		    long long
#define ull         unsigned long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb(x)       push_back(x)
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         1000000007
#define aLL(x)      x.begin(),x.end()
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define ai(a)       for(auto &i:a)cin>>i;
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define db(...)     __f(#__VA_ARGS__, __VA_ARGS__)                      //for debugging
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
//LOVE ALGO
int n,k;
int *a;
void solve(){
    cin>>n>>k;
    a= new int[n+1];
    r1n(i,n)
        cin>>a[i];
    int dp[n+1][k+1];
    for(int i=0;i<=k;i++){
        dp[1][i]=(a[1]>=i)?1:0;
    }
    for(int i=2;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j==0){
                dp[i][j] = dp[i-1][j];
            }else dp[i][j] = ((dp[i][j-1]+dp[i-1][j]-((j-1-a[i]>=0)?(dp[i-1][j-1-a[i]]):0))%mod+mod)%mod;
        }
    }
    cout<<dp[n][k]<<"\n";
}

// Driver Code
int main(){
    CHI
    TEST1
    return 0;
}


Measured memory_bytes: 39296
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ull sum;

int main(){
	ll n,T;
	cin >> n >> T;
	ll t[n];
	cinf(t,n);
	arep(1,i,n){
		if(T>t[i]-t[i-1])
			sum+=t[i]-t[i-1];
		else
			sum+=T;
	}
	cout << sum+T << endl;
}

Measured memory_bytes: 5064
# -*- coding: utf-8 -*-
"""
Created on Thu Sep  3 23:43:13 2020

@author: liang
"""

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

A = list()
lis = list()
ans = 0

def make_list(n,m):
    if n == N:
        A.append(lis.copy())
        return 
    for i in range(m,M+1):
        lis.append(i)
        make_list(n+1,i)
        lis.pop()

make_list(0,1)
#print(A)

calc = [list(map(int,input().split())) for _ in range(Q)]

for a in A:
    tmp = 0
    for c in calc:
        if a[c[1]-1] - a[c[0]-1] == c[2]:
            tmp += c[3]
    if tmp > ans:
        ans = tmp
       
print(ans)

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


int main()
{
    int a,b;
    cin>>a>>b;
    string x="",y="";
    for(int i = 0;i<b;i++) x+=to_string(a);
    for(int i = 0;i<a;i++) y+=to_string(b);
    
    (x<y)?cout<<x:cout<<y;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	string t[]={"Sunny","Cloudy","Rainy"};
	map<string,int> m;
	m["Sunny"]=0;
	m["Cloudy"]=1;
	m["Rainy"]=2;
	cin>>s;
	cout<<t[(m[s]+1)%3]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pi pair<int,int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  double n;
  cin>>n;
  cout<<2*n*3.1415926535<<endl;

  return 0;
}


Measured memory_bytes: 3808
N, K = map(int,input().split())

from operator import mul
from functools import reduce

def combinations_count(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

div = K - 1  
for i in range(1, K+1):
  split_ball = combinations_count(div, i-1)
  red_ball = N-K-i+1
  if red_ball<0:
    red_balls = 0
  else:
    red_balls = combinations_count(red_ball+i, i)
  print((split_ball * red_balls) % (10**9 + 7))

Measured memory_bytes: 3944
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a,b] <- getInts
  ; let result = hikaku (a,b)
  ; putStrLn result
  }

hikaku :: (Int, Int) -> String
hikaku (x,y)
  | x < y  = "a < b"
  | x == y = "a == b"
  | x > y  = "a > b"

getInts :: IO [Int]
getInts = map read . words <$> getLine

Measured memory_bytes: 3668
#include<cstdio>
#include<cmath>
/*
px2-2pxx1+x12+py2-2pyy1+y12=px2-2pxx2+x22+py2-2pyy2+y22
x12+y12-2(pxx1+pyy1)=x22+y22-2(pxx2+pyy2)
x12+y12-2(pxx1+pyy1)=x32+y32-2(pxx3+pyy3)
2px(x2-x1)+2py(y2-y1)=x22+y22-x12-y12
2px(x3-x1)+2py(y3-y1)=x32+y32-x12-y12
px=((x22+y22-x12-y12)(y3-y1)-(x32+y32-x12-y12)(y2-y1))/2((x2-x1)(y3-y1)-(x3-x1)(y2-y1))
py=(x22+y22-x12-y12-2px(x2-x1))/2(y2-y1)*/
int main(){
    int n;
    scanf("%d", &n);
    while(n--){
        float x1, x2, x3, y1, y2, y3; 
        scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);
        float px, py; 
        px=((x2*x2+y2*y2-x1*x1-y1*y1)*(y3-y1)-(x3*x3+y3*y3-x1*x1-y1*y1)*(y2-y1))/(2*((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)));
        if(y2!=y1)
             py=(x2*x2+y2*y2-x1*x1-y1*y1-2*px*(x2-x1))/(2*(y2-y1));
        else
            py=(x3*x3+y3*y3-x1*x1-y1*y1-2*px*(x3-x1))/(2*(y3-y1));
        float r;
        r=sqrt((px-x1)*(px-x1)+(py-y1)*(py-y1));
        printf("%.3f %.3f %.3f\n", px, py, r); 
    }   
    return 0;
}



Measured memory_bytes: 2732
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, X; cin >> N >> X;
    vector<int> x(N);
    REP(i, 0, N) cin >> x[i];

    int d = abs(x[0] - X);
    REP(i, 1, N) d = __gcd(d, abs(x[i] - X));
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
const int MAX = 101;
char m[MAX+1][MAX+1];

int main(){
	int h,w;
	while(cin >> h >> w){
		bool visited[MAX+1][MAX+1];
		if(h==0 && w==0) break;

		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				visited[i][j] = true;
				cin >> m[i][j];
			}
		}
		
		int x=0, y=0;
		
		while(1){
			if(!visited[y][x]){
				cout << "LOOP" << endl;
				break;
			}
			visited[y][x] = false;
			if(m[y][x]=='v') y++;
			if(m[y][x]=='>') x++;
			if(m[y][x]=='^') y--;
			if(m[y][x]=='<') x--;
			if(m[y][x]=='.'){
				cout <<  x << " " << y << endl;
				break;
			}
			
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  var(int, n, m, k);

  rep(i, 0, n + 1)rep(j, 0, m + 1) {
    int ans = i * m + j * n - (i * j) * 2;
    if (k == ans) {
      cout << ("Yes") << endl;
      return;
    }
  }
  cout << ("No") << endl;


}


Measured memory_bytes: 256
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,
        h: [usize; n],
        a: [usize; n]
    }
    let mut tab = BIT::new(n + 1);
    for i in 0..n {
        let pre = tab.max(h[i] - 1);
        tab.update(h[i], pre + a[i] as i64);
    }
    println!("{}", tab.max(n));
}

struct BIT {
    v: Vec<i64>,
    n: usize
}

impl BIT {
    fn new(n: usize) -> BIT {
        BIT{v: vec![0; n + 1], n: n}
    }

    // update i th element by x
    fn update(&mut self, i: usize, x: i64) {
        let mut id = i as i64 + 1;
        while id <= self.n as i64 && self.v[id as usize] < x {
            self.v[id as usize] = x;
            id += id & -id;
        }
    }

    // max in 0 to i th element
    fn max(&self, i: usize) -> i64 {
        let mut id = i + 1;
        let mut ret = i64::min_value();
        while id > 0 {
            ret = std::cmp::max(ret, self.v[id]);
            id &= id - 1;
        }
        ret
    }
}


Measured memory_bytes: 10492
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;

int main(){
	int h,w;
	char c[302][302];
	scanf("%d%d",&h,&w);
	rep(i,h){
		scanf("\n");
		rep(j,w){
			scanf("%c",&c[i][j]);
		}
	}
	
	ll ret = 0;
	ll dp[302][302];
	rep(k,w-1){
		rep(i,302)rep(j,302)dp[i][j] = 0;
		rep(i,h)rep(j,h){
			if(c[i][k] == c[j][k+1]){
				if(i <= j){
					dp[j-i][0] ++;
					dp[h-i][h-j] --;
				}
				else {
					dp[0][i-j] ++;
					dp[h-i][h-j] --;
				}
			}
		}
		rep1(i,301)rep1(j,301){
			dp[i][j] += dp[i-1][j-1];
		}
		rep(i,302)rep(j,302){
			if(i == 0 && j == 0)continue;
			if(i == 0)dp[i][j] += dp[i][j-1];
			else if(j == 0)dp[i][j] += dp[i-1][j];
			else {
				dp[i][j] += min ( dp[i-1][j] , dp[i][j-1] );
			}
		}
		ret += dp[h][h];
	}
	cout << ret << endl;
}
		


Measured memory_bytes: 1152
use std::io::{BufRead, Write, stdin, stdout};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let n: u32 = s.split_whitespace().next().unwrap().parse().unwrap();
    s.clear();
    let mut even = 0;
    let mut odd = 0;
    input.read_line(&mut s).unwrap();
    for buf in s.split_whitespace() {
        let a: u32 = buf.parse().unwrap();
        if a % 2 == 1 {
            odd += 1;
        } else {
            even += 1;
        }
    }
    writeln!(output, "{}", if odd % 2 == 0 { "YES" } else { "NO" }).unwrap();
}

fn main() {
    let stdin = stdin();
    solve(stdin.lock(), stdout());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v = Vec::<u8>::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("3
1 2 3\n",
             "YES\n");
    }
    #[test]
    fn case2() {
        test("5
1 2 3 4 5\n",
             "NO\n");
    }
}

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

void input(vector<vector<int>>& rvvnCandy)
{
  int nSize;
  cin >> nSize;

  rvvnCandy.resize(2, vector<int>(nSize, 0));
 
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < nSize; j++)
      cin >> rvvnCandy[i][j];
}

int calcCandy(const vector<vector<int>>& cnrvvnCandy)
{
  int nCumlSum = 0;
  int n1stSum  = 0;
  for (int i = 0; i < cnrvvnCandy[0].size(); i++)
  {
    n1stSum += cnrvvnCandy[0][i];
    int n2ndSum = 0;
    for (int j = i; j < cnrvvnCandy[1].size(); j++)
      n2ndSum += cnrvvnCandy[1][j];

    nCumlSum = max(nCumlSum, (n1stSum + n2ndSum));
  }
  return nCumlSum;
}
    
int main()
{
  vector<vector<int>> vvnCandy;
  
  input(vvnCandy);
  cout << calcCandy(vvnCandy) << endl;

  return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<string.h>
int main()
{
	char s[11],t[11],u[11];
	int a,b;
	scanf("%s%s%d%d%s",&s,&t,&a,&b,&u);
	printf("%d %d\n",a-!strcmp(s,u),b-!strcmp(t,u));
	return 0;
}

Measured memory_bytes: 128
// AIZU ONLINE JUDGE http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=10006
//*
#include <stdio.h>
int main(){
  int x;
  int i=0;

  while(1){
    scanf("%d", &x);
    if(x==0){
      break;
    }else{
	printf("Case %d: %d\n", ++i, x);
    }
  }

  return 0;
}
//*/

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

int main(){
	int N, M, i, j, ans=0;
	cin >> N;
	int T[N];
	for(i=0; i<N; i++){
		cin >> T[i];
	}
	cin >> M;
	int P[M], X[M];
	for(i=0; i<M; i++){
		cin >> P[i] >> X[i];
	}
	for(i=0; i<M; i++){
		int temp = T[P[i]-1];
		T[P[i]-1] = X[i];
		for(j=0; j<N; j++){
			ans += T[j];
		}
		cout << ans << endl;
		ans = 0;
		T[P[i]-1] = temp;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#define tin int
#define itn int
#define tni int
#define nit int
#define nti int
#define pritnf printf
#define scnaf scanf
#define retrun return
#define sizoef sizeof
#define ll long long
#define inl inline
#define br break
#define con continue
#define mst(a,b) memset(a,b,sizeof(a))
#define re register itn
#define fora(x,a,b) for(re x=a;x<=b;++x)
#define forb(x,a,b) for(re x=a;x>=b;--a)
#define infa 0x3f3f3f3f
#define infb 0x7fffffff
#define infc 1061109567
#define infd 0x7f
using namespace std;
#define maxa 100004
#define maxb 10004
#include<cstring>

tni num,x,n[maxa]={0},sum=0;

tin main()
{
	scanf("%d",&num);
	fora(i,1,num)
	{
		scanf("%d",&x);
		if(x>num)
		{
			++sum;
		}
		else
		{
			++n[x];
		}
	}
	//
	fora(i,1,num)
	{
		if(n[i]<i)
		{
			sum+=n[i];
		}
		else if(n[i]>i)
		{
			sum+=n[i]-i;
		}
	}
	//
	printf("%d\n",sum);
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  vector<int> A(N); cin >> A;
  map<int, ll> m;
  rep(i, N) m[A[i]]++;
  ll total = 0;
  for (auto e: m) {
    total += e.second * (e.second - 1) / 2;
  }
  rep(i, N) {
    cout << total - (m[A[i]] - 1) << "\n";
  }
}


Measured memory_bytes: 10240
N = int(input())
# 先頭が i でお尻が j の数がN以内にいくつあるか
lst = [[0 for _ in range(10)] for _ in range(10)]

def f(a):
	now = str(i)
	top = int(now[0])
	bottom = int(now[-1])
	return top, bottom

for i in range(1, N + 1):
	top, bottom = f(i)
	lst[top][bottom] += 1

ans = 0

for i in range(10):
	for j in range(10):
		ans += lst[i][j] * lst[j][i]
	
# print(lst)
print(ans)

Measured memory_bytes: 40556
#include <bits/stdc++.h>
#define fto(i, x, y) for (int i=(x); i <= (y); ++i)
#define fdto(i, x, y) for (int i=(x); i >= (y); --i)
#define forit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define forrit(it, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)
#define pb push_back
#define mp make_pair
#define ii pair<int, int>
#define vi vector<int>
#define fi first
#define se second
#define ll long long
#define oo 1000000007
#define maxN 100005

const double pi = acos(-1);

using namespace std;

int a, c;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> a >> c;
    cout << 2*c-a;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int finv[200005],f[200005],inv[200005],mod=998244353;
int POW(int x,int y){
	if(!y)RE 1;
	int t=POW(x,y/2);t=t*t%mod;
	if(y&1){
		RE t*x%mod;
	}else RE t;
}
int bl(int x,int y){
	x=x+y;
	RE f[x-1]*finv[y-1]%mod*finv[x-y]%mod;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,k;
	inv[1]=1;
	f[0]=f[1]=1;
	finv[0]=finv[1]=1;
	FOR(i,2,200000){
		inv[i]=mod-inv[mod%i]*(mod/i)%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
		f[i]=f[i-1]*i%mod;
	}
	cin>>n>>m>>k;
	int sum=0,t;
	FOR(i,0,k){
		t=POW(m-1,n-i-1)*m%mod;
		t=t*bl(i,n-i)%mod;
		sum=(sum+t)%mod;
	}
	cout<<sum;
	RE 0;
}




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

using namespace std;

int main(){
    int n; cin >> n;
    long long t, a; cin >> t >> a;
    for(int i=1; i<n; ++i){
        long long ti, ai; cin >> ti >> ai;
        for(long long j=max(t/ti, a/ai); ; ++j){
            if(j*ti>=t && j*ai>=a){
                t=j*ti;
                a=j*ai;
                break;
            }
        }
    }
    cout << t+a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

int main(){
    int a,b,c;
    cin >>a>>b>>c;
    if (a==b) cout <<c<<endl;
    if (a==c) cout <<b<<endl;
    if (c==b) cout <<a<<endl;
    
}

Measured memory_bytes: 256
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static int p[1 << 20];
    static int q[1 << 20];
    int n;
    fi>>n;
    for (int i = 1;i <= n;++i)
        fi>>p[i],q[p[i]] = i;
    set < int > S;
    S.insert(0);
    S.insert(n+1);
    ll ans = 0;
    for (int i = 1;i <= n;++i)
    {
        auto B = S.lower_bound(q[i]);
        auto A = B;--A;
        ans += 1ll * i * (*B - q[i]) * (q[i] - *A);
        S.insert(q[i]);
    }
    fo << ans << '\n';
    return 0;
}

Measured memory_bytes: 11136
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] d = new int[nx[0]+1];
            d[0] = 0;
            for (int i = 1; i < nx[0]+1; i++)
            {
                d[i] = d[i - 1] + l[i - 1];
            }
            int res = 0;
            for (int i = 0; i < d.Length; i++)
            {
                if (d[i] <= nx[1]) res++;
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int n, k;
    cin >> n >> k;
    int arr[n + 5];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    int ans = 1e9 + 5;
    for(int i = 0; i <= n - k; i++)
        ans = min(ans, arr[i + k - 1] - arr[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 100005
int N, A[MXN], M;

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

    cin>>N;
    FOR(i,1,N)cin>>A[i];
    sort( A+1, A+1+N );
    if( A[1] == A[N] )
    {
        M = A[1];
        if( M+1==N )//M+1 kinds
        {
            cout<<"Yes\n";
            return 0;
        }
        if( N/M >= 2 )
        {
            cout<<"Yes\n";
            return 0;
        }
        else cout<<"No\n";
    }
    else if( A[1]+1 == A[N] )
    {
        M = A[1];
        int P=0,K=0;
        FOR(i,1,N)
        {
            if( A[i]==M )P++;
            else break;
        }
        K=N-P;
        //cout<<P<<' '<<K<<' '<<M+1<<'\n';
        if( (M+1-P)>=1 && K>=2*(M+1-P) )
        {
            cout<<"Yes\n";
        }
        else cout<<"No\n";
    }
    else
    {
        cout<<"No"<<'\n';
    }

    return 0;
}


Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CWalkingTakahashi {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int X, K, D;
        cin >> X >> K >> D;
        X = abs(X);
        int num = X / D;
        if (num > K) {
            cout << X - K * D << endl;
            return;
        }

        K -= num;
        int res = X - D * num;
        if (K % 2 == 0) {
            cout << res << endl;
        } else {
            cout << abs(D - res) << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CWalkingTakahashi solver;
    solver.solve(in, out);
    return 0;
}


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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N, M; cin >> N >> M;
  vector<vector<int>> nbr(N);
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b; a--; b--;
    nbr.at(a).push_back(b);
    nbr.at(b).push_back(a);
  }
  vector<bool> onPath(N);
  int x = 0;
  int y = nbr.at(x).at(0);
  onPath.at(x) = onPath.at(y) = true;

  auto sch = [&](int p, int n, auto& vec) {
    auto sub = [&](int t) -> int {
      for (int m : nbr.at(t)) {
	if (m == p) continue;
	if (onPath.at(m)) continue;
	return m;
      }
      return -1;
    };
    vec.push_back(n);
    while (true) {
      int m = sub(n);
      if (m == -1) return;
      vec.push_back(m);
      onPath.at(m) = true;
      p = n;
      n = m;
    }
  };

  vector<int> pXY, pYX;
  sch(x, y, pXY);
  sch(y, x, pYX);
  cout << pXY.size() + pYX.size() << endl;
  for (int i = pYX.size() - 1; i >= 0; i--) {
    cout << pYX.at(i) + 1;
    if (i > 0) cout << " ";
  }
  cout << " ";
  for (int i = 0; i < (int)pXY.size(); i++) {
    cout << pXY.at(i) + 1;
    if (i < (int)pXY.size() - 1) cout << " ";
  }
  cout << endl;

  return 0;
}



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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int x;//maximum
  if (max(a, b) <= c){
    x = c;
  }
  else {
    if (a >= max(b, c)){
      x = a;
    }
    else {
      x = b;
    }
  }
  int y = x;
  for (int i = 0; i < k; i++){
    y *= 2;
  }
  cout << a + b + c + y - x << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long ans = 0;
		boolean flg = false;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		if (a[0] != 0) flg = true;
		for(int r = n - 1; r > 0; r--) {
			if(a[r] - a[r-1] > 1) {
				flg = true;
				break;
			}
			if(a[r] != 0) {
				if(a[r] <= a[r-1]) {
					ans += a[r];
				}else {
					ans++;
				}
			}
			
		}
		if(flg) {
			System.out.println(-1);
		}else {
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 88392
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	vector<double> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	double ans = v[0];
	for (int i = 0; i < n-1; i++) {
		ans += v[i+1];
		ans = ans *0.5;
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define mk make_pair
#define pb push_back


using namespace std;


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

   int N; cin >> N;
   int types = 0;
   set<string> kinds;
   while(N--){
      string s; cin >> s;
      kinds.insert(s);
   }
   
   cout << kinds.size();
   
   return 0;
}


Measured memory_bytes: 19196
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] mae = new int[m];
    int[] rank = new int[n];
    TreeMap<Integer,TreeMap<Integer,Integer>> map = new TreeMap<Integer,TreeMap<Integer,Integer>>();
    String[] ans = new String[m];
    for(int i = 0; i < m; i++){
      int p = sc.nextInt();
      int y = sc.nextInt();
      mae[i] = p;
      if(!map.containsKey(p)){
        map.put(p,new TreeMap<Integer,Integer>());
      }
      map.get(p).put(y,i);
    }
    for(int i = 1; i <= n; i++){
      if(map.containsKey(i)){
        Iterator<Integer> it = map.get(i).keySet().iterator();
        while(it.hasNext()){
          int key = it.next();
          ans[map.get(i).get(key)] = String.format("%06d%06d",mae[map.get(i).get(key)],++rank[i-1]);
        }
      }
    }
    for(String s : ans){
      System.out.println(s);
    }
  }
}


Measured memory_bytes: 186388
using System;

class A
{
    static void Main()
    {
        int K = int.Parse(Console.ReadLine());
        int[] P = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int A = P[0];
        int B = P[1];
        int C = B / K;
        if (C * K <= B && C * K >= A) Console.WriteLine("OK");
        else Console.WriteLine("NG");
    }
}

Measured memory_bytes: 17900
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


int main() {
    cin>>N;
    vec a(N),dr(N,0),r(N,0);
    ll sum = 0;
    rep(i,N) {
        cin>>a[i];
        sum += a[i];
    }
    ll d=0, dsum = 0;
    rep(i,N-1){
        d += (a[(2*i + 1)%N] - a[2*i % N])*2;
        dr[(2*i + 2) % N] = d;
        dsum += d;
    }
    r[0] = (sum - dsum) / N;
    reps(i,1,N){
        r[i] = r[0] + dr[i];
    }
    rep(i,N) {
        cout<<r[i];
        if(i != N-1) cout<<' ';
        else cout<<endl;
    }
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

	static int n,r,p,c;
	static int[] card;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			n=cin.nextInt();
			r=cin.nextInt();
			if(n+r==0){
				break;
			}
			card=new int[n];
			for(int i = 0;i<n;i++){
				card[i]=i+1;
			}
			for(int i = 0;i<r;i++){
				p=cin.nextInt();
				c=cin.nextInt();
				shuffle();
			}
			System.out.println(card[n-1]);
		}
	}
	static void shuffle(){
		int[] tmp = new int[c];
		for(int i = 0;i<c;i++){
			tmp[i]=card[i+n-c-p+1];
		}
		for(int i = 0;i<p-1;i++){
			card[i+n-c-p+1]=card[i+n-p+1];
			out();
		}
		for(int i = 0;i<c;i++){
			card[i+n-c]=tmp[i];
		}
		out();
	}
	static void out(){
		for(int i = 0;i<n;i++){
			//System.out.println(card[i]);
		}
		//System.out.println();
	}
}

Measured memory_bytes: 12000
#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>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}

int main() {
  int n,x,y;cin>>n>>x>>y;
  vector<int> ans(n);
  FOR(i,1,n){
    FOR(j,1+i,n){
        ans.at(min(j-i,abs(x-i)+abs(j-y)+1))++;
    }
  }
  rep(i,n-1){
    cout<<ans.at(i+1)<<endl;
  }
}
    

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

int main()
{
  long long int n;
  cin>>n;
  long long int mi = (long long int)(1e13);
  for(int i=1;i<=sqrt(n);i++)
  {
    long long int curr = n/i;
    if(curr*i == n)
      mi = min(mi,curr + i);
  }
  mi -= 2;
  cout<<mi;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int count = 0;
  for (int i = 0; i < S.size(); i++){
    if (S[i] == 'x'){
      count++;
    }
  }
  cout << (count < 8 ? "YES" : "NO");
}

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

struct Data{
	int child_num = 0;
	double child_sum = 0.0;
	double ans = 0.0;
};

template <typename T,typename F0,typename F1>
struct rerooting{
	F0 func0;
	F1 func1;
	T init_value;
	
	vector<T> v;
	vector<bool> visited;
	
	rerooting(vector<vector<int>> &E,F0 f0,F1 f1,T iv):func0(f0),func1(f1){
		init_value = iv;
		v.resize(E.size());
		visited.resize(E.size(),false);
		for(int i=0;i<E.size();i++){
			if(visited[i])continue;
			dfs(E,i,-1);
			redfs(E,i,-1,init_value);
		}
	}
	
	void dfs(vector<vector<int>> &E,int now,int p){
		v[now] = init_value;
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to==p)continue;
			dfs(E,to,now);
			v[now] = func0(v[now],v[to]);
		}
		v[now] = func1(v[now]);
		visited[now]=true;
	}
	
	void redfs(vector<vector<int>> &E,int now,int p,T pv){
		vector<T> P(E[now].size()+1,init_value),S(E[now].size()+1,init_value);
		rep(i,E[now].size()){
			int to = E[now][i];
			if(to!=p)P[i+1] = func0(P[i],v[to]);
			else P[i+1] = func0(P[i],pv);
		}
		rep(i,E[now].size()){
			int to = E[now][E[now].size()-1-i];
			if(to!=p)S[i+1] = func0(v[to],S[i]);
			else S[i+1] = func0(pv,S[i]);
		}
		v[now] = func1(P.back());

		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to!=p){
				redfs(E,to,now,func1(func0(P[i],S[E[now].size()-1-i])));
			}
		}
	}
	
};


int main(){
	
	int N;
	cin>>N;
	
	vector<vector<int>> E(N,vector<int>());
	rep(i,N-1){
		int u,v;
		scanf("%d %d",&u,&v);
		u--;v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	
	auto f0 = [](Data a,Data b){
		a.child_num += b.child_num;
		a.child_sum += b.child_sum;
		return a;
	};
	
	auto f1 = [](Data a){
		if(a.child_num==0)a.ans = 0.0;
		else a.ans = a.child_sum / a.child_num + 1.0;
		a.child_sum = a.ans;
		a.child_num = 1;
		return a;
	};
	
	rerooting<Data,decltype(f0),decltype(f1)> rr(E,f0,f1,Data());
	
	rep(i,N){
		cout<<fixed<<setprecision(10)<<rr.v[i].ans<<'\n';
	}
	
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 100005
#define MOD 1000
#define oo 1000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, root, color[maxN], dp[2][maxN], maxPath, ans;
bool marked[maxN];
vector<int> g[maxN];
char s[maxN];

void DFS1(int u, int p) {
    marked[u] = (color[u] == 0);
    for(int v: g[u]) {
        if (v == p) continue;
        DFS1(v, u);
        marked[u] |= marked[v];
    }
}

void Solve(int u, int p) {
    int x = (color[u] == 0) ? 2 : 0;
    for(int v: g[u]) {
        if (!marked[v] || v == p) continue;
        ans += 2;
        Solve(v, u);
        if (dp[0][v]+x > dp[0][u]) {
            dp[1][u] = dp[0][u];
            dp[0][u] = dp[0][v]+x;
        } else if (dp[0][v]+x > dp[1][u]) {
            dp[1][u] = dp[0][v]+x;
        }
    }

    maxPath = max(maxPath, dp[0][u] + dp[1][u] - x);

}

int main () {
    scanf("%d", &n);
    fto(i, 1, n-1) {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].pb(v); g[v].pb(u);
    }
    scanf("%s", s);
    fto(u, 1, n) color[u] = (s[u-1] == 'B');

    fto(u, 1, n) {
        if (color[u] == 0) {root = u; break;}
    }

    if (root == 0) {
        puts("0");
        return 0;
    }

    DFS1(root, -1);

    fto(u, 1, n) {
        if (marked[u]) {
            for(int v: g[u])
                if (marked[v]) color[u] ^= 1;
            ans += (color[u] == 0);
        }
    }

    Solve(root, -1);

    ans -= maxPath;
    printf("%d", ans);


    return 0;
}


Measured memory_bytes: 14080
//AOJ斐波拉契数列问题
#include <iostream>
using namespace std;

int dp[45];//根据题目里给定限制 

int main(){
	
	int n;
	cin>>n;
	dp[1]=1;
	dp[2]=2;	
	for(int i=3;i<=n;i++){
		dp[i]=dp[i-1]+dp[i-2];
	}
	cout<<dp[n]<<endl;
	
	return 0;
} 


Measured memory_bytes: 3116
W,H,N = map(int, raw_input().split())
ans = 0
pX,pY = map(int, raw_input().split())
for _ in range(N-1):
    X,Y = map(int, raw_input().split())
    ans += abs(X-pX)+abs(Y-pY)
    if X-pX>0 and Y-pY>0 or X-pX<0 and Y-pY<0:
        ans -= min(abs(X-pX), abs(Y-pY))
    pX,pY = X,Y
print ans

Measured memory_bytes: 6384
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  string S;

  cin >> S;

  int len_S = S.size();

  int count = 0;

  rep(i, len_S) {
    if (S[i] == '+')
      count++;
    else
      count--;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256