akhauriyash/Code-Regression huggingface dataset:
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            var A = input[0];
            var B = input[1];
            var C = input[2];
            Console.WriteLine(A[A.Length - 1] == B[0] && B[B.Length - 1] == C[0] ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 11092
while True:
    l = list(map(int,input().split()))
    m = l[0]
    f = l[1]
    r = l[2]

    if m == f == r == -1:
        break
    

    if   m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


Measured memory_bytes: 5596
#include <stdio.h>

int main() {
  char s[4];
  scanf("%s", s);
  for (size_t i = 0; i < 3; i++) {
    if (s[i] == s[i+1]) {
      printf("Bad\n");
      return 0;
    }
  }
  printf("Good\n");
  return 0;
}


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

int main(){
	while(1){
		string s1,s2;
		cin >> s1;
		if(s1==".")break;
		cin >> s2;

		if(s1==s2){
			cout << "IDENTICAL" << endl;
			continue;
		}

		string t1,t2;
		t1 = s1;t2 = s2;
		while(1){
			size_t d1b = t1.find('\"');
			if(d1b==string::npos)break;
			t1.replace(d1b,1,"@");
		
			size_t d1e = t1.find('\"');
			t1.replace(d1e,1,"@");
		
			size_t d2b = t2.find('\"');
			if(d2b==string::npos)break;
			t2.replace(d2b,1,"@");
		
			size_t d2e = t2.find('\"');
			t2.replace(d2e,1,"@");

			string u1 = s1;
			u1.replace(d1b+1,d1e-d1b-1,"");
			string u2 = s2;
			u2.replace(d2b+1,d2e-d2b-1,"");
	
			if(u1==u2){
				t1 = u1;
				t2 = u2;
				break;
			}
		}
		if(t1==t2){
			cout << "CLOSE" << endl;
		}else{
			cout << "DIFFERENT" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3232
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        n: usize, q: usize,
    }

    let mut dsu = DSU::new(n);
    for _ in 0..q {
        input! {
            t: u8, u: usize, v: usize,
        }
        match t {
            0 => {
                dsu.merge(u, v);
            }
            1 => {
                let res = dsu.same(u, v) as u8;
                println!("{}", res);
            }
            _ => unreachable!()
        }
    }
}
#[allow(dead_code)]
pub struct DSU {
    parent_or_size: Vec<isize>,
}

#[allow(dead_code)]
impl DSU {
    pub fn new(n: usize) -> Self {
        assert!(n <= std::isize::MAX as usize);
        Self {
            parent_or_size: vec![-1; n],
        }
    }

    pub fn merge(&mut self, a: usize, b: usize) -> usize {
        let mut x = self.leader(a);
        let mut y = self.leader(b);
        if x == y {
            return x;
        }
        if -self.parent_or_size[x] < -self.parent_or_size[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.parent_or_size[x] += self.parent_or_size[y];
        self.parent_or_size[y] = x as isize;
        x
    }

    pub fn same(&mut self, a: usize, b: usize) -> bool {
        self.leader(a) == self.leader(b)
    }

    pub fn leader(&mut self, a: usize) -> usize {
        if self.parent_or_size[a] < 0 {
            a
        } else {
            self.parent_or_size[a] = self.leader(self.parent_or_size[a] as usize) as isize;
            self.parent_or_size[a] as usize
        }
    }

    pub fn size(&mut self, a: usize) -> usize {
        let leader = self.leader(a);
        -self.parent_or_size[leader] as usize
    }

    pub fn groups(&mut self) -> Vec<Vec<usize>> {
        let mut leader_buf = vec![0usize; self.parent_or_size.len()];
        let mut group_size = vec![0usize; self.parent_or_size.len()];
        for i in 0..self.parent_or_size.len() {
            leader_buf[i] = self.leader(i);
            group_size[leader_buf[i]] += 1;
        }
        let mut result = vec![Vec::new(); self.parent_or_size.len()];
        for i in 0..self.parent_or_size.len() {
            result[i].reserve(group_size[i]);
        }
        for i in 0..self.parent_or_size.len() {
            result[leader_buf[i]].push(i);
        }
        result.retain(|v| !v.is_empty());
        result
    }
}

Measured memory_bytes: 5520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int ma=pow(2,n);
	vector<int> a(ma);
	rep(i,ma) cin >> a.at(i);
	rep(i,n){
		vector<int> b;
		for(int j=0;j<pow(2,n-i);j+=2){
			if(a.at(j)==a.at(j+1)) b.pb(a.at(j));
			else b.pb(abs(a.at(j)-a.at(j+1)));
		}
		a=b;
	}
	cout << a.at(0) << endl;
}

Measured memory_bytes: 1916
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
l = make_divisors(N)
r = sorted(l)
l = sorted(l, reverse = True)
# print(r)
# print(l)

s = []
for i in range(len(r)):
  s.append(r[i]+l[i])
# print(s)
print(min(s)-2)


Measured memory_bytes: 5684
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,Q; cin >> N >> Q;
    vector<int> G[N];
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> cnt(N,0);
    rep(i,Q){
        int a,b; cin >> a >> b;
        a--;
        cnt[a]+=b;
    }
    vector<bool> visited(N,false);
    queue<pair<int,int>> que;
    que.push(make_pair(0,0));
    while(!que.empty()){
        pair<int,int>p=que.front(); que.pop();
        cnt[p.first]+=p.second;
        visited[p.first]=true;
        for(auto s:G[p.first]){
            if(!visited[s]){
                que.push(make_pair(s,cnt[p.first]));
            } 
        }
    }
    rep(i,N) cout << cnt[i] << (i==N-1 ? "":" ");
    cout << endl;

    return 0;
}

Measured memory_bytes: 19568
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import string


def generate_sequence(n):
    n -= 1
    def gen(result, x):
        if x < 0:
            return result
        else:
            d, m = divmod(x, 26)
            char = string.ascii_lowercase[m]
            return gen(char + result, d - 1)
    return gen("", n)


main = lambda: print(generate_sequence(int(input())))


if __name__ == '__main__':
    main()


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


long long a[200005];
long long n,x;
long long pre[200005];

long long f(long long x){
    if(x==1)return 5;
    return (2*x+1);
}

int main() {
    cin >> n >> x;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        pre[i]+=a[i];
        pre[i+1] = pre[i];
    }
    long long mn = 1e18;
    for(int k=1;k<=n;k++){
        bool take = true;
        long long ans = 0;
        int cur = 1;
        for(int i=n;i>0;i-=k){
            ans+=(pre[i]-pre[max(0,i-k)])*f(cur);
            if(ans>mn){
                take = false;
                break;
            }
            cur++;
        }
        mn = min(ans+k*x,mn);
    }
    cout << mn+n*x;
    return 0;
}


