akhauriyash/Code-Regression huggingface dataset:
def examC():
    ABC = LI(); ABC.sort()
    judge = ABC[2]*2-ABC[1]-ABC[0]
    ans = judge//2 + (judge%2)*2
    print(ans)
    return

def examD():
    def judge(A,B):
        if A==B:
            return (A-1)*2
        cur = int((A*B)**0.5)
        if cur**2==A*B:
            return (cur-1)*2 -1
        if cur*(cur+1)>=A*B:
            return cur*2 -2
        else:
            return cur*2-1
    Q = I()
    ans = []
    for _ in range(Q):
        a,b = LI()
        ans.append(judge(a,b))
    for v in ans:
        print(v)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examD()


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int A, B;

void solve(){
	cout << A + B / 2 << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> A >> B;
		solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 20050;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n, h;
struct magic
{
    int a, b;
} x[N];
int dp[N];

void solve()
{
    scanf("%d%d", &h, &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &x[i].a, &x[i].b);
    memarray(dp, inf);
    dp[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = x[i].a; j <= 20000; ++j)
            dp[j] = min(dp[j], dp[j - x[i].a] + x[i].b);
    }
    int ans = inf;
    for (int i = h; i <= 20000; ++i)
        ans = min(ans, dp[i]);
    cout << ans << '\n';
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll ans = 0;
    ll boarder = 0;
    rep(i, N){
        ll a; cin >> a;
        if(a > boarder) boarder = a;
        else ans += boarder-a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	ll cnt = 1;
	for (ll i = a; i <= b; i++) {
		if (cnt <= k || b - a - k + 2 <= cnt) {
			cout << i << endl;
		}
		cnt++;
	}
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8) #再帰関数の上限を変更
ans = []
def dfs(x, y):
    c[x][y] = 0 #今いる場所を0にする
    for dx in range(-1, 2):
        for dy in range(-1, 2):
            nx = x + dx
            ny = y + dy
            ##動く先が範囲内で、1であれば移動する
            if 0 <= nx < h and 0 <= ny < w and c[nx][ny] == 1:
                dfs(nx, ny)
while True:
    w, h = map(int, input().split())
    if w == 0 and h ==0:
        break
    count = 0
    c = [[] for _ in range(h)]
    for i in range(h):
        if w == 1:
            c[i] = [int(input())]
        else:
            c[i] = list(map(int, input().split()))
            #c = [[1, 0, 1, 0, 0], [1, 0, 0, 0, 0], [1, 0, 1, 0, 1], [1, 0, 0, 1, 0]]
    for x in range(h):
        for y in range(w):
            if c[x][y] == 1:
                dfs(x, y)
                count += 1
    ans.append(count)
for i in ans:
    print(i)


Measured memory_bytes: 8000
#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

constexpr ll MOD = 998244353LL;
constexpr int N = 212345;
ll a[N];
ll pw(ll a, ll b){
	ll c = 1;
	do {
		if(b&1) c = c * a % MOD;
		a = a * a % MOD;
	} while(b /= 2);
	return c;
}
ll inv(ll a){
	return pw(a, MOD-2);
}
ll fct[N] = {1}, fctinv[N];
ll cmb(ll a, ll b){
	return fct[a] * fctinv[b] % MOD * fctinv[a-b] % MOD;
}
 
int main(){
	FOR(i, 1, N) fct[i] = fct[i-1] * i % MOD;
	REP(i, N) fctinv[i] = inv(fct[i]);

	ll n, m, k; scanf("%lld%lld%lld", &n, &m, &k);
	a[1] = m;
	FOR(i, 2, N) a[i] = a[i-1] * (m-1) % MOD;
	ll ans = 0;
	FOR(i, n-k, n+1){
		ans += a[i] * cmb(n-1, n-i) % MOD;
	}
	printf("%lld\n", ans % MOD);
}





Measured memory_bytes: 8796
#include <bits/stdc++.h>
using namespace std;
long long tas,res,tass=0,h;
int main() {
  cin>>h;
  while(h>=1) {
    h=h/2;
    tass++;
  }
  //cout<<tass<<endl;
  tas=1;
  res=1;
  while (tass>1){
    tas=tas*2;
    res+=tas;
    tass--;
  }
  cout<<res;
}

Measured memory_bytes: 256
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x.abs()
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    let N = read!(usize);
    let A = read![[i64]];

    let mut g = 0;
    for a in A {
        g = gcd(g, a);
    }

    println!("{}", g)
}


