akhauriyash/Code-Regression huggingface dataset:
t1,n1 = map(int, input().split())
t2,n2 = map(int, input().split())
t3,n3 = map(int, input().split())
t4,n4 = map(int, input().split())

if t1==1:
    print(n1*6000)
elif t1==2:
    print(n1*4000)
elif t1==3:
    print(n1*3000)
else:
    print(n1*2000)

if t2==1:
    print(n2*6000)
elif t2==2:
    print(n2*4000)
elif t2==3:
    print(n2*3000)
else:
    print(n2*2000)

if t3==1:
    print(n3*6000)
elif t3==2:
    print(n3*4000)
elif t3==3:
    print(n3*3000)
else:
    print(n3*2000)

if t4==1:
    print(n4*6000)
elif t4==2:
    print(n4*4000)
elif t4==3:
    print(n4*3000)
else:
    print(n4*2000)    


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

int main(){
  int N;
  cin >> N;
  int answer = 0;
  for(int C=1; C <= N; C += 2){
    int num_of_divisors = 0;
    for(int X=1; X <= C; ++X){
      if(C % X == 0){
        ++num_of_divisors;
      }
    }
    if(num_of_divisors == 8){
      ++answer;
    }
  }
  cout << answer << endl;
}

    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mod 1000000007 ;
typedef long long ll;

void IO()
{
	#ifndef ONLINE_JUDGE
			freopen("input.txt","r",stdin);
			freopen("output.txt","w",stdout);
	#endif 
}
vector<bool> used(200000);
vector<int> adj[200000];
vector<int> a,b;
void bfs(int i)
{	
queue<int> q;
	q.push(i);
	used[i] = 1;
	a.push_back(i);
	while(!q.empty())
	{	i = q.front();
		q.pop();
		for(auto vertex:adj[i])
		{	
			if(used[vertex]==-1)
			{
				used[vertex] = used[i]^1;
				if(used[vertex]==1) a.push_back(vertex);
				else b.push_back(vertex);
				q.push(vertex);
			}
			if(used[vertex]==used[i]){
				cout<<-1;
				exit(0);
			}
	
			}


	}
}

ll in[200000][2];  // 0th colummn is weight of item and 1st column is profit
ll dp[200000][201];

int n,W;
ll rec(int w,int i)
{
	if(dp[w][i] != -1) return dp[w][i];
	if( w==0 | i == 0) return dp[w][i] =  0;

	if(in[i][0] > w) return dp[w][i] = rec(w,i-1);

	else {
		dp[w][i] = max(rec(w,i-1), rec(w-in[i][0],i-1) + in[i][1]) ;	
		return dp[w][i];
		}

}
		
void solve()
{		
		cin>>n>>W;
		for(int i = 1;i<=n;i++)
			cin>>in[i][0]>>in[i][1];

		cout<<rec(W,n);
		
		
}
int main()
{
	IO();
	fast;
	// int t;cin>>t;while(t--)
	memset(dp,-1,sizeof(dp));
	solve();

		

	return 0;
}





Measured memory_bytes: 322360
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]a = new int[n];
    int[]A = new int[n];
    
    long al = 0;
    for(int i=0; i<n; i++) {
    		a[i] = sc.nextInt();
    		al += a[i];
    	}
    	long all= a[0];
    	for(int i=1; i<n; i++) {
    		if(a[i] < a[i-1]) {
    			a[i] = a[i-1];
    			all += a[i];
    		}else {
    			all += a[i];
    		}
    	}
    	System.out.println(all - al);
    }
}

Measured memory_bytes: 61540
#include <stdio.h>
#include<math.h>
#include <string.h>
#include <ctype.h>

int main(){
int n,f,i;
int a[10001];
a[1]=2;
for(i=2;i<=10000;i++){
a[i]=a[i-1]+i;
}
while(scanf("%d",&n)!=EOF){
printf("%d\n",a[n]);
}

return 0;
}

