akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
minans = inf ;ans = 0 ;count = 0 ;pro = 1

L,n=map(int,input().split())
lrc=[]
for i in range(n):
    l,r,c=map(int,input().split()); l-=1; r-=1
    lrc.append((l,r,c))
lrc.sort(key=lambda tup:tup[1])
class Segment_Tree:
    __slots__ = ['ide_ele', 'size', 'num', 'seg', 'segfunc']

    def __init__(self, size, func, element):
        #####単位元######
        self.ide_ele = element
        self.size = size

        #num:n以上の最小の2のべき乗
        self.num = 2 ** (self.size - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        #####segfunc######
        self.segfunc = func

    def apply(self, apply_seq):
        #set_val
        for i in range(self.size):
            self.seg[i + self.num - 1] = apply_seq[i]    
        #built
        for i in range(self.num - 2, -1, -1) :
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) 
        
    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k-1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1],  self.seg[k * 2 + 2])
        
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2 
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res


dp=[inf]*L; dp[0]=0
seg=Segment_Tree(L,min,inf)
seg.apply(dp)
for l,r,c in lrc:
    dp[r]=min(dp[r],seg.query(l,r)+c)
    seg.update(r,dp[r])
print(dp[L-1] if dp[L-1] != inf else -1)
    
    

Measured memory_bytes: 122328
#include<bits/stdc++.h>
using namespace std;
int s[3]={-1,-1,-1};//ge shi bai
int main()
{
	int I,i,n,m,t,tt,II,flag=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){scanf("%d%d",&t,&tt);if(s[n-t]==-1||s[n-t]==tt)s[n-t]=tt;else flag=1;}
	if(flag)goto loop;
	if(n==1)I=0;else I=pow(10,n-1);II=pow(10,n);
	for(;I<II;I++)
	{
		//printf("I=%d\n",I);
		t=I%10;if(s[0]!=-1&&t!=s[0])continue;//ge wei
		t=I/10%10;if(s[1]!=-1&&t!=s[1])continue;//shi wei
		t=I/100;if(s[2]!=-1&&t!=s[2])continue;//bai wei
		printf("%d",I);
		return 0;
	}
	
	loop:printf("-1");
	return 0; 
} 

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

#define rep(i,n)  for(int i = 0; i < (int)(n); i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int n; std::cin >> n;

  ll ans = 0;
  for(int a=1; a<=n; a++) {
    ans += n/a;
    if ( n % a == 0 ) ans--;
  }
  std::cout << ans << std::endl;
  return 0;
}



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

int A, B, C;

void solve() {
  int result = C - (A - B);
  if (result > 0) printf("%d", result);
  else printf("%d", 0);
}

int main() {
  scanf("%d %d %d", &A, &B, &C);
  solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reve(a) reverse(a.begin(), a.end())
typedef long long ll;
const ll MOD = 1e9+7;

ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b){
  ll g = gcd(a, b);
  b /= g;
  a *= b;
  return a;
}

int main(){
  ll n, m, i=0, j=0;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  ll ans = lcm(n, m); 
  ll m1 = ans/n;
  ll m2 = ans/m;
  ll g = lcm(m1, m2);
  while(i<n){
    if(s.at(i)!=t.at(j)) ans = -1;
    i += m2;
    j += m1;
  }  
  cout << ans << endl;

}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInt()
	b := scanInt()

	fmt.Fprintln(wr, n/(a+b)*a+min(a,n%(a+b)))

}