Measured memory_bytes: 8444
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************


int main() {

    ll N;
    cin >> N;

    ll ans = 0;
    FOR(i, 1, N + 1) {
        if (i % 15 == 0) continue;
        if (i % 3 == 0 || i % 5 == 0) {
            continue;
        }
		ans += i;
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
	int h, n;
  	cin >> h >> n;
	rep(i, n){
      	int a;
      	cin >> a;
    	h -= a;
    }
  	
  	if(h > 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(S);
  int f1 = 2, f2 = 2;
  if (S % 100 > 12) {
    f2 = 1;
  } else if (S % 100 == 0) {
    f2 = 1;
  }
  if (S / 100 > 12) {
    f1 = 1;
  } else if (S / 100 == 0) {
    f1 = 1;
  }
  if (f1 == 2 && f2 == 2) {
    print("AMBIGUOUS");
  } else if (f1 == 2 && f2 == 1) {
    print("MMYY");
  } else if (f1 == 1 && f2 == 2) {
    print("YYMM");
  } else {
    print("NA");
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	long N,x;
	scanf("%ld",&N);
	scanf("%ld",&x);
	long a[N],i;
	for(i=0;i<N;i++) 	scanf("%ld",&a[i]);
	long eat = 0;
	if(a[0]>x){ eat=a[0]-x; a[0]=x;}
	for(i=0;i<N-1;i++){
		if(a[i]+a[i+1]>x){
		eat += a[i+1]+a[i]-x;
		a[i+1]=x-a[i];}
	}
	printf("%ld\n",eat);
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
  int main()

  {
      int b,n,i,r,digit,p,count=0,q,num=0;
      char a[100];
     scanf("%d",&n);
    scanf("%d",&b);
     p=n;
      do
    {
        r=p%b;
        digit='0'+r;
        if(digit>'9')
            digit=digit+7;
        a[count]=digit;
        count++;
        p=p/b;
         } while(p!=0);
      for(i=count-1;i>=0;--i)
      {
          while(a[i]!=0)
          {
              a[i]=a[i]/10;
              num++;
          }
      }
      printf("%d",num/2);
      return 0;
  }


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

using namespace std;

typedef long long ll;

int main()
{
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // LOCAL

    int n, m;   cin >> n >> m;

    vector <vector <int>> Adj(n + 1);

    while(m--)
    {
        int x, y;   scanf("%d%d", &x, &y);

        Adj[x].push_back(y);
        Adj[y].push_back(x);
    }

    queue <int> q;
    vector <int> P(n + 1);

    q.push(1);

    while(!q.empty())
    {
        int x = q.front();
        q.pop();

        for(int y : Adj[x])
        {
            if(!P[y])
            {
                P[y] = x;
                q.push(y);
            }
        }
    }

    for(int x = 2; x <= n; x++)
        if(!P[x])
            return 0 * puts("No");

    puts("Yes");
    for(int x = 2; x <= n; x++) printf("%d\n", P[x]);
    puts("");
}


Measured memory_bytes: 10192
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-11
#define M_PI 3.141592653589793
#define BS 12345678891
#define bsize 256

#define ldouble long double

using namespace std;

long long INF = 1e9;
const int N = 500031;

int n,am[N];
vector<int> g[N];
int ok=1;
int used[N];

long long goes_up[N];

void trace(int v)
{
	vector<int> sons;
	used[v]=1;
	for (int i=0;i<g[v].size();i++)
	{
		int to=g[v][i];
		if (used[to])
			continue;
		trace(to);
		sons.push_back(to);
	}

	long long max_son=0;

	if (sons.size()==0)// leaf
	{
		goes_up[v]=am[v];
		return;
	}

	long long total_in_sons=0;
	for (int i=0;i<sons.size();i++)
	{
		int to=sons[i];
		total_in_sons+=goes_up[to];
		max_son=max(max_son,goes_up[to]);
	}

	if (total_in_sons<am[v])
	{
		ok=0;
		return ;
	}
	long long paired=total_in_sons-am[v];

	if (paired*2>total_in_sons)
	{
		ok=0;
		return ;
	}

	long long in_dif=total_in_sons-max_son;
	if (paired>in_dif)
	{
		ok=0;
		return ;
	}

	long long unpaired=total_in_sons-2*paired;
	goes_up[v]=unpaired;
}

int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>am[i];
	}

	if (n==2)
	{
		if (am[1]==am[2])
		{
			cout<<"YES"<<endl;
		}
		else
			cout<<"NO"<<endl;
		return 0;
	}

	for (int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int root=1;
	while (g[root].size()==1)
	{
		++root;
	}

	trace(root);

	/*for (int i=1;i<=n;i++)
	{
		cout<<goes_up[i]<<" ";
	}
	cout<<endl;
	cout<<root<<endl;
*/
	if (ok==1&&goes_up[root]==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 24704
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    string s;
    cin >> s;
    string ans;
    rep(i,s.size()){
        if(!(i%2))ans += s[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N = 4e5+5;
typedef long long ll;
int n;
int fa[N];
struct Dat{
	int sz0,sz1,id;
	Dat(int sz0=0, int sz1=0, int id=0):sz0(sz0),sz1(sz1),id(id){}
	bool operator < (const Dat b)const{
		return 1ll*sz0*b.sz1 == 1ll*b.sz0*sz1 ?  id > b.id : 1ll*sz0*b.sz1 > 1ll*b.sz0*sz1;
	}
}t[N];
int par[N];
inline int find(int x){
	return par[x]==x?par[x]:par[x] = find(par[x]);
}
ll ans;
set<Dat> S;
inline void combine(int x){
	int cur = find(x), f = find(fa[cur]);
	// cout << cur << ":" << f << endl;
	// cout << t[cur].sz0 << " " << t[cur].sz1 << endl;
	if(f!=1)S.erase(t[f]);
	S.erase(t[cur]);
	par[cur] = f;
	ans += 1ll*t[f].sz1 * t[cur].sz0;
	// cout << ":contribute" << 1ll*t[f].sz1 * t[cur].sz0 << endl;
	t[f].sz1 += t[cur].sz1, t[f].sz0 += t[cur].sz0;
	if(f!=1)S.insert(t[f]);
}

int main()
{
	cin >> n;
	for(int i=2;i<=n;i++){
		scanf("%d",&fa[i]);
	}
	for(int i=1;i<=n;i++){
		par[i] = i;
		int x;scanf("%d",&x);
		if(x)t[i].sz1++;
		else t[i].sz0++;
		t[i].id=i;
		if(i>1){
			// cout << i << " " << "ins" << endl;
			S.insert(t[i]);
			// cout << S.size() << endl;
		}
	}
	for(int j=1;j<n;j++){
		// cout << "sz" << ":" << S.size() << endl;
		combine((*S.begin()).id);
	}
	cout << ans << endl;
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 212345;
const ll mod = 1000000007;
int main() {
    string s, ans = "";
    cin >> s;
    for (auto i : s) {
        if (i == 'B') {
            if (ans.size()) ans.pop_back();
        } else {
            ans += i;
        }
    }
    cout << ans << endl;

}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

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

const long long int INF = 1e18;

int main(){
  //この問題は多重辺無し。
  //input
  inputInt2(N,M);
  
  vector<vector<pair<int,long long int>>> graph(N); //graph[from][i番目の辺].<to,cost>
  for(int i=0; i<M; i++){
    int from, to;
    long long int cost;
    cin >> from >> to >> cost;
    from --; to --; cost *= -1;//最長経路問題を最短経路問題に帰着させるため。
    graph[from].pb(mp(to,cost));
    //graph[to].pb(mp(from,cost));
  }
  
  //main
  //ベルマンフォード法
  vector<long long int> d(N,INF);
  d[0] = 0;//頂点1までの距離を0に。
  bool NegativeLoop = false;
  
  for(int it=0; it<N*2+1; it++){//念のため頂点数の2倍ループを回す。
    for(int v=0; v<N; v++){//for auto文との組み合わせで1セット。
      if(d[v]>INF/2) continue; //無駄を省く&オーバーフロー対策。
      for(auto edge:graph[v]){//edgeはpair型
        if(d[edge.first] > d[v] + edge.second){
          d[edge.first] = d[v] + edge.second;
          if(edge.first == N-1 && it == N*2){
            NegativeLoop = true; 
          }
        }
      }
    }
  }
  
  //確認用
  /*for(int i=0; i<N; i++){
    cout << d[i] << endl;
  }*/
  
  // output
  if(NegativeLoop){
    cout << "inf" << endl;
  }else{
    cout << -d[N-1] << endl; 
  }
    
  return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	priority_queue<int> t;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		t.push(x);
	}
	for (int i = 0; i < m; i++) {
		int x = t.top();
		t.pop();
		x /= 2;
		t.push(x);
	}
	long long int ans = 0;
	for (int i = 0; i < n; i++) {
		int x = t.top();
		t.pop();
		ans += x;
	}
	cout << ans << endl;

	return 0;


}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<string> result(N);
  for(int i = 0; i < N; i++){
   cin >> result.at(i);
  }
  
  int A = 0,W = 0, T = 0, R = 0;
  
  for(int i = 0; i < N; i++){  
    if(result.at(i) == "AC"){
      A++;}
    else if(result.at(i) == "WA"){
      W++;}
    else if(result.at(i) == "TLE"){
      T++;}
    else {R++;}
  }
  cout << "AC x " << A << endl; 
   cout << "WA x " << W << endl; 
  cout << "TLE x " << T << endl; 
  cout << "RE x " << R << endl; 
  
    
  
}

Measured memory_bytes: 6388
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#define ll long long
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l)for(int i=r;i>=l;i--)
using namespace std;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int a;
  string s="red";
  string s1;
  cin>>a>>s1;
  if(a<3200)cout<<s<<endl;
  else cout<<s1<<endl;
}

Measured memory_bytes: 256
import scala.reflect.ClassTag

object Main extends App {
  import scala.io.StdIn.{readLine}
  solve(readLine().toInt)
  class Grid[T:ClassTag](val size:Int, default:() ⇒ T){
    private val defaultValue = default()
    private val mArray = Array.tabulate(size){_ ⇒ Array.tabulate(size){_ ⇒ default()}}
    def apply(x:Int, y:Int):T = mArray(y)(x)
    def update(x:Int, y:Int, value:T) = mArray(y)(x) = value
    def getOrDefault(x:Int, y:Int) = (0 until size).contains(x) && (0 until size).contains(y) match{
      case true ⇒ mArray(y)(x)
      case _ ⇒ defaultValue
    }
  }
  object Grid{
    def apply[T:ClassTag](size:Int, default:() ⇒ T):Grid[T] = new Grid(size, default)
  }
  class MaxValues(var up:Int = 0, var left:Int = 0, var leftUp:Int = 0, var rightUp:Int = 0) {
    def max:Int = List(up, left, leftUp, rightUp).max
  }
  object MaxValues{
    def apply() = new MaxValues()
  }
  def solve(n:Int):Unit = {
    if (n == 0) return
    val grid = Grid(n, () ⇒ 0)
    val maxGrid = Grid(n, MaxValues.apply)
    for (y ← 0 until n){
      readLine().zipWithIndex.foreach{case (c, x) ⇒
        grid(x, y) = c.asDigit
      }
    }
    println((for (y <- 0 until n; x ← 0 until n) yield {
      grid(x, y) match{
        case 1 ⇒ {
          maxGrid(x, y).left = maxGrid.getOrDefault(x - 1, y).left + 1
          maxGrid(x, y).leftUp = maxGrid.getOrDefault(x - 1, y - 1).leftUp + 1
          maxGrid(x, y).up = maxGrid.getOrDefault(x, y - 1).up + 1
          maxGrid(x, y).rightUp = maxGrid.getOrDefault(x + 1, y - 1).rightUp + 1
        }
        case _ ⇒
      }
      maxGrid(x, y).max
    }).max)
    solve(readLine().toInt)
  }
}



Measured memory_bytes: 181968
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> S;
    N = S.size();
    vi a(N);
    vi r;
    vi res(N, 0);
    for (int i = 1; i < N; i++) {
        if (S[i] == 'L' && S[i - 1] == 'R') {
            r.push_back(i - 1);
        }
    }
    int tmp = 0;
    for (int i = 0; i < N; i++) {
        if (S[i - 1] == 'L' && S[i] == 'R') {
            tmp++;
        }
        if (S[i] == 'R') {
            int x = r[tmp] - i;
            if (x & 1) {
                res[r[tmp] + 1]++;
            } else {
                res[r[tmp]]++;
            }
        } else if (S[i] == 'L') {
            int x = i - r[tmp];
            if (x & 1) {
                res[r[tmp] + 1]++;
            } else {
                res[r[tmp]]++;
            }
        }
    }
    for (int i = 0; i < N; i++) {
        cout << res[i];
        if (i != N - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
}

Measured memory_bytes: 1664
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream> 
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL n,k;
struct node{
	LL a[50][50];
	node() {memset(a,0,sizeof(a));}
}e;
node operator * (node a,node b)
{
	node ans;
	for(LL k=0;k<n;k++)
		for(LL i=0;i<n;i++)	
			for(LL j=0;j<n;j++)
				(ans.a[i][j]+=a.a[i][k]*b.a[k][j]%mod)%=mod;
	return ans;
}
node operator ^ (node a,LL b)
{
	node ans;
	for(LL i=0;i<n;i++) ans.a[i][i]=1;
	while(b)
	{
		if(b&1) ans=ans*a;
		a=a*a;b>>=1;
	}
	return ans;
}
int main()
{
	scanf("%lld %lld",&n,&k);
	for(LL i=0;i<n;i++)
		for(LL j=0;j<n;j++) scanf("%lld",&e.a[i][j]);
	e=e^k;
	LL ans=0;
	for(LL i=0;i<n;i++)
		for(LL j=0;j<n;j++) (ans+=e.a[i][j])%=mod;
	printf("%lld",ans);
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int H,W;

    while(1) {
        cin >> H >> W;
        if (H == 0 && W == 0) break ;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i % 2 == 0) && (j % 2 == 0)  || (i % 2 == 1) && (j % 2 == 1))  {
                    cout << '#';
                } else {
                    cout << '.';    
                }
                
            }
            cout << "\n";
            
            
        }
        cout << endl;
    }
    
    // cout << min << " " << max << " " << sum << endl;
    
    
    return 0;
}

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

int main() {

	int aorb = 0;
    int max = 0;
	int scorea = 0, scoreb = 0,ans = 0;
	int n = 0,memory = 0,p = 0;
	int a[100];
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	max = a[0];
	memory = 0;

	for (int j = 0; j < n; j++) {
		
		for (p; p < n; p++) {
			if (max < a[p]) {
				max = a[p];
				memory = p;

			}
		}

		if (aorb == 0) {
			scorea += max;
			aorb = 1;
			a[memory] = 0;
			p = 0;
			max = 0;
		}
		else {
			scoreb += max;
			aorb = 0;
			a[memory] = 0;
			p = 0;
			max = 0;
		}

	}

	ans = scorea - scoreb;

	if (ans < 0) {
		ans = ans*-1;
	}
	std::cout << ans;
}

Measured memory_bytes: 256
//Link : https://atcoder.jp/contests/arc101/tasks/arc101_c

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

vector<int> adj[N];
ll d[N];
pair<ll,int> in[N];
int sz[N];

int dsz[N];
ll dd[N];

void dfs(int node) {
  dsz[node] = 1;
  for(int ch : adj[node]) {
    dfs(ch);
    dsz[node] += dsz[ch];
    dd[node] += dd[ch] + dsz[ch];
  }
}

bool dfs2(int node,ll tmp,int n) {
  if(tmp!=d[node]) {
    return false;
  }
  for(int ch : adj[node]) {
    if(!dfs2(ch,tmp + n - dsz[ch]*2,n)) {
      return false;
    }
  }
  return true;
}

void solve() {
  int n;scanf("%d ", &n);
  set<pair<ll,int> >s;
  ll sum = 0;
  for(int i=1;i<=n;++i) {
    scanf("%lld ", &in[i].first);
    d[i] = in[i].first;
    in[i].second = i;
    sz[i] = 1;
    s.insert(in[i]);
    sum += d[i];
  }
  if(sum%2==1) {
    printf("-1\n");
    return;
  }
  sort(in+1,in+n+1);
  int pos = n;

  while(s.size()>1) {
    pair<ll,int> tmp = *prev(s.end());
    s.erase(prev(s.end()));
    ll dist = tmp.first;
    int node = tmp.second;
    pair<ll,int> tmp2 = make_pair(dist - n + sz[node]*2,0);
    set<pair<ll,int> >::iterator it = s.lower_bound(tmp2);
    if(it==s.end() || (*it).first!=tmp2.first) {
      printf("-1\n");
      return;
    }
    int x = (*it).second;
    sz[x] += sz[node];
    adj[x].push_back(node);
  }
  int root = in[1].second;
  dfs(root);
  if(!dfs2(root,dd[root],n)) {
    printf("-1\n" );
    return;
  }
  for(int i=1;i<=n;++i) {
    for(int ch : adj[i]) {
      printf("%d %d\n", i,ch);
    }
  }
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 16256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <climits>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    string s , t;   cin >> s >> t;
    for (int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1005;
const char END = '\n';

ll youkurido(ll x, ll y) {
	if (x > y) swap(x, y);
	ll n = y % x;
	if (n == 0)
		return x;
	else
		youkurido(x, n);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll A, B;
	cin >> A>> B;
	ll kouyaku = youkurido(A, B);
	ll Ans = 1;
	ll sub = 2;
	bool firstv = true;

	while (1) {
		if (kouyaku%sub == 0){
			if (firstv == true) {
				Ans++;
				firstv = false;
			}
			kouyaku/= sub;
		}
		else {
			firstv = true;
			sub++;
			if (sub >= sqrt(kouyaku))
				break;
		}		
	}
	if (kouyaku != 1)
		Ans++;
	cout << Ans;
	cout << END;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
	int a, b, c, n, a2, b2, c2;
	std::cin >> n;
	for(int i=0; i<n; i++){
		std::cin >> a >> b >> c;
		a2 = a * a;
		b2 = b * b;
		c2 = c * c;
		if(a2 + b2 == c2 || b2 + c2 == a2 || c2 + a2 == b2)
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1152
N = int(input())
S = input()

b = 0
w = 0
for s in S:
  if s == '#':
    b += 1
  else:
    w += 1
dp = w
min = w
for s in S:
  if s == '.':
    dp -= 1
  else:
    dp += 1
    
  if dp < min:
    min = dp
print(min)

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
string s,p;
int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>s>>p;
    n=s.size();
    s+=p[n];
    (s==p)? cout<<"Yes\n":cout<<"No\n";
    return 0;
}



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

vector<vector<int>> nails;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m;
	cin >> n >> m;
	
	nails.resize(n + 2);
	for(int i = 0; i < n + 2; ++i)
		nails[i].assign(i + 2, 0);
	
	for(int i = 0; i < m; ++i){
		int a, b, x;
		cin >> a >> b >> x;
		--a, --b;
		nails[a][b]++;
		nails[a][b + 1]--;
		nails[a + x + 1][b]--;
		nails[a + x + 2][b + 1]++;
		nails[a + x + 1][b + x + 2]++;
		nails[a + x + 2][b + x + 2]--;
	}
	
	for(int i = 0; i < n; ++i){
		for(int j = 0; j <= i; ++j){
			nails[i][j + 1] += nails[i][j];
		}
	}
	
	for(int i = 0; i < n; ++i){
		for(int j = 0; j <= i; ++j){
			nails[i + 1][j] += nails[i][j];
		}
	}
	
	for(int i = 0; i < n; ++i){
		for(int j = 0; j <= i; ++j){
			nails[i + 1][j + 1] += nails[i][j];
		}
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j <= i; ++j){
			if(nails[i][j] > 0)
				ans++;
		}
	}

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

Measured memory_bytes: 50100
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define out(x) cout << (x) << endl;
#define outs(x) for(auto i : x) cout << i << " ";
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

int main() {
  int a,b,c,d; cin >> a >> b >> c >> d;
  cout << max(min(b,d) - max(a,c),0);
  return 0;
}

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

int main(){
    int H, W;
    cin >> H >> W;
    char s[55][55];
    int a[55][55]={{0}};
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            cin >> s[i][j];
        }
    }
    
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(s[i][j]=='#'){
                a[i-1][j-1]++;
                a[i][j-1]++;
                a[i+1][j-1]++;
                a[i-1][j]++;
                a[i+1][j]++;
                a[i-1][j+1]++;
                a[i][j+1]++;
                a[i+1][j+1]++;
            }
        }
    }
    
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(s[i][j]=='#')
                cout << s[i][j];
            else
                cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;