Measured memory_bytes: 3328
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
 
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())
 
#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

char board[305][305];

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

  int N;
  cin >> N;

  for (int i = 0; i < N; ++i) {
    cin >> board[i];
  }

  int answer = 0;

  for (int c = 0; c < N; ++c) {
    bool check = true;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        if (board[(i + c) % N][j] != board[(j + c) % N][i]) {
          check = false;
          break;
        }
        if (!check) {
          break;
        }
      }
    }

    if (check) {
      answer++;
    }
  }

  cout << answer * N << endl;

  return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define INF 10000000
int senbei[10][10000];
int max(int a,int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
int main(){
	while(1){	
		int r,c,i,count,a,ans=0;
		int d[10];
		cin>>r>>c;
		if(r==0&&c==0)break;
		for(i=0;i<r;i++){
			for(int j=0;j<c;j++){
				cin>>senbei[i][j];	
			}	
		}
		for (i = 0; i <=(1 << r); i++) {
			a=0;
			for (int j = 0; j < r; j++) {
				d[j]=((i >> j) & 1);
			}
			for(int j=0;j<c;j++){
				count=0;
				for(int k=0;k<r;k++){
					if(senbei[k][j]==d[k]){
						count++;
					}
				}
				if(count>r/2){
					a+=count;
				}else{
					a+=(r-count);
				}
			}
			ans=max(ans,a);
		}
		cout<<ans<<endl;
	}

	return 0;
}	

Measured memory_bytes: 1548
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>
#include <cstdio>

using namespace std;

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

int main() {
    int A, B;
    scanf("%d %d", &A, &B);
    if (B < A) swap(A, B);
    if ((A + B) % 2 == 0) {
        cout << (A + B) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
typedef priority_queue<int> p_queue;
typedef long long ll;
int read(){
	char c=getchar();
	int sum=0;
	while(c>'9'||c<'0')c=getchar();
	while(c<='9'&&c>='0')sum=sum*10+c-'a',c=getchar();
	return sum;
}
ll n,s,k;
ll x=1e9;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>k>>s;
	for(int i=0;i<k;i++){
		cout<<s<<' ';
	}
	for(int i=k;i<n;i++){
		if(s==x){
			cout<<1<<' ';
		}
		else cout<<s+1<<' ';
	}
	return 0;
}


Measured memory_bytes: 1280
use proconio::input;

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        n: usize,
        mut a: [usize; n],
    }
    a.sort();
    a.reverse();

    let mut ans = 0;
    let mut v = Vec::new();
    v.push(a[0]);
    for i in 1..n {
        v.push(a[i]);
        v.push(a[i]);
    }
    for i in 0..n-1 {
        ans += v[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 9304
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

#include<unistd.h>
struct Buffer{
    int idx;
    enum { chunk = 1 << 16 };
    char buf[chunk];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, chunk); }
    void check(){ if(idx == chunk){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0;//, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        // if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return /*sign **/ ret;
    }
};

string ans;
void out(int num){
    if(!num){
        // putchar('0');
        ans += '0';
        return;
    }
    char buf[16];
    int idx = 0;
    while(num){
        auto ret = div(num, 10);
        buf[idx] = ret.rem + '0';
        num = ret.quot;
        idx++;
    }
    for(int i = idx - 1; i >= 0; i--){
        // putchar(buf[i]);
        ans += buf[i];
    }
}

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    Buffer buf;
    const int lim = 1e5;
    vector<char> prime(lim + 1, true);
    prime[0] = prime[1] = false;
    for(int i = 2; i <= lim; i++){
        if(prime[i]){
            for(int j = i + i; j <= lim; j += i){
                prime[j] = false;
            }
        }
    }
    vector<int> accs(lim + 1);
    // for(int i = 1; i <= lim; i++){
    //     accs[i] = accs[i - 1] + (i & 1 && prime[i] && prime[(i + 1) >> 1]);
    // }
    for(int i = 1; i <= lim; i += 2){
        accs[i] = prime[i] && prime[(i + 1) >> 1];
    }
    for(int i = 1; i <= lim; i++){
        accs[i] += accs[i - 1];
    }
    // printd(accs[lim]);
    // int q; cin >> q;
    int q = buf.next();
    // stringstream ss;
    ans.reserve(4 * q);
    for(int i = 0; i < q; i++){
        // int l, r;
        // cin >> l >> r;
        int l = buf.next(), r = buf.next();
        // cout << accs[r] - accs[l - 1] << '\n';
        // ss << accs[r] - accs[l - 1] << '\n';
        out(accs[r] - accs[l - 1]);
        // putchar('\n');
        ans += '\n';
    }
    // cout << ss.str();
    cout << ans;
    // write(1, ans.data(), ans.size());
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 5e5 + 8;

namespace Fenwick {
	int n;
	int f[N];

	void init(int n_) {
		n = n_;
	}

	void add(int pos, int val) {
		for (int i = pos; i < n; i = (i | (i + 1))) {
			f[i] += val;
		}
	} 

	int sum(int r) {
		int ans = 0;
		for (int i = r; i >= 0; i = (i & (i + 1)) - 1) {
			ans += f[i];
		}
		return ans;
	}

	int sum(int l, int r) {
		return sum(r) - sum(l - 1);
	}
};

int a[N];
int ans[N];
vector<pair<int, int>> qr[N];

int lst[N];

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

	int n, q;	
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		qr[r].push_back({l, i});
	}
	fill(lst, lst + N, -1);
	Fenwick::init(n);
	for (int i = 0; i < n; i++) {
		if (lst[a[i]] != -1) {
			Fenwick::add(lst[a[i]], -1);
		}
		lst[a[i]] = i;
		Fenwick::add(lst[a[i]], 1);
		for (auto [l, ind] : qr[i]) {
			ans[ind] = Fenwick::sum(l, i);
		}
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << '\n';
	}
}


