akhauriyash/Code-Regression huggingface dataset:
a, b = map(int, input().split())
x, y = max(a, b), min(a, b)
z = x % y
ans = 0

while 1:
    if z == 0:
        z = y
        break
    elif z >= y:
        break
    else:
        y, z = z, y % z

for i in range(z, 0, -1):
    if y % i == 0 and z % i == 0:
        ans = i
        break

print(ans)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;

	int mae = N + 1;
	double kotae = 0;
	int kaisuu = 1;
	rep1(i, 20) {
		int k = min(N + 1, (K + kaisuu - 1) / kaisuu);
		int kazu = mae - k;
		kotae += kazu * 1.0 / N / kaisuu;
		kaisuu *= 2;
		mae = k;
	}

	cout << fixed << setprecision(12) << kotae << endl;

	Would you please return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  long double a;
  while(cin >> a) {
    long double ret = 0;
    FOR(i, 1, 11) {
      ret += a;
      if(i%2) a *= 2;
      else a /= 3;
    }
    cout << fixed << setprecision(15) << ret << endl;
  }

  return 0;
}

Measured memory_bytes: 3256
#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<deque>
#include<cmath>
#include<set>
#include<cstring>
#include<string.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
//----------------
#define int long long
//----------------
inline int read()
{
    int x = 0, f = 1;char ch = getchar();
    while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}
    while (ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();}
    return x * f;
}
#define sdf(x) x=read()
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define FFor(i, a, b) for (int i = (a); i >= (b); i--)
#define me(a, b) memset(a, b, sizeof(a))
#define mid ((l + ((r - l)/2)))
#define random(a, b) ((a) + rand() % ((b) - (a) + 1))
#define bg1(x) cout<<(#x)<<":"<<(x)<<" "<<endl
#define bg2(x,y) cout<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<endl
#define bg3(x,y,z) cout<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<(#z)<<":"<<(z)<<" "<<endl
#define bg4(x,y,z,w) cout<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<(#z)<<":"<<(z)<<" "<<(#w)<<":"<<(w)<<" "<<endl
#define bg5(x,y,z,w,k) cout<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<(#z)<<":"<<(z)<<" "<<(#w)<<":"<<(w)<<" "<<(#k)<<":"<<(k)<<" "<<endl
#define call(x) cout<<x<<":"
#define lll cout<<"\n------\n"
int die = 0;
#define Die die++;if(die>100000){cout<<"dead!!!";exit(0);}
#define mk make_pair
#define pb push_back
const double eps = 1e-8;
// srand((unsigned)time(NULL));
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

int n,k;
char s[N];

void sol1(){
    s[k]=s[k]-'A'+'a';
    printf("%s", s+1);
}

void rd(){
    sdf(n),sdf(k);
scanf("%s",s+1);
    sol1();
}

signed main()
{

    rd();
}



Measured memory_bytes: 888
# Dinic's algorithm
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
dinic = Dinic(n*2+2)
for i in range(n):
    c,d = map(int,input().split())
    for j in range(n):
        if ab[j][0] < c and ab[j][1] < d:
            dinic.add_edge(i+1,n+j+1,1)
    dinic.add_edge(0,i+1,1)
    dinic.add_edge(n+i+1,2*n+1,1)
ans = dinic.flow(0,2*n+1)
print(ans)

Measured memory_bytes: 43248
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { Integer.parseInt(it) }.toTypedArray()
    val b = readLine()!!.split(" ").map { Integer.parseInt(it) }.toTypedArray()

    var ans = 0
    for (k in 29 downTo 0) {
        var count = 0L
        val powk = 1.shl(k)

        /* this code is assumed answer, but cause TLE :(
         * maybe O(NlogN) *//*
        for (i in 0 until n) {
            val ai = a[i]
            val t1 = b.lowerbound(powk - ai)
            val t2 = b.lowerbound(powk*2 - ai)
            count += t2 - t1
            val t3 = b.lowerbound(powk*3 - ai)
            val t4 = b.size
            count += t4 - t3
        }
        *//* end */

        /* this code is faster than above code, why????????*/
        var r1 = 0
        var r2 = 0
        var r3 = 0
        for (i in n - 1 downTo 0) {
            val ai = a[i]
            while (r1 < n && (ai + b[r1]) < powk) r1 += 1
            while (r2 < n && (ai + b[r2]) < 2 * powk) r2 += 1
            while (r3 < n && (ai + b[r3] < 3 * powk)) r3 += 1
            count += r2 - r1 + n - r3
        }
        /* end */

        for (index in 0 until n) {
            a[index] %= powk
            b[index] %= powk
        }
        a.sort()
        b.sort()

        ans += (count % 2).toInt().shl(k)
    }
    println(ans)
}