Measured memory_bytes: 1064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple{
    string S, T;
    void Solve(){
        //input
        S = io.String;
        T = io.String;
        S = new string(S.Reverse().ToArray());
        T = new string(T.Reverse().ToArray());
        //cal
        if(T.Length > S.Length){
            Console.WriteLine("UNRESTORABLE");
            return;
        }
        var X = S.Select(c => c == '?' ? 'a' : c).ToArray();
        for(int i = 0; i < S.Length - T.Length + 1; ++i){
            var f = true;
            for(int j = 0; j < T.Length; ++j){
                if(S[i + j] == '?' || S[i + j] == T[j]){
                    //
                }
                else{
                    f = false;
                    break;
                }
            }
            if(f){
                for(int j = 0; j < T.Length; ++j) if(S[i + j] == '?' || S[i + j] == T[j]) X[i + j] = T[j];
                //ret
                Console.WriteLine(new string(X.Reverse().ToArray()));
                return;
            }
        }
        //ret
        Console.WriteLine("UNRESTORABLE");
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream(){
        Solve();
        io.writeFlush();
    }
}
class SimpleIO{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[]{' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    public SimpleIO(){
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next(){
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int a,b;
  cin >> a  >> b;
  cout << a * b << endl;


  return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[1] << s3[2] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a[100] = {0};
  int n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = n - 1; i > 0; i--) printf("%d ", a[i]);
  printf("%d", a[i]);
  putchar('\n');
  return 0;
}

Measured memory_bytes: 600
#
s=input()+'R' #以下ではRが出てきたときに値を更新しているので最後にRを付け加える
l=len(s)
ans=[0]*(l-1) #すべてのマスの答えを0で初期化
rcnt=0
lcnt=0
rpos=0
lpos=0
flag=0
for i in range(l):
 if s[i]=='R':
   if flag==1: #文字列がLRとなっているとき、直前のRLについて答えを求める
     if rcnt%2==0: #Rの個数が偶数のとき
       ans[rpos]+=rcnt//2
       ans[lpos]+=rcnt//2
     else: #Rの個数が奇数のとき
       ans[rpos]+=rcnt//2+1
       ans[lpos]+=rcnt//2
     if lcnt%2==0: #Lの個数が偶数のとき
       ans[rpos]+=lcnt//2
       ans[lpos]+=lcnt//2
     else: #Lの個数が奇数のとき
       ans[rpos]+=lcnt//2
       ans[lpos]+=lcnt//2+1
     rcnt=0
     lcnt=0
   flag=0
   rcnt+=1 #Rの個数を求める
   rpos=i #右端のRの位置を求める
 elif s[i]=='L':
   if flag==0:
     lpos=i #左端のLの位置を求める
   lcnt+=1 #Lの個数を求める
   flag=1
print(*ans)


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int64_t>a(N),b(N);
  int64_t cnta=0,cntb=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    cnta+=a[i];
  }
  for(int i=0;i<N;i++){
    cin>>b[i];
    cntb+=b[i];
  }
  int64_t cntv=0,cnto=0;
  for(int i=0;i<N;i++){
    if(a[i]>b[i]){cntv+=(a[i]-b[i]);}
    if(a[i]<b[i]){cnto+=(b[i]-a[i])/2;}
  }
  if(cntv>cnto){cout<<"No"<<endl;}
  else if(cnto<=cntb-cnta){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}

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

using namespace std;

const int MAXN = 3010;

int dp[MAXN][MAXN];

int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif

    string s, t;
    cin >> s >> t;

    s = ' ' + s;
    t = ' ' + t;

    for(int i = 1; i < s.size(); ++i) {
    	for(int j = 1; j < t.size(); ++j) {
    		dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    		dp[i][j] = max(dp[i][j], dp[i-1][j-1] + (s[i]==t[j]));
    	}
    }

    int i = s.size() - 1;
    int j = t.size() - 1;
 	
 	string ans;
    while(i && j) {
    	if(s[i] == t[j]) {
    		ans += s[i];
    		--i;
    		--j;
    		continue;
    	} 
    	if(dp[i][j] == dp[i-1][j]) -- i;
    	else --j;
    }

    reverse(ans.begin(), ans.end());
    cout << ans;
}  

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

