akhauriyash/Code-Regression huggingface dataset:
S = list(input())
Q = int(input())
a = 0
A = []
B = []
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      B.append(q[2])
    else:
      A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
  ans = ans[::-1]
ans = ''.join(ans)
print(ans)

Measured memory_bytes: 15856
#include<stdio.h>
int main()
{
long long int n,m,l,i,j,k;
scanf("%lld%lld%lld",&n,&m,&l);
long long int a[n][m];
long long int b[m][l];

for(i=0;i<n;i++)
{
    for(j=0;j<m;j++)
    {
        scanf("%lld",&a[i][j]);
    }
}


for(j=0;j<m;j++)
{
    for(k=0;k<l;k++)
    {
        scanf("%lld",&b[j][k]);
    }
}


long long int sum=0;
for(i=0;i<n;i++)
{
    for(k=0;k<l;k++)
    {
        for(j=0;j<m;j++)
        {
          sum=sum+a[i][j]*b[j][k];
        }
        if(k==(l-1))printf("%lld",sum);
       else{ printf("%lld ",sum);}
        sum=0;
    }
    printf("\n");

}

    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int N;
    cin >> N;
    vector<int> input(N);
    vector<int> tmp(N);
    rep0(i,N){
        cin >> input[i];
        tmp[i] = input[i];
    }
    sort(input.begin(),input.end());
    int diff = 0;
    rep0(i,N){
        if(input[i]!=tmp[i]){
            diff++;
        }
    }
    if(diff<=2){
        cout << "YES";
    }else{
        cout << "NO";
    }
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    vector<vector<pair<int,ll>>> g(n);
    for(int i=0;i<m;i++){
        int x,y,t;cin >> x >> y >> t;
        x--,y--;
        g[x].push_back({y,t});
        g[y].push_back({x,t});
    }
    priority_queue<pair<ll,pair<ll,ll>>,vector<pair<ll,pair<ll,ll>>>,greater<pair<ll,pair<ll,ll>>>> pq;
    int v0;cin >> v0;
    int a,b,c;cin >> a >> b >> c;
    vector<vector<ll>> d(n,vector<ll>(c,INF));
    d[0][v0]=0;
    pq.push({0,{v0,0}});
    while(!pq.empty()){
        ll u=pq.top().first,v=pq.top().second.first,w=pq.top().second.second;
        pq.pop();
        if(u>d[w][v]){
            continue;
        }
        for(auto e:g[w]){
            ll x=e.first,y=e.second;
            if(chmin(d[x][(a*v+b)%c],d[w][v]+y*v)){
                pq.push({d[x][(a*v+b)%c],{(a*v+b)%c,x}});
            }
        }
    }
    for(int i=0;i<n-1;i++){
        for(int j=0;j<c;j++){
            d[i][j]=INF;
        }
    }
    for(int i=0;i<c;i++){
        pq.push({d[n-1][i],{i,n-1}});
    }
    while(!pq.empty()){
        ll u=pq.top().first,v=pq.top().second.first,w=pq.top().second.second;
        pq.pop();
        if(u>d[w][v]){
            continue;
        }
        for(auto e:g[w]){
            ll x=e.first,y=e.second;
            if(chmin(d[x][(a*v+b)%c],d[w][v]+y*v)){
                pq.push({d[x][(a*v+b)%c],{(a*v+b)%c,x}});
            }
        }
    }
    ll ans=INF;
    for(int i=0;i<c;i++){
        chmin(ans,d[0][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6084
#include <iostream>
#include <vector>
#include <cmath>
int main(){
int n ;
std::cin >> n ;
std::vector<int>myvector;
for (int a = 0 ; a < n; a = a + 1 )
        {  int x;
        std::cin >> x;
            myvector.push_back(x);
}
    int sum = 0 ;
    for (int a = 0; a < n; a = a + 1 )
    { sum = sum + myvector[a];

    }
    int i = 0; int cost = 1000000;
    for( int a = 0; a < n; a = a + 1){
        if (std::abs(sum - n * myvector[a])  < cost){
            cost = std::abs(sum - n * myvector[a]);
            i = a ;
        }
    }
std::cout << i;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
bool flip[100000];
int main() {
	string S, T;
	cin >> S;
	for (int i = 0; i < S.size(); i++) S[i] -= '0';
	T = S;
	int l = 1, r = S.size() + 1;
	while ((r - l) > 1) {
		int m = (l + r) / 2;
		bool now = 0;
		memset(flip, 0, sizeof(flip));
		for (int i = 0; i + m <= S.size(); i++) {
			S[i] ^= now;
			if (S[i]) {
				flip[i] = 1;
				S[i] = 0;
			}
			now ^= flip[i];
			if (i >= m - 1) now ^= flip[i - (m - 1)];
		}
		for (int i = S.size() - m + 1; i < S.size(); i++) {
			S[i] ^= now;
			if (i >= m - 1) now ^= flip[i - (m - 1)];
		}
		bool ok = 1;
		for (int i = 0; i < min((int)S.size(), m); i++) {
			if (S[i]) {
				ok = 0;
				break;
			}
		}
		if (ok) l = m;
		else r = m;
		S = T;
	}
	cout << l << endl;
}

Measured memory_bytes: 512
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define rep(i,n) rep1(i,0,n)
#define rep1(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
const double PI = acos(-1);
int main(){
    string s;
    cin >> s;
    int o = 0, x = 0;
    rep(i,s.size()){
        if(s[i]=='0')
            o++;
        else
            x++;
    }
    cout << min(o, x) * 2 << endl;
}


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

int main() {
	string S;
	cin >> S;
	vector<long long> N(S.size());
	for (int i = 0; i < S.size(); i++) N[i] = S[i] - '0';
	reverse(N.begin(), N.end());
	long long INF = 1000000000;
	vector<vector<long long> > DP(S.size() + 1, vector<long long>(2, INF));
	DP[0][0] = 0;
	for (int i = 0; i < S.size(); i++) {
		DP[i + 1][0] = min(DP[i + 1][0], DP[i][0] + N[i]);
		DP[i + 1][1] = min(DP[i + 1][1], DP[i][0] + 10 - N[i]);
		if (N[i] == 9) {
			DP[i + 1][1] = min(DP[i + 1][1], DP[i][1]);
		}
		else {
			DP[i + 1][0] = min(DP[i + 1][0], DP[i][1] + N[i] + 1);
			DP[i + 1][1] = min(DP[i + 1][1], DP[i][1] + 9 - N[i]);
		}
	}
	cout << min(DP[S.size()][0], DP[S.size()][1] + 1) << endl;
}

Measured memory_bytes: 63748
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int x;
	cin >> x;
	if(x < 1200){
		cout << "ABC" << endl;
	}else{
		cout << "ARC" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N,K;
LL d[101][101];
typedef pair<int,int>P;
vector<P>v;

void add_edge(int x,int y){
	d[x][y]=1;
	d[y][x]=1;
	v.push_back(P(x,y));
}

int main(){
	cin>>N>>K;
	if(K>(N-1)*(N-2)/2){
		cout<<"-1"<<endl;
		return 0;
	}
	LL now=(N-1)*(N-2)/2;
	REP(i,N){
		REP(j,N){
			d[i][j]=0;
		}
	}
	
	REP(i,N){
		if(i!=0){
			add_edge(0,i);
		}
	}
	REP(i,N){
		REP(j,N){
			if(now==K)break;
			if(i==j)continue;
			if(d[i][j]==0){
				add_edge(i,j);
				now--;
			}
		}
	}
	
	cout<<v.size()<<endl;
	REP(i,v.size()){
		cout<<v[i].first+1<<" "<<v[i].second+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
import os
import sys
import datetime

def main():
    sDate = datetime.datetime.strptime("2019/04/30", '%Y/%m/%d')

    inputdate = input()

    try:
        inputdate = datetime.datetime.strptime(inputdate, '%Y/%m/%d')
    except:
        print("Error: illegal date format.")
        return 1

    if inputdate <= sDate:
        print("Heisei")
    else:
        print("TBD")

    return 0

if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 4464
n = int(input())
xyl = [tuple(map(int, input().split())) for _ in range(n)]

xyp = []
xym = []

for x,y in xyl:
    xyp.append(x+y)
    xym.append(x-y)

# xyp.sort()
# xym.sort()

ans1 = max(xym)-min(xym)
# print(ans1)
ans2 = max(xyp)-min(xyp)
ans = max(ans1,ans2)
print(ans)


Measured memory_bytes: 126552
/* 2018-01-15-11.35.00 */

#include<bits/stdc++.h>
#define ll long long int
#define N 2010
using namespace std;

int main()
{
    int n,A[N],i,bit=0,ans=1e9+7;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]),bit+=A[i];
    bitset<N*N> dp;
    dp[0]=1;
    for(i=0;i<n;i++) dp|=(dp<<A[i]);
    for(i=(bit+1)/2;i<=bit;i++)
    {
        if(dp[i])
        {
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
n=gets.to_i
a=gets.split.map(&:to_i)

len=a.sum
half_a=Array.new(n,0)
half_b=Array.new(n,0)
half_a[0]=a[0]
half_b[0]=len
ans=len
1.upto(n-1) do |i|
    half_a[i]=half_a[i-1]+a[i]
    half_b[i]=half_b[i-1]-a[i-1]
    ans=[ans,(half_a[i-1]-half_b[i]).abs].min
end
puts ans


Measured memory_bytes: 31236
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a[12];
	long long n,m,l;
	cin>>a;
	l=strlen(a);
	for(int i=0;i<1<<(l-1);i++)
	{
		m=a[0]-'0';
		for(int j=0;j<l-1;j++)
		{
			if(i&1<<j)
			{
				n=n+m;
				m=a[j+1]-'0';
			}
			else m=m*10+a[j+1]-'0';
		}
		n+=m;
	}
	cout<<n<<endl;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

if len(list(set(v))) == 1:
    print(n//2)
    exit()

v_even = v[0::2]
v_odd = v[1::2]

cve = Counter(v_even)
cvo = Counter(v_odd)

if cve.most_common()[0][0] != cvo.most_common()[0][0]:
    ans = (n//2 - cve.most_common()[0][1]) + (n//2 - cvo.most_common()[0][1])
else:
    ans = min((n//2 - cve.most_common()[1][1]) + (n//2 - cvo.most_common()[0][1]), (n//2 - cve.most_common()[0][1]) + (n//2 - cvo.most_common()[1][1]))

print(ans)

Measured memory_bytes: 20572
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
 
int main() {
    ll n, W;
    cin >> n >> W;
    
    vector<P> p(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(all(p));
    
    vvl dp(n, vl(W));  // dp[i][j] : i番目の料理までで食べるのにかかる時間の総和がj以下のときの美味しさの合計の最大値
    rep(i, n-1) {
        exrep(j, 0, W-1) {
            chmax(dp[i+1][j], dp[i][j]);
            if(j + p[i].first < W) {
                chmax(dp[i+1][j + p[i].first], dp[i][j] + p[i].second);
            }
        }
    }
    
    ll ans = 0;
    rep(i, n) {  // i番目の料理まで時間を使って食べるとする
        chmax(ans, dp[i][W-1] + p[i].second);
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 73744
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		long min = Long.MAX_VALUE;

		for (int i = 0; i <= 100000; i++) {
			long amount = 0;
			amount = i * 2 * C + Math.max(0, X-i) * A + Math.max(0, Y-i) * B;
			min = Math.min(min, amount);
		}

		System.out.println(min);

	}
}


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

using namespace std;

using ull = unsigned long long;
using ll = long long;

#define READ freopen("input.txt", "r", stdin)
#define ROUT freopen("output.txt", "w", stdout)
#define pb push_back
#define endl '\n'

void fasterIO()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

///(Moan) ey (hoe) pakhi jeno (Oral) dibe <3

void fuck()
{
    int n, i, count=0;
    cin>>n;
    int s[n];
    for(i=0; i<n; i++){
        cin>>s[i];
    }
    for(i=1; i<n-1; i++){
        if((s[i-1]<s[i] && s[i]<s[i+1]) || (s[i-1]>s[i] && s[i]>s[i+1]))
            count++;
    }
    cout<<count<<endl;
}

int main()

{
    ///READ;
    ///ROUT;
    fasterIO();

    fuck();

    return 0;
}



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

#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 ALL(v) v.begin(), v.end()

string N;

int main() {
  std::cout << std::fixed << std::setprecision(20);
  cin >> N;
  

  int ans = 0;

  
  for(int i = 0; i < N.size(); i++){
    ans += int((N[i]) - '0');
  
    
  }
 

  if(ans %9 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3756
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br =
		        new BufferedReader(new InputStreamReader(System.in));

		  int x  = Integer.parseInt(br.readLine());

		 // System.out.println(x*x*x);

		 // ????????????????????¢???????????????????????´?????????????????§???????????????
		 System.out.println((int)Math.pow(x, 3));

	}

}

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

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

	if(a<b){
		cout << "a < b" << endl;
	}
	else if (a==b){
		cout << "a == b" << endl;
	}
	else {
		cout << "a > b" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

ll A[200002];

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

    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=1;i<N;i++){
        A[i] += A[i - 1];
    }

    ll ans = 1LL << 60;
    int a_end = 0, c_end = 2;
    for(int b_end=1;b_end<N-2;b_end++){
        while(a_end + 1 < b_end && abs(A[a_end] - (A[b_end] - A[a_end])) > abs(A[a_end + 1] - (A[b_end] - A[a_end + 1]))){
            a_end++;
        }
        while(c_end + 1 < N && abs((A[c_end] - A[b_end]) - (A[N - 1] - A[c_end])) > abs((A[c_end + 1] - A[b_end]) - (A[N - 1] - A[c_end + 1]))){
            c_end++;
        }
        ll diff = max({A[a_end], A[b_end] - A[a_end], A[c_end] - A[b_end], A[N - 1] - A[c_end]})
            - min({A[a_end], A[b_end] - A[a_end], A[c_end] - A[b_end], A[N - 1] - A[c_end]});
        ans = min(ans, diff);
    }
    cout << ans << endl;

    return 0;
}

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

int main(){

  string S; cin >> S;
  int dx;
  // vector<int> cnt(S.size(), 0);
  int cnt = 0;

  for(int i = 0 ; i < S.size() - 1 ; ++i){
    // if(S[i] == '1') cnt[i]++;
    // cout << S[i] << "\t" << S[i + 1];
    if(S[i] == '0' && S[i+1] == '0'){
      cnt++;
      S[i+1] = '1';
    }
    else if(S[i] == '1' && S[i+1] == '1'){
      cnt++;
      S[i+1] = '0';
    }
    // cout << "\t" << cnt << endl;
  }

  cout << cnt << endl;

  

}

Measured memory_bytes: 512
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref max_int
let _ = for i = -100 to 100 do ans := min !ans @@ Array.fold_left (fun s a -> s + (a - i) * (a - i)) 0 a_s done; Printf.printf "%d\n" !ans

Measured memory_bytes: 2432
#include <stdio.h>

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

void push(char* s, char** heap, int* n)
{
	int i = *n;
	char *tmp;
	heap[(*n)++] = s;
	while (1) {
		if (i == 0) break;
		else if (lex_smaller(heap[i], heap[(i - 1) / 2]) == 1) {
			tmp = heap[(i - 1) / 2];
			heap[(i - 1) / 2] = heap[i];
			heap[i] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}

char* pop(char** heap, int* n)
{
	int i = 0, j;
	char *tmp, *output = heap[0];
	heap[0] = heap[--(*n)];
	while (1) {
		if (i * 2 + 1 >= *n) break;
		else if (i * 2 + 2 >= *n) j = i * 2 + 1;
		else if (lex_smaller(heap[i * 2 + 1], heap[i * 2 + 2]) == 1) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (lex_smaller(heap[j], heap[i]) == 1) {
			tmp = heap[j];
			heap[j] = heap[i];
			heap[i] = tmp;
			i = j;
		} else break;
	}
	return output;
}

int main()
{
	int K;
	char s[5001];
	scanf("%s", s);
	scanf("%d", &K);
	
	int i, j, k, m, n = 0;
	char **heap = (char**)malloc(sizeof(char*) * 25000), **t = (char**)malloc(sizeof(char*) * 25000), *tmp[5] = {};
	for (i = 0; i < 25000; i++) t[i] = (char*)malloc(sizeof(char) * 6);
	for (i = 0, m = 0; s[i] != 0; i++) {
		for (j = 0; j < 5 && s[i+j] != 0; j++) {
			for (k = 0; k <= j; k++) t[m][k] = s[i+k];
			push(t[m++], heap, &n);
		}
	}
	
	k = 0;
	while (k < K) {
		tmp[k] = pop(heap, &n);
		for (i = 0; i < k; i++) if (lex_smaller(tmp[k], tmp[i]) == 0) break;
		if (i == k) k++;
	}
	
	printf(tmp[K-1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#define N 100001
int Partition(int, int);
int A[N], n;

int main(void){
  int i, k;
  scanf("%d", &n);
  for(i=1; i<=n; i++)scanf("%d", &A[i]);
  
  i=1;
  k =  Partition(i, n);
  
  for(i=1; i <= n; i++) {

    if(k == i) {
      printf("[%d] ", A[i]);
      continue;
    }
    printf("%d", A[i]);
    if(i < n)printf(" ");
    
  }
  
  printf("\n");
  
  return 0;
}


int Partition(p, r){
  int i, j, x, a;
  x = A[r];
  i = p-1;

  for(j = p; j <= r-1; j++){

    if(A[j]<=x){
      i++;
      a = A[i];
      A[i] = A[j];
      A[j] = a; 
    }

  }

  a = A[i+1];
  A[i+1] = A[r];
  A[r] = a; 
  return i+1;
    }

Measured memory_bytes: 992
import sys
N = int(raw_input())
row1 = raw_input()
row2 = raw_input()

power2 = 0
power3 = 0
# special handling for 1st column.
if row1[0] == row2[0]:
    power3 += 1
    i = 1
    previous_tate = True
else:
    power2 += 1
    power3 += 1
    i = 2
    previous_tate = False

while i < N:
    if row1[i] == row2[i]:
        # tate
        i += 1
        if previous_tate:
            power2 += 1
        previous_tate = True
    else:
        i += 2
        if not previous_tate:
            power3 += 1
        else:
            power2 += 1
        previous_tate = False
print (pow(2, power2) * pow(3, power3)) % 1000000007

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    s[0] = '2';
    s[1] = '0';
    s[2] = '1';
    s[3] = '8';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
#define pls(x,y) (((x)+(y)+P)%P)
#define mul(x,y) ((x)%P*(y)%P)
using namespace std;
const int N=100020;
int s[N][26],mnpos[26];
char str[N];
int main()
{
    for(int i=0;i<26;i++)mnpos[i]=N-1,s[N-1][i]=N;
    scanf("%s",str+1);
    int n=strlen(str+1);
    for(int i=1;i<=n;i++)
    {
        if(str[i]==str[i-1]){printf("%d %d",i-1,i);return 0;}
        else if(i>1&&str[i]==str[i-2]){printf("%d %d",i-2,i);return 0;}
    }
    printf("-1 -1");
    return 0;
}


Measured memory_bytes: 384
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    n: usize,
    d: i64,
    mut a1: [(i64, i64); n],
    }

    let mut cnt = 0;
    for a in a1 {
      if  a.0*a.0 + a.1*a.1 <= d * d {
        cnt +=1;
      }
      
    }

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


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

int main(){
    string s,t;
    cin >> s >> t ;
    int count = 0;
    for (int i = 0;i < s.size();i++){
        if (s[i] != t[i]){
            count++;
        }
    }
    cout << count << endl;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

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;
}

const int maxn = 200010;

bool dp1[maxn], dp2[maxn];
bool dp3[maxn], dp4[maxn];

int main() {
	int N, A, B, C, D;
	string S;
	cin >> N >> A >> B >> C >> D >> S;
	--A; --B;
	--C; --D;

	dp1[A] = dp3[B] = 1;
	rep(i, N) {
		if (i + 1 < N && S[i + 1] != '#') {
			dp1[i + 1] |= dp1[i];
			dp3[i + 1] |= dp3[i];
		}
		if (i + 2 < N && S[i + 2] != '#') {
			dp1[i + 2] |= dp1[i];
			dp3[i + 2] |= dp3[i];
		}		
	}

	dp2[C] = dp4[D] = 1;
	for (int i = N-1; i >= 0; --i) {
		if (i - 1 >= 0 && S[i - 1] != '#') {
			dp2[i - 1] |= dp2[i];
			dp4[i - 1] |= dp4[i];
		}
		if (i - 2 >= 0 && S[i - 2] != '#') {
			dp2[i - 2] |= dp2[i];
			dp4[i - 2] |= dp4[i];
		}	
	}
	if (C < D) {
		//puts("1");
		puts(dp1[C] && dp3[D] ? "Yes" : "No");
	} else {
		//puts("2");
		bool ok = 0;
		for (int i = B; i <= D; ++i) {
			if (dp2[i] && dp4[i] && dp1[i-1] && dp3[i+1]) {
				ok = 1;
			}
		}
		puts(ok ? "Yes" : "No");
	}

	return 0;
}

Measured memory_bytes: 1284
import java.util.Scanner;
import java.util.Date;


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

	String str=sc.next();

	for(int i=str.length()-1;i>=0;i--){
	    System.out.print(str.charAt(i));
	}
	System.out.println();
    }
}

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

int main(){
    string card_order, do_card;
    int shuffle_count, i, do_shuffle;

    while(1){
        cin >> card_order >> shuffle_count;
        if (card_order == "-") break;
        i = 0;
        while(i < shuffle_count){
            cin >> do_shuffle;
            do_card = card_order.substr(0, do_shuffle);
            card_order = card_order.erase(0, do_shuffle);
            card_order = card_order + do_card;
            i++;
        }
        cout << card_order << endl;
    }
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    string s;
    bool Y = false;
    rep(i, N){
        s = "";
        cin >> s;
        
        if (s == "Y")
        {
            Y = true;
        }
        
        
    }

    if (Y){
        cout << "Four" << endl;
    }
    else
    {
        cout << "Three" << endl;
    }
    
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
using namespace std;
int ta[26],ans=1;
signed main() {
	int n;
	string s;
	cin>>n>>s;
	rep(i,n){
		ta[s[i]-'a']++;
	}
	rep(i,26){
		ans*=ta[i]+1;
		ans%=mod;
	}
	cout<<ans-1<<endl;
	return 0;
}


Measured memory_bytes: 512
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    if((100*n)%108==0)  cout<<(100*n)/108<<endl;
    else{
        bool flag=false;
        for(int x=1;x<=n;x++){
            int p = int((double)x*1.08);
            if(p==n){
                cout<<x<<endl;
                return 0;
            }
        }
        if(!flag)   cout<<":("<<endl;
    }
    return 0;
}



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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    for(int i = 1; i <= 5; ++i) {
        int x; cin >> x;
        if(x == 0) cout << i << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 3652
import collections
import sys

def solve(n, A, B):
  ans = B[:]
  same = collections.deque()
  for i, (a, b) in enumerate(zip(A, B)):
    if a == b:
      if same and B[same[0]] != a:
        j = same.popleft()
        B[i], B[j] = B[j], B[i]
      else:
        same.append(i)
 # print(A)
  #print(B)
  #print(same)
  if same:
    s = A[same[0]]
    to_swap = []
    possible = False
    for i, (a, b) in enumerate(zip(A, B)):
      if a != s and b!=s:
        to_swap.append(i)
      if len(to_swap) == len(same):
        possible = True
        break
    if not possible:
      print('No')
      return
    for i, j in zip(same, to_swap):
      B[i], B[j] = B[j], B[i]
  print('Yes')
  print(' '.join(map(str, B)) )


       


def main():
  input = sys.stdin.readline
  n = int(input())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  solve(n, A, B)

main()


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

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

    if(a < b)
    cout << "a < b" << endl;
    else if(a > b)
    cout << "a > b" << endl;
    else if(a == b)
    cout << "a == b" << endl;
}


Measured memory_bytes: 3092
N, M = list(map(int, input().split()))


class UnionFind():
    def __init__(self, n):
        self.rank = [1 for _ in range(n)]
        self.parent = [i for i in range(n)]

    def union(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if self.rank[i] < self.rank[j]:
            self.parent[i] = j
        else:
            if self.rank[i] == self.rank[j]:
                self.rank[j] += 1
            self.parent[j] = i

    def same(self, i, j):
        return self.root(i) == self.root(j)

    def root(self, i):
        if self.parent[i] != i:
            self.parent[i] = self.root(self.parent[i])
        return self.parent[i]


uf = UnionFind(N)

for _ in range(M):
    X, Y, _ = list(map(int, input().split()))
    uf.union(X-1, Y-1)

ans = 0

for i in range(N):
    if uf.parent[i] == i:
        ans += 1

print(ans)


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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	char c;cin>>c;
	c++;
	cout<<c<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <climits>
#include <map>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <vector>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <utility>
#include <queue>
 
using namespace std;

#define ll long long
#define ulli  unsigned ll int
#define sl(n) scanf("%lld", &n)
#define sl2(a,b) scanf("%lld%lld", &a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld", &a,&b,&c)
#define VI  vector<int>
#define Vll  vector<ll>
#define all(v)  v.begin(),v.end()
#define ub(v,x)  upper_bound(all(v),x)

int st(int x,int pos){  return x= x |(1<<pos);}
int  Reset(int x,int pos ){ return x= x &~(1<<pos);}

#define  si(n) scanf("%d", &n)
#define  si2(a,b) scanf("%d%d", &a,&b)
#define  si3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define  sf(n) scanf("%lf", &n)
#define  pii pair <int, int>
#define  pll pair <ll, ll>
#define  plp pair <int, pll >
#define  pb push_back
#define  mkpr  make_pair
#define  ff   first
#define  ss  second
#define  srt(V)  sort(V.begin(),V.end());
#define  rsrt(V)  sort(V.rbegin(),V.rend());
#define  nl printf("\n");   
#define  PI  2*acos(0.0);
#define  INFP ((ll)1<<62)
#define  INFN (0-(ll)1<<62)
#define  loop(a,b)  for(int g=a;g<=b;g++)
#define  for1(n)  for(int i=0;i<n;i++)
#define  for2(n)  for(int j=0;j<n;j++)
#define  for3(n)  for(int k=0;k<n;k++)
#define  for4(n)  for(int l=0;l<n;l++)
#define  fr(i,a,b) for(int i=a;i<=b;i++)
#define  bug1(a)  cout<<a<<endl;
#define  bug2(a,b)  cout<<a<<" "<<b<<endl;
#define  bug3(a,b,c)  cout<<a<<" "<<b<<" "<<c<<endl;
#define  bug4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

#define  tst(n)  for(int cs=1;cs<=n;cs++)
#define  spc <<" "<<
#define  pys puts("Yes");
#define  pno  puts("No");
#define  bug puts("bug");
#define  pmn puts("-1");
#define  zero puts("0");
#define  limit 200006
#define  md 1000000007
#define  sq(n)  n*n





typedef pair<ll,ll> iPair;


int main()
{
 
               
     /*  freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
*/

       string A;

       cin>>A;
       ll n=A.size();
       bool no=false;

       for(ll i=0;i<n/2;i++)
       {

        if(A[i]!=A[n-i-1])no=true;


       }

       for(ll i=0;i<(n/4);i++)
       {
        //cout<<i<<" "<<(n/2)-i-1<<endl;


        if(A[i]!=A[(n/2)-i-1])no=true;

       }
       ll c=n-1;
       for(ll i=(n/2)+1;i<c;i++)

       {
        //cout<<i<<" "<<c<<endl;

        if(A[i]!=A[c])no=true;
        c--;
       }

       if(no)pno
        else pys

           




    

 

        /**
       *    @author     : Ikbal Hossain
       *    @University  : RUET CSE 15
       *    @CodeForces : iAmrifat
       *    @UVA        : rifat_ikbal
       *    @facebook   : https://www.facebook.com/ikbal.rifat.5
       */
 
      /* ll dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
      /* ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
      /* ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
      /* ll dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction
 
}
 
 
 


Measured memory_bytes: 3572
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            String S = sc.next();
        sc.close();
        
        int white = 0;
        int black = 0;
        int[] color = new int[N];
        String[] text = new String[N];

        for (int i = 0; i < N; i++) {
            text[i] = String.valueOf(S.charAt(i));
            if(i != 0 && text[i].equals("#")){
                black++;
                color[i] = color[i-1]+1;
            }else if(i == 0 && text[i].equals("#")){
                black++;
                color[i] = 1;
            }else if(i == 0 && text[i].equals(".")){
                white++;
                color[i] = 0;
            }else{
                white++;
                color[i] = color[i-1];
            }


            //System.out.println(color[i]);
        }

        //System.out.println(black);
        //System.out.println(white);


        int ans = 300000;
        int tmp= 0;
        for (int i = 0; i < N; i++) {
                int bb = color[i];
                int ww = (N-i-1) - (color[N-1] - color[i]);
                //System.out.println(bb);
                //System.out.println(ww);
                tmp = bb+ww;
                //System.out.println(tmp);

                if(ans > tmp){
                    ans = tmp;
                }
        }

        if(white == 0 || black == 0){
            System.out.println("0");
        }
        else if(N-color[N-1] < ans){
            System.out.println(N-color[N-1]);
        }
        else{
            System.out.println(ans);
        }

    }
}


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

using namespace std;
#define set_precision(ans,l) cout << fixed << setprecision(l)<<ans;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<ll>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<ll>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long double EPS = 1e-9;

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,ll b){return((a-1)/b+1);} 
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll po(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1){ans=(ans*x)%mod;}
        y>>=1;x=(x*x)%mod;
    }
    return ans;
}

int main()
{
    FIO;
    ll n,t,x,y,m,k;
    cin>>n>>x>>y;
    x*y>=n?cout<<"Yes":cout<<"No";
    return 0;
}

Measured memory_bytes: 3636
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			// solveB();
			// solveC();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numX = Integer.parseInt(next());
		int numY = Integer.parseInt(next());

		out.print(numX + numY / 2);

		out.println("");
	}

	private void solveB() {
		int numN = Integer.parseInt(next());

		out.println("");
	}

	private void solveC() {
		int numN = Integer.parseInt(next());

		out.println("");
	}

	private void solveD() {
		int numN = Integer.parseInt(next());

		out.println("");
	}

	private void solveE() {
		int numN = Integer.parseInt(next());

		out.println("");
	}

	private void solveF() {
		int numN = Integer.parseInt(next());

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21076
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
vector<vector<int> > G(100005);
int N, K;
int ans;
bool checked[100005];
// ??¨??????????????????????????????????????¢
int dfs(int v, int s) {
  int ret = 1e9;
  checked[v] = true;
  if(G[v].size() == 0) {
    ans++;
    return 1;
  }
  for(auto to : G[v]) {
    ret = min(ret, dfs(to, s));
  }
  if(ret < K && v != s) ans++;
  return ret + 1;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  int st;
  FOR(i,1,N+1) {
    int in; cin >> in;
    G[in].push_back(i);
  }
  FOR(i,1,N+1){
    if(checked[i]) continue;
    if(dfs(i, i) != 1) ans ++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13108
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,q;cin>>n>>q;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    int par[n+1],son[n+1],a[n+2];
    rep(i,n)cin>>a[i+1];
    a[0]=a[n+1]=0;
    rep(i,n+1){
        par[a[i+1]]=a[i];
        son[a[i]]=a[i+1];
    }
    rep(j,q){
        int x;cin>>x;
        if(par[x]!=0&&son[x]!=0){
        swap(son[par[x]],son[par[0]]);
        swap(par[son[x]],par[son[0]]);
        swap(son[x],son[0]);
        swap(par[x],par[0]);
        }
        else if(par[x]==0){
            par[x]=par[0];
            son[0]=son[x];
            par[0]=x;
            son[x]=0;
            son[par[x]]=x;
            par[son[0]]=0;
        }
        else if(son[x]==0){
            son[x]=son[0];
            par[0]=par[x];
            par[x]=0;
            son[0]=x;
            son[par[0]]=0;
            par[son[x]]=x;
            
        }
    }
    int ret=0;
    rep(i,n){
        cout<<son[ret];
        ret=son[ret];
        if(i!=n-1)cout<<" ";
    }
    cout<<endl;
    return 0;
}


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

int main() {
  int n, m; cin >> n >> m;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  vector<int> c = convolution(a, b);
  for (int i = 0; i < c.size(); i++) cout << c[i] << " ";
  cout << endl;
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	ll a, b, c; scanf("%lld%lld%lld", &a, &b, &c);
	if(4*a*b < (c-a-b) * (c-a-b) && c-a-b > 0){
		printf("Yes\n");
	} else {
		printf("No\n");
	}
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define endl "\n"
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i = 0;
    int j = n - 1;
    int cnt = 0;
    while (i < n && j >= 0 && i < j)
    {
        while (i < n && s[i] == 'R')
        {
            ++i;
        }
        while (j >= 0 && s[j] == 'W')
        {
            --j;
        }
        if (i < n && j >= 0 && i < j)
        {
            swap(s[i], s[j]);
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define MEM(a, x) memset(a, x, sizeof a)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T> void dbg(T &x) {cerr << x << endl;}
template<typename T> void dbga(T &x, int &n) {for(int i = 0; i < n; i++) {cerr << i << ": "; cerr << x[i] << endl;} }
template<typename T> void dbgv(T &x) {bool first = true; cerr << "{"; for(auto i : x) {if(!first) cerr << ","; cerr << i; first = false;} cerr << "}" << endl;}

struct Meal {
	int t, h;

	bool operator < (const Meal& m) {
		if(t == m.t)
			return h < m.h;
		return t < m.t;
	}
};

int n, t;
Meal a[3005];
int dp[3005][3005]; // idx, time

int solve(int idx, int t) {
	if(t <= 0 || idx >= n)
		return 0;

	int &ret = dp[idx][t];

	if(ret != -1)
		return ret;

	return ret = max(solve(idx+1, t), a[idx].h + solve(idx+1, t - a[idx].t));
}

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

	cin >> n >> t;
	for(int i = 0; i < n; i++)
		cin >> a[i].t >> a[i].h;

	sort(a, a+n);

	MEM(dp, -1);
	int ans = solve(0, t);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 35712
from collections import deque
while 1:
    n,a,b,c,x=map(int,input().split())
    if n==a==b==c==x==0:break
    y=list(map(int,input().split()))
    y_q=deque(y)
    t=0
    while t<10001:
        if x==y_q[0]:y_q.popleft()
        if len(y_q)==0:break
        t+=1
        x=(a*x+b)%c
    if t>10000:print(-1)
    else:print(t)


Measured memory_bytes: 5992
import sys
import math
import itertools

s=input()
year=int(s[0:4])
if not s[5]=="0":
	month=int(s[5:7])
else :
	month=int(s[6])
day=int(s[8:10])
if year>=2020:
	print("TBD")
elif year<=2018:
	print("Heisei")
elif month>=5:
	print("TBD")
else :
	print("Heisei")

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

using namespace std;

string a[3] = {"Sunny", "Cloudy", "Rainy"};

int main() {
	string s;
    cin >> s;
    for(int i=0;i<3;++i) if( a[i] == s ) cout << a[(i+1)%3] << endl;
	return 0;
}

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

#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
	int n,x;
	int ans;
	int tmp;
	
	cin >> n >> x;
	
	int L[n];
	
	for(int i=0; i<n; i++){
		cin >> L[i];
	}
	
	ans=1;
	tmp=0;
	for(int i=0; i<n; i++){
		tmp+=L[i];
		
		if(tmp>x)	break;
		else	ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N+1, 0), b(N+1, 0);
  
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) cin >> b[i];
  
  vector<int> s(N+1, 0), t(N+1, 0);
  for (int i = 0; i < N; i++){
    s[i+1] = s[i] + a[i];
    t[i+1] = t[i] + b[i];
  }
  
  int ans = 0;
  
  for (int i = 1; i < N+1; i++) {
    int ame = s[i] - s[0] + t[N] - t[i-1];
    
    if (ame > ans) ans = ame;  
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<int,int>

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

    ll n;
    cin>>n;
    string s="";
    if(n==0){cout<<"0";return(0);}
    while(n!=0)
    {
        int r=n%(-2);
        n/=(-2);
        if(r<0){r+=2;++n;}
        if(r==0){s+='0';}
        else{s+='1';}
    }
    reverse(s.begin(),s.end());
    cout<<s;

return(0);
}

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

int main(){
  ll h;
  cin >> h;
  ll ans = 0;
  while(1){
    ans++;
    if (h > 1) ans *= 2;
    else break;
    h /= 2;
  }  
  
  cout << ans << endl;
  
  return 0;
}

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< ll > x(n), y(n);
  for (int i=0; i<n; ++i) cin >> x[i] >> y[i];
  int ans = 0;

  for (int i=0; i<n; ++i) {
    for (int j=i+1; j<n; ++j) {
      ll p=x[i]-x[j], q=y[i]-y[j];
      int cur = 0;
      for (int k=0; k<n; ++k) {
        for (int l=0; l<n; ++l) {
          if (x[k]-x[l]==p && y[k]-y[l]==q) cur++;
          else if (x[l]-x[k]==p && y[l]-y[k]==q) cur++;
        }
      }
      ans = max(ans, cur);
    }
  }
  cout << n-ans/2 << endl;
  return 0;
}


Measured memory_bytes: 256