akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

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

int calc(std::string s, int k) {
	if (k == 4) {
		return s.empty() ? 1 : 0;
	}
	if (s.empty()) return 0;
	if (s.front() == '0') {
		return calc(s.substr(1), k + 1);
	}
	int res = 0;
	REP(i, 3) {
		if (std::stoi(s.substr(0, i + 1)) <= 255) {
			if (s.size() <= i + 1) {
				res += calc("", k + 1);
				break;
			}
			else res += calc(s.substr(i + 1), k + 1);
		}
	}
	return res;
}

signed main() {
	std::string s;
	std::cin >> s;
	std::cout << calc(s, 0) << std::endl;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2);
}

void solve()
{
	int n , x;
	
	cin >> n;
	
	int cn = 0;
	
	for(int i = 1; i <= n; ++i) {
		cin >> x;
		
		if(i % 2 && x % 2) {
			cn++;
		}
	}
	
	cout << cn;
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"

using namespace std;
using ll = long long;

int main(void){
    Cin(string, a);
    //Cout();
    Cout((a[6] <= '4' && a[5] == '0') ? "Heisei" : "TBD");
    //Cout(() ? "YES" : "NO");
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        long K = cin.Long();
        long A = cin.Long();
        long B = cin.Long();
        long ans = 0;
        if (K == 1) ans = 2;
        else if (K >= 2 && B <= A + 2) ans = 1 + K;
        else {
            long now = 1;
            while(now < A) {
                now++;
                K--;
            }
            if (K >= 2) {
                now += (B - A) * (K / 2);
                K %= 2;
                now += K;
            }
            else {
                now += K;
            }
            ans = now;
        }
        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, T;
  cin >> N >> T;
  vl c(N), t(N);
  rep(i, N) cin >> c[i] >> t[i];

  ll cost = 10000;

  rep(i, N){
    if(t[i] <= T) cost = min(cost, c[i]);
  }

  if(cost == 10000)
    cout << "TLE\n";
  else
    cout << cost << "\n";
  
  return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)

int main(){

	lli n;
	cin>>n;

	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	deque<lli> b;

	REP(i,0,n)
	{
		if(i%2==0)b.push_front(a[i]);
		else b.push_back(a[i]);
	}

	while(b.size()){
	if(n%2==0){
		cout<<b.back()<<" ";
		b.pop_back();
	}
	else{
		cout<<b.front()<<" ";
		b.pop_front();
	}
	}
	
	cout<<endl;


	return 0;
}


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

int main(){
    int n,total=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            total+=a[i]*a[j];
        }
    }
    
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int n, m;
    string s;
    cin >> n >> m >> s;

    vector<int> minCnt(n+1), maxCnt(n+1);
    for(int i=0; i<n; ++i){
        if(s[i] == '1')
            minCnt[i+1] = maxCnt[i+1] = 1;
        minCnt[i+1] += minCnt[i];
        maxCnt[i+1] += maxCnt[i];
    }

    for(int i=0; i<m; ++i){
        int l, r;
        cin >> l >> r;

        int x = minCnt[l-1];
        int y = minCnt[r];
        for(int j=r; j>=l; --j)
            minCnt[j] = max(x, y - (r - j));

        x = maxCnt[l-1];
        y = maxCnt[r];
        for(int j=l; j<=r; ++j)
            maxCnt[j] = min(y, x + (j - l + 1));
    }

    vector<int> dp(n+1, 0);
    dp[0] = 1;
    for(int i=1; i<=n; ++i){
        vector<int> nextDp(n+1, 0);
        for(int j=0; j<=n; ++j){
            if(minCnt[i] <= j && j <= maxCnt[i]){
                nextDp[j] += dp[j];
                nextDp[j] %= MOD;
            }
            if(minCnt[i] <= j + 1 && j + 1 <= maxCnt[i]){
                nextDp[j+1] += dp[j];
                nextDp[j+1] %= MOD;
            }
        }
        dp.swap(nextDp);
    }

    int ans = accumulate(dp.begin(), dp.end(), 0);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int x;
	int y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)break;
		
	if(x>y){
		printf("%d %d\n",y,x);}
	else{
		printf("%d %d\n",x,y);}
	}
	return 0;
}

Measured memory_bytes: 600
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod    1000000007
#define PI 2*acos(0.0)

const int N = 2000005;
vi fac(N);

void fcalc()
{
    fac[0] = 1;
    for(int i = 1; i< N; i++)
        fac[i] = (1LL*fac[i-1] *  i)%mod;
}

