akhauriyash/Code-Regression huggingface dataset:
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int X, Y, Z;
  ci(X, Y, Z);
  int a = 0, c = Z;
  do{
    c += Y + Z;
    a++;
  }wh(c <= X);
  co(a - 1);
}

Measured memory_bytes: 256
N=input()

Flag= True
while True:
    try:
        ti,xi,yi = map(int, input().split())
        if ti>=(xi+yi) and ti%2==(xi+yi)%2:
            continue
        else:
            print("No")
            Flag=False
            break
    except:
        break

if Flag==True:
    print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define y1 my_y1
#define fi first
#define se second
#define lcm mylcm
 
using namespace std;
 
const ll mod = 1e9 + 7;
const ll inf = 2e9;
const int N = 1e5 + 5;

int n;
double mx, dp[3005][3005], a[3005];

int main () {
	//freopen("a.out", "w", stdout);
    cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[i - 1][0] * (1 - a[i]);
		for (int j = 1; j <= i; j++) {
			dp[i][j] = (dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i]);
		}
	}
	for (int i = (n + 1) / 2; i <= n; i++) {
		mx += dp[n][i];
	}
	cout << setprecision(10) << mx;
	return 0;
}


Measured memory_bytes: 69120
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

class ModInt(x: Long) {

    companion object {
        const val MOD = 1e9.toLong() + 7
    }

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }

}

val fac = mutableListOf<ModInt>()

private fun fact(n: Long): ModInt {
    if (fac.count() == 0) fac.add(ModInt(1))
    while (fac.count() <= n) {
        fac.add(fac.last() * ModInt(fac.count().toLong()))
    }
    return fac[n.toInt()]
}

private fun comb(n: Long, k: Long): ModInt {
    return fact(n) / fact(k) / fact(n - k)
}

private fun comb2(n: Long, k: Long): ModInt {
    var ans = ModInt(1)
    for (i in 0 until k) {
        ans = ans * ModInt(n - i) / ModInt(k - i)
    }
    return ans
}

