akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1e9+7;
const ll ARR_MAX = 1e5+1;
const ll INF=1e14;
bool dp[ARR_MAX]; // dp[i]=1 if player playing now will win. =0 if he will lose.

void solve(){
    int n,k;cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }

    for(int i=a[0];i<=k;i++){
    	bool f=0;
    	for(int j=0;j<n;j++){
    		if(a[j]<=i){
    			f = f || !(dp[i-a[j]]);
    		}
    	}
    	dp[i]=f;
    }
    // for(int i=0;i<=k;i++){
    // 	cout<<dp[i]<<" ";
    // }
    // cout<<nl;
    if(dp[k]==0){
    	cout<<"Second"<<nl;
    }
    else{
    	cout<<"First"<<nl;
    }


}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

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

Measured memory_bytes: 3632
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int K;
    cin >> K;
    queue<int64_t> que;
    // push 1~9 numbers firstly
    for(int i=1; i<10; i++){
        que.push(i);
    }
    int count = 0;
    int64_t print_num;
    while(true){
        int64_t x = que.front();
        que.pop();
        count += 1;
        if(count == K){
            print_num = x;
            break;
        }
        if(x % 10 == 0){
            que.push(x * 10);
            que.push(x*10 + 1);
        }else if(x % 10 == 9){
            que.push(x*10 + (x%10-1));
            que.push(x*10 + x%10);
        }else{
            que.push(x*10 + (x%10 - 1));
            que.push(x*10 + x%10);
            que.push(x*10 + (x%10 + 1));
        }
    }
    cout << print_num << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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

    vector<ll> a(n);
    ll suma = 0;

    rep(i, n) {
        cin >> a[i];
        suma += a[i];
    }

    vector<ll> b_sub_a(n);
    ll sumb = 0;

    rep(i, n) {
        ll b;
        cin >> b;
        sumb += b;
        b_sub_a[i] = b - a[i];
    }

    if ( sumb > suma ) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    ll rest = suma - sumb;
    vector<ll> a_larger_than_b;

    rep(i, n) {
        if ( b_sub_a[i] == 0 ) continue;
        else if ( b_sub_a[i] > 0 ) {
            ++ans;
        }
        else {
            a_larger_than_b.push_back(abs(b_sub_a[i]));
        }
    }