ll bigmod(ll x, ll po)
{
    ll res = 1;
    while(po)
    {
        if(po&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        po >>= 1;
    }
    return res;
}

ll bin(int n, int i)
{
    return (fac[n] * (bigmod(1LL*fac[n-i]*fac[i]%mod, mod-2)%mod))%mod;
    //return ((fac[n]*bigmod(fac[i], mod-2)%mod)%mod * bigmod(fac[n-i], mod-2)%mod)%mod;
}


int32_t main()
{
    io;
    fcalc();
    int n;
    string s;
    cin>>n>>s;
    int m = s.size();
    n += m;
    ll ans = 1, sub = 0;
    vi p(n+1); p[0] = 1;
    for(int i = 1; i<=n; i++)
        p[i] = (p[i-1]*25LL)%mod;
    for(int i = 1; i <= n; i++)
        ans = (ans* 26)%mod;
    for(int i =0 ; i< m; i++)
        sub = (sub + bin(n, i)*p[n-i] %mod)%mod;
    cout<<(ans - sub + mod)%mod;
    return 0;
}


Measured memory_bytes: 19968
#include <vector>
#include <iostream>
using namespace std;
 
int ans[10005];
 
int main() {
  int N;
  cin >> N;
  for (int x = 1; x <= 100; x++) for (int y = 1; y <= 100; y++) for (int z = 1; z <= 100; z++) {
    int a = x*x + y*y + z*z + x*y + x*z + y*z;
    if (a <= 10000) ans[a]++;
  }
  
  for (int i = 1; i <= N; i++) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 3640
package main

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

func main() {
	S := readString()

	var res string

	switch S {
	case "Sunny":
		res = "Cloudy"
	case "Cloudy":
		res = "Rainy"
	case "Rainy":
		res = "Sunny"
	}

	fmt.Println(res)
}


const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

Measured memory_bytes: 640
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
 
using namespace std;
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	double x = 0, y = 0;
	double m, d;
	char c;
	double next = 0;
	while(cin >> m >> c >> d && (m != 0 || d != 0) ){
		double rad = (90 - next) / 180.0 * M_PI;
		x += m * cos(rad);
		y += m * sin(rad);
		next += d;
	}
	
	cout << (int)x << endl;
	cout << (int)y << endl;
	
	return 0;
}

Measured memory_bytes: 1232
#Python Template

from sys import stdin, stdout

def d(a, b):
	return abs(a[0]-b[0]) + abs(a[1]-b[1])

def v1(l):
	return l[0] + l[1]

def v2(l):
	return l[0] - l[1]

def main():
	n = int(stdin.readline())
	pts = []
	for _ in range(n):
		x, y = [int(i) for i in stdin.readline().split()]
		pts.append([x,y])
	s1 = sorted(pts, key=v1)
	s2 = sorted(pts, key=v2)
	#print(s1)
	#print(s2)

	d1 = d(s1[0], s1[-1])
	d2 = d(s2[0], s2[-1])
	dist = max(d1, d2)
	print(dist)


	

main()

Measured memory_bytes: 51732
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = [None] * len(a)
ans = 0
for i in range(len(a)):
    if i != len(a)-1:
        b[i] = a[i+1]-a[i]
    else:
        b[i] = k - a[i] + a[0]
ans = sum(b)-max(b)
print(ans)

Measured memory_bytes: 26420
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = 1, b = 1;
        while (a != 0 && b != 0) {
            a = scanner.nextInt();
            b = scanner.nextInt();
            if (a == 0 && b == 0) {
                break;

            }

            for (int i = 1; i <= a; i++) {
                for (int j = 1; j <= b - 1; j++) {
                    System.out.print("#");
                }
                System.out.println("#");
            }
            System.out.println("");
        }
    }
}

Measured memory_bytes: 37576
#include<bits/stdc++.h>
using namespace std;
vector<int> vi;
int main(){
   int n;
   cin>>n;
   int cnt=0;
   for(int i=1;i<=n;i++){
    int s;
    scanf("%d",&s);
    if(i%2&&s%2) cnt++;
   }
   cout<<cnt;
    return 0;
}


Measured memory_bytes: 3688
import * as fs from 'fs';

