akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int64_t mod = 1000000007;

int64_t power(int64_t n, int64_t k) {
  if (k == 0) return 1;
  int64_t ans = power(n * n % mod, k / 2);
  if (k % 2) ans = ans * n % mod;
  return ans;
}

int64_t inv(int64_t a) {
  return power(a, mod - 2);
}

int64_t gcd(int64_t a, int64_t b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int64_t lcm(int64_t a, int64_t b) {
  return a / gcd(a, b) * b % mod;
}

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  int64_t l = 1, ainv = 0;
  map<int64_t, int64_t> s;
  for (int i = 0; i < n; i++) {
    ainv += inv(a.at(i));
    ainv %= mod;
    map<int64_t, int64_t> scache;
    for (int d = 2; d * d <= a.at(i); d++) {
      while (a.at(i) % d == 0) {
        scache[d]++;
        a.at(i) /= d;
      }
    }
    scache[a.at(i)]++;
    for (auto x : scache) {
      s[x.first] = max(s[x.first], scache[x.first]);
    }
  }
  for (auto x : s) {
    for (int i = 0; i < x.second; i++) {
      l *= x.first;
      l %= mod;
    }
  }
  cout << l * ainv % mod << endl;
}


Measured memory_bytes: 896
n, m = sorted(map(int, input().split()))
mod = 10**9 + 7


def factorial(n):
    ans = 1
    for i in range(1, n + 1):
        ans *= i
        ans %= mod
    return ans
if n == m:
    ans = factorial(n)
    print(ans ** 2 * 2 % mod)
elif m - n == 1:
    ans = factorial(n)
    print(ans ** 2 * m % mod)
else:
    print(0)


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int a[100010];
int main() {
	int n;
	scanf("%d", &n);
	int gap = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		gap = max(gap, a[i]);
	}
	int ch = -1;
	int cc = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == gap)continue;
		int cc1 = min(a[i], gap - a[i]);
		if (ch < cc1)
		{
			ch = cc1;
			cc = a[i];
		}
	}
	printf("%d %d\n", gap, cc);
}