Measured memory_bytes: 640
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve(){
	while (true) {
		int n, m;
		cin >> n >> m;
		if (n == 0) return;
		int dp[1002] = {};
		int left[1002] = {};
		left[0] = 1e9;
		for (int i = 1; i < 1002; ++i) {
			dp[i] = 1e9;
			left[i] = 1e9;
		}
		dp[0] = 0;
		REP(i, m) {
			int a, b;
			cin >> a >> b;
			left[b] = min(left[b], a);
		}
		for (int i = 0; i <= n; ++i) {
			int lefting = 1e9;
			for (int q = i; q <= n; ++q) {
				lefting = min(lefting, left[q]);
				dp[q + 1] = min(dp[q + 1], dp[i] + (q - i + 1LL) + max(0LL, 2LL * (q - lefting)));
			}
		}
		cout << dp[n+1] << endl;
		return;
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3232
N = int(input())
A = list(map(int, input().split()))[::-1]
for i in range(N - 1):
    if A[i] + 1 == A[i + 1]:
        A[i + 1] -= 1
    if A[i] < A[i + 1]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 14396
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] t = new int[N + 1];
		int[] x = new int[N + 1];
		int[] y = new int[N + 1];
		for (int i = 1; i <= N; i++) {
			t[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		for (int i = 1; i <= N; i++) {
			if (t[i] - t[i - 1] < Math.abs(x[i] - x[i - 1]) + Math.abs(y[i] - y[i - 1])) {
				System.out.println("No");
				return;
			} else if (((t[i] - t[i - 1]) - (Math.abs(x[i] - x[i - 1]) + Math.abs(y[i] - y[i - 1]))) % 2 != 0) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	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;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		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() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 24188
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<random>
#include<unordered_set>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const int big=1e16+10;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(b==0){return a;}return gcd(b,a%b);}//a>b
llint lcm(llint a,llint b){return (a/gcd(max(a,b),min(a,b)))*b;}
int main(void){
	llint bmax=1e10,bmin=1e9,gen;
	cout<<"? "<<bmin<<endl;char C;
	cin>>C;
	if(C=='Y'){
		bmax=1e9;//なんかバグらせそう
	}else{
		while(bmax-bmin!=1){
		//ここで自書式順序を示すはず
		gen=(bmax+bmin)/2;
		cout<<"? "<<gen<<endl;
		char c;
		cin>>c;
		if(c=='Y'){bmax=gen;}
		else{bmin=gen;}
		}
	}
	//bmax,bmax/10,bmax/100...
	llint ans=bmax;
	while(-1){
		if(ans/10==0){cout<<"! "<<ans<<endl;return 0;}
		cout<<"? "<<(ans/10)+1<<endl;
		char ch;cin>>ch;
		if((ch=='N')==((to_string((ans/10)+1)).size()==to_string(ans/10).size())){cout<<"! "<<ans<<endl;return 0;}
		ans/=10;
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define N 100005
#define M 1000000007
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define rep(i, begin, end) for( __typeof(end) i = (begin) -((begin) > (end)); i!=(end)-((begin) > (end));i+= 1-2*((begin) >(end)))
#define all(x) (x).begin(),(x).end()
#define Min(...) min({__VA_ARGS__})
#define Max(...) max({__VA_ARGS__})

using namespace std;
typedef long long ll;
int a[N];
int main(){
    ios_base::sync_with_stdio(0);
    int n,x;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int cnt =0;
    bool p=0;
    for(int i=1;i<=n;i++){
        if(i!=n&&a[i]==i&&a[i+1]==i+1){
            cnt ++;
            i++;
        }
        else if(a[i]==i){
            cnt++;
        }
    }
    /*
    if(a[n]==n&&!p)
        cnt ++;
        */
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

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

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int n;
const int MAX_N = 50;
string S[MAX_N];

int main(){
  cin >> n;
  REP(i, n) cin >> S[i];
  int ans[26];
  REP(i, 26) ans[i] = INFi;
  REP(i, n) {
    int ct[26];
    REP(i, 26) {
      ct[i] = 0;
    }
    REP(j, S[i].size()) {
      ct[S[i][j] - 'a']++;
    }
    REP(i, 26) {
      ans[i] = min(ans[i], ct[i]);
    }
  }

  REP(i, 26) {
    REP(j, ans[i]) {
      cout << char('a' + i);
    }
  }
  cout << endl;

  return 0;
}


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

int main() {
    int n, t;
    cin >> n;
    int x[n], y[n], h[n];
    rep(i, n) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] > 0) t = i;
    }

    rep(cx, 101) rep(cy, 101) {
        bool ok = true;
        int hx = h[t] + abs(x[t] - cx) + abs(y[t] - cy);
        rep(i, n) {
            if (h[i] != max(hx - abs(x[i] - cx) - abs(y[i] - cy), 0))
                ok = false;
        }
        if (ok) {
            printf("%d %d %d\n", cx, cy, hx);
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(ll i= (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N; cin >> N;
    string S; cin >> S;
    string ans = "";
    REP(i, S.length()) {
        if (S[i] + N <= 'Z') {
            ans += S[i] + N;
        } else {
            ans += S[i] + N - 26;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3680
<>;@a=glob<>;$\=1e9;map{$b[$s=@a]=@b=$N=$c=0;$c+=$N+=2*$_>$l+$\?-$b[++$s]:$b[$s--],$b[$s]++for@a;$c*4/@a>@a+1?$\:$l=$l+$\>>1}1..35;print

Measured memory_bytes: 28864
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long t,n,m,i,j,k,x,y,z,sum=0;
  cin>>n>>m>>x>>y;
  i=0;
  if(n%y==0)
  {
      k=n/y;
  }
  else
  {
      k=n/y+1;
  }
  if(x%m==0)
  {
      j=x/m;
  }
  else
  {
      j=x/m+1;
  }
  if(k>=j)
  {
      cout<<"Yes"<<endl;
  }
  else
  {
      cout<<"No"<<endl;
  }
  return 0;
} 

Measured memory_bytes: 3624
#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++)
typedef long long Int;


int main() {
  
  int N, K;
  cin >> N >> K;
  int cnt = 0;
  rep(i,N) {
    int h;
    cin >> h;
    if (h >= K) cnt++;
  }
  
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    while(true){
       int i,j,k,n,x,tem=0;
       cin >> n >> x;
       if(n == 0 && x == 0)break;
       for(i=1;i<=n-2;i++){
           for(j=i+1;j<=n-1;j++){
               for(k=j+1;k<=n;k++){
                   if((i+j+k == x) && (i!=j || j!=k ||i!=k))tem = tem+1;
               }
           }
       }
       cout << tem << endl;
    }
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define sll set<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define fo(i,n) for(i=0;i<n;i++)
using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    ll n,i,j,k,t,q;

    cin>>k;

    cout<<50<<endl;

    if(k<50)
    {
        cout<<k*50<<" ";
        fo(i,49)
            cout<<0<<" ";
        return 0;
    }

    ll a,b;
    a=k/50+50;
    b=k%50;

    fo(i,50)
    {
        if(i<b)
            cout<<a<<" ";
        else
            cout<<a-1<<" ";
            a--;
    }

    return 0;
}


Measured memory_bytes: 256
#include<set>
#include<stack>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<cstring>

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

using namespace std;

int main(){
	int m; scanf("%d",&m);
	char name[100][21];
	int lb[100],ub[100];
	rep(i,m) scanf("%s%d%d",name[i],lb+i,ub+i);

	int n; scanf("%d",&n);
	stack< set<int> > S;
	while(n--){
		char s[21]; scanf("%s",s);
		int i;
		for(i=0;i<m;i++) if(strcmp(s,name[i])==0) break;
		if(i<m){ // 変数
			set<int> A;
			for(int x=lb[i];x<=ub[i];x++) A.insert(x);
			S.push(A);
		}
		else if(isdigit(s[0])){ // 定数
			set<int> A;
			A.insert(atoi(s));
			S.push(A);
		}
		else{ // 演算子
			set<int> B=S.top(); S.pop();
			set<int> A=S.top(); S.pop();
			set<int> C;
			set<int>::iterator it,jt;
			for(it=A.begin();it!=A.end();++it) for(jt=B.begin();jt!=B.end();++jt) {
				switch(s[0]){
					case '+': C.insert(((*it)+(*jt))%256);     break;
					case '-': C.insert(((*it)-(*jt)+256)%256); break;
					case '*': C.insert(((*it)*(*jt))%256);     break;
					case '/': if(*jt==0){ puts("error"); return 0; }
							  C.insert(((*it)/(*jt))%256);
				}
			}
			S.push(C);
		}
	}

	puts("correct");

	return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  set<char> s;
  string S;
  cin >> S;
  s.insert(S[0]);
  s.insert(S[1]);
  s.insert(S[2]);
  cout << (s.size() == 3 ? "Yes":"No") << endl;
}

Measured memory_bytes: 256
while(True):
  height,width = map(int,input().split())
  if height == 0 and width == 0:
    break
  else:
    for i in range(height):
      for j in range(width):
        if i % 2  == 0:
          if j % 2 == 0:
            print("#",end ="")
          else:
            print(".",end ="")
        else:
          if j % 2 == 0:
            print(".",end ="")
          else:
            print("#",end ="")
      print()
    print()


Measured memory_bytes: 7000
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8101145141919364364;

int main(){
	int n; cin>>n;
	string r,s1,s2;
	string eins[]={".",".","#","#"};
	string zwei[]={".","#",".","#"};
	bool side=1;
	while(1){
		rep(i,4){
			string tmp1=(side?s1+eins[i]:eins[i]+s1);
			string tmp2=(side?s2+zwei[i]:zwei[i]+s2);
			cout<<tmp1<<"\n"<<tmp2<<"\n"; fflush(stdout);
			cin>>r;
			if(r=="end") return 0;
			if(r=="T"){
				s1=tmp1;
				s2=tmp2;
				break;
			}else if(i==3){
				side=0;
				break;
			}
		}
		int x=s1.size();
		if(x==n){
			cout<<s1<<"\n"<<s2<<"\n"; fflush(stdout);
			cin>>r;
			if(r=="end") return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 724
# cook your dish here
s=input()
aa=s[:2]
bb=s[2:]
#print(aa,bb)
aa=int(aa)
bb=int(bb)
if aa<=12 and bb<=12 and aa>0 and bb>0:
    print("AMBIGUOUS")
elif aa<=12 and aa>0:
    print("MMYY")
elif bb<=12 and bb>0:
    print("YYMM")
else:
    print("NA")
    


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [list(map(int, input().split())) for i in range(m)]
ans = sum(t)
for i in range(m):
    print(ans + px[i][1] - t[px[i][0] - 1])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ld long double

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    ld k = 0.01;
    ll p = 100, x, sum = p, ans = 0;
    cin >> x;
    while(sum < x) {
        sum = sum + floor(1.0 * k * sum);
        ans++;
    }
    cout << ans;
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>



using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

const ll mod = 1000000007;

using namespace std;

int main() {
	int n, m;

	cin >> n >> m;

	ll work_day = 0;

	rep(i , m) {
		ll day;
		cin >> day;
		work_day += day;
	}
	
	if (work_day > n) {
		cout << -1 << endl;
	} else {
		cout << n - work_day << endl;
	}

 	return 0;
}


Measured memory_bytes: 3160
#include <iostream>
using namespace std;
int main(void){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  
  int ans = 0;
  
  while(a >= b){
    b *= 2;
    ans++;
  }
  
  while(b >= c){
    c *= 2;
    ans++;
  }
  
  if(ans <= k) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int n, k;
  cin >> n >> k;
  cout << k * int(pow(k - 1, n - 1)) << endl;
}


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

int main() {
  string s;
  cin >> s;

  int s1 = s.size();
  if(s.at(s1 - 1) == 's') {
    s.push_back('e');
    s.push_back('s');
  }
  else {
    s.push_back('s');
  }
  
  cout << s << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  for(int i=A;i<=B;i++){
    int k1 = i % 10;
    int k2 = (i / 10) % 10;
    int k4 = (i / 1000) % 10;
    int k5 = (i / 10000) % 10;
    if(k1 == k5 && k2 == k4) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long long int n,t,tmpa=0,tmpb=0,i,ret=0;
  scanf("%lld%lld",&n,&t);
  for(i=1;i<n;i++){
    scanf("%lld ",&tmpa);
    if(i!=1){
      ret += (tmpa-tmpb>t)?t:(tmpa-tmpb);
    }
    tmpb = tmpa;
  }
  scanf("%lld",&tmpa);
  ret += (tmpa-tmpb>t)?t:(tmpa-tmpb);
  printf("%lld\n",ret+t);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long n,ans=1,la,zj,nw;
int main()
{
	cin>>n;cin>>la;
	for(int i=2;i<=n;i++)
	{
		cin>>nw;
		if(nw>la)
		{
			if(zj==0)
				zj=1;
			else if(zj==-1)
			{
				zj=0;
				ans++;
			}
		}
		if(nw<la)
		{
			if(zj==0)
				zj=-1;
			else if(zj==1)
			{
				zj=0;
				ans++;
			}
		}
		la=nw;
	}
	cout<<ans;
}

Measured memory_bytes: 384
$,=$";$k=-($K=<>)&3;print$n=$K+3>>2<<1,$K-1?map{map{($t=($'+$_)%$n)+1+($'%2?$n-$k:$t<$n-$k?0:$K-$n)}//..$n}1..$n:(1)x4

Measured memory_bytes: 11264
#include<iostream>
using namespace std;
int main(){
    int m,f,r;
    while(1){
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1)break;
        if(m==-1||f==-1)cout<<"F"<<endl;
        else if(m+f>=80)cout<<"A"<<endl;
        else if(m+f>=65&&m+f<80)cout<<"B"<<endl;
        else if(m+f>=50&&m+f<65)cout<<"C"<<endl;
        else if(m+f>=30&&m+f<50&&r>=50)cout<<"C"<<endl;
        else if(m+f>=30&&m+f<50)cout<<"D"<<endl;
        else if(m+f<30)cout<<"F"<<endl;
    }return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::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 == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int high = -1;
	int ans = 0;
	REP(i, N) {
		int H;
		cin >> H;
		if (H >= high) {
			chmax(high, H);
			ans++;
		}
		
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define pb push_back
#define F first
#define S second
#define ll long long 
#define ld long double 

#define int long long int

const int mod = 1e9+7;
const ll inf = 1e18; 
 
int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n, int r){ int C[r+1]; memset(C, 0, sizeof(C)); C[0] = 1; for(int i = 1; i <= n; i++) {int t=i;if(r<t)t=r; for (int j = t; j > 0; j--) C[j] = C[j] + C[j-1]; }return C[r];} 
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}

int min(int a , int b){return a < b ? a : b;}
int max(int a , int b){return a > b ? a : b;}

using namespace std;


signed main(){

	 ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n , k;
	cin >> n >> k;
	int a[n];
	for(int i = 0 ; i < n ; i++)
		cin >> a[i];
	
	int dp[k+1] = {};
	dp[0] = 1;
	
	for(int i = 0 ; i < n ; i++){
		int prefix_sum[k+1] = {};
		for(int given = 0 ; given <= k ; given++){
			int mini = given + 1;
			int maxi = given + min(a[i] , k-given);
			
			if(mini <= maxi){
				prefix_sum[mini] = (prefix_sum[mini] + dp[given])%mod;
				if(maxi+1 <= k)
					prefix_sum[maxi+1] = (prefix_sum[maxi+1] - dp[given] + mod)%mod;
			}
	
		}
		
		for(int j = 0 ; j <= k ; j++){
			if(j)
				prefix_sum[j] = (prefix_sum[j] + prefix_sum[j-1])%mod;
			dp[j] = (dp[j] + prefix_sum[j])%mod;
		}
	}
	
	cout << dp[k];
}










Measured memory_bytes: 5216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int k,s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0;i <= k;i++){
    for (int j = 0; j <= k;j++){
      if (s-i-j >= 0 &&  s-i-j <= k) ans++;
    }
  }
  cout << ans << endl;
  

  
  return 0;
  
}


Measured memory_bytes: 3620
N, M = map(int, input().split())
A=[]
for _ in range(N):
    A.append(input())
B=[]
for _ in range(M):
    B.append(input())
#print(A)
#print(B)

success=0
for right in range(N-M+1):
    for down in range(N-M+1):
        count=0
        for x in range(M):
            for y in range(M):
                if A[down+y][right+x]==B[y][x]:
                    count+=1
        if count==M*M:
            success=1

if success==1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[10];
int main(){
	scanf("%s",in);
	for(int i=0;i<4;i++){
		if(in[i]=='A'&&in[i+1]=='C'){
			printf("Yes\n");return 0;
		}
	}
	printf("No\n");
}

Measured memory_bytes: 128
##AtCoder Group Contestの参加者に 3N人が参加します。 
##i番目の参加者の 強さ は整数 aiで表されます。
##参加者が 3人 1組となるようにチームを N組作ることにしました。
##1人の参加者が複数のチームに所属することはできません。

##入力は以下の形式で標準入力から与えられる。
##N
##a1 a2 ... a3N
n = gets.chomp.to_i
a_n = gets.chomp.split(" ").map(&:to_i).sort
# p a_n

##チームの強さはチームメンバーの強さのうち 2番目に大きい値で表されます。
##強さが 1,5,2のメンバーからなるチームの強さは 2になり、
##強さが 3,2,3のメンバーからなるチームの強さは 3になります。

##N組のチームの強さの和としてありうる値のうち、最大の値を求めてください。
sum = 0
idx = n
n.times do
  # p idx
  sum += a_n[idx]
  idx += 2
end

p sum

Measured memory_bytes: 30700
import math

def isPrime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i += 2
    return True

count = 0
n = int(input())
for i in range(0,n):
    flg = isPrime(int(input()))
    if flg:
        count += 1

print(count)


Measured memory_bytes: 5672
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
double PI = 3.141592653589793238;
vector<vector<int>>G(100030);
int main() {
	int n, m, x;
	cin >> n >> m >> x;
	int cs[100] = {};
	int argo[100][100] = {};
	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		cs[i] = c;
		for (int j = 0; j < m; j++) {
			int a;
			cin >> a;
			argo[i][j] = a;
		}
	}
	int ans = 100000000;
	for (int i = 0; i < (1 << n); i++) {
		int sumarugo[100] = {};
		int sumvalue = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				//cout << bitset<10>(i) << " " << j << endl;
				sumvalue = sumvalue + cs[j];
				for (int k = 0; k < m; k++) {
					sumarugo[k] = sumarugo[k] + argo[j][k];
					//cout << sumarugo[k] << endl;
				}
			}
		}
		for (int j = 0; j < m; j++) {
			if (sumarugo[j] < x) {
				break;
			}
			if (j == m - 1) {
				ans = min(ans, sumvalue);
			}
		}
	}
	if (ans == 100000000) {
		cout << -1;
	}
	else {
		cout << ans;
	}
}

Measured memory_bytes: 5496
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


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

  ll N;
  cin >> N;

  vector<double> x(N), y(N);
  REP(i,N){ cin >> x[i] >>y[i]; }

  double ans = 0;
  REP(i,N-1){
    REP3(j,i+1,N){
      double s = (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
      ans += sqrt(s) * 2;
    }
  }
  ans = ans / N;
  cout << setprecision(10) << fixed << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int>buka(N);  
  vector<int>joshi(N); 
  for(int i=1;i<N;i++){
    cin>>joshi.at(i);
    buka.at(joshi.at(i)-1)++;
  }
  for(int i=0;i<N;i++)
    cout<<buka.at(i)<<endl;
}


Measured memory_bytes: 4844
# Max sum
A, B, C = list(map(int,input().strip().split(' ')))
K = int(input().strip())
v = [A,B,C]
import itertools
nums = [0,1,2]
o = 0
for i in itertools.combinations_with_replacement(nums,K):
    tmp = [v[0],v[1],v[2]]
    for j in i:
        tmp[j] = tmp[j]*2
    o = max(o,sum(tmp))
print(o)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include<map>
using namespace std;

//typedef long long signed int ll
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(),(obj).end()

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int N;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	map<int, int> Works;
	int a, b;
	REP(i, N) {
		cin >> a >> b;
		Works[b] += a;
	}
	int sum = 0;
	for(auto itr = Works.begin(); itr != Works.end(); ++itr) {
		sum += itr->second;
		if (sum > itr->first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n, d;
  cin >> n >> d;
  int a = d * 2 + 1;
  cout << (n + a - 1) / a << endl;
}

Measured memory_bytes: 256
loop do
    n = gets.to_i
    break if n == 0
    qu = []
    n.times do
        line = gets.chomp.split
        l = line.shift
        pr,a,b,c,d,e,f,s,m = line.map(&:to_i)
        be = m*s*f-pr
        tm = a+b+c+(d+e)*m
        qu << [-Rational(be,tm),l]
    end
    qu.sort!.each do |r,l|
        puts l
    end
    puts '#'
end



Measured memory_bytes: 6936
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
//#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
	int n; cin >> n;
	int i, j, k, u, count=0;
	vector<int> rod;
	for( i=0; i<n; i++ ){
		cin >> u;
		rod.push_back(u);
	}
	sort( rod.begin(), rod.end(), greater<int>() );
	for( i=0; i<n-2; i++ ){
		for( j=i+1; j<n; j++ ){
			for( k=j+1; k<n; k++ ){
				if( rod[k] > rod[i] - rod[j] ){
				count++;
				}
			}
		}
	}
	cout << count << endl;
	return 0;
}

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

int main(){

  int a,b,c,i,j,k,n,sum;
  
  int result=0,p;
  
  while(1){
    result = 0;
    
    cin >>n >>sum;
    
    if(n == 0 && sum == 0)break;
    
    for(i=1;i<=n;i++)
      {
	for(j=i+1;j<=n;j++)
	  {
	    for(k=j+1;k<=n;k++)
	      {
		p = i + j + k;
		if(p == sum){
		  result++;
		}
	      }
	  }
      }
    cout <<result <<"\n" ;
    
  }
  return 0;
  
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int n,m;
   cin>>n>>m;
   if(n==1||m==1)
   {
      cout<<1;
   }
   else
      cout<<(n*m+1)/2;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }


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

int main(){
    string str;
    list<char> l;
    list<char>::iterator itr;
    int n;
    bool reverse=false;
    cin>>str>>n;
    for(int i=0;i<str.length();i++){
        l.push_back(str[i]);
    }
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        if(t==1){
            reverse=!reverse;
        }else{
            int f;
            char s;
            cin>>f>>s;
            if(reverse){
                if(f==1){
                    l.push_back(s);
                }else{
                    l.push_front(s);
                }
            }else{
                if(f==2){
                    l.push_back(s);
                }else{
                    l.push_front(s);
                }
            }
        }
    }
    if(!reverse){
        for(itr=l.begin();itr!=l.end();itr++){
            cout<<*itr;
        }
    }else{
        itr=l.end();
        itr--;
        while(1){
            if(itr==l.begin()){
                cout<<*itr;
                break;
            }
            cout<<*itr;
            itr--;
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 9984
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
		int b = sc.nextInt();
      	int c = sc.nextInt();
      
      	if(c-(a-b) > 0) System.out.println(c-(a-b));
      	else System.out.println(0);
    }
}

Measured memory_bytes: 35620
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

int const inf = 1<<29;
int H, W;
vector<vector<char>> fi;
vector<vector<int>> dist;

int d1[4] = {0,0,1,-1};
int d2[4] = {1,-1,0,0};

void input(){
    cin >> H >> W;
    fi.resize(H+5, vector<char>(W+5, '.'));
    dist.resize(H+5, vector<int>(W+5, inf));
    repr(i, 1, H+1) repr(j, 1, W+1) cin >> fi[i][j];
}

void solve(){
    queue<pair<int, int>> qu;
    repr(i, 1, H+1) repr(j, 1, W+1) {
        if(fi[i][j] == '#'){
            qu.push(make_pair(i, j));
            dist[i][j] = 0;
        }

        
    }

    while(!qu.empty()){
        auto p = qu.front(); qu.pop();
        rep(k, 4){
            int ni = p.first + d1[k];
            int nj = p.second + d2[k];
            if(1<=ni && ni<=H && 1<=nj && nj<=W && dist[ni][nj] > dist[p.first][p.second]+1){
                dist[ni][nj] = dist[p.first][p.second] + 1;
                qu.push(make_pair(ni, nj));
            }
        }
    }

    int ans = 0;
    repr(i, 1, H+1) repr(j, 1, W+1) chmax(ans, dist[i][j]);
    cout << ans << endl;
}

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

    input();
    solve();
    
    return 0;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<P,int>P2;

int n,nA,nB,nC,x,y,m;
vector<P>v[100009];
vector<int> A,B,C;
set<int>sA,sB,sC;

P d1[100009];
P d2[100009];
P d3[100009];

void dij1(){
    priority_queue<P2,vector<P2>,greater<P2> >q;
    r(i,100009)d1[i]=P(1e8,1e8);
    q.push(P2(P(0,1e9),A[0]));
    d1[A[0]]=P(0,1e9);
    while(!q.empty()){
        P2 p=q.top();q.pop();
        P cost = p.first;
        int now = p.second;
        if(d1[now]<cost)continue;
        r(i,v[now].size()){
            P pp=v[now][i];
            int nex=pp.first;
            P co=P(pp.second+cost.first,min(cost.second,nex));
            if(d1[nex]<=co)continue;
            d1[nex]=co;
            q.push(P2(co,nex));
        }
    }
}

void dij2(){
    priority_queue<P2,vector<P2>,greater<P2> >q;
    r(i,100009)d2[i]=P(1e8,1e8);
    q.push(P2(P(0,1e9),B[0]));
    d2[B[0]]=P(0,1e9);
    while(!q.empty()){
        P2 p=q.top();q.pop();
        P cost = p.first;
        int now = p.second;
        if(d2[now]<cost)continue;
        r(i,v[now].size()){
            P pp=v[now][i];
            int nex=pp.first;
            P co=P(pp.second+cost.first,min(cost.second,nex));
            if(d2[nex]<=co)continue;
            d2[nex]=co;
            q.push(P2(co,nex));
        }
    }
}
void dij3(){
    priority_queue<P2,vector<P2>,greater<P2> >q;
    r(i,100009)d3[i]=P(1e8,1e8);
    q.push(P2(P(0,1e9),C[0]));
    d3[C[0]]=P(0,1e9);
    while(!q.empty()){
        P2 p=q.top();q.pop();
        P cost = p.first;
        int now = p.second;
        if(d3[now]<cost)continue;
        r(i,v[now].size()){
            P pp=v[now][i];
            int nex=pp.first;
            P co=P(pp.second+cost.first,min(cost.second,nex));
            if(d3[nex]<=co)continue;
            d3[nex]=co;
            q.push(P2(co,nex));
        }
    }
}


signed main(){
    cin>>n>>nA>>nB>>nC;
    r(i,nA){
        cin>>x; x--;
        A.push_back(x);
        sA.insert(x);
        v[n].push_back(P(x,0));
        v[x].push_back(P(n,0));
    }
    r(i,nB){
        cin>>x; x--;
        B.push_back(x);
        sB.insert(x);
        v[n+1].push_back(P(x,0));
        v[x].push_back(P(n+1,0));
    }
    r(i,nC){
        cin>>x; x--;
        C.push_back(x);
        sC.insert(x);
        v[n+2].push_back(P(x,0));
        v[x].push_back(P(n+2,0));
    }
    cin>>m;
    r(i,m){
        cin>>x>>y; x--; y--;
        v[x].push_back(P(y,1));
        v[y].push_back(P(x,1));
    }

    dij1();
    dij2();
    dij3();

    P ans=P(1e9,1e9);

    r(i,n){
        P tmp=P(0,i);
        r(j,3){
            int MIN=1e9;
            if(j==0)MIN=min(MIN,d1[i].first) , tmp.second=min(tmp.second,d1[i].second);
            if(j==1)MIN=min(MIN,d2[i].first) , tmp.second=min(tmp.second,d2[i].second);
            if(j==2)MIN=min(MIN,d3[i].first) , tmp.second=min(tmp.second,d3[i].second);
            tmp.first+=MIN;
        }
        ans=min(ans,tmp);
    }
    cout<<ans.first<<' '<<ans.second+1<<endl;

}


Measured memory_bytes: 20232
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, v: "List[int]"):
    v.sort()
    curr = (v[0] + v[1])/2
    for i in range(2, N):
        curr = (curr + v[i])/2
    print(curr)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, v)


if __name__ == '__main__':
    main()


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



signed main(){
    int n;
    cin>>n;
    if(n==3){
        
        cout <<"2 5 63";
       
    }
    else{
        int sum=5,i=2;
        cout <<4<<' ';
        sum+=4;i++;
        int t=0,k=5;
        while(i<n&&k<30000){
            cout <<k<<' ';sum+=k;
            i++;k+=30;
        }
        k=25;
        while(i<n&&k<30000){
            cout <<k<<' ';sum+=k;
            i++;k+=30;
        }
        k=9;
        while(i<n&&k<30000){
            cout <<k<<' ';sum+=k;
            i++;k+=6;
        }
        k=6;
        while(i<n&&k<30000){
            cout <<k<<' ';sum+=k;
            i++;k+=2;
        }
        int r=30 - sum%30;
        if(r%2==0){
            cout <<3<<' ';
            if(r==30)cout <<2;
            else cout <<30000-30+(r+2);
        }else{
            cout <<30000<<' ';
            cout << 29940+r+5;
        }


    }

    return 0;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort()
f.sort()
a = a[::-1]
kaketa = []
for i in range(n):
    kaketa.append(a[i]*f[i])

left = 0
right = max(kaketa)

while True:
    jiku = (left+right)//2
    kaisuu = 0
    for i in range(n):
        if kaketa[i] - jiku > 0:
            if (kaketa[i] - jiku) % f[i] != 0:
                kaisuu += (kaketa[i] - jiku) // f[i] + 1
            else:
                kaisuu += (kaketa[i] - jiku) // f[i]
    if kaisuu > k:
        left = jiku
    else:
        right = jiku
    if right - left == 1:
        break

if sum(a) <= k:
    print(0)
else:
    print(right)

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

    double l;
    cin >> l;
    cout << setprecision(7) << fixed << pow(l / 3, 3);
}


Measured memory_bytes: 4156