akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;


int main(void) {
    int a, b, c, d;
    
    cin >> a >> b >> c >> d;
    
    int turn = 0;
    while (a > 0 && c > 0) {
        if (turn % 2 == 0)
            c -= b;
        else
            a -= d;

        turn++;
    }

    if (a > 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	string kai(s.size(),' ');
	int basho = 0;
	for(int i = 0;i < s.length();i++)
	{
		if(s.at(i) == 'B')
		{
			if(basho > 0)
			{
				basho--;
				kai.at(basho) = ' ';
			}
		}
		else
		{
			kai.at(basho) = s.at(i);
			basho++;
		}
	}
    cout << kai.substr(0,basho) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] arr = scanner.next().toCharArray();
        scanner.close();

        char[] op = new char[arr.length - 1];

        // bit全探索
        // 集合 (1, 2, 3) の部分集合(1, 12, 123 など) の種類で回す (2のn乗 == Math.pow(2, S.length()))
        for (int i = 0; i < (1 << arr.length - 1); i++) {
            int total = arr[0] - '0';
            for (int j = 0; j < arr.length - 1; j++) {
                if (((i >> j) & 1) == 1) {
                    op[j] = '+';
                    total += arr[j + 1] - '0';
                } else {
                    op[j] = '-';
                    total -= arr[j + 1] - '0';
                }
            }
            if (total == 7) {
                break;
            }
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]);
            if (i < op.length) {
                System.out.print(op[i]);
            }
        }
        System.out.print("=7");
    }
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool okey = false;
    if (a < c && c < b) {
        okey = true;
    }else if(b < c && c < a){
        okey = true;
    }
    
    if(okey){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define PI 3.141592653589793238
#define mod 1000000007
#define endl '\n'
#define fastio; ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    string s;
    cin>>s;
    if(s=="ARC") cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
    return 0;


}


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