Measured memory_bytes: 33244
N,M,C = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0

for i in range(N):
    A = list(map(int, input().split()))
    re = 0
    for j in range(M):
        re += A[j] * B[j]
        
    re += C
    if re > 0:
        cnt += 1
        
print(cnt)

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

#define llint long long int

using namespace std;

int main(){
    string S;

    cin >> S;

    deque<char> ans;

    for(int i = 0; i < S.length(); i ++){
        ans.push_back(S[i]);
    }
    int Q;

    cin >> Q;

    bool front = true;

    for(int i = 0; i < Q; i ++){
        int T;

        cin >> T;

        if(T == 1){
            front = !front;
        }else{
            int F;
            char C;

            cin >> F >> C;

            if(front == true && F == 1 || front == false && F == 2){
                ans.push_front(C);
            }else{
                ans.push_back(C);
            }
        }
    }
    if(front == true){
        for(auto itr = ans.begin(); itr != ans.end(); itr ++){
            cout << *itr;
        }
    }else{
        for(auto itr = ans.end() - 1; itr != ans.begin() - 1; itr --){
            cout << *itr;
        }
    }
    cout << endl;
}

Measured memory_bytes: 896
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//227
	int a,b;
	cin>>a>>b;
	cout<<a+b/2;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

class E
{
	static long[] Read() => Console.ReadLine().Split().Select(long.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		long n = h[0], x = h[1], m = h[2];

		var f = new long[m];
		for (long i = 0; i < m; i++)
			f[i] = i * i % m;

		var l = new List<long> { 0, x };
		var order = new int[m];
		var c = 0;
		order[x] = ++c;
		var t = x;

		while (order[f[t]] == 0)
		{
			l.Add(l.Last() + f[t]);
			order[f[t]] = ++c;
			t = f[t];
		}
		var o1 = order[f[t]];
		var o2 = ++c;
		if (n < o2) { Console.WriteLine(l[(int)n]); return; }

		n -= o2 - 1;
		var r = l.Last();
		r += n / (o2 - o1) * (l.Last() - l[o1 - 1]);
		r += l[o1 - 1 + (int)(n % (o2 - o1))] - l[o1 - 1];
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 30000
N, D = map(int, input().split())
X = []
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x)

import itertools
cnt = 0

for x, y in list(itertools.combinations(X, 2)):
    dist = 0
    for i in range(D):
        dist += (x[i]-y[i])**2
    if (dist**0.5)%1==0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3188
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

n,k=list(map(int,input().split()))
x2=Base_10_to_n(n,k)
print(len(str(x2)))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890l
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define foritr(itr, A) for(set<ll>::iterator itr = A.begin(); itr != A.end(); itr++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing if(db)cout << " ";
#define space " "
#define cbr cout << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, m, co[1006];
int main()
{
	cin >> n >> m;
	FOR(i,0,n)
	{
		ll k; cin >> k;
		FOR(j,0,k) { ll a; cin >> a; co[a] ++; }
	}
	ll ans = 0;
	FOR(i,1,m+1) if(co[i] == n) ans ++;
	cout << ans;
}


Measured memory_bytes: 256
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
c.sort()
ans = 0
for i in range(n):
    ans += bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
print(ans)

Measured memory_bytes: 23232
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    int N;
    cin>>N;
    int a;
    int flag=0;
    for(int i=0;i<N;i++){
        cin>>a;
        if(a%2==0){
            if(a%3==0||a%5==0){

            }else{
                flag=1;
            }
        }
    }
    if(flag){
        cout<<"DENIED"<<endl;
    }else{
        cout<<"APPROVED"<<endl;
    }

    
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] a = new int[n];
			long sum = 0;
			for(int i = 0 ; i < n ; i++) {
				a[i] = sc.nextInt();
				sum += a[i];
			}
			long now = 0;
			long min = Long.MAX_VALUE;
			for(int i = 0 ; i < n - 1 ; i++) {
				now += a[i];
				min = Math.min(min, Math.abs(now - (sum - now)));
			}
			System.out.println(min);
		}

	}

}


