akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<ll> a(n), b(n);
	vector<ll> p;
	ll t = 0, aSum = 0, bSum = 0;
	int res = 0;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n)
	{
		aSum += a[i];
		bSum += b[i];
		if (a[i] < b[i])
		{
			t += (b[i] - a[i]);
			++res;
		}
		else p.push_back(a[i] - b[i]);
	}
	if (aSum < bSum)
	{
		cout << -1 << endl;
		return 0;
	}

	sort(all(p), greater<ll>());
	int i = 0;
	while (t > 0)
	{
		t -= p[i];
		++res;
		++i;
	}
	cout << res << endl;
}

Measured memory_bytes: 2936
use std::collections::*;
use std::io;
use std::cmp::*;

fn main(){
    let t_cases = 1;
    for _ in 0..t_cases{
        solve();
    }
}

fn solve(){
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let a = buf
                .trim()
                .split_whitespace()
                .map(|x| x.parse::<i32>().unwrap())
                .collect::<Vec<i32>>();
    let (_n,k) = (a[0],a[1]);
    buf.clear();
    io::stdin().read_line(&mut buf).unwrap();
    let a = buf
                .trim()
                .split_whitespace()
                .map(|x| x.parse::<i32>().unwrap())
                .collect::<Vec<i32>>();
    let n = a.len();
    let mut dp = vec![10i32.pow(9)+7;n];
    dp[0] = 0;
    for i in 1..n{
        for j in ((max(0,i as i32-k)as usize)..i).rev(){
            dp[i] = min(dp[i],dp[j]+(a[i]-a[j]).abs());
        }
    }
    println!("{}",dp[n-1]);
}

Measured memory_bytes: 6396
#include<bits/stdc++.h> 
using namespace std; 
  
// Function to find that number divisible by 9 or not 
int check(string str) 
{ 
    // Compute sum of digits 
    int n = str.length(); 
    int digitSum = 0; 
    for (int i=0; i<n; i++) 
        digitSum += (str[i]-'0'); 
  
    // Check if sum of digits is divisible by 9. 
    return (digitSum % 9 == 0); 
} 
  
// Driver code 
int main() 
{ 
    string str;
  cin>>str;
    check(str)?  cout << "Yes" : cout << "No "; 
    return 0; 
} 

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

int main(void){
  int n;
  vector<int> p(10);
  cin >> n;
  int price = 0;
  for(int i = 0; i < n; i ++){
    cin >> p.at(i);
    price += p.at(i);
  }

  int max = *max_element(p.begin(), p.end());

  cout << price - max/2 << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)

r, g, b, n = MI()
ans = 0
for i in range(n+1):
    for j in range(n+1):
        # if 0 <= n-(i*r)-(j*g) <= n and (n-(i*r)-(j*g)) % b == 0:
        # print(i,j,n-(i*r)-(j*g))
        if (n-(i*r)-(j*g)) % b == 0 and (n-(i*r)-(j*g))//b >= 0:
            # print('check')
            ans += 1
print(ans)


Measured memory_bytes: 67432
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
        int a,b,c;
        cin >> a >> b >> c;
        ll ans1 = a * 10 + b + c;
        ll ans2 = a + b * 10 + c;
        ll ans3 = a + b + c * 10;
        cout << max({ans1, ans2, ans3}) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// g++ -std=c++1z
// int to string : string s = to_string(n);
// string to int : int n = stoi(s);
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int l = a + b;
    int r = c + d;
    if (l < r) cout << "Right" << endl;
    else if (l == r) cout << "Balanced" << endl;
    else cout << "Left" << endl;

    return 0;
}








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

int a[200];