//in
//
//out
//
const main = (inp: string) => {
    const [a, b]: number = inp.split(' ').map(Number);
    // a+b
    // a-b
    // a*b
    const ans1: number = a + b;
    const ans2: number = a - b;
    const ans3: number = a * b;

    console.log(Math.max(ans1,ans2,ans3));

    // if (ans1 >= ans2 && ans1 >= ans3) {
    //     console.log(ans1);
    // }
    // if (ans2 >= ans1 && ans2 >= ans3) {
    //     console.log(ans2);
    // }
    // if (ans3 >= ans1 && ans3 >= ans2) {
    //     console.log(ans3);
    // }

};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n=0,m=0,l=0;
  string s;
  cin >> s;
  for(int i=0;i<3;i++){
    if(s.at(i)=='a'){
      n++;
    }
    else if(s.at(i)=='b'){
      m++;
    }
    else if(s.at(i)=='c'){
      l++;
    }
  }
  if(n==1&&m==1&&l==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

char s[26], str[101];
int main(){
	int n, x, y, t, ans, res = 0;
	scanf("%d%s", &n, s);
	while(n--){
		scanf("%s", str);
		x = strlen(s);
		y = strlen(str);
		ans = 0;
		//printf("%d %d\n", x, y);
		for(int i = 0;i < y;i++){
			for(int j = 1;j <= y;j++){
				t = 1;
				for(int k = 0;k < x;k++){
					if(i+j*k >= y){
						t = 0;
						break;
					}
					if(str[i+j*k] == s[k])max(t, 0);
					else t = 0;
				}
				if(t){
					ans++;
					break;
				}
			}
		}
		//printf("%d\n", ans);
		res += !!ans;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 3204
S = input()
T = input()

from collections import defaultdict

nx = [defaultdict(lambda: -1) for i in range(len(S)+1)]
lastpos = defaultdict(lambda: 0)

SS = S+S
for i,c in enumerate(SS[::-1]):
    i = len(SS)-1-i
    if i < len(S):
        for k,v in lastpos.items():
            nx[i+1][k] = v-i
    lastpos[c] = i
for k,v in lastpos.items():
    nx[0][k] = v+1

ans = 0
for c in T:
    if nx[ans%len(S)][c] == -1:
        print(-1)
        exit()
    ans += nx[ans%len(S)][c]
print(ans)

Measured memory_bytes: 221328
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <stdio.h>
#include <sstream>

using namespace std;
void swap(int &a, int &b);

int main()
{
	char **input = new char *[3000]();
	for (int i = 0; i < 3000; ++i)
		input[i] = new char[10000]();

	int count = 0;
	while (true)
	{
		cin >> input[count];
		// 終了チェック
		if (input[count][0] == '0')
			break;

		// string -> char
		//strcpy_s(input[count], sstr.size() + 1, sstr.c_str());
		count++;

	}

	int *output = new int[count]();
	for (int i = 0; i < count; ++i)
	{
		for (int j = 0;input[i][j] != '\0'; ++j)
		{
			// atoiでは上手くいかなかった
			//int temp = atoi(input[i] + j);

			// 数字はASCIIコードで連番　ex.'0'=48, '2'=50
			// だから'0'からの相対距離値を一桁の数字としてとらえる
			int temp = static_cast<int>(input[i][j] - '0'); 
			output[i] += temp;
		}
	}

	for (int i = 0; i < count; ++i)
	{
		cout << output[i] << endl;
	}

	return 0;
}




Measured memory_bytes: 32472
package main

import (
	"fmt"
	"strconv"
)

func solve() {
	var N, A, B int
	fmt.Scan(&N, &A, &B)

	ans := 0
	for i := 1; i <= N; i++ {
		si := strconv.FormatInt(int64(i), 10)
		c := 0
		for _, s := range si {
			po, _ := strconv.ParseInt(string(s), 10, 64)
			c += int(po)
		}
		if A <= c && c <= B {
			ans += i
		}

	}
	fmt.Println(ans)
}

func main() {
	solve()
}


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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll r,d,x;
    cin>>r>>d>>x;
    ll i=10;
    while(i>0)
    {
        x=r*x-d;
        cout<<x<<endl;
        i--;
    }
    return 0;
}

Measured memory_bytes: 256
# 素朴な実装では、Kが大きすぎるので確実にTLEしてしまう。
# N～NlogN程度の計算時間で実行できるロジックを検討する必要あり
# もしくは、O（K ÷ （2のべき乗)＝Kの２進数表現の桁数）の実行時間でできないか？
# 最大（一番左）のビットを半分以上にするｘを使えばよいのか？YES。
N , K = map(int, input().split())
an = list(map(int,input().split()))
lenbitK = len(bin(K)) - 2
lenmax = max(len(bin(max(an))) - 2,lenbitK)
usebitK = [0] * lenmax
anbit = [0] * lenmax
for a in an:
    for i in range(len(bin(a))-2):
        if a>>i & 1 :
            anbit[i] += 1
tempK = 0
for i in reversed(range(lenbitK)):
    if (anbit[i] < ((N>>1)+(N&1)) ) and (tempK + (1<<i)  <= K) :
        usebitK[i] = 1
        tempK += (1<<i)
ans = 0
#print("tempK",tempK)
#print("usebitK",usebitK)
for j in range(lenmax):
    if usebitK[j] == 0:
        ans += anbit[j] * (1<<j)
    else:
        ans += (N - anbit[j]) * (1<<j)
print(ans)

Measured memory_bytes: 14620
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n, m;
int p[100010], par[100010], pos[100010];
int pn(int u) { return par[u] == u ? u : (par[u] = pn(par[u])); }
int main() {
	scanf("%d%d", &n, &m);
	for(int i=1; i<=n; i++) scanf("%d", p+i), pos[p[i]] = i;
	for(int i=1; i<=n; i++) par[i] = i;
	for(int i=0; i<m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		par[pn(v)] = pn(u);
	}
	int res = 0;
	for(int i=1; i<=n; i++)
		if(pn(i) == pn(pos[i])) res++;
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin >> s;
    bool flag = true;
    if(s[2] != s[3]){
        flag = false;
    }
    if(s[4] != s[5]){
        flag = false;
    }
    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

ll f(ll n, ll x)
{
    if (n == -1) return 0LL;
    return n / x+1;
}

int main()
{
    ll a, b, x, ans = 0; cin >> a >> b >> x;
    ll l = f(b, x);
    ll r = f(a-1, x);
    cout << l - r << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, a[333333];

  std::cin >> N;

  for (int i = 0; i < N * 3; i ++)
    std::cin >> a[i];

  std::multiset<int> set;

  long long s = 0, S[333333];

  for (int i = 0; i < N; i ++) {
    set.insert(a[i]);

    s += a[i];
  }

  S[N] = s;

  for (int i = N; i < N * 2; i ++) {
    set.insert(a[i]);

    s += a[i];

    s -= *std::begin(set);

    set.erase(std::begin(set));

    S[i + 1] = s;
  }

  long long dp = -INF;

  s = 0;

  set.clear();

  for (int i = N * 2; i < N * 3; i ++) {
    set.insert(a[i]);

    s += a[i];
  }

  dp = std::max(S[N * 2] - s, dp);
  
  for (int i = N * 2 - 1; i >= N; i --) {
    set.insert(a[i]);

    s += a[i];

    auto it = std::end(set);

    std::advance(it, -1);

    s -= *it;

    set.erase(it);

    dp = std::max(S[i] - s, dp);
  }

  std::cout << dp << std::endl;
  
  return 0;
}


Measured memory_bytes: 8192
double P[102][101];
char L[101],B[101];
main(){
	int N,T,l,b,x,t,n,k;
	for(;scanf("%d%d%d%d",&N,&T,&l,&b),N;){
		memset(P,0,sizeof(P));
		memset(L,0,sizeof(L));
		memset(B,0,sizeof(B));
		for(;l--;)scanf("%d",&x),L[x]=1;
		for(;b--;)scanf("%d",&x),B[x]=1;
		for(P[t=0][0]=1;t<T;P[t+1][N]+=P[t][N],t++)for(n=0;n<N;n++){
			for(k=1;k<=6;k++){
				x=n+k;
				if(x>N)x=2*N-x;
				if(B[x])x=0;
				P[t+1+L[x]][x]+=P[t][n]/6;
			}
		}
		printf("%f\n",P[T][N]);
	}
exit(0);}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	
	int dp[2][3];
	for(int i = 0; i < 3; i++)
		cin >> dp[0][i];
	
	for(int i = 1; i < n; i++){
		int a[3];
		for(int j = 0; j < 3; j++)
			cin >> a[j];
		for(int j = 0; j < 3; j++){
			dp[1][j] = 0;
			for(int k = 0; k < 3; k++){
				if(j == k)
					continue;
				dp[1][j] = max(dp[1][j],dp[0][k] + a[j]);
			}
		}
		for(int j = 0; j < 3; j++){
			dp[0][j] = dp[1][j];
		}
	}
	cout << max({dp[0][0],dp[0][1],dp[0][2]}) << endl;

	return 0;
}



Measured memory_bytes: 384
n=int(input())
S=input()

l,cnt1=0,0
for s in S:
  if s=='(':
    cnt1+=1
  else:
    cnt1-=1
    l=min(l,cnt1)
r,cnt2=0,0
for s in S[::-1]:
  if s==')':
    cnt2+=1
  else:
    cnt2-=1
    r=min(r,cnt2)
print('('*-l+ S + ')'*-r)

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

int main(){
  int a,b,k,i;
  cin >> a >> b >> k;
  for(i=0; i<k; i++){
    if(a+i<=b){
      cout << a+i << endl;
    }
  }
  for(i=k; i>0; i--){
    if((b-i+1)>=(a+k)){
      cout << b-i+1 << endl;
    }
  }
}

Measured memory_bytes: 256
from itertools import accumulate, chain

n, c = map(int, input().split())
xs, vs = zip(*(map(int, input().split()) for _ in range(n)))

ds = [j - i for i, j in zip(chain([0], xs), chain(xs, [c]))]

clockwise1      = [0] + [v - d*2 for v, d in zip(accumulate(vs), accumulate(ds))]
anticlockwise1  = [0] + [v - d for v, d in zip(accumulate(vs[::-1]), accumulate(ds[::-1]))]
clock_anticlock = (x + y for x, y in zip(clockwise1, reversed(list(accumulate(anticlockwise1, func=max)))))

anticlockwise2  = [0] + [v - d*2 for v, d in zip(accumulate(vs[::-1]), accumulate(ds[::-1]))]
clockwise2      = [0] + [v - d for v, d in zip(accumulate(vs), accumulate(ds))]
anticlock_clock = (x + y for x, y in zip(anticlockwise2, reversed(list(accumulate(clockwise2, func=max)))))
 
print(max(chain(anticlock_clock, clock_anticlock)))

Measured memory_bytes: 59224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  int res=0;
  cin >> N;

  res = N/2;
  if(N%2) res++;

  cout << res << endl;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, K = map(int, next(sys.stdin).split())

MOD = K * 2
grid = [[0 for _ in range(MOD)] for _ in range(MOD)]


def draw(sx, sy, ex, ey):
    sx %= MOD
    sy %= MOD
    ex = (ex - 1) % MOD + 1
    ey = (ey - 1) % MOD + 1

    if sx < ex and sy < ey:
        grid[sx][sy] += 1
        if ex < MOD:
            grid[ex][sy] -= 1
        if ey < MOD:
            grid[sx][ey] -= 1
        if ex < MOD and ey < MOD:
            grid[ex][ey] += 1

    elif ex <= sx:
        if ey <= sy:
            draw(0, 0, ex, ey)
            draw(0, sy, ex, MOD)
            draw(sx, 0, MOD, ey)
            draw(sx, sy, MOD, MOD)
        else:
            draw(0, sy, ex, ey)
            draw(sx, sy, MOD, ey)
    else:
        draw(sx, 0, ex, ey)
        draw(sx, sy, ex, MOD)


for _ in range(N):
    x, y, c = next(sys.stdin).split()
    x = int(x)
    y = int(y)
    if c == 'W':
        x += K

    # 黒マスをどこに置けばこの条件を満たすか
    # 累積和とったときに条件を満たす範囲だけ +1 されるように調整
    draw(x, y, x + K, y + K)
    draw(x + K, y + K, x + K * 2, y + K * 2)

for i in range(MOD - 1):
    for j in range(MOD):
        grid[i + 1][j] += grid[i][j]
for i in range(MOD - 1):
    for j in range(MOD):
        grid[j][i + 1] += grid[j][i]
ans = 0
for i in range(MOD):
    ans = max(ans, *grid[i])
print(ans)


Measured memory_bytes: 102620
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,k;
    for(;;){
        scanf("%d%d",&n,&k);
        if(n==0&&k==0)break;
        vector<int> ns(k);
        for(int i=0;i<k;i++){
            scanf("%d",&ns[i]);
        }
        sort(ns.begin(),ns.end());
        vector<pair<int,int> > rens;
        int st=0;
        bool isc=false;
        if(ns[0]==0){
            st=1;
            isc=true;
        }
        for(int i=st+1;i<k;i++){
            if(ns[i]!=ns[i-1]+1){
                rens.push_back(make_pair(ns[st],ns[i-1]));
                st=i;
            }
        }
        rens.push_back(make_pair(ns[st],ns[k-1]));
        int ma=0;
        if(isc){
            for(int i=1;i<rens.size();i++){
                if(rens[i-1].second+2==rens[i].first){
                    ma=max(ma,rens[i].second-rens[i-1].first+1);
                }else ma=max(ma,rens[i].second-rens[i].first+1);
            }
        }else{
            for(int i=0;i<rens.size();i++){
                ma=max(ma,rens[i].second-rens[i].first+1);
            }
        }
        printf("%d\n",ma);
    }
}

Measured memory_bytes: 1532
import sys
x = int(input())
if x ==0:
    print(1, 1)
    sys.exit()
    
div = []
for i in range(1, round(x**0.5)+1):
    if x % i ==0:
        div.append(i)
        if i != x/i:
            div.append(x//i)

for d in div:
    minvalue = -d//2
    maxvalue = 1000
    while maxvalue - minvalue > 1:
        midvalue = (minvalue + maxvalue)//2
        if (midvalue+d)**5 - midvalue**5 < x:
            minvalue = midvalue
        else:
            maxvalue = midvalue
            
        if (maxvalue+d)**5 - maxvalue**5 == x:
            break
    else:
        continue
    break
    
print(d+maxvalue, maxvalue)

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

int main(){
        int x=0,n=0,temp=0;
        cin>>x>>n;
        set<int> arr;
        for(int i=0;i<n;i++){
                cin>>temp;
                arr.insert(temp);
        }
        int ans=0;
        for(int i=0;i<100;i++){
                if(arr.find(x-i)==arr.end()){
                        ans=x-i;
                        break;
                }
                else if(arr.find(x+i)==arr.end()){
                        ans=x+i;
                        break;
                }
        }
        cout<<ans<<endl;
        return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int x,a,b,c,z;
		z = 0;

		// 入力
		a = scanner.nextInt();
		b = scanner.nextInt();
		c = scanner.nextInt();
		x = scanner.nextInt();

		for(int i=0; i<=a; i++){
			for(int j=0; j<=b; j++){
				for(int k=0; k<=c; k++){
					int temp = 500*i + 100*j + 50*k;
					if(x == temp)
						z++;
				}
			}
		}

		System.out.println(z);

		scanner.close();
	}
}

Measured memory_bytes: 22356
#include <cstdio>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;

int n, k, tot, a[300010];

int main()
{
    scanf("%d%d", &k, &n);
    if (k % 2 == 0)
    {
        printf("%d ", k / 2);
        FOR(i, 2, n) printf("%d ", k);
    }
    else
    {
        FOR(i, 1, n) a[i] = (k + 1) / 2;
        tot = n;
        FOR(i, 1, n / 2)
            if (a[tot] == 1) --tot;
            else
            {
                --a[tot];
                FOR(j, tot + 1, n) a[j] = k;
                tot = n;
            }
        FOR(i, 1, tot) printf("%d ", a[i]);
    }
    return 0;
}


Measured memory_bytes: 3328
package main

import "fmt"

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	sum := 0
	for _, x := range xs {
		sum += x
	}

	ans := sum
	acc := 0
	for i, x := range xs {
		if i == len(xs)-1 {
			break
		}
		acc += x
		if v := abs(acc - (sum - acc)); v < ans {
			ans = v
		}
	}

	fmt.Println(ans)
}


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