Measured memory_bytes: 60500
#include<stdio.h>
#define ll long long int
int main()
{
    ll n,a,b;
    scanf("%lld %lld %lld",&n,&a,&b);
    if(n==(a+b)){
        printf("%lld",a);
    }
    else if(n<(a+b)){
        if(n<a){
            printf("%lld",n);
        }
        else{
            printf("%lld",a);
        }
    }
    else{
        ll x=n%(a+b);
        ll y=n/(a+b);
        if(x<a){
            printf("%lld",(a*y)+x);
        }
        else{
            printf("%lld",(a*y)+a);
        }
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
typedef long long ll;
int main(void)
{
	ll x,k,d;
	scanf("%lld%lld%lld",&x,&k,&d);
	if(x<0) x=-x;
	ll j=x/d;
	if(j>=k) printf("%lld",x-d*k);
	else
	{
		k-=j;
		ll ans=x%d;
		if(k%2==0) printf("%lld",ans);
		else printf("%lld",-(ans-d));
	}
}

Measured memory_bytes: 3824
N, K =list(map(int, input().split()))
x=list(map(int, input().split()))
ans=10000000000000
for i in range(N-K+1):
    if min(abs(x[i])+abs(x[i+K-1]-x[i]), abs(x[i+K-1])+abs(x[i+K-1]-x[i]))<ans:
        ans=min(abs(x[i])+abs(x[i+K-1]-x[i]), abs(x[i+K-1])+abs(x[i+K-1]-x[i]))
print(ans)


Measured memory_bytes: 14252
package main
 
import (
	"fmt"
)
 
func main() {
  var a, b, c int
  var k int
  
  fmt.Scanf("%d %d %d", &a, &b, &c)
  fmt.Scanf("%d", &k)
  
  for i := 0; i < k; i++{
    if a < b && b < c {
      break
    }
    if a >= b{
      b *= 2
      continue
    }
    if b >= c{
      c *= 2
      continue
    }
  }
  
  ans := "Yes"
  if a >= b {
    ans = "No"
  }
  if b >= c {
    ans = "No"
  }
  
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1832
from bisect import *
n=int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
ans=0
for i in range(n):
    x=bisect_left(a,b[i])
    y=n-bisect_right(c,b[i])
    ans+=x*y
print(ans)

Measured memory_bytes: 107108
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define inf 1e9

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

struct edge{
	int to, cost, cost2;
	edge(int a, int b, int c){
		to = a, cost = b, cost2 = c;
	}
};

int n, m;
vector<edge> G[10005];
int dist[10005];
int mn[10005];

void dijkstra()
{
	for(int i = 1; i <= n; i++) dist[i] = inf;
	dist[1] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, 1) );
	
	int v, d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i].to] > d + G[v][i].cost){
				dist[G[v][i].to] = d + G[v][i].cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

int main(void)
{
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		
		for(int i = 1; i <= n; i++) G[i].clear();
		
		int u, v, d, c;
		for(int i = 1; i <= m; i++){
			cin >> u >> v >> d >> c;
			G[u].push_back(edge(v, d, c));
			G[v].push_back(edge(u, d, c));
		}
		
		dijkstra();
		
		for(int i = 1; i <= n; i++) mn[i] = inf;
		for(int i = 1; i <= n; i++){
			for(int j = 0; j < G[i].size(); j++){
				int v = G[i][j].to;
				if(dist[i] + G[i][j].cost == dist[v]) mn[v] = min(mn[v], G[i][j].cost2);
			}
		}
		
		int ans = 0;
		for(int i = 2; i <= n; i++) ans += mn[i];
		cout << ans << endl;
	}
	
	return 0;
}


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