int main(void){
  	char s[7] = {0};
    int result=0;
  scanf("%s",&s);
  if(s[2]==s[3] && s[4]==s[5]) result = 1;
  if(result==1) printf("Yes");
  else printf("No");
  
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    ll v[100010][3];
    rep(i,n) cin >> v[i][0] >> v[i][1] >> v[i][2];
    ll dp[100010][3] = {};
    rep(j,3) dp[0][j] = v[0][j];
    rep1(i,n-1) {
        rep(j,3) {
            dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + v[i][j];
        }
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  i32 *a = ALLOC (n, i32);
  for (i32 i = 0; i < m; ++i) {
    i32 b;
    scanf ("%" SCNi32, &b);
    a[b] = 1;
  }
  i32 *dp = ALLOC (n + 2, i32);
  const i32 mod = 1000000007;
  dp[0] = 1;
  for (i32 i = 0; i < n; ++i) {
    if (a[i]) {
      dp[i] = 0;
    } else {
      dp[i + 1] = (dp[i + 1] + dp[i]) % mod;
      dp[i + 2] = (dp[i + 2] + dp[i]) % mod;
    }
  }
  printf ("%" PRIi32 "\n", dp[n]);
}

int main (void) {
  run();
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main(){
    int N, i;
    int minus_num = 0;
    long long minus = 0;
    vector<long long> Plus;
    cin >> N;

    vector<long long> A(N);
    vector<long long> B(N);
    for (i=0; i<N; i++) cin >> A[i];
    for (i=0; i<N; i++) cin >> B[i];

    //long long A_sum = accumulate(A.begin(), A.end(), 0);
    //long long B_sum = accumulate(B.begin(), B.end(), 0);

    for (i=0; i<N; i++){
        if (B[i] > A[i]) {
            minus += (B[i] - A[i]);
            minus_num++;
        }
    }
    // cout << minus_num << '\n';
    for (i=0; i<N; i++){
        if (B[i] < A[i]) Plus.push_back(A[i] - B[i]);
    }

    long long pos = 0;
    if (minus > 0){
        sort(Plus.begin(), Plus.end(), std::greater<long long>());


        for (i=0; i<Plus.size(); i++){
            pos += Plus[i];
            minus_num++;
            if (pos >= minus) break;
        }
    }

    if (pos < minus) cout << -1 << '\n';
    else cout << minus_num << '\n';

}

Measured memory_bytes: 2428
s=[]
S=input()
for i in S:
    s+=[int(i)]
#print(s)
ans=0
if s[0]==0:
    for i in s[0::2]:
        if i!=0:
            ans+=1
            #print(0,i,ans)
    for i in s[1::2]:
        if i!=1:
            ans+=1
            #print(1,i,ans)
#print(s[0::2],s[1::2])
if s[0]==1:
    for i in s[0::2]:
        if i!=1:
            ans+=1
    for i in s[1::2]:
        if i!=0:
            ans+=1
print(ans)

Measured memory_bytes: 10204
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

map<string, int> mp;

ll Cnm(ll n,ll m)//计算组合数C(n,m) 
{
	if(m>n/2)//根据组合公式，可以减少枚举量 
	m=n-m;
	ll a=1,b=1;
	for(int i=1;i<=m;i++)//顺序进行m次运算 
	{
		a*=n+1-i;//计算前i项运算结果的分子a和分母 b 
		b*=i;
		if(a%b==0)
		{
			a/=b;
			b=1;
		}
	}
	return a/b;
}


int main(void) {
    FAST_IO;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans = 0;
    for (auto &x: mp) {
        int m = x.second;
        if (m < 2) continue;
        ans += Cnm(m, 2);
    }
    cout << ans << endl;
    return 0;
}

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

n = int(input())
t = [0] * n
x = [0] * n
y = [0] * n
for i in range(n):
    t[i],x[i],y[i] = map(int,input().split())

def travel(x,y,t):
    if abs(t-t_st) >= abs(x-x_st) + abs(y-y_st) and abs(t-t_st) % 2 == (abs(x-x_st) + abs(y-y_st)) % 2:
        return True
    else:
        return False

t_st = 0
x_st = 0
y_st = 0

ans = travel(x[0],y[0],t[0])

for i in range(1,n):
    x_st = x[i-1]
    y_st = y[i-1]
    t_st = t[i-1]
    if travel(x[i],y[i],t[i]):
        pass
    else:
        ans = False

if ans:
    print("Yes")
else:
    print("No")

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

constexpr int MODULUS = 1000000007;
long long S;

long long memo[2009];

long long ans(long long S) {
  if (S == 3) return 1;
  if (S < 3) return 0;

  if (memo[S] != -1) return memo[S];

  long long ret = 1;
  for (int i=3; i<S; i++) {
    ret += ans(S-i);
    ret %= MODULUS;
  }
  return memo[S] = ret;
}

int main() {

  for (int i=0; i<2009; i++) memo[i] = -1;
  
  cin >> S;
  long long r = ans(S);
  r %= MODULUS;
  r += MODULUS;
  r %= MODULUS;

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 3200
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

length = []
for i in range(N):
    s = XL[i][0] - XL[i][1]
    f = XL[i][0] + XL[i][1]
    length.append([s, f])

length = sorted(length, key=lambda x:x[1])
ans = 0
f = - (10**9+7)
for i in range(N):
    if f <= length[i][0]:
        ans += 1
        f = length[i][1] - 0.5

print(ans)

Measured memory_bytes: 43560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 50100;

bool p[MAXN];

int main()
{
    p[0] = p[1] = 1;
    REP(MAXN)if(!p[i])for(int j = i*2;j<MAXN;j+= i) p[j] = 1;

    int n;
    while(cin >> n && n)
    {
        int ans = 0;
        for(int i = 2;i <= n/2 ;i++) ans += (!p[i]) &(!p[n - i]);

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 912
/* Copyright 2016 AcrossTheSky */
#include <iostream>
#include <cstdio>
#include <utility>
#include <cassert>
#include <map>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sstream>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define PER(i, a, b) for (int i = (a); i >= (b); --i)
#define RVC(i, c) fot (int i = 0; i < (c).size(); ++i)
#define RED(k, u) for (int k = head[(u)]; k; k = edge[k].next)
#define SQR(k) (k) * (k)
#define lowbit(x) ((x) & (-(x)))
#define CL(x, v) memset(x, v, sizeof x)
#define MP std::make_pair
#define PB push_back
#define FR first
#define SC second
#define rank rankk
#define next nextt
#define link linkk
#define index indexx
#define abs(x) ((x) > 0 ? (x) : (-(x)))
using namespace std;
typedef long long LL; typedef pair<int, int> PII;

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

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

template<class T> inline
void read(T *a) {
    char c;
    while (isspace(c = getchar())) {}
    bool flag = 0;
    if (c == '-') flag = 1, *a = 0;
    else
        *a = c - 48;
    while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
    if (flag) *a = -*a;
}

const int mo = 1000000007;
template<class T>
T pow(T a, T b, int c = mo) {
    T res = 1;
    for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c) if (b & i) res = 1LL * res * a % c;
    return res;
}
/*======================= TEMPLATE =======================*/
const int N = 210000;
int n;
LL f[N];
multiset<LL> S;
LL T, E, x[N];
int main() {
    cin >> n >> E >> T;
    REP(i, 1, n) read(x + i);
    int j = 0;
    LL tmp = 1e18;
    S.insert(T);
    REP(i, 1, n) {
        while (2LL * (x[i] - x[j + 1]) >= T) {
            getmin(&tmp, f[j] + x[j + 1] - x[j] -  x[j + 1] * 3);
            multiset<LL>::iterator it = S.find(T + f[j] + x[j + 1] - x[j] - x[j + 1]);
            S.erase(it);
            ++j;
        }
        f[i] = 1e18;
        if (!S.empty()) {
            LL t1 = *S.begin();
            getmin(&f[i], t1 + x[i]);
        }
        getmin(&f[i], tmp + x[i] * 3);
        S.insert(T + f[i] + x[i + 1] - x[i] - x[i + 1]);
    }
    cout << f[n] + E - x[n] << endl;
    return 0;
}


Measured memory_bytes: 3840
from itertools import product
n = int(input())
s = input()
r = []
g = []
b = []
for i in range(len(s)):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    elif s[i] == 'B':
        b.append(i)

ng_cnt = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            continue
        else:
            k = 2 * j - i
            if k < n and s[i] != s[k] and s[j] != s[k]:
                ng_cnt += 1

print(len(r) * len(g) * len(b) - ng_cnt)


Measured memory_bytes: 73928
using System;
using System.Collections.Generic;
using System.Linq;

namespace id_0022cs
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while((line = Console.ReadLine()) != null)
            {
                var n = int.Parse(line);
                if (n == 0) { break; }
                List<int> vs = new List<int>();
                foreach (var x in Enumerable.Range(0, n))
                {
                    vs.Add(int.Parse(Console.ReadLine()));
                }

                int formerValue = 0;
                List<int> dp = new List<int>();
                
                foreach( var x in vs)
                {
                    formerValue = Math.Max(formerValue + x, x);
                    dp.Add(formerValue);
                }
                Console.WriteLine(dp.Max());
            }
        }
    }
}



Measured memory_bytes: 9580
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	int a[40]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	scanf("%d",&k);
	printf("%d\n",a[k]);
}