int main(){
    int N, X;
    cin >> N >> X;

    int l[N];
    for(int i = 0; i < N; i++){
        cin >> l[i];
    }

    int pos = 0;
    int cou = 1;

    for(int i = 0; i < N; i++){
        pos += l[i];
        if(pos <= X){
            cou++;
        }else{
            break;
        }
    }

    cout << cou << endl;
}

Measured memory_bytes: 256
# include<iostream>
# include<queue>
# include<stack>
# include<algorithm>
# include<cmath> 
using namespace std;
const int INF =pow(10,9)+7;
int a[1000000];

struct P{
	int x,y;
};
bool cmp(P a,P b)
{
	 return 1;
}

void update(int a,int b,int k,int l,int r)
{
	 
}

int main ()
{
	 int t=1;
	 //cin>>t;
	 while(t>0)
	 {
	 	 t--;
	 	 string S,T;
	 	 cin>>S>>T;
	 	 int A,B;
	 	 cin>>A>>B;
		 string U;
		 cin>>U;
		 if(U==S)
		 {
		 	A--;
		  } 
		  else
		  {
		  	B--;
		  }
		  cout<<A<<" "<<B<<endl;
	 }
    	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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(){
    int n;
    cin>>n;
    V<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(all(a));
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]){
                    if(a[i]+a[j]>a[k])ans++;
                }
            }
        }
    }
    cout<<ans<<"\n";
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for( int i= 0; i < N; i++ ) cin >> A.at(i);
  sort(A.begin(), A.end());
  cout << A.at(N-1) - A.at(0) << endl;
  
}

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

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; (L <= R? i <= R : i >= R); (L <= R? i += 1 : i -= 1))
#define int long long