/*============================ DEBUGGING =============================*/

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*============================= DEFINES ==============================*/

#define eps 1e-9
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define B begin()
#define E end()
#define F first
#define S second
#define tostr(x) to_string(x)
#define SZ(x) ((int)x.size())
#define ins insert
#define rep(i,x,y) for(int i=x;i<y;i++)
#define per(i,x,y) for(int i=x;i>y;i--)
#define repi(i,x,y) for(int i=x;i<=y;i++)
#define peri(i,x,y) for(int i=x;i>=y;i--)
#define inf (ll)LLONG_MAX
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x)
#define fib(n) ceil(pow((1+sqrt(5),n)-pow((1-sqrt(5),n)/(float)(pow(2,n)*sqrt(5)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define dig(n) (int)(log10(n)+1)
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define set(x,k) memset(x,k,sizeof x)

/*============================== TYPEDEFS ============================*/

typedef long long ll;
typedef long double ld;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<bool> vb;
typedef queue<int> qi;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;

/*============================ START FROM HERE =======================*/

int main(){
	FIO
	
	ll n;cin>>n;
	ll ans=inf;
	for(ll i=1;i*i<=n;i++){
		if(!(n%i)){
			ans=min(ans,(abs(i-1)+abs(n/i-1)));
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i,t,n) for(int i=t;i<n;i++)
#define nd "\n"
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>




/*ll power(ll x,ll t){
if(t<=0){
    return 1;
}
ll y=(power(x,t/2));
y=(y*y)%ma;
if(t%2)
    y=(y*x)%ma;
return y;

}*/
/*ll ph[100001];
void E_phi(int n){

ph[0]=0;
ph[1]=1;
for(int i=2;i<=n;i++){
    ph[i]=i;
}
for(int i=2;i<=n;i++){
    if(ph[i]==i){
        for(int j=i;j<=n;j+=){
            ph[j]-=ph[j]/i;
        }
    }
}


}*/
/*string s,t;
vector<int>  z_fun(string s){

int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}*/

/*struct st{
ll sum,pre,suf,ans;
st(){}
st(ll k){
ans=k,pre=k,suf=k,sum=0;
}

};
ll t[4*200001+4];
ll a[200001];
ll lazy[4*200001+4];
ll mx=1e14;



void push(int ind){
int l=2*ind+1,r=2*ind+2;
t[l]+=lazy[ind];
t[r]+=lazy[ind];
lazy[l]+=lazy[ind];
lazy[r]+=lazy[ind];
lazy[ind]=0;

}

void build(int ind,int l,int r){
if(l==r){
    t[ind]=a[l];
return;
}
int mid=(l+r)/2;
build(2*ind+1,l,mid);
build(2*ind+2,mid+1,r);

  t[ind] =min(t[ind*2+1] , t[ind*2+2]);



}
ll query(int ind,int l,int r,int p,int q){

if(l>q || r<p )
    return mx;
    int mid=(l+r)/2;

if(l>=p && r<=q )
    {
      return t[ind];
    }
    push(ind);
ll x=query(2*ind+1,l,mid,p,q);
ll y=query(2*ind+2,mid+1,r,p,q);


return min(x,y);
}

void update(int ind,int l,int r,int p,int q,int val){
if(l>q || r<p )
    return;

if(l>=p && r<=q )
    {
      t[ind]+=val;
      lazy[ind]+=val;
      return;
    }
push(ind);
int mid=(l+r)/2;
    update(2*ind+1,l,mid,p,q,val);
     update(2*ind+2,mid+1,r,p,q,val);
    t[ind]=min(t[2*ind+1],t[2*ind+2]);



}


ll mod(ll a){
if(a>=0)
    return a;
else return -a;
}
*/

int v[1000001];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    vector<ll> b;
    for(ll i=2;i<1000001;i++){
        if(!v[i]){
            b.pb(i);
            for(ll j=i*i;j<=1000000;j+=i)
                v[j]=1;
        }
    }

    int n;
    cin>>n;
    ll ans=1;
    for(int i=2;i<n;i++){
        int p=i;
        ll t=1;
        for(int j=0;j<b.size() && b[j]*b[j]<=p;j++){
            int co=0;
            while(p%b[j]==0){
                p/=b[j];
                co++;

            }
            t*=(co+1);
        }
        if(p>1)t*=2;
        ans+=t;
    }
    cout<<ans<<endl;


}


Measured memory_bytes: 8112
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N;
  cin>>N;
  vector<bool> A(100000);
  int count=0;
  rep(i,0,N){
    int X; cin>>X;
    if(A[X-1])
      count++;
    else
      A[X-1]=1;
    }
  int K=(count+1)/2;
  cout<<N-K*2<<endl;
  }


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