fun Array<Int>.lowerbound(key: Int): Int {
    return this.binarySearch(key, Comparator { o1: Int, o2: Int -> if (o1 >= o2) 1 else -1 }).inv()
}

Measured memory_bytes: 157832
//from Kuugo
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
 
int nn,mm,n,l[N],r[N],f[N],g[N],ans;
 
struct node{int x,y;}a[N];
vector<node> ql,qr;
bool cmp(node a,node b){return a.y<b.y;}

int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}

void build(int t,int x,int y){
	l[t]=x;r[t]=y;
	if (x==y){f[t]=nn-a[x].y;return;}
	build(2*t,x,(x+y)/2);
	build(2*t+1,(x+y)/2+1,y);
	g[t]=0;f[t]=max(f[2*t],f[2*t+1]);
}
 
void modify(int t,int x,int y,int z){
	if (x<=l[t]&&y>=r[t]) {f[t]+=z;g[t]+=z;return;};
	if (x<=r[2*t]) modify(2*t,x,y,z);
	if (y>=l[2*t+1]) modify(2*t+1,x,y,z);
	f[t]=max(f[2*t],f[2*t+1])+g[t];
}
 
void solve(){
	sort(a+1,a+n+1,cmp);
	build(1,0,n);
	ql.clear();ql.push_back((node){0,-1});ql.push_back((node){0,0});
	qr.clear();qr.push_back((node){nn,-1});qr.push_back((node){nn,0});
	for (int i=1;i<=n;i++){
		ans=max(ans,(f[1]+a[i].y)*2);
		if (a[i].x<=nn/2){
			for (int j=ql.size()-1;j&&ql[j].x<=a[i].x;ql.pop_back(),j--)
				modify(1,ql[j-1].y+1,ql[j].y,ql[j].x-a[i].x);
			ql.push_back((node){a[i].x,i-1});
		}
		else {
			for (int j=qr.size()-1;j&&qr[j].x>=a[i].x;qr.pop_back(),j--)
				modify(1,qr[j-1].y+1,qr[j].y,a[i].x-qr[j].x);
			qr.push_back((node){a[i].x,i-1});
		}
		ql.push_back((node){0,i});
		qr.push_back((node){nn,i});
	}
	ans=max(ans,(f[1]+mm)*2);
}
int main(){
	nn=read();mm=read();n=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	solve();
	for (int i=1;i<=n;i++) swap(a[i].x,a[i].y);
	swap(mm,nn);solve();
	printf("%d\n",ans);
	return 0;
}

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

long long n;