Measured memory_bytes: 256
x,k,d = map(int, input().split())
X = abs(x)
if X-d*k >= 0:
    print(X-d*k)
else:
    s = X // d
    if (k-s) % 2 == 0:
        print(abs(X-d*s))
    else:
        print(abs(X-d*(s+1)))

Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std;
char s[25];
int main()
{
	cin>>s;
	for(int i=0;i<5;i++)
		printf("%c",s[i]);
	printf(" ");
	for(int i=6;i<13;i++)
		printf("%c",s[i]);
	printf(" ");
	for(int i=14;i<19;i++)
		printf("%c",s[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 256
# 入力
S = str(input())
# 配列に変換
S_list = list(S)

S_len  = len(S_list)
## B = 0, W = 1
##BWB
BWB_list = ["0"] * S_len
for i in range(S_len):
  if i % 2 != 0:
    BWB_list[i] = "1"
## print("BWB_list:"+str(BWB_list))

##WBW
WBW_list = ["1"] * S_len
for i in range(S_len):
  if i % 2 != 0:
    WBW_list[i] = "0"
## print("WBW_list:"+str(WBW_list))

    
## cost	の計算
##BWB
BWB_cost = 0
for (target, bwb) in zip(S_list, BWB_list):
  if target != bwb:
    BWB_cost += 1
## WBW
WBW_cost = 0
for (target, wbw) in zip(S_list, WBW_list):
  if target != wbw:
    WBW_cost += 1
    
## print("BWB_cost:"+str(BWB_cost))
## print("WBW_cost:"+str(WBW_cost))
print(str( min(BWB_cost,WBW_cost) ) )

Measured memory_bytes: 5620
#include <iostream>
using namespace std;
int main()
{
	string input;
	cin>>input;
	if (input == "Sunny")
	{
		cout<<"Cloudy";
	}
	else if (input == "Cloudy")
	{
		cout<<"Rainy";
	}
	else
	{
		cout<<"Sunny";
	}
	return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  string S;
  cin >> S;
  string correct = "CODEFESTIVAL2016";
  int res = 0;
  REP(i,16) if(S[i] != correct[i]) res++;
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/1/30 8:02:34
*******************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=404;
int n,m,s;
int like[maxn][maxn],a[maxn][maxn];
int used[maxn],t[maxn],mind=0x7fffffff,cho;
int main()
{
      //  freopen("at2671.in","r",stdin);
       // freopen("at2671.out","w",stdout);
       cin>>n>>m;
       
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            	cin>>like[i][j];
               // cin>>s,like[i][s]=j;
        for(int k=0;k<m;k++)
        {
            used[cho]=1;
            cho=0;
            memset(t,0,sizeof t);
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    if(used[like[i][j]])continue;
                    t[like[i][j]]++;break;
                }
            }
            for(int i=1;i<=m;i++) if(t[cho]<t[i]) cho=i;
            mind=min(mind,t[cho]);
        }
        cout<<mind<<endl;
        return 0;
}

Measured memory_bytes: 768
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


int a, b, dis[55][55], sha;
char area[55][55];

int bfs(int n, int m) {
	queue<pair<int, int>>q;
	q.emplace(n, m);
	memset(dis, -1, sizeof(dis));
	dis[n][m] = 0;

	while (!q.empty()) {
		pair<int, int>mon = q.front();
		q.pop();
		if (mon.first == a - 1 && mon.second == b - 1) { return dis[mon.first][mon.second]; }

		for (int i = 0; i < 4; ++i) {
			int nn = mon.first + dy[i], mm = mon.second + dx[i];
			if (nn < 0 || mm < 0 || nn >= a || mm >= b || dis[nn][mm] != -1 || area[nn][mm] == '#') { continue; }
			dis[nn][mm] = dis[mon.first][mon.second] + 1;
			q.emplace(nn, mm);
		}
	}

	return -1;
}

int main() {
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) { cin >> area[i][j]; if (area[i][j] == '#') { ++sha; } }
	}
	int ans = bfs(0, 0);
	if (ans == -1) { cout << -1 << endl; }
	else { cout << a * b - sha - ans - 1 << endl; }
}

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