int main() {

  int64_t H,W;
  cin >> H >> W;

  int64_t ans;
  if(W==1 || H==1) {
    ans=1;
  } else {

  
  if(H%2==0 || W%2==0) {
      ans=(H*W)/2;
  } else {
      ans=(H*W+1)/2;
  }
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
n,m=map(int,input().split())

l=[]
r=[]

for i in range(m):
    a,b=map(int,input().split())
    l.append(a)
    r.append(b)

if min(r)-max(l)+1<0:
    print(0)
else:
    print(-max(l)+min(r)+1)

Measured memory_bytes: 11036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100 + 5;

void bfs(int n){
	int ans = 0;
	priority_queue <ll,vector<ll>,greater<ll> > q;
	for(int i = 1; i <= 9; i++)
		q.push(i);
	while(!q.empty()){
		ll x = q.top();
		q.pop();
		ans++;
		if(ans == n){
			cout << x << endl;
			return;
		}
		ll z = x % 10;
		if(z - 1 >= 0)
			q.push(x*10+z-1);
		if(z >= 0)
			q.push(x*10+z);
		if(z + 1 <= 9)
			q.push(x*10+z+1);
	}
	return;
}

int main(){
	int n;
	cin >> n;
	bfs(n);
    return 0;
}

Measured memory_bytes: 2420
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int NN = N+2;
		double[][] dist = new double[NN][];
		for(int i=0;i<NN;i++) dist[i] = new double[NN];
		for(int i=0;i<NN;i++){
			for(int j=i+1;j<NN;j++){
				if((X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]) < (R[i]+R[j])*(R[i]+R[j]) ){
					dist[i][j] = dist[j][i] = 0;
				}else{
					dist[i][j] = dist[j][i] = Math.Sqrt((double)((X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]))) - (double)(R[i]+R[j]);
				}
			}
		}
		
//for(int i=0;i<NN;i++) Console.WriteLine(String.Join(" ",dist[i]));
		
		double[] Min = new double[NN];
		for(int i=1;i<NN;i++) Min[i] = 1e15;
		bool[] used = new bool[NN];
		used[0] = false;
		
		for(int i=0;i<NN;i++){
			int idx = -1;
			double mi = 1e16;
			for(int j=0;j<NN;j++){
				if(used[j])continue;
				if(Min[j] < mi){
					idx = j;
					mi = Min[j];
				}
			}
			used[idx] = true;
			for(int j=0;j<NN;j++){
				Min[j] = Math.Min(Min[j],Min[idx]+dist[idx][j]);
			}
		}
		Console.WriteLine(Min[NN-1]);
	}
	int Xs,Ys,Xt,Yt;
	int N;
	long[] X,Y,R;
	public Sol(){
		
		var d = ria();
		Xs = d[0]; Ys = d[1];
		Xt = d[2]; Yt = d[3];
		
		N = ri();
		X = new long[N+2];
		Y = new long[N+2];
		R = new long[N+2];
		
		X[0] = Xs;X[N+1] = Xt;
		Y[0] = Ys;Y[N+1] = Yt;
		
		for(int i=0;i<N;i++){
			var dd = rla();
			X[i+1] = dd[0];
			Y[i+1] = dd[1];
			R[i+1] = dd[2];
		}
		
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


class SkewHeap<T> where T:IComparable<T>{
	public int Count{
		get{return cnt;}
		private set{cnt=value;}
	}
	
	public SkewHeap(){
		root=null;
		this.Count=0;
	}
	
	public void Push(T v){
		NodeSH<T> p=new NodeSH<T>(v);
		root=NodeSH<T>.Meld(root,p);
		this.Count++;
	}
	
	public void Pop(){
		if(root==null)return;
		root=NodeSH<T>.Meld(root.L,root.R);
		this.Count--;
	}
	
	public T Top{
		get{return root.Val;}
	}
	
	int cnt;
	NodeSH<T> root;
	
	class NodeSH<S> where S : IComparable<S> {
		public NodeSH<S> L, R;
		public S Val;

		public NodeSH(S v){
			Val = v;
			L = null; R = null;
		}
		public static NodeSH<S> Meld(NodeSH<S> a, NodeSH<S> b){
			if(a == null)return b;
			if (b == null) return a;
			if (a.Val.CompareTo(b.Val) > 0) swap(ref a, ref b);
			a.R = Meld(a.R, b);
			swap(ref a.L, ref a.R);
			return a;
		}

		static void swap<U>(ref U x, ref U y) {
			U t = x; x = y; y = t;
		}
	}
}



Measured memory_bytes: 14680
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;


	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			char[] s = sc.next().toCharArray();
			String T = sc.next();
			
			Character[] t = new Character[T.length()];
			
			for(int i=0;i<T.length();i++) {
				t[i] = T.charAt(i);
			}
			
			Arrays.sort(s);
			Arrays.sort(t,Collections.reverseOrder());
			
			char[] tn = new char[T.length()];
			
			for(int i =0;i<T.length();i++) {
				tn[i] = t[i];
			}
			
						
			String Sn = String.valueOf(s);
			String Tn = String.valueOf(tn);
			

			
			if(Sn.compareTo(Tn)<0) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
			
		}



	}


