akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ABC125B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            int[] V = new int[N];
            int[] C = new int[N];

            var line1 = Console.ReadLine().Split(' ').ToArray();
            var line2 = Console.ReadLine().Split(' ').ToArray();

            for(var i = 0; i < N; i++)
            {
                V[i] = int.Parse(line1[i]);
                C[i] = int.Parse(line2[i]);
            }

            int sum = 0;

            for(var i = 0; i < N; i++)
            {
                int A = V[i] - C[i];
                if(A > 0)
                {
                    sum += A;
                }
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    int check[101];
    for(int i = 0; i < 101; i++) check[i] = 0;
    int count = 0;
    for(int i = 0; i < N; i++){
        int d;
        cin >> d;
        if(check[d] == 0) count++;
        check[d] = 1;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
//
//  abc061d.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/11/13.
//

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>

#define MAX 2010
#define INF (-3000000000000)

using namespace std;

typedef long long ll;

int main()
{
    int n,m;
    cin>>n>>m;
    int a[MAX],b[MAX];
    ll c[MAX];
    for(int i=0;i<m;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
    }
    ll max[MAX];
    
    for(int i=0;i<n;i++) max[i]=INF;
    max[0]=0;
    
    bool flag=false;
    
    for(int i=0;i<2*n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(max[a[j]]!=INF&&max[a[j]]+c[j]>max[b[j]])
            {
                max[b[j]]=max[a[j]]+c[j];
                if(b[j]==n-1&&i>=n) flag=true;
            }
        }
    }
    
    if(flag) cout<<"inf"<<endl;
    else     cout<<max[n-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 256
a = input()
N = int(a)
A = list(map(int,input().split()))
A.sort()

x = A[N-1]

for i in range(1,(N-2)//2+1):
    x = x + 2*A[N-1-i]
if (N-2) % 2 == 1:
    x = x + A[N-2-(N-2)//2]

print(x)


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

int main(){
    long a;
    cin >> a;
    long b;
    cin >> b;
    long c;
    cin >> c;
    long d;
    d = a - c;
    if(d < 0){
        b += d;
        if(b < 0)b = 0;
        d = 0;
    }
    cout << d << endl;
    cout << b << endl;
    return 0;
}

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

int main()
{
  char a;
  cin >> a;
  map<char, char> b;
  b.insert(pair<char, char>('A', 'T')); 
  b.insert(pair<char, char>('T', 'A'));
  b.insert(pair<char, char>('G', 'C'));
  b.insert(pair<char, char>('C', 'G'));
  cout << b[a] << endl;
  return 0;
}

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

namespace ABC109_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var words = new string[n];
            var hash = new HashSet<string>(); 
            for(var i = 0;i < n;i++){
                words[i] = Console.ReadLine();
                hash.Add(words[i]);
            }

            if(hash.Count < n){
                Console.WriteLine("No");
                return;
            }

            for(var i = 1;i < n;i++){
                if(words[i - 1][words[i - 1].Length - 1] != words[i][0]){
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");

            



        }
    }
}


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

void solve(){
	string a,b;
	cin >> a >> b;
	int dp[1001][1001];
	memset(dp,0,sizeof(dp));
	for(int i=0;i<=a.size();i++){
		for(int j=0;j<=b.size();j++){
			if(i > 0)
				dp[i][j] = max(dp[i][j],dp[i-1][j]);
			if(j > 0)
				dp[i][j] = max(dp[i][j],dp[i][j-1]);
			if(i > 0 && j > 0)
				dp[i][j] = max(dp[i][j],dp[i-1][j-1] + (a[i-1] == b[j-1] ? 1 : 0));
		}
	}
	cout << dp[a.size()][b.size()] << endl;
}
int main(void) {
	int q;
	cin >> q;
	for(int i=0;i<q;i++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 7032
Q = gets.to_i
require 'prime'
require 'pp'

def debug *objs
  PP.pp *objs, STDERR
end
prime_map = {}
target_map = Hash.new(0)
Prime.each(10**5).each do |pri|
  prime_map[pri] = true
  if prime_map[(pri+1)/2]
    target_map[pri] = 1
  end
end

counts = Array.new(10**5+1,0)
1.upto(10**5).each do |i|
  counts[i] = counts[i-1] + target_map[i]
end

debug counts[0,10]

Q.times do |i|
  l, r = gets.split(' ').map(&:to_i)
  puts counts[r] - counts[l-1]
end

Measured memory_bytes: 4732
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int, int>a, pair<int, int>b) {
	if (a.first == b.first) {
		return a.second > b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {
	int n, l;
	int ans = 0;
	cin >> n >> l;
	//lからl+n-1までの和を求める
	ans = n * (l + l + n - 1) / 2;
	if (l < 0) {
		if (n + l - 1 < 0) {
			ans -= n + l - 1;
		}
	}
	else {
		ans -= l;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    //freopen("Inp.txt","r", stdin);
    //freopen("Out.txt","w", stdout);

    int n,k; cin >> n >> k;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector <int> b(n);
    b[0]=0;
    b[1]=abs(a[1]-a[0]);
    for (int i = 2; i < n; i++)
        for (int j = 1; j <=min(i,k); j++)
        if (j == 1)
            b[i] = b[i-1] + abs(a[i]-a[i-1]);
        else
            b[i] = min(b[i-j] + abs(a[i]-a[i-j]),b[i]);
    cout << b[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int k;
    char s[106];
    cin>>k>>s;
    if (strlen(s)>k) {
        s[k]='.';
        s[k+1]='.';
        s[k+2]='.';
        s[k+3]='\0';
    }
    cout << s << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw27(10,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

//a,b x
int main(){
	string s; cin>>s;
	ll A=0,B=0,C=0;
	rep(i,s.sz){
		if(s[i]=='a') A++;
		else if(s[i]=='b') B++;
		else C++;
	}
	if(maxx(A,B,C)-minn(A,B,C)<=1) cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;
int lcs(string x, string y){
    int c[N+1][N+1];
    int m = x.size();
    int n = y.size();
    int maxl = 0;
    x = ' ' + x; //x[0]
    y = ' ' + y; //y[0]
    for(int i = 0; i <= m; i++) c[i][0] = 0;
    for(int j = 1; j <= n; j++) c[0][j] = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(x[i] == y[j]){
                c[i][j] = c[i-1][j-1] + 1;
            } else {
                c[i][j] = max(c[i-1][j], c[i][j-1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
    return maxl;
}
int main(){
    string s1, s2;
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}


Measured memory_bytes: 7120
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool is_palindrome(string str){
  string rstr = str;
  reverse(str.begin(), str.end());

  return rstr == str;
}

int main(){
  int A, B, ans = 0;
  cin >> A >> B;

  for (int i = A; i <= B; i++){
    if (is_palindrome(to_string(i))) ans++;
  }
  
  printf("%d\n", ans);
}


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

using namespace std;


map<string,int>mp;
int main()
{
    int n;
    cin >> n;
    int mx = 0;
    for(int i = 1;i <= n;i++){
        string str;
        cin >> str;
        mp[str]++;
        mx = max(mx,mp[str]);
    }
    set<string>st;
    for(auto x : mp){
        if(x.second == mx)st.insert(x.first);
    }
    for(auto x : st)cout << x << "\n";


}


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

int main() {
  int N;
  cin >> N;
  int answer;
  for (int i=0; i<9; i++) {
    if (111*i<N && N<=111*(i+1)) {
      answer = 111*(i+1);
      break;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char a,b;
	while (scanf("%c %c", &a, &b) != EOF)
	{
		getchar();
	//	printf("%c,%c\n", a, b);
		if (a == 'H')
		{
			if (b == 'H')
				printf("H\n");
			else if (b == 'D')
				printf("D\n");
		}
		else if (a == 'D')
		{
			if (b == 'H')
				printf("D\n");
			else if (b == 'D')
				printf("H\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
local n=io.read("n")
for i=1,3500 do
    for j=1,3500 do
        local a=n*i*j
        local b=(4*i*j-n*j-n*i)
        if b>0 and a%b==0 then
            local k=math.floor(a/b)
            print(i.." "..j.." "..k)
            os.exit()
        end
    end
end

Measured memory_bytes: 2796
import math
while True:
    n = int(input())
    if n == 0:
        break

    s = [int(s) for s in input().split()]
    ave = sum(s) / n
    a = 0
    for N in s:
        a += (N - ave)**2
    
    a = math.sqrt((a / n))
    print(a)

Measured memory_bytes: 7796
#include<cstdio>
#include<cstring>
#define LL long long
#define ll LL
#define N 1200000
#define INF 0x3f3f3f3f3f3f3f3f
LL n,m,x,y,ans,mn1,mn2,a[N],seg[2][N],seg0[2][N],seg1[2][N],tag[2][N];
 
ll min(ll x,ll y){ return x<y?x:y; }
ll max(ll x,ll y){ return x>y?x:y; }
ll abs(ll x){ return x>0?x:-x; }
void add(LL op,LL k){
	seg[op][1]+=k; seg0[op][1]+=k; seg1[op][1]+=k; tag[op][1]+=k;
}
 
void pushdown(LL op,LL x){
	tag[op][x<<1]+=tag[op][x]; tag[op][x<<1|1]+=tag[op][x];
	seg[op][x<<1]=min(INF,seg[op][x<<1]+tag[op][x]);
	seg0[op][x<<1]=min(INF,seg0[op][x<<1]+tag[op][x]);
	seg1[op][x<<1]=min(INF,seg1[op][x<<1]+tag[op][x]);
	seg[op][x<<1|1]=min(INF,seg[op][x<<1|1]+tag[op][x]);
	seg0[op][x<<1|1]=min(INF,seg0[op][x<<1|1]+tag[op][x]);
	seg1[op][x<<1|1]=min(INF,seg1[op][x<<1|1]+tag[op][x]);
	tag[op][x]=0;
}
 
void mdf(LL op,LL x,LL l,LL r,LL t,LL k){
	if (l==r){
		if (seg[op][x]>k){seg[op][x]=k; seg0[op][x]=k-t; seg1[op][x]=k+t;}
		return;
	}
	pushdown(op,x);
	LL mid=(l+r)>>1;
	if (t<=mid) mdf(op,x<<1,l,mid,t,k);
	if (t>mid) mdf(op,x<<1|1,mid+1,r,t,k);
	seg[op][x]=min(seg[op][x<<1],seg[op][x<<1|1]);
	seg0[op][x]=min(seg0[op][x<<1],seg0[op][x<<1|1]);
	seg1[op][x]=min(seg1[op][x<<1],seg1[op][x<<1|1]);
}
		
LL qry1(LL op,LL x,LL l,LL r,LL L,LL R){
	if (l>=L && r<=R){
		return seg0[op][x];
	}
	LL mid=(l+r)>>1,tmp=INF;
	pushdown(op,x);
	if (L<=mid) tmp=min(tmp,qry1(op,x<<1,l,mid,L,R));
	if (R>mid) tmp=min(tmp,qry1(op,x<<1|1,mid+1,r,L,R));
	return tmp;
}
 
LL qry2(LL op,LL x,LL l,LL r,LL L,LL R){
	if (l>=L && r<=R){
		return seg1[op][x];
	}
	LL mid=(l+r)>>1,tmp=INF;
	pushdown(op,x);
	if (L<=mid) tmp=min(tmp,qry2(op,x<<1,l,mid,L,R));
	if (R>mid) tmp=min(tmp,qry2(op,x<<1|1,mid+1,r,L,R));
	return tmp;
}
 
int main(){
	scanf("%lld%lld%lld%lld",&n,&m,&x,&y);
	memset(seg,0x3f,sizeof seg);
	memset(seg0,0x3f,sizeof seg0);
	memset(seg1,0x3f,sizeof seg1);
	mdf(0,1,1,n,x,0); mdf(1,1,1,n,y,0);
	for (LL i=1;i<=m;i++){
		scanf("%lld",&a[i]);
		mn1=mn2=INF;
		mn1=qry1(0,1,1,n,1,a[i])+a[i];
		mn1=min(mn1,qry2(0,1,1,n,a[i],n)-a[i]);
		mn2=qry1(1,1,1,n,1,a[i])+a[i];
		mn2=min(mn2,qry2(1,1,1,n,a[i],n)-a[i]);
		add(0,abs(a[i]-(i==1?y:a[i-1])));
		add(1,abs(a[i]-(i==1?x:a[i-1])));
		mdf(0,1,1,n,i==1?x:a[i-1],mn2); mdf(1,1,1,n,i==1?y:a[i-1],mn1);
	}
	printf("%lld\n",min(seg[0][1]+tag[0][1],seg[1][1]+tag[1][1]));
	
	return 0;
}

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

int main() {
  int N, ans, count=0;
  cin >> N;
  vector<int> data(N);
  for(int i=0; i<N; i++){
  	cin >> data.at(i);
  	if(data.at(i) != i+1){count++;}
  }
  if(count == 0 || count == 2){
  	cout << "YES" << endl;  	
  } else {
  	cout << "NO" << endl;  	  	
  }

  return 0;
}  

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vs = vector<string>;
using ii = vector<vector<long long>>;
int main() {
    ll n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    bool aaaaa = true;
    if (n == 1) {
        cout << 0 << endl;
    }
    else {
        for (int i = 0; i < n - 1; i++) {
            if (a[i] != a[i + 1]) {
                aaaaa = false;
            }
        }
        if (aaaaa) {
            cout << 0 << endl;
        }
        else {
            sort(a.begin(), a.end());
            vl count(abs(a[0] - a[n - 1]), 0);
            ll ans = 0;
            for (int j = 0; j < abs(a[0] - a[n - 1]); j++) {
                for (int i = 0; i < n; i++) {
                    ans += pow(abs(j - a[i]), 2);
                    if (i == n - 1) {
                        count[j] = ans;
                        ans = 0;
                    }
                }
            }
            sort(count.begin(), count.end());
            cout << count[0] << endl;
        }
    }
}

Measured memory_bytes: 3600
#include <iostream>
#include <queue>
#include <vector>

#define MAX_NODE 100
#define INF 1000000000

using namespace std;

int d[MAX_NODE];
vector<int> adj[MAX_NODE];

void bfs(int n, int start) {
	queue<int> que;

	for (int i = 0; i < n; i++)
		d[i] = (i == start ? 0 : INF);

	que.push(start);
	while(!que.empty()) {
		int from = que.front();
		que.pop();

		for (int i = 0; i < adj[from].size(); i++) {
			int to = adj[from][i];
			if (d[to] == INF) {
				d[to] = d[from] + 1;
				que.push(to);
			}
		}
	}
}

int main() {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		u--;
		while (k--) {
			int v;
			cin >> v;
			v--;
			adj[u].push_back(v);
		}
	}

	bfs(n, 0);

	for (int i = 0; i < n; i++)
		if (d[i] != INF)
			cout << i + 1 << " " << d[i] << endl;
		else
			cout << i + 1 << " -1" << endl;

	return 0;
}

Measured memory_bytes: 1228
/**
 *    author:  FromDihPout
 *    created: 2020-06-21
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, x;
    cin >> n >> x;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        long long diff = min(a[i] + a[i - 1] - x, a[i]);
        if (diff > 0) {
            a[i] -= diff;
            ans += diff;
        }
        diff = a[i] + a[i - 1] - x;
        if (diff > 0) {
            a[i - 1] -= diff;
            ans += diff;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    ll i; ll j;
    ll h[n]; ll temp;
    for(i=0;i<n;i++)
    cin>>h[i];
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    {
        temp=dp[i-1]+abs(h[i]-h[i-1]);
        for(j=1;j<=k;j++)
        {
            if((i-j)>=0)
            temp=min(temp,dp[i-j]+abs(h[i]-h[i-j]));
        }
        dp[i]=temp;
    }
    cout<<dp[n-1];
    return 0;
    
}

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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		String s = fs.next();
		int q = fs.nextInt();
		int k = 0;//0なら先頭
		StringBuilder fsb = new StringBuilder();
		StringBuilder bsb = new StringBuilder();
				
		for(int i=0;i<q;i++) {
			int t = fs.nextInt();
			if(t==1) {
				k = 1-k;
			}
			else {
				int f = fs.nextInt()-1;
				char c = fs.next().charAt(0);
				
				if(k==1)f = 1-f;
				
				if(f==0) {//先頭につける
					//s = c + s;
					fsb.append(c);
				}
				else {
					//s = s + c;
					bsb.append(c);
				}
				
			}
		}
		if(k==0) {
			System.out.print(fsb.reverse().toString());
			System.out.print(s);
			System.out.println(bsb.toString());
		}
		else {
			StringBuffer str = new StringBuffer(s);
			String ans = str.reverse().toString();
			System.out.print(bsb.reverse().toString());
			System.out.print(ans);
			System.out.println(fsb.toString());

		}
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 46472
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  int N;
  long double ans;
  cin >> N ;
  vector<long double> num(N);
  for (int i = 0; i < N; i++) {
    cin >> num[i];
  }
  sort(num.begin(),num.end());
  ans = num[0];
  for(int j =0; j < N; j++){
    ans = (ans + num[j]) / 2;
  }  
  cout << ans <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	int H[1000], W[1000];
	int i,j,h,w;

	for(i=0;;i++){
		scanf("%d %d", &H[i], &W[i]);
		if(H[i]==0 && W[i]==0) break;
	}

	for(j=0;j<i;j++){
		for(h=0;h<H[j];h++){
			for(w=0;w<W[j];w++){
				if((h+w)%2==0){
					printf("#");
				} else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");

	}


	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <string>
#include <math.h>

using namespace std;
 
int main() {
	string ans;
	string str;
	cin >> str;
	ans = "Yes";
	
	size_t size = str.length();
	
	for(int i = 0; i<size; i++){
		if(i%2==0){
			if(str[i] == 'R' || str[i] == 'U' || str[i] == 'D'){
			}else{
				ans = "No";
				break;
			}
		}else{
			if(str[i] == 'L' || str[i] == 'U' || str[i] == 'D'){
			}else{
				ans = "No";
				break;
			}
		}
	}
	
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
import bisect
N=int(input())
L=list(map(int,input().split()))
L.sort()
cnt=0
for i in range(N-2):
    for j in range(i+1,N-1):
        total=L[i]+L[j]
        point=bisect.bisect_left(L,total)
        cnt+=(point-j-1)
print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mod 1000000007



int main()
{
	ll n;
	cin>>n;
	if(n%1000==0)
		cout<<0;
	else
		cout<<1000-n%1000;

  return 0;
	
}





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

int main() {
  vector<int> data(5);
  for(int i = 0; i < 5; i++)
  {
    cin >> data[i];
    if(data[i] == 0)
    {
      cout << i + 1 << endl;
    }
  }
}


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

int main(){
	int N,K,Q;
	cin >> N >> K >> Q;
	vector<int> A(N,0);
	for(int i=0;i<Q;i++){
		int a;
		cin >> a;
		a--;
		A[a]++;
	}
	for(int i=0;i<N;i++){
		if(K-(Q-A[i])>0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

int main() {
  ll n,m,count=0,sum=0;
  cin>>n>>m;
  vector<pair<ll,ll>> p(n);
  for(int i=0; i<n; i++){
    ll x,y;
    cin>>x>>y;
    p[i] = make_pair(x,y);
  }
  sort(p.begin(),p.end());
  for(int i=0; i<n; i++){
    for(;;){
    	count++;
    	p[i].second--;
    	sum+=p[i].first;
      	if(count==m) {
          cout<<sum;
          return 0;
        }
    	if(p[i].second == 0) break;
    }
  }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
    ll a,b,c;
    cin >> a>>b>>c;
    if(a%2==0||b%2==0||c%2==0){
        cout << 0 <<endl;
        return 0;
    }
    cout << min(a*b,min(b*c,a*c)) <<endl;

}

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

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = b + c - a;
  if (ans <= 0) cout << 0 << endl;
  else cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


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

int a[100010];
int cost[100010];

int solve(int n)
{
    if(n == 1){
        return 0;
    }
    else if(n == 2){
        return abs(a[1] - a[2]);
    }
    else if(cost[n] != -1){
        return cost[n];
    }
    else{
        return cost[n] = min(solve(n-1) + abs(a[n-1] - a[n]),solve(n-2) + abs(a[n-2] - a[n]));
    }
}

int main(){
    int n,i;
    cin >> n;
    
    for(i=1;i<=n;i++){
        cin >> a[i];
        cost[i] = -1;
    }
    cout << solve(n);
}





Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
using namespace std;
char seq[15];
int n;
void dfs(int st,int p)
{
	if(st==n+1)
	{
		printf("%s\n",seq+1);
		return;
	}
	for(int i=1;i<=p;i++)
	{
		seq[st]='a'+i-1;
		dfs(st+1,p);
	}
	seq[st]='a'+p;
	dfs(st+1,p+1);
}
int main()
{
	scanf("%d",&n);
	dfs(1,0);
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll n, r;
    ll rate;
    cin >> n >> r;


    if(n<10) rate =  r + 100 * (10 - n);
    else rate = r;

    cout << rate << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    stop
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> P;
vector<P> v[110];
bool vis[110][110];
priority_queue<P,vector<P>,greater<P> >Q;
int n,m;
void DKT(int x){
	int t[110];
	for(int i=0;i<n;i++)t[i]=1145141919;
	Q.push(make_pair(0,x+100000));
	while(!Q.empty()){
		int y=Q.top().first,z=Q.top().second,r=z/200;
		Q.pop();z%=200;
		//頂点zがコストyでいける
		if(t[z]<y)continue;
		if(r!=500)vis[r][z]=true,vis[z][r]=true;
		t[z]=y;
		for(int i=0;i<v[z].size();i++){
			Q.push(make_pair(y+v[z][i].first,v[z][i].second+z*200));
		}
	}
}

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b,c;cin>>a>>b>>c;a--,b--;
		v[a].push_back(make_pair(c,b));
		v[b].push_back(make_pair(c,a));
	}
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)vis[i][j]=0;
	for(int i=0;i<n;i++)DKT(i);
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<v[i].size();j++){
			if(i<v[i][j].second)continue;
			if(vis[i][v[i][j].second]==false)ans++;
		}
	}cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int board[3][3];
    rep(i, 3) rep(j, 3) cin >> board[i][j];
    int N;
    cin >> N;
    int tmp;
    set<int> b;
    rep(i, N) {
        cin >> tmp;
        b.insert(tmp);
    }
    rep(i, 3) rep(j, 3) {
        board[i][j] = (b.find(board[i][j]) != b.end()) ? 1 : 0;
    }
    rep(i, 3) {
        tmp = board[i][0] + board[i][1] + board[i][2];
        if (tmp == 3) {
            cout << "Yes" << endl;
            exit(0);
        }
        tmp = board[0][i] + board[1][i] + board[2][i];
        if (tmp == 3) {
            cout << "Yes" << endl;
            exit(0);
        }
    }
    if (board[0][0] + board[1][1] + board[2][2] == 3 || board[0][2] + board[1][1] + board[2][0] == 3) {
        cout << "Yes" << endl;
        exit(0);
    }
    cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
using namespace  std;

void fnDictionary(set<string>& rsesKey, vector<string>& rvsFnd)
{
  int nCmdCnt;
  cin >> nCmdCnt;

  for (int i = 0; i < nCmdCnt; i++)
  {
    string sCmd;
    string sKey;
    cin >> sCmd >> sKey;

    if (sCmd[0] == 'i')
      rsesKey.insert(sKey);
    else if (sCmd[0] == 'f')
    {
      auto itsesKey = rsesKey.find(sKey);
      if (itsesKey != end(rsesKey))
        rvsFnd.push_back("yes");
      else
        rvsFnd.push_back("no");
    }
  }
}

void fnResult(const vector<string>& cnrvsFnd)
{
  for (int i = 0; i < cnrvsFnd.size(); i++)
    cout << cnrvsFnd[i] << endl;
}

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

  set<string> sesKey;
  vector<string> vsFnd;

  fnDictionary(sesKey, vsFnd);
  fnResult(vsFnd);
  
  return 0;
}

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

int main(){
    int abc[3];
    cin >> abc[0] >> abc[1] >> abc[2];
    sort(abc, abc+3);
    if(abc[0] == 5 && abc[1] == 5 && abc[2] == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
def main():

    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    d = {'r': R, 's': S, 'p': P}
    opp = {'r': 'p', 's': 'r', 'p': 's'}

    ans = 0
    prev = ["" for _ in range(K)]
    for i in range(N):
        c = T[i]
        if opp[c] == prev[i%K]:
            prev[i%K] = ""
        else:
            ans += d[opp[c]]
            prev[i % K] = opp[c]
        # print(prev)

    return ans

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 44528
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3030;

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (auto& e : a) cin >> e;
    
    long long dp[MAX_N][MAX_N] = {};
    for (int s = 1; s <= n; s++) for (int l = 0; l < n; l++) {
        int r = l + s;
        if (n < r) continue;
        if ((n-(r-l)) % 2 == 0) {
            dp[l][r] = max(dp[l+1][r]+a[l], dp[l][r-1]+a[r-1]);
        } else {
            dp[l][r] = min(dp[l+1][r]-a[l], dp[l][r-1]-a[r-1]);
        }
    }
    
    cout << dp[0][n] << endl;
    return 0;
}

Measured memory_bytes: 71936
import numpy as np


n, m = (int(x) for x in input().split())
a = [int(y) for y in input().split()]

total = np.sum(a)
criteria = total / (4 * m)

count = 0
for i in range(n):
    if a[i] >= criteria:
        count += 1

print("No" if count < m else "Yes")


Measured memory_bytes: 12392
N = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
f1, f2, f3, ans = 0, 0, sum(a2), 0
for i in range(N):
    f1 += a1[i]
    sub = f1 + f3 - f2
    ans = max(sub, ans)
    f2 += a2[i]
print(ans)

Measured memory_bytes: 38256
n = int(input())
an = []
for i in range(n):
    an.append(int(input()))

import numpy as np
an = np.array(an)
_an = an.argsort()[::-1]
_max = np.max(an[_an[0]])
_max_next = np.max(an[_an[1]])
an[an < _max] = _max
an[_an[0]] = _max_next
an = an.astype("str")
print("\n".join(list(an)))

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

int main()
{
  int D,N ;
  cin>>D>>N ;
  
  int sum=1 ;
  for(int i=0;i<D;i++) sum*=100 ;
  
  if(N<=99) cout<<sum*N<<endl ;
  else cout<<sum*101<<endl ;
  
  return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int sa[100002], sb[100002], ta[100002], tb[100002];

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    for(int i = 1; i <= n; i++){
        sa[i] = sa[i - 1], sb[i] = sb[i - 1];
        if(s[i - 1] == 'A') sa[i]++;
        else sb[i]++;
    }
    for(int i = 1; i <= m; i++){
        ta[i] = ta[i - 1], tb[i] = tb[i - 1];
        if(t[i - 1] == 'A') ta[i]++;
        else tb[i]++;
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if((((sa[b] - sa[a - 1]) - (sb[b] - sb[a - 1])) - ((ta[d] - ta[c - 1]) - (tb[d] - tb[c - 1]))) % 3 == 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

vector<string>vec;
map<char, int>alpha;
int n;
char al[] = {"MARCH"};

long long dfs(int now, int time, long long ans) {
  if ( time == 3 ) {
    return ans;
  } else if ( now >= 5 ) {
    return 0;
  }

  return dfs(now + 1, time + 1, ans * alpha[al[now]]) + dfs(now + 1, time, ans);
}

int main() {
  string s;
  int kind = 0;
  char visit[3] = {};
  
  cin >> n;
  for ( int i = 0; i < n; i++) {
    cin >> s;
    if ( s[0] == 'M' || s[0] == 'A' || s[0] == 'C' || s[0] == 'H' || s[0]  == 'R' ) {
      if ( alpha[s[0]] == 0 ) {
        kind++;
      }
    }
    alpha[s[0]]++;
  }

  if ( kind >= 3 ) {
    cout << dfs(0, 0, 1) << endl;
  } else {
    cout << 0 << endl;
  }

//  cout << kind << endl;

  return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    ll cnt = 0;
    ll ma = inf;
    for(ll i=0;i<n;i++){
	if( ma > a[i] ){
	    cnt++;
	    ma = a[i];
	}
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1792
# ABC105 C - Base -2 Number
# 2019/10/28

def main():
    n = int(input())

    a = []
    while n!= 0:
        r = n % 2
#         print('r={0}, n={1}'.format(r,n))
        
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
        
    if a == []:
        a.append(0)
        
    a.reverse()
#     print(a)
    
    print("".join(map(str,a)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int n;
vector<ll> l;

int main()
{
  ll ans=0;

  cin >> n;
  l.resize(n);
  for (int i=0; i<n; i++) {
    cin >> l[i];
  }
  for (int i=0; i<n-2; i++) {
    for (int j=i+1; j<n-1; j++) {
      for (int k=j+1; k<n; k++) {
//printf("[%d %d %d](%lld %lld %lld) ",  i+1, j+1, k+1, l[i], l[j], l[k]);
        if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
        if (l[i] < l[j]+l[k] && l[j] < l[i]+l[k] && l[k] < l[i]+l[j]) ans++;
//printf("%lld\n", ans);
      }
    }
  }

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


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

#define LEN 100005
using namespace std;
	int head, tail, n;
typedef struct pp_ {
	string ps;
	int time;
} pp;
vector<pp>Q(LEN); // 配列を準備する
void enqueue(pp x) {
	Q.at(tail) = x;
	tail = (tail + 1) % LEN;
}
pp dequeue() {
	pp x = Q.at(head);
	head = (head + 1) % LEN;
	return x;
}
int main()
{
	int q; // クオンタム
	int x; // 各処理時間
	string s; // 名前
	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		cin >> s >> x;
		Q.at(i).ps = s;
		Q.at(i).time = x;
	}
	head = 0;
	tail = n;

	int elaps = 0; // 経過時間
	while (head!=tail)
	{
		pp u = dequeue();
		elaps += min(u.time, q);
		u.time = u.time - min(u.time, q);
		if (u.time>0)
		{
			enqueue(u);
		}
		else {
			cout << u.ps << " " << elaps << endl;
		}
	}

}
/*
5 100
p1 150
p2 80
p3 200
p4 350
p5 20

*/



Measured memory_bytes: 6880
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();

      int avg = m / n;

      int maxD = 1;
      for(int i = avg; i >= 1; i--) {
        if(m % i == 0) {
          maxD = i;
          break;
        }
      }
      System.out.println(maxD);
  }
}

Measured memory_bytes: 23124
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("needed");
            //2 5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("atcoder");
            //-1 -1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("ABCBA");
            //2 4
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];

        //始点のループ
        for (int I = 0; I <= S.Length - 1; I++) {
            char StaChar = S[I];

            int Cnt = 0;
            for (int J = I ; J <= S.Length - 1; J++) {
                if (S[J] == StaChar) Cnt++;
                else {
                    if (--Cnt < 0) break;
                }
                if (J > I && Cnt >= 1) {
                    Console.WriteLine("{0} {1}", I + 1, J + 1);
                    return;
                }
            }
        }
        Console.WriteLine("-1 -1");
    }
}


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

#define ll long long

void read(ll &rem){
	rem = 0; char c = getchar();
	while(c<'0'||c>'9') c = getchar();
	while(c>='0'&&c<='9') rem = rem*10+c-48, c = getchar();
}

double tem[500050];
ll v[500050], cnt, head = 1;

int main(){
	ll T, L, nt, nv, ans = 0;
	bool flag = 0;
	read(T), read(L);
	while(T--){
		scanf("%lld %lld", &nt, &nv);
		tem[++cnt] = nt;
		v[cnt] = nv;
		ans += nt * nv;
		ll p = 0;
		if(flag){
			while(p+v[head]<=nv) {
				p+=v[head], ans -= tem[head] * v[head], head++;
			}
			if(p<nv){
				v[head] -= nv-p;
				ans -= (nv-p) * tem[head];
			}
		}
		printf("%.8f\n", 1.0 * ans / L);
		while(tem[cnt] <= tem[cnt-1] && cnt-1 >= head){
			tem[cnt-1] = 1.0 * (v[cnt] * tem[cnt] + v[cnt-1] * tem[cnt-1]) / (v[cnt] + v[cnt-1]);
			v[cnt-1] += v[cnt];
			cnt--;
		}
		flag = 1;
	}
}

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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		long N = nextLong();
		long A = nextLong();
		long B = nextLong();
		long C = nextLong();
		long D = nextLong();
		long E = nextLong();
		long[] x ={A,B,C,D,E};
		Arrays.sort(x);

//		long ans =0;
//		//1から2に移動する
//		ans+=(N+A-1)/A;
//		//2から3に移動する
//		//1回目の移動時に何人移動したときに何人乗れないか
//		long remB =Math.min(0, A-B);
		System.out.println((N+x[0]-1)/x[0]+4);
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

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

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 102;

int n;
int a[N];
int cnt[N];
int mn = OO, mx = -OO;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mn = min(mn, a[i]);
		mx = max(mx, a[i]);
		cnt[a[i]]++;
	}
	if (mn != (mx + 1) / 2 || ((mx & 1) && cnt[mn] != 2) || (!(mx & 1) && cnt[mn] != 1)) {
		puts("Impossible");
		return 0;
	}
	for (int i = mn + 1; i < mx; i++) {
		if (cnt[i] < 2) {
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
	return 0;
}


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

class Dice
{
public:
	int top;
	int front;
	int right;
	int left;
	int back;
	int bottom;
	Dice(int a,int b,int c,int d,int e,int f){
		top = a;
		front = b;
		right = c;
		left = d;
		back = e;
		bottom = f;
	}
	void rotateN(){
		int t = top;
		top = front;
		front = bottom;
		bottom = back;
		back = t;
	}
	void rotateE(){
		int t = top;
		top = left;
		left = bottom;
		bottom = right;
		right = t;
	}
	void rotateS(){
		int t = top;
		top = back;
		back = bottom;
		bottom = front;
		front = t;
	}
	void rotateW(){
		int t = top;
		top = right;
		right = bottom;
		bottom = left;
		left = t;
	}
};

int main()
{
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	Dice obj(a,b,c,d,e,f);
	int q;
	cin >> q;
	for(int i=0; i<q; i++){
		int x,y;
		cin >> x >> y;
		Dice p = obj;
		if(y == p.top){
			p.rotateS();
		}else if(y == p.right){
			p.rotateW();
			p.rotateS();
		}else if(y == p.left){
			p.rotateE();
			p.rotateS();
		}else if(y == p.back){
			p.rotateS();
			p.rotateS();
		}else if(y == p.bottom){
			p.rotateN();
		}
		if(x == p.right){
			p.rotateW();
		}else if(x == p.left){
			p.rotateE();
		}else if(x == p.bottom){
			p.rotateE();
			p.rotateE();
		}
		cout << p.right << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, A: int, B: int):
    return min(N * A , B)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    result = solve(N, A, B)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5376
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
  int A,B,Q;
  std::cin >> A >> B >> Q;

  std::vector<long long> s_arr(A+2), t_arr(B+2);
  for(int i = 0; i < A; i++) std::cin >> s_arr[i];
  for(int i = 0; i < B; i++) std::cin >> t_arr[i];

  s_arr[A] = t_arr[B] = std::pow(10,11);
  s_arr[A+1] = t_arr[B+1] = -std::pow(10,11);
  std::sort(s_arr.begin(), s_arr.end());
  std::sort(t_arr.begin(), t_arr.end());

  for(int i = 0; i < Q; i++){
    long long x;
    std::cin >> x;
    auto s2 = std::lower_bound(s_arr.begin(), s_arr.end(), x);
    auto t2 = std::lower_bound(t_arr.begin(), t_arr.end(), x);

    long long min_length = std::pow(10,11);
    for(auto it=s2-1; it!=s2+1; ++it){
      for(auto it2=t2-1; it2!=t2+1; ++it2){
        min_length = std::min(min_length, std::abs(x-*it)+std::abs(*it-*it2));
        min_length = std::min(min_length, std::abs(x-*it2)+std::abs(*it2-*it));
      }
    }
    std::cout << min_length << "\n";
  }

  return 0;
}



Measured memory_bytes: 2944