Measured memory_bytes: 512
object Main
  extends App {
  val _   = readInt
  val ans = readLine
    .split(" ")
    .map(_.toInt)
    .zipWithIndex
    .map { case (n, i) => n == i + 1 }
    .foldLeft((0, false))((acc, h) => (acc._2, h) match {
      case (false, true) => (acc._1 + 1, true)
      case _             => (acc._1, false)
    })
    ._1
  println(ans)
}

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


    class Program
    {
        static void Main(string[] args)
        {
            long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            if (a[0] >= 30)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }

Measured memory_bytes: 28224
#include<bits/stdc++.h>
#define lli long long int
#define pii pair<lli, lli>

using namespace std;
deque<pii> q;
int main()
{
    lli n, tmp, cnt, i, sum=0;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> tmp >> cnt;
        q.push_front(pii(tmp,cnt));
    }
    for(i=0;i<n;i++)
    {
        tmp=q[i].first+sum;
        cnt=q[i].second;
        sum += (ceil((double)tmp/(double)cnt)*cnt)-tmp;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define MAX 105


int n,m,a,b,c;
int ans=0;

int t[MAX];
int g[MAX];
int G[MAX][MAX];

void rec(int p,int cnt,int size){

  
  
  if(cnt==size){
    int sum=0;
    for(int i=0;i<size;i++){

      int mini=1e9;
      for(int j=0;j<size;j++){
        if(i==j)continue;
        mini=min(mini,G[t[i]][t[j]]);
      }
      sum+=mini;
    }

    ans=max(ans,sum);
    return;
  }
  if(p==n+1)return;

  rec(p+1,cnt,size);

  if(g[p]>=size-1){
    t[cnt]=p;
    rec(p+1,cnt+1,size);
  }
}

int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a>>b>>c;
    g[a]++;
    g[b]++;
    G[a][b]=G[b][a]=c;
  }
  for(int i=2;i<=14;i++)rec(1,0,i);
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
	long long int n,i,j;
	cin>>n;
	long long int arr[n],max=0;
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]>max)
		max=arr[i];
		
	}
	long long int arr1[max];
	for(i=0;i<max;i++)
	{
		arr1[i]=0;
	}
	
	for(i=0;i<n;i++)
	{
		arr1[arr[i]-1]++;
	}
	
	long long int total=0;
	for(i=0;i<max;i++)
	{
		total=total+(arr1[i]*(arr1[i]-1))/2;
	}
	
	for(i=0;i<n;i++)
	{
		cout<<total-(arr1[arr[i]-1]-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

#define loop(n) for(int lp=0; lp<(n); lp++)
#define ascent(i, a, b)  for(int (i)=(a); (i)<(b); (i)++)
#define descent(i, a, b) for(int (i)=(a); (i)<(b); (i)--)

int main() {
  string D;
  cin >> D;

  if(D.length() < 8) {
    cout << D << endl;
    return 0;
  }

  /*
  map<string, string> mask;
  mask.insert(pair<string, string>("A", "AAAAAAAA"));
  mask.insert(pair<string, string>("I", "IIIIIIII"));
  mask.insert(pair<string, string>("D", "DDDDDDDD"));
  mask.insert(pair<string, string>("U", "UUUUUUUU"));
  mask.insert(pair<string, string>("N", "NNNNNNNN"));
  mask.insert(pair<string, string>("N", "NNNNNNNN"));
  */


  string ans, tmp;
  int i;
  for(i = 0;i < D.length()-7;i++) {
    tmp.clear();
    tmp = D.substr(i, 8);
    int mask = 0;

    ascent(k, 0, tmp.length()) {
      if(tmp[k] == 'A') 
	mask += 1*100000;
      else if(tmp[k] == 'I')
	mask += 1*10000;
      else if(tmp[k] == 'D')
	mask += 1*1000;
      else if(tmp[k] == 'U')
	mask += 1*100;
      else if(tmp[k] == 'N')
	mask += 1*10;
      else if(tmp[k] == 'Y') 
	mask += 1;
    }


    if(mask == 211121) {
      ans += "AIZUNYAN";
      i += 7;
    }
    else {
      ans += D[i];
    }
  }

  ans += D.substr(i, D.length());

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

Measured memory_bytes: 1196
#include <stdio.h>

int main()
{
    int H, W;
    int h, w;
    while(1) {
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) {
            break;
        }
        for(h = 0; h < H; h++) {
            for(w = 0; w < W; w++) {
                if((h+w)%2 == 0) {
                    putchar('#');
                } else {
                    putchar('.');
                }
            }
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 2108
N = int(input())
v = list(map(int,input().split()))

v = sorted(v, reverse = False)
def average(x,y):
    XY = (x + y) / 2
    return XY

gen = v[0]
for i in range(1,N):
    gen = average(gen ,v[i])

print(gen)    

Measured memory_bytes: 9176
//********************************************************************//
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fi first 
#define se second 
#define RANGE(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DFOR(i, a, b) for(int i = a; i > b; --i)
#define DEB(x) cout << #x << ": " << x << endl
#define ALL(v) v.begin(), v.end() 
#define SORT(v) sort(ALL(v))
#define DISPV(v) { for(auto x___: v) cout << x___ << " "; cout << endl; }
#define DISPM(m) { for(auto x____: m){ cout << x____.first << ": " << x____.second << endl; } };
#define DISPMV(m) { for(auto x_____: m){ cout << x_____.first << ": " ;DISPV(x_____.second);} };
using LL = long long;
using VI = vector <int>;
using VC = vector <char>;
using VS = vector <string>;
using VL = vector <long long>;
using VVI = vector<VI>;
using VVL = vector <VL>;
using MII = map<int, int>;
using MIVI = map<int, VI>;
using MSS = map<string, string>;
using MLL = map<LL, LL>;
int READ_INT(){int temp;cin>>temp;return temp;}      // read an int
LL READ_LONG(){LL temp;cin>>temp;return temp;}      // read a long long
void mcs(VI &series, int &max_sum){                    // maximum contigous sub sum(kadane)
    int s=0;
    for(auto x: series){
        s += x;
        max_sum = max(max_sum, s);
        if(s < 0)s = 0;
    }
}
template<typename T>
T MAX(T t){ return t;}
template <typename T, typename... Args>
T MAX(T t, Args... args){ return max(t, MAX(args...)); }
const int MOD = int(1e9) + 7;
const int INF = 1e9 + 5;
const double PI = acos(-1.0); //M_PI;
const double EPS = 1e-9;
//********************************************************************//

LL n, w;
vector<array<LL, 2>>items;    // {weight, value}
LL dp[100001][101];


LL max_sum_values(int n, int capacity){
    if(n == 0)return 0;
    if(dp[capacity][n] != -1)
		return dp[capacity][n];
	LL a;
    if(items[n][0] <= capacity){        // either include or exclude
        a =  max(max_sum_values(n-1, capacity), 
                max_sum_values(n-1, capacity-items[n][0]) + items[n][1]);
    }
    else{       // exclude
        a = max_sum_values(n-1, capacity);
    } 
    dp[capacity][n] = a;
    return dp[capacity][n];
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> w;
    items.push_back({0, 0});
	memset(dp, -1, sizeof(dp));
    RANGE(i,n)items.push_back({READ_INT(), READ_INT()});
    cout << max_sum_values(n, w) << endl;
    // for(auto v: dp)cout << v.first.first << ", " << v.first.second << ": " << v.second << endl;
    // for(auto v: dp)cout << v.first  << ": " << v.second << endl;
    return 0;
}



/* complie flags
-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector
*/

Measured memory_bytes: 82528
#include <stdio.h>

int main(void)
{

  long long int n, i, sum=0, not_sum=0;

  scanf("%lld", &n);

  if (n == 1) sum = 1;
  else if (n == 2) sum = 3;
  else if (n == 3) sum = 3;
  else if (n == 4) sum = 7;
  else  if (n >= 5 && n < 15) {
    not_sum += (3 + (n / 3) * 3) * (n / 3)/2;
    not_sum += (5 + (n / 5) * 5) * (n / 5)/2; 
    sum = (1+n)*n/2 - not_sum;
  } else {
    not_sum += (3 + (n / 3) * 3) * (n / 3)/2;
    not_sum += (5 + (n / 5) * 5) * (n / 5)/2; 
    not_sum -= (15 + (n / 15) * 15) * (n / 15)/2; 
    sum = (1+n)*n/2 - not_sum;
  }

  printf("%lld", sum);

  return 0;
}


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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9532
INF = 2**100

h, w = map(int, input().split())
n = 10
d = [[INF for i in range(n)] for j in range(n)]
for i in range(n):
    a = [int(i) for i in input().split()]
    for j in range(n):
        d[i][j] = a[j]
for i in range(n):
    d[i][i] = 0
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

num = [0] * n
for i in range(h):
    b = [int(j) for j in input().split()]
    for j in b:
        if j != -1:
            num[j] += 1

print(sum([d[i][1]*num[i] for i in range(n)]))

Measured memory_bytes: 73580
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		ArrayList<Integer> list=new ArrayList<>();
		int nine=1;
		while(nine<=n){
			nine*=9;
			list.add(nine);
		}
		int six=1; 
		while(six<=n){
			six*=6;
			list.add(six);
		}
		list.add(1);
		Collections.sort(list);
		int[] dp=new int[n+1];
		for(int i=0; i<n; i++){
			for(int j=0; j<list.size(); j++){
				int a=list.get(j);
				if(a+i>n){
					break;
				}
				if(dp[a+i]==0){
					dp[a+i]=dp[i]+1;
				}else{
					dp[a+i]=Math.min(dp[a+i],dp[i]+1);
				}
			}
		}
		System.out.println(dp[n]);
	}
}



Measured memory_bytes: 24276
#include<iostream>
    using namespace std;
    int main(){
      int n;
      cin >> n;
      if(n % 10 == 3){
        cout << "bon\n";
      }else if((n % 10 == 0) || (n % 10 == 1) || ( n % 10 == 6) || (n % 10 == 8)){
        cout << "pon\n";
      }else{
        cout << "hon\n";
      }
      return 0;
    }

Measured memory_bytes: 3592
#include <cstdio>
const int MAXN = 51;
const int ZERO = 2551;
const int MAXM = ZERO*2;
typedef long long LL;
LL F[MAXN][MAXM];
int C[MAXN];
int main()
{
	int N, A, i, j, x;
	scanf("%d%d", &N, &A);
	F[0][ZERO] = 1;
	for(i=1; i<=N; ++i)
	{
		scanf("%d", &x);
		x -= A;
		for(j=MAXN; j+MAXN<MAXM; ++j)
			F[i][j] = F[i-1][j] + F[i-1][j-x];
	}
	printf("%lld\n", F[N][ZERO]-1);
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n, m, k;
	cin >> n >> m >> k;
	
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= m; ++j){
			if(i * m + j * n - 2 * i * j == k){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a;
  in(n);
  vector<ll> c(n - 1), s(n - 1), f(n - 1);
  vector<vector<ll>> t(n, vector<ll> (n, 0));
  rep(i, n - 1)
    in3(c[i], s[i], f[i]);
  rep(i, n - 1){
    rep(j, i + 1){
      if(t[j][i] < s[i])
        t[j][i] = s[i];
      else if(t[j][i] % f[i] != 0)
        t[j][i] = (t[j][i] / f[i] + 1) * f[i];
      t[j][i + 1] = t[j][i] + c[i];
    }
  }
  rep(i, n){
    out(t[i][n - 1]);
    memi;
  }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s, t;
  cin >> s >> t;
  string ans = "~";
  int ns = s.size(), nt = t.size();
  rep(i, ns - nt + 1) {
    if(s[i] != t[0] && s[i] != '?') continue;
    bool ok = true;
    string sa = s;
    rep(j, nt) {
      if(s[i + j] != t[j] && s[i + j] != '?') ok = false;
      sa[i + j] = t[j];
    }
    if(!ok) continue;
    replace(all(sa), '?', 'a');
    ans = min(ans, sa);
  }
  cout << (ans == "~" ? "UNRESTORABLE" : ans) << endl;
}

Measured memory_bytes: 256
import math
 
A, B, H, M = map(int, input().split())
 
 
doubledt = abs(60*H - 11*M)
t = 0
if(doubledt > 360):
    t = math.pi * (720-doubledt)/360
else:
    t = math.pi * doubledt/360
 
tlen = math.sqrt(A*A + B*B - 2*A*B*math.cos(t))
print('{:.20f}'.format(tlen))

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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  double times = 1.0 / (1.0 / (double)pow(2, m));
  cout << (int)(times * (1900 * m + 100 * (n - m))) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int res[2010];

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n,x,y;
	cin>>n>>x>>y;
	x--;y--;
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
		res[min(j-i,abs(x-i)+abs(y-j)+1)]++;
	}
	for(int i=1;i<n;i++)cout<<res[i]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
    long long x,ans=0;
  	cin>>n>>x;
  
  for(int k=n;k>=0;k-=1){
  	if(x<pow(2,k+1)-1 && x!=1){           //左半分
		x-=1;
    }else if(x==pow(2,k+1)-1){    //中心
		ans+=pow(2,k);
      	break;
    }else if(x==1){               //左端
		break;
    }else if(x==pow(2,k+2)-3){    //右端
		ans+=pow(2,k+1)-1;
      	break;
    }else{                        //右半分
      	ans+=pow(2,k);
      	x-=pow(2,k+1)-1;
    }
  }
		
  cout<<ans<<endl;
}


Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

// #define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
// #define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

int main(){
	int a,b,c; cin>>a>>b>>c;
	ote((a<=c && c<=b)?"Yes":"No");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a[100],n,i,j,k,key;
 
    scanf("%d",&n);
    for(i = 0;i < n;i++){
      scanf("%d",&a[i]);
    }
    for(k = 0;k < n;k++){
      if(k == n-1) printf("%d\n",a[k]);
	else printf("%d ",a[k]);
    }
    for(i = 1;i < n;i++){
      key = a[i];
      j = i - 1;
      while(j >= 0 && a[j] > key){
	a[j+1] = a[j];
	j--;
      }
      a[j+1] = key;
      for(k = 0;k < n;k++){
	if(k == n-1) printf("%d\n",a[k]);
	else printf("%d ",a[k]);
      }
    }
    return 0;
}

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

using ll = long long;
// #define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}

int torch_nums[100005];
vector<vector<int>> paths(200005);
bool visited[100005];

void bfs() {
  queue<int> que;
  int current = 0;
  visited[0] = true;
  que.push(0);
  while(!que.empty()) {
    current = que.front();
    que.pop();
    for(auto& next : paths[current]) {
      if(visited[next]) continue;
      que.push(next);
      torch_nums[next] = current;
      visited[next] = true;
    }
  }
}
/***** MAIN *****/
signed main() {
  int n,m;
  cin >> n >> m;
  REP(i,m) {
    int a,b; cin >> a >> b;
    --a; --b;
    paths[a].PB(b);
    paths[b].PB(a);
  }
  
  bfs();
  bool flag = true;
  for(int i = 1; i < n; ++i) {
    if(!visited[i]) {
      flag = false;
      break;
    }
  }
  if(!flag) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for(int i = 1; i < n; ++i) {
    cout << torch_nums[i] + 1 << endl;
  }
  return 0;
}
/***** MAIN *****/

Measured memory_bytes: 12768
s = input()

for i in range(1<<3):
  x = int(s[0])
  y = s[0]
  for j in range(3):
    if ((i>>j)&1) == 0:
      x += int(s[j+1])
      y += "+" + s[j+1]
    else:
      x -= int(s[j+1])
      y += "-" + s[j+1]
  if x == 7:
    print(y+"=7")
    break


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N; cin >> N;
	string S; cin >> S;
	int red = 0, blue = 0;
	REP(i,N){
		if(S[i] == 'R') red++;
		else blue++;
	}

	if(red > blue) cout << "Yes" << endl;
	else cout << "No" << endl;
	


	return 0;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    d = Counter()
    for s in S:
        d[tuple(sorted(s))] += 1
    return reduce(lambda x, y: x + (y*(y-1))//2, d.values(), 0)


def main():
    N = read_int()
    S = [read_str() for _ in range(N)]
    print(slv(N, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 155736
#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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#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 bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
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;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

vi encode(string str) {
  vi ans;
  int count;
  for(int i = 0;str[i];i++) {
    count = 1;
    while(str[i] == str[i+1]) {
      count++;
      i++;
    }
    ans.push_back(count);
  }
  return ans;
}
  
int main() {
  string s;
  cin >> s;
  int N = sz(s);
  vi lr = encode(s);
  string ans = "";
  rep(i,sz(lr)) {
    if(i % 2 == 1) continue;
    int r = lr[i];
    int l = lr[i+1];
    rep(i,r-1) {
      cout << 0 << " ";
    }
    cout << (r+1) / 2 + l / 2 << " ";
    cout << r / 2 + (l+1) / 2 << " ";
    rep(i,l-1) {
      cout << 0 << " ";
    }
  }
  cout << ans.substr(0,sz(ans)-1) << endl;
  return 0;
}

Measured memory_bytes: 1148
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  string s;
  cin >> s;
  int l = inf, r = -inf;
  rep(i, s.size()){
    if (s[i] == 'A') chmin(l, i);
    if (s[i] == 'Z') chmax(r, i);
  }
  cout << r - l + 1 << endl;
}


Measured memory_bytes: 720
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

main {
  int a, b, c;
  cin >> a >> b >> c;
  int s = 0;
  loop(i, a, b + 1) s += c % i == 0;
  cout << s << endl;
}

Measured memory_bytes: 3124
# -*- coding: utf-8 -*-
import sys

#time= int(input())
tmp = input().split()
a,b,c = list(map(lambda a: int(a), tmp))

if(a<b):
    if(b<c):
        print(a,b,c)
    else:
        if(a<c):
            print(a,c,b)
        else:
            print(c,a,b)
else:
    if(b<c):
        if(a<c):
            print(b,a,c)
        else:
            print(b,c,a)
    else:
        print(c,b,a)




Measured memory_bytes: 5604
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int a[10];
int b[10] = { 0,2,5,5,4,5,6,3,7,6 };
int dp[30000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a, a + m);
	reverse(a, a + m);
	for (int i = 1; i <= n; i++) {
		dp[i] = -Inf;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i + b[a[j]] > n) continue;
			dp[i + b[a[j]]] = max(dp[i + b[a[j]]], dp[i] + 1);
		}
	}
	string h = "";
	for (int i = n; i > 0;) {
		for (int j = 0; j < m; j++) {
			if (i - b[a[j]] >= 0 && dp[i - b[a[j]]] == dp[i] - 1) {
				h += (char)(a[j] + '0');
				i -= b[a[j]];
				break;
			}
		}
	}
	cout << h << endl;
}


Measured memory_bytes: 384
n,x = map(int, input().split())
line = list(map(int, input().split()))
line.sort()
ans = 0
for i in range(n):
  x -= line[i]
  if x < 0:
    break
  else:
    ans += 1
    
  if i == n-1 and x != 0:
    ans -= 1
print(ans)


Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll INF = 1e9 + 7;
int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    ll mi = INF;
    for(int i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        ans += a;
        if(a > b) mi = min(mi, b);
    }
    if(mi == INF) cout << 0 << endl;
    else cout << ans - mi << endl;
}


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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    // a and c are health
    // b and d are attack values
    while(true) {
        c = c - b;
        if(c <= 0){
            cout << "Yes";
            break;
        }
        a = a - d;
        if(a <= 0) {
            cout << "No";
            break;
        }
    }
}

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

