akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
void ABC140(void);
void ABC141(void);
void ABC142(void);
void ABC143(void);
void ABC144(void);
void ABC145(void);
void ABC146(void);
void ABC147(void);
void ABC148(void);
void ABC149(void);

int main(void){
    ABC141();
}

void ABC141(){
    string s;
    cin>>s;
    if(s=="Sunny")cout<<"Cloudy";
    else if(s=="Cloudy")cout<<"Rainy";
    else cout<<"Sunny";
}

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

#define INF ((1<<31)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;



int main(){
    bool flag=true;
    ll ans=0,sum=0;
    ll n,a;
    cin >>n>>a;
    vector<int> x(n);

    for (int i = 0; i < n; i++)
    {
        cin >>x[i];
        sum += x[i];
    }

    ll dp[n+1][n+1][sum+1]={};
    dp[0][0][0]=1;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            
            for (int k = 0; k <= sum; k++){
                if(k + x[i] <= sum){
                    dp[i+1][j+1][k + x[i]] += dp[i][j][k];
                }
                dp[i+1][j][k] += dp[i][j][k];
            }
        }
    }
    
    for (int i = 1; i <= n; i++){
        if(a*i <= sum)ans += dp[n][i][a*i];
        //cout << dp[n][i][a*i] << endl;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 51072
#include <bits/stdc++.h>
using namespace std;
const int maxn=200005;
int n,id[maxn],x_[maxn],y_[maxn],tot;
inline void add(int x,int y) { x_[++tot]=x,y_[tot]=y; }
int main()
{
	scanf("%d",&n);
	for(int i=0;i<=16;i++)
		if((1<<i)==n) return puts("No"),0;
	add(1,2),add(2,3),add(3,n+1),add(n+1,n+2),add(n+2,n+3);
	for(int i=4;i<n;i+=2)
		add(i,i+1),add(i+1,n+1),add(n+1,n+i),add(n+i,n+i+1);
	if(!(n&1))
	{
		#define id(x) ((x&1)?x:x+n)
		for(int i=2;i<n;i++)
			if((n^i^1)<n) { add(n,id(i)),add(id(n^i^1),2*n); break; }
	}
	puts("Yes");
	for(int i=1;i<=tot;i++) printf("%d %d\n",x_[i],y_[i]);
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    N %= 10;
    if(N==2 || N==4 || N==5 || N==7 || N==9){
        cout << "hon" << endl;
    }else if(N==0 || N==1 || N==6 || N==8){
        cout << "pon" << endl;
    }else if(N==3){
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
s = str(input())
k = int(input())
S = []
for i in range(len(s)):
    S.append(ord(s[i]) - 97)
i = 0
while k > 0:
    if S[i] > 0 and 26 - S[i] <= k:
        k -= 26 - S[i]
        S[i] = 0
        i += 1
    else:
        i += 1
    if i >= len(s):
        S[-1] += k
        break
ans = ''
for x in S:
    ans += chr((x % 26) + 97)
print(ans)


Measured memory_bytes: 4340
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define pll pair<ll , ll >
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back

using namespace std;
const int maxn = 1000*100+5 ;
const ll inf = 9223372036854775807 ;

ll n , a[maxn] , b[maxn] , c[maxn] , dp[maxn][3]; 
int main()
{
	migmig ;
	cin>>n ; 
	for(int i= 1 ; i <= n ; i++ )
	{
		cin>>a[i]>>b[i]>>c[i] ; 
	}
	dp[1][0] = a[1] ; 
	dp[1][1] = b[1] ; 
	dp[1][2] = c[1] ; 
	
	for(int i = 2 ; i <= n ; i++ )
	{
		dp[i][0] = a[i] + max(dp[i-1][1] , dp[i-1][2]) ; 
		dp[i][1] = b[i] + max(dp[i-1][0] , dp[i-1][2]) ; 
		dp[i][2] = c[i] + max(dp[i-1][1] , dp[i-1][0]) ;  
	}
	cout<<max(dp[n][0] , max(dp[n][1] , dp[n][2])) ; 
}
//////
////////
///////////




Measured memory_bytes: 4992
#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() {

	char a;
	cin >> a;

	if (isupper(a)) {
		cout << "A" << endl;
	}
	else {
		cout << "a" << endl;
	}








}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5005;
int n,k,p[N],c[N],cir[N];
int cal(int st)
{
	int now=p[st],j=0;
	while(now!=st)
	{
		cir[++j]=c[now];
		now=p[now];
	}
	cir[++j]=c[now];
	for(int i=1;i<=j;i++) 
		cir[i]+=cir[i-1];
	if(k<=j)
	{
		int ans=cir[1];
		for(int i=1;i<=k;i++) 
			ans=max(ans,cir[i]);
		return ans;
	}
	else
	{
		int ans=cir[1];
		for(int i=1;i<=j;i++) 
			ans=max(ans,cir[i]);
		int macir=ans,qu=k%j,maqu=0;
		for(int i=1;i<=qu;i++) 
			maqu=max(maqu,cir[i]);
		ans=max(ans,k/j*cir[j]+maqu);
		if(k/j>0)
			ans=max(ans,(k/j-1)*cir[j]+macir);
		return ans;
	}
}
signed main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++) 
		scanf("%lld",&p[i]);
	for(int i=1;i<=n;i++) 
		scanf("%lld",&c[i]);
	int ans=-1e17;
	for(int i=1;i<=n;i++)
		ans=max(cal(i),ans);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3936
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
struct edge {
	int to;
	ll weight;
	edge(int to, ll weight = 1) :to(to), weight(weight) {}
};
void dijkstra(int s, vector<vector<edge>> &G, vector<ll> &dist) {
	using P = pair<ll, int>;
	dist.resize(G.size());
	fill(ALL(dist), INF);
	dist[s] = 0;
	priority_queue<P, vector<P>, greater<P>> Q;
	Q.emplace(0, s);
	while (!Q.empty()) {
		P now = Q.top(); Q.pop();
		if (dist[now.second] < now.first) continue;
		for (edge &e : G[now.second]) {
			if (dist[e.to] > now.first + e.weight) {
				dist[e.to] = now.first + e.weight;
				Q.emplace(dist[e.to], e.to);
			}
		}
	}
}
int main() {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--; t--;
	vector<vector<edge>> G1(n), G2(n);
	rep(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--; v--;
		G1[u].emplace_back(v, a);
		G1[v].emplace_back(u, a);
		G2[u].emplace_back(v, b);
		G2[v].emplace_back(u, b);
	}
	vector<ll> dist1(n), dist2(n);
	dijkstra(s, G1, dist1);
	dijkstra(t, G2, dist2);
	vector<ll> ans(n);
	for (int i = n - 1; i >= 0; i--) {
		ll snuke = 1e15;
		snuke -= dist1[i];
		snuke -= dist2[i];
		ans[i] = snuke;
		if (i + 1 < n) ans[i] = max(ans[i], ans[i + 1]);
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 19012
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main(void) {
	int a, c = 0, d = 0;
	char h;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> h;
		if (h == 'D') {
			c--;
		}
		else {
			c++;
		}
		if (c > d)d = c;
	}
	cout << d << endl;
}

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

using namespace std;

void chmin(int& a, int b) { if (a > b) { a = b; } };

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; ++i) { cin >> s[i]; }

	auto cost = [&](char a, char b) -> int {
		return (a == '.' && b == '#');
	};

	vector<vector<int>> d(H, vector<int>(W, 1e8));
	d[0][0] = (s[0][0] == '#');
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (j + 1 < W) {
				chmin(d[i][j + 1], d[i][j] + cost(s[i][j], s[i][j + 1]));
			}
			if (i + 1 < H) {
				chmin(d[i + 1][j], d[i][j] + cost(s[i][j], s[i + 1][j]));
			}
		}
	}
	cout << d[H - 1][W - 1] << endl;

	return 0;
}


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

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