#define hell                         1000000007
#define __lcm(a,b)                   (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cerr << #x << " is " << x << endl;
#define endl                           '\n'

#define MAX 100005
using namespace std;

string add(ll n) {
    string s = to_string(n);
    while(s.length()<6) {
        s='0'+s;
    }
    return s;
}

ll ind[MAX];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll n,m;
    cin >> n >> m;
    vector<pair<pair<ll,ll>, ll > > v;
    rep(i,0,m) {
        ll x,y;
        cin >> x >> y;
        v.pb({{x,y},i});
    }
    sort(all(v));
    string ans[m];

    
    rep(i,0,m) {
        ll p = v[i].F.F;
        ll in = ind[p]+1;
        ind[p]++;
        ans[v[i].S] = add(p)+add(in);
    }
    rep(i,0,m) cout << ans[i] << endl;
}

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

#define int int64_t
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<=(n); ++i)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define ll long long
#define abs(a) llabs(a)
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define INF 1000000000;
const long long mod = 1000000007;
using namespace std;

double dp[3010][3010];
int n;
double a,ans=0.0;
signed main(){

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

    cin>>n;
    vector<double> x;

    rep(i,n) cin>>a,x.push_back(a);

    dp[0][0] = 1.0;

    rep(i,n){
        for(int j = 0; j<= i; ++j){
            dp[i+1][j+1] += dp[i][j] * x[i];
            dp[i+1][j] += dp[i][j] * (1.0 - x[i]);
        }
    }

    for(int i = (n+1)/2; i <= n; ++i) ans += dp[n][i];

    cout<<setprecision(10)<<ans<<'\n';
}

