akhauriyash/Code-Regression huggingface dataset:
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  																						   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;	
const int mod = 1e9+7;																							   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra																													   																				   list<int>::iterator it;																								   
																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////


///////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int a, b;
	cin >> a >> b;
	cout << (a % b != 0) << endl;
	
	
	
	
	
	
						
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int a,b,c,d;
        int x,y;

        scanf("%d%d%d%d",&a,&b,&c,&d);

        if(b<=c){ printf("0\n");
                return 0;
        }
//77 88 34 96
        x=c;
        if(a>c) x=a;
        y=d;
        if(b<d) y=b;

        if(y-x<0) printf("0\n");
        else printf("%d\n",y-x);

        return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    ll N;
    cin >> N;

    ll ans = 0;
    map<ll, ll> m;
    // 一回でもkが入るパターン
    for(ll k = 2; k <= N; k++){       
        if(k * k > N) break;
        ll kn1 = k; 
        while (true)
        {
            if( N % kn1 == 0 ){
                ll ntmp = N / kn1;
                if( (ntmp - 1) % k == 0) {
                    //cout << k << endl;
                    ans ++;
                }
            }
            kn1 *= k;
            if( kn1 > N ) break;
        }
    }

    ll ans2 = 0;
    for(ll k = 1; k <= N; k++){
        if(k * k > N) break;
        if( (N - 1ll) % k == 0 ){
            ans += 2;
            //cout << k << endl;
        }
        if(k * k == (N - 1) ) ans2 -= 1;
    }

    cout << ans + ans2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(){


  long long i,n,num,min=1000000,max=-1000000,sum=0;


scanf("%lld", &n);


for(i=0;i<n;i++){
  scanf("%lld", &num);

  sum += num;

  if(num < min){
    min = num;
  }

  if(num > max){
    max = num;
  }
 }

printf("%lld %lld %lld\n", min, max, sum);

return 0;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);
    rep(i, n) cin >> t[i] >> x[i] >> y[i];
    int nx = 0, ny = 0, nt = 0;
    auto dist = [&](int x, int y) { return abs(x - nx) + abs(y - ny);};
    rep(i, n) {
        int d = dist(x[i], y[i]);
        if (d <= t[i] - nt && (t[i] - nt - d) % 2 == 0) {
            nx = x[i];
            ny = y[i];
            nt = t[i];
            continue;
        } else {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<string,int>>data(n);
  rep(i,n){
    cin >> data[i].first >> data[i].second;
    if(i != 0) data[i].second += data[i-1].second;
  }
  string x;
  cin >> x;
  rep(i,n){
    if(data[i].first == x){
      cout << data[n-1].second-data[i].second << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}
impl<T: Iterator> IteratorExt for T {}

fn main() {
    let mut n = read!(usize);
    let mut s = String::new();

    while n != 0 {
        n -= 1;
        let c = ('a' as u8  + (n % 26) as u8) as char; 
        s.push(c);
        n /= 26;
    }
    unsafe {
        s.as_mut_vec().reverse();
    }
    println!("{}", s);
}



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

 const int N = 2e5 + 7;

 pair <int, int> arr[N];

 int q[N];
 
int32_t main() {
 
        int n, d, a; cin >> n >> d >> a;
        for(int i = 1;  i <= n; i++) {
        	int x, h; cin >> x >> h;
        	arr[i] = {x, h};
        }
        sort(arr + 1, arr + n + 1);


        int ans = 0;

        for(int i = 1; i <= n; i++) {
        	q[i] += q[i - 1];
        	int k = arr[i].second - q[i];
        	if(k <= 0) continue;
        	int x = (k + a - 1) / a;
        	ans += x;
        	q[i] += x * a;
        	int l = lower_bound(arr + 1, arr + n + 1, make_pair(arr[i].first + 2 * d + 1, -1LL)) - arr;
        	//cout << i << " " << q[i] << endl;
        	q[l] -= x * a;
        }
        cout << ans << endl;

}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,m,c=0;
  cin>>n>>m;
  if(n*2<=m){
    c+=n;
    m-=n*2;
    c+=m/4;
  }else{
    c+=m/2;
  }
  cout<<c<<endl;
}

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

int main(){
  int N;
  cin>>N;
  vector<char> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  string ans="Three";
  for(int i=0;i<N;i++){
    if(vec.at(i)=='Y'){
      ans="Four";
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main()
{
	int N, Q;
	char S[500001];
	scanf("%d", &N);
	scanf("%s", S);
	scanf("%d", &Q);
	
	int i, j, count[1001][26] = {};
	for (i = 0; i < N / 500; i++) {
		for (j = 0; j < 500; j++) count[i][S[i*500+j] - 'a']++;
	}
	for (j = 0; j < N % 500; j++) count[i][S[i*500+j] - 'a']++;

	int l, r, q, type, flag[26], ans;
	char c;
	for (q = 0; q < Q; q++) {
		scanf("%d", &type);
		if (type == 1) {
			scanf("%d %c", &i, &c);
			i--;
			count[i/500][S[i] - 'a']--;
			count[i/500][c - 'a']++;
			S[i] = c;
		} else {
			scanf("%d %d", &l, &r);
			l--;
			r--;
			for (j = 0; j < 26; j++) flag[j] = 0;
			for (i = (l + 499) / 500; i < (r + 1) / 500; i++) {
				for (j = 0; j < 26; j++) if (count[i][j] > 0) flag[j] = 1;
			}
			for (j = l; j <= r && j % 500 != 0; j++) flag[S[j] - 'a'] = 1;
			for (j = r; j >= l && (j + 1) % 500 != 0; j--) flag[S[j] - 'a'] = 1;
			for (j = 0, ans = 0; j < 26; j++) ans += flag[j];
			printf("%d\n", ans);
		}
	}
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2320
#include<iostream>

using namespace std;

int main()
{
	int H, N, a[100000], i = 0;

	cin >> H;
	cin >> N;
	if (H > 1000000000 || N > 100000)return 0;

	for (i = 0; i < N; i++)
	{
		cin >> a[i];
		if (a[i] > 10000) return 0;
	}
	for (i = 0; i < N; i++)
	{
		H = H - a[i];
	}
	if (H > 0)cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int sz=1e4+100;
const int Max=1e9+100;

int dp[sz][1100];
int n, h[sz], tk[sz];

int cholo(int id,int rem)
{
    if(rem<=0) return 0;
    else if(id>=n) return Max;
    int &ret=dp[rem][id];
    if(~ret) return ret;

    int mx=Max;
    mx=min(mx, tk[id]+cholo(id,rem-h[id]));
    mx=min(mx, cholo(id+1,rem));
    return (ret= mx);
}

int main()
{
    int m,p,q,x,y,i,j,k,l,tot;
    cin>>tot>>n;

    for(i=0;i<n;i++){
        cin>>h[i]>>tk[i];
    }

    memset(dp,-1,sizeof dp);
    int ans=cholo(0,tot);
    cout<<ans<<'\n';
}



Measured memory_bytes: 44160
#include<stdio.h>
#define N 200
int a[N];
int main()
{
    int n,i,j,k,key;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
 for(k=0;k<n;k++)
        {
            printf("%d",a[k]);
            if(k==n-1)
                printf("\n");
            else
                printf(" ");
        }
    for(i=1;i<n;i++)
    {
       key=a[i];
       j=i-1;
       while(j>=0&&a[j]>key)
       {
           a[j+1]=a[j];
           j--;
           a[j+1]=key;
       }
       for(k=0;k<n;k++)
        {
            printf("%d",a[k]);
            if(k==n-1)
                printf("\n");
            else
                printf(" ");
        }
    }

    return 0;
}



Measured memory_bytes: 2080
#include <iostream>
#include <vector>
int main(){
    int n;
    int ans = 0;
    std::cin >> n;
    std::vector <int> v(n);
    std::vector <int> c(n);
    for(int i=0; i<n; ++i){
        std::cin >> v[i];
    }
    /*
    for(int i=0; i<n; ++i){
        std::cout << v[i] << std::endl;
    }*/
    for(int i=0; i<n; ++i){
        std::cin >> c[i];
    }
    /*
    for(int i=0; i<n; ++i){
        std::cout << c[i] << std::endl;
    }*/
    for(int i=0; i<n; ++i){
        int tmp;
        tmp = v[i] - c[i];
        if(tmp > 0){
            ans = ans + tmp;
            //std::cout << ans << std::endl;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int a,b,ans=0;
    cin>>a>>b;
    if(a>b)
    {
        ans+=a;a--;
        if(a>b)
        {
            ans+=a;
        }
        else
        {
            ans+=b;
        }
    }
    else
    {
        ans+=b;b--;
        if(a>b)
        {
            ans+=a;
        }
        else
        {
            ans+=b;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

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

typedef vector<int> vi;

vi x[2], y[2], d[2];
vi cx, cy, cd;
int maps[101][101][101];

int getRev(vi &xs, int i) {
	if (i == -1) return 0;
	return *(xs.begin() + i);
}

void compress(vi &x1, vi &x2, vi &xs) {
	REP(i, x1.size()) {
		xs.push_back(x1[i]);
		xs.push_back(x2[i]);
	}
	
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	
	REP(i, x1.size()) x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
	REP(i, x2.size()) x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
}

int main() {
	int n, K;
	cin >> n >> K;
	
	REP(i, n) {
		int a1, b1, c1, a2, b2, c2;
		scanf("%d %d %d %d %d %d", &a1, &b1, &c1, &a2, &b2, &c2);
		x[0].push_back(a1);
		y[0].push_back(b1);
		d[0].push_back(c1);
		x[1].push_back(a2);
		y[1].push_back(b2);
		d[1].push_back(c2);
	}
	compress(x[0], x[1], cx);
	compress(y[0], y[1], cy);
	compress(d[0], d[1], cd);
	

	
	REP(i, n) {
		int x1 = x[0][i] + 1, y1 = y[0][i] + 1, d1 = d[0][i] + 1;
		int x2 = x[1][i], y2 = y[1][i], d2 = d[1][i];
		
		FOR(j, d1, d2 + 1) {
			maps[j][y1][x1]++;
			maps[j][y1][x2 + 1]--;
			maps[j][y2 + 1][x1]--;
			maps[j][y2 + 1][x2 + 1]++;
		}
	}
	
	REP(i, n * 2 + 1) {
		REP(j, n * 2 + 1) FOR(k, 1, n * 2 + 1) maps[i][j][k] += maps[i][j][k - 1];
		FOR(j, 1, n * 2 + 1) REP(k, n * 2 + 1) maps[i][j][k] += maps[i][j - 1][k];
	}
	
	long long ans = 0;
	
	REP(i, n * 2 + 1) REP(j, n * 2 + 1) REP(k, n * 2 + 1) {
		if (maps[i][j][k] >= K) {
			long long  dx = getRev(cx, k) - getRev(cx, k - 1);
			long long  dy = getRev(cy, j) - getRev(cy, j - 1);
			long long  dd = getRev(cd, i) - getRev(cd, i - 1);
			
			ans += dx * dy * dd;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 7268
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N;
	string S; cin >> N >> S;
	ll sum = 0;;
	ll maxV = 0;;
	rep(i, 0, N) {
		if (S[i] == 'I') {
			sum++;
			maxV = max(maxV, sum);
		}
		else {
			sum--;
		}
	}
	cout << maxV << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] lines = Console.ReadLine().Split(' ');
            int N = int.Parse(lines[0]);
            int M = int.Parse(lines[1]);

            int[] a = new int[M];
            int[] b = new int[M];

            int[] ans = new int[N];

            for (int i = 0; i < M; i++)
            {
                lines = Console.ReadLine().Split(' ');
                a[i] = int.Parse(lines[0]);
                b[i] = int.Parse(lines[1]);
                ans[a[i] - 1]++;
                ans[b[i] - 1]++;
            }

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(ans[i]);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int p=1000000007;
  vector<int64_t> e(k+1,1);
  for(int i=0;i<=k;i++){
    int x=n;
    vector<bool> b;
    while(x>0){
      b.push_back(x%2==1);
      x/=2;
    }
    for(int d=(int)b.size()-1;d>=0;d--){
      e.at(i)=e.at(i)*e.at(i)%p;
      if(b.at(d))
        e.at(i)=e.at(i)*i%p;
    }
  }
  vector<int64_t> c(k+1,0);
  int64_t s=0;
  for(int i=k;i>=1;i--){
    c.at(i)=e.at(k/i);
    for(int j=2;i*j<=k;j++)
      c.at(i)=(c.at(i)-c.at(i*j)+p)%p;
    s=(s+c.at(i)*i)%p;
  }
  cout<<s<<endl;
}

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

int main(void){
    // Your code here!
   int K,S;
   cin >> K >> S;
   int count = 0;
   for(int i = 0; i <= K; i++){
       for(int j = 0; j <= K; j++){
           if(0 <= S - i - j && S - i - j <= K){
               count++;
           }
       }
   }
   cout << count << endl;
}

Measured memory_bytes: 256
S=list(input())
n=len(S)

for i in range(n) :
	if i%2==0 and S[i]=='L' :
		print('No')
		break
	elif i%2==1 and S[i]=='R' :
		print('No')
		break
	elif i==n-1 :
		print('Yes')

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
//#define mod 1000000007
#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

ll dp[3005][3005];

ll mod_pow(ll x,ll n,ll m){
    if(n==0) return 1;
    ll res=mod_pow(x*x%m,n/2,m);
    if(n&1) res=res*x%m;
    return res;
}

ll modinv(ll n){
    return mod_pow(2,mod-2,mod);
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,s;
    cin>>n>>s;
    V<ll> a(n);
    cinf(n,a);
    dp[0][0]=1;
    rep(i,n){
        for(int j=0;j<=s;j++){
            dp[i+1][j]+=2*dp[i][j];
            dp[i+1][j]%=mod;
            if(j+a[i]<=s){
                dp[i+1][j+a[i]]+=dp[i][j];
                dp[i+1][j+a[i]]%=mod;
            }
        }
    }
    out(dp[n][s]);
}

Measured memory_bytes: 74068
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    b = lmi()
    ans = 0
    for i in range(n):
        if a[i] >= b[i]:
            ans += b[i]
        else:
            ans += a[i]
            rest_power = b[i] - a[i]
            ans += min(a[i+1], rest_power)
            a[i+1] = max(0, a[i+1] - rest_power)
    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
typedef vector<vector<lli> > vvi;
typedef vector<ii> vii;

#define EB emplace_back
#define PB push_back
#define MP make_pair
#define FF first
#define SS second

const lli mod = 1e9 +7;
lli d, dp[10002][2][2][101];
string l="1", r;

lli solve(int level, int tlo, int thi, int rem)
{
	if(level>=r.size()){
		if(rem==0) return 1;
		return 0;
	}
	if(dp[level][tlo][thi][rem]==-1){
		int blo=0, bhi=9;
		lli ans=0;
		if(tlo==1)
			blo = l[level]-'0';
		if(thi==1)
			bhi = r[level]-'0';
		for(int i=blo; i<=bhi; i++)
		{
			int nlo=tlo, nhi=thi;
			if(i>l[level]-'0')
				nlo=0;
			if(i<r[level]-'0')
				nhi=0;
			ans += solve(level+1, nlo, nhi, (rem+i)%d);
			ans %= mod;
		}
		dp[level][tlo][thi][rem] = ans;
	}
	return dp[level][tlo][thi][rem];
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> r >> d;
	while(l.size()<r.size())
		l+='0';
	reverse(l.begin(), l.end());
	memset(dp, -1, sizeof(dp));
	cout << solve(0, 1, 1, 0);
}

Measured memory_bytes: 36136
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        sc.close();
        
        int count = 0;
        
        for(int i = 0; i < str.length(); i++){
            String tempStr = String.valueOf(str.charAt(i));
            
            if(tempStr.equals("1")){
                count++;
            } 
        }
        
        System.out.println(count);
    }
}


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

struct Point { double x, y; };

void koch(int n, Point a, Point b) {
  if (n == 0) return;

  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}

int main() {
  Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N = 1e5+7;
int T,n,m;
VI a;
int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> T;
    rep(i,1,n+1){
        int x, y;
        cin >> x >> y;
        if(y<=T){
            a.push_back(x);
        }
    }
    if(a.size()==0)
        puts("TLE");
    else
    {
        sort(a.begin(), a.end());
        printf("%d\n", a[0]);
        
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#include <assert.h>
#define FOR(i,a,n) for(i=(a);i<(n);i++)
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define LOCAL
#ifdef LOCAL
    #define DEBUG(...) printf(" "__VA_ARGS__)
#else
    #define DEBUG(...)
#endif /* LOCAL */
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
int x[100000];
int main(void)
{
	int n,k,i;
	ll l,r,res=1e18;
	scanf("%d%d",&n,&k);
	FOR(i,0,n) scanf("%d",&x[i]);
	FOR(i,0,n-k+1){
		l=x[i],r=x[i+k-1];
		if(l>=0) res=MIN(res,r);
		else if(r<=0) res=MIN(res,-l);
		else{
			res=MIN(res,2*(-l)+r);
			res=MIN(res,-l+2*r);
		}
	}
	printf("%lld\n",res);
	return 0;
}
    
    
    
    
    

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s; cin >> s;
	if(s[2]==s[3]&&s[4]==s[5])cout << "Yes" << endl;
	else cout << "No" << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


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

int main() {
  int N, K, count=0, ans=0, re;
  string S;
  cin >> N >> K >> S;

  vector<int> T;
  if (S.at(0) == '0') T.push_back(0);
  for (int i=0; i<S.size()-1; i++) {
    if (S.at(i) == S.at(i+1)) count++;
    else {
      T.push_back(count+1);
      count = 0;
    }
  }
  T.push_back(count+1);

  //for (int i=0; i<T.size(); i++) cout << T.at(i) << endl;
  vector<int> U(T.size() + 1);
  U.at(0) = 0;
  for (int i=0; i<T.size(); i++) {
    U.at(i+1) = U.at(i) + T.at(i);
  }

  for (int i=0; i<U.size(); i+=2) {
    re = i + 2*K + 1;
    if (re >= U.size()) re = U.size() - 1;
    ans = max(ans, U.at(re) - U.at(i));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1272
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000000
#define kaigyou <<"\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define endl "\n"
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
typedef long long int lli;
using namespace std;

int main()
{
  int N,M,C;
  scanf("%d%d%d",&N,&M,&C);

  vector<int> B(M);
  int A;
  

  int sm;
  int cnt;
  
  REP(i,M)
    {
      scanf("%d",&B[i]);
      
    }

  cnt = 0;
  
  REP(j,N)
    {
      sm = C;
      
      REP(i,M)
	{
	  scanf("%d",&A);
	  sm += A*B[i];
	  
	}
      if(sm > 0)
	{
	  ++ cnt;
	  
	}
    }

  printf("%d\n",cnt);
  

}


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

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


}

Measured memory_bytes: 256
def main():
    X = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = int(input())
    return X[K - 1]
print(main())

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  unordered_map<long, long> C;
  rep (i, N) {
    long a;
    cin >> a;
    C[a]++;
  }
  unordered_map<long, long> D;
  for (auto it: C) D[it.second]++;

  vector<long> accumFoo(N + 1, 0);
  for (long i = 1; i <= N; i++) accumFoo[i] = accumFoo[i-1] + i * D[i];

  vector<long> accumBar(N + 1, 0);
  accumBar[N] = D[N];
  for (long i = N - 1; i >= 0; i--) accumBar[i] = accumBar[i+1] + D[i];

  vector<long> asdf(N + 1, 0);
  asdf[0] = MOD;
  for (long i = 1; i <= N; i++) {
    long tmp = 0;
    tmp += accumFoo[i];
    if (i + 1 <= N) tmp += i * accumBar[i+1];
    tmp /= i;
    asdf[i] = tmp;
  }

  reverse(asdf.begin(), asdf.end());
  for (long i = 1; i <= N; i++) {
    auto it = lower_bound(asdf.begin(), asdf.end(), i);
    long ans = it - asdf.begin();
    ans = N - ans;
    cout << ans << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 34804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;
typedef long long ll;

const int MOD = 1e9+7;
const int INF = 1e9;
ll dp[105][123456];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,W;
    cin>>N>>W;
    vector<ll> w(N),v(N);
    rep(i,N)cin>>w[i]>>v[i];
    rep(i,N)rep(j,W+1){
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        if(j + w[i] > W)continue;
        dp[i+1][j + w[i]] = max(dp[i+1][j + w[i]], dp[i][j] + v[i]);
    }
    ll ans = dp[N][W];
    cout<<ans<<endl;
}

Measured memory_bytes: 97408
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

#define bzero(m)  memset(m,0,sizeof(m))
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

typedef unsigned long long u64;
typedef long long i64;


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

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

        vector<u64> h(n);
        REP(i,n)
                cin >> h[i];

        sort(h.begin(), h.end());

        u64 m = 0xffffffffff;
        REP(i,n-k+1) {
                m = min(m, h[i+k-1] - h[i]);
        }
        cout << m;

        return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#define INF (1e9)
#define cost first
#define node second
using namespace std;
typedef pair <int, int> P;
int n,m;
vector<P> G[101];

int prim(){
  int res = 0;
  bool visited[101]={};
  int D[101];
  for(int i=0;i<n;i++) D[i] = INF;
  priority_queue <P, vector<P>, greater<P> > Q;
  Q.push(P(0,0));
  while(!Q.empty()){
    P t = Q.top(); Q.pop();
    if(visited[t.node]) continue;
    visited[t.node] = true;
    res += t.cost;
    for(int i=0;i<G[t.node].size();i++){
      int nnode = G[t.node][i].node;
      int ncost = G[t.node][i].cost;
      if(D[nnode] > ncost) Q.push(P(ncost,nnode)),D[nnode]=ncost;
    }
  }
  return res;
}
void init(int n){
  for(int i=0;i<n;i++) G[i].clear();
}

int main() {
  while(1){
    cin >> n >> m;
    if(n == 0 && m ==0) break;
    init(n);
    for(int i=0;i<m;i++) {
      int a,b,c;
      cin >> a>>b>>c;
      G[a].push_back((P){c,b});
      G[b].push_back((P){c,a});
    }
    cout << prim()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = null;
		int[] num = new int[3];
		try {
			scan = new Scanner(System.in);
			for (int i = 0; i < num.length; i++) {
				num[i] = scan.nextInt();
			}
			Arrays.sort(num);
			StringBuffer sortlist = new StringBuffer();
			for (int i = 0; i < num.length; i++) {
				sortlist.append(num[i]);
				if (i < num.length - 1) {
					sortlist.append(' ');
				}
			}
			System.out.println(sortlist);
		} catch (InputMismatchException e) {
			System.out.println(e);
		} finally {
			scan.close();
		}
	}
}

Measured memory_bytes: 17172
void main(){
	
	auto NK = readLine!long();
	
	long[] list = new long[](cast(size_t)NK[0]);
	long K = NK[1];
	
	foreach( i ; 0..K ){
		auto type = readLine!int()[0];
		auto toList = readLine!int();
		foreach( to ; toList ){
			list[to-1] += type;
		}
	}
	
	list.count(0).writeln();
}



import std;

string alphabet = "abcdefghijklmnopqrstuvwxyz";

string readStr(){
	return readln().chomp();
}
T[] readLine( T = long )(){
	return readln().split().to!(T[])();
}

Measured memory_bytes: 3848
H,W=map(int,input().split())
A=[]
for h in range(H):
    A.append(list(map(str,input().split())))
A = [a for a in A if "#" in a[0]]
del_l=[]
for w in range(W):
    s="".join([a[0][w] for a in A])
    if "#" not in s:
        del_l.append(w)
for a in A:
    for w in range(W):
        if w not in del_l:
            print(a[0][w],end="")
    print()



Measured memory_bytes: 4468
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let n: u64 = s.trim().parse().unwrap();
    let m: u64 = (n as f64).sqrt() as u64;

    let mut v: Vec<(u64, u64)> = (1..(m+1)).map(|e| (e, n/e))
        .filter(|(e, _)| e*e <=n).collect();
    let x = v[v.len()-1];
    let mut ans = 0;
    if x.0 == x.1 {
        ans += x.0 * x.0 * (x.0+1) / 2;
    } else {
        v.push((x.1, x.0));
    }
    for i in 0..(v.len()-1) {
        ans += v[i].0 * v[i].1 * (v[i].1 + 1) / 2;
        ans += v[i].0 * (v[i].0 + 1) * (v[i].1 - v[i+1].1) * (v[i].1 + v[i+1].1 + 1) / 4;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2168
import math
def comb(n,m):
    p=1;q=1
    for i in range(m):p*=i+1;q*=n-i
    return q//p
n,m=map(int,input().split())
q=int(math.sqrt(m))
l=[True]*q
l[0]=False
for i in range(2,q+1):
    if l[i-1]:
        j=2
        while i*j<=q:l[i*j-1]=False;j+=1
p={}
for i in {(i+1)for i in range(q)if l[i]}:
    while 1:
        if m%i==0:p[i]=1+p[i]if i in p.keys()else 1;m//=i
        else:break
if m>1:p[m]=1+p[m]if m in p.keys()else 1
r=1
for v in p.values():r*=comb(v+n-1,v)
print(r%1000000007)

Measured memory_bytes: 3444
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
int DP[2002][2002],back[2002][2002];

template<typename T>
vector<T> LCS(const vector<T> &a,const vector<T> &b){
	memset(DP,0,sizeof(DP));
	memset(back,1,sizeof(back));
	for(int i=1;i<=(int)a.size();i++){
		for(int j=1;j<=(int)b.size();j++){
			if(a[i-1]==b[j-1]){
				if(DP[i][j]<DP[i-1][j-1]+1){
					DP[i][j]=DP[i-1][j-1]+1;
					back[i][j]=0;
				}
			}
			if(DP[i][j]<DP[i-1][j]){
				DP[i][j]=DP[i-1][j];
				back[i][j]=1;
			}
			if(DP[i][j]<DP[i][j-1]){
				DP[i][j]=DP[i][j-1];
				back[i][j]=-1;
			}
		}
	}
	int x=a.size(),y=b.size();
	vector<T> res;
	while(x>0&&y>0){
		if(back[x][y]==0){
			res.push_back(a[x-1]);
			x--;y--;
		}else if(back[x][y]>0)x--;else y--;
	}
	std::reverse(res.begin(),res.end());
	return res;
}
string LCS(const string &a,const string &b){
	vector<char> a_,b_,ret;
	for(int i=0;i<(int)a.size();i++)a_.push_back(a[i]);
	for(int i=0;i<(int)b.size();i++)b_.push_back(b[i]);
	ret=LCS(a_,b_);
	string res;
	for(int i=0;i<(ret.size());i++)
		res+=ret[i];
	return res;
}
int main() {
	string in;
	while(cin>>in){
		string a=in;
		reverse(a.begin(),a.end());
		cout<<LCS(a,in)<<endl;
	}

	return 0;
}

Measured memory_bytes: 31000
N = STDIN.gets.chomp.to_i
p = STDIN.gets.chomp.split(" ").map(&:to_i)

count = 0
for i in 1..(N-2)
  if p[i] < p[i+1] && p[i] > p[i-1] then
    count += 1
  elsif p[i] > p[i+1] && p[i] < p[i-1]
	count += 1
  end
end
  
puts count

Measured memory_bytes: 1788
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    ans=0
    for i in range(n):
        min_j=i
        for j in range(i+1,n):
            if aa[j]<aa[min_j]:min_j=j
        if min_j!=i:
            aa[i],aa[min_j]=aa[min_j],aa[i]
            ans+=1
    print(*aa)
    print(ans)

main()



Measured memory_bytes: 5616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, a, b; cin >> n >> a >> b;
    ll num = n/(a+b)*a;
    ll k = n%(a+b);
    cout << num + min(k,a) << endl;

    return 0;
}

Measured memory_bytes: 256
def c_count_order():
    from itertools import permutations
    N = int(input())
    P = tuple(int(i) for i in input().split())
    Q = tuple(int(i) for i in input().split())

    rank = {perm: k for k, perm in enumerate(permutations(range(1, N + 1), N), 1)}
    return abs(rank[P] - rank[Q])

print(c_count_order())

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

int main() {
  string s;
  int q;
  cin >> s >> q;
  
  bool isrev = false; //reverseがかかっていればtrue
  int t, f;
  string head = "", tail = "";
  char c;
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (t == 1) isrev = !isrev;
    else {
      cin >> f >> c;
      if ((!isrev && (f == 1)) || (isrev && (f == 2)))
        head += c;
      else
        tail += c;
    }
  }
  
  reverse(head.begin(), head.end());
  s = head + s + tail;
  
  if (isrev) 
    reverse(s.begin(), s.end());
   
  
  cout << s << endl;
}


Measured memory_bytes: 1348
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;

//	public static int min = 3000000;

	public static void main(String[] args) {

		double ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double h = sc.nextDouble();
		double m = sc.nextDouble();

//		String s = sc.next();

//		long k = sc.nextLong();

//		int[] a = new int[n];
//		for (int i = 0; i < n; i++) {
//			a[i] = sc.nextInt();
//		}

//		String s = sc.next();

//		int[] ans = new int[n];

//		ArrayList<Integer> list = new ArrayList<>();

		//-------------------------------------------------------------------------------------

//		if(h == m && h == 0) {
//			ans = 0;
//		} else {
			double ak = (30 *  h) + (0.5 * m);
			double bk = 6 * m;
			double kakudo = Math.abs(ak - bk);
			System.err.println(kakudo);
			ak = a * a;
			bk = b * b;
			double tmp = 2 * a * b * Math.cos(Math.toRadians(kakudo));
			ans = ak + bk - tmp;
			System.err.println(tmp);
			ans = Math.sqrt(ans);
//		}

		//-------------------------------------------------------------------------------------

//		if(!f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}



}

Measured memory_bytes: 37484
import math
s = list(map(int,input().split()))
a=s[0]
b=s[1]
h=s[2]
m=s[3]

min=h*60+m
place_a=math.radians(min*0.5)
place_b=math.radians(min*6%360)

ans = math.sqrt((b*math.cos(place_b)-a*math.cos(place_a))**2 +
                (b*math.sin(place_b)-a*math.sin(place_a))**2)
print(ans)


Measured memory_bytes: 9516
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var DL = ReadInts();
            var D = DL[0];
            var L = DL[1];

            WriteLine(D / L + D % L);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 17908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    string S;
    cin >> N >> S;
    int ans=0;
    rep(i,N){
        vector<bool> ex1(26,false),ex2(26,false);
        rep(j,i){
            ex1[S[j]-'a']=true;
        }
        rep2(j,i,N){
            ex2[S[j]-'a']=true;
        }
        int count=0;
        rep(j,26){
            if (ex1[j]&&ex2[j]){
                count++;
            }
        }
        ans=max(ans,count);
    }
    cout << ans << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<pii, int> para;
const int inf = 1e9 + 7;
const int maxN = 1e6 + 5;

int n, arr[maxN];
vi fours, twos, rest;

int main() {
	ios_base::sync_with_stdio(0);
	cin>>n;
	REP(i, n) {
		cin>>arr[i];
		if (arr[i] % 4 == 0) {
			fours.pb(arr[i]);
		} else {
			if (arr[i] % 2 == 0) {
				twos.pb(arr[i]);
			} else {
				rest.pb(arr[i]);
			}
		}
	}

	if (sz(rest) > sz(fours) + 1 || (sz(rest) == sz(fours) + 1 && sz(twos) > 0)) {
		cout<<"No\n";
	} else cout<<"Yes\n";
	return 0;
}


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

#define INF_MAX 	2147483647
#define INF_MIN 	-2147483648
#define INF 		(1 << 30)
#define SORT(a,n)   sort(a,a+n)
#define EPS			1e-9
#define PI 			acos(-1.0)
#define N 		    2 + 100
#define MOD			10000000007
#define sz(x) 		(int)(x).size()
#define all(x) 		(x).begin(), (x).end()
#define pb 			push_back
#define mp			make_pair
#define ms(x, a) 	memset((x), (a), sizeof(x))
#define ff           first
#define ss           second
#define rep(i,a,b)  for(int i=(a); i<(b); i++)
#define repC(i,x) 	for(size_t i=0; i<x.size(); i++)
#define repIT(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define nn          '\n'
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define i64 __int64
#define isValid(x, y) ( x >= 0 And x < row And y >= 0 And y < col )
#define dump cin.ignore()


typedef long long 		LL;
typedef pair<int,int> 	pii;
typedef vector<int> 	vi;
typedef vector<string> 	vs;
typedef vector<char>	vc;
typedef vector<bool>    vb;
typedef vector< pii >   vii;
typedef map<string,int> msi;
typedef map<int,int>	mii;
typedef map<char,int>   mci;
typedef map<int,string>	mis;

template<class T> T Abs(T x) {return x>0 ? x : -x;}
template<class T> T Max(T a, T b) {return a>b ? a : b;}
template<class T> T Min(T a, T b) {return a<b ? a : b;}
template<class T> T gcd(T a, T b) {return (b ? gcd(b,a%b) : a);}
template< class T > T sq(T x){ return x * x;}
template< class T > T lcm(T a, T b){ return (a / gcd<T>(a, b) * b); }
template< class T > T deb(T cmd) {cout << "debugger:" << endl; cout << cmd << endl;}
template< class T > T deb(T cmd1, T cmd2) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << endl;}
template< class T > T deb(T cmd1, T cmd2, T cmd3) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << "\t" << cmd3 << endl;}
template< class T > T deb(T cmd1, T cmd2, T cmd3, T cmd4) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << "\t" << cmd3 <<"\t" << cmd4 << endl;}
bool isVowel(char ch){ch=tolower(ch);return(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');}

//int dx[4] = {-1, 0, 0, 1};
//int dy[4] = {0, -1, 1, 0};
//int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
//int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

#define MAX 10000

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
	#endif

    vi v; int num;

    rep(i, 0, 5) cin >> num, v.pb(num);
    sort(v.rbegin(), v.rend());
    repC(i, v)
    {
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;

  return 0;
}

/*

3 6 9 7 5

*/

Measured memory_bytes: 1212
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
    ll n,a,b;
    std::cin >> n>>a>>b;
    std::cout << min(n*a,b) << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int main() {
  long long n,a[200020]={0},ans1=0,ans2=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if(ans1<a[i]) {
      ans1=ans2;
      ans1=a[i];
    }
    else if(ans2<a[i]) {
      ans2=a[i];
    }
  }
  for(int i=0; i<n; i++) {
    if(a[i]==ans1) {
      cout << ans2 << endl;
    }
    else {
      cout << ans1 << endl;
    }
  }
}

Measured memory_bytes: 3200