akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S1, S2;
  cin >> S1 >> S2;
  ll ans = 1;
  int idx = 0;
  bool flg_1 = false, flg_2 = false;
  if (S1[0] == S2[0])
  {
    flg_1 = true;
    ans *= 3;
    idx++;
  }
  else
  {
    flg_2 = true;
    ans *= 3*2;
    idx += 2;
  }
  while(idx < N)
  {
    if (S1[idx] == S2[idx])
    {
      flg_2 = false;
      if (flg_1) ans *= 2;
      else flg_1 = true;
      idx++;
    }
    else
    {
      flg_1 = false;
      if (flg_2) ans *= 3;
      else
      {
        flg_2 = true;
        ans *= 2;
      }
      idx += 2;
    }
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:String,
    }
    let mut a=a.chars().collect_vec();
    let mut b=0;
    for i in 0..6 {
        if a[i]=='1'{b+=1}
    }
    println!("{}",b)
}

Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const long long mod = 1e9 + 7;
//木構造
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p)
{
    for (int u : to[v])
    {
        if (u == p)
            continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}
int main()
{
    int n, q;
    cin >> n >> q;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        //双方向の辺
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i, q)
    {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0, -1);
    rep(i, n)
    {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 23552
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int num[50];
int main()
{
	int n,a,x=0,y=0;
	cin>>n;
	memset(num,0,sizeof(num));
	rep(i,n){
		cin>>a;
		if(a>=3200) x++;
		else num[a/400]++;
	}
	rep(i,10){
		if(num[i]>0) y++;
	}
	if(y==0) cout<<1<<' '<<x<<endl;
	else cout<<y<<' '<<x+y<<endl;
}


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

int q,n;
struct Node{
    int p,id;
    bool operator < (const Node & x) const{
        int t = p,t2 = x.p;
        if(id == 0) t *= 8;
        else if(id == 1) t *= 4;
        else if(id == 2) t *= 2;
        if(x.id == 0) t2 *= 8;
        else if(x.id == 1) t2 *= 4;
        else if(x.id == 2) t2 *= 2;
        return t < t2;
    }
}t[4];

int main(){
    cin >> t[0].p >> t[1].p >> t[2].p >> t[3].p >> n;
    t[0].id = 0;t[1].id = 1;t[2].id = 2;t[3].id = 3;
    sort(t,t+4);
//    printf("//%d %d %d %d\n",t[0].id,t[1].id,t[2].id,t[3].id);
    if(t[0].id <= 2){
        if(t[0].id == 0) cout << 1LL * t[0].p * 4 * n << endl;
        else if(t[0].id == 1) cout << 1LL * t[0].p * 2 * n << endl;
        else if(t[0].id == 2) cout << 1LL * t[0].p * n << endl;
    }
    else{
        long long ans = n / 2 * 1LL * t[0].p;
        if(n & 1){
            if(t[1].id == 0) ans += 1LL * t[1].p * 4;
            else if(t[1].id == 1) ans += 1LL * t[1].p * 2;
            else if(t[1].id == 2) ans += 1LL * t[1].p;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define ull unsigned long long
using namespace std;
const ull nmax = 100100;
ull pr[nmax];
int main()
{
    pr[2] = 0;
    for(ull i= 2;i<nmax;++i)
    {
        if(pr[i]==2) continue;
        for(ull j = i; i*j<nmax;++j)
        {
            pr[i*j] = 2;
        }
        if((i&1) && pr[(i+1)/2] != 2)
            pr[i] = 1;
    }

    for(int i=2;i<nmax;++i)
    {
        if(pr[i]==1) pr[i]+=pr[i-1];
        else pr[i]+=pr[i-1]-pr[i];
    }
    int q,l,r;
    cin >> q;
    for(int i= 0; i< q;++i)
    {
        cin >> l >> r;
        cout << pr[r]-pr[l-1] << endl;
    }
}

Measured memory_bytes: 1408
<?php
 fscanf(STDIN,'%d',$A);
 fscanf(STDIN,'%d',$B);
 fscanf(STDIN,'%d',$C);
 fscanf(STDIN,'%d',$X);
 $zan1=0;
 $j=0;
for ($c500=0; $c500 <=$A ; $c500++) {
  // code...
  $zan1=$X-$c500*500;
  if($zan1<0){
    break;
  }
  for ($c100=0; $c100 <=$B ; $c100++) {
    // code...
    $zan2=$zan1-$c100*100;
    if($zan2<0){
      break;
    }
    if($zan2%50==0 or $zan2==0){
      if($zan2/50<=$C){
        $j++;
      }
    }
  }
}
echo $j;
echo "\n";

 ?>


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

int main(){

    int day=0, money=0, a, b, goal;
    cin >> a >> b >> goal ;

    while (money < goal){
        day += 1;
        money += a;
        if (day % 7 == 0)money += b;
    }

    cout << day << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

long long N;
long long num[210000];

int main() {
  while (cin >> N) {
	long long sum = 0;
	for (int i = 0; i < N; ++i) cin >> num[i], sum += num[i];
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i) {
	  int a, b;
	  cin >> a >> b;
	  --a;
	  int dif = b - num[a];
	  cout << sum + dif << endl;
	}
  }
}
	


Measured memory_bytes: 256
def merge(A, left, mid, right):
    global c
    n1 = mid - left
    n2 = right - mid
    L = [0 for e in range(n1+1)]
    R = [0 for e in range(n2+1)]
    L = A[left:mid] + [10 ** 9]
    R = A[mid:right] + [10 ** 9]
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
          A[k] = L[i]
          i = i + 1
        else:
          A[k] = R[j]
          j = j + 1
    c += right - left

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

if __name__ == "__main__":
    n = int(input())
    S = [int(e) for e in input().split()]
    c = 0
    mergeSort(S,0,n)
    print(*S)
    print(c)


Measured memory_bytes: 63700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N,K,S;
    cin >> N >> K >> S;

    vector<ll> a(N);

    if(S < (ll)1e9){
        rep(i,N){
            if(i < K){
                a[i] = S;
            }else{
                a[i] = (ll)1e9;
            }
        }
    }else{
        rep(i,N){
            if(i < K){
                a[i] = (ll)1e9;
            }else{
                a[i] = 1;
            }
        }
    }

    rep(i,N){
        cout << a[i] << ' ';
    }

    cout << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int x,y,r;
int main() {
  scanf("%d%d",&x,&y);
  if (x<4) r+=100000*(4-x);
  if (y<4) r+=100000*(4-y);
  if (x==1 && y==1) r+=400000;
  printf("%d\n",r);
  return 0;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/dp/tasks/dp_p
//木DP
//https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
vector<vector<LL>> adj_list;//隣接リスト

LL ans = 0;

//dp[頂点番号][その頂点の状態]
//dp[i][j]=(頂点iを(j?黒く:白く)塗ったとき、iを親とする部分木の塗り方の場合の数)
vector<vector<LL>> dp;
//flag[i]=頂点iをもう見たかどうか
vector<bool> flag;

//メモ化再帰
void mem_rec(LL i){
	if(flag[i])return;//頂点iをもう見たならreturn
	flag[i]=1;
	dp[i][0]=1;
	dp[i][1]=1;
	for(LL j : adj_list[i]){
		if(flag[j]) continue;//頂点jをもう見たなら飛ばす
		mem_rec(j);
		//頂点iを白く塗った時
		dp[i][0]=(dp[i][0]*((dp[j][0]+dp[j][1])%mod_int))%mod_int;
		//頂点iを黒く塗った時
		dp[i][1]=(dp[i][1]*dp[j][0])%mod_int;
	}
}

void solve(){
	dp = vector<vector<LL>>(N,vector<LL>(2,0));
	flag = vector<bool>(N,false);
	mem_rec(0);//dp[0][0]とdp[0][1]を求める
	ans = (dp[0][0]+dp[0][1])%mod_int;
	//ans 
	//    =頂点0を黒く(1)塗った時、頂点0を親とする部分木の塗り方の場合の数
	//         + 頂点0を白く(0)塗った時、頂点0を親とする部分木の塗り方の場合の数
}
 
int main(){
	cin >> N;
	adj_list = vector<vector<LL>>(N);
	for(int i=0;i<N-1;i++){
		LL x,y;
		cin >> x >> y;
		x--;y--;
		adj_list[x].push_back(y);
		adj_list[y].push_back(x);
	}
 
	solve();

	cout << ans << endl;
	return 0;
}

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

#define f(i,a,b) for (int i = a; i < b; i++)

const int mxn = 3e6;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n; cin >> n;
	int a[n];
	f(i,0,n) cin>>a[i];
	sort(a,a+n);
	bitset<mxn> dp;	
	dp[0] = 1;
	f(i,0,n) dp = dp | (dp<<a[i]);		
	int S = 0;
	f(i,0,n) S += a[i];
	f(j,S/2+(S&1),mxn) if (dp[j]) {
		cout << j << endl;
		break;
	}

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 1792
//package atcoder;

import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			int N= sc.nextInt();	
			int D = sc.nextInt();
			
	
			int count = 1;
			int A = (2*D+1)*1;
		while(A<N) {
			count ++;
			A = (2*D+1)*count;
			
		}
		
		System.out.println(count);
	}		
}

Measured memory_bytes: 23252
/*
- About Touhou Project -
The Touhou Project is a series of 2D (with 3D background)
vertically-scrolling danmaku shooting games made by Team
Shanghai Alice, with three fighting game spinoffs co-produced
with Tasogare Frontier. They are similar to regular shooting
games, but focus more on weaving through complex patterns
containing anywhere from dozens to hundreds of bullets.
Every game in the Touhou series is set in the fantasy land of
Gensokyo, and the series is known for its huge cast of
characters, well-developed storylines, and related materials
such as music CDs, fan-made comics and animated videos made to
the music.
*/
#include <bits/stdc++.h>
using namespace std;

int main(){
    int x[100],n;
    for(n=0;1;n++){
        cin>>x[n];
        if(x[n]==0)break;
    }
    n-=1;//n=(num)-1
    int map[9][9];//map[x][y]
    for(int k=0;k<=n;k++){
        //calculation
        int y=1;
        for(int i=0;i<x[k];i++){//x+y
            for(int j=0;j<=i;j++){//x
                if(i%2)map[j][i-j]=y;
                else map[i-j][j]=y;
                y++;
            }
        }
        for(int i=x[k];i<x[k]*2-1;i++){//x+y
            for(int j=i-x[k]+1;j<x[k];j++){//x
                if(i%2)map[j][i-j]=y;
                else map[i-j][j]=y;
                y++;
            }
        }
        //writing
        cout<<"Case "<<k+1<<":"<<endl;
        //(x[k],x[k])
        for(int i=0;i<x[k];i++){
            for(int j=0;j<x[k];j++){
                if(map[i][j]>9)cout<<" "<<map[i][j];
                else cout<<"  "<<map[i][j];
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
string s1, s2;
int n;
int main(){
  // freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    cin >> s1 >> s2;
    int i = 0;
    ll ans = 1LL;
    int fg;
    if(s1[0] == s2[0]) {ans = 3;i=1;fg = 1;}
    else {ans = 6;i=2;fg = 2;}
    for(; i < n;){
        if(fg == 1){
            if(s1[i] == s2[i]){
                fg = 1;
                i++;
            }
            else{
                i+=2;
                fg = 2;
            }
            ans = ans * 2 % mod;
        }
        else{
            if(s1[i] == s2[i]){
                fg = 1;
                i++;
            }
            else{
                i+=2;
                fg = 2;
                ans = ans * 3 % mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void Printfff(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    printf("%d", A[i]);
    if ( i < n-1 ) printf(" ");
  } 
  printf("\n");
}

void insertionSort(int A[], int n){
  int v, i, j;
  for ( i = 1; i < n; i++ ) {
    v = A[i];
    j = i - 1;
    while ( j >= 0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  Printfff(A, n);
  }
}

int main(){

  int n, i;
  int A[100];

  scanf("%d", &n);
  for ( i = 0; i < n; i++) scanf("%d", &A[i]);

  Printfff(A, n);
  insertionSort(A, n);


  return 0;
}
  

Measured memory_bytes: 1764
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n ;
    string s;
    cin >> s;
    ll ans[n+1];
    memset(ans, 0, sizeof(ans));
    for(int i=1;i<=n;i++){
    	ll num = __builtin_popcount(i);
    	ans[i] = ans[i % num] + 1;
    }
    ll num = 0;
    for(int i=0;i<n;i++){
    	if(s[i] == '1') num++;
    }    	
    if(num == 0){
    	for(int i=0;i<n;i++) cout << 1 << endl;
    	return 0;
    }
    if(num == 1){
    	num++;
    	if(s[n-1] == '1'){
    		for(int i=0;i<n-1;i++){
    			cout << 2 << endl;
    		}
    		cout << 0 << endl;
    		return 0;
    	}

    	for(int i=0;i<n;i++){
    		if(s[i] == '1'){
    			cout << 0 << endl;
    		}else{
    			if(i == n - 1) cout << 2 << endl;
    			else cout << 1 << endl;
    		}
    	}
    	return 0;
    }


    ll mi = num - 1 , ma = num + 1;
    ll dmi = 0, dma = 0;
    for(int i=0;i<n;i++){
    	dmi *= 2;
    	dma *= 2;
    	dmi %= mi;
    	dma %= ma;
    	if(s[i] == '1'){
    		dmi++;
    		dma++;
    		//cout << dmi << " " << dma << endl;
    	}
    	dmi %= mi;
    	dma %= ma;
    }
    
    vector<ll> v;
    ll emi = 1, ema = 1;
    for(int i= n-1;i >= 0;i--){
    	if(s[i] == '1'){
    		ll unchi = dmi - emi;
    		unchi %= mi;
    		unchi += mi;
    		unchi %= mi;
    	    v.pb(ans[unchi] + 1);
    	}else{
    		v.pb(ans[(dma + ema) % ma] + 1);
    	}
    	emi *= 2;
    	emi %= mi;
    	ema *= 2;
    	ema %= ma;
    }
    reverse(be(v));
    for(auto& i : v){
    	cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 6956
#  --*-coding:utf-8-*--

def main():
    K,X = map(int, input().split())
    P = max(-1000000, X-(K-1))
    Q = min(1000000, X+(K-1))

    print(' '.join(map(str, [k for k in range(P, Q+1)])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let q: usize = input();
    let qs: Vec<Query> = (0..q)
        .map(|_| {
            let i: i32 = input();
            if i == 1 {
                Query::Q1(input(), input())
            } else {
                Query::Q2
            }
        })
        .collect();

    let mut xs = vec![i64::min_value(), i64::max_value()];
    for &q in &qs {
        if let Query::Q1(a, _) = q {
            xs.push(a);
        }
    }
    xs.sort();
    xs.dedup();
    let n = xs.len();

    let mut num = FenwickTree::new(n);
    let mut val = FenwickTree::new(n);
    let mut bsum = 0;

    for q in qs {
        if let Query::Q1(a, b) = q {
            let p = xs.lower_bound(&a);
            num.add(p, 1);
            val.add(p, xs[p]);
            bsum += b;
        } else {
            let nx = (num.sum(n) + 1) / 2;
            let med = num.lower_bound(&nx);
            let nl = num.sum(med - 1);
            let nr = num.sum(n) - num.sum(med);
            let vl = nl * xs[med] - val.sum(med - 1);
            let vr = val.sum(n) - val.sum(med) - nr * xs[med];
            println!("{} {}", xs[med], vl + vr + bsum);
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
enum Query {
    Q1(i64, i64),
    Q2,
}

trait LowerBound<T: Ord> {
    fn lower_bound(&self, x: &T) -> usize;
}

impl<T: Ord> LowerBound<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut l = -1 as i64;
        let mut r = self.len() as i64;
        while r - l > 1 {
            let m = ((l + r) / 2) as usize;
            if self[m] >= *x {
                r = m as i64;
            } else {
                l = m as i64;
            }
        }
        r as usize
    }
}

#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
struct FenwickTree(Vec<i64>);

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

    fn add(&mut self, i: usize, v: i64) {
        let n = self.0.len() as i64;
        let mut i = i as i64;
        while i < n {
            self.0[i as usize] += v;
            i += i & -i;
        }
    }

    fn sum(&self, i: usize) -> i64 {
        let mut i = i as i64;
        let mut r = 0;
        while i > 0 {
            r += self.0[i as usize];
            i -= i & -i;
        }
        r
    }

    fn lower_bound(&self, x: &i64) -> usize {
        let n = self.0.len();
        let mut k = 1;
        while k * 2 < n {
            k *= 2;
        }

        let mut i = 0;
        let mut x = *x;
        while k > 0 {
            if i + k < n && self.0[i + k] < x {
                x -= self.0[i + k];
                i += k;
            }
            k /= 2;
        }
        i + 1
    }
}


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

int main () {
  int H, W;
  cin >> H >> W;
  vector<vector<char> > s;
  s.resize(H+1);
  for (int i = 0; i < H; i ++ ) {
    s[i].resize(W+1);
    for (int j = 0; j < W; j++ ) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < (H+1); i++) {
    if (i == (H)) {
      s[i].resize(W+1);  
    }  
    if (i == H ) {
      for (int j = 0; j < (W+1); j++) {
        s[i][j] = '.';  
      }
    }
    else {
      s[i][W] = '.';  
    }
  } 

  bool forEnd = false;
  int iterator[4] = {0,0,0,0};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      iterator[0] = (i == 0) ? (H) : (i-1);
      iterator[1] = (i == (H-1)) ? H : (i + 1);
      iterator[2] = (j == 0) ? (W) : (j-1);
      iterator[3] = (j == (W-1)) ? W : (j + 1);
      if (s[i][j] == '#') {
        if(s[i][j] == s[iterator[0]][j] || s[i][j] == s[iterator[1]][j] || s[i][iterator[2]] == s[i][j] || s[i][j] == s[i][iterator[3]] ) {
             
        }
        else {
          forEnd = true;
          break;
        }
      }
      if (forEnd) {
        break;  
      }
    }
  }

  if (forEnd) {
    cout << "No" << endl;  
  }
  else {
    cout << "Yes" << endl;  
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int a,b;

    scanf("%d %d", &a, &b);

    if(a<b){
    	printf("a < b\n");
    } else if(a>b) {
    	printf("a > b\n");
    } else {
    	printf("a == b\n");
    }

    return 0;
}

Measured memory_bytes: 580
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

int main(void){
	int n,i;
	ll a[123456],ans=0ll;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	a[n] = 0ll;
	for(i=1; i<=n; ++i){
		if(a[i]){
			a[i] += a[i-1];
		}else{
			a[i] += a[i-1];
			ans += a[i]/2;
			a[i] = 0ll;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	int ans = 0;
	while (N)
	{
		if (N % 10 == 2)
		{
			++ans;
		}
		N /= 10;
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

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

int main() {
    //
    long long num;
    long long cnt = 0;
    cin >> num;

    // 奇数
    if (num % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    num /= 2;
    while (num > 0) {
        cnt += num / 5;
        num /= 5;
    }

    cout << cnt << endl;

    //
}

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

if __name__ == '__main__':
    print(" ".join(map(str, A)))
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
            A[j+1] = v
        print(" ".join(map(str, A)))


Measured memory_bytes: 5600
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int,int> P;

bool comp(P a, P b) {
    if (a.second > b.second)
        return true;
    else if (a.second == b.second && a.first > b.first)
        return true;
    else
    {
            return false;
    }
    
} 

int main() {
    int n;  cin >> n;
    P *ab = new P[n];
    for (int i = 0; i < n; i++)
        cin >> ab[i].first >> ab[i].second;
    
    P *cd = new P[n];
    for (int i = 0; i < n; i++)
        cin >> cd[i].first >> cd[i].second;

    sort(ab, ab+n, comp);
    sort(cd, cd+n);

    int ans = 0;
    vector<bool> check(n, false);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (ab[j].first < cd[i].first && ab[j].second < cd[i].second && !check[j]) {
                check[j] = true;
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;    
}

Measured memory_bytes: 256
h,w=map(int,input().split())
c=[]
c.append("."*(w+2))
for i in range(h):
    c.append(".{}.".format(input()))
c.append("."*(w+2))
for i in range(1,h+1):
    for j in range(1,w+1):
        if c[i][j]=="#" and c[i-1][j] ==c[i][j-1] ==c[i+1][j]==c[i][j+1]==".":
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3064
#include<cstdio> 
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<iostream>
#define ll long long
int main()
{
	ll a,b,k,n,i;
	ll x,y;
	ll sum=0;
	scanf("%lld%lld",&n,&k);
	if(k==0)		//分开考虑，如果一起考虑，会出错误 
	{
		printf("%lld\n",n*n);
		return 0;
	}
	for(b=k+1;b<=n;b++)
	{
		x=b-k;			//从k到b-1总共多少个数,这也是a<b的情况】
		//从上面那个式子可以推出1---b一共有x个数；显然这个可以联想到1--n
		//联想有多少个b就是n/b;然后再判断就行了
		// 1-b有x是的，所以有b-x个数字不是的，这个方便等下处理最后几位数字
		 sum+=n/b*x;		
		 //最后还剩下n%b个数；
		 if(n%b>b-x-1)	//防止加个负数
		 	sum+=n%b-b+1+x; 
	//	printf("b-%d  sum-%d\n",b,sum);
	}
	printf("%lld\n",sum);
	return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m ;
    int l[m], r[m];
    int left, right;

    for (int i=0; i < m; i++) {
      cin >> l[i] >> r[i];
    }

    int count = 0;
    for (int j=0; j < m; j++) {
      if (j == 0) {
        left = l[0];
        right = r[0];
      }
      if (j > 0) { // 2nd iteration
        if (l[j] > left) {
          left = l[j];
        }
        if (r[j] < right) {
          right = r[j];
        }
      }
    }

    if (right == left || right > left) {
      printf("%d", right - left + 1);
    } else {
      printf("0");
    }

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;

struct node{
	int x,y;
	int dir;
}p[N];

bool cmp1(node a,node b){
	if(a.x!=b.x)return a.x<b.x;
	return a.y<b.y;
}
bool cmp2(node a,node b){
	if(a.y!=b.y)return a.y<b.y;
	return a.x<b.x;
}
bool cmp3(node a,node b){
	if(a.x-a.y==b.x-b.y)return a.x<b.x;
	return a.x-a.y<b.x-b.y;
}
bool cmp4(node a,node b){
	if(a.x+a.y==b.x+b.y)return a.x<b.x;
	return a.x-a.y<b.x-b.y;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		char ch;
		scanf("%d %d %c",&p[i].x,&p[i].y,&ch);
		if(ch=='U')p[i].dir=1;
		if(ch=='R')p[i].dir=2;
		if(ch=='D')p[i].dir=3;
		if(ch=='L')p[i].dir=4;
	}
//	cout<<endl;
//	for(int i=1;i<=n;i++)
//		cout<<p[i].x<<" "<<p[i].y<<" "<<p[i].dir<<endl;
	
	map<pair<int,int>,int>mp;
	int f=0,ans=0x3f3f3f3f;
	
	sort(p+1,p+1+n,cmp1); //U D
	for(int i=1;i<=n;i++){
		if(p[i].dir==3&&mp[{p[i].x,1}]){
			f=1;
			ans=min(ans,(p[i].y-p[mp[{p[i].x,1}]].y)*5);
		}
		mp[{p[i].x,p[i].dir}]=i;
	}
	
	sort(p+1,p+1+n,cmp2); //L R
	mp.clear();
	for(int i=1;i<=n;i++){
		if(p[i].dir==4&&mp[{p[i].y,2}]){
			f=1;
			ans=min(ans,(p[i].x-p[mp[{p[i].y,2}]].x)*5);
		}
		mp[{p[i].y,p[i].dir}]=i;
	}
	
	sort(p+1,p+1+n,cmp3); // k=1
	mp.clear();
	for(int i=1;i<=n;i++){
		if(p[i].dir==3&&mp[{p[i].x-p[i].y,2}]){
			f=1;
			ans=min(ans,(p[i].x-p[mp[{p[i].x-p[i].y,2}]].x)*10);
		}
		if(p[i].dir==4&&mp[{p[i].x-p[i].y,1}]){
			f=1;
			ans=min(ans,(p[i].x-p[mp[{p[i].x-p[i].y,1}]].x)*10);
		}
		mp[{p[i].x-p[i].y,p[i].dir}]=i;
	}
	
	sort(p+1,p+1+n,cmp4);//k=-1
	mp.clear();
	for(int i=1;i<=n;i++){
		if(p[i].dir==1&&mp[{p[i].x+p[i].y,2}]){
			f=1;
			ans=min(ans,(p[i].x-p[mp[{p[i].x+p[i].y,2}]].x)*10);
		}
		if(p[i].dir==4&&mp[{p[i].x+p[i].y,3}]){
			f=1;
			ans=min(ans,(p[i].x-p[mp[{p[i].x+p[i].y,3}]].x)*10);
		}
		mp[{p[i].x+p[i].y,p[i].dir}]=i;		
	}
	
	if(f)printf("%d\n",ans);
	else printf("SAFE\n");
	
	return 0;
} 

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

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

  long result = 0;
  long t;
  long a, b, odr;
  
  if (n%2 == 0) {
    //
    odr = 1;
    a = n/5;
    do {
      b = a/5;
      //cout << a << " " << b << " " << odr << endl;
      result += odr * (a/2 - b/2);
      a = b;
      odr++;
    } while (b > 0);
  }
  cout << result << endl;
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
      string[] input = Console.ReadLine().Split(' ');
      int H = int.Parse(input[0]);
      int W = int.Parse(input[1]);
      string[] a = new string[H];
      for (int i=0; i<H; i++)
      {
        a[i] = Console.ReadLine();
      }
      string tmp = new string('#', W+2);
      Console.WriteLine(tmp);
      for (int i=0; i<H; i++)
      {
        Console.WriteLine("#" + a[i] + "#");
      }
      Console.WriteLine(tmp);
    }
}

Measured memory_bytes: 11092
use std::io::*;
use std::str::*;
use std::cmp::Ordering;
 
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
 
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
 
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
 
fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}
 
fn main() {
    let n: usize = read().unwrap();
    let mut a: Vec<i64> = Vec::new();
 
    for i in 0..n {
        a.push(read().unwrap());
    }
    a.sort_by_key(|&num| Rev(num));
 
    let mut alice_score = 0;
    let mut bob_score = 0;
    for (j, ai) in a.iter().enumerate() {
        if j % 2 == 0 {
            alice_score += *ai;
        } else {
            bob_score += *ai;
        }
    }
 
    println!("{}", alice_score - bob_score);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

void insertion (vector<int> &a, int n, int g, int &cnt) {
    rep (i, g, n) {
        int v = a[i];
        int j = i - g;
        while (j >= 0 && a[j] > v) {
            a[j + g] = a[j];
            j -= g;
            cnt++;
        }
        a[j + g] = v;
        // rep (i, 0, n) cout << " " << a[i];
        // cout << "\n";
    }
}

void shellsort (vector<int> &a, int n) {
    int cnt = 0;
    vector<int> shellsize;
    for (int i = 1; i <= n; (i *= 3)++) shellsize.emplace_back (i);
    int m = shellsize.size();
    cout << m << "\n";
    per (i, 0, m) {
        if (i != m - 1) cout << " ";
        cout << shellsize[i];
        insertion (a, n, shellsize[i], cnt);
    }
    cout << "\n" << cnt << "\n";
}

int main() {
    int n;
    cin >> n;
    vector<int> a (n);
    rep (i, 0, n) cin >> a[i];
    shellsort (a, n);
    rep (i, 0, n) cout << a[i] << "\n";
}


Measured memory_bytes: 6780
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s,t;
int k;
vector <string> v;

int main()
{
	cin>>s>>k;
	int sz=s.size();
	rep(i,sz)
	{
		t="";
		for(int j=i;j<sz&&j-i<k;j++)
		{
			t.pb(s[j]);
			v.pb(t);
		}
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	cout<<v[k-1]<<endl;
	rt0;
}

Measured memory_bytes: 1660
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [input().rstrip()[:-1] for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    if n == 0:
        return False
    group = set()
    go_group = set()
    member = set()
    d = defaultdict(int)
    g = SR(n)
    for gi in g:
        group.add(gi.split(":")[0])
        d[gi.split(":")[0]] = gi.split(":")[1].split(",")
    C = defaultdict(int)
    def s(g):
        for gi in g:
            if gi in group:
                if C[gi]:
                    continue
                C[gi] = 1
                s(d[gi])
            else:
                member.add(gi)
    s(d[g[0].split(":")[0]])
    print(len(member))
    return True

#main
if __name__ == '__main__':
    while solve():
        pass



Measured memory_bytes: 8964
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    ll x, y;
    cin >> x >> y;

    ll k = max(x, y) * 2;

    ll r = 1LL << 60;
    for (ll i = 0; i <= k; i++) {
        ll t = i * c + max(x - i / 2, 0LL) * a + max(y - i / 2, 0LL) * b;
        r = min(r, t);
    }

    cout << r << endl;

    return 0;
}

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

using namespace std;

int main(){
    int n,m; cin >> n >> m;
    int a[m][2];
    
    for(int i = 0 ; i < m ; i ++){
        for(int j = 0 ; j < 2 ; j++){
            cin >> a[i][j];
        }
    }
    
    int count[n];
    for(int i = 0 ; i < n ; i++){
        count[i] = 0;
    }
    
    for(int k = 1 ; k <= n ; k++){
        for(int i = 0 ; i < m ; i++){
            for(int j = 0 ; j < 2 ; j++){
                if(k == a[i][j])
                    count[k-1]++;
            }
        }
    }
    for(int i = 0 ; i < n ; i++){
            cout << count[i]  << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from itertools import product

N, M = map(int, input().split())
A, B, C = [], [], []
for i in range(N):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)

P = list(product([1, -1], repeat=3))

ans = 0
for x, y, z in P:
    S = []
    for a, b, c in zip(A, B, C):
        S.append(a*x + b*y + c*z)
    S.sort(reverse=True)
    ans = max(ans, sum(S[:M]))

print(ans)


Measured memory_bytes: 3188
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int[] dist;
	private int[] visited;
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		dist = new int[totalVertex];
		for (int i = 0; i < dist.length; i++) {
			dist[i] = -1;
		}
		visited = new int[totalVertex];
		for (int j = 0; j < visited.length; j++) {
			visited[j] = 0;
		}
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public int[] BFS(int v) {
		LinkedList<Integer> toVisit = new LinkedList<Integer>();
		toVisit.add(v);
		visited[v] = 1;
		dist[v] = 0;
		while(!toVisit.isEmpty()) {
			int u = toVisit.remove();
		    for(int i = 0; i < adjList.get(u).size(); ++i) {
		    	int k = adjList.get(u).get(i);
		    	if (visited[k] == 0) {
		    		visited[k] = 1;
		    		toVisit.add(k);
		    		dist[k] = dist[u] + 1;
		    	}
		   
		    }
		   
		}
		for (int k = 0; k < dist.length; k++) {
		System.out.println(k+1 + " " + dist[k]);
		
	}
		return dist;
}
}
//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		int[] dist = g.BFS(0);
	}
}


Measured memory_bytes: 29016
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int cd=0,ans=0;
    for(int i=1;i<=n;i++){
        cd=0;
        for(int j=1;j<=i;j++){
            if(i%2==1&&i%j==0){
                cd++;
            }
        }
        if(cd==8){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int oo = 1e9;
const int MOD = 1000000007;
const int N = 200010;
#define x first
#define y second
#define pb push_back
#define mp make_pair

struct state {
	int x , y , z;
	state() {
		x=y=z=0;	
	}
	state(int _x, int _y , int _z) {
		x = _x, y = _y, z = _z;
	}
};
int n, p[N];
vector<int> g[N];
deque<state> dq[N];

int fast(int a , int b) {
	if (!b)return 1ll;
	int res = fast(a, b / 2);
	res = (1ll * res * res) % MOD;
	if (b & 1)return (1ll * res * a) % MOD;
	return res;
}
int inv(int a) {
	return fast(a, MOD - 2);
}
state merge(state a , state b) {
	state res;
	res.x = (1ll*a.x * b.x + MOD) % MOD;
	res.y = (1ll * a.x * b.y + 1ll * b.x * a.y) % MOD;
	res.z = (1ll + 1ll*(MOD - res.x) + 1ll*(MOD - res.y) + MOD) % MOD;
	return res;
}
const int INV = inv(2);

void solve(int u) {
	int mx = -1 , at = -1;
	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i];
		solve(v);
		if ((int)dq[v].size() > mx)
			mx = dq[v].size() , at = v;
	}
	int smx = 1;
	if (at != -1) {
		dq[u].swap(dq[at]);
		for (int i = 0 ; i < g[u].size(); ++i) {
			int v = g[u][i];
			if (v == at)continue;
			assert(dq[u].size()>=dq[v].size());
			smx = max(smx,(int)dq[v].size()+1);
			for (int j = 0 ; j < dq[v].size(); ++j) {
				dq[u][j] = merge(dq[v][j], dq[u][j]);
			}
		}
	}
	dq[u].push_front(state(INV, INV, 0));
	for (int j = 0 ; j < smx; ++j) {
		dq[u][j].x = (1ll*dq[u][j].x+dq[u][j].z)%MOD;
		dq[u][j].z = 0;
	}
}


int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n ; ++i) {
		scanf("%d", &p[i]);
		g[p[i]].pb(i);
	}
	solve(0);
	ll res = 0;
	ll cons =  fast(2, n + 1);
	for (int i = 0; i < dq[0].size(); ++i) {
		res = (res + 1ll * dq[0][i].y * 1ll *cons) % MOD;
	}
	printf("%lld\n", res );


	return 0;
}


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

public class Main {

	public static void main(String[] args) {

		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
			
			String input = br.readLine();
			
			StringBuilder sb = new StringBuilder();
			
			for(int i = 0; i < input.length(); i++) {
				char c = input.charAt(i);
				String s = String.valueOf(c);
				
				if(isUpperCase(c)) {
					sb.append(s.toLowerCase());
				} else if(isLowerCase(c)) {
					sb.append(s.toUpperCase());
				} else {
					sb.append(c);
				}
			}
			
			System.out.println(sb.toString());
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private static boolean isUpperCase(char c) {
		return 'A' <= c && c <= 'Z';
	}
	
	private static boolean isLowerCase(char c) {
		return 'a' <= c && c <= 'z';
	}
}


Measured memory_bytes: 24752
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int[] num = new int[] { int.Parse(input[0]), int.Parse(input[1]), int.Parse(input[2]) };
    Array.Sort(num);
    Array.Reverse(num);
	Console.WriteLine(num[0] * 10 + num[1] + num[2]);
  }
}

Measured memory_bytes: 13140
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);   
       //値の取得
      int N = sc.nextInt();
      int x = sc.nextInt();
      int[] a = new int[N];
      for(int i=0;i<N;i++){
        a[i]=sc.nextInt();
      }
      //ほしい飴少ない順に並べる
      int A;
      for(int j=N-1;j>0;j--){
       for(int i=0;i<j;i++){
        if(a[i]>a[i+1]){
          A=a[i+1];
          a[i+1]=a[i];
          a[i]=A;
        }
       }
      }
      //謙虚な子からあめなくなるまであげる
      int ans=0;
      for(int i=0;i<N;i++){
        x-=a[i];
        if(x>0){//余った
          ans++;
        }else if(x==0){//ぴったり配れた
          ans=i+1;
          break;
        }else if(x<0){//足りない
          ans=i;
          break;
        }
      }
      if(x>0){
       System.out.println(ans-1);
      }else{
        System.out.println(ans);
      }
    }
}

Measured memory_bytes: 35680
#include<bits/stdc++.h>
using namespace std;
int a,b,k;
string str;
int main()
{
    cin>>a>>b>>str;
    for(int i=0;i<=a+b;i++)
	{
        if(isdigit(str[i])) continue;
		else if(i != a) { k = 1; break; }
    }
    if(str[a]!='-') k = 1;
    if(k) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long i64;
const int P=998244353,M=100007;
char s1[M],s2[M];
int A=0,B=0,N,K,rev[M];
i64 fac[M],fiv[M],_A[M],_B[M],E[M];
i64 pw(i64 a,i64 n){
	if(n<0)n+=P-1;
	i64 v=1;
	for(;n;n>>=1,a=a*a%P)if(n&1)v=v*a%P;
	return v;
}
void init(int mx){
	for(N=2,K=0;N<mx;N<<=1,++K);
	for(int i=1;i<N;++i)rev[i]=rev[i>>1]>>1|(i&1)<<K;
}
inline i64 fix(i64 x){return x+(x>>63&P);}
void ntt(i64*a,int t){
	for(int i=0;i<N;++i)if(i<rev[i])std::swap(a[i],a[rev[i]]);
	for(int i=1;i<N;i<<=1){
		E[0]=1;
		E[1]=pw(3,(P-1)/(i<<1)*t);
		for(int j=2;j<i;++j)E[j]=E[j-1]*E[1]%P;
		for(int j=0;j<N;j+=i<<1){
			i64*b=a+j,*c=b+i;
			for(int k=0;k<i;++k){
				i64 x=b[k],y=c[k]*E[k]%P;
				b[k]=fix(x+y-P);
				c[k]=fix(x-y);
			}
		}
	}
	if(t==-1){
		i64 I=pw(N,-1);
		for(int i=0;i<=A;++i)a[i]=a[i]*I%P;
		for(int i=A+1;i<N;++i)a[i]=0;
	}
}
void pre(){
	const int mx=1e5;
	for(int i=fac[0]=1;i<=mx;++i)fac[i]=i*fac[i-1]%P;
	fiv[mx]=pw(fac[mx],-1);
	for(int i=mx;i;--i)fiv[i-1]=i*fiv[i]%P;
}
void mul(i64*a,i64*b){
	for(int i=0;i<N;++i)a[i]=a[i]*b[i]%P;
}
int main(){
	scanf("%s%s",s1,s2);
	pre();
	for(int i=0;s1[i];++i)if(s1[i]=='1'){
		if(s2[i]=='1')++A;
		else ++B;
	}
	for(int i=0;i<=A;++i)_A[i]=fiv[i+1];
	_B[0]=1;
	init(A*2+5);
	for(int n=B;n;n>>=1){
		if(n&1)ntt(_B, 1);ntt(_A, 1);
		if(n&1)mul(_B,_A);mul(_A,_A);
		if(n&1)ntt(_B,-1);ntt(_A,-1);
	}
	i64 ans=0;
	for(int i=0;i<=A;++i)ans=fix(ans+_B[i]-P);
	ans=ans*fac[A]%P*fac[B]%P*fac[A+B]%P;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2944
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

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

 	ll n, flag = 0;
 	cin >> n;
 	ll a[n], curr = 1;
 	for(int i=0;i<n;i++) cin >> a[i];
 	for(int i=0;i<n;++i)
 	{
 		if(a[i] == 1) flag = 1;
 		if(a[i] == curr)
 			curr += 1;
 	}
 	if(!flag) cout << -1 << endl;
 	else cout << n - curr + 1 << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;                                                                                  

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        for(int i = 1; i <= 10000; i++) {
          String line = sc.nextLine();
          int x = Integer.parseInt(line);

          if(x == 0) {
            break;
          }   

          System.out.println("Case " + i + ": " + x); 
        }   
    }   
}

Measured memory_bytes: 58792
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[6] = {0,1,0,-1,1,-1};
const int vy[6] = {1,0,-1,0,1,1};



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

    string s;
    cin >> s;
    rep(i,3) cout << s[i];


    cout << endl;
    return 0;
}


Measured memory_bytes: 3652