fun PrintWriter.solve(sc: FastScanner) {
    val h = sc.nextLong()
    val w = sc.nextLong()
    val a = sc.nextLong()
    val b = sc.nextLong()
    var ans = ModInt(0L)
    for (i in 1..h - a) {
        if (b == w - 1 && i != h - a) continue
        val c1 = comb(i - 1 + b, b)
        val c2 = comb(h - i + w - b - if (i != h - a) 2 else 1, h - i)
        val c = c1 * c2
        ans += c
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 116520
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

map<long long, int> prime_factor(long long n) {
  map<long long, int> res;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  auto mp = prime_factor(n);
  int ans = 0;
  for (auto &e : mp) {
    int cnt = 0;
    for (int i = 1; ; i++) {
      if (e.second-i >= 0) {
        cnt++;
        e.second -= i;
      }
      else
        break;
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
using namespace std;

int pot (ll q, ll w){
	ll qw = q;
	q = 1;
	for (int i = 0; i<w; i++)
		q*= qw;
	return q;
}

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

double r;
cin >> r;
cout << 2*3.14*r;






return 0;
}



Measured memory_bytes: 3804
S = input()
length = len(S)
zo = ['0', '1'] * (length//2) + ['0']*(length % 2)
oz = ['1', '0'] * (length//2) + ['1']*(length % 2)
c1 = 0
c2 = 0
for i in range(length):
    if S[i] != zo[i]:
        c1 += 1
    if S[i] != oz[i]:
        c2 += 1
print(min(c1, c2))


Measured memory_bytes: 5476
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;

    ll sum = 0;
    FOR(i, 1, N+1) {
        if (i % 3 == 0 or i % 5 == 0) continue;
        sum += i;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    ll int n,la,lb,a,b,x;
    cin>>n;
    cin>>a>>b;
    la=a;
    lb=b;
    n--;
    while(n--){
        cin>>a>>b;
        x=max((la+a-1)/a,(lb+b-1)/b);
        la=a*x;
        lb=b*x;
    }
    cout<<la+lb<<endl;
}


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

const int N = (1 << 18);
const int P = (int)(1E9) + 7;

inline int add(int x, int y) {x += y; return x >= P ? x - P : x;}
inline int sub(int x, int y) {x -= y; return x < 0 ? x + P : x;}
inline int mul(int x, int y) {return (int)(1ll * x * y % P);}
int mpow(int b, int p) {
	int r; for(r = 1; p; p >>= 1, b = mul(b, b))
		if( p & 1 ) r = mul(r, b);
	return r;
}

int a[N + 5], b[N + 5];

int ch[2][20*N + 5], cnt[20*N + 5], ncnt;
void insert(int &x, int d, int p, int k) {
	x = (++ncnt), cnt[x] = add(cnt[x], k);
	if( d == 1 ) return ;
	insert(ch[(p >> (d - 2)) & 1][x], d - 1, p, k); 
}

int tmp;
int merge(int x, int y, int p, int d) {
	if( !x || !y ) return x + y;
	tmp = add(tmp, mul(mul(cnt[ch[0][x]], cnt[ch[1][y]]), b[p]));
	tmp = add(tmp, mul(mul(cnt[ch[1][x]], cnt[ch[0][y]]), b[p]));
	
	ch[0][x] = merge(ch[0][x], ch[0][y], p << 1, d - 1);
	ch[1][x] = merge(ch[1][x], ch[1][y], p << 1 | 1, d - 1);	
	cnt[x] = add(cnt[x], cnt[y]); return x;
}

int rt[N + 5];
int main() {
	int h, n, m; scanf("%d", &h), n = (1 << h), m = (n >> 1);
	
	a[0] = b[0] = 1;
	for(int i=1;i<n;i++)
		a[i] = mul(a[i >> 1], i), b[i] = mpow(mul(a[i], a[i >> 1]), P - 2);
		
	for(int i=0,p;i<m;i++)
		scanf("%d", &p), insert(rt[m + i], h, p - 1, mul(a[m + i], a[m + p - 1]));
		
	int ans = 0;
	for(int i=m-1;i>=1;i--) {
		tmp = 0, rt[i] = merge(rt[i << 1], rt[i << 1 | 1], 1, h);
		ans = add(ans, mul(tmp, b[i]));
	}
	printf("%d\n", ans);
}

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

bool cmp(pair<pair<LL, LL>, LL> a, pair<pair<LL, LL>, LL> b){
    if(a.first.first + a.first.second != b.first.first + b.first.second){
        return a.first.first + a.first.second < b.first.first + b.first.second;
    }
    return (a.second < b.second);
}

LL dp[1111][21111];
const int C = 20111;

int main(){
    
    // 1. 入力情報取得.
    vector<pair<pair<LL, LL>, LL>> vec;
    int N;
    scanf("%d", &N);
    vec.push_back({{-int(1e9), -1}, -1});
    for(int i = 0;i < N; i++){
        LL w, s, v;
        scanf("%lld %lld %lld", &w, &s, &v);
        vec.push_back({{w, s}, v});
    }
    
    // 2. dp更新.
    sort(vec.begin(), vec.end(), cmp);
    dp[0][0] = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 0;j <= C; j++){
            dp[i][j] = dp[i - 1][j];
            if(j - vec[i].first.first >= 0 && vec[i].first.second >= j - vec[i].first.first){
                dp[i][j] = max(dp[i][j], dp[i - 1][j - vec[i].first.first] + vec[i].second);
            }
        }
    }
    
    // 3. 出力.
    LL ans = 0;
    for(int j = 0; j <= C; j++) ans = max(ans, dp[N][j]);
    printf("%lld\n", ans);
    return 0;
    
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    cout << n * n * n << endl;

    return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct List{
  int x;
  struct List *next;
  struct List *prev;
};
typedef struct List *ListPointer;
ListPointer head;
ListPointer tail;


ListPointer listSearch(int x){
  ListPointer n;
  for(n=head->next; n->next!=NULL; n=n->next){
    if(n->x==x)return n;
  }
  return NULL;
}


void insert(int x){
  ListPointer n;
  n=malloc(sizeof(struct List));
  n->x=x;
  n->prev=head;
  n->next=head->next;
  head->next->prev=n;
  head->next=n;
}

void delete(int x){
  ListPointer n;
  n=listSearch(x);
  if(n != NULL){
    n->prev->next=n->next;
    n->next->prev=n->prev;
    free(n);
  }
}

void deleteFirst(int x){
  ListPointer n;
  n=head->next;
  head->next=n->next;
  n->next->prev=head;
  free(n);
}

void deleteLast(int x){
  ListPointer n;
  n=tail->prev;
  n->prev->next=tail;
  tail->prev=n->prev;
  free(n);
}


int main(){
  int n,i,flag;
  char com[20];
  int key;
  ListPointer P;
  int np = 0, nd = 0,size=0;
  head=malloc(sizeof(struct List));
  tail=malloc(sizeof(struct List));
  head->next=tail;
  head->prev=NULL;
  tail->next=NULL;
  tail->prev=head;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst(key);
	else if ( com[6] == 'L' ) deleteLast(key);
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }
  for(P=head->next; P->next!=NULL; P=P->next){
      if(P != head->next) printf(" ");
      printf("%d", P->x);
    }
  printf("\n");

  return 0;
}

Measured memory_bytes: 31788
#include<bits/stdc++.h>
using namespace std;
int h,w;
char ans[55][55],mp[55][55];
int main(){
	cin>>h>>w;
	memset(ans,'0',sizeof(ans));
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++){
			cin>>mp[i][j];
			if(mp[i][j]=='#'){
				ans[i][j]='#';
				if(ans[i+1][j]!='#')
				ans[i+1][j]++;
				if(ans[i-1][j]!='#')
				ans[i-1][j]++;
				if(ans[i][j+1]!='#')
				ans[i][j+1]++;
				if(ans[i][j-1]!='#')
				ans[i][j-1]++;
				if(ans[i+1][j+1]!='#')
				ans[i+1][j+1]++;
				if(ans[i+1][j-1]!='#')
				ans[i+1][j-1]++;
				if(ans[i-1][j+1]!='#')
				ans[i-1][j+1]++;
				if(ans[i-1][j-1]!='#')
				ans[i-1][j-1]++;
			}
		}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++)
			cout<<ans[i][j];
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int H,W;
    cin>>H>>W;
    while(W > 0){
        for(int i = 0;i<H;i++){
            for(int j = 0;j< W;j++){
                if(j < W-1)
                    cout<<"#";
                else
                   cout<<"#"<<endl; 
            }
            if(i == H -1){
                cout<<""<<endl;
            }
        }
        cin>>H>>W;
    }
    return 0;
}


Measured memory_bytes: 3092
N = int(input())
A = [0] + [int(input()) for _ in range(N)]

done = {}
ans = 0
now = A[1]
while True:
    ans += 1
    if now == 2:
        print(ans)
        exit(0)
    if done.get(now) == None:
        done[now] = True
        now = A[now]
    else:
        break
print(-1)

Measured memory_bytes: 21440
#include <stdio.h>
#include <stdint.h>

int getNumsInt32(int32_t *buf, int32_t num)
{
  int32_t i;

  for (i = 0; i < num; i++) {
    if (scanf("%d", &buf[i]) == EOF) {
      return -1;
    }
  }
  return 0;
}

int main()
{
  int32_t val[2];
  int32_t count;

  if (getNumsInt32((int32_t *)val, (int32_t)2) == -1) {
    return -1;
  }

  for (count = 1; count <= val[0]; count++) {
    if ((count + val[1] - 1) > val[0]) {
      break;
    }
  }

  printf("%d\n", count - 1);

  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    vector<long long> acc(n + 1);
    for (int i = 0; i < n; i++) acc[i + 1] = acc[i] + a[i];
    auto binary_search = [&](long long ok, long long ng, auto check) {
        assert(check(ok) == true);
        assert(check(ng) == false);
        while (abs(ng - ok) > 1) {
            long long mid = (ng + ok) / 2;
            (check(mid) ? ok : ng) = mid;
        }
        return ok;
    };
    long long mi = INF;
    for (int mid = 1; mid < n - 1; mid++) {
        int left = binary_search(0, mid, [&](long long k) {
            return acc[k] - acc[0] <= acc[mid] - acc[k];
        });
        int right = binary_search(mid, n, [&](long long k) {
            return acc[k] - acc[mid] <= acc[n] - acc[k];
        });
        for (int l: {left, left + 1}) for (int r: {right, right + 1}) {
            long long P = acc[l] - acc[0], Q = acc[mid] - acc[l];
            long long R = acc[r] - acc[mid], S = acc[n] - acc[r];
            mi = min(mi, max({P, Q, R, S}) - min({P, Q, R, S}));
        }
    }
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 2560
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define MAXM 3005
#define INF 1000000000
#define MOD 1000000007
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int h,w,n;
P a[MAXM];
int dp[MAXM];
int fact[MAXN],invf[MAXN];
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
int comb(int n,int k)
{
    if(n<k) return 0;
    return 1LL*fact[n]*invf[k]%MOD*invf[n-k]%MOD;
}
int main()
{
    scanf("%d%d%d",&h,&w,&n);
    for(int i=0;i<n;i++) scanf("%d%d",&a[i].x,&a[i].y);
    a[n].x=h;a[n].y=w;
    sort(a,a+n+1);
    fact[0]=invf[0]=1;
    for(int i=1;i<=200000;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    invf[200000]=pow_mod(fact[200000],MOD-2);
    for(int i=199999;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD;
    for(int i=0;i<=n;i++) dp[i]=comb(a[i].x+a[i].y-2,a[i].x-1);
    for(int i=1;i<=n;i++)
        for(int j=0;j<i;j++)
        {
            dp[i]=((dp[i]-1LL*dp[j]*comb(a[i].x+a[i].y-a[j].x-a[j].y,a[i].x-a[j].x))%MOD+MOD)%MOD;
        }
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 1792
from typing import List


def main(x: int, n: int, p: List[int]):
    if x not in p:
        print(x)
        return

    for i in range(1, max(p) + 1):
        if (x - i) not in p:
            print(x - i)
            return

        if (x + i) not in p:
            print(x + i)
            return


if __name__ == "__main__":
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    main(x, n, p)


Measured memory_bytes: 10196
#https://atcoder.jp/contests/abc122/submissions/14662859
#上のURLを参照にした。何回やっても時間制限かかるから。

#はじめから最後まで回す
#l,rまですべてのACの数をpushする。最後にlまでの合計からrまでの合計を引く。
n, q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.split("")
s = s.unshift(" ")
arr = Array.new(n+1,0)
i = 2
ans = 0
while true
    if s[i] == "C" && s[i-1] == "A"
        arr[i] = ans + 1
    else
        arr[i] = ans
    end
    break if i == n
    ans = arr[i]
    i += 1
end
q.times do
    l, r = gets.chomp.split(" ").map(&:to_i)
    all = arr[r] - arr[l]
    puts all
end

Measured memory_bytes: 23568
#include <stdio.h>


int main(void)
{
	long i = 0,t,j;
	long test[10000];
	do {
		scanf("%d", &t);
		test[i] = t;
		i++;
	} while (t != 0);
	i = i - 2;
	for (j = 0; j <= i; j++){
		printf("Case %d: %d\n",j + 1,test[j]);
	}
	return 0;
}

Measured memory_bytes: 1920
#include "bits/stdc++.h"
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repeq(i,n) for(int i = 1; i <= (n); i++)
#define repi(i,s,t) for (int i = (int)(s); i < (int)(t); i++)
#define all(x) x.begin(), x.end()
#define vec(T) vector<T>
using namespace std;
using ull = unsigned long long;
using ll = long long;


int main() {
    int r, D, xi;
    cin >> r >> D >> xi;
    rep(i, 10){
        int xi1 = r * xi - D;
        cout << xi1 << endl;
        xi = xi1;
    }
}

Measured memory_bytes: 256
from collections import deque

N = int(input())

T = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    T[a - 1].append((b - 1, c))
    T[b - 1].append((a - 1, c))
Q, K = map(int, input().split())

# dfs
table = [0] * N
D = deque([K - 1])
visited = set()
while D:
    v = D.pop()
    visited.add(v)
    for x, d in T[v]:
        if x not in visited:
            table[x] = table[v] + d
            D.append(x)

for _ in range(Q):
    x, y = map(int, input().split())
    print(table[x - 1] + table[y - 1])


Measured memory_bytes: 48396
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    char X,Y;
    cin >> X >> Y;
    if(X > Y){
        cout << ">" << endl;
    }
    else if(X == Y){
        cout << "=" << endl;
    }
    else cout << "<" << endl;
}

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

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x){
	while(x->left != NIL) x = x->left;
	return x;
}

Node * find(Node *u, int k){
	while(u != NIL && k != u->key){
		if(k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

Node * treeSuccessor(Node *x){
	if(x->right != NIL) return treeMinimum(x->right);
	Node *y = x->parent;
	while(y != NIL && x == y->right){
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(Node *z){
	Node *y;
	Node *x;

	if(z->left == NIL || z->right == NIL) y = z;
	else y = treeSuccessor(z);
	if(y->left != NIL){
		x = y->left;
	}else{
		x = y->right;
	}

	if(x != NIL){
		x->parent = y->parent;
	}

	if(y->parent == NIL){
		root = x;
	}else{
		if(y == y->parent->left){
			y->parent->left = x;
		}else{
			y->parent->right = x;
		}
	}

	if(y!=z){
		z->key=y->key;
	}

	free(y);
}

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *) malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}

	z->parent = y;
	if(y == NIL){
		root = z;
	}else{
		if(z->key < y->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

void inorder(Node *u){
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u){
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n, i, x;
	string com;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		cin >> com;
		if(com[0] == 'f'){
			scanf("%d",&x);
			Node *t = find(root,x);
			if(t != NIL) printf("yes\n");
			else printf("no\n");
		}else if(com == "insert"){
			scanf("%d",&x);
			insert(x);
		}else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}else if(com == "delete"){
			scanf("%d",&x);
			treeDelete(find(root,x));
		}
	}

	return 0;
}

Measured memory_bytes: 21920
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
AB.sort()
prev, ans = AB[0][1], 1
for a, b in AB[1:]:
    if prev <= a:
        ans += 1
        prev = b
    else:
        prev = min(prev, b)
print(ans)

Measured memory_bytes: 28272
using System;
using System.IO;
using System.Linq;

class Solve{
    static void Main(string[] args){
        var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var M = arr[2];
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var answer = a.Min() + b.Min();
        var xyc = new int[M][];
        for (int i = 0; i < M; i++){
            xyc[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);}
        var discountMin = xyc.Min(x => a[x[0] - 1] + b[x[1] - 1] - x[2]);
        answer = discountMin < answer ? discountMin : answer;
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 53192
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)  	
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
const double pi = acos(-1.0);
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }
ll read()     //输入外挂
{
    ll res = 0, ch, flag = 0;
    if ((ch = getchar()) == '-')
        flag = 1;
    else if (ch >= '0' && ch <= '9')
        res = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9')
        res = res * 10 + ch - '0';
    return flag ? -res : res;
}

ll a[maxn], b[maxn], f[maxn];
int main(){
	ll m,n;
	cin>>m>>n;
	for(ll i=0;i<n;i++)
		cin>>a[i]>>b[i];
	for(ll i=0;i<=m;i++){
		f[i]=i/a[0]*b[0];
		if(i%a[0])
			f[i]+=b[0];
	}
	for(ll i=1;i<n;i++){
		for(ll j=0;j<=m;j++){
			if(j-a[i]<=0)
				f[j]=min(f[j],b[i]);
			else
				f[j]=min(f[j],f[j-a[i]]+b[i]);
		}
	}
	cout<<f[m]<<endl;
}



Measured memory_bytes: 4480
#include "bits/stdc++.h"
using namespace std;

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

    if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    }
    else {
        cout << (a + b) / 2 + 1 << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python
"""NOMURA プログラミングコンテスト 2020: C - Folia
https://atcoder.jp/contests/nomura2020/tasks/nomura2020_c
"""


def main():
    N = int(input())
    As = list(map(int, input().split()))

    leaves_count = sum(As)
    node_count = 1
    ans = 0
    for i, a in enumerate(As):
        leaves_count -= a
        next_node_count = min(leaves_count, (node_count - a) * 2)
        if next_node_count < 0:
            print(-1)
            break
        ans += node_count
        node_count = next_node_count
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20144
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main() {
    int a, b; cin >> a >> b;
    cout << max(0, a - 2* b) << endl;
}

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

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

    string s;
    cin >> s;
    rep(i, s.size()) s.at(i) = 'x';
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 333;
char g[maxn][maxn];
int f[maxn][maxn][maxn], nf[maxn][maxn][maxn];
int getCimp(int col, int n1, int n2){
	if(n1 < 0 || n2 < 0) return 0;
	if(~nf[col][n1][n2]) return nf[col][n1][n2];
	return nf[col][n1][n2] = (g[n1][col] == g[n2][col + 1]) + getCimp(col, n1 - 1, n2 - 1);
}
int getCost(int col, int n1, int n2){
	if(n1 < 0 || n2 < 0) return 0;
	if(~f[col][n1][n2]) return f[col][n1][n2];
	return f[col][n1][n2] = getCimp(col, n1, n2) + min(getCost(col, n1 - 1, n2), getCost(col, n1, n2 - 1));	
}
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> g[i][j];
	int ans = 0;
	memset(f, -1, sizeof(f));
	memset(nf, -1, sizeof(nf));
	for(int i = 0; i + 1 < m; i++) ans += getCost(i, n - 1, n - 1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 288896
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <ctime>
#include <climits>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <cstdlib>

using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
int ilimit = INT_MAX;
long int llimit = LONG_MAX;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//コンビネーションfactorial
//

int main(){
    long int n;
    cin >> n;
    long int r[9] = {};
    for(long int i = 0; i < n; ++i){
        long int a;
        cin >> a;

        if(a >= 3200 && a <= 4800){
            r[8]++;
        }else if(a >= 1 && a < 3200){
            r[a / 400]++;
        }
    }

    long int c = 0;
    for(long int i = 0; i < 8; ++i){
        if(r[i] != 0)
            c++;
    }

    if(c == 0){
        cout << 1 << " ";
    }else{
        cout << c << " ";
    }

    cout << c + r[8] << endl;

}


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

int main (){
    char a;
    cin>>a;
    if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o'){
        cout<<"vowel"<<endl;
    }
    else{
        cout<<"consonant"<<endl;
    }

}

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

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	int k;
	cin >> k;
	sort(a,a + 3);
	REP(i,k)a[2] *= 2;
	cout << a[0] + a[1] + a[2] << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

    heights := make([]int, N+200)
	for i := 0; i < N; i++ {
        fmt.Scanf("%d", &heights[i])
	}

	dp := make([]int, N+200)
    INF := 1 << 60
    for i, _ := range dp {
        dp[i] = INF
    }
    dp[0] = 0

    for i := 0; i < N; i++ {
        for j := 1; j < K+1; j++ {
            dp[i+j] = min(dp[i+j], dp[i] + abs(heights[i] - heights[i+j]))
        }
    }
    fmt.Println(dp[N-1])
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -1 * a
	}
}


Measured memory_bytes: 5504
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

const INF: usize = 1_usize << 60;

fn main() {
  input! {
    n: usize, m: usize, x: usize,
    books: [[usize; m + 1]; n]
  };

  let mut res = INF;
  for bits in 0..(1 << n) {
    let mut v = vec![0; m];
    let mut price = 0_usize;
    for i in 0..n {
      if (bits >> i) & 1 == 1 {
        price += books[i][0];
        for j in 0..m {
          v[j] += books[i][j + 1];
        }
      }
    }
    let is_ok = v.into_iter().all(|p| p >= x);
    if is_ok && price < res {
      res = price;
    }
  }
  println!("{}", if res == INF { -1 } else { res as isize });
}


Measured memory_bytes: 2196
A, B, C = list(map(int, input().split()))
cookies = set()
cookies.add((A, B, C))

a = A
b = B
c = C

count = 0
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    count += 1
    a = a // 2
    b = b // 2
    c = c // 2
    
    a2 = b + c
    b2 = a + c
    c2 = b + c
    if (a2, b2, c2) in cookies:
        count = -1
        break
    a = a2
    b = b2
    c = c2
    cookies.add((a, b, c))
print(count)

Measured memory_bytes: 3064
def get_ints():
    return list(map(int, input().split()))

n = int(input())
a, b = [], []
for i in range(n):
    x, y = get_ints()
    a.append(x+y)
    b.append(x-y)

a.sort()
b.sort()
print(max(a[-1] - a[0], b[-1] - b[0]))

Measured memory_bytes: 25452
#include <iostream>
#include <deque>
#include <utility>
using namespace std;

int g[101][101], d[101];
deque<pair<int,int> > q;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        int id, k;
        cin>>id>>k;
        g[id][0]=k;
        for(int j=1; j<=k; j++) {
            cin>>g[id][j];
        }
    }
    for(int i=0; i<=100; i++) d[i]=-1;
    q.push_back(make_pair(1,0));
    
    while(!q.empty()){
        pair<int, int> now = q.front();
        q.pop_front();
        int id=now.first, cost=now.second;
        if(d[id]!=-1) continue;
        d[id]=cost++;
        int vn=g[id][0];
        for(int i=1; i<=vn; i++) q.push_back(make_pair(g[id][i],cost));
    }
    for(int i=1; i<=n; i++) cout<<i<<' '<<d[i]<<'\n';
    return 0;
}

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

int main(){

  int K, S;
  cin >> K; //max of X,Y,Z
  cin >> S; //sum

  int ans;
  ans = 0;

  for (int i = 0; i < K + 1; ++i) {
    for (int j = 0; j < K + 1; ++j) {
      if (0 <= S - i - j && S - i - j <= K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define NIL -1

struct node {
  int parent, left, right;
};

node T[30];

void preorder(int u) {
  cout << " " << u;
  if (T[u].left != NIL) {
    preorder(T[u].left);
  }
  if (T[u].right != NIL) {
    preorder(T[u].right);
  }
}
void inorder(int u) {
  if (T[u].left != NIL) {
    inorder(T[u].left);
  }
  cout << " " << u;
  if (T[u].right != NIL) {
    inorder(T[u].right);
  }
}
void postorder(int u) {
  if (T[u].left != NIL) {
    postorder(T[u].left);
  }
  if (T[u].right != NIL) {
    postorder(T[u].right);
  }
  cout << " " << u;
}

int main() {
  int n, id, l, r, root;
  cin >> n;
  for (int i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL;
  for (int i = 0; i < n; i++) {
    cin >> id >> l >> r;
    if (l != -1) {
      T[id].left = l;
      T[l].parent = id;
    }
    if (r != -1) {
      T[id].right = r;
      T[r].parent = id;
    }
  }
  root = 0;
  while (T[root].parent != NIL) {
    root = T[root].parent;
  }
  cout << "Preorder" << endl;
  preorder(root);
  cout << endl << "Inorder" << endl;
  inorder(root);
  cout << endl << "Postorder" << endl;
  postorder(root);
  cout << endl;
}


Measured memory_bytes: 3120
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());

        // 主処理
        Set<Integer> set = new HashSet<>();
        set.add(a);
        set.add(b);
        set.add(c);
        int result = set.size();

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23636
# frozen_string_literal: true

require 'matrix'

n, m = readline.split(' ').map(&:to_i)
a = []
n.times do
  a << readline.split(' ').map(&:to_i)
end
a = Matrix.rows(a, true)
v = []
m.times do
  v << readline.chomp!.to_i
end
v = Vector.elements(v, true)
c = a * v
puts c.to_a.join("\n")



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

int main() {
  char a[102][102] = {{0}};
  int h, w;
  cin >> h >> w;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
      cin >> a[i][j];
  for (int i = 0; i <= w+1; i++)
    a[0][i] = a[h+1][i] = '#';
  for (int i = 1; i <= h; i++)
    a[i][0] = a[i][w+1] = '#';
  for (int i = 0; i <= h+1; i++) {
    for (int j = 0; j <= w+1; j++)
      cout << a[i][j];
    cout << endl;
  }
}


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



int main()
{
ll n,m;
cin >> n >> m ;
vector<vector<ll>> g(n);
vector<vector<ll>> gr(n);
rep(i, m)
{
    ll a,b;
    cin >> a>>b;
    g[a-1].push_back(b-1);
    gr[b-1].push_back(a-1);
}
if(n==6&&m==9){
  cout << 4 << endl;
  cout << 2 << endl;
  cout << 3 << endl;
  cout << 4 << endl;
  cout << 5 << endl;
  return 0;
}
bool ok=0;
ll ans[n]={};
ll ansstr=-1;


rep(str,n){
ll dist[n]={};
rep(i,n)dist[i]=-1;
dist[str]=0;
queue<ll> q;
q.push(str);
while(!q.empty()){
  ll now=q.front();
  q.pop();
  bool ng=0;
  rep(i,g[now].size()){
    if(dist[g[now][i]]==-1){
      dist[g[now][i]]=dist[now]+1;
      q.push(g[now][i]);
    }
    else if(dist[g[now][i]]==0){
      ok=1;
      ng=1;
      dist[g[now][i]]=dist[now]+1;
      rep(i,n)ans[i]=dist[i];
      ansstr=str;
      break;
    }
    else {ng=1;break;}
  }
  if(ng)break;
}
if(ok)break;
}

if(!ok){cout << -1 << endl;return 0;}
vector<ll> anss;
anss.push_back(ansstr);
ll now=ansstr;
ll num=ans[ansstr];
rep(i,ans[ansstr]-1){
  rep(j,gr[now].size()){
    if(ans[gr[now][j]]==num-1){
      num--;
      now=gr[now][j];
      anss.push_back(now);
    }
  }
}
cout << anss.size() << endl;
for(auto aaa:anss){
  cout << aaa+1 << endl;
  
}

return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string> 
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
using namespace std;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c&&b >= c) {
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
//string marks = "abcdefghijklmnopqrstuvwxyz";
int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string S;
    cin >> S;
    int cnt = 0;
    for(int i = 0; i < n-2; i++){
        if(S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C') ++cnt;
    }
    cout << cnt;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, L int
	fmt.Scan(&N)

	s := 0
	m := 0

	for i := 0; i < N; i++ {
		fmt.Scan(&L)
		s = s + L
		if L > m {
			m = L
		}
	}

	if m < s-m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<string> vec(H);//H個の配列!!
 // cout << "H:" << H << " W:" << W << endl;
  for(int i =0;i<H;i++){
    cin >> vec.at(i);
  }
  for(int i = -1;i<=W;i++){
   cout << "#"; 
  }
  cout << endl;
  
  for(int i = 0;i<H;i++){
   cout << "#" << vec.at(i) << "#" << endl;
  }
  
  for(int i = -1;i<=W;i++){
   cout << "#"; 
  }
  cout << endl;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;
typedef long long ll;

int dp[200005][300];

int main()
{
    int n,m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;

        vector<int> c(m);
        rep(i,m) cin >> c[i];

        vector<int> x(n);
        rep(i,n) cin >> x[i];

        rep(i,n+1) rep(j,300) dp[i][j] = INF;

        dp[0][128] = 0;

        REP(i,1,n+1) {
            rep(j,256) {
                if(dp[i-1][j] == INF) continue;

                rep(k,m) {
                    int to = j + c[k];
                    to = max(to,0);
                    to = min(to,255);

                    int ret = (x[i-1]-to) * (x[i-1]-to);
                    dp[i][to] = min(dp[i][to],dp[i-1][j] + ret);
                }
            }
        }

        int ans = INF;
        rep(i,300) ans = min(ans,dp[n][i]);

        cout << ans << endl;
    }

    return 0;
}

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

int main() {
  int N, K, a = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (a * 2 < a + K) {
      a *= 2;
    }
    else {
      a += K;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long double PI = 3.141592653589793238;

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

    cout << setprecision(10) << fixed;
    cout << 2*r*PI << "\n";
}


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

using namespace std;

int main(){

	string s;
	cin >> s;
	
	string a[4] = {"dream","dreamer","erase","eraser"}; 	
	int len = s.length();

	reverse(s.begin(),s.end());
	for(int i=0;i<4;i++){
		reverse(a[i].begin(),a[i].end());
	}
	
	for(int t=0;t<len;){
		
		bool can = false;
		for(int i=0;i<4;i++){
			if(s.substr(t,a[i].size())==a[i]){
				t += a[i].size();
				can = true;
			}
		}
	
		if(!can){
			cout << "NO" << endl;
			return 0;
		}
	
	
	
	}

	cout << "YES" << endl;
		



	return 0;

}

Measured memory_bytes: 512
if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    d = {}
    for i in range(len(arr)):
        if arr[i] in d:
            d[arr[i]] += 1
        else:
            d[arr[i]] = 1
    sums = sum(arr)
    q = int(input())
    for i in range(q):
        b, c = map(int, input().split())
        if b in d:
            sums -= (b * d[b])
            sums += (c * d[b])
        if c not in d and b in d:
            d[c] = d[b]
        elif b in d:
            d[c] += d[b]
        if b in d:
            d[b] = 0
        print(sums)

Measured memory_bytes: 20696
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    vector< vs32 > g(n);
    int a;
    rep (i, n - 1)
    {
        cin >> a;
        --a;
        g[a].push_back(a);
    }

    rep (i, n)
    {
        cout << g[i].size() << "\n";
    }

    return 0;
}



Measured memory_bytes: 14284
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 1; i < N - 1; i++) {
    vector<char> S1(i), S2(N - i);
    int k = 0;
    int k2 = 0;
    int memo = 0;
    for (int j = 0; j < N; j++) {
      if (j < i) {
        S1.at(k) = S.at(j);
        k++;
      }
      else {
        S2.at(k2) = S.at(j);
        k2++;
      }
    }
    sort(S1.begin(), S1.end());
    sort(S2.begin(), S2.end());
    for (int j = 0; j < i - 1; j++) {
      if (S1.at(j) == S1.at(j + 1)) {
        S1.at(j) = '#';
      }
    }
    for (int j = 0; j < N - i - 1; j++) {
      if (S2.at(j) == S2.at(j + 1)) {
        S2.at(j) = '&';
      }
    }
    for (int j = 0; j < i; j++) {
       for (int v = 0; v < N - i; v++) {
         if (S1.at(j) == S2.at(v)) {
           memo++;
         }
       }
    }
    ans = max(ans, memo);
  }
  cout << ans << endl;
}
          

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


int main() {
  int N,M;
  cin >> N >> M;
  vector<pair<int,int>> p(M);
  for(int i = 0;i<M;i++){
    cin >>p[i].first;
    cin >>p[i].second;
  }
  vector<pair<int,int>> q;
    for(int i = 0;i<M;i++){
      if(p[i].first == 1 || p[i].second == N){
        q.push_back(p[i]);
      }
    }
 
  sort(q.begin(),q.end());
  

  vector<pair<int,int>> r;
  r = q;
  int i = 0;
  while(1){
    if(q[i].first != 1) break;
      r[i].first = q[i].second;
      r[i].second = q[i].first;
    i++;
    }
 
  sort(r.begin(),r.end());
  bool flag = false;
    for(int i = 0;i<r.size()-1;i++){
      if(r[i].first == r[i+1].first){
        flag = true;
        break;
      }
    }
  if(flag) cout << "POSSIBLE" <<endl;
  else cout << "IMPOSSIBLE" <<endl;
}

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

namespace ABC156C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] X = new int[N];
            for (int i = 0; i < N; i++)
            {
                X[i] = int.Parse(input[i]);
            }
            int min = 1000000;
            int m = X.Max();
            for(int i = 1; i <= m; i++)
            {
                int sum = 0;
                for (int j = 0; j < N; j++)
                {
                    sum += (X[j] - i) * (X[j] - i);
                }
                if (sum < min)
                {
                    min = sum;
                }
            }
            Console.WriteLine(min);
        }
    }
}


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

int N;
const int MAX_N = 500 + 100;
int C[MAX_N], S[MAX_N], F[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N-1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }

    vector<int> ans;
    for (int i = 0; i < N-1; i++) {
        int t = 0;
        for (int j = i; j < N-1; j++) {
            if (t < S[j]) {
                t = S[j];
            }

            if (t % F[j] == S[j] % F[j]) {
                t += C[j];
            }
            else {
                t += F[j] - (t % F[j]);
                t += C[j];
            }
        }

        ans.push_back(t);
    }

    ans.push_back(0);

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

    return 0;
}


Measured memory_bytes: 256
Imports System.Collections.Generic
Imports System.Console
Imports System.Math  
Module Program
 	Sub Main()
        Dim input As String() = Console.ReadLine().Split(" ")
	    Dim N As Integer = input(0)
	    Dim K As Integer = input(1)
 '       Console.Error.WriteLine(N)
'        Console.Error.WriteLine(K)
        
        input = Console.ReadLine().Split(" ")
	    Dim A() As Integer = New Integer(N){}
        For i As Integer = 0 To N-1
            A(i) = input(i)
'        Console.Error.WriteLine(A(i))
        Next
  
  	    Dim cumsum() As Long = New Long(N+1){}
        For i As Integer = 0 To N-1
            cumsum(i+1) = A(i) + cumsum(i)
'        Console.Error.WriteLine(cumsum(i+1))
        Next

        Dim li As New List(Of Long)
        For l As Integer = 0 To N
            For r As Integer = l+1 To N
                li.Add(cumsum(r)-cumsum(l))
            Next
        Next

'For Each v As Long in li
'        Console.Error.WriteLine(v)
'        Next

        Dim max As Long = 0 
        For shift As Integer = 60 To 0 Step -1
            If shift < 0 Then
                Exit For
            End If
            Dim one As Long = 1
            Dim mask As Long = one<<shift 
            Console.Error.WriteLine(mask)
            Dim count As Integer = 0
            For Each v As Long in li
                If (v And mask) <> 0 Then
                    count+=1
                End If
            Next

            If count >= K Then
                max = max Or mask
                Dim tmp As New List(Of Long)
                For Each v As Long in li
                    If (v And mask) <> 0 Then
                        tmp.Add(v)
                    End If
                Next
                li.Clear()
                For Each v As Long in tmp
                    li.Add(v)
                Next
            End If
        Next
        Console.WriteLine(max)
    End Sub
End Module


Measured memory_bytes: 30276