Measured memory_bytes: 21844
N, K = map(int, input().split())
mod = 10 ** 9 + 7

ans = 0
for k in range(K, N+2):
    upper = k * ((N-k+1)+N) // 2
    lower = k * (k-1) // 2
    ans += upper - lower + 1
    ans %= mod
print(ans)


Measured memory_bytes: 9084
#include <iostream>
#include <vector>
using namespace std;
// http://drken1215.hatenablog.com/entry/2019/05/19/224500
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

int N;
Graph G;
vector<int> res;

void dfs(int v, int p, int c) {
    res[v] = c;
    for(auto e : G[v]) {
        if(e.first == p)
            continue;
        if(e.second & 1)
            dfs(e.first, v, 1 - c);
        else
            dfs(e.first, v, c);
    }
}

int main() {
    cin >> N;
    G.assign(N, vector<Edge>());
    for(int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        --u;
        --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    res.assign(N, 0);
    dfs(0, -1, 1);
    for(auto v : res)
        cout << v << endl;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
	string s;
	cin>>s;
	vector<int> outp(int(1e6),-1);
	int x=5*int(1e5),y;
	for(y=0;y<s.size();y++){
		outp[x+1+y]=int(s[y]-'a');
	}
	y=s.size()+1+x;


	bool flag =true;
	int q;
	cin>>q;
	int t,f;
	char c;
	for(int i=0;i<q;i++){
		cin>>t;
		if(t==1){
			flag=(!flag);
		}
		else{
			cin>>f>>c;
			if(flag){
				if(f==1){
					outp[x]=int(c-'a');
					x--;
				}
				else{
					outp[y]=int(c-'a');
					y++;
				}
			}
			else{
				if(f==2){
					outp[x]=int(c-'a');
					x--;
				}
				else{
					outp[y]=int(c-'a');
					y++;
				}
			}
		}
	}
	if(flag){
		for(int i=0;i<outp.size();i++)
			if(outp[i]!=-1)
			cout<<char(outp[i]+'a');
		cout<<"\n";
	}
	else{
		for(int i=outp.size()-1;i>-1;i--)
			if(outp[i]!=-1)
			cout<<char(outp[i]+'a');
		cout<<"\n";
	}

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

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

int main()
{
    int n, l, r, sum = 0;
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> l >> r;
        sum += r - l + 1;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
 
template <class T>
void printArray(vector<T> arr) {for (T a: arr) cout << a << " ";cout << '\n';}
void printVerdict(bool verdict) {cout << (verdict ? "YES": "NO") << '\n';}
void printDecimal(double d) {printf("%.9f\n", d);}
bool inrange(int val, int start, int end) {return val >=start && val <= end;}
 
int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> count(n+1, 0);
	for (int x = 1; x<=105; x++) {
		for (int y = 1; y<=105; y++) {
			for (int z = 1; z <= 105; z++) {
				int evaluate = x*x + y*y + z*z + x*y + y*z + z*x;
				if (evaluate <= n) count[evaluate]++;
			}
		}
	}
	for (int i = 1; i<=n; i++) cout << count[i] << '\n';
	
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  int ans = 0;
  for(int i = 0; i < m; i++){
      cin >> a.at(i);
      ans += a[i];
  }
  if(n-ans < 0){
      cout << "-1";
  }else{
  cout << (n - ans);
  }
}

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

int main() {
	vector<int> d(5);
	int A, B; cin >> A >> B;
	int res = 0;
	for (int i = A; i <= B; i++)
	{
		int c = i;
		for (int j = 0; j < 5; j++)
		{
			d[4-j] = c % 10;
			c /= 10;
		}
		if(d[0] == d[4] && d[1] == d[3]) res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int a,b,c;
    std::cin>>a;
    std::cin>>b;
    std::cin>>c;
    
    if(a<b&&b<c){
        std::cout<<"Yes"<<std::endl;
    }
    else{
        std::cout<<"No"<<std::endl;
    }
}



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

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> city(n);
  ll genzaiti = 1;
  ll count = 0;
  map <ll, ll> mp;
  rep(i,n)
    cin >> city[i];
  while(!mp.count(genzaiti)){
    mp[genzaiti] = count;
    count++;
    genzaiti = city[genzaiti-1];
  }
  ll hanpuku = genzaiti;
  ll syuuki = mp.size() - mp.at(hanpuku);
  genzaiti = 1;
  if(mp.at(hanpuku) > k){
    rep(i,k){
      genzaiti = city[genzaiti-1];
    }
  }
  else{
    k = k - mp.at(hanpuku);
    k = k % syuuki;
    k = k + mp.at(hanpuku);
    rep(i,k){
      genzaiti = city[genzaiti-1];
    }
  }
  cout << genzaiti << endl;
}

Measured memory_bytes: 17252
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <queue>
#define FOR(x, y, z) for(int x = 0; y; x++)
#define rep(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(),x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define sp_str(str, sp_word) istringstream stream(str); string res; while(getline(stream,res,sp_word))
#define rem_space(x) x.erase(remove(all(x), ' '),x.end())
#define scl(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
using namespace std;

int main(){
 up_queue(int) bels;
 string line;
 getline(cin,line);
 sp_str(line,' ') bels.push(atoi(res.c_str()));
 int anser = bels.top();
 bels.pop();
 anser += bels.top();
 
 printf("%d\n",anser);
 return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(br.readLine());
        int k = Integer.parseInt(br.readLine());
        int x = Integer.parseInt(br.readLine());
        int y = Integer.parseInt(br.readLine());
        if(n <= k){
            System.out.print(n*x);
            return;
        }
        System.out.print((k*x + (n - k)*y));
    }
}

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

int main()
{
  int N ;
  cin>>N ;
  vector<pair<int,int>>A ;
  for(int i=0;i<N;i++){
    int tmp ;
    cin>>tmp ;
    A.push_back(make_pair(tmp,i)) ;
  }
  sort(A.begin(),A.end()) ;
  
  for (pair<int, int> t : A) {
    cout << t.second+1 <<" " ;
  }
  
  return 0 ;
}

Measured memory_bytes: 1780
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

#define INF (1LL << 60)

Int R[5 << 10][5 << 10];
int C[5 << 10][5 << 10];

int main()
{
	int N;
	Int A, B;
	scanf("%d%lld%lld", &N, &A, &B);

	int i, j;
	VInt p(N);
	VInt q(N);
	FOR(i, 0, N)
	{
		scanf("%d", &p[i]);
		--p[i];
		q[p[i]] = i;
	}

	CLEAR(C, 0);
	FOR(i, 0, N)
		RFOR(j, i, 0)
		{
			C[i][j] = C[i][j + 1];
			if (q[j] > q[i]) ++C[i][j];
		}

	FOR(i, 0, N + 1)
		FOR(j, 0, N + 1)
		R[i][j] = INF;

	R[0][0] = 0;
	FOR(i, 0, N)
		FOR(j, 0, N + 1)
		if(R[i][j] != INF)
		{
			if(p[i] <= j)
			{
				R[i + 1][max(j, p[i] + 1)] = min(R[i + 1][max(j, p[i] + 1)], R[i][j]);
				continue;
			}

			R[i + 1][j] = min(R[i + 1][j], R[i][j] + A);
			R[i + 1][p[i] + 1] = min(R[i + 1][p[i] + 1], R[i][j] + B*C[p[i]][j]);
		}

	Int res = INF;
	FOR(i, 0, N + 1) res = min(res, R[N][i]);

	printf("%lld\n", res);
	return 0;
};


Measured memory_bytes: 303360
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
typedef vector<pii> vp;

#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

int n;
int a[112345];

int main() {
	cin >> n;
	REP(i, n) scanf("%d", a + i);
	
	ll ans = 0, ma = 1;
	REP(i, n) {
		if (a[i] < ma) continue;
		
		ll now = (a[i] + ma - 1) / ma - 1;
		ans += now;
		
		
		if (now >= 1) {
			a[i] -= ma * (now - 1);
			a[i] = 1;
		}
		
		if (a[i] == ma) ma++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long

using namespace std;
const double PI=acos(-1);
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    double r;
    cin >> r;
    cout<< fixed <<setprecision(16) << r*r*PI << " "<< fixed << setprecision(16) << r*2*PI <<endl ;
    return 0;


}



Measured memory_bytes: 3260