int main(){
	//scanf("%d",&t);
	while(t--){
		string s;
		cin>>s;
		stack<int>st;
		int n=s.size();
		for(int i=0;i<n;i++){
			if(st.empty()){
				st.push(s[i]-'0');
			}
			else{
				if(st.top()==1&&s[i]=='0'){
					st.pop();
				}
				else if(st.top()==0&&s[i]=='1'){
					st.pop();
				}
				else{
					st.push(s[i]-'0');
				}
			}
		}
		cout<<n-st.size()<<endl;
	}
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  int r,s,p;
  cin >> r >> s >> p;
  string t;
  cin >> t;
  int ans = 0;
  rep(i,N) {
    if(t[i] == 'r') {
      if(i-K>=0 && t[i-K] == 'r') {
        t[i] = 'x';
      } else {
        ans += p;
      }
    } else if(t[i] == 's') {
      if(i-K>=0 && t[i-K] == 's') {
        t[i] = 'x';
      } else {
        ans += r;
      }
    } else if(t[i] == 'p') {
      if(i-K>=0 && t[i-K] == 'p') {
        t[i] = 'x';
      } else {
        ans += s;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.next());
		sc.close();
		Main m = new Main();

		while (true) {
			if(m.searchPrime(num)) {
				break;
			}else{
				num++;
			};
		}
		System.out.println(num);

	}

	public boolean searchPrime(int num) {
		//true == prime
		//false == not prime
		boolean isPrimeFlg = true;
		int numsPiv = (int)Math.sqrt(num);
		for (int i = 2; i < numsPiv; i++) {
			if (num % i == 0) {
				isPrimeFlg = false;
				break;
			}
		}

		return isPrimeFlg;
	}
}

Measured memory_bytes: 22608
import java.util.*;

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

    int list[] = new int[n];
    for(int i = 0; i < n; i++){
      int a = sc.nextInt();
      list[i] = a;
    }
    for(int i = 0; i<n/2; i++){
      int temp = list[i];
      list[i] = list[(n-1)-i];
      list[(n-1)-i] = temp;
    }
    for(int i = 0; i<n; i++){
      if(i != (n-1)){
        System.out.print(list[i] + " ");
      }else{
        System.out.print(list[i]);
      }
    }
    System.out.println();
  }
}