Measured memory_bytes: 69248
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
.split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    // solver code...
    let tmp_vec = read_vec::<i32>();
    let d = tmp_vec[0];
    let t = tmp_vec[1];
    let s = tmp_vec[2];

    if s * t >= d {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 4;

void solve(){
    string s; cin >> s;
    int n = s.size();
    map<char, int> mp;
    for(int i = 0; i < n; ++i){
        ++mp[s[i]];
    }
    if(mp.size() == 1){
        cout << "0\n";
        return;
    }

    ll ans = INF64;

    for(auto it : mp){
        string str = s;
        string str2;
        ll tmp = 0;
        bool flag = true;
        while(flag){
            ++tmp;
            str2.clear();
            for(int i = 0; i < str.size() - 1; ++i){
                if(str[i] == it.first || str[i + 1] == it.first ){
                    str2 += it.first;
                }
                else{
                    str2 += str[i];
                }
            }

            flag = false;
            for(int i = 0; i < str2.size() ; ++i){
                if(str2[i] != it.first){
                    str = str2;
                    flag = true;
                    break;
                }
            }
        }
        ans = min(ans, tmp);
    }
    cout << ans << '\n';

    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() { 
    int n;
    cin >> n;
    bool flag=false;
    for(int i=0;i<=n/4;i++){
        for(int j=0;j<=n/7;j++){
            if(4*i+7*j==n)flag=true;
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(void)
{
    long long A, B, C, K;
    
    cin >> A >> B >> C >> K;
    
    long long count = 0;
    long long ans = 0;
    for (int i = 0; i < A; i ++) {
        if (count >= K) {
            cout << ans << endl;
            return 0;
        }
        ans ++;
        count ++;
    }
    
    for (int i = 0; i < B; i ++) {
        if (count >= K) {
            cout << ans << endl;
            return 0;
        }
        count ++;
    }
    
    for (int i = 0; i < C; i ++) {
        if (count >= K) {
            cout << ans << endl;
            return 0;
        }
        ans --;
        count ++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N,K = LI()

mod = 10**9+7

#modに対応して高速なコンビネーションが求められる

n = 2000

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, n+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))



def combinations_count(n,r):
    if n-r < 0:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod


"""
N = 5 , K = 2

i = 1
bbrrr
rbbrr
rrbbr
rrrbb

i = 2
brbrr
6

(N - K + 1) C i * 

00|||

|||00
||00|
|00||
00|||

K - i = 0
i + 1

"""

for i in range(1, K+1):
    print(combinations_count(N - K + 1, i) * combinations_count(K- i + (i - 1), K -i) % mod)

Measured memory_bytes: 6732
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
// combination c(max);
// mint c(n, k)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, a, b, k;
    cin >> n >> a >> b >> k;

    combination c(n);
    mint ans = 0;
    for (ll x = 0; x <= n; ++x) {
        ll y = k - a * x;
        if (y < 0) break;
        if (y % b != 0) continue;
        y /= b;
        if (y > n) continue;
        ans += c(n, x) * c(n, y);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using pll = pair<long long, long long>;

int main() {
    int N; cin >> N;
    vector<pll> v(N);
    for (int i = 0; i < N; ++i) {
        long long a, l;
        cin >> a >> l;
        v[i] = {a - l, a + l};
    }

    // 区間を右端の小さい順にソート
    sort(v.begin(), v.end(), [](pll a, pll b) {
            return a.second < b.second;});

    // cur := 現在選んでいる区間のうち、最も右にあるやつの右端
    int res = 0;
    long long cur = -(1LL<<60);
    for (int i = 0; i < N; ++i) {
        if (cur > v[i].first/*腕の左の先端*/) continue; // 被るやつは飛ばす←わからん
        ++res;
        cur = v[i].second;
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,1,0,-1,-1,-1,0,1};
int dy[] = {0,-1,-1,-1,0,1,1,1};
vector<vector<int>> graph;
vector<vector<bool>> reached;

int main(){
    int N;
    cin >> N;
    vector<int> A(9,0);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a >= 3200){
            A[8]++;
        }
        else{
            A[a/400]++;
        }
    }
    int colors=0,rbw=0;
    if(A[8] > 0){
        rbw = A[8];
    }
    for(int i=0;i<8;i++){
        if(A[i] > 0) colors++;
    }
    if(colors == 0 && rbw > 0){
        cout << 1 << ' ' << rbw << endl;
    }
    else{
        cout << colors << ' ' << colors+rbw << endl;
    }

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int n,m;
  cin>>n>>m;
  vector<int>s(n),t(m);
  rep(i,n)cin>>s[i];
  rep(i,m)cin>>t[i];
  vector<vector<ll>>dp(n+1,vector<ll>(m+1));
  vector<vector<ll>>sum(n+1,vector<ll>(m+1));
  dp[0][0]=1;
  sum[1][1]=1;
  rep(i,n){
    rep(j,m){
      if(s[i]==t[j]){
        dp[i+1][j+1]+=sum[i][j]+1;
      }
      dp[i+1][j+1]%=mod;
      sum[i+1][j+1]=(sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i+1][j+1]+mod)%mod;
    }
  }
  cout<<(sum[n][m]+1)%mod<<endl;
}

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


Measured memory_bytes: 62976
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <utility>
#include <functional>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)

using ll = long long;
using P = std::pair<int, int>;
using namespace std;

constexpr int INF = 1000000000; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18
constexpr int MAX_N = 201;

// d[i][j]はi->jの最小コスト
int d[MAX_N][MAX_N];
// S->すでに訪れた点の集合, v->現在位置, dp[S][v]: 左の状況での最小コスト
int dp[256][8];
int N, M, R;
vector<int> r;

int func(int s, int v) {
	if (s == (1 << R) - 1) {
		return 0;
	}
	if (dp[s][v] != INF) { return dp[s][v]; }
	REP(u, R) {
		if (!((s >> u) & 1)) {
			dp[s][v] = min(dp[s][v], func(s | (1 << u),u) + d[r[v]][r[u]]);
		}
	}
	return dp[s][v];
}

// dpテーブルを埋める
void solve() {
	//for (int s = (1 << R) - 2; s >= 0; --s) {
	//	REP(v, R) {
	//		func(s, v);
	//	}
	//}
	//return;
	for (int s = (1 << R) - 2; s >= 0; --s) {
		REP(v, R) {
			REP(u, R) {
				if (!((s >> u) & 1)) {
					dp[s][v] = min(dp[s][v], dp[s | 1 << u][u] + d[r[v]][r[u]]);
				}
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	// 初期化
	cin >> N >> M >> R;
	r = vector<int>(R);
	REP(i, R) cin >> r[i];
	for (int i = 1; i <= N; ++i) {
		fill(d[i], d[i] + N+1, INF);
		d[i][i] = 0;
	}
	REP(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		d[a][b] = c;
		d[b][a] = c;
	}
	for (int S = 0; S < (1 << R); ++S) {
		fill(dp[S], dp[S] + R, INF);
	}

	// WF法

	REP(k, N + 1) {
		REP(i, N + 1) {
			REP(j, N + 1) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	// ビットDP

	REP(i, R) dp[(1 << R) - 1][i] = 0; // 全て通った後のコストを0にする

	solve();

	int m = INF;
	REP(i, R) {
		m = min(m, dp[1 << i][i]);
	}

	cout << m << "\n";

	return 0;
}


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

int main() {
  int N, M, x;
  cin >> N >> M;
  
  vector<int> vec(N);
  for(int i=0; i<2*M; i++){
    cin >> x;
    vec.at(x-1)++;
  }
  for(int i=0; i<N; i++){
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
a, b, c, x, y = map(int, input().split())
print(
    min(
        a * x + b * y,
        max(x, y) * c * 2,
        c * x * 2 + (y - x) * b if y > x else c * y * 2 + (x - y) * a if x > y else 10**9,
    ))


Measured memory_bytes: 9172
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        int cnt = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '1') {
                cnt++;
            } else {
                break;
            }
        }
        if (cnt >= k) {
            System.out.println(1);
        } else {
            System.out.println(s.charAt(cnt));
        }
    }
}

Measured memory_bytes: 21844
import static java.lang.System.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public void solve() {

		int A = nextInt();
		int B = nextInt();
		int C = nextInt();

		out.println(C+" "+A+" "+B);

	}

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

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

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

	public int nextInt() {
		return (int) nextLong();
	}

	public int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	double sqrt(double x) {
		return Math.sqrt(x);
	}

	double pow(double x, double y) {
		return Math.pow(x, y);
	}
	int max(int a,int b) {
		return Math.max(a, b);
	}

	public static void main(String[] args) {
		Main m = new Main();

		m.solve();
	}

	public void println(Object o) {
		out.println(o);
	}

}


Measured memory_bytes: 23124
from itertools import permutations
n=int(input())
q=[list(map(int,input().split())) for _ in range(n)]
l=list(range(8))
Q=list(permutations(l,8))
def OK(s):
    a=list(s)
    b=list(s)
    for i in range(len(s)):
        a[i]-=i
        b[i]+=i
    for i,j in enumerate(a[:-1]):
        if j in a[i+1:]:
            return False
    for i,j in enumerate(b[:-1]):
        if j in b[i+1:]:
            return False
    return True
for i in Q:
    chk=i
    for x,y in q:
        if i[x]!=y:
            chk=[]
            break
    if chk:
        if OK(i):
            A=i
            break
ans=[['.']*8 for _ in range(8)]
for i,j in enumerate(A):
    ans[i][j]='Q'
    print(''.join(map(str,ans[i])))


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

public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int ans = (X-A)%B;
		
		out.println(ans);
		out.close();
	}

	//-----------http://codeforces.com/blog/entry/7018---------------------------------
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	//--------------------------------------------------------

}



Measured memory_bytes: 21076
def get_score(medium, final, retry):
    medium_final = medium + final
    if medium == -1 or final == -1:
        return 'F'
    elif 80 <= medium_final:
        return 'A'
    elif 65 <= medium_final:
        return 'B'
    elif 50 <= medium_final:
        return 'C'
    elif 30 <= medium_final:
        if 50 <= retry:
            return 'C'
        else:
            return 'D'
    else:
        return 'F'


while True:
    [medium, final, retry] = [int(x) for x in raw_input().split()]
    if [medium, final, retry] == [-1, -1, -1]:
        break

    print(get_score(medium, final, retry))

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

const int MAX = 10000 + 1;
bool IsPrime[MAX];
vector<int> Eratosthenes(int n = MAX) {
    vector<int> res;    // prime numbers
    IsPrime[0] = false; IsPrime[1] = false;
    for (int i = 2; i < n; ++i) IsPrime[i] = true;
    for (int i = 2; i < n; ++i) if (IsPrime[i]) {
        res.push_back(i);
        for (int j = i * 2; j < n; j += i) IsPrime[j] = false;
    }
    return res;
}

int main() {
    vector<int> prime = Eratosthenes();
    int n;
    while (cin >> n, n) {
        int cnt = 0;
        int right = 0, sum = 0;
        for (int left = 0; left < prime.size(); left++) {
            while (right < prime.size() && sum < n) {
                sum += prime[right++];
            }
            if (sum == n) cnt++;
            sum -= prime[left];
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    cout << fixed << setprecision(10) << ((n  + 1) / 2) / (n*1.0) ;
    return 0;
}

Measured memory_bytes: 256
n,m=list(map(int,input().split(" ")))
l=[]
l=[list(map(int,input().split(" "))) for i in range(n)]
drink=0
price=0
i=0
l.sort(key=lambda x: x[0])
while drink<m:
    pri=l[i][0]
    num=l[i][1]
    i+=1
    drink+=num
    price+=pri*num
if drink>m:
    price-=(drink-m)*pri
print(price)


Measured memory_bytes: 28956
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  string s1, s2;cin>>s1>>s2;
  vector<int> pattern;
  rep(i, n){
    pattern.push_back(s1[i]==s2[i]);
    if(s1[i]!=s2[i])i++;
  }
  n=(int)pattern.size();
  ll ans=1LL;
  if(pattern[0])ans*=3;
  else ans*=6;
  repb(i, 1, n){
    if(pattern[i-1]==0){
      if(pattern[i]==0)ans*=3;
      else ans*=1;
    }else{
      if(pattern[i]==0)ans*=2;
      else ans*=2;
    }
    ans%=MOD;
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


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

#define int long long

using namespace std;

const int maxn = 110, maxl = 1e5 + 10;
int w[maxn], v[maxn], dp[maxn][maxl], n, W;

signed main()
{
    ios::sync_with_stdio(false);
    cin >> n >> W;

    for (int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    fill(dp[0] + w[0], dp[0] + maxl, v[0]);
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < w[i]; j++)
            dp[i][j] = dp[i - 1][j];
        for (int j = w[i]; j <= W; j++)
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
    }

    cout << dp[n - 1][W];

    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
}
int N=1e5+9,k;
void input_(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
void dfs(int u,vector<int> &vis,std::vector<std::vector<int>> &vtx){
    vis[u]=1;
    for(auto v:vtx[u]) if(vis[v]==0) dfs(v,vis,vtx);
}
void solve(){
	int n,m;
    cin>>n>>m;
    vector<vector<int>> vtx(n+1);
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        vtx[u].pb(v);
        vtx[v].pb(u);
    }
    int ans=0;
    std::vector<int> vis(n+1,0);
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            dfs(i,vis,vtx);
            ans++;
        }
    }
    cout<<ans-1;
}
int main(){
    input_();
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int t=1;
	//cin>>t;
	while(t--) 
	    solve();
	return 0; 
}

Measured memory_bytes: 10048
#include <stdio.h>
typedef long long ll;

ll min(ll a, ll b) {
  return a < b ? a : b;
}

int main(void) {
  ll i, a[7];
  for(i = 0; i < 7; ++i) scanf("%lld", &a[i]);
  ll m = min(a[0], min(a[3], a[4]));
  if(m) {
    ll cnt = 0;
    if(a[0] & 1) cnt++;
    if(a[3] & 1) cnt++;
    if(a[4] & 1) cnt++;
    if(cnt == 2) a[0]--, a[3]--, a[4]--, cnt = 3;
    printf("%lld", a[0] / 2 * 2 + a[1] + a[3] / 2 * 2 + a[4] / 2 * 2 + (cnt > 1 ? cnt : 0));
  } else printf("%lld", a[0] / 2 * 2 + a[1] + a[3] / 2 * 2 + a[4] / 2 * 2);
  return 0;
}

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

const int INF = 1e9;

int main() {
  string s;
  cin>>s;
  if(s.length()==2){
    cout<<s<<endl;
  }else{
    reverse(s.begin(),s.end());
    cout<<s<<endl;
  }

}


Measured memory_bytes: 256
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element : vec) {
        is >> element;
    }
    return is;
}
template <class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main(std::istream &in, std::ostream &out) {
    int K, N;
    scanf("%lld %lld", &K, &N);
    //in >> K >> N;
    vi a(N);
    for (int i = 0; i < N; ++i) {
        scanf("%lld", &a[i]);
    }

    int diff = K - a[N - 1] + a[0];
    REP(i, N - 1) {
        chmax(diff, a[i + 1] - a[i]);
    }
    out << K - diff;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    Main(in, out);
    //cout << flush;
}
#pragma endregion


Measured memory_bytes: 4888
#include <iostream>
using namespace std;
int A,B,C,D;

void solve()
{
    int AB;
    int CD;
    int result;
    AB = A*B;
    CD = C*D;
    if(AB>CD)
    {
        result = AB;
    }
    else
    {
        result = CD;
    }
    cout << result << endl;
}
int main()
{
    cin >> A >> B >> C >> D;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  while(cin>>a>>b>>c){
    if(a==b&&b==c)
      cout<<1<<endl;
    else if(a==b)
      cout<<2<<endl;
    else if(b==c)
      cout<<2<<endl;
    else if(a==c)
      cout<<2<<endl;
    else
      cout<<3<<endl;
  }
  return 0;
}





Measured memory_bytes: 256
n=int(input())
L=[[] for i in range(n+1)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    L[u].append((v,w%2))
    L[v].append((u,w%2))

V=[0 for i in range(n+1)]
V[1]=1
ans=[0 for i in range(n+1)]
que=[1]
head=0

while len(que)>head:
    now=que[head]
    head+=1
    for nex in L[now]:
        if V[nex[0]]==0:
            V[nex[0]]=1
            ans[nex[0]]=ans[now]^nex[1]
            que.append(nex[0])
    
for pri in ans[1:]:
    print(pri)

Measured memory_bytes: 41788
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int f(int n){
	if (n % 2 == 0) {
		return n / 2;
	} else {
		return 3 * n + 1;
	}
}

int main() {
	int n; cin >> n;
	vector<bool> checked(1000000, false);
	bool isfound = false;
	checked[n] = true;
	int i = 2;
	int b = n;
	int ans = 0;
	while (!isfound) {
		if (checked[f(b)]) {
			isfound = true;
			ans = i;
		} else {
			checked[f(b)] = true;
			b = f(b);
		}
		++i;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 



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

string S;
int Q;
cin >> S >> Q;

int crev = 0; // 反転する回数
string pre, suff;
rep(_, 0, Q){
    int T; cin >> T;
    if (T == 1){
        ++crev;
    }
    else {
        int F; char C; cin >> F >> C;
        if (crev % 2){
            swap(pre, suff);
            if (F == 1){
                pre.push_back(C);
            }
            else {
                suff.push_back(C);
            }
            swap(pre, suff);
        }
        else {
            if (F == 1){
                pre.push_back(C);
            }
            else {
                suff.push_back(C);
            }
        }
    }
}

if (crev % 2) {
    reverse(ALL(S));
    swap(pre, suff);
}
reverse(ALL(pre));

cout << pre + S + suff << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1300
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
  int N;
  cin>>N;
  vector<vector<pair<int,int>>> A(N);
  for(int i=1;i<N;i++){
    int a,b,c;
    cin>>a>>b>>c;
    A[a-1].push_back({b-1,c});
    A[b-1].push_back({a-1,c});
  }
  vector<int> B(N,-1);
  queue<int> Q;
  B[0]=0;
  Q.push(0);
  while(!Q.empty()){
    int I=Q.front();
    Q.pop();
    for(pair<int,int> p:A[I])
      if(B[p.first]==-1){
        B[p.first]=(B[I]+p.second)%2;
        Q.push(p.first);
      }
  }
  for(int i=0;i<N;i++)cout<<B[i]<<endl;
}

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

ll N, K;
vector<ll> a;

int main() {
    scanf("%Ld%Ld", &N, &K);
    a.resize(N);
    for (int i = 0; i < N; i++) scanf("%Ld", &a[i]);
    int ans = (N-1)/(K-1) + !!((N-1)%(K-1));
    cout << ans << endl;
    return 0;
}

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

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

using namespace std;

using ll = long long int;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> s(3);
  rep(i, 3)
  {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  cout << s[0] + s[1] << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
l = 0
count = 0
max_h = 0
for i in range(1,N):
    if A[i-1]>max_h:
        max_h = A[i-1]
    if A[i]<max_h:
        k = max_h - A[i]
        count += k
        if k>l: l=k
        A[i] = max_h
print(count)

Measured memory_bytes: 32320
using System;

namespace ITP1_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputLine = "";
            int firstNum, secondNum = 0;
           
            string[] Num = Console.ReadLine().Split(' ');
            firstNum = int.Parse(Num[0]);
            secondNum = int.Parse(Num[1]);
            if(firstNum<secondNum)
            {
                Console.WriteLine("a < b");
            }else if (firstNum > secondNum)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}



Measured memory_bytes: 15932
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b))?(b):(a))
#define chmin(a, b) a = (((a)<(b))?(a):(b))

const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};