int main() {
	cin >> n;
  if (n&1) return puts("0"), 0;
    long long ans = 0;
    n /= 2;
    while (n > 0) {
        n /= 5;
        ans += n;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3608
def d_all_your_paths_are_different_lengths(L):
    # l=2から始めて、lを2倍するか+1するかを何回か行ってLにしたい。
    # その回数を最小にするには、Lから始めて、Lが偶数なら2で割って奇数なら1引くことを
    # 繰り返した回数を調べればいい。
    do = []  # 2からLにするには*2と+1をどのように行えばいいか？
    while L > 2:
        if L % 2 == 0:
            do.append('*2')
            L >>= 1
        else:
            do.append('+1')
            L -= 1
    do.reverse()

    # 解説(英語版の Solution 2.)に従って辺を構成
    vertex = 2  # 現時点での頂点数
    edge = [[1, 2, 0], [1, 2, 1]]  # L=2のときはこのようにつなぐ他ない
    l = 2
    for op in do:
        if op == '*2':
            # 各辺の長さを2倍、新しい頂点に長さ0,1の辺をつなぐ
            edge = [[v1, v2, c * 2] for v1, v2, c in edge]
            edge.append([vertex, vertex + 1, 0])
            edge.append([vertex, vertex + 1, 1])
            vertex += 1
            l *= 2
        elif op == '+1':
            # 先頭と末尾の頂点に長さlの辺をつなぐ
            edge.append([1, vertex, l])
            l += 1

    # 出力形式に沿った文字列を構成
    ans = '{} {}\n'.format(vertex, len(edge))
    ans += '\n'.join([' '.join(map(str, row)) for row in edge])
    return ans

L = int(input())
print(d_all_your_paths_are_different_lengths(L))


Measured memory_bytes: 3064
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
void addself(ll &a,ll b)
{
	a+=b;
	if(a>=M)
	{
		a-=M;
	}
}
void subself(ll &a,ll b)
{
	a-=b;
	if(a<0)
	{
		a+=M;
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,k;
    cin>>n>>k;
    std::vector<ll> v(n);
    for(ll& x:v)
    {
    	cin>>x;
    }
    std::vector<ll> dp(k+1,0);
    dp[0]=1;
   	for (ll z:v)
    {
    	std::vector<ll> fake(k+1);
    	for (int i = k; i >=0; --i)
    	{
    		int L=i+1;
    		int R=i+min(z,k-i);
    		if(L<=R)
    		{
    			addself(fake[L],dp[i]);
    			if(R+1<=k)
    				subself(fake[R+1],dp[i]);
    		}
    	}
    	addself(dp[0],fake[0]);
    	for (int i = 1; i <=k; ++i)
    	{
    		addself(fake[i],fake[i-1]);
    		addself(dp[i],fake[i]);
    	}
    }
    cout<<dp[k]%M<<'\n';	
}


Measured memory_bytes: 1792
import java.util.Scanner;
import java.math.*;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int x=sc.nextInt();
        int n=sc.nextInt();
        int count1=0;
        int count2=0;
        int plus=0;
        int minus=0;
        int flg=0;
        if(n==0){
            System.out.println(x);
        }else{
        int[] list = new int[n];
        for(int i=0; i<list.length; i++){
            list[i]=sc.nextInt();
        }
        while(true){
            for(int i=0; i<list.length; i++){
                if(list[i]==x+plus){
                    plus++;
                }
            }
            count1++;
            if(count1>plus){
/*                System.out.println(plus+" "+count1);
*/                break;
            }
        }
        while(true){
            for(int i=0; i<list.length; i++){
                if(list[i]==x+minus){
                    minus--;
                }
            }
            count2--;
            if(count2<minus){
/*                System.out.println(minus+" "+count2);
*/
                break;
            }
        }
        flg=plus+minus;
        if(flg>=0){
            System.out.println(x+minus);
        }else if(flg<0){
            System.out.println(x+plus);
        }
    }
}
}

Measured memory_bytes: 35760
n,x,y=map(int,input().split())

ans=[0 for _ in range(n-1)]

for i in range(n-1):
  for j in range(i+1,n):
    t=i+1
    u=j+1
    H=min(abs(u-t),abs(t-x)+1+abs(y-u),abs(t-y)+1+abs(x-u))
    ans[H-1]+=1
    
for l in ans:
  print(l)


Measured memory_bytes: 74772
n = int(input())
a, b = [], []
for _ in range(n):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)
a.sort()
b.sort()
if n % 2 == 1:
    print(b[n // 2] - a[n // 2] + 1)
else:
    print(b[n // 2] + b[n // 2 - 1] - a[n // 2] - a[n // 2 - 1] + 1)

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

const int MOD = (int)1e9+7;

int main(){
	long long N,M;
	cin >> N >> M;
	vector<long long> A(N);
	for(int i=0;i<N;i++)	cin >> A.at(i);

	vector<long long> sum(N+1,0);
	for(int i=0;i<N;i++)	sum.at(i+1)=sum.at(i)+A.at(i);

	long long ans=0;
	map<long long,long long> mp;
	for(int i=0;i<N+1;i++){
		long long xx=sum.at(i)%M;
		if(mp.count(xx))	ans+=mp.at(xx);
		mp[xx]++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main()
{
    int a;
    cin>>a;
    a=a%10;
    switch(a){
    case 2 :
    case 4 :
    case 5 :
    case 7 :
    case 9 : cout<<"hon\n"; break;
    case 0 :
    case 1 :
    case 6 :
    case 8 : cout<<"pon\n"; break;
    case 3 : cout<<"bon\n"; break;
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;cin>>n;
	ll a[n+1];
	for (int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	int ans=0;
	for (int i=1;i<=n-2;i++)
	for (int j=i+1;j<=n-1;j++)
	for (int k=j+1;k<=n;k++)
	if (a[i]<a[j] && a[j]<a[k] && a[i]+a[j]>a[k]) ans++;
	cout<<ans;
}

Measured memory_bytes: 3644
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define MOD 1000000007
const int N = 2000005;


int main()
{
    ll n;
    cin >> n;
    ll a[n+1],b[n+1][21];
    memset(b,0,sizeof(b));
    for(ll i=1;i<=n;i++)    cin >> a[i];
    for(ll i=20;i>=0;i--)
    {
        for(ll j=1;j<=n;j++)
        {
            if((a[j]&(1<<i)))    b[j][i] = 1;
        }
    }
    for(ll i=0;i<21;i++)
    {
        for(ll j=1;j<=n;j++)   b[j][i] = b[j][i] + b[j-1][i];
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
        ll low = 1,high = i;
        ll ans1=-1;
        while(low<=high)
        {
            ll mid = (low + high)/2;
            ll chk = 1;
            for(ll j=0;j<21;j++)
            {
                if(b[i][j] - b[mid-1][j]>1)   chk = 0;
            }
            if(chk)
            {
                high = mid-1;
                ans1 = mid;
            }
            else   low = mid+1;
        }
        ans += (i - ans1 + 1);
    }
    cout<<ans;
}

Measured memory_bytes: 34688
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll;
#define pb push_back
#define endl        '\n'
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
   ll N;
   cin>>N;
   int a=0;
   int aa=0;
   for(int i=0;i<N;i++)
   {
       int x;
       cin>>x;
       a=a+x;
       aa=aa+x*x;
   }
   cout<<(a*a-aa)/2;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int t=n,c=0;
    while(t>0)c+=t%10,t/=10;
    if(n%c==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
url = "https://atcoder.jp/contests/abc090/tasks/arc091_a"
import copy
def main():
    tate, yoko = list(map(int, input().split()))
    count = 0
    if tate == 1 and yoko == 1:
        print("1")
        exit()
    elif tate == 1:
        print(yoko - 2)
        exit()
    elif yoko == 1:
        print(tate - 2)
        exit()
    count += (yoko - 2) * (tate - 2)
    print(count)




if __name__ == '__main__':
    main()




Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
int main() {
int A,B,C;
cin >> A >> B >> C;
    if(A+B==C) cout << "Yes" << endl;
    else if(B+C==A) cout << "Yes" << endl;
    else if(C+A==B) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int n, t, ans=0;
bool isprime(int x) {
    for (int i=2; i<=sqrt(x); i++) {
        if (x%i==0) return 0;
    }
    return 1;
}

int main() {
    cin >> n;
    while (n--) {
        cin >> t;
        if (isprime(t)) ans++;
    }
    cout << ans << "\n";
}


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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define FILE "file"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const ull ULLINF = numeric_limits<ull>::max();
const double PI = acos(-1.0);

int a[100010];

int main()
{
//    freopen(FILE".in", "r", stdin);
//    freopen(FILE".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 0;
    for(int i = 0; i + 1 < n; i++)
        if(a[i] == i + 1)
            swap(a[i], a[i + 1]), ans++;
    if(a[n - 1] == n)
        ans++;
    cout << ans;
    return 0;
}


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

string S;
int Q;

int main(){
  cin >> S >> Q;
  int n = S.size();
  deque<char> deq(n);
  rep(i, n) deq[i] = S[i];
  
  bool rev = 0; //true : reversed
  rep(i, Q){
    int t; cin >> t;
    if(t == 1){
      rev = !rev;
      continue;
    }
    int tmp;
    char c;
    cin >> tmp >> c;
    tmp--;
    bool f = tmp;
    if(rev ^ f){
      deq.push_back(c);
    }else{
      deq.push_front(c);
    }
  }
  if(rev) reverse(deq.begin(), deq.end());
  for(auto c : deq) cout << c;
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 896
import math
def myAnswer(K:int,A:int,B:int) -> int:
   if(K <= A-1): return K+1
   tmp =(K - (A-1))
   # print(tmp)
   ans = (B - A) * math.floor(tmp//2) + tmp % 2 + A
   # print(ans)
   return max(ans,K+1)



def modelAnswer():
   return
def main():
   K,A,B = map(int,input().split())
   print(myAnswer(K,A,B))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
using namespace std;

long long int A,B,K;
int main (){
    cin >> A >> B >> K;
    while( K ) {
        if( A % 2 ) A--;
        A /= 2;
        B += A;
        K--;
        if( K == 0 ) break;
        if( B % 2) B--;
        B /= 2;
        A += B;
        K--;
    }
    cout << A << " " << B << endl;
    return 0;
}


Measured memory_bytes: 256
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


const int mx =2e5+123;
int a[mx];

int main()
{
    optimize();


    int n, ans = 1;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) cin >> a[i];

    for ( int i = 1; i <= n; i++ ) {
        if ( a[i] == ans ) ans++;
    }

    if ( ans == 1 ) cout << -1 << endl;
    else cout << n - ans + 1 << endl;

    return 0;
}


















Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top = 0, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop(void) {
  top--;
  return S[top+1];
}

int main(void) {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF) {
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}


Measured memory_bytes: 2088
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoderSolve
{
    class Solve
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Math.Abs(p[0] - p[1]) < Math.Abs(p[0] - p[2]) ? "A" : "B");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 11348
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <list>
using namespace std;
#include <stdio.h>
#include <map> 
#include <algorithm>
#include <functional>
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>



int main()
{
	int N;
	std::map<std::string, int> m;
	cin >> N;

	for (int i = 0; i < N; ++i) {
		std:string s;
		cin >> s;
		auto q = m.find(s);
		if (q != m.end()) {
			q->second += 1;
		} else {
			
			m.insert(std::make_pair(s, 0));
		}
	}

	auto itr = m.begin();
	int cc = 0;

	for (auto a : m) {
		if (a.second > cc) {
			cc = a.second;
		}
	}
	for (auto a : m) {
		if (a.second == cc) {
			printf("%s\n", a.first.c_str());
		}
	}

	return 0;
}




Measured memory_bytes: 25216
#include <stdio.h>

#define MAX 100
#define MAXVAL 2000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int main(){
  int n, i, j, u, k, v, c, min;
  int col[MAX], arr[MAX];

  scanf("%d", &n);

  int d[n];
  int g[n][n];

  for( i=0; i<n; i++){
    d[i] = 0;
    arr[i] = MAXVAL;
    col[i] = WHITE;
    for( j=0; j<n; j++){
      g[i][j] = MAXVAL;
    }
  }

  arr[0] = 0;
  col[0] = GRAY;

  for( i=0; i<n; i++){
    scanf("%d %d", &u, &k);
    for( j=0; j<k; j++){
      scanf("%d %d", &v, &c);
      g[u][v] = c;	
    }
  }

  while(1){
    min = MAXVAL;
    u = -1;

    for( i=0; i<n; i++){
      if( min > arr[i] && col[i] != BLACK ){
	u = i;
	min = arr[i];
      }
    }

    if( u == -1 )break;

    col[u] = BLACK;

    for( i=0; i<n; i++){
      if( col[i] != BLACK && g[u][i] != MAXVAL ){
	if( arr[i] > (arr[u] + g[u][i]) ){
	  arr[i] = arr[u] + g[u][i];
	  col[i] = GRAY;
	}
      }
    }
  }

  for( i=0; i<n; i++){
    printf("%d ", i);
    if( arr[i] == MAXVAL ) arr[i] = -1;
    printf("%d\n", arr[i]);
  }

  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <cstdio>
#include <cstdint>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int_fast64_t ll;

ll M, d, c, sd = 0, sc = 0, A;
const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char readchar() {
    if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
    return *ci++;
}
 
inline ll readint() {
	A = 0;
	if (ci - cn + 16 > cm) while ((ct = readchar()) >= '0') A = A * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
    return A;
}

int main() {
    M = readint();
    REP(i, M) {
        d = readint();
        c = readint();
        sd += d * c; sc += c;
    }
    printf("%lld\n", --sc + --sd / 9);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n,m=0; cin>>n;
  vi h(n); rep(i,n) cin>>h[i];
  rep(i,n){
    if(m-1>h[i]){
      cout<<"No"<<endl;
      return 0;
    }
    m=max(h[i],m);
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,m,fa[N],a[N];
int find(int x)
{
	if(x==fa[x])
		return x;
	int t=fa[x];
	int ft=find(t);
	a[x]+=a[t];
	return fa[x]=ft;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    	fa[i]=i,a[i]=0;
	ll u,v,d;
    bool ok=true;
    while(m--)
    {
    	cin>>u>>v>>d;
    	ll x=find(u),y=find(v);
    	if(x!=y)
    	{
    		if(x>y)
			{
				fa[x]=y;
				a[x]=a[v]-(a[u]+d);
			}		
			else
			{
				fa[y]=x;
				a[y]=a[u]-(a[v]-d);
			}
		}
		else 
		{
			ll t=a[v]-a[u];
			if(t!=d)
				ok=false;
		}
	}
	for(int i=1;i<=n;i++)
	{
		find(i);
		if(a[i]>1e9)
			ok=false;
	}
	puts(ok?"Yes":"No");
    
	    

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main(){
    long N,K,R,S,P;
    string T;
    string choice="";
    char buf;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    long point=0;
    for(int i = 0; i<N;i++){
        switch(T[i]){
            case 'r':
                if(i < K){
                    point+=P;
                    choice+="p";
                }else{
                    if(!(*(choice.end()-K)=='p')){
                        point+=P;
                        choice+="p";
                    }else{
                        choice+="q";
                    }
                }
            break;
            case 'p':
                if(i<K){
                    point+=S;
                    choice+="s";
                }else{
                    if(!(*(choice.end()-K)=='s')){
                        point+=S;
                        choice+="s";
                    }else{
                        choice+="q";
                    }
                }
            break;
            case 's':
            if(i<K){
                point+=R;
                choice+="r";
            }else{
                if(!(*(choice.end()-K)=='r')){
                    point+=R;
                    choice+="r";
                }else{
                    choice+="q";
                }
            }
        }
    }
    cout << point << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n, m, x, y;
    cin >> n >> m >> x >> y;

    int min_x = 101;
    int max_x = -101;
    REP(i, n) {
        int input;
        cin >> input;
        min_x = min(min_x, input);
        max_x = max(max_x, input);
    }

    int min_y = 101;
    int max_y = -101;
    REP(i, n) {
        int input;
        cin >> input;
        min_y = min(min_y, input);
        max_y = max(max_y, input);
    }

    if (x < y && max_x + 1 <= min_y && x < min_y && y >= min_y) {
        P("No War");
    }
    else {
        P("War");
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<=s.length();i++){
		if(((i+1)%2)==0){
			if(s[i]=='R'){
				printf("No");
				return 0;
			}
				
		}
		else{
			if(s[i]=='L'){
				printf("No");
				return 0;
			}
		}		
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#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()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int main()
{
  int N, H, W;
  cin >> N >> H >> W;
  int A[N];
  int B[N];
  int cnt = 0;
  REP(i,N){
    cin >> A[i] >> B[i];
    if (A[i] >= H && B[i] >= W){
      cnt++;
    }
  }
  cout << cnt;


  return 0;
}


Measured memory_bytes: 256
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

# x軸側にr回、y軸側にl回動くとすると、最終的な到達マスは
# (x,y) = (2r+l, r+2l)
# 2r + l == X
# r + 2l == Y
# ∴ r = (2X-Y)/3, l = (2Y-X)/3 
def main():

    X,Y = [int(i) for i in input().split(" ")]

    # そもそも到達不可能
    if (2*X-Y) < 0 or (2*Y-X) < 0 or (2*X-Y)%3 > 0 or (2*Y-X)%3 > 0:
        print(0)
        return 0

    # コンビネーション計算
    else:
        r = (2*X-Y)//3
        l = (2*Y-X)//3
        n = r+l
        
        a = cmb(n,r)
        print(a%(int(1e9+7)))
        return 0


main()

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

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

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  string x = s;
  REP (i, s.size()) {
    x = s[s.size() - 1] + s.substr(0, s.size() - 1);
    if (s == t) {
      cout << "Yes" << endl;
      exit(0);
    }
    s = x;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
string a="",b="",c="";
std::cin >> a>>b>>c;
std::cout << a[0]<<b[1]<<c[2] << '\n';
}


Measured memory_bytes: 256
import javax.swing.*;
import java.io.*;
import java.sql.Struct;
import java.text.DecimalFormat;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(rd.readLine());
        int[] arr = new int[n];
        StringTokenizer s = new StringTokenizer(rd.readLine());
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(s.nextToken());
        }
        long[][] dp = new long[n + 1][n + 1];

        for (int i = 0; i < n; i++) {
            dp[i][i] = arr[i];
        }

        for (int i = 2; i < n + 1; i++) {
            for (int j = 0; j <= n - i; j++) {
                int start = j;
                int end = start + i - 1;
                dp[start][end] = Math.max(-dp[start + 1][end] + arr[start], -dp[start][end -1]+arr[end]);

            }
        }

        System.out.println(dp[0][n - 1]);
    }
}

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, W, w, v;
  ll dp[101][100000];
  memset(dp, -1, sizeof(ll) * 101 * 100000);
  dp[0][0] = 0;
  cin >> n >> W;
  for(int i = 0; i < n; i++) {
    cin >> w >> v;
    for(int j = 0; j <= W; j++) {
      if(dp[i][j] != -1) {
        if(j + w <= W) dp[i + 1][j + w] = max(dp[i][j] + v, dp[i + 1][j + w]);
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
      }
    }
  }
  ll o = 0;
  for(int i = 0; i <= W; i++) o = max(o, dp[n][i]);
  cout << o << '\n';
}

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

int main(){
	int w, h, x, y, r;
	scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
	if(x+r <= w && x-r >= 0 && y-r >= 0 && y+r <= h)
		printf("Yes\n");
	else
		printf("No\n");
}



Measured memory_bytes: 3160
///
// File:  d.go
// Author: ymiyamoto
//
// Created on Sun Jun 10 21:21:55 2018
//
package main

import "fmt"

var N, C int

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func main() {
	fmt.Scan(&N, &C)

	colors := make([][]int, C+1)
	for i := 1; i <= C; i++ {
		colors[i] = make([]int, C+1)
		for j := 1; j <= C; j++ {
			fmt.Scan(&colors[i][j])
		}
	}

	g0 := map[int]int{}
	g1 := map[int]int{}
	g2 := map[int]int{}
	for i := 1; i <= N; i++ {
		for j := 1; j <= N; j++ {
			var c int
			fmt.Scan(&c)
			switch (i + j) % 3 {
			case 0:
				g0[c]++
			case 1:
				g1[c]++
			case 2:
				g2[c]++
			}
		}
	}

	ans := int64(1 << 30)
	for i := 1; i <= C; i++ {
		for j := 1; j <= C; j++ {
			for l := 1; l <= C; l++ {
				if i != j && j != l && l != i {
					var tmp int64
					for k, v := range g0 {
						tmp += int64(colors[k][i] * v)
					}
					for k, v := range g1 {
						tmp += int64(colors[k][j] * v)
					}
					for k, v := range g2 {
						tmp += int64(colors[k][l] * v)
					}
					ans = min(ans, tmp)
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7684
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  map<ll,int> mp;
  int a;

  rep(i,N){
    cin >> a;
    mp[a]++;
  }
  int ans=0;
  for(auto x:mp){
    if(x.second%2==1)ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define DEBUG

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

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7, maxn = (5 * 1e5) + 10, maxm = (3e6) + 2;
const double PI = acos(-1);
vector<ll> seg(4*maxn, 0), ans(maxn), vs(maxn);
vector<pii> qs[maxn];

void update(int i, int l, int r, int pos, int val){
    if (l == r){
        seg[i] = val;
    }
    else {
        int mid = (l+r)/2;
        if (pos <= mid) update(2*i, l, mid, pos, val);
        else update(2*i+1, mid+1, r, pos, val);
        seg[i] = seg[2*i] + seg[2*i+1];
    }
}

int query(int i, int l, int r, int ql, int qr){
    if (qr < l || ql > r) return 0;
    if (ql <= l and r <= qr) return seg[i];
    int mid = (l+r)/2;
    return query(2*i, l, mid, ql, qr) + query(2*i+1, mid+1, r, ql, qr);
}

void solve (int n){
    vector<int> last(maxn, -1);

    for(int r=1; r<=n; r++){
        if (last[vs[r]] != -1) update(1, 1, n, last[vs[r]], 0);
        last[vs[r]] = r;
        update(1, 1, n, r, 1);
        // cout << "OK" << endl;
        // cout << qs[r].size() << endl;
        for (auto it: qs[r]){
            int pos, l;
            tie(l, pos) = it;
            ans[pos] = query(1, 1, n, l, r);
        }
    }
}
int main (){
    ios_base::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;

    for (int i=1; i<=n; i++) cin >> vs[i];  
    for (int i=0; i<q; i++){
        int l, r;
        cin >> l >> r;
        qs[r].push_back({l, i});
    }

    solve(n);
    // cout << query(1, 1, n, 1, n) << endl; 

    for (int i=0; i<q; i++){
        cout << ans[i] << endl;
    }
    return 0;   
}

Measured memory_bytes: 53268
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
  Comb(){
    fac = new ll[1000001];
    finv = new ll[1000001];
    inv = new ll[1000001];
    fac[0] = 1;
    for(int i=1;i<1000001;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000001;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000001;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  ll n;
  cin >> n;
  string s;
  cin >> s;
  set<int> table[26];
  for(int i=0;i<n;i++){
    int index = s[i]-'a';
    table[index].insert(i+1);
  }

  int q;
  cin >> q;
  int type;
  vector<int> ansL;
  for(int i=0;i<q;i++){
    cin >> type;
    if(type == 1){
      int l;
      char c;
      cin >> l >> c;
      if(s[l-1] == c) continue;
      int num = c - 'a';
      int beforeNum = s[l-1]-'a';
      table[beforeNum].erase(l);
      table[num].insert(l);
      s[l-1] = c;
    }
    else{
      int l,r;
      cin >> l >> r;
      int ans = 0;
      for(int j=0;j<26;j++){
        auto itr = table[j].lower_bound(l);
        if(itr == table[j].end() || *itr > r) continue;
        ans++;
      }
      ansL.push_back(ans);
    }
  }
  for(int i=0;i<ansL.size();i++){
    cout << ansL[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 24452
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
char str[11000];
vector<int>li[10000];
int cur;
int calc(int a){
	//printf("%d %d\n",a,cur);fflush(stdout);
	int ret=0;
	if(str[cur]>='0'&&str[cur]<='9'){
		while(str[cur]>='0'&&str[cur]<='9'){
			ret*=10;
			ret+=str[cur]-'0';
			cur++;
		}
		return (ret+1)/2;
	}
	li[a].clear();
	while(str[cur]=='['){
		cur++;
		li[a].push_back(calc(a+1));
		cur++;
	}
	std::sort(li[a].begin(),li[a].end());
	for(int i=0;i<(li[a].size()+1)/2;i++)ret+=li[a][i];
	return ret;
}
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		scanf("%s",str);
		cur=0;
		printf("%d\n",calc(0));
	}
}

Measured memory_bytes: 1328
#include<bits/stdc++.h>
 
using namespace std;
 
void solve(int TestCase) {
    int k, n;
    cin >> k >> n;
    
    auto A = vector<int>(n);
    for(auto& x : A)
        cin >> x;
    
    sort(A.begin(), A.end());
    
    int ret = k;
    for(auto i = 0; i < n-1; ++i)
    {
        ret = min(ret, k - (A[i+1] - A[i]));
    }

    ret = min(ret, -A[0] + A.back());
    cout << ret << endl;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    int i;
    for(i=1;i<1010;i++)
    {
        int x=i*0.08;
        int y=i*0.1;
        if(x==a&&y==b)
        {
            cout<<i;
            break;
        }
    }
    if(i==1010)
        cout<<-1;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

const int R = 1000000007;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> xs(n);
  vector<int> ys(m);
  for (int i = 0; i < n; ++i) cin >> xs[i];
  for (int i = 0; i < m; ++i) cin >> ys[i];

  long xsize = 0;
  for (int x = 1; x < xs.size(); ++x) {
    long dx = xs[x] - xs[x - 1];
    xsize += dx * x * (xs.size() - x);
    xsize %= R;
  }
  long ysize = 0;
  for (int y = 1; y < ys.size(); ++y) {
    long dy = ys[y] - ys[y - 1];
    ysize += dy * y * (ys.size() - y);
    ysize %= R;
  }
  cout << (xsize * ysize) % R << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
// Author : Pham Ngoc Minh - 12 Tin - CTB
// The Way To Progress Is To Constantly Try
using namespace std;
#define f first
#define s second
#define ll long long
#define fl float
#define db double
#define ii pair<ll,ll>
#define pii pair<ii,ii>
#define ford(i,a,b) for(int i=a;i<=b;i++)
#define foru(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,a,b) for(int i=a;i<b;i++)
#define oo 10000000000001
#define ooo -1000000000001
#define bost  ios_base::sync_with_stdio(false); cin.tie(0);
int main()
{
    bost
    int a,b,c;
    cin>>a>>b>>c;
    int nuocthua=a-b;
    if(nuocthua>0){
        if(c>=nuocthua) c-=nuocthua;
        else c=0;
        cout<<c;
        return 0;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> V;
const long long MOD=1000000007LL;
const long long INFL=1LL << 60;
const int INF=1<<29;


int main() {
    int N;
    cin >>N;
    V p(N);
    for(int i=0;i<N;i++){
        cin>>p.at(i);
    }
    int cnt=0;
    for(int i=0;i<N-2;i++){
        if((p.at(i)<p.at(i+1)&&p.at(i+1)<p.at(i+2))
        ||(p.at(i+2)<p.at(i+1)&&p.at(i+1)<p.at(i))) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

bool solve(Int n, vector<Int> &a){
	if(a.front() + 1 < a.back()) return false;
	if(a.front() == a.back()) return a.front() <= n / 2 || a.front() == n-1;
	Int cnt = 0;
	for(auto i:a)
		if(i == a.front())
			++cnt;
	return cnt + 1 <= a.back() && a.back() <= cnt + (n - cnt) / 2;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n; cin >> n;
	vector<Int> a(n);
	a.resize(n);
	for(auto &i:a) cin >> i;
	sort(a.begin(), a.end());
	if(solve(n, a)) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#define N 101000
int n,m,o,p,q,e[100][100],sta,i,g[N],dp[N][100],sum;
int main()
{
	scanf("%d %d",&n,&m);
	for (i=1;i<=m;i++)
	{
		scanf("%d %d %d",&o,&p,&q);
		e[o][p]=q,e[p][o]=q;sum+=q;
	}
	for (sta=0;sta<(1<<n);sta++)
	{
		for (i=1;i<=n;i++) if (sta&(1<<(i-1)))
		for (int j=i+1;j<=n;j++) if (sta&(1<<(j-1)))
		if (e[i][j]) g[sta]+=e[i][j];
	}
//	pri(g,(1<<n));
	for (sta=0;sta<(1<<n);sta++) for (i=1;i<=n;i++) dp[sta][i]=-inf;
	dp[1][1]=0;
	for (sta=0;sta<(1<<n);sta++)
		for (i=1;i<=n;i++)
		{	
			int now=sta^(1<<(i-1));
			for (int j=1;j<=n;j++) if (now&(1<<(j-1))&&e[i][j]) 
				dp[sta][i]=max(dp[sta][i],dp[now][j]+e[i][j]);
			for (int t=now;t;t=(t-1)&now) 
			{
				dp[sta][i]=max(dp[sta][i],dp[sta^t][i]+g[t|(1<<(i-1))]);
			}
		//	if (dp[sta][i]>=0)printf("dp[%d][%d]=%d\n",sta,i,dp[sta][i]);
		}
	int ans=-inf;
	for (i=0;i<(1<<n);i++) ans=max(ans,dp[i][n]);
	printf("%d\n",sum-ans);
}

Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, a[100100], b[100100];
vector<pii > v;

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
        v.pb(mk(a[i] + b[i], i));
    }
    sort(v.rbegin(), v.rend());
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(i % 2){
            ans -= b[v[i].second];
        }
        else {
            ans += a[v[i].second];
        }
    }
    cout << ans << endl;

}
/*


*/




Measured memory_bytes: 3444
n,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
t=0
for i in range(n):
  for j in range(i+1,n):
    s=0
    for b,c in zip(a[i],a[j]):
      s+=(b-c)**2
    if s**0.5==int(s**0.5):
      t+=1

print(t)

Measured memory_bytes: 9448