int main()
{
    long long int N;
    string S;
    cin >> N;
    cin >> S;
    int count = 1;
    for(int i = 0; i < N - 1;i++)
    {
        if(S[i] != S[i + 1])
            count++;
    }
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++) {
			a[i]=sc.nextLong();
		}
		long ans = 0;
		for(int i = 1; i < n; i++) {
			if(a[i]<a[i-1]) {
				ans+=a[i-1]-a[i];
				a[i]=a[i-1];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 60852
/// awoooooo

# include <bits/stdc++.h>

# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)1e6 + 5;
const int inf = (int)1e9 + 7;

int a, b, c;

int main(){
  scanf("%d %d %d", &a, &b, &c);
  if(a + b + 1 >= c){
    printf("%d", b + c);
  } else{
    printf("%d", b + (a + b + 1));
  }
  return 0;
}


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

vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int c = 10000;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w;
  cin >> h >> w;
  
  queue<pair<int, int>> q;
  vector<vector<char>> a(h, vector<char>(w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a.at(i).at(j);
      if(a.at(i).at(j) == '#') q.push(make_pair(c * i + j, 0));
    }
  }
  
  int ans = 0;
  pair<int, int> p;
  while(!q.empty()){
    p = q.front();
    q.pop();
    for(int i = 0; i < 4; i++){
      if(p.first / c + dx.at(i) >= 0 && p.first / c + dx.at(i) < h
      && p.first % c + dy.at(i) >= 0 && p.first % c + dy.at(i) < w){
        if(a.at(p.first / c + dx.at(i)).at(p.first % c + dy.at(i)) == '.'){
          a.at(p.first / c + dx.at(i)).at(p.first % c + dy.at(i)) = '#';
          q.push(make_pair(p.first + dx.at(i) * c + dy.at(i), p.second + 1));
          ans = p.second + 1;
        }
      }
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 9488
from collections import deque

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

adj = [[] for _ in range(n + 1)]
for a, b in ab:
    adj[a].append(b)
    adj[b].append(a)

s = 1
dq = deque([s])
d = [-1] * (n + 1)
d[s] = 0
p = [-1] * (n + 1)

while dq:
    u = dq.popleft()
    for v in adj[u]:
        if d[v] == -1:
            d[v] = d[u] + 1
            p[v] = u
            dq.append(v)

print("Yes")
print(*p[2:], sep="\n")


Measured memory_bytes: 60248
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(void) {
    char s[100002];
    int count1 = 0, count2 = 0;

    if(scanf("%s", s) == 1);

    for(long i = 0; i < strlen(s); i++) {
        if(i % 2 == 0) {
            if(s[i] == '1') {
                count1++;
            }
            if(s[i] == '0') {
                count2++;
            }
        } else {
            if(s[i] == '0') {
                count1++;
            }
            if(s[i] == '1') {
                count2++;
            }
        }
    }

	if(count1 > count2) {
        printf("%d", count2);
    } else {
        printf("%d", count1);
    }

      return 0;
}

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


int main(){
    random_device rd;
    mt19937_64 mt(rd());
    vector<ll>hash(202020, 0);
    for(ll i = 0; i < 202020; i++){
        hash[i] = mt();
    }
    
    string s, t;
    cin >> s >> t;
    vector<ll>S(256, 0);
    vector<ll>T(256, 0);
    for(ll i = 0; i < s.size(); i++){
        S[s[i]] ^= hash[i];
        T[t[i]] ^= hash[i];
    }
    sort(S.begin(), S.end());
    sort(T.begin(), T.end());
    ll flg = 1;
    for(ll i = 0; i < 256; i++){
        if(S[i] != T[i])flg = 0;
    }
    if(flg)cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 2436
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
#include<numeric>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;
 
Int n;
Real a[440000];
Real b[440000];
Real e[440000];
Real c[440000];
 
Real bi_sum[440000];
Real b_sum[440000];
 
vector<P> highs;
set<int> done;
 
int main(){
    cin >> n;
    int mxa = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        a[i+n] = a[i];
        if(a[mxa] < a[i])mxa = i;
    }
    for(int i = 0;i < n;i++){
        cin >> b[i];
        b[i+n] = b[i];
    }
    e[mxa] = e[mxa + n] = a[mxa];
    for(int i = 1;i < n;i++){
        c[mxa + i+1] = - 2 * b[mxa + i] + 2*c[mxa + i] - c[mxa + i-1];
//        cout << c[mxa + i + 1] << endl;
    }
 
    using RP = pair<Real, Real>;
    vector<RP> ch = {{mxa, a[mxa] + c[mxa]}};
 
    for(int i = 1;i <= n;i++){
        RP p = {mxa + i, a[mxa + i] + c[mxa + i]};
        while(ch.size() >= 2){
            RP bb = ch[ch.size() - 2];
            RP b = ch.back();
            bb.first -= p.first;bb.second -= p.second;
            b.first -= p.first;b.second -= p.second;
            if(b.first * bb.second - b.second * bb.first <= 0)ch.pop_back();
            else break;
        }
        ch.push_back(p);
    }
    for(auto p:ch){
//        cout << p.first << " " << p.second << endl;
    }
    Real ans = a[mxa];
    for(int i = 1;i < n;i++){
        int ind = mxa + i;
        auto r = lower_bound(ch.begin(), ch.end(), RP(ind, -INF));
        auto l = prev(r);
        auto l_dist = ind - l->first;
        auto r_dist = r->first - ind;
//        cout << ind << " "  << (l_dist * r->second + r_dist * l->second) /(l_dist + r_dist) - c[ind] << endl;
        ans += (l_dist * r->second + r_dist * l->second) /(l_dist + r_dist) - c[ind]; 
    }
    printf("%.10lf\n", double(ans / n));    
    
    return 0;
}

Measured memory_bytes: 27136
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> A(N);
	for (auto &a : A) {
		cin >> a;
	}

	vector<long long> X(N, 0);

	X[N - 1] = A[N - 1];
	for (int i = 0; i < N - 1; ++i) {
		if (i % 2 == 0) {
			X[N - 1] -= A[i];
		}
		else {
			X[N - 1] += A[i];
		}
	}
	X[N - 1] /= 2;
	for (int i = N - 2; i >= 0; --i) {
		X[i] = A[i] - X[i + 1];
	}

	for (auto x : X) {
		cout << 2 * x << " ";
	}
	cout << endl;
}


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

int main(){
  long long int n,x;
  cin >> n >> x;
  long long int a[n];
  for (int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  long long int b[n];
  b[0]=a[0];
  for (int i=1;i<n;i++){
    b[i]=b[i-1]+a[i];
  }
  int ans=0;
  for (int i=0;i<n-1;i++){
    if(b[i]<=x){
      ans=max(ans,i+1);
    }
  }
  if(b[n-1]==x){
    ans=n;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int res[100003],n,m,ans;
vector<int>v[100003];
int dfs(int x){
	if(res[x])return res[x];
	for(int i=0;i<v[x].size();i++)
		res[x]=max(dfs(v[x][i])+1,res[x]);
	ans=max(ans,res[x]);
	return res[x];
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		v[a].push_back(b);
	}
	for(int i=0;i<n;i++)
		if(!res[i])
			dfs(i);
	cout<<ans;
}

Measured memory_bytes: 8192
import fractions

N = int(input())
A = [int(i) for i in input().split()]
A.insert(0,0)
A.append(0)
tmp = 0

L, R = [0]*(N+2), [0]*(N+2)
L[0] = 0
R[N+1] = 0

for i in range(1, N+1):
  L[i] = fractions.gcd(L[i-1], A[i])
  R[N+1-i] = fractions.gcd(R[N+2-i], A[N+1-i])

for i in range(1,N+1):
  tmp = max(tmp, fractions.gcd(L[i-1], R[i+1]))
print(tmp)

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

	public static void main(String[]args) {
		
		Scanner S = new Scanner(System.in);
		
		int[] t = new int[3];
		
		for(int i = 0; i<3; i++) {
			t[i] = S.nextInt();
		}
			if(t[0] == t[1] && t[1] == t[2]) {
				
				System.out.println("Yes");
					
			}
			else {
				System.out.println("No");
			}
		}
	}


Measured memory_bytes: 23764
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,cnt2,cnt5;
int main()
{
	scanf("%lld",&n);
	if(n&1)return printf("0"),0;
//	long long x=n;
//	while(x)x/=2,cnt2+=x;
//	x=n;
	n/=2;
	while(n)n/=5,cnt5+=n;
	printf("%lld",cnt5);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main() {

	int a, b, i = 0;

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

	if (a > 0) {
		if (b < 0) {
			printf("Zero");
		}
		else {//aもbもどちらも正の数
			printf("Positive");
		}
	}
	else if (a < 0) {
		if (b > 0) {
			printf("Zero");
		}
		else if ((a - b) % 2 == 0) {
			printf("Negative");
		}
		else {
			printf("Positive");
		}
	}

	return 0;
}

Measured memory_bytes: 128
H,W=[int(s) for s in input().split()]
s=''
for i in range(W):
  s = s + '.' 
ls=[]
for i in range(H):
  x=input()
  if x!=s:
    ls.append(list(x))
i=0
for j in range(W):
  for e in ls:
    if e[i]=='#':
      i+=1
      break
  else:
    for e in ls:
      e.pop(i)
for e in ls:
  print(''.join(e))

    

Measured memory_bytes: 38896
def bsf_dist_grid(grid,start):
    H = len(grid)
    W = len(grid[0])
    d = [[-1]*W for _ in [0]*H]
    d[start[0]][start[1]] = 0
    q = [start[::-1]]
    while q:
        qq = []
        for xy in q:
            x,y = xy
            d0 = d[y][x]
            for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):
                if (not 0<=x+dx<W) or (not 0<=y+dy<H): continue
                if d[y+dy][x+dx] != -1: continue
                if not grid[y+dy][x+dx]: continue
                d[y+dy][x+dx] = d0
                q.append((x+dx,y+dy))
            for dx,dy in ((2,0),(2,1),(2,2),(2,-1),(2,-2),(1,2),(1,1),(1,-1),(1,-2),(0,2),(0,-2),(-1,2),(-1,1),(-1,-1),(-1,-2),(-2,2),(-2,1),(-2,0),(-2,-1),(-2,-2)):
                if (not 0<=x+dx<W) or (not 0<=y+dy<H): continue
                if d[y+dy][x+dx] != -1: continue
                if not grid[y+dy][x+dx]: continue
                qq.append(((x+dx,y+dy),d0+1))
        q = []
        for qq2,d2 in qq:
            x,y = qq2
            if d[y][x] != -1: continue
            d[y][x] = d2
            q.append(qq2)
    return d

H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
s = [[c=="." for c in input()] for _ in [0]*H]

d = bsf_dist_grid(s,(Ch-1,Cw-1))

print(d[Dh-1][Dw-1])

Measured memory_bytes: 143720
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define M   1000000007 // 1e9 + 7
#define MAXN 500100
using namespace std;
typedef pair<int,int> pii;
const int inf = 1e18;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

int32_t main(){
	fastio;
	int n,r;
	cin>>n>>r;
	if(n>=10){
		cout<<r<<endl;
	}else cout<<r + (100*(10-n))<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}


unordered_map <ll,ll> ma;
void solve(){
    ll n;
    cin >> n;
    ll N = n;
    for(ll i=2;i<=sqrt(n);i++){
        ll cnt = 0;
        while(N%i == 0){
            cnt ++;
            N/=i;
        }
        if(cnt)
            ma[i] = cnt;

    }
    if(N > 1){
        ma[N] = 1;
    }
    ll an = 0;
    for(auto it:ma){
        for(ll j=1;j<=1000;j++){
            if(it.S - j>=0){
                it.S-=j;
                an++;
            }
            else{
                break;
            }
        }
    }
    g(an);


}
int main()
{
#ifndef ONLINE_JUDGE
input_from_file
#endif
 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
   // cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

Measured memory_bytes: 3680
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            char odd = 'R';
            char even = 'L';
            bool ret = true;
            for (int i = 1; i <= S.Length; i++)
            {
                if ((i % 2 == 0 && S[i - 1] == odd) || (i % 2 == 1 && S[i - 1] == even))
                {
                    ret = false;
                    break;
                }
            }

            if (ret)
            {
                Console.Write("Yes");
            }
            else
            {
                Console.Write("No");
            }
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC130.D();
        //    temp.Run();
        //}

    }
}

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

namespace ProconTemplate
{
    //https://atcoder.jp/contests/agc038/tasks/agc038_a
    class Class1
    {
        public static void Main(string[] args)
        {
            string[] asInput = Console.ReadLine().Split(' ');
            int H = int.Parse(asInput[0]);
            int W = int.Parse(asInput[1]);
            int A = int.Parse(asInput[2]);
            int B = int.Parse(asInput[3]);

            for (int y = 0; y < H; y++)
            {
                string sOut = "";
                for (int x = 0; x < W; x++)
                {
                    sOut += (x < A ^ y < B) ? '1' : '0';
                }
                Console.WriteLine(sOut);
            }
        }
    }
}


Measured memory_bytes: 16156
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int count=0;
    for(int i=1;i<=n;i+=2){
      int cou=1;
      for(int j=3;j<=i;j+=2){
        if(i%j==0)cou++;
      }
      if(cou==8)count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 35836
#include <iostream>
#include <cmath>

using namespace std;

double distance(double x1, double y1, double x2, double y2)
{
	return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}

double helon(double a, double b, double c)
{
	double s = (a + b + c) / 2;

	return sqrt(s * (s - a) * (s - b) * (s - c));
}

double helon(double x1, double y1, double x2, double y2, double x3, double y3)
{
	double a = distance(x1, y1, x2, y2);
	double b = distance(x2, y2, x3, y3);
	double c = distance(x3, y3, x1, y1);

	return helon(a, b, c);
}

int main()
{
	double x1, y1, x2, y2, x3, y3, xp, yp;

	while ( cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
		if (round(helon(x1, y1, x2, y2, x3, y3)*100) == round((helon(x1, y1, x2, y2, xp, yp) + helon(x2, y2, x3, y3, xp, yp) + helon(x3, y3, x1, y1, xp, yp)) *100)) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3268
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	nClocks := scanInt(sc)

	clocks := make([]int64, nClocks)
	for i := 0; i < len(clocks); i++ {
		clocks[i] = int64(scanInt(sc))
	}

	m := clocks[0]
	for i := 1; i < len(clocks); i++ {
		m = lcm(m, clocks[i])
	}

	fmt.Println(m)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func lcm(a, b int64) int64 {
	return a * (b / gcd(a, b))
}

func gcd(a, b int64) int64 {
	if a > b {
		b, a = a, b
	}

	for b%a > 0 {
		b, a = a, b%a
	}
	return a
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
string A[50],B[50];
int main(){
    int N,M;
    cin >> N >> M;
    REP(i,N) cin >> A[i];
    REP(i,M) cin >> B[i];
    bool ans = false;
    REP(i,N-M+1){
        REP(j,N-M+1){
            bool ans2 = true;
            REP(k,M){
                if(B[k] != A[i+k].substr(j,M)) ans2 = false;
            }
            if(ans2) ans = true;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

   char s[3];
   int i,a=700;
   scanf("%s",s);

   for(i=0;i<3;i++){
      if(s[i]=='o'){
         a+=100;
         }
      }

   printf("%d\n",a);
      
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

map<ll, ll> factoring(ll n){
  	map<ll, ll> mp;
  	for (ll i = 2; i * i <= n; i++) {
    	while (n % i == 0) {
      	    n /= i;
      	    mp[i]++;
    	}
  	}
  	if (n != 1) mp[n]++;
    return mp;
}

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

    ll n;
    cin >> n;
    map<ll, ll> mm = factoring(n);
    ll res = 0;
    for (auto p : mm) {
        ll h = p.second, cnt = 1;
        while (h - cnt >= 0) {
            h -= cnt;
            cnt++;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <iostream>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define INF 999999999
using namespace std;
int cnt=0;
void merge(int A[],int left,int mid,int right);
void mergeSort(int A[],int left,int right);

int main()
{
    int n;
    cin >> n;
    int S[n];
    REP(i, n) cin >> S[i];
    mergeSort(S, 0, n);
    REP(i,n) {
        cout << S[i];
        if (i < n-1) cout << " ";
    }
    cout << endl << cnt << endl;;
    return 0;
}

void merge(int A[],int left,int mid,int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1], R[n2];
    REP(i,n1) L[i] = A[left + i];
    REP(i,n2) R[i] = A[mid + i];
    L[n1] = INF;
    R[n2] = INF;
    int i = 0;
    int j = 0;
    FOR(k,left,right){
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i = i + 1;
        } else {
            A[k] = R[j];
            j = j + 1;
        }
    }
}

void mergeSort(int A[],int left,int right){
    if (left+1 < right) {
        int mid = (left + right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid ,right);
    }
}

Measured memory_bytes: 6884
#include<iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include<set>


using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;


int N, M, L, Q;
map<int, int> m[512];


#define PI 3.141592653589
ll A[200001], F[200001];

int is_ok(ll y, const int N, const ll K){
    ll cnt = 0;
    //fprintf(stderr, "y = %d\n", y);
    for (int i = 0; i < N; i++){
        //fprintf(stderr, "%d, %d, %d,, %d\n", 
        //    A[i], F[i], y, A[i] - y / F[i]);
        if (A[i] - y / F[i] > 0){
            cnt += A[i] - y / F[i];
            //fprintf(stderr, "%d, %d, %d\n", i, A[i] - y / F[i], cnt);
        }
        //cnt += max(0, A[i] - y / F[i]);
    }
    if (cnt <= K){
        return 1;
    } else {
        return 0;
    }
}

int main()
{
    int N;
    ll K;
    cin >> N >> K;
    ll max_val = 0LL;
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    for (int i = 0; i < N; i++){
        cin >> F[i];
        if (max_val < A[i] * F[i]){
            max_val = A[i] * F[i];
        }
    }
    sort(A, A+ N, greater<int>());
    sort(F, F+ N);
    
    ll lb = -1, ub = max_val;
    
    while (ub - lb > 1){
        ll mid = (ub + lb) /2;
        if (is_ok(mid, N, K)){
            ub = mid;
        } else {
            lb = mid;
        }
    }
    cout << ub << endl;
    return 0;    
}


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

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

    if(c=='+'){
        cout<<a+b<<endl;
    }
    else {
        cout<<a-b<<endl;
    }

}


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


int main(){
    int a, b;
    int result;

    cin >> a >> b;

    if(a >= 13){
        result = b;
    } else if(a <= 12 && a >= 6){
        result = b / 2;
    } else {
        result = 0;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC
{
    class B043
    {
        static void Main()
        {
            string str = Console.ReadLine();
            Stack<char> chars = new Stack<char>();
            foreach(char key in str)
            {
                if (key == '0')
                    chars.Push('0');
                if (key == '1')
                    chars.Push('1');
                if (key == 'B' && chars.Count() != 0)
                    chars.Pop();
            }
            Console.WriteLine(new string(chars.Reverse().ToArray()));
        }
    }
}


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

int main() {
  long N, A, B;
  cin >> N >> A >> B;

  long repeat = N / (A + B);
  long carry = N % (A + B);
  long ans = 0;
  if (carry > A) {
    ans = A * repeat + A;
  } else {
    ans = A * repeat + carry;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
from copy import deepcopy
N, M, K = map(int, input().split())

table = [-1]*N
def union(x, y):
    global table
    x, y = find(x), find(y)
    if x==y:
        return False
    else:
        if table[x]>table[y]:
            x, y = y, x
        table[x] += table[y]
        table[y] = x
        return True

def find(x):
    if table[x]<0:
        return x
    else:
        table[x] = find(table[x])
        return table[x]

def rank(x):
    return table[find(x)]

friend = [[] for _ in range(N)]
block = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
    union(a-1, b-1)

for _ in range(K):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)

ans = [""]*N
for i in range(N):
    tmp = abs(rank(i)) - len(friend[i]) - 1
    cnt = 0
    for b in block[i]:
        if find(i)==find(b):
            cnt += 1
    ans[i] = str(tmp - cnt)
print(" ".join(ans))

Measured memory_bytes: 54936
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

typedef tuple<ll,ll> sushi;
int main(){
    ll N,K;
    cin >> N >> K;
    vector<sushi> s(N);
    vector<ll>cnt(N,0); // 各ネタが何貫あるか
    ll delicious_p=0; // おいしさポイント
    ll kind_p=0; // 種類ボーナスポイント
    ll ans=0; // 満足ポイント

    rep(i,N){
        ll t,d;
        cin >> t >> d;
        t--;
        s[i]=sushi(d, t);
    }

    sort(s.begin(),s.end(), greater<sushi>());

    priority_queue<sushi, vector<sushi>, greater<sushi>> que;
    for(int i=0; i<K; i++){
        delicious_p+=get<0>(s[i]);
        cnt[get<1>(s[i])]++;
        que.push(s[i]);
    }

    for(int i=0; i<N; i++){
        if(cnt[i]>0) kind_p++;
    }

    ans=delicious_p + kind_p*kind_p;

    for(ll i=K; i<N; i++){
        ll val = get<0>(s[i]);
        ll kind = get<1>(s[i]);

        // すでにそのネタがあるならおいしさポイントを減らしてまで入れるのは無駄
        if(cnt[kind]>0) continue;

        while(!que.empty()){
            ll qval = get<0>(que.top());
            ll qkind = get<1>(que.top());
            que.pop();

            // ネタが1貫しかないのに取り出すと種類ポイントは同じでもおいしさが減る
            if(cnt[qkind]==1) continue;

            cnt[qkind]--;
            cnt[kind]++;

            delicious_p-=qval;
            delicious_p+=val;
            kind_p++;
            ans=max(ans, delicious_p + kind_p*kind_p);
            break;
        }
    }

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



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

int a[5005];
bool pref[5005][5005], suff[5005][5005];
int sum[5005][5005];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    int res = 0;
    for(int i=1;i<=n;i++) scanf("%d", &a[i]), res = min(res+a[i], k);

    pref[0][0] = 1;
    suff[n+1][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(pref[i-1][j]){
                pref[i][min(k, j+a[i])] = 1;
                pref[i][j] = 1;
            }
        }
    }
    for(int i=n;i>=1;i--){
        for(int j=0;j<=k;j++){
            if(suff[i+1][j]){
                suff[i][min(k, j+a[i])] = 1;
                suff[i][j] = 1;
            }
        }
    }
    for(int i=1;i<=n+1;i++){
        sum[i][0] = suff[i][0];
        for(int j=1;j<=k;j++){
            sum[i][j] = sum[i][j-1] + suff[i][j];
        }
    }

    int ans = 0;
    for(int i=1;i<=n;i++){
        bool ok = 1;
        for(int j=0;j<=k-1;j++){
            if(pref[i-1][j]){
                if(j+a[i] >= k){
                    ok = 0;
                    break;
                }
                int l = k-(j+a[i]);
                int r = k-j-1;
                if(l <= r && sum[i+1][r] - sum[i+1][l-1] > 0) ok = 0;
            }
        }
        for(int j=max(0, k-a[i]);j<=k-1;j++){
            if(pref[i-1][j]) ok = 0;
            if(suff[i+1][j]) ok = 0;
        }
        ans += ok;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 147072
#include <iostream>
#include <algorithm>
using namespace std;
int value[2][201],n,k,x;

int main()
{
 cin>>n>>k;
 for(int i=1;i<=2*n;i++) value[0][i]=i;
 for(int i=0;i<k;i++){
  cin>>x;
  if(x==0){
   for(int j=1;j<=2*n;j++){
    if(j&1) value[(i+1)&1][j]=value[i&1][j/2+1];
    else value[(i+1)&1][j]=value[i&1][j/2+n];
    }
   }
  else{
    for(int j=1;j<=2*n-x;j++) value[(i+1)&1][j]=value[i&1][x+j];
    for(int j=2*n-x+1;j<=2*n;j++) value[(i+1)&1][j]=value[i&1][j-2*n+x];
   }
 }
 for(int i=1;i<=2*n;i++) cout<<value[k&1][i]<<endl;
}

Measured memory_bytes: 1160