const int N = 2e5 + 2, inf = 1e18;

int n, m, k, mat[3002][3002];
int dp[5][3002][3002];

int go(int i, int j, int row) {
    if(i < 1 || i > n || j < 1 || j > m) 
        return -inf;
    if(row > 3) 
        return -inf;

    int &ans = dp[row][i][j];
    if(~ans)
        return ans;

    if(i == n && j == m) {
        return (row == 3 ? 0 : mat[i][j]);
    }

    int c1 = mat[i][j] + go(i, j + 1, row + 1);
    int c2 = -inf;
    if(row < 3)
        c2 = mat[i][j] + go(i + 1, j, 0);
    int c3 = 0 + go(i, j + 1, row);
    int c4 = 0 + go(i + 1, j, 0);

    return ans = max({c1, c2, c3, c4});
}

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

    cin >> n >> m >> k;
    FOR(i,1,k) {
        int x, y, v;
        cin >> x >> y >> v;
        mat[x][y] = v;
    }
    memset(dp, -1, sizeof(dp));
    cout << go(1,1,0);
}


Measured memory_bytes: 426768
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

class UnionFindTree
{
public:
	int n;
	vector<int> par;
	vector<int> rank;
	UnionFindTree(){}
	UnionFindTree(int num){
		n = num;
		par.resize(n);
		rank.resize(n);
		for (int i = 0; i < n; ++i)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		int root_x = find(x);
		int root_y = find(y);
		if(root_x == root_y) return;
		if(rank[root_x] < rank[root_y]){
			par[root_x] = root_y;
		}else{
			par[root_y] = root_x;
			if(rank[root_x] == rank[root_y]) rank[root_x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};


class Connectivity
{
public:
	int n, k, l;
	UnionFindTree uft1;
	UnionFindTree uft2;
	Connectivity();
	void exec();	
};

Connectivity::Connectivity(){
	cin >> n >> k >> l;
	uft1 = UnionFindTree(n+1);
	uft2 = UnionFindTree(n+1); 
	for (int i = 0; i < k; ++i)
	{
		int p, q;
		cin >> p >> q;
		uft1.unite(p, q);
	}
	for (int i = 0; i < l; ++i)
	{
		int r, s;
		cin >> r >> s;
		uft2.unite(r, s);
	}
}

void Connectivity::exec(){
	map<pair<int, int >, int> hash;
	for (int i = 1; i <= n; ++i)
	{
		pair<int, int> p;
		p.first = uft1.find(i);
		p.second = uft2.find(i);
		hash[p]++;
	}
	for (int i =1 ; i <= n; ++i)
	{
		pair<int, int> p;
		p.first = uft1.find(i);
		p.second = uft2.find(i);
		cout << hash[p] << " ";
	}
	cout << endl;

}

int main(){
	Connectivity c = Connectivity();
	c.exec();

}


Measured memory_bytes: 15104
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << fixed << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template

int main() {
    // source code
    
    int N = inputValue();
    int M = inputValue(); // weight
    
    vector<int> C(N);
    vector<int> W(N);
    
    rep(i, N){
        C[i] = inputValue();
        W[i] = inputValue();
    }
    
    vector<vector<int>> dp(N + 1, vector<int>(M + 1, 0));
    
    repd(i, 1, N + 1){
        repd(j, 1, M + 1){
            if (j - W[i - 1] >= 0) {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - W[i - 1]] + C[i - 1]);
            }
            else{
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    
    output(dp[N][M], 0);
    
    return 0;
}

Measured memory_bytes: 4956
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Edge{
	Edge(int arg_from,int arg_to,int arg_weight){
		from = arg_from;
		to = arg_to;
		weight = arg_weight;
	}
	int from,to,weight;
};

int POW[21];
int L;
vector<Edge> edge;

int main(){

	POW[0] = 1;
	for(int i = 1; i <= 20; i++){

		POW[i] = POW[i-1]*2;
	}

	vector<int> V;

	scanf("%d",&L);

	int num;
	for(int i = 0; i <= 20; i++){

		if(POW[i] <= L){

			num = i;
		}
	}

	int goal = num+1;
	for(int i = 1; i <= num+1; i++){

		V.push_back(i);
	}
	for(int i = 0; i < V.size()-1; i++){

		edge.push_back(Edge(V[i],V[i+1],POW[V[i]-1]));
		edge.push_back(Edge(V[i],V[i+1],0));
	}

	for(int i = V.size()-2; i >= 0; i--){

		if(L-POW[V[i]-1] >= POW[num]){

			edge.push_back(Edge(V[i],goal,L-POW[V[i]-1]));
			L -= POW[V[i]-1];
		}
	}

	printf("%lld %lld\n",V.size(),edge.size());
	for(int i = 0; i < edge.size(); i++){

		printf("%d %d %d\n",edge[i].from,edge[i].to,edge[i].weight);
	}

	return 0;
}


Measured memory_bytes: 3712
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<map>
using namespace std;

int x, n, m, s;
int ans = 0;
int main()
{
	scanf("%d%d%d", &x, &n, &m);
	scanf("%d", &s);
	for(int i = 0; i <= x; i++)
		for(int j = 0; j <= n; j++)
			for(int k = 0; k <= m; k++)
			{
				if(i * 500 + j * 100 + k * 50 == s) ans++ ;
			}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX=3000;
ld coins[MAX];
ld mem[MAX][MAX/2];
int n;

ld dp(int i,int sellos){
	if(sellos<0)return 0.0;
	if(i==n)return 1.0;
	ld &ans=mem[i][sellos];
	if(ans > -0.5) return ans;
	ans = coins[i]*dp(i+1,sellos)+(1.0-coins[i])*dp(i+1,sellos-1);
	return ans;
}
int main() {

  ios::sync_with_stdio(0), cin.tie(0);
  cin>>n;
  for(int i=0;i<=n;i++){
  	for(int j=0;j<=n;j++){
  		mem[i][j]=-1.0;
  	}
  }
  forn(i,n){
  	cin>>coins[i];
  }
  int m = (n+1)/2-1;
  ld ans = dp(0, m);
  cout<<fixed<<setprecision(10)<< ans << endl;
  return 0;
}

Measured memory_bytes: 35584
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	int n, m;
	cin >> n >> m;

	vector<queue<int>> a(n);

	for (int i = 0; i < m; i++)
	{
		int q, t;
		cin >> q >> t;

		int x;

		switch (q)
		{
			case 0:
				cin >> x;
				a[t].push(x);
				break;

			case 1:
				if (!a[t].empty())
				{
					println(a[t].front());
				}
				break;

			case 2:
				if (!a[t].empty())
				{
					a[t].pop();
				}
				break;
		}
	}
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()

const char newl = '\n';

using namespace std;
using ll = long long;

auto main() -> int
{
	cin.tie(0);
  	ios::sync_with_stdio(0);

	int N; cin >> N;
    N %= 10;
    
    if(N==3)
  	  cout << "bon" << newl;
    
    else if(N == 2 or N == 4 or N == 5 or N == 7 or N == 9)
      cout << "hon" << newl;
      
    else cout << "pon" << newl;
       
}

Measured memory_bytes: 3600
package main

import "fmt"

func main() {
	var (
		S string
	)
	fmt.Scanf("%s\n", &S)
	
	var zero, one int
	for _, str := range S {
		if fmt.Sprintf("%c",str) == "0" {
			zero ++
		} else {
			one ++
		}
	}
	result := one
	if zero < one {
		result = zero
	}

	fmt.Println(result * 2)
}

Measured memory_bytes: 2048
//
//  main.cpp
//  TOUIST
//
//  Created by Jay Scott on 1/27/19.
//  Copyright © 2019 hoangtheanh. All rights reserved.
//

#include <iostream>
using namespace std;
int n, dem = 0;
string a, b, c;
int main()
{
    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == b[i] && b[i] != c[i])
        {
            dem++;
            c[i] = b[i];
        }
        if (a[i] != b[i] && b[i] == c[i])
        {
            dem++;
            a[i] = b[i];
        }
        if (a[i] == c[i] && a[i] != b[i])
        {
            dem++;
            b[i] = a[i];
        }
        if (a[i] != b[i] && b[i] != c[i])
        {
            dem+=2;
            c[i] = b[i];
            a[i] = b[i];
        }
    }
    cout << dem;
    return 0;
}


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

using namespace std;

int main()
{
	int k;
	cin >> k;
	string s;
	cin >> s;
	if(s.length()<=k)
		cout << s << endl;
	else 
	{
		cout << s.substr(0,k) << "..." << endl;
	}
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int X = C - A, Y = D - B;

  cout << C - Y << " " << D + X << " " << A - Y << " " << B + X << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n,q,p=1,c,x;
	cin>>n>>q;
	for(int i=0;i<q;i++){
		cin>>c>>x;
		if(!c)cout<<((p+x-1)%n==0? n:(p+x-1)%n)<<endl;
		else {p=(p+x)%n; if(p==0)p=n;}
	}
	return 0;
}


Measured memory_bytes: 3120
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String[] str = sc.nextLine().split("[\\s]");
			boolean flag = false;
			
			for(int i = 0; i < 26; i++){
				
				for(int j = 0; j < str.length; j++){
					char[] c = str[j].toCharArray();
					
					for(int k = 0; k < c.length; k++){
						if(Character.isLowerCase(c[k])){
							if(c[k] == 'z')
								c[k] = 'a';
							else
								c[k] = (char)(c[k] + 1);
						}
					}
					str[j] = new String(c);
					if(str[j].equals("this") || str[j].equals("the") || str[j].equals("that"))
						flag = true;
				}
				if(flag)
					break;
			}
			int i = 0;
			for(String tmp:str){
				System.out.print(tmp);
				if(i == (str.length) - 1)
					break;
				System.out.print(" ");
				i++;
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 17232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int n;
vector<ll>a,b,c;
ll solve(){
   ll ans=0;
   sort(all(a));
   sort(all(b));
   sort(all(c));
   vector<ll>sum(n+1);
   for(int i=n-1;i>=0;i--){
       int s=upper_bound(all(c),b[i])-c.begin();
       sum[i]=sum[i+1]+n-s;
   }
    for(int i=n-1;i>=0;i--){
       int s=upper_bound(all(b),a[i])-b.begin();
       ans+=sum[s];
   }

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

    cin>>n;
    a.resize(n);
    b.resize(n);
    c.resize(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];  
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 3456
import math


a, b, x = map(int, input().split())
volume = a * a * b
if x < volume / 2:
    ans = math.degrees(math.atan((a*b*b)/(2*x)))
else:
    ans = math.degrees(math.atan(2*(a * a * b - x)/(a ** 3)))
print(ans)


Measured memory_bytes: 38384
# 5     n
# 1 2   d1_1 d1_1
# 6 6
# 4 4
# 3 3
# 3 2   d1_n d2_n

n = gets.to_i
array_d1, array_d2 = n.times.map{ gets.split.map(&:to_i) }.transpose

array_flag = Array.new(n+1, 0)
ans = 0

n.times do |i|
  d1 = array_d1[i]
  d2 = array_d2[i]
  if d1 == d2
    array_flag[i+1] = array_flag[i] + 1
    if array_flag[i+1] == 3
      ans += 1
      break
    end
  else
    array_flag[i+1] = 0
  end
end

if ans == 1
  puts "Yes"
else
  puts "No"
end


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

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

  set<char> st = {'A', 'C', 'G', 'T'};
  int ans = 0;
  int n = 0;
  for (int i = 0; i < S.size(); i++) {
    if (st.find(S[i]) == st.end()) {
      ans = max(n, ans);
      n = 0;
    } else {
      n++;
    }
  }
  cout << max(n, ans) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[0]<<c[0];
}

Measured memory_bytes: 3600
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .trim()
  .split("\n")
  .map((line) => line.split(" ").map((val) => parseInt(val), 10));

const N = input[0][0];
const M = input[0][1];

const ans = [];

// Union-Find

class UnionFind {
  constructor(n) {
    this.parent = [];
    for (let i = 0; i < n; i++) {
      this.parent[i] = -1;
    }
  }

  root(x) {
    if (this.parent[x] < 0) {
      return x;
    }
    return (this.parent[x] = this.root(this.parent[x]));
  }

  unite(x, y) {
    const rx = this.root(x);
    const ry = this.root(y);
    if (rx === ry) {
      return;
    }

    if (this.size(rx) >= this.size(ry)) {
      this.parent[rx] += this.parent[ry];
      this.parent[ry] = rx;
    } else {
      this.parent[ry] += this.parent[rx];
      this.parent[rx] = ry;
    }
  }

  isSame(x, y) {
    return this.root(x) === this.root(y);
  }

  size(x) {
    return -this.parent[this.root(x)];
  }
}

// end Union-Find

const union = new UnionFind(N);

ans[M] = (N * (N - 1)) / 2;

for (let i = M; i > 1; i--) {
  const x = input[i][0] - 1;
  const y = input[i][1] - 1;

  ans[i - 1] = ans[i];

  if (!union.isSame(x, y)) {
    ans[i - 1] -= union.size(x) * union.size(y);
    union.unite(x, y);
  }
}

for (let i = 1; i <= M; i++) {
  console.log(ans[i]);
}


Measured memory_bytes: 58064
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<iostream>
#include<string>
#define ll long long
#define N 100005
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i>=y;i--)
#define Forn(i,x,y) for(int i=x;i<y;i++)
using namespace std;
ll read(){ll x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}
void write(ll x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}
void writeln(ll x){if(x<0) putchar('-'),x=-x;write(x);puts(".0");}
int n,m,f[N][65],Q[N];
ll k,a[N];
int main(){
	n=read();For(i,1,n) a[i]=read();
	m=read();k=read();
	Forn(i,1,n) f[i][0]=i,Q[i]=i;
	For(i,1,m){int x=read();swap(f[x][0],f[x-1][0]);}
	For(i,1,61) Forn(j,1,n) f[j][i]=f[f[j][i-1]][i-1];
	For(i,0,61) if(k>>i&1)
		Forn(j,1,n) Q[j]=f[Q[j]][i];
	ll ans=a[1];
	writeln(ans);
	Forn(i,1,n){
		ans+=a[Q[i]+1]-a[Q[i]];
		writeln(ans);
	}
	return 0;
}

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

int Count(int n){
  int cnt=0;
  while(n%2==0){
    cnt++; n/=2;
  }
  return cnt;
}

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int& m:a)cin>>m;
  
  int ans=100;
  for(int m:a)ans=min(ans,Count(m));
  cout<<ans<<endl;
}

Measured memory_bytes: 256