int main(){
  long N , M;
  std::cin>>N>>M;
  std::vector<std::pair<long, long> > A(N);
  for(long i = 0 ; i < N ; i++ ){
    std::cin>>A[i].first>>A[i].second;
  }
  std::sort(A.begin(),A.end());

  long result = 0;
  long Num = 0;
  for(long i = 0 ; i < N ; i++ ){
    if(M - Num >= A[i].second){
      result += A[i].first * A[i].second;
      Num += A[i].second;
    }else{
      result += A[i].first * (M - Num);
      Num += M - Num;
    }
    if(Num == M) break;
  }
  std::cout<<result<<std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

struct UF
{
    vi r, p; int sz;
    UF(int n) : r(n, 0), p(n, 0), sz(n)
    {
        iota(p.begin(), p.end(), 0);
    }
	
    int f(int x)
    {
        return (p[x] == x ? x : p[x] = f(p[x]));
    }
	
    void u(int i, int j)
    {
        int x = f(i), y = f(j);
        if (x == y)
            return;

        sz--;
        if (r[x] >= r[y])
        {
            p[y] = x;
            if (r[x] == r[y])
                r[x]++;
        }
        else
            p[x] = y;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    UF uf(n);
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        uf.u(a - 1, b - 1);
    }
    cout << uf.sz - 1;
}


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

int main() {
  int a, b, c ;
  cin >> a >> b >> c;
    vector<int> vec = {a, b, c};
    sort(vec.begin(), vec.end());

    for (int i = 0; i < vec.size(); i++) ;
      
    

    if (vec.at(0)==5 && vec.at(1)==5 && vec.at(2)==7){
      cout << "YES" << endl;
    }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n;
    cin >> n;
    if (n == 1){
        cout << "Hello World" << endl;
    } else {
        int a,b;
        cin >> a >> b;
        cout << a + b << endl;
    }


}


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

#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 1e3+5;
const int MOD= 998244353;
int n,m,a[MAXN];
int main(){
    while(cin>>n>>m){
        memset(a,-1,sizeof(a));
        int flag=0;
        while(m--){
            int x,y;
            cin>>x>>y;
            if(a[x]!=-1&&a[x]!=y)flag=1;
            else a[x]=y;
        }
        if(n!=1&&a[1]==0)flag=1;
        if(flag){
            puts("-1");
            continue;
        }
        if(n==1&&a[1]==-1){
            puts("0");
            continue;
        }
        if(a[1]==-1)a[1]=1;
        rep(i,1,n){
            if(a[i]==-1)printf("0");
            else printf("%d",a[i]);
        }puts("");
    }
}


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

int main() {
  int a, b, t;
  cin >> a >> b >> t;
  cout << t / a * b << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	cin>>n;
	std::vector<int> v(n);
	std::vector<int> a(n);
	for(int i=0; i<n; i++)
	{
		cin>>v[i];
		a[i]=v[i];
	}
	sort(a.begin(),a.end());
	for (int i = 0; i <n; ++i)
	{
		if(v[i]!=a[n-1])cout<<a[n-1]<<endl;
		else cout<<a[n-2]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#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++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, L, R;
    cin >> N;
    
    int sum = 0;
    rep(i, N) {
        cin >> L >> R;
        sum += R - L + 1;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);  
//*s.find_by_order(p)   returns the value of pth largest starting from 0 
//s.order_of_key(p)   returns no. of items that are strictly < p 
//string bin = bitset<64>(m).to_string();     convert decimal m to binary 
int main()
{
      fast;ll t;t=1;
      while(t--)
      { 
            ll n;
            cin>>n;
            if(n==0){cout<<1;}
            else{cout<<0;}
            cout<<"\n";

      }
}

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

int main()
{
	long long x, v = 100;
	cin >> x;
	
	for (int i = 1 ;; i++)
	{
		v *= 1.01;
		if (v >= x)
		{
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 3612
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n,a,b=MI()
    if (b-a)%2==0:print((b-a)//2)
    else:
        ans=min((2*n-a-b+1)//2,(a+b-1)//2)
        print(ans)

main()

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX=400+1;
int N;
ll ns[MAX];
ll dp[MAX][MAX];
ll solve(int l, int r){


    if(r<=l) return 0;

    ll &ret=dp[l][r];
    if(r-l+1==2){
        return ret=ns[r]-(l?ns[l-1]:0);
    }

    if(~ret) return ret;

    ret=1e18;
    for(int i=l;i<r;i++){
        ret=min(ret, solve(l, i)+solve(i+1, r)+ns[r] - (l>0?ns[l-1]:0) );
    }


    return ret;

}

int main(){
    scanf("%d",&N);
    for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) dp[i][j]=-1;
    for(int i=0;i<N;i++){
        scanf("%lld",&ns[i]);
        if(i) ns[i] += ns[i-1];
    }


    printf("%lld\n", solve(0, N-1));


    return 0;
}


Measured memory_bytes: 5072
#include <cstdio>
#include <algorithm>
// E - Gluttony

#define INF 0x3f3f3f3f
#define fi first
#define se second

using namespace std;

int A[200005],F[200005];

int main() {
    int N,i;
    long long K,lo,hi,mid,temp;

    scanf("%d%lld",&N,&K);

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

    for (i = 0;i < N;i++)
        scanf("%d",&F[i]);
    sort(F,F + N);
    reverse(F,F + N);

    lo = -1;
    hi = 1000000000001LL;
    while ((hi - lo) > 1) {
        mid = (lo + hi) >> 1;

        temp = 0;
        for (i = 0;i < N;i++)
            temp += max(0LL,A[i] - mid / F[i]);

        if (temp <= K)
            hi = mid;
        else
            lo = mid;
    }

    printf("%lld\n",hi);

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <math.h>
#include <cstdlib> //絶対値 abs()
using namespace std;


int main(){
	string s;
	cin >> s;

	int l=s.size();
	string ans="";

	for(int i=0; i<l; i++){
		if(s[i]=='B'){
			if(ans.size()!=0){
				ans.pop_back();
			}
		}
		else{
			ans += s[i];
		}
	}
	cout << ans <<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    while (1) {
        int a, b;
        char ch;
        cin >> a >> ch >> b;
        if (ch == '?' ) break;
        if (ch == '+') cout << a + b << endl;
        else if (ch == '-') cout << a - b << endl;
        else if (ch == '*') cout << a * b << endl;
        else cout << a / b << endl;
    }
}



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

int main(){
  int n; long long h;
  cin >> n >> h;
  vector<long long> a, b;
  long long amax = 0; long long bsum = 0;
  for (int i = 0; i < n; i++){
    long long u, v;
    scanf("%lld %lld", &u, &v);
    a.push_back(u); b.push_back(v);
    if (amax < a[i]) amax = a[i];
    bsum += b[i];
  }

  int m = n;
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++){
    if (b[i] <= amax){
      bsum -= b[i];
      m--;
    } else {
      break;
    }
  }

  if (bsum <= h) {
    printf("%lld\n", m + (h - bsum + amax - 1) / amax);
    return 0;
  } else {
    int count = 0;
    for (int i = n; i > 0; i--){
      h -= b[i-1];
      count++;
      if (h <= 0){
        printf("%d\n", count);
        return 0;
      }
    }
  }
  return 0;
}

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

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

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
	int N;
	cin >> N;
	int A, B;
	
	for (int i=1; i<10; i++){
		if (N%i == 0){
			int x = N/i;
			if(x > 0 && x < 10){
				cout << "Yes" << endl;
				exit(0);
			}
		}
	}
	cout << "No" << endl;
	/*
	if (A > 0 && A < 10 && B > 0 && B < 10){
		cout << A*B << endl;
	}
	else{
		cout << "-1" << endl;
	}
	*/
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;cin >> s;
  int n = s.length(),cnt=0;
  for(int i=0;i<n;i++)if(s[i]-'0' == i%2)cnt++;
  cout << min(cnt,n-cnt);
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin>>n;
    int l[2020];
    for(int i=0; i<n; i++) cin>>l[i];
    sort(l, l+n);
    int ans=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                if(l[k]>=l[i]+l[j]) break;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n;
    cin >> n;
    string s = "";
    while(n) {
        n--;
        ll rem = n % 26;
        n /= 26;
        s += (char)((ll)'a' + rem);
    }
    reverse(s.begin(), s.end());
    cout << s;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
process.stdin.resume();
process.stdin.setEncoding('utf8');

class Dice {
    constructor(top, front, right, left, back, bottom) {
        this.top = top;
        this.front = front;
        this.right = right;
        this.left = left;
        this.back = back;
        this.bottom = bottom;
    }
    rollVertical() {
        return new Dice(this.front, this.bottom, this.right, this.left, this.top, this.back);
    }
    rollHorizontal() {
        return new Dice(this.top, this.right, this.back, this.front, this.left, this.bottom);
    }
    existVertial(number) {
        return [this.top, this.front, this.bottom, this.back].includes(number);
    }
    existHorizontal(number) {
        return [this.front, this.left, this.back, this.right].includes(number);
    }
    fit(top, front) {
        let dice = this;
        if (!dice.existVertial(top)) {
            dice = dice.rollHorizontal();
        }

        let isNotTop = true;
        
        while (isNotTop) {
            dice = dice.rollVertical();
            if (dice.top === top) {
                isNotTop = false;
            }
        }
        
        let isNotFront = true;
        while (isNotFront) {
            dice = dice.rollHorizontal();
            if (dice.front === front) {
                isNotFront = false;
            }
        }
        return dice;
    }
}


process.stdin.on('data', function (chunk) {
    const n = chunk.toString() // 文字列化する
        .split("\n") // \nで分割
        .filter(x => x !== "");

    const [diceNumber, qNumber, ...questions] = n;

    const [top, front, right, left, back, bottom] = diceNumber.split(" ");


    questions.forEach(q => {
        const dice = new Dice(top, front, right, left, back, bottom);
        const qq = q.split(" ");
        console.log((dice.fit(qq[0], qq[1])).right);
    })

});





Measured memory_bytes: 16040
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int K = scan.nextInt();
        PriorityQueue<Long> queue = new PriorityQueue<>();
        HashSet<Long> set = new HashSet<>();
        for (long i = 1; i <= 9; i++) {
            queue.add(i);
            set.add(i);
        }
        while(queue.size() < K) {
            HashSet<Long> new_set = new HashSet<>();
            for (long x : set) {
                new_set.add(x);
                String s = Long.toString(x);
                char[] d = s.toCharArray();
                int t = d[s.length() - 1] - '0';
                for (int j = -1; j <= 1; j++) {
                    if (t + j < 0) {
                        continue;
                    }
                    if (9 < t + j) {
                        continue;
                    }
                    long n = Long.valueOf(s + String.valueOf(t + j));
                    if (set.contains(n)) {
                        continue;
                    }
                    if (new_set.contains(n)) {
                        continue;
                    }
                    new_set.add(n);
                    queue.add(n);
                }
            }
            set = new_set;
        }
        for (int i = 0; i < K - 1; i++) {
            queue.poll();
        }
        System.out.println(queue.poll());
    }
}


Measured memory_bytes: 88028
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> A(N);
  vector<int> under(N, 0);
  vector<int> over(N, 0);
  rep(i, N) {
    cin >> A[i];
    if (i + A[i] < N) under[i + A[i]]++;
    if (i - A[i] >= 0) over[i - A[i]]++;
  }

  long long pair = 0;
  rep(i, N) {
    pair += (long long)under[i] * over[i];
  }

  cout << pair << endl;

  return 0;
}


Measured memory_bytes: 5636
s = input()
q = int(input())
querys = [list(input().split()) for i in range(q)]

rev = 0
moji = []
for query in querys:
    if query[0] == '1':
        rev += 1
    else:
        query[1] = int(query[1])
        p = True if query[1] == 1 else False
        moji.append([query[2], rev, p])

if rev%2 != 0:
    s = s[::-1]
head = ""
end = ""
for m in moji:
    if (rev - m[1]) % 2 != 0:
        m[2] = not(m[2])
    
    if m[2]:
        head = m[0] + head
    else:
        end = end + m[0]

s = head + s + end
print(s)

Measured memory_bytes: 51748