const int INF = 1e9;

const int N = 111;

int n,m; 
string a[N];

int dp[N][N];
void relax(int i, int j, int ni, int nj) {
    int cost = a[ni][nj] == '#' && a[i][j] == '.';
    dp[ni][nj] = min(dp[ni][nj], dp[i][j] + cost);
}

int main() {
    cin >> n >> m;
    forn(i,n) cin >> a[i];

    forn(i,n) forn(j,m) {
        if (i == 0 && j == 0) dp[i][j] = a[i][j] == '#';
        else {
            dp[i][j] = N*N;
            if (i) relax(i-1,j,i,j);
            if (j) relax(i,j-1,i,j);
        }
    }
    cout << dp[n-1][m-1];

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    LL a, b, c, d;
    cin >> a >> b >> c >> d;
    LL ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    printf("%lld\n", ans);
}


Measured memory_bytes: 3760
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=sc.nextInt();
        System.out.println(A<=C&&C<=B?"Yes":"No");
    }
}

Measured memory_bytes: 22996
#include<iostream>
#include<vector>
#include<algorithm>
#define INF -(1<<29)
#define F first
#define S second
#define T P
using namespace std;
typedef pair<int,int> P;
const int MAX_N = 1000010;
 
 bool cmp(const P& a,const P& b)
  {
    if(a.first == b.first)
      return a.second > b.second;
    return a.first < b.first;
  }
 
 
 
  int n;
  T dat[3*MAX_N-1];
  
  void init(int n_){
    n = 1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;i++)dat[i] = P(INF,INF);
  }
 
// kテァツ閉ェテ」ツつ?」ツ?ョテ・ツ?、(0-indexed)テ」ツつ誕テ」ツ?ォテ・ツ、ツ嘉ヲツ崢エ
  void update(int k,T a){
    k += n-1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = max(dat[k*2+1],dat[k*2+2],cmp);
    }
  }
  
// [a,b)テ」ツ?ョテヲツ慊?・ツ、ツァテ・ツ?、テ」ツつ津ヲツアツづ」ツつ?」ツつ?
  T query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return P(INF,INF);
    else if(a<=l && r<=b)return dat[k];
      
      T vl = query(a,b,k*2+1,l,(l+r)/2);
      T vr = query(a,b,k*2+2,(l+r)/2,r);
      return max(vl,vr,cmp);
  }
 
//nテ」ツ?ョテァツッツ?・ツ崢イテ」ツ?ァテ」ツδ淌」ツつケテ」ツ?療」ツ?ェテ」ツ??」ツつ暗」ツ??」ツ?ォテヲツ・ツオテ・ツ環崚」ツ?禿」ツ?」テ」ツ?。テ」ツつ津・ツ按ゥテァツ板ィ 
  T _query(int a,int b){
    return query(a,b,0,0,n);
  }
 
 
int main()
{
  int n,q;
  cin >> n >> q;
   
  init(n);
  P total[n+1];
  for(int i=0;i<=n;i++)
    total[i] = P(INF,INF);
  vector<P> vec;
  for(int i=0;i<q;i++)
    {
      int a,v;
      cin >> a >> v;
      if(total[a] == P(INF,INF))
    {
      vec.push_back(P(a,v));
      int index = vec.size()-1;
      total[a] = P(v,index);
      update(index,P(v,a));
    }
      else
    {
      total[a].first += v;
      update(total[a].second,P(total[a].first,a));
    }
      
      P p = _query(0,vec.size());
      cout << p.second << " " << p.first << endl;    
    }
 
  return 0;
}