Measured memory_bytes: 26272
A, B, C, D = map(int, input().split())
if A <= C:
    if B <= C:
        print(0)
    if C < B and B <= D:
        print(B - C)
    if D < B:
        print(D - C)
if C < A:
    if D <= A:
        print(0)
    if A < D and D <= B:
        print(D - A)
    if B < D:
        print(B - A)


Measured memory_bytes: 3060
#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 500001;

vl A,B;

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

    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;
    cin >> n >> m >> k;

    rep(c1,0,n){
        cin >> a;
        A.push_back(a);
    }
    rep(c1,0,m){
        cin >> a;
        B.push_back(a);
    }
    ll ans = big;
    rep(c1,0,k){
        cin >> a >> b >> c;
        a--;b--;
        ans = min(ans, A[a] + B[b] - c);
    }
    sort(all(A));sort(all(B));
    ans = min(ans, A[0]+B[0]);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string ans;
  
  int n = s.size();
  rep(i, 0, n) {
    ans += 'x';
  }
  cout << ans << "\n";


}


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

#1リットル買う最も安い方法を考える
x = a*4
y = b*2
z = min(x,y,c)
if z == x:
    e = x
elif z == y:
    e = y
else:
    e = c

if e*2 <= d:
    print(e*n)
else:
    if n%2 == 0:
        print(d*n//2)
    else:
        print(d*(n//2)+e)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    bool es = false;
    if(s[s.size() - 1] == 's') es = true;
    if(es) cout << s << "es" << endl;
    else cout << s << "s" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;

int main() { string S1, S2;
    cin >> S1 >> S2;
    n = S1.length();
    m = S2.length();

    ll dp[n + 1][m + 1];
    rep(i,n+1){
        rep(j, m + 1) { dp[i][j] = INF;
            if (i == 0 && j == 0) dp[i][j] = 0;
            if (i > 0) chmin(dp[i][j], dp[i - 1][j] + 1);
            if (j > 0) chmin(dp[i][j], dp[i][j - 1] + 1);
            if(i>0&&j>0)
                chmin(dp[i][j], dp[i - 1][j - 1] + (S1[i - 1] != S2[j - 1]));
        }
    }

    cout << dp[n][m] << endl;
}



Measured memory_bytes: 11064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll dp[101][100001];
main(){
    int N,K;
    cin >> N >> K;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    ll accum[K+2] = {};
    dp[0][0] = 1;
    rep(i,0,N){
        rep(j,0,K+1){
            accum[j+1] = accum[j] + dp[i][j];
        }
        rep(j,0,K+1){
            dp[i+1][j] = (accum[j+1] - accum[max(0, j - V[i])]) % MOD;
        }
    }
    /*
    rep(j,0,N+1){
    rep(i,0,K+1){
        cout << dp[j][i] << " ";
        
    }
    cout << endl;
    }
    */
    cout << dp[N][K] << endl;
}

Measured memory_bytes: 79104
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
)

func lib_AbsInt64(value int64) int64 {
	return int64(math.Abs(float64(value)))
}
func lib_MinInt64(values ...int64) (min int64, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	min = values[0]
	for _, value := range values {
		if min > value {
			min = value
		}
	}
	return
}
func lib_MustMinInt64(values ...int64) (min int64) {
	min, err := lib_MinInt64(values...)
	if err != nil {
		panic(err)
	}
	return min
}
func lib_NewInt64SliceWithInitialValue(length int, initialValue int64) []int64 {
	ret := make([]int64, length)
	for i := 0; i < length; i++ {
		ret[i] = initialValue
	}
	return ret
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	h := make([]int64, N)
	for i := int64(0); i < N; i++ {
		scanner.Scan()
		h[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}
	fmt.Println(solve(N, h))
}
func solve(N int64, h []int64) int64 {
	dp := lib_NewInt64SliceWithInitialValue(int(N), math.MaxInt64/2)
	dp[0] = 0
	dp[1] = lib_AbsInt64(h[1] - h[0])
	for n := int64(2); n < N; n++ {
		dp[n] = lib_MustMinInt64(dp[n-1]+lib_AbsInt64(h[n]-h[n-1]), dp[n-2]+lib_AbsInt64(h[n]-h[n-2]))
	}
	return dp[N-1]
}


Measured memory_bytes: 2688
N, M = gets.split.map(&:to_i)

sp = []

pattern = []
0.upto((2 ** N) - 1) do |i|
  pattern << format("%0#{N}d", i.to_s(2).to_i)
end

M.times do
  d = gets.split.map(&:to_i)
  d.shift
  sp << d
end
pt = gets.split.map(&:to_i)

rs = Array.new(M) {
  Array.new
}
sp.each_with_index do |d, idx|
  pattern.each do |ptn|
    rn = 0
    d.each do |dn|
      rn += ptn[dn-1].to_i
    end
    if rn.odd? && pt[idx] == 1
      rs[idx] << ptn
    elsif rn.even? && pt[idx] == 0
      rs[idx] << ptn
    end
  end
end

result = rs[0]
rs.each do |r|
  result = result & r
end
p result.size

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

int main() {

	int r[105] = { 0 };
	int num = 0;
	int a = 0;
	int ans = 0;

	cin >> num;

	for (int i = 0; i < num; i++) {
		cin >> a;
		r[a] = 1;
	}

	for (int i = 104; i >= 1; i--) {
		if (r[i] != 0) {ans += 1; }
	}


	cout << ans << endl;


	return 0;
}

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

int main(){
  while(1){
    int H, W;
    cin>>H>>W;
    if(H == 0 && W == 0) break;
    
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int a[3];
    int sa,sumsa = 0;
    for (int i = 0; i < 3; ++i) {
        a[i] = 0;
        cin >> a[i];
    }
    sort(a,a+3);
    sa = 0;
    for (int j = 0; j < 3; ++j) {
        if(j == 0){sa = 0;} else {
            sa = a[j] - a[j-1];
        }
        sumsa = sa + sumsa;
    }
    cout << sumsa << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int main(){
FASTIO	
char a;
cin>>a;
int b=a+1;
char c=b;
cout<<c;
}


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

int main(void) {
	int a, b; cin >> a >> b;
	string str1 = "", str2 = "";
	for (int i = 0; i < b; i++) {
		str1 += to_string(a);
	}

	for (int i = 0; i < a; i++) {
		str2 += to_string(b);
	}

	if (str1 <= str2) cout << str1 << endl;
	else cout << str2 << endl;

	return 0;
}

Measured memory_bytes: 256