int main (void) {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++)
		cin >> a[i];
	int ans = 0;
	for (int i = 1; i <= n; i += 2) if (a[i] & 1)
		ans ++;
	cout << ans << endl;
}

Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
int main()
{
  int t; cin >> t;
  vector<ll> n(t), a(t), b(t), c(t), d(t);
  rep(i,t) {
    cin >> n[i] >> a[i] >> b[i] >> c[i] >> d[i];
  }
  ll inf = (1LL << 60);

  rep(i,t) {
    map<ll,ll> dp;
    dp[0] = 0;
    dp[1] = d[i];
    auto rec = [&](auto f, ll nn)-> ll{
		 if(dp.find(nn) != dp.end()) return dp[nn];
		 ll res = inf;
		 if(((ld)nn * (ld)d[i]) < inf) {
		   res = nn * d[i];
		 }
		 if(nn % 2 == 0) chmin(res, f(f, nn/2) + a[i]);
		 else {
		   chmin(res, f(f, (nn+1)/2) + a[i] + d[i]);
		   chmin(res, f(f, (nn-1)/2) + a[i] + d[i]);		   
		 }
		 if(nn % 3 == 0) chmin(res, f(f, nn/3) + b[i]);
		 else {
		   chmin(res, f(f, nn/3) + b[i] + d[i]*(nn % 3));
		   chmin(res, f(f, nn/3 + 1) + b[i] + d[i]*(3 - nn%3));		   		   
		 }
		 if(nn % 5 == 0) chmin(res, f(f, nn/5) + c[i]);
		 else {
		   chmin(res, f(f, nn/5) + c[i] + d[i]*(nn % 5));
		   chmin(res, f(f, nn/5 + 1) + c[i] + d[i]*(5 - nn%5));		   		   
		 }
		 return dp[nn] = res;
	       };
    cout << rec(rec, n[i]) << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 4276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int t = 0;
		if(b <= c || d <= a) {
		} else if(a <= c && c <= b) {
			if(b <= d) {
				t = b - c;
			} else if(d <= b) {
				t = d - c;
			}
		} else if(c <= a) {
			if(b <= d) {
				t = b - a;
			} else if(d <= b) {
				t = d - a;
			}
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    double L;
    cin >> L;
    cout << setprecision(15) << (L*L*L)/27.0;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
int lst[Max], ls[Max];
int main()
{
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		scanf("%d", &lst[i]);
	}
	int g = 1, d = 5, t = 1;
	int f = n % 2;
	if (f) t = -1;
	else t = 1;
	ls[d] = lst[g];
	while (++g <= n)
	{
		t = -t;
		ls[d + t * (g / 2)] = lst[g];
	}
	for (int i = d - n / 2;i <= d + (n - 1) / 2;i++)
		printf("%d ", ls[i]);
}

Measured memory_bytes: 4816
#include <stdio.h>
#include <math.h>

typedef struct point
{
    double x;
    double y;
}Point;

void kock(int n, Point p1, Point p2);

int main(int argc, char** argv)
{
	Point p1, p2;
	int n;

	scanf("%d", &n);
	p1.x = 0, p1.y = 0;
	p2.x = 100, p2.y = 0;

	printf("%.8f %.8f\n", p1.x, p1.y);
	kock(n, p1, p2);
	printf("%.8f %.8f\n", p2.x, p2.y);

	return 0;
}

void kock(int n, Point p1, Point p2)
{
    Point s, t, u;
    if (n == 0) return;

    double theta = M_PI * 1/3;

    s.x = (2*p1.x + p2.x) / 3;
    s.y = (2*p1.y + p2.y) / 3;
    t.x = (p1.x + 2*p2.x) / 3;
    t.y = (p1.y + 2*p2.y) / 3;
    u.x = (t.x - s.x) * cos(theta) - (t.y-s.y) * sin(theta) + s.x;
    u.y = (t.x - s.x) * sin(theta) + (t.y-s.y) * cos(theta) + s.y;

    kock(n-1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    kock(n-1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    kock(n-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    kock(n-1, t, p2);
}



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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//ceil(a/(double)b)=(a+b-1)/b
//printf("myco\n");//for debug
/*--------------------------------------------*/
P f(int i){
    int a,b;
    b=i%10;
    int tmp;
    while(i){
        tmp=i;
        i/=10;
    }
    a=tmp;
    return P(a,b);
}


int main(){
    int n;cin>>n;
    int cnt=0;
    map<P,int> freq;
    REP(i,n){
        P now=f(i);
        freq[now]++;
    }
    REP(i,n){
        P ord=f(i);
        //このペアの入れ替えのペアの数
        P rev(ord.second,ord.first);
        cnt+=freq[rev];
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

int main(){
  ll X, Y;
  cin >> X >> Y;

  int ans = 0;
  while(X <= Y){
    ans++;
    X *= 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char s[99];
  char c;
  int n,k,i;
  scanf("%d",&n);
  scanf("%s",&s[0]);
  scanf("%d",&k);

  c=s[k-1];
  for(i=0;i<n;i++){
    if(s[i]!=c)
      s[i]='*';
  }
  printf("%s\n",s);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int pricelist[] = new int[n];
        for (int i = 0; i < n; i++){
            pricelist[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(pricelist);
        int sum = 0;
        for(int i: pricelist){
            sum += i;
        }
        System.out.println(sum - pricelist[n-1]/2);
    }
}

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

int main()
{
  int n;
  unordered_set<int> a;
  cin >> n;

  for (int i = 0; i < n; i++)
  {
    uint64_t tmp;
    cin >> tmp;
    if (a.count(tmp))
    {
      cout << "NO" << endl;
      return 0;
    }
    a.insert(tmp);
  }
  cout << "YES" << endl;
}


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

	char s[10];
	int n = 0;
	int max = 0;

	scanf("%s", s);
	for (int i = 0;i < 3;i++) {
		if (s[i] == 'R')
		{
			n++;
			if (max < n)
			{
				max = n;
			}
		}
		else
			n = 0;
	}
	printf("%d", max);
	return 0;
}

Measured memory_bytes: 1724
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

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

signed main() {
  int n, p;
  cin >> n >> p;

  map<int, int> mp = prime_fac(p);
  int ans = 1;
  for (auto x : mp) {
    if (x.second / n >= 1) ans *= (int)pow(x.first, (x.second / n));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys, math, operator, itertools, collections, heapq, bisect
# sys.setrecursionlimit(10**4)


class Solution:
    def __init__(self):
        pass

    def solve(self, *Input):
        ans = 0
        h,w,k,matrix = Input
        # print(matrix)
        for r in range(h):
            rows = list(itertools.combinations(range(h),r))
            for c in range(w):
                # print(r,c)
                cols = list(itertools.combinations(range(w), c))
                # print(list(rows), list(cols))
                for row in rows:
                    for col in cols:
                        # print(row,col)
                        new_matrix = [[x for x in ROW] for ROW in matrix]
                        ans += self.create(h,w,k,new_matrix,row,col)
                        # print(ans)

        return ans

    def create(self, *Input):
        h,w,k,matrix,rows,cols = Input
        for i in range(h):
            for j in cols:
                matrix[i][j] = '.'
        for r in rows:
            matrix[r] = ['.'] * w
        # print(matrix)
        return self.check(k,matrix)

    def check(self, *Input):
        k,matrix = Input
        cnt = 0
        for row in matrix:
            cnt += row.count('#')
        return cnt == k

    def sieve_classic(self,a,b):
        self.primes = [True] * (b+1)
        self.primes[0] = self.primes[1] = False
        for i in range(2,b+1):
            if self.primes[i] and i*i <= b:
                for j in range(i*i,b+1,i):
                    self.primes[j] = False
        self.primes = [x for x,y in enumerate(self.primes) if y]
        ind = bisect.bisect_left(self.primes,a)
        self.primes[:ind] = []
        return None


if __name__=='__main__':
    solution = Solution()

    inputs = iter(sys.stdin.readlines())
    h,w,k = map(int, next(inputs).split())
    matrix = [list(next(inputs).rstrip()) for _ in range(h)]
    ans = solution.solve(h,w,k,matrix)
    print(ans)


Measured memory_bytes: 9416
#include <iostream>
using namespace std;
#define MAX 20

int A[MAX],n;

int solve(int i,int m){
  if(m==0) return 1;
  if(i>=n) return 0;
  int res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}

int main(){
  int m,key;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>key;
    if(solve(0,key)) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	int len=s.size(),ans=s.size();
	for(int i=0;s[i+1];i++)
		if(s[i]!=s[i+1])
			ans=min(ans,max(i+1,len-i-1));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
	int kado[4][13]={0},n,i,j,b;
	char a;
	scanf("%d",&n);
	for(i=0;i<2*n;i++){
		scanf("%c %d",&a,&b);
		if(a=='S'){
			kado[0][b-1]=1;
		}else if(a=='H'){
			kado[1][b-1]=1;
		}else if(a=='C'){
			kado[2][b-1]=1;
		}else if(a=='D'){
			kado[3][b-1]=1;
		}
	}
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(kado[i][j]!=1){
				if(i==0){
					printf("S %d\n",j+1);
				}else if(i==1){
					printf("H %d\n",j+1);
				}else if(i==2){
					printf("C %d\n",j+1);
				}else if(i==3){
					printf("D %d\n",j+1);
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>

using namespace std;

string vd[] = {"AC", "WA", "TLE", "RE"};
int cnt[4];
int main(){
    int n;
    cin >>n;

    for(int i=0;i<n;i++){
        string s;
        cin >>s;
        for(int j=0;j<4;j++){
            if(s==vd[j]){
                cnt[j]++;
            }
        }
    }

    for(int i=0;i<4;i++){
        cout << vd[i]<<" x "<<cnt[i]<<endl;
    }
}


Measured memory_bytes: 3576
using System;
using static System.Console;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong N = ulong.Parse(ReadLine());
            ulong sum = 0;
            for(ulong i = 0; i < N; i ++)
            {
                if((i + 1)% 3 != 0 && (i + 1) % 5 != 0)
                {
                    sum += i + 1;
                }
            }
            WriteLine(sum);
        }
    }
}


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

int main(void){
  unsigned long long int score, pre, ans, r, j;
  int q, a, b, i, dis, t;
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d %d",&a, &b);
    if(a<b){t=a; a=b; b=t;}
    score = (unsigned long long int) a*b;
    pre = -1;  dis=0;
    //printf("%d: s=%llu\n",i,score);
    for(j=sqrt(score); ;j++){
      r=score/j;
      if(score%j==0) r--;
      if(r==pre) break;
      if(j==a || r==b) dis++;
      else pre=r;
      //printf("%llu->",r);
    }
    //printf(".\n");
    if(r>b) dis++;
    ans = r+j-2-dis;
    printf("%llu\n",ans);
  }

  return 0;
}


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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const int INF = 1e9 + 5;
const long long MAXN=2e5 + 5;;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool cmp(const string& a, const string& b) {
	return (a + b) < (b + a);
}

vector<int> Reversed(const vector<int>& s){
   vector<int> d = s;
   reverse(all(d));
   return d;
}

void solve(){
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll sum = 0;
    if(a[0] > x){
        sum = a[0] - x;
        a[0] = x;
    }
    for(int i = 0; i < n-1; i++){
        if(a[i+1] + a[i] > x){
            sum += (a[i+1] + a[i]) - x;
            a[i+1] = a[i+1] - ((a[i+1] + a[i]) - x);
        }
    }
    cout << sum;
}


int main(){
    //freopen("slalom.in","r",stdin);
    //freopen("slalom.out","w",stdout);
    //faster();
    int n = 1;
    //cin >> n;
    while(n--){
        solve();
        cout << endl;
    }
    //fclose(stdout);
}


Measured memory_bytes: 3960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
	std::string s;
	std::cin >> s;
	size_t K;
	std::cin >> K;

	std::vector<std::string> t;

	for (size_t i = 0; i < s.length(); ++i)
	{
		t.emplace_back(s.substr(i));
	}
	std::sort(t.begin(), t.end());

	size_t c = 0;
	size_t k = K;
	while (true)
	{
		if (c != 0) {
			for (size_t j = 0; j < std::min(t[c - 1].length(), t[c].length()); ++j) {
				if (t[c - 1].at(j) != t[c].at(j)) break;
				++k;
			}
		}
		if (k <= t[c].size()) {
			std::cout << t[c].substr(0, k) << std::endl;
			return 0;
		}
		else {
			k -= t[c].size();
		}
		++c;
	}

	return 0;
}


Measured memory_bytes: 16128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, A;
	cin >> X >> A;
	if (X < A)cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int res[100001],i,j,a,b,n,x;
int main(){
	cin>>n>>x;
	for(i=0;i<n;i++){
		scanf("%lld%lld",&a,&b);

		for(j=x;j>=a;j--) res[j]=max(res[j],res[j-a]+b);
	}
	cout<<res[x];
}


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

class P
{
    static void Main()
    {
        //int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        char[] s = Console.ReadLine().OrderBy(x => x).ToArray();
        char[] t = Console.ReadLine().OrderByDescending(x => x).ToArray();
        int comp = string.Join("", s).CompareTo(string.Join("", t));
        Console.WriteLine(comp < 0 ? "Yes" : "No");
    }
}

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

typedef long long int   ll;
#define f(i,st,en)    for(int i=st;i<en;i++)
#define s(n)            scanf("%d",&n)
#define sc(n)           scanf("%c",&n)
#define sl(n)           scanf("%lld",&n)
#define sf(n)           scanf("%lf",&n)

using namespace std;


int main(){
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
int x1,x2,x3,x4,x5;
cin>>x1>>x2>>x3>>x4>>x5;
if(x1==0)cout<<1<<endl;
if(x2==0)cout<<2<<endl;
if(x3==0)cout<<3<<endl;
if(x4==0)cout<<4<<endl;
if(x5==0)cout<<5<<endl;



return 0;
}


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

int main(){
    int P, Q, R;
    cin >> P >> Q >> R;
    int ans = 1e5;
    ans = min(ans, P+Q);
    ans = min(ans, Q+R);
    ans = min(ans, R+P);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<numeric>
#include<map>

using namespace std;

int main(){
  vector<int> v;
  while(true){
    int N,M;
    cin >> N >> M;
    if(N==0){break;}
    int a[N];
    int b[M];
    for(int i=0;i<N;i++)
      cin>>a[i];
    for(int i=0;i<M;i++)
      cin>>b[i];
    map<int,int> K;
    map<int,int> L;
    #if 0
      横とたての長さでありうるものを全てかぞえあげる
    #endif

    for(auto i=a;i<a+N;i++){
      for(auto j=i;j<a+N;j++){
        int k=accumulate(i,j+1,0);
        if(K.find(k)==K.end()) K[k]=1;
        else K[k]+=1;
      }
    }
    int mk=accumulate(a,a+N,0);

    for(auto i=b;i<b+M;i++){
      for(auto j=i;j<b+M;j++){
        int l=accumulate(i,j+1,0);
        if(L.find(l)==L.end()) L[l]=1;
        else L[l]+=1;
      }
    }
    int ml=accumulate(b,b+M,0);

    //K,Lにそれぞれでありうる長さを格納
    int c=0;
    for(int i=1;i<=min(mk,ml);i++){
      c+=K[i]*L[i];
    }
    v.push_back(c);
  }
  for(int i=0;i<v.size();i++)
    cout << v[i] << endl;

}



Measured memory_bytes: 49884
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      double r,g;
      cin >> r >> g;
      cout << 2*g-r << endl;
      return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

lint gen(string s) {
  lint res = 0;
  for (int i = 0; i < 26; i++) res = res * s.size() + count(s.begin(), s.end(), 'a' + i);
  return res;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  V<string> s(h); for (int i = 0; i < h; i++) cin >> s[i];
  map<lint, int> mp;
  for (int i = 0; i < h; i++) mp[gen(s[i])]++;
  V<> a(2); for (auto&& i : mp) a[i.second & 1]++;
  sort(s.begin(), s.end(), [&](string a, string b) { return (mp[gen(a)] & 1) != (mp[gen(b)] & 1) ? (mp[gen(a)] & 1) > (mp[gen(b)] & 1) : gen(a) != gen(b) ? gen(a) < gen(b) : a < b; });
  if (h & 1) {
    if (a[1] != 1) return cout << "NO" << '\n', 0;
    auto tmp = s; int p = 0;
    s[(h - 1) / 2] = tmp[p++];
    for (int i = 0; i < (h - 1) / 2; i++) s[i] = tmp[p++], s[h - 1 - i] = tmp[p++];
  } else {
    if (a[1] != 0) return cout << "NO" << '\n', 0;
    auto tmp = s; int p = 0;
    for (int i = 0; i < h / 2; i++) s[i] = tmp[p++], s[h - 1 - i] = tmp[p++];
  }

  V<string> t(w);
  for (int i = 0; i < w; i++) {
    t[i].resize(h);
    for (int j = 0; j < h; j++) t[i][j] = s[j][i];
  }
  mp.clear();
  for (int i = 0; i < w; i++) mp[gen(t[i])]++;
  a.assign(2, 0); for (auto&& i : mp) a[i.second & 1]++;
  sort(t.begin(), t.end(), [&](string a, string b) { return (mp[gen(a)] & 1) != (mp[gen(b)] & 1) ? (mp[gen(a)] & 1) > (mp[gen(b)] & 1) : gen(a) != gen(b) ? gen(a) < gen(b) : a < b; });
  if (w & 1) {
    if (a[1] != 1) return cout << "NO" << '\n', 0;
    auto tmp = t; int p = 0;
    t[(w - 1) / 2] = tmp[p++];
    for (int i = 0; i < (w - 1) / 2; i++) t[i] = tmp[p++], t[w - 1 - i] = tmp[p++];
  } else {
    if (a[1] != 0) return cout << "NO" << '\n', 0;
    auto tmp = t; int p = 0;
    for (int i = 0; i < w / 2; i++) t[i] = tmp[p++], t[w - 1 - i] = tmp[p++];
  }

  for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) if (t[i][j] != t[w - 1 - i][h - 1 - j]) return cout << "NO" << '\n', 0;
  cout << "YES" << '\n';
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, M;
ll penalties[200000];
bool ac[200000];

signed main() {
  cin >> N >> M;
  rep(i, M) {
    ll p;
    string s;
    cin >> p >> s;
    p--;
    if (s == "AC") {
      ac[p] = true;
    } else {
      if (!ac[p]) {
        penalties[p]++;
      }
    }
  }
  ll a = 0, p = 0;
  rep(i, N) {
    if (ac[i]) {
      a++;
      p += penalties[i];
    }
  }
  cout << a << " " << p << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n, m;
    cin >> n >> m;
    ll a[n];
    ll sum = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        sum+=a[i];
    }
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        double check = (double)a[i]/(double)sum;
        double c = 1/(double)(4*m);
        if(check >= c) ans++;
    }
    if(ans >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
  string O,E;
  cin >> O >> E;
  if (O.size() == E.size()){
    for (int i=0; i<O.size(); i++){
      printf("%c%c", O[i], E[i]);
    }
  }
  else{
    printf("%c", O[0]);
    for (int i=0; i<E.size(); i++){
      printf("%c%c", E[i], O[i+1]);
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){

    int n,k;
    cin >> n >> k;

    double ans = 0;

    for(int i = 1; i <= n; ++i){
        int pt = i;
        double coin = 1;
        while(pt < k){
            pt *= 2;
            coin /= 2;
        }
        ans += coin/n;
    }

    cout << setprecision(10) << ans << endl;

}

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

using namespace std;

typedef long long ll;
const int MOD = 1e9 + 7;
ll fact[200005], inv[200005];
ll n, m, a, b;

ll pw(ll a, ll b) {
	if(b == 0) return 1;
	ll temp = pw((a * a) % MOD,b >> 1);
	if(b & 1) return temp % MOD * a % MOD;
	else return temp % MOD;
}

ll C(ll k, ll n) {
    if(n < k || k < 0 || n < 0) return 0;
    return (fact[n] * inv[k]) % MOD * inv[n - k] % MOD;
}

int main() {
    fact[0] = 1;
    inv[0] = 1;
    for(ll i = 1; i < 200005; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = inv[i - 1] * pw(i, MOD - 2) % MOD;
    }
    cin >> n >> m >> a >> b;
    ll res = 0;
    for(ll i = b + 1; i <= m; i++){
            ll tmp = (C(n - a - 1, i - 1 + n - a - 1)* C(m - i, m - i + a - 1)) % MOD;
            res = (res + tmp) % MOD;
        }
        cout << res;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(void)
{
	bool flag = false;
	char s[101];
	long long i = 0;

	cin >> s;

	while (s[i] != NULL)
	{
		if (i % 2 == 1)
		{
			if (s[i] == 'R')
			{
				flag = true;
				break;
			}
		}
		else
		{
			if (s[i] == 'L')
			{
				flag = true;
				break;
			}
		}
		i++;
	}

	if (flag)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair< int, int > PII;
typedef vector< int > VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int n;

int ans = 1e9;

int main()
{
	gi(n);
	for (int i = 1; i < n; ++i)
	{
		int a = i, b = n - i;
		int ret = 0;
		while (a) ret += a % 10, a /= 10;
		while (b) ret += b % 10, b /= 10;
		ans = min(ans, ret);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

H, W = map(int, input().split())
C = []
for i in range(9+1):
    c = list(map(int, input().split()))
    C.append(c)

A = []
for i in range(H):
    a = list(map(int, input().split()))
    A.append(a)

def warshall(org, V):
    d = org[:]

    for k in range(V):
        for i in range(V):
            for j in range(V):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    return d

V = 10
cost = warshall(C, V)
#print(cost)

ans = 0
for h in range(H):
    for w in range(W):
        if 0 <= A[h][w]:
            ans += cost[A[h][w]][1]

print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j == n){
                cout <<"Yes" <<endl;
                return 0;
            }
        }
    }
    cout<< "No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int n, d;
        cin >> n >> d;
        int ans = 0;
        while (n--)
        {
            int x, y;
            cin >> x >> y;
            int dis = x * x + y * y;
            double val = sqrt(dis);
            // cout << val << "dd\n";
            if (val <= d)
                ans++;
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3640
n = int(input())
a = list(map(int, input().split()))

nodes = []
if a[0] > 0:
    if a[0] == 1 and n == 0: print(1)
    else: print(-1)
    exit()
else:
    nodes.append(1)
if a[-1] > 2 ** n:
    print(-1)
    exit()

# forward
for i in range(1, n + 1):
    x = nodes[i - 1] * 2 - a[i]
    if i < n:
        if x <= 0:
            print(-1)
            exit()
        nodes.append(x)
    else:
        if x < 0:
            print(-1)
            exit()
        nodes.append(0)

# backward
for i in range(n - 1, -1, -1):
    if nodes[i] > a[i + 1] + nodes[i + 1]:
        nodes[i] = a[i + 1] + nodes[i + 1]

print(sum(a) + sum(nodes))


Measured memory_bytes: 700048
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		int k = fs.nextInt();
		int sunuke[] = new int[n + 1];
		for (int i = 0; i < k; i++) {
			int d = fs.nextInt();
			for (int j = 0; j < d; j++) {
				sunuke[fs.nextInt()]++;
			}
		}
		int count = 0;
		for (int i = 1; i < n + 1; i++) {
			if (sunuke[i] == 0)
				count++;
		}
		System.out.println(count);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

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

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

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

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

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

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

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 33184
#include<bits/stdc++.h>
//pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>   using orderedSet =tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
///use less_equal in pbds template to work as multiset...................................................
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
//BFS+DFS
#define boundary(i,j) (i>=0 && i<n && j>=0 && j<m)
int X[]={-1,1,0,0};
int Y[]={0,0,1,-1};
/*
struct cmp{
bool operator()(const pii &a,const pii &b)
{
    if(a.first==b.first) return a.second<b.second;///second value small to big
    else return a.first>b.first;///first value big to small
}
};
///in pq true means swap required  ,false means swap  not required...
set<pii,cmp>st;
priority_queue<pii,deque<pii>,cmp>pq;
*/
ll mod=1e9+7;
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll n;
     cin>>n;
     ll w=1LL,x=1LL,y=1LL,z=1LL;
     for(ll i=1; i<=n; i++)
     {
         w=(w*10LL)%mod;
     }
     for(ll i=1; i<=n; i++)
     {
         x=(x*9LL)%mod;
     }
     for(ll i=1; i<=n; i++)
     {
         y=(y*8LL)%mod;
     }
  //  z=(w-x+mod)%mod;
   // z=(z-x+mod)%mod;
   // z=(z+y)%mod;
   z=(w-(2LL*x)%mod+mod)%mod;
   z=(z+y)%mod;
     cout<<z<<endl;

}




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

typedef long long ll;
typedef pair<int, int> ii;

int main()
{
    char inp[100010];
    scanf("%s", inp);

    int n;
    scanf("%d", &n);

    bool isNormal = true;
    string head, tail;
    auto solve = [&]() {
        for (int i = 0; i < n; i++) {
            int op;
            scanf("%d", &op);

            if (op == 1) {
                isNormal = !isNormal;
            } else {
                // op == 2
                int pos;
                scanf("%d", &pos);

                char c[10];
                scanf("%s", c);

                if (pos == 1) {
                    if (isNormal)
                        head += c;
                    else
                        tail += c;
                } else {
                    if (isNormal)
                        tail += c;
                    else
                        head += c;
                }
            }
        }

        reverse(head.begin(), head.end());
        string ans = head + inp + tail;
        if (isNormal == false)
            reverse(ans.begin(), ans.end());
        printf("%s\n", ans.c_str());
    };

    solve();

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

bool is_prime(ll N) {
    if (N <= 1) {
        return false;
    } else {
        for (ll i = 2; i * i <= N; ++i) {
            if (N % i == 0) {
                return false;
            }
        }
    }
    return true;
}


void Main() {
    ll X;
    cin >> X;
    rep2(i, X, X*100) {
        if (is_prime(i)) {
            cout << i << '\n';
            return;
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define _GLIBCXX_DEBUG
const int INF=1e18;

signed main(){
  	string S;cin>>S;
    int N=S.size();
    vector<int>A(N,0);
    int piyo=0;
    REP(i,N-1){
        if(S[i]=='R'&&S[i+1]=='L'){
            if((i-piyo)%2==0){
                A[i]+=(i-piyo)/2+1;
                A[i+1]+=(i-piyo)/2+1;
            }
            else{
                A[i]+=(i-piyo)/2+1;
                A[i+1]+=(i-piyo)/2+2;
            }
            int j=0;
            while(S[i+2+j]=='L'){
                if(j%2==0)A[i]++;
                else A[i+1]++;
              	j++;
            }
            i=i+1+j;
            piyo=i+1;
        }
    }
    REP(i,N)cout<<A[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

struct cond {
    int x;
    int y;
    int height;
};
#define NUM_MAX 100
#define POS_MAX 100

int func(int x, int y, int top, int cx, int cy) {
    int dist1 = abs(cx-x)+abs(cy-y);
    return max(0, top-dist1);
}

int main(void) {
    int num = get_int();
    struct cond conds[NUM_MAX];

    int i;
    int pivot = 0;
    for(i = 0; i < num; i++) {
        get_int3(&conds[i].x, &conds[i].y, &conds[i].height);
        if(conds[i].height) pivot = i;
    }

    int cx, cy;
    int top = 0;
    for(cx = 0; cx <= POS_MAX; cx++) {
        for(cy = 0; cy <= POS_MAX; cy++) {
            int flag = 1;
            // calc height for pivot
            top = conds[pivot].height + abs(conds[pivot].x-cx) + abs(conds[pivot].y-cy);
            for(i = 0; i < num; i++) {
                if(func(conds[i].x, conds[i].y, top, cx, cy) != conds[i].height) {
                    flag = 0; break;
                }
            }
            if(flag) {
                goto finish;
            }
        }
    }
finish:
    printf("%d %d %d\n", cx, cy, top);
    return 0;
}

Measured memory_bytes: 128
# 初見分からず
# 考え方：個数の組み合わせを総当たりで全パターン試せばよい！
a, b, c, x = map(int, [input() for val in range(4)])

n_pattern = 0
for i in range(a+1):#0~a+1
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                n_pattern += 1

print(n_pattern)


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

using namespace std;
typedef pair<int, int> P;

int main(){
  int N,M;cin>>N>>M;
  P req[M];
  for (int m = 0; m < M; m++) {
    cin>>req[m].first>>req[m].second;
    req[m].first--;req[m].second--;
  }
  sort(req,req+M);
  int start=req[0].first, end=req[0].second;
  int ans=1;
  for (int m = 1; m < M; m++) {
    if(req[m].second<end){
      end=req[m].second;
    }
    if(end<=req[m].first){
      ans++;
      end=req[m].second;
    }
  }
  cout<< ans  << "\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
 
int n,h[1000];
int main()
{
  cin >> n;
  for(int i=0;i<n;i++)
  cin >> h[i];
  sort(h,h+n,greater<int>());
  long long ans = 0;
  for(int i=0;i<n;i++)ans += max(0,h[i]-i/4);
  cout << ans+1 << endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


int N, M;
vvi G;
vb visited;

int dfs(int s)
{
    int path = 0;
    visited[s] = true;
    bool isReef = true;
    REP(i, N)
    {
        if(G[s][i] == 1 && !visited[i])
        {
            isReef = false;
            path += dfs(i);
        }
    }
    bool allVisited = true;
    REP(i, N) if(visited[i] == false) allVisited = false;
    visited[s] = false;
    if(isReef && !allVisited) return 0;
    else if(isReef) return 1;
    return path;
}

void solve()
{
    cin >> N >> M;
    G = vvi(N, vi(N, 0)); 
    visited = vb(N, false);
    REP(i, M)
    {
        int a, b; cin >> a >> b;
        G[--a][--b] = 1;
        G[b][a] = 1;
    }
    cout << dfs(0) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int n;
  cin >> n;
  int min_p = INF;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    int p;
    cin >> p;
    min_p = min(min_p, p);
    if(p <= min_p)++ans;
  }

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


Measured memory_bytes: 256