Measured memory_bytes: 33352
using System;
using System.Linq;

namespace B___Checkpoints
{
    class Program
    {
        static void Main(string[] args)
        {
            var N_M = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = N_M[0], M = N_M[1];
            var aibi = Enumerable.Range(1, N).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
            var cidi = Enumerable.Range(1, M).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

            for (int n = 0; n < N; n++)
            {
                int index = 0, res = int.MaxValue;
                for (int m = 0; m < M; m++)
                {
                    if (res > Math.Abs(aibi[n][0] - cidi[m][0]) + Math.Abs(aibi[n][1] - cidi[m][1]))
                    {
                        res = Math.Min(res, Math.Abs(aibi[n][0] - cidi[m][0]) + Math.Abs(aibi[n][1] - cidi[m][1]));
                        index = m;
                    }
                }
                Console.WriteLine(index + 1);
            }
        }
    }
}


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

int a[100000][3], dp[100000][3];

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

	int n;
	cin >> n;
	for(int i=0; i<n; ++i)
		for(int j=0; j<3; ++j)
			cin >> a[i][j];
	for(int j=0; j<3; ++j)
		dp[0][j]=a[0][j];
	for(int i=1; i<n; ++i) {
		for(int j=0; j<3; ++j) {
			int mx=0;
			for(int k=0; k<3; ++k)
				if(k!=j)
					mx=max(dp[i-1][k], mx);
			dp[i][j]=mx+a[i][j];
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}


Measured memory_bytes: 2560
N = int(input())

cdic = {}
for i in range(N):
    si = input()
    if si not in cdic.keys():
        cdic[si] = 1
    else:
        cdic[si] += 1
        
spair = sorted(cdic.items(), key=lambda x:x[1], reverse=True)


# print(cdic)
# print(spair)


vmax = -1
maxes = []
for pair in spair:
    if pair[1] >= vmax:
        maxes.append(pair[0])
        vmax = pair[1]
    else:
        break
        
# print(maxes)
smaxes = sorted(maxes)
# print(smaxes)
# print('---')

for s in smaxes:
    print(s)


Measured memory_bytes: 47324
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub trait Monoid {
    fn mempty() -> Self;
    fn mappend(&self, other: &Self) -> Self;
}
pub struct SegmentTree<T>
where
    T: Monoid + Clone,
{
    size: usize,
    data: Vec<T>,
}
impl<T> SegmentTree<T>
where
    T: Monoid + Clone,
{
    pub fn new(size: usize) -> Self {
        let size = Self::normalize_data_size(size);
        let data = vec![T::mempty(); size * 2 - 1];
        Self { size, data }
    }
    pub fn from_slice(values: &[T]) -> Self {
        let mut st = SegmentTree::new(values.len());
        for (i, v) in values.into_iter().enumerate() {
            st.data[i + st.size - 1] = v.clone();
        }
        if st.size < 2 {
            return st;
        }
        for i in (0..=(st.size - 2)).rev() {
            st.data[i] = st.data[i * 2 + 1].mappend(&st.data[i * 2 + 2]);
        }
        st
    }
    /// 0-origin
    pub fn update(&mut self, i: usize, v: T) {
        let mut i = i + self.size - 1;
        self.data[i] = v;
        while i > 0 {
            i = (i - 1) / 2;
            self.data[i] = self.data[i * 2 + 1].mappend(&self.data[i * 2 + 2]);
        }
    }
    /// [a, b)
    /// 0-origin
    pub fn query(&self, a: usize, b: usize) -> T {
        self.execute_query(a, b, 0, 0, self.size)
    }
    fn normalize_data_size(size: usize) -> usize {
        let mut n = 1;
        while n < size {
            n *= 2;
        }
        n
    }
    fn execute_query(&self, a: usize, b: usize, i: usize, l: usize, r: usize) -> T {
        if r <= a || b <= l {
            return T::mempty();
        }
        if a <= l && r <= b {
            return self.data[i].clone();
        }
        let vl = self.execute_query(a, b, i * 2 + 1, l, (l + r) / 2);
        let vr = self.execute_query(a, b, i * 2 + 2, (l + r) / 2, r);
        vl.mappend(&vr)
    }
}

impl Monoid for usize {
    fn mempty() -> Self {
        0
    }
    fn mappend(&self, other: &Self) -> Self {
        *self.max(other)
    }
}

fn solve() {
    input! {
        n: usize, k: i64,
        av: [i64; n]
    };

    let max_a = 300000;
    let mut st: SegmentTree<usize> = SegmentTree::new(max_a + 1);
    let mut res = 0;
    for a in av {
        let l = (a - k).max(0) as usize;
        let r = (a + k).min(max_a as i64) as usize;
        let c = st.query(l, r + 1) + 1;
        if c > res {
            res = c;
        }
        st.update(a as usize, c);
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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


int main () {
  int64_t X, A, B;
  cin >> X >> A >> B;
  if (B - A <= 0) cout << "delicious" << endl;
  else if (B - A <= X) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}

Measured memory_bytes: 3556
# -*- coding: utf-8 -*-
"""
B - たてなが / Thin
https://atcoder.jp/contests/abc049/tasks/abc049_b

"""
import sys


def solve(H, W, C):
    ans = [['.']*(W) for _ in range(H*2)]
    for y, row in enumerate(C):
        for x, ch in enumerate(row):
            if ch == '*':
                ans[y*2][x] = '*'
                ans[y*2+1][x] = '*'
    return '\n'.join([''.join(r) for r in ans])


def main(args):
    H, W = map(int, input().split())
    C = [input() for _ in range(H)]
    ans = solve(H,  W, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 3188
# RGBの数列からから'R,G,B'を取り出す必要がある．
# RGBの組み合わせのなかから(r*g*b)の中から，例えば，Rを固定して，Rからの距離の絶対値が一致するようなものは
# iを固定して， j-i=k-j= l として j,kの位置で，i以外の２文字になっているかを確認する．
# i
from collections import deque
N=int(input())
S=input()
R=deque()
G=deque()
B=deque()
for i,s in enumerate(S):
    if s=='R':
        R.append(i)
    if s == 'G':
        G.append(i)
    if s == 'B':
        B.append(i)

rgb = len(R)*len(G)*len(B)
import bisect
# ワンホット表現にしてみる
R_one = [0 for _ in range(N+3)]
G_one = [0 for _ in range(N+3)]
B_one = [0 for _ in range(N+3)]

for r in R:
    R_one[r] = 1
for g in G:
    G_one[g] = 1
for b in B:
    B_one[b] = 1

for i in range(0,N):
    if i in R:
        lest1 = G_one
        lest2 = B_one
    elif i in G:
        lest1 = B_one
        lest2 = R_one
    else:
        lest1 = R_one
        lest2 = G_one
    max_j_width = int((N-1-i)/2)+1
    for j in range(1,max_j_width+1):
        if lest1[i+j]== lest2[i+2*j] == 1:
            rgb-=1
        elif lest2[i + j] == lest1[i + 2 * j] == 1:
            rgb-=1
print(rgb)









Measured memory_bytes: 9668
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

string S[30];

int d[30][30][30][30];
struct P {
	int x, y;
};

int tox[] = { 0,1,0,-1 };
int toy[] = { 1,0,-1,0 };
int main()
{
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < H; i++) { 
		for (int j = 0; j < W; j++) {
			d[i][j][i][j] = 1;
			if (S[i][j] != '#') {
				queue<P> Q;
				Q.push({ j,i });
				while (!Q.empty()) {
					P p = Q.front();
					Q.pop();
					//cout << i << " " << j << endl;
					for (int k = 0; k < 4; k++) {
						if (p.x + tox[k] < W && p.x + tox[k] >= 0 && p.y + toy[k] < H && p.y + toy[k] >= 0 && d[i][j][p.y + toy[k]][p.x + tox[k]] == 0 && S[p.y + toy[k]][p.x + tox[k]] == '.') {
							Q.push({ p.x + tox[k],p.y + toy[k] });
							d[i][j][p.y + toy[k]][p.x + tox[k]] = d[i][j][p.y][p.x] + 1;
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = 0; k < H; k++) {
				for (int l = 0; l < W; l++) {
					ans = max(ans, d[i][j][k][l]);
					/*cout << i << " " << j << " " << k << " " << l << " ";
					cout << d[i][j][k][l] << endl;*/
				}
			}
		}
	}
	cout << ans - 1 << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    Fast;
    long long t,n,m,i,j,k,x=0,y=0,z;
    cin>>n;
    long long a[n+5];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==0){
            if(a[i]%3!=0 && a[i]%5!=0){
                x=1;
            }
        }
    }
    if(x==1){
        cout<<"DENIED"<<endl;
    }
    else{
            cout<<"APPROVED"<<endl;
    }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> l(M,0);
    vector<ll> r(M,0);
    for(ll i=0;i<M;i++){
        cin>>l[i]>>r[i]
    ;}
    ll L=l[0];
    ll R=r[0];
    for(ll i=1;i<M;i++){
        L=max(L,l[i]);
        R=min(R,r[i]);
        if(L>R){
            cout<<0<<endl;
            return 0;
        }
    ;}
    cout<<R-L+1<<endl;
return 0;
}


Measured memory_bytes: 1792
s= input()
g = 'gp'*(len(s)//2)+'g'*(len(s)%2)
cnt = 0
for si,gi in zip(s,g):
    if si == gi:
        continue
    elif si =='g' and gi == 'p':
        cnt += 1
    else:
        cnt -= 1
print(cnt)


Measured memory_bytes: 9216
import string
alph = string.ascii_lowercase * 2
s = input()
k = int(input())

needed = 0
ind_list = []
for i in range(len(s)):
	ind_list.append(alph.index(s[i]))
	if ind_list[-1] != 0:
		needed += 26 - ind_list[-1]

if needed <= k:
	mod = (k - needed) % 26
	print("a" * (len(s) - 1) + alph[mod])
else:
	ans = []
	for i in range(len(s) - 1):
		if k == 0 or s[i] == "a":
			ans.append(s[i])
			continue
		if k >= 26 - ind_list[i]:
			ans.append("a")
			k -= 26 - ind_list[i]
		else:
			ans.append(s[i])

	if k == 0:
		ans.append(s[-1])
	else:
		ans.append(alph[(ind_list[-1] + k) % 26])

	print(*ans, sep="")

Measured memory_bytes: 8476
#include <stdio.h>
#include <string.h>

int main() {
  int number_n, i, count = 0;
  char str[16];
  scanf("%s", str);
  for(i = 0; i < strlen(str); i++) {
    if(str[i] == 'x') count++;
  }
  if(count >= 8) {
    printf("NO\n");
  } else {
    printf("YES\n");
  }
  return 0;
}


Measured memory_bytes: 128
N,M,R = gets.split.map(&:to_i)
Rs = gets.split.map(&:to_i).sort
inf = M*M*100000
ds = (0..N).map{ (0..N).map{ inf } }
M.times{
  a,b,c = gets.split.map(&:to_i)
  ds[a][b] = ds[b][a] = c
}

(1..N).each{ |k|
  (1..N).each{ |i|
    (1..N).each{ |j|
      v = ds[i][k] + ds[k][j]
      ds[i][j] = v if v < ds[i][j]
    } 
  }
}


ans = inf
Rs.permutation{ |rs|
  v = (1...rs.size).reduce(0){ |a,i| a + ds[rs[i-1]][rs[i]] }
  ans = v if v < ans
}
puts ans

Measured memory_bytes: 2300
#include<stdio.h>
#include<string.h>
int c,n,i,j,f[16][16][16][16],dp[16][16],x,y,fx,fy,tx,ty;
int main()
{
	scanf("%d",&c);
	for(;c--;)
	{
		memset(f,0,sizeof(f));
		memset(dp,0,sizeof(dp));
		scanf("%d%d%d",&x,&y,&n);
		for(i=0;i<n;i++,f[fy][fx][ty][tx]=f[ty][tx][fy][fx]=1)
			scanf("%d%d%d%d",&fx,&fy,&tx,&ty);
		dp[0][0]=1;
		for(i=1;i<=x;i++)
			dp[0][i]=f[0][i-1][0][i]?0:dp[0][i-1];
		for(i=1;i<=y;i++)
			dp[i][0]=f[i-1][0][i][0]?0:dp[i-1][0];
		for(i=1;i<=y;i++)
			for(j=1;j<=x;j++)
			{
				dp[i][j]+=f[i][j-1][i][j]?0:dp[i][j-1];
				dp[i][j]+=f[i-1][j][i][j]?0:dp[i-1][j];
			}
		if(!dp[y][x])
			puts("Miserable Hokusai!");
		else
			printf("%d\n",dp[y][x]);
	}
	return 0;
}

Measured memory_bytes: 876
#include <stdio.h>

int main() {
  int n, b, f, r, v;
  int i, j;
  
  int info[12][10];
  for (i = 0; i < 12; i++)
    for (j = 0; j < 10; j++)
      info[i][j] = 0;
  
  scanf("%d", &n); 
  for(i = 0; i < n; i++){
    scanf("%d%d%d%d", &b, &f, &r, &v);
    info[(b-1)*3+(f-1)][r-1] = info[(b-1)*3+(f-1)][r-1] + v;
  }

  for (i = 0; i < 12; i++){
    for (j = 0; j < 10; j++) {
      printf(" %d", info[i][j]);
    }
    if ((i+1) % 3 == 0 && i != 11) printf("\n####################");
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2064
unittest
{
	assert( [ "7 1 3 6 7", ".#..#.." ].parse.expand.solve == "Yes" );
	assert( [ "7 1 3 7 6", ".#..#.." ].parse.expand.solve == "No" );
	assert( [ "15 1 3 15 13", "...#.#...#.#..." ].parse.expand.solve == "Yes" );

	assert( [ "7 1 3 7 5", ".#.#..." ].parse.expand.solve == "No" );		// 追加ケース
	assert( [ "7 1 3 7 6", ".#.#..." ].parse.expand.solve == "Yes" );		// 追加ケース
	assert( [ "8 1 3 8 7", ".#...#.." ].parse.expand.solve == "Yes" );		// 追加ケース
	assert( [ "6 1 2 6 5", "...#.." ].parse.expand.solve == "Yes" );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nabcd = input.front.split.to!( long[] );
	input.popFront;
	auto s = input.front.to!( char[] );
	return tuple( nabcd[ 0 ], nabcd[ 1 ], nabcd[ 2 ], nabcd[ 3 ], nabcd[ 4 ], s );
}

auto solve( long n, long a, long b, long c, long d, char[] s )
{
	// 移動範囲内に飛び越せない二連岩があったらダメ
	foreach( g; s[ a .. max( c, d ) ].group )
	{
		if( g[ 0 ] == '#' && 2 <= g[ 1 ] ) return "No";
	}
	
	// すぬけ君がふぬけ君を飛び越える必要がなければイイ
	if( c < d ) return "Yes";
	
	// すぬけ君がふぬけ君を飛び越えるための三連スペースがあったらイイ
	foreach( g; s[ b - 2 .. d + 1 ].group )
	{
		if( g[ 0 ] == '.' && 3 <= g[ 1 ] ) return "Yes";
	}
	return "No";
}


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

using namespace std;

#define INF 1<<30
#define LINF 1ll<<60ll
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

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

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b<c){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

res = deque()
t = (N + 1) % 2

for i in range(N):
    if i % 2 == t:
        res.appendleft(A[i])
    else:
        res.append(A[i])

print(*res)


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

int main() {
  int N, X;
  cin >> N >> X;
  int L[N];
  for (int i = 0; i < N; i++) cin >> L[i];
  int D = 0, b = 1;
  while (true) {
    if (b == N + 1) break;
    else if (D + L[b-1] <= X) {
      D += L[b-1];
      b++;
    }
    else break;
  }
  cout << b << endl;
  return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
k = 50
grid = [["#"]*(2*k) for _ in range(k)] + [["."]*(2*k) for _ in range(k)]

for i in range(a-1):
    row = 2*(i//k)
    col = 2*(i % k)
    grid[row][col] = "."

for i in range(b-1):
    row = 2*(i//k) + k+1
    col = 2*(i % k)
    grid[row][col] = "#"

print(2*k, 2*k)
for i in range(2*k):
    s = "".join(grid[i])
    print(s)


Measured memory_bytes: 3188
S = input()
T = input()
N = len(S)
V = ["" for i in range(N)]
for i in range(N):
  for j in range(N):
    V[i] = V[i][:] + S[(i+j)%N]
flg = False
for i in range(N):
  if V[i] == T:
    flg = True
if flg:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fi   first
#define se   second
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 3e3 + 5;
string s, t;
int n, m;
int dp[N][N];

void input() {
	cin >> s >> t;
	n = s.size(); m = t.size();
	s = ' ' + s; t = ' ' + t;
}

void solve() {
	memset(dp, 0, sizeof dp);
	FOR(i, 1, n) FOR(j, 1, m) {
		if (s[i] == t[j]) {
			dp[i][j] = dp[i - 1][j - 1] + 1;
		} else {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	int a = n, b = m;
	vector <char> res;
	while (a > 0 && b > 0) {
		if (s[a] == t[b]) {
			res.push_back(s[a]);
			a--; b--;
		} else {
			if (dp[a - 1][b] > dp[a][b - 1]) a--; else b--;
		}
	}
	reverse(res.begin(), res.end());
	for (char v : res) cout << v;
}	

int main(int argc, char const *argv[])
{
  	ios_base::sync_with_stdio(0); cin.tie(0);

	input();
	solve();

	return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b;a>=c;a--)
#define ll long long 
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))
#define ctz(x) __builtin_ctz(x)
#define clz(x) __builtin_clz(x)
#define popcount(x) __builtin_popcount(x)
#define parity(x) __builtin_parity(x)

//=======binarysearch===========
int bs(vector<int>&a,int que){
 auto it=lower_bound(a.begin(),a.end(),que);
 if(*it==que){
    return it-a.begin();
 }
 return -1;
}
//========binarysearch=========


bool isprime(int x)
{
  if ( x == 2 ) return true;
  if ( x  < 2 ) return false;
  for ( int i = 2; i * i <= x; i++ )
    if ( x % i == 0 ) return false;


  if(x==0) return false;
  return true;
}


#define inf 1e9



int main(){


int a[4];

rep(i,0,2){
  cin>>a[i];
}

sort(a,a+3);

int sum=0;

rep(i,1,2){
  sum=sum+abs(a[i]-a[i-1]);
}

cout<<sum<<endl;


return 0;
}

Measured memory_bytes: 256
from collections import *
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
C=list(map(int,input().split()))
C.sort(reverse=True)
data=[[] for i in range(N+1)]
num=[-1 for i in range(N+1)]
num[1]=C[0]
for a,b in AB:
    data[a].append(b)
    data[b].append(a)
sumc=sum(C[1:])

stack=[1]
stack=deque(stack)
visited=set()
visited.add(1)
idx=1
while stack:
    a=stack.popleft()
    for p in data[a]:
        if not p in visited:
            visited.add(p)
            num[p]=C[idx]
            idx+=1
            stack.append(p)
print(sumc)
print(" ".join([str(num[i]) for i in range(1,N+1)]))


Measured memory_bytes: 50648
#include <stdlib.h>
#include <iostream>
using namespace std;

bool binary_search(int *array, int left, int right, int num);
void print_array(int *array, int size);
int main(){
	int s_num;
	int t_num;

	cin >> s_num;

	int* array_s = (int*)malloc(s_num * sizeof(int));

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

	cin >> t_num;

	int* array_t = (int*)malloc(t_num * sizeof(int));

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

	int result_size = 0;

	for(int i = 0; i < t_num; ++i){
		if(binary_search(array_s, 0, s_num, array_t[i])){
			++result_size;
		}
	}

	cout << result_size << endl;
	return 0;
}

bool binary_search(int *array, int left, int right, int num){
	if(left < right){
		int mid = (left + right) >> 1;
		if(array[mid] == num){
			return true;
		}else if (array[mid] < num){
			return binary_search(array, mid+1, right, num);
		}else{
			return binary_search(array, left,  mid,   num);
		}
	}
	return false;
}

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define tc ll t; cin >> t; while (t--)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define sz(c) (ll) c.size()
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(x,c) for(auto &x : c)
#define _for(i,a,n) for(ll i = a ; i < n ; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

int main() {
    godspeed;
    ll n; cin >> n;

    ll ans = 0;

    ans += 1000*(n/500);

    ans += 5*((n%500)/5);

    cout << ans;
}

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

int main(){
    //input
    string s;
    cin >> s;
    map<char,int> dic;

    for(char c : s){
        if(++dic[c] > 1){
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int n;cin >>n;
    V l(n);
    int sum=0;
    int mx=-1;
    for (int i = 0; i < n; ++i) {
        cin >>l[i];
        mx=max(mx,l[i]);
        sum+=l[i];
    }
    sum-=mx;
    if(mx<sum)puts("Yes");
    else puts("No");
}



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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int A, B;
  cin >> A >> B;
  int K;
  cin >> K;
  vector<int> vc;
  REP1(i, min(A, B)) {
    if (A % i == 0 && B % i == 0) vc.push_back(i);
  }
  reverse(ALL(vc));
  cout << vc[K - 1] << endl;
  return 0;
}

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

int main()
{
    int a, b, c;
    scanf("%d %d", &a, &b);
    if(a>0&&a<10&&b>0&&b<10)
        printf("%d", a * b);
    else
        printf("%d", -1);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
ll dp[3001][3001];
string a,b;
string ans;
ll lcs(ll idx1,ll idx2)
{
    if(idx1>=a.size() || idx2>=b.size()){
        return 0;
    }
    if(dp[idx1][idx2]!=-1){
        return dp[idx1][idx2];
    }
    ll p=0,q=0,r=0;
    if(a[idx1]==b[idx2]){
        p=1+lcs(idx1+1,idx2+1);
    }
    else{
        q=lcs(idx1+1,idx2);
        r=lcs(idx1,idx2+1);
    }
    return dp[idx1][idx2]=max(p,max(q,r));
}
void lcsprint(ll idx1,ll idx2)
{
    if(idx1==a.size()|| idx2==b.size()){
        return ;
    }
    if(a[idx1]==b[idx2]){
        ans+=a[idx1];
        lcsprint(idx1+1,idx2+1);
        return;
    }
    if(dp[idx1+1][idx2]>dp[idx1][idx2+1]){
        lcsprint(idx1+1,idx2);
        return;
    }
    lcsprint(idx1,idx2+1);
}
int main()
{
    FastIO
    reset(dp);
    cin>>a>>b;
    ll ans1=lcs(0,0);
    lcsprint(0,0);
    cout<<ans<<endl;
}


Measured memory_bytes: 70784
#include <stdio.h>
#include<string.h>


int main(void) {
 int n;
 scanf("%d",&n);
 long int a[n],sum=0;
 for(int i=0;i<n;i++)
 {
   scanf("%ld",&a[i]);
   if(i>0)
   {
     if(a[i-1]>a[i])
     {sum=sum+a[i-1]-a[i];
     a[i]=a[i-1];}
   }

 }
 printf("%ld\n",sum);
 
  
  return 0;
}

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

int a[200000],b[200000],n;

bool check(int m){
	for(int i=0;i<2*n-1;i++)
		b[i]=(a[i]>=m);
	for(int i=0;i<2*n-2;i++){
		if(b[i]==b[i+1])	continue;
		int j=i+1;
		while(j+1<2*n-1&&b[j+1]!=b[j])	j++;
		if((j-i)&1){
			for(int k=i+1;k<=i+(j-i)/2;k++)
				b[k]=b[i];
			for(int k=i+(j-i)/2+1;k<j;k++)
				b[k]=b[j];
		}
		else{
			for(int k=i+1;k<j;k++)
				b[k]=b[i];
		}
		i=j;
	}
	return b[n-1]==1;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<2*n-1;i++)
		cin>>a[i];
	int l=1,r=2*n-1;
	while(l<r){
		int mid=(l+r+1)>>1;
		if(check(mid))
			l=mid;
		else
			r=mid-1;
	}
	cout<<l<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll k, n; cin >> k >> n;
    vector<ll> a;
    rep(i, n){
        ll atemp; cin >> atemp;
        a.push_back(atemp);
    }

    a.push_back(a[0] + k);

    ll dmax = 0;
    rep(i, n){
        dmax = max(dmax, a[i + 1] - a[i]);
    }

    cout << k - dmax << endl;

    return 0;
}

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

int main() {
    string S, left="", right="", ci;
    int Q, ti, fi;
    int rev_num=0;

    cin >> S;
    cin >> Q;

    rep(i, Q) {
        cin >> ti;
        if (ti == 1) {
            rev_num++;
        } else {
            cin >> fi >> ci;
            if ((rev_num % 2 == 0) && (fi == 1)) left = ci + left;
            if ((rev_num % 2 == 0) && (fi == 2)) right = right + ci;
            if ((rev_num % 2 == 1) && (fi == 1)) right = right + ci;
            if ((rev_num % 2 == 1) && (fi == 2)) left = ci + left;
        }
    }

    S = left + S + right;
    if (rev_num % 2 == 1) reverse(S.begin(), S.end());
    cout << S << endl;

    return 0;
}



Measured memory_bytes: 1464
import bisect

N=int(raw_input())
A=sorted([int(x) for x in raw_input().split()])
Al=[0 for i in range(100001)]
K=[]
for a in A:
    Al[a]+=1
    if Al[a]>1:
        K.append(a)
ans=len(A)
while(len(K)>2):
    ans-=2
    al=K.pop(0)
    ar=K.pop(-1)
    Al[al]-=1
    Al[ar]-=1
if len(K)==2:
    al=K.pop(0)
    ar=K.pop(-1)
    if sum(Al[al:ar+1])==2:
        ans-=4
    else:
        ans-=2
elif len(K)==1:
    ans-=2
print ans


Measured memory_bytes: 11556
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a);i>int(b);--i)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define show(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl;
#define MOD 1000000007
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define SZ(x) ((int)(x).size())
#define sum(v,i) accumulate(all(v),i)
//#define int long long
using ll = long long;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }//最大公約数
int lcm(int a, int b) { return a * b / gcd(a, b); }	//最小公倍数
#define deg_to_rad(deg) (((deg)/360)*2*PI);
#define rad_to_deg(rad) (((rad)/2/PI)*360);
//template <typename... Args>void IN(Args& ... args) {cin >>args;IN(args...);return;} //まとめて入力　IN(a,b,c,d...)

void Main(){
	int n; cin >> n;
	string s, t; cin >> s >> t;
	rep(i, n) {
		cout << s[i] << t[i];
	}
}

signed main() {
	Main();

	return 0;
}


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

using namespace std;

int main()
{
    int N;
    char ch;
    string s;
    cin>>N>>s;
    for(int i=0;i<s.length();i++)
    {
        ch=((s[i]-'A')+N)%26+'A';
        cout<<ch;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,count4=0,count2=0;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
  	cin>>A.at(i);
  }
  for(int j=0;j<N;j++){
  	if(A.at(j)%4==0){
    	count4++;
        continue;
    }else if(A.at(j)%2==0){
    	count2++;
    }
  }
  if(count4>=N/2){
  	cout<<"Yes"<<endl;
    
  }else if(count2>=N-2*count4){
    cout<<"Yes"<<endl;
    
  }else{
  	cout<<"No"<<endl;
    
  }
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a<6) {
    cout << 0 << endl;
  }
  else if(a<13) {
    cout << b/2 << endl;
  }
  else {
    cout << b << endl;
  }
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
S = list(input())
T = list(input())

a, b = sorted([N, M])
while True:
	if b % a == 0:
		break
	else:
		a, b = b % a, a
GCM = abs(a)

LCM = int(N * M // GCM)
judge = "YES"
for i in range(GCM):
	if S[int(N // GCM) * i] != T[int(M // GCM) * i]:
		judge = "NO"
		print(-1)
		break
	else:
		pass

if judge == "YES":
	print(LCM)

Measured memory_bytes: 4628
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int min = int.Parse(input[0]);
        int max = int.Parse(input[1]);
        int w = 0;
        
        for(int i=min;i<=max;i++){
            int[] suji = new int[5];
            int temp = i;
            for(int j=0;j<5;j++){
                suji[j] = temp%10;
                temp /= 10;
            }
            if(suji[0] == suji[4] && suji[1] == suji[3]){
                w++;
            }
        }
        WriteLine(w);
    }
}

Measured memory_bytes: 15184
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#define N 100100
#define LOG 20

//head

int n;
int x[N];
int l;
int q;
int a, b;
int dd[LOG][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, n) cin >> x[i];
  cin >> l;
  rep(i, n) {
    dd[0][i] = upper_bound(x, x+n, x[i]+l)-x-1;
  }
  rep(j, LOG-1) rep(k, n) {
    int u = dd[j][k];
    dd[j+1][k] = dd[j][u];
  }
  cin >> q;
  while(q--) {
    cin >> a >> b;
    a--; b--;
    if(a > b) swap(a, b);
    int ans = 0;
    for(int i = LOG-1; i >= 0; i--) {
      if(dd[i][a] < b) {
        a = dd[i][a];
        ans += 1<<i;
      }
    }
    cout << ans+1 << '\n';
  }
}

Measured memory_bytes: 11820
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;


int main() {

    int C[3][3];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            int c;
            cin >> c;
            C[i][j] = c;
        }
    }

    for (int a1 = 0; a1 <= 100; a1++) {

        int b1 = C[0][0] - a1;
        int b2 = C[0][1] - a1;
        int b3 = C[0][2] - a1;
        int a2 = C[1][0] - b1;
        int a3 = C[2][0] - b1;

        int A[3] = {a1, a2, a3};
        int B[3] = {b1, b2, b3};

        bool ok = true;

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if ((A[i] + B[j]) != C[i][j]) {
                    ok = false;
                }
            }
        }

        if (ok) {
            cout << "Yes" << "\n";
            return 0;
        }
    }

    cout << "No" << "\n";

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod =1e9 + 7;


int main(){
  int n,m;
  cin >> n >> m;  
  vector<int>oks(n+1,true);
  for(int i = 0; i < m; i++){
    int a; 
    cin >> a;
    oks[a] = false;
  }

  vector<long long int> dp(n+1);
  dp[0] = 1;
  for(int now = 0; now < n; now++){
    for(int next= now+1; next<=min(n,now+2); next++){
      if(oks[next]){
        dp[next]+=dp[now];
        dp[next]%=mod;
      }
    }
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (b % a == 0) {
			System.out.println(a + b);
		} else {
			System.out.println(b - a);
		}
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>

using namespace std;

//void B_113()
int main()
{
  int N, T, A;
  cin >> N >> T >> A;

  int idx;
  float abs_min = abs(A - 600);
  for (int i = 0; i < N; ++i)
  {
    int H;
    cin >> H;
    
    float temp = T - H * 0.006;
    if (abs_min > fabs(A - temp))
    {
      abs_min = abs(A - temp);
      idx = i + 1;
    }
  }

  cout << idx << endl;
}


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

#define REP(i, n ,N) for(int i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;

int n;
int main(){
	while(cin >> n && n){
		if(n==1){
			int a;
			cin >> a;
			p(a);
			continue;
		}
		stack<int> op_num;
		int ans=0;
		int intend_level = 1;
		REP(i,0,n){
			string s;
			cin>>s;
			int now_len = s.size();
			if(intend_level <= now_len){
				char c = s.back();
				if(c=='+' || c=='*') intend_level++;
				op_num.push(c - '0');
			}else{
				vector<int> vt;
				while(intend_level > now_len){
					int c = op_num.top();
					op_num.pop();
					if(c!='+'-'0' && c!='*'-'0'){
						vt.push_back(c);
					}else{
						int sum = vt.back();
						vt.pop_back();
						intend_level--;
						if(c=='+'-'0'){
							for(auto v: vt){
								sum += v;
							}
						}else{
							for(auto v: vt){
								sum *= v;
							}
						}
						ans = sum;
						op_num.push(sum);
						vt.clear();
					}
				}
				char c = s.back();
				if(c=='+' || c=='*') intend_level++;
				op_num.push(c - '0');
			}

		}
		vector<int> vt;
		while(intend_level > 1){
			int c = op_num.top();
			op_num.pop();
			if(c!='+'-'0' && c!='*'-'0'){
				vt.push_back(c);
			}else{
				int sum = vt.back();
				vt.pop_back();
				intend_level--;
				if(c=='+'-'0'){
					for(auto v: vt){
						sum += v;
					}
				}else{
					for(auto v: vt){
						sum *= v;
					}
				}
				ans = sum;
				op_num.push(sum);
				vt.clear();
			}
		}
		p(ans);
	}
	return 0;
}


Measured memory_bytes: 3112
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n): 
    s = s + a[i] 

e = s * s 

ss = 0
for i in range(n): 
    ss += a[i] * a[i] 
p =  (e - ss) // 2
print(p % (10**9 + 7))

Measured memory_bytes: 31436
def main():
    n = int(input())
    nl = 0
    yokei = 0
    yokei_pre = 0
    while yokei < n:
        nl += 1
        yokei_pre = yokei
        yokei += 26 ** nl

    n -= yokei_pre
    n -= 1
    c = [0] * nl
    for i1 in range(1, nl + 1):
        r = n % 26
        c[-i1] = r
        n = n // 26
    cs = []
    for ce in c:
        ce += 97
        cec = chr(ce)
        cs.append(cec)
    print("".join(cs))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62008