#define lengthof(x) (sizeof(x) / sizeof(*(x)))


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

bool contain(int mask, int position){
  if((mask&(1<<position))) return true;
  else return false;
}

// GCD,LCMを求める関数
ll gcd(ll a,ll b){
	if(a%b==0) return(b);
	else return(gcd(b,a%b));
}
ll lcm(ll a, ll b){
	return a*b/gcd(a,b);
}


signed main(){
	int n,m; cin>>n>>m;
  if(500*n>=m) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var S = lines[0].split("");
    var ans = 0; result = 0;

    for (var string of S) {
        if (string === "A" || string === "C" || string === "G" || string === "T") {
            result++;
            ans = Math.max(ans, result);
        }
        else { result = 0; }
    }
    console.log(ans);
});

Measured memory_bytes: 7628
N, K = map(int, input().split())

def a(x, K):
    return abs(x-K)

tmp2 = N//K
N = N - (tmp2*K)

pre = N + 1
while True:
    if pre <= N:
        N = pre
        break
    pre = N
    N = a(N, K)

print(N)

Measured memory_bytes: 38256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int total;

        Scanner inp = new Scanner(System.in);
        total = inp.nextInt();

        int[] a = new int[total];

        for (int k = 0; k < total; k++) {
            a[k] = inp.nextInt();
        }

        for (int l = 0; l < total; l++) {
            if (l == 0) {
                System.out.printf("%d", a[l]);
            } else {
                System.out.printf(" %d", a[l]);
            }
        }

        System.out.printf("\n");

        for (int i = 1; i <= a.length-1; i++) {
            int key = a[i];
            /* insert A[i] into the sorted sequence A[0,...,j-1] */
            int j = i - 1;
            while (j >= 0 && a[j] > key) {
                a[j+1] = a[j];
                j--;
            }
            a[j+1] = key;

            for (int l = 0; l < total; l++) {
                if (l == 0) {
                    System.out.printf("%d", a[l]);
                } else {
                    System.out.printf(" %d", a[l]);
                }
            }

            System.out.printf("\n");
        }
    }
}



Measured memory_bytes: 44604