//    cout << rest << " " << a_larger_than_b[0] << endl;

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

    for ( auto tmp_num : a_larger_than_b ) {
        if ( rest >= tmp_num ) {
            rest -= tmp_num;
        }
        else {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

// bool Check(int array[], int n)
// {
// 	bool flag = false;
// 	for (int i=0;i<n;i++)
// 	{
// 		if (array[i]%2==0) return true;
// 	}
// 	return false;
// }

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

	unsigned long long answer=0;
	if (d==0) {
		if (n<100)
		cout << n;
		else cout << 101;
	}
	else if (d==1)
	{
		if (n<100)
			answer = n*100;
		else answer = 10100;
		cout << answer;
	}
	else
	{
		if (n<100)	
			answer = n*10000;
		else answer = 1010000;

		cout << answer;
	}

	// int n;
	// cin >> n;

	// int array[n];

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

	// long long operations = 0;

	// bool flag = Check(array, n);
	// while (flag)
	// {
	// 	for (int i=0;i<n;i++)
	// 	{
	// 		if (array[i]%2==1)
	// 		{
	// 			array[i] *= 3;
	// 		}
	// 		else
	// 		{
	// 			array[i] /= 2;
	// 		}
	// 	}
	// 	operations++;
	// 	flag = Check(array,n);
	// }
	// cout << operations;

	return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush

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

GA = [[] for _ in range(N+1)]
GB = [[] for _ in range(N+1)]

for _ in range(M):
    u, v, a, b = map(int, input().split())
    GA[u].append([v, a])
    GA[v].append([u, a])
    GB[v].append([u, b])
    GB[u].append([v, b])

costa = [10**16]*(N+1)
costb = [10**16]*(N+1)

costa[S] = 0
costb[T] = 0
Q = [[0, S]]


while Q:
    c, p = heappop(Q)
    if costa[p] < c:
        continue

    for q, a in GA[p]:
        if costa[q] > c+a:
            costa[q] = c+a
            heappush(Q, [c+a, q])

Q = [[0, T]]

while Q:
    c, p = heappop(Q)
    if costb[p] < c:
        continue

    for q, b in GB[p]:
        if costb[q] > c+b:
            costb[q] = c+b
            heappush(Q, [c+b, q])

ans = []
tmp = 10**16

for i in range(N, -1, -1):
    
    tmp = min(tmp, costa[i] + costb[i])
    ans.append(10**15 - tmp)

print(*ans[::-1][1:], sep="\n")

Measured memory_bytes: 129132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n,k;
  cin>>k>>n;
  vector<int>a(n);
  rep(i,n) cin>>a[i];
  vector<int>d(n);
  rep(i,n-1)
    d[i]=a[i+1]-a[i];
  d[n-1]=a[0]+k-a[n-1];
  sort(all(d));
  int sum=0;
  rep(i,n-1){
    sum+=d[i];
  }
  cout<<sum<<endl;
}


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

int main() {
  int N, A;
  cin >> N >> A;
  
  int X;
  
  X = N % 500;

	if (X <= A) {
    cout << "Yes" << endl;
    }
	else {
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;

int main()
{
  while (1)
  {
    int h, w;
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0)
      break;
    for (int i = 0; i < h; i++)
    {
      for (int j = 0; j < w; j++)
      {
        if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
        {
          printf("#");
        }
        else
        {
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


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

int N,Ma,Mb,dp[44][444][444];
int A[44],B[44],C[44];
const int INF=INT_MAX/2;

int main(){
  cin>>N>>Ma>>Mb;
  rep(i,N) cin>>A[i]>>B[i]>>C[i];
  rep(i,44) rep(j,444) rep(k,444) dp[i][j][k]=INF;
  dp[0][0][0]=0;
  rep(i,N) rep(j,401) rep(k,401){
    if(dp[i][j][k]>=INF) continue;
    dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
    dp[i+1][j+A[i]][k+B[i]]=min(dp[i+1][j+A[i]][k+B[i]],dp[i][j][k]+C[i]);
  }
  int ans=INF;
  rep(i,401){
    if(Ma*i>400||Mb*i>400) break;
    if(dp[N][Ma*i][Mb*i]==0) continue;
    ans=min(ans,dp[N][Ma*i][Mb*i]);
  }
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}


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

   typedef long long ll;
   typedef pair<ll, ll> P;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

   int dx[4]={1,0,-1,0};
   int dy[4]={0,1,0,-1};

ll N;

ll func(ll x, ll y){
    if (x > y) return ((x -1) * x) / 2 + y + 1;
    else if (x == y) return 0;
    else return func(y, x);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    //input
    cin >> N;
    bool flag = false;
    REP(k, N + 1){
        if (k * (k  -1) / 2 == N){
            flag = true;
            cout << "Yes" << endl;
            cout << k << endl;
            REP(i, k){
                cout << k -1;
                REP(j, k){
                    if (j != i) cout << ' ' << func(i, j);
                }
                cout << endl;
            }
        }
    }
    if (N == 1){
    cout << "Yes" <<endl;
    cout << 2 << endl;
    cout << "1 1\n" << "1 1\n";
    }
    else if (!flag) cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
using namespace std;

// Debug Vector
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v)
{
    if (!v.empty())
    {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p)
{
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}

typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t, x;
    cin >> t >> x;
    cout << (1.0 * t / x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int> i;
vector<int> u;
int o[11000000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a=0,b,c,d=0,e=0,f=0,g;
  string s;
   cin >>a;
   for(int n=1;n<=a;n++){
     d+=n;
     o[n]=1;
     if(d>a){
       o[d-a]=0;
       break;
     }
     if(d==a) break;
   }
   for(int n=1;n<=a;n++){
     if(o[n]==1) cout <<n<<'\n';
   }
   return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  
  int n;
  cin>>n;
  vector<ll>vc;
  for(int i=0;i<n;i++)
  {
    ll temp;
    cin>>temp;
    vc.push_back(temp);
    
  }
  sort(vc.begin(),vc.end());
  if(vc[0]==0)cout<<0<<endl;
  else
  {
    ll sum = 1;
    double digit = 0;
    for(int i=0;i<n;i++)
    {
      digit+= (double)log10l((double)vc[i]);
      //cout<<digit<<endl;
      if(digit>18)
      {
        cout<<-1<<endl;
        return 0;
      }
      sum*=vc[i];
      //cout<<sum<<endl;
      if(sum>(ll)1e18)
      {
        cout<<-1<<endl;
        return 0;
      }
      
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 4300
n=int(input())
a=list(map(int,input().split()))

nn=10**5+1
c=[0]*nn
for i in range(n):
    c[a[i]]=c[a[i]]+1
    
cmax=0
for i in range(2,nn):
    cmax=max(cmax,c[i-2]+c[i-1]+c[i])
print(cmax)


Measured memory_bytes: 13964
#include<iostream>

#define A 500
#define B 100
#define C 50

int main(int argc, char **argv) {
    int a, b, c, x;
    int count = 0;

    std::cin >> a >> b >> c >> x;

    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (A * i + B * j + C * k == x) {
                    count++;
                }
            }
        }
    }

    std::cout << count << std::endl;

    return 0;
}

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

using namespace std;

int main()
{
    string temp;
    cin>>temp;
    int len=temp.size();
    bool flag=0;
    for(int i=0;i<len;i++)
    {
        if(flag==0)
        {
            if(temp[i]=='C') flag=1;
            continue;
        }
        if(flag==1)
        {
            if(temp[i]=='F')
            {
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
 
int main(){
	int n;scanf("%d",&n);
	ll b=1,d=1;
	rep(i,n){
		int a;scanf("%d",&a);
		b*=3;
		if(a%2==0)d*=2;
	}
	cout<<b-d<<endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        k: usize,
        mut a: [i64; k],
    }
    a.reverse();

    let mut least = 2;
    let mut most = 2;
    for a in a.into_iter() {
        if a > most {
            println!("-1");
            return;
        }
        least = (least + a - 1) / a * a;
        if least > most {
            println!("-1");
            return;
        }
        most = most / a * a + a - 1;
    }
    println!("{} {}", least, most);
}


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

using namespace std;

#define INPUT_OUTPUT { \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout); \
}
#define Pi acos(-1)
#define ll long long

int main()
{
    // INPUT_OUTPUT;
    int a;
    cin >> a;
    for(int i=1;i<=9;i++) {
        for(int j=1;j<=9;j++) {
            if((i*j) == a) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main(){
    string a,b;
    cin >> a >> b;
    if (a.size()>b.size()) {
        cout << "GREATER" << endl;
    } else if (a.size()<b.size()) {
        cout << "LESS" << endl;
    } else {
        for (int i = 0; i < a.size(); i++) {
            if (a[i]>b[i]) {
                cout << "GREATER" << endl;
                return 0;
            } else if (a[i]<b[i]) {
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 500001
void buildMaxHeap(void);
void maxHeapify(int);
int left(int);
int right(int);
void swap(int,int);
int A[MAX],H;

int main(){
  int i;
  scanf("%d",&H);
  for(i = 1; i <= H; i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap();
  for(i = 1;i <= H; i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

void buildMaxHeap(){
  int i;
  for(i = H/2; i >= 1; i--){
    maxHeapify(i);
  }
}

void maxHeapify(int i){
  int l,r,largest;
  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){
    swap(i,largest);
    maxHeapify(largest);
  }
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

void swap(int i,int largest){
  int tmp;
  tmp = A[i];
  A[i] = A[largest];
  A[largest] = tmp;
}



Measured memory_bytes: 3676
import java.util.Scanner;

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

		int S = sc.nextInt();
		
		int h = S / 3600;
		int m = (S % 3600) / 60;
		int s = (S % 3600) % 60;
		
		System.out.println(h + ":" + m + ":" + s);
		
		
	}

}

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

int main() {
  
  int N;
  string S;
  cin >> N >> S;
  
  for ( int i = 0; i < S.size(); i++){
    if ( S.at(i) + N > 90 ){
      S.at(i) = S.at(i) + N - 26;
    }else{
      S.at(i) += N;
    }
  }
  
  cout << S << endl;
 
}

Measured memory_bytes: 256
package main

import "fmt"

var (
	N int
	X int
	Y int
)

func main() {
	fmt.Scan(&N, &X, &Y)

	m := make(map[int]int)
	for i := 1; i <= N-1; i++ {
		for j := i + 1; j <= N; j++ {
			m[d(i, j)]++
		}
	}
	for k := 1; k < N; k++ {
		fmt.Println(m[k])
	}
}

func min(x1, x2, x3, x4 int) int {
	var x12, x34 int
	if x1 < x2 {
		x12 = x1
	} else {
		x12 = x2
	}
	if x3 < x4 {
		x34 = x3
	} else {
		x34 = x4
	}
	if x12 < x34 {
		return x12
	}
	return x34
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func d(i, j int) int {

	// 1. i -> j
	// 2. i -> X -> j
	// 3. i -> Y -> j
	// 4. i -> X -> Y -> j

	d1 := abs(j - i)
	d2 := abs(j-X) + abs(X-i)
	d3 := abs(j-Y) + abs(Y-i)
	d4 := abs(X-i) + 1 + abs(Y-j)

	return min(d1, d2, d3, d4)
}


Measured memory_bytes: 768
#include <iostream>
    #include <vector>
    #include <cmath>
    using namespace std;
    
    bool isPrime(int n){
        int s = sqrt(n);
        for(int i = 2; i <= s; i++ ){
            if(n%i == 0) return false;
        }   
        return true;
    }
    
    int main()
    {
        int n;
        cin >> n;
        vector<int> v = {11, 31};
        for(int i = 61; v.size() < n; i+=10){
            if(isPrime(i) && i%5 ==1) v.push_back(i);    
        }
        
        for(auto s: v){
            cout << s << " ";
        }
        return 0;
    }

Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())

if c < a/2 and c < b/2:
    result = max(x,y) * c * 2
elif a + b < c * 2:
    result = a * x + b * y
elif c < a/2:
    result = c * 2 * x
    if y > x:
        result += b * (y - x)
elif c < b/2:
    result = c * 2 * y
    if x > y:
        result += a * (x - y)
else:
    if x == y:
        result = c * 2 * x
    elif x > y:
        result = c * 2 * y + a * (x - y)
    elif x < y:
        result = c * 2 * x + b * (y - x)

print(result)

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

int main(){
    using namespace std;
    size_t N, K;
    cin >> N >> K;
    if(2 * K > (N - 1) * (N - 2))return 0 & puts("-1");
    auto t = (N - 1) * (N - 2) / 2 - K;
    cout << N - 1 + t << endl;
    for(unsigned long i = 1; i < N; ++i)cout << i << " " << N << endl;
    for(unsigned long i = 0, j = 1, k = 2; i < t; ++i){
        cout << j << " " << k << endl;
        ++k;
        if(k == N)k = 1 + ++j;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <stack> st;
#include <algorithm>
using namespace std;
int main()
{
	string s;
	int n,m;
	cin>>s>>n;
	for(int i=0;i<s.size();i=i+n)
	cout<<s[i];
	cout<<"\n";
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
int x;
cin >> x;
int a = x/500;
x -= a*500;
int b = x/5;

int grad = 1000*a + 5*b;
cout << grad << endl;
return 0;

}

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

using namespace std;
using ll = long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

  long double x;
  cin >> x;
  cout << 2 * M_PI * x << endl;

  return 0;
}

Measured memory_bytes: 3804
using System.Numerics;
using static System.Math;
using System;

class Modulo
{
    private const int MOD = 1000000007;
    private readonly int[] m_facs;
    public int Mul(int a, int b) => (int)(Math.BigMul(a, b) % MOD);
    public Modulo(int n)
    {
        m_facs = new int[n + 1];
        m_facs[0] = 1;
        for (int i = 1; i <= n; ++i)
            m_facs[i] = Mul(m_facs[i - 1], i);
    }
    public int Fac(int n) => m_facs[n];
    public int Pow(int a, int m)
    {
        switch (m)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, m / 2);
                int p2 = Mul(p1, p1);
                return ((m % 2) == 0) ? p2 : Mul(p2, a);
        }
    }
    public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2));
    public int Ncr(int n, int r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        int res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}

public class Hello
{
    public const int MOD = 1000000007;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var a = int.Parse(line[1]);
        var b = int.Parse(line[2]);
        var c = new Modulo(Max(a, b));
        var ans1 = (long)(BigInteger.ModPow(2, n, MOD) - 1);
        var ans2 = c.Div((int)getFac(n, a), c.Fac(a));
        var ans3 = c.Div((int)getFac(n, b), c.Fac(b));
        long t = (ans2 + ans3) % MOD;
        long ans = (ans1 - t) % MOD;
        if (ans < 0) ans += MOD;
        Console.WriteLine(ans);
    }
    static long getFac(int n, int a)
    {
        var ans = 1L;
        for (int i = n - a + 1; i <= n; i++)
        {
            ans *= i;
            ans %= MOD;
        }
        return ans;
    }
}


Measured memory_bytes: 13264
#include <stdio.h>


int main (void){
    char s[4];
    int answer = 0;
    scanf("%s",&s);
    if(s[0] == 'A'){
        if(s[1] == 'B' || s[2] == 'B') answer = 1;
    }else{
        if(s[1] == 'A' || s[2] == 'A') answer = 1;
    }
    if(answer == 1) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int C[511][511];
void MAIN() {
    int K;
    scanf("%d", &K);

    if (K == 1) {
	puts("1");
	puts("1");
    } else {
	int N = 2;
	while (2*N < K) N += 2;
	REP (i, N) REP (j, N) {
	    int tmp = (i+j)%N + i%2*N;
	    if (tmp >= K) tmp -= N;
	    C[i][j] = tmp+1;
	}
	printf("%d\n", N);
	REP (i, N) rprintf("%d", C[i], C[i]+N);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 2176
n,q = map(int,input().split())
s =str(input())
l = [0]*n
r = [0]*n
for i in range(1,n):
    if s[i] == 'C':
        if s[i - 1] == 'A':
            l[i] = 1
            r[i] = 1
for i in  range(1, n):
    l[i] = l[i] + l[i - 1]
    r[i] = r[i] + r[i - 1]
for i in range(q):
    a,b = map(int,input().split())
    print(r[b - 1] - l[a -1])


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

bool cmp(int x,int y)
{
	return (x>y);
}

int main()
{
	int k,n,sum,tab[100];
	cin>>n>>k;
	int i;
	for (i=1;i<=n;i++)
	 cin>>tab[i];
	sort(tab+1,tab+n+1,cmp);
	sum=0;
	for (i=1;i<=k;i++)
	 sum+=tab[i];
	cout<<sum<<"\n";
}

Measured memory_bytes: 256
#####segfunc#####
def segfunc(x, y):
  return max(x, y)
#################

#####ide_ele#####
ide_ele = 0
#################

class SegTree:
  """
  init(init_val, ide_ele): 配列init_valで初期化 O(N)
  update(k, x): k番目の値をxに更新 O(logN)
  query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
  """
  def __init__(self, init_val, segfunc, ide_ele):
    """
    init_val: 配列の初期値
    segfunc: 区間にしたい操作
    ide_ele: 単位元
    n: 要素数
    num: n以上の最小の2のべき乗
    tree: セグメント木(1-index)
    """
    n = len(init_val)
    self.segfunc = segfunc
    self.ide_ele = ide_ele
    self.num = 1 << (n - 1).bit_length()
    self.tree = [ide_ele] * 2 * self.num
    # 配列の値を葉にセット
    for i in range(n):
      self.tree[self.num + i] = init_val[i]
    # 構築していく
    for i in range(self.num - 1, 0, -1):
      self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

  def update(self, k, x):
    """
    k番目の値をxに更新
    k: index(0-index)
    x: update value
    """
    k += self.num
    self.tree[k] = x
    while k > 1:
      self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
      k >>= 1

  def query(self, l, r):
    """
    [l, r)のsegfuncしたものを得る
    l: index(0-index)
    r: index(0-index)
    """
    res = self.ide_ele

    l += self.num
    r += self.num
    while l < r:
      if l & 1:
        res = self.segfunc(res, self.tree[l])
        l += 1
      if r & 1:
        res = self.segfunc(res, self.tree[r - 1])
      l >>= 1
      r >>= 1
    return res

def resolve():
  N, K = map(int, input().split(" "))
  max_range = (3000000 + 1)
  dp = [0] * max_range
  seg = SegTree(dp, segfunc, ide_ele)

  for _ in range(N):
    A = int(input())
    left = A-K
    right = A+K+1 #半開区間なので +1 してる
    seg.update(A, seg.query(left, right) + 1)

  print(seg.query(0, max_range+1))

if __name__ == "__main__":
  resolve()

Measured memory_bytes: 160836
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  int N,M; cin >> N >> M;
  vector<string> A(N);
  vector<string> B(M);
  rep(i, N) cin >> A[i];
  rep(i, M) cin >> B[i];

  for(int h = 0; h + M <= N; ++h) {
    for(int w = 0; w + M <= N; ++w) {
      bool flag = true;
      rep(i, M) {
        if(!flag) break;
        rep(j, M) {
          if(A[h + i][w + j] != B[i][j]) {
            flag = false;
            break;
          }
        }
      }
      if(flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}


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

int main(){
  long long int n;
  cin >> n;
  long long int x=1,y=1,z=1;
  for(int i=0;i<n;i++){
    x=x*10%1000000007;
    y=y*9%1000000007;
    z=z*8%1000000007;
  }
  long long int ans=(x-(2*y-z))%1000000007;
  ans=(ans+1000000007)%1000000007;
  cout << ans << endl;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES //円周率を使用
#include <math.h>
#include <iomanip> //小数点以下を表示
#include <iostream>
using namespace std;

int main(void)
{
	double r; //半径
	double s; //面積
	double l; //周の長さ

	cin >> r;

	s = r * r * M_PI;
	l = 2 * r * M_PI;

	cout << fixed << setprecision(6) << s << ' ' << fixed << setprecision(6) << l;

	return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int n, m;
	cin >> n >> m;
	VPi ans(m);
	int inter = ((m+1) / 2);
	int at    = 0;
	if(n%2==0){
	for (int i = 0; i < inter; i++) {
		ans[i].F = i+1;
		if(i==inter-1){
			ans[inter - 1].S = ans[inter - 1].F + 1;
		}
	}

	for (int i = inter - 2; i >=0 ;i--){
		ans[i].S = ans[i + 1].S+1;
	}
	clog << ans[inter - 1] << endl;
	// inter*2+1
	for (int i = inter; i < m; i++) {
		ans[i].F = (inter + 1 + i);
		if(i==m-1){
			ans.back().S = ans.back().F + 2;
		}
		}
		
	for (int i = m - 2; i >= inter;i--){
		ans[i].S = ans[i + 1].S+ 1;
	}
	//	if(ans[inter].S-ans[inter].F==ans[inter].F-ans[inter].S+n){
	//		ans[inter] = mp(ans.back().F + 1, ans.back().S - 1);
	//	}
	}else{
	//	ans[0] = mp(n/2, n/2+2);
		for (int i = 0; i < m;i++){
			ans[i].F = i+1;
		}
		ans.back().S = ans.back().F + 1;
		for (int i = m - 2; i >= 0;i--){
			ans[i].S = ans[i + 1].S + 1;
		} }
	rep(i, m) { cout << ans[i].F << " " << ans[i].S << endl; }
}
/*
1 2 |3 5| 4 7

1 2 3 4  ... 5 6 7 8  | 9 10 11 12 13... (14) 15 16 17 18 19 ... 9 (9)
07 05 03 01 10 08 06 04 02 || 9 10
12 14 16 18 09 11 13 15 17

1 12  13
11 2
6 2
1 2 |5 6 => 2 5  3 4


1 2

4 5

1

1 7
2 6
3 5
1
3
2
1 2 3 4 5 7

1
2
2
*/

Measured memory_bytes: 3980
n = int(input())
s = list(input())

num1, num2, num3 = set([]), set([]), set([])

#new for num3 <=> new password

for i in range(n):
    if s[i] in num1:
        continue
    num1.add(s[i])
    for j in range(i+1, n):
        word2 = s[i] + s[j]
        if word2 in num2:
            continue
        num2.add(word2)
        for k in range(j+1, n):
            word3 = word2 + s[k]
            if word3 in num3:
                continue
            num3.add(word3)

print(len(num3))

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

int main() {
	int n, k, x, y, ans;
	cin >> n;
	cin >> k;
	cin >> x;
	cin >> y;
	if (n <= k) ans = n * x;
	else ans = k * x + (n - k) * y;
	cout << ans << endl;
	return 0; 
}

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

int Count(int num) {
	if (num == 1) return 1;
	else if (num == 2) return 2;
	else if (num == 3) return 4;
	else return Count(num - 1) + Count(num - 2) + Count(num - 3);
}



int main() {
	int num;
	while (1) {
		scanf("%d", &num);
		if (num == 0)break;
		printf("%d\n", (Count(num)/10)/365 + 1);
	}
	return 0;
}


Measured memory_bytes: 1920
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 100002;

int n, m;

int a[N_MAX], b[N_MAX];

int cnt[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        cin >> a[i] >> b[i];
        cnt[a[i]]++;
        cnt[b[i]]++;
    }
    for(int i = 1; i <= n; i++)
        if(cnt[i] & 1)
        {
            cout << "NO\n";
            return 0;
        }
    cout << "YES\n";
    return 0;
}


Measured memory_bytes: 4800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1e9 + 5;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> f(n ,vector<int>(10));
  rep(i, n) {
    rep(j, 10) {
      cin >> f[i][j];
    }
  }
  vector<vector<int>> p(n, vector<int>(11));
  rep(i, n) {
    rep(j, 11) {
      cin >> p[i][j];
    }
  }

  int ans = -INF;
  FOR(k, 1, (1 << 10)) {
    int res = k;
    vector<bool> open(10, false);
    rep(i, 10) {
      if (res & 1) open[i] = true;
      res /= 2;
    }

    vector<int> cnt(n, 0);
    rep(i, n) {
      rep(j, 10) { 
        if (open[j] && f[i][j] == 1) cnt[i]++;
      }
    }

    int sum = 0;
    rep(i, n) {
      sum += p[i][cnt[i]];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;






  
  return 0;
}

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

int main(void){
	while(1){
		int n;
		cin>>n;
		if(n == 0) break;
		for(int i=0;i<9;i++){
			int m;
			cin>>m;
			n -= m;
		}
		cout<<n<<endl;
	}

	return 0;
}

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

int main() {
  
  int N,M,a,b;
  cin >> N >> M;
  
  vector<int> vec(N);
  for (int i=0; i<M; i++) {
    cin >> a >> b;
    vec.at(a-1)+=1;
    vec.at(b-1)+=1;
  }
  
  for (int i=0; i<N; i++) cout << vec.at(i) << endl;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
    ll n,m,ma=0,mi=INT_MAX;
    cin>>n>>m;
    ll a[m][2];
    for(ll i=0;i<m;i++)
    {
        for(ll j=0;j<2;j++)
        {
            cin>>a[i][j];
        }
    }
    
    for(ll i=0;i<m;i++)
    {
        ma=max(ma,a[i][0]);
        mi=min(mi,a[i][1]);
    }
    ll count=0;
    for(ll i=ma;i<=mi;i++)
    {
        count++;
    }
    
    cout<<count<<endl;

}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
ll a, b;
ll x, y;
int n;
int main(){
	scanf("%d", &n);
	a=b=1;
	rep(i, 0, n){
		cin>>x>>y;
		if(x>=a&&y>=b)a=x, b=y;
		else if(x<=a||y<=b){
			ll t=max((a+x-1)/x, (b+y-1)/y);
			a=t*x;
			b=t*y;
		}
	}
	printf("%lld\n", a+b);
	return 0;
}
/*
3
2 3
1 1
3 2
10

4
1 1
1 1
1 5
1 100
101

5
3 10
48 17
31 199
231 23
3 2
6930
*/

Measured memory_bytes: 256
import Data.List

main = do
  li <- getLine
  let [n,m] = map read $ words li
  co <- getContents
  let abs = map (l2p . map read . words) $ lines co
  print $ compute n m abs

l2p [a,b] = (a,b)

compute :: Int -> Int -> [(Int,Int)] -> Int
compute n m abs = loop m (sort abs)
  where
    loop m ((a,b):abs)
      | m > b = a * b + loop (m - b) abs
      | True  = a * m


Measured memory_bytes: 52476
import java.util.*;

//update 2019/12/29

public class Main{

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    String[] s = splitString(next());

    String[] acgt = {"A","C","G","T"};

    int cnt = 0;
    int ans = 0;

    for(int i=0;i<s.length;i++){
      boolean a = false;
      for(int j=0;j<4;j++){
        if(s[i].equals(acgt[j])){
          a = true;
          break;
        }
      }
      if(a){
        cnt++;
        ans = Math.max(cnt,ans);
      }
      else{
        cnt = 0;
      }
    }

    System.out.println(ans);



  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char aaa){
    return aaa - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			String w = sc.next().toLowerCase();
			String[] y = new String[w.length()];

			if (w.length() % 2 == 0) {
				for (int i = 0; i < w.length(); i++) {
					y[i] = String.valueOf(w.charAt(i));
				}
				Arrays.sort(y);

				int ans = 0;

				for (int i = 0; i < w.length() / 2; i++) {

					if (y[2 * i].equals(y[2 * i + 1])) {
						ans += 0;
					} else {
						ans += 1;
					}
				}

				if (ans == 0) {
					System.out.println("Yes");
				} else {
					System.out.println("No");
				}

			} else {

				System.out.println("No");

			}
		}
	}
}

Measured memory_bytes: 23764
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int N, Q;
int par[100001];
VI chd[100001];
VI node(100001, 1);
VI mkd(100001, 0);

class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

  //find root of x
  int find(int x){
	if(par[x] == x)
	  return x;
	return (par[x] = find(par[x]));
  }

  void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rank[x] < rank[y])
	  par[x] = y;
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }

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

void init(int i, int p, UnionFind& uf){
  if(mkd[i]){
	for(int c: chd[i]){
	  init(c, i, uf);
	}
  }
  else{
	node[i] = node[p];
	uf.unite(p, i);
	for(int c: chd[i]){
	  init(c, p, uf);
	}
  }
}

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

  while(cin >> N >> Q, N){
	REP(i,100001) chd[i].clear();
	UnionFind uf(N+1);
	REP(i,N-1){
	  cin >> par[i+2];
	  chd[par[i+2]].PB(i+2);
	}	
	
	vector<PII> q;
	for(int i=1;i<=N;++i)
	  node[i] = i;
	fill(ALL(mkd), false);
	mkd[1] = true;
	REP(i,Q){
	  char ch; int x;
	  cin >> ch >> x;
	  if(ch == 'M')
		q.PB(MP(0,x)), mkd[x]++;
	  else
		q.PB(MP(1,x));
	}

	init(1, 1, uf);
	
	LL ans = 0;
	for(int i=Q-1;i>=0;--i){
	  if(q[i].first == 0){
		int idx = q[i].second;
		--mkd[idx];
		if(!mkd[idx]){
		  node[uf.find(idx)] = node[uf.find(par[idx])];
		  uf.unite(idx, par[idx]);
		}
	  }
	  else{
		ans += node[uf.find(q[i].second)];
	  }
	}
	cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 18208
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;

#define LL long long
map<pair<string,string>,LL> Hash;
string S;
LL Ans=0;
int N;

int main(){
    scanf("%d",&N);
    cin>>S;
    for(register int i=0;i<(1<<N);++i){
        string a,b;
        for(register int pos=1,k=1;pos<(1<<N);pos<<=1,++k){
            if(i&pos) a.push_back(S[2*N-k]);
            else b.push_back(S[2*N-k]);
        }
        Hash[make_pair(a,b)]++;
    }
    for(register int i=0;i<(1<<N);++i){
        string a,b;
        for(register int pos=1,k=1;pos<(1<<N);pos<<=1,++k){
            if(i&pos) a.push_back(S[k-1]);
            else b.push_back(S[k-1]);
        }
        Ans+=Hash[make_pair(a,b)];
    }
    cout<<Ans<<endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 91904
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 100000
using namespace std;
typedef long long ll;
int dp[1002][1002];
int lcs(string a,string b)
{
	a=" "+a;
	b=" "+b;
	int m,n;
	m=a.size();
	n=b.size();
	
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(a[i]==b[j]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	return dp[m][n]-1;
}
int main()
{	
	int n;
	string a,b;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		cout<<lcs(a,b)<<endl;
	}
	return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
}
Node treeSearch(Node u, int k){
}
Node treeSuccessor(Node x){
}
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  }
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct 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){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);


  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");

    } else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    } else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  } 
  return 0;
}

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

struct node{
  unsigned int key;
  struct node *n;
  struct node *p;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur=nil->n;
  while(cur!=nil && cur->key!=key){
    cur=cur->n;
  }
  return cur;
}

void init(){
  nil=malloc(sizeof(struct node));
  nil->n=nil;
  nil->p=nil;
}

void printList(){
  int a=1;
  NodePointer c=nil->n;

  while(1){
    if(c==nil)break;
    if(a==0)printf(" ");
    printf("%d",c->key);
    c=c->n;
    a=0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->p->n=t->n;
  t->n->p=t->p;
  free(t);
}

void deleteFirst(){
  if(nil->n==nil)return;
  deleteNode(nil->n);
}

void deleteLast(){
  if(nil->n==nil)return;
  deleteNode(nil->p);
}

void delete(int key){
  NodePointer t=listSearch(key);
  if(t==nil)return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x=malloc(sizeof(struct node));
  x->key=key;
  x->n=nil->n;
  nil->n->p=x;
  nil->n=x;
  x->p=nil;
}

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int np=0;
  int nd=0;
  
  scanf("%d",&n);
  init();
  
  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();
	else if(com[6]=='L')deleteLast();
      }
      else{
	delete(key);
	nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}



Measured memory_bytes: 33000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string S;
void input() {
    cin >> S;
}
bool solve() {
    if (S.size() % 2 == 1) return 0;
    for (int i = 1; i < S.size(); i+=2) {
        if (S[i-1] == 'h' && S[i] == 'i') {}
        else return 0;
    }
    return 1;
}
void output(bool f) {
    if (f) {puts("Yes");}
    else {puts("No");}
}
int main () {
    input();
    output(solve());
}

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

vector<int> a, b;

int main() {
	int n; cin >> n; a.resize(n); b.resize(n);
	for (auto &x : a) { cin >> x; }
	for (auto &x : b) { cin >> x; }
	reverse(b.begin(), b.end()); 
	
	int l = 0, r = 0;
	while (l < n && a[l] != b[l]) { l++; r++; }
	while (r < n && a[r] == b[r]) { r++; }
	for (int i = 0; i < n && l != r; i++)
		if (a[i] != a[l] && b[i] != b[l]) 
			swap(b[l++], b[i]);

	if (l != r) { cout << "No" << '\n'; return 0; }
	cout << "Yes" << '\n';
	for (auto &x : b) cout << x << ' ';
	cout << '\n'; cin.ignore(2); return 0;
}

Measured memory_bytes: 4792
#include <iostream>
using namespace std;
int main() {
    int N;
    int sum = 0;
    int pow_sum = 0;
    cin >> N;
    int d[N];
    for(int i=0; i<N; i++){
        cin >> d[i];
        sum += d[i];
        pow_sum += d[i]*d[i];
    }
    int ret = (sum*sum - pow_sum)/2;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256