akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N+1), B(N), C(N+1);
    for(int i = 0; i < N+1; i++){
        cin >> A.at(i);
    }
    for(int i = 0; i < N; i++){
        cin >> B.at(i);
    }
    C.at(0) = A.at(0);
    C.at(1) = A.at(1);
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(C.at(i) + A.at(i+1) <= B.at(i)){
            C.at(i+1) = 0;
            ans += C.at(i) + A.at(i+1);
        }
        else{
            if(B.at(i) >= C.at(i)){
            C.at(i+1) = (C.at(i) + A.at(i+1)) - B.at(i);
            ans += B.at(i);
            }
            else{
                C.at(i+1) = A.at(i+1);
                ans += B.at(i);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5600
N, M = map(int, input().split())


if N == 1 and M == 1:
    print(1)
elif N == 1:
    print(M - 2)
elif M == 1:
    print(N - 2)
elif M > 2 and N > 2:
    print((M - 2) * (N - 2))
else:
    print(0)


Measured memory_bytes: 2940
def main():
    N = int(input())

    dp = [0] + [float('inf')] * N
    for n in range(1, N + 1):
        for i in (6, 9):
            power = 1
            while power <= n:
                dp[n] = min(dp[n], 1 + dp[n - power])
                power *= i

    print(dp[N])

main()


Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<typename T>
struct Doubling{
	const int LOG_X;
	bool flag1, flag2;
	vector<vector<T>> dp;

	Doubling(int n,ll x):LOG_X(log2(x)+1){//n:配列のサイズ,x:遷移する回数
		flag1 = false;
		flag2 = false;
		dp.assign(LOG_X, vector<T>(n, -1));
	}

	void init(vector<T> &a){//適宜変える
		int n = a.size();
		flag1 = true;
		rep(i, n)
		{
			dp[0][i] = a[i];
		}
	}

	void build(){
		assert(flag1);
		flag2 = true;
		for (int k = 0; k + 1 < LOG_X; ++k)
		{
			for (int i = 0; i < dp[0].size();++i){
				if(dp[k][i]==-1){//2^k先の要素がないなら2^(k+1)先の要素もない
					dp[k + 1][i] = -1;
				}
				else{//2^k*2^k=2^(k+1)
					dp[k + 1][i] = dp[k][dp[k][i]+1];
				}
			}
		}
	}

	T query(int s,ll x){//s:スタート地点,x:遷移回数
		assert(flag2);
		for (int i = LOG_X - 1; i >= 0; i--)
		{
			if(x&(1LL<<i)){
				s = dp[i][s]+1;
			}
		}
		return s;
	}
};

void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	if(n<=k){
		rep(i,n){
			if(i)cout<<" ";
			cout<<n;
		}
		return;
	}
	vector<vector<ll>>imos(2,vector<ll>(n+5));
	int cnt=0;
	rep(x,k){
		rep(i,n){
			imos[x%2][max(0LL,i-a[i])]++;
			imos[x%2][min(n,i+a[i]+1)]--;
		}
		bool flag=x>=1?true:false;
			rep(i,n){
				imos[x%2][i+1]+=imos[x%2][i];
				a[i]=imos[x%2][i];
				if((x>=1)){
					if(imos[x%2][i]!=imos[(x-1)%2][i])flag=false;
				}
			}
		if(flag)break;
		else if(x>=1){
			rep(i,n)imos[(x-1)%2][i]=0;
		}
		++cnt;
	}
	rep(i,n){
		if(i)cout<<" ";
		cout<<imos[(cnt-1)%2][i];
	}
}

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


Measured memory_bytes: 9500
#include <iostream>

using namespace std;

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

	int n;
	cin >> n;

	int i = n;
	while (1) {
		if (i % 2 == 0) {
			cout << i << endl;
			break;
		}
		i += n;
	}

	return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())
mod = 10**9+7

pos = []
neg = []
for a in As:
    if a>=0:
        pos.append(a)
    else:
        neg.append(a)
pos.sort(reverse=True)
neg.sort()
ans = 1
lenp, lenn = len(pos), len(neg)
if (lenp+lenn)==K:
    for a in As:
        ans *= a
        ans %= mod
    print(ans)
elif lenn==0:
    for i in range(K):
        ans *= pos[i]
        ans %= mod
    print(ans)
elif lenp==0:
    if K%2==0:
        for i in range(K):
            ans *= neg[i]
            ans %= mod
        print(ans)
    else:
        neg = neg[::-1]
        for i in range(K):
            ans *= neg[i]
            ans %= mod
        print(ans)        
else:
    p, n = 0, 0
    while p+n+1<K:
        if p+2<=lenp and n+2<=lenn:
            if pos[p]*pos[p+1]>=neg[n]*neg[n+1]:
                ans *= pos[p]
                p += 1
            else:
                ans *= neg[n]*neg[n+1]
                n += 2
        elif n+2<=lenn:
            ans *= neg[n]*neg[n+1]
            n += 2
        else:
            ans *= pos[p]
            p += 1
        ans %= mod
    if p+n<K:
        ans *= pos[p]
        ans %= mod
    print(ans)

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

template <class T>
using lim = numeric_limits<T>;

struct cake{
	ll x, y, z;
	
	cake(){x=y=z=0;}
	cake(int a, int b, int c){
		x = a;
		y = b;
		z = c;
	}
	
	cake operator+(const cake &other)const{
		cake c;
		c.x = x + other.x;
		c.y = y + other.y;
		c.z = z + other.z;
		return c;
	}
	
	ll val(){
		return abs(x)+abs(y)+abs(z);
	}
};

bool compare1(const cake &a, const cake &b){return a.x+a.y+a.z < b.x+b.y+b.z;}
bool compare2(const cake &a, const cake &b){return a.x+a.y-a.z < b.x+b.y-b.z;}
bool compare3(const cake &a, const cake &b){return a.x-a.y+a.z < b.x-b.y+b.z;}
bool compare4(const cake &a, const cake &b){return a.x-a.y-a.z < b.x-b.y-b.z;}
bool compare5(const cake &a, const cake &b){return -a.x+a.y+a.z < -b.x+b.y+b.z;}
bool compare6(const cake &a, const cake &b){return -a.x+a.y-a.z < -b.x+b.y-b.z;}
bool compare7(const cake &a, const cake &b){return -a.x-a.y+a.z < -b.x-b.y+b.z;}
bool compare8(const cake &a, const cake &b){return -a.x-a.y-a.z < -b.x-b.y-b.z;}

ll solve(cake arr[], int m){
	cake ans;
	for (int i = 0; i < m; i++){
		ans = ans+arr[i];
	}
	return ans.val();
}

int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	cake arr[n];
	
	for (int i = 0; i < n; i++){
		cin >> arr[i].x >> arr[i].y >> arr[i].z;
	}
	
	ll ans = 0;
	sort(arr,arr+n,compare1);
	ans = max(ans,solve(arr,m));
	sort(arr,arr+n,compare2);
	ans = max(ans,solve(arr,m));
	sort(arr,arr+n,compare3);
	ans = max(ans,solve(arr,m));
	sort(arr,arr+n,compare4);
	ans = max(ans,solve(arr,m));
	sort(arr,arr+n,compare5);
	ans = max(ans,solve(arr,m));
	sort(arr,arr+n,compare6);
	ans = max(ans,solve(arr,m));
	sort(arr,arr+n,compare7);
	ans = max(ans,solve(arr,m));
	sort(arr,arr+n,compare8);
	ans = max(ans,solve(arr,m));
	
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>


int main()
{
    long  int s,k,x,y,z,i,j,l,count=0;

    scanf("%ld%ld",&k,&s);

    for(x=0; x<=k; x++)
        for(y=0; y<=k; y++)
        {
            z=s-x-y;
            if(z>=0 && z<=k)
            {

                count++;

            }
        }


    printf("%ld",count);
    return 0;

}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
    int a[100]={},i,j,m;
    for(i=0;i<3;i++){
        scanf("%d",&a[i]);
    }
    for(m=0;m<2;m++){
        for(i=0;i<2;i++){
            if(a[i]>a[i+1]){
            j=a[i];
            a[i]=a[i+1];
            a[i+1]=j;
            }
        }
    }
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void omit_LF (void)
{
  char c;
  
  scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  for (i=0; i<n; i++) {
    scanf("%c", &buf[i]);
  }

//  if (NULL == fgets(buf, sizeof(buf), stdin)) {
//    return NULL;
//  }
  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

char *s[50];
int64 t[50];

int main()
{
  int64 N,i,time;
  char *X;
  int64 size = 100;
  int64 sleep = 0;

  get_N(&N);
  omit_LF();

  for (i=0; i<N; i++) {
    s[i] = get_SN(100, &size);
    get_N(&t[i]);
  }

  X = get_SN(100, &size);

  time = 0;
  for (i=0; i<N; i++) {
//    printf("i=%d %s %d\n", i, s[i], t[i]);
    if (sleep) {
      time += t[i];
    }
    if (strcmp(X, s[i]) == 0) {
      sleep = 1;
    }
  }

  printf("%lld\n", time);

  return 0;
}



Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
int main(){
	char str[1001];
	int sum;
	
	for(;;){
		sum = 0;
		scanf("%s", str);
		for(int i = 0; i < strlen(str); i++){
			sum += str[i] - '0';
		}
		if( str[0] - '0' == 0) break;
		printf("%d\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 964
public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int cnt = sc.nextInt();
			int[][][] cntT = new int[4][3][10];
			java.util.stream.IntStream.range(0, cnt).forEachOrdered(i -> {
				int bIdx = sc.nextInt() - 1;
				int floor = sc.nextInt() - 1;
				int room = sc.nextInt() - 1;
				int v = sc.nextInt();

				int tmp = cntT[bIdx][floor][room] + v;
				if (tmp < 0) {
					cntT[bIdx][floor][room] = 0;
				} else if (tmp > 9) {
					cntT[bIdx][floor][room] = 9;
				} else {
					cntT[bIdx][floor][room] = tmp;
				}
			});

			for (int i = 0; i < cntT.length; i++) {
				StringBuilder sb = new StringBuilder();
				for (int j = 0; j < cntT[i].length; j++) {
					for (int k = 0; k < cntT[i][j].length; k++) {
						sb.append(" " + cntT[i][j][k]);
					}
					sb.append("\n");
				}
				if (i != cntT.length - 1) {
					sb.append("####################\n");
				}
				System.out.print(sb);
			}

		}
	}
}


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


int main(){

	int N;
	scanf("%d",&N);

	int tmp;
	vector<int> V;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	int num_query;
	scanf("%d",&num_query);

	int loc;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&tmp);

		loc = lower_bound(V.begin(),V.end(),tmp)-V.begin();

		if(loc != (int)V.size() && V[loc] == tmp){

			printf("1\n");

		}else{

			printf("0\n");
		}
	}

	return 0;
}




Measured memory_bytes: 3516
#include <iostream>
using namespace std;
int N, T;
long long ans;
int Time[200005];
void Read()
{
    cin >> N >> T;
    for(int i = 1; i <= N; i++)
    {
        cin >> Time[i];
    }
    for(int i = 2; i <= N; i++)
        ans += min(T, Time[i] - Time[i - 1]);
    ans += T;
    cout << ans << "\n";
}

int main()
{
    Read();
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int a[N];
int n, ans;

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

    return 0;
}


Measured memory_bytes: 3612
N, M = map(int,input().split())
data = [[list(map(int,input().split())),i] for i in range(M)]

data.sort(key = lambda x:x[0][1])

count=[0]*N
ans=[]

for i in data:
    count[i[0][0]-1] += 1
    ans.append([i[1],str(i[0][0]).zfill(6) + str(count[i[0][0]-1]).zfill(6)])

ans.sort(key = lambda x:x[0])

for i in ans:
    print(i[1])

Measured memory_bytes: 54928
N = int(input())
f = False
if N%2==1:
    f = True
    N -= 1
from itertools import product
A = []
for a, b in product(range(1, N+1), range(1, N+1)):
    if a < b and a+b!=N+1:
        A.append((a,b))
if f:
    N+=1
    for i in range(1, N):
        A.append((i, N))
print(len(A))
for a, b in A:
    print(a, b)


Measured memory_bytes: 45040
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		set<int,greater<int>> s,s1;
		for(int i=1;i<=n;i++)
		s.insert(i);
		while(m--){
			int x=*s.rbegin(),y=-1;
			int i=x;
			for(auto j:s){
				if(i==j||n-j+i==j-i||s1.count(abs(i-j))==true||s1.count(abs(n-j+i))==true){
					continue;
				}
				x=i;
				y=j;
				break;
			}
			cout<<x<<" "<<y<<endl;
			s1.insert(y-x);
			s1.insert(n-y+x);
		//	cout<<y-x<<" "<<n-y+x<<endl;
			s.erase(x);
			s.erase(y);
		}
	}
	return 0;
}

Measured memory_bytes: 11964
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int d;
	cin>>d;
	cout<<"Christmas";
	for(int i=d;i<25;i++){
		cout<<" Eve";
	}
	cout<<endl;


	return 0;
}


Measured memory_bytes: 3572
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())

def read_int_n():
    return list(map(int, input().split()))

def read_float():
    return float(input())

def read_float_n():
    return list(map(float, input().split()))

def read_str():
    return input().strip()

def read_str_n():
    return list(map(str, input().split()))

def error_print(*args):
    print(*args, file=sys.stderr)



def main():
    a, b = read_int_n()
    print(a * b)

if __name__ == '__main__':
    main()

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

#define swap(type,a,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(int i=0;i<n;i++)
#define forS(i,start,n) for(int i=start;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(15)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int gcd(int,int);
int main(){
    int n,m,cnt=0;

    cin >> n;
    vi a(n),l(n+1), r(n+1);
    forN(i,n){
        cin >> a[i];
    }
    l[0] = 0;
    r[n] = 0;
    m=0;
    forS(i,1,n+1){
        l[i]=gcd(l[i-1],a[i-1]);
        r[n-i]=gcd(a[n-i],r[n-i+1]);
    }
    forN(i,n){
        int tmp = gcd(l[i],r[i+1]);
        m=max(m,tmp);
    }
    cout << m << endl;
}
int gcd(int x,int y){
    int a=x,b=y;
    if(a<b){
        swap(int,a,b);
    }
    int tmp;
    if(b==0) return a;
    while((tmp=a%b)!=0){
        a=b;b=tmp;
    }
    return b;
}


Measured memory_bytes: 4412
#import queue #queue
INF=1145141919
dx=[1,-1,0,0]
dy=[0,0,1,-1]
def search(cor_s,dst):
    mem=[[INF for i in range(a[1])]for j in range(a[0])]
    #q=queue.Queue() #queue
    #q.put(cor_s) #queue
    li=[cor_s] #list
    mem[cor_s[0]][cor_s[1]]=0
    #while not q.empty(): #queue
    while len(li)!=0: #list
        #cor=q.get() #queue
        cor=li.pop(0) #list
        for i in range(4):
            x=cor[0]+dx[i]
            y=cor[1]+dy[i]
            if 0<=x<a[0] and 0<=y<a[1] and s[x][y]!='X' and mem[x][y]==INF:
                mem[x][y]=mem[cor[0]][cor[1]]+1
                if s[x][y]==str(dst):return [[x,y],mem[x][y]]
                else:
                    #q.put([x,y]) #queue
                    li.append([x,y])
#
a=[int(num)for num in input().split(' ')]
s=[list(input()) for i in range(a[0])]
pos_s=[]
time=0
for li in s:
    if 'S' in li:pos_s=[s.index(li),li.index('S')]
for i in range(a[2]):
    ret_l=search(pos_s,i+1)
    pos_s=ret_l[0]
    time+=ret_l[1]
print(time)

Measured memory_bytes: 37748
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000


int main(){
  int n,k;
  double ans;
  
  cin >> n >> k;

  ans = 1 * 1 * sin(2*M_PI/n) * n/2;
  
  if(k > 1){
    double a = sqrt(2 * (1 - cos(2*M_PI/n)));
    ans -= (tan(M_PI/n*(k-1)) * a / 2) * a / 2 * n;
  }
  
  printf("%.10lf\n",ans);
  
  return 0;
}

Measured memory_bytes: 3544
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define mid ((l+r)>>1)
using namespace std;

typedef long long LL;
int n,a,b,d,x[100100],y[100100];
LL ans;
bool flag[100100];
struct data
{
    int k,x,id;
    bool operator<(const data &t) const
    {
        return k<t.k || k==t.k && x<t.x;
    }
};
struct set
{
    int nxt[100100];
    data a[100100];
    int find(int x)
    {
        if (nxt[x]==x)
            return x;
        return nxt[x]=find(nxt[x]);
    }
    void build(int u,int v)
    {
        repu(i,1,n+1)
            a[i]=(data){u*x[i]+v*y[i],u*x[i],i},nxt[i]=i;
        sort(a+1,a+1+n);
    }
    int query(data x)
    {
        int l=1,r=n+1;
        while (l<r)
            a[mid]<x?l=mid+1:r=mid;
        return l;
    }
    void calc(int k,int ql,int qr);
} s[4];

void insert(int k)
{
    if (flag[k])
        return;
    flag[k]=1;
    s[0].calc(x[k]+y[k]+d,x[k],x[k]+d-1);
    s[1].calc(x[k]-y[k]+d,x[k]+1,x[k]+d);
    s[2].calc(-x[k]+y[k]+d,-x[k]+1,-x[k]+d);
    s[3].calc(-x[k]-y[k]+d,-x[k],-x[k]+d-1);
}

void set::calc(int k,int ql,int qr)
{
    int l=query((data){k,ql}),r=query((data){k,qr+1});
    ans+=r-l;
    for (; (l=find(l))<r; ++l)
        nxt[l]=l+1,insert(a[l].id);
}

int main()
{
    scanf("%d%d%d",&n,&a,&b);
    repu(i,1,n)
        scanf("%d%d",&x[i],&y[i]);
    s[0].build(1,1),s[1].build(1,-1),s[2].build(-1,1),s[3].build(-1,-1);
    d=abs(x[a]-x[b])+abs(y[a]-y[b]),insert(a);
    printf("%lld\n",ans/2);
    return 0;
}

Measured memory_bytes: 18176
import com.sun.org.apache.xerces.internal.xs.StringList;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String in = sc.nextLine();
        int len = in.length();
        if(len % 2 == 0){
            char[] test = in.substring(0,in.length() / 2).toCharArray();
            char[] test2 = in.substring(in.length() / 2).toCharArray();
            List<Character> testRev = new ArrayList<Character>();
            for(char each : test){
                testRev.add(each);
            }
            Collections.reverse(testRev);
            List<Character> testRev2 = new ArrayList<Character>();
            for(char each : test2){
                testRev2.add(each);
            }
            Collections.reverse(testRev2);
            int cur = 0;
            int r = 0;
            for(char c : test){
                if(c != testRev2.get(cur)){
                    r++;
                }
                cur++;
            }
            cur = 0;
            int r1 = 0;
            for(char c : test2){
                if(c != testRev.get(cur)){
                    r1++;
                }
                cur++;
            }
            System.out.println(Math.min(r,r1));
        }else{
            char[] test = in.substring(0,in.length() / 2).toCharArray();
            char[] test2 = in.substring(in.length() / 2 + 1).toCharArray();
            List<Character> testRev = new ArrayList<Character>();
            for(char each : test){
                testRev.add(each);
            }
            Collections.reverse(testRev);
            List<Character> testRev2 = new ArrayList<Character>();
            for(char each : test2){
                testRev2.add(each);
            }
            Collections.reverse(testRev2);
            int cur = 0;
            int r = 0;
            for(char c : test){
                if(c != testRev2.get(cur)){
                    r++;
                }
                cur++;
            }
            cur = 0;
            int r1 = 0;
            for(char c : test2){
                if(c != testRev.get(cur)){
                    r1++;
                }
                cur++;
            }
            System.out.println(Math.min(r,r1));
        }
    }
}

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

using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	cout<<(n)*(n-1)/2+(m)*(m-1)/2<<endl;
	
	return 0;
}

Measured memory_bytes: 3628
N, M = map(int, input().split())
A = list(map(int, input().split()))

total = sum(A)

def check(score):
    return (True if score >= (total/(4*M)) else False)

cnt = 0
for i in range(N):
    if check(A[i]):
        cnt += 1
if cnt >= M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS=1e-10;
const ll INF=1000000000;
int w,h;
int c[60][60];
bool visited[60][60];
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,1,-1,-1};
bool field(int x,int y){
    if(x>=0&&x<w&&y>=0&&y<h){
        return true;
    }
    return false;
}
int dfs(int x,int y){
    if(visited[y][x]){
        return 0;
    }
    visited[y][x]=true;
    for(int i=0;i<8;i++){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(field(nx,ny)&&c[ny][nx]){
            dfs(nx,ny);
        }
    }
    return 1;
}
int main(){
    while(cin>>w>>h,w+h){
        memset(visited,false,sizeof(visited));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>c[i][j];
            }
        }
        int ans=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(c[i][j]){
                    ans+=dfs(j,i);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int p[1001];

int main() {
	int n, m;
	while (cin >> n >> m&&n&&m) {
		REP(i, n)cin >> p[i];
		vector<int> vec;
		REP(i, n + 1)REP(j, n + 1) {
			vec.emplace_back(p[i] + p[j]);
		}
		sort(vec.begin(), vec.end());
		int ans = 0;
		REP(i, vec.size()) {
			int num = m - vec[i];
			if (num < 0)continue;
			int num2 = upper_bound(vec.begin(), vec.end(), num) - 1 - vec.begin();
			ans = max(vec[i] + vec[num2], ans);
		}
		cout << ans << endl;
	}
}

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

int count;

void merge(int* L, int* R, int* array, int left, int mid, int right)
{
    for(int i=left; i<mid; ++i) L[i - left] = array[i];
    for(int i=mid; i<right; ++i) R[i - mid] = array[i];
    int l = 0, r = 0;
    for(int i=left;i<right;++i)
    {
        if(l >= mid - left) array[i] = R[r++];
        else if(r >= right - mid) array[i] = L[l++];
        else if(R[r] < L[l]){
            array[i] = R[r++];
        }
        else
        {
            array[i] = L[l++];
        }
        ++count;
    }
}

void mergeSort(int* L, int* R, int* array, int left, int right)
{
    if(left < right - 1){
        int mid = (left + right) / 2;
        mergeSort(L, R, array, left, mid);
        mergeSort(L, R, array, mid, right);
        merge(L, R, array, left, mid, right);
    }
}

void printArray(int* array, int n)
{
    for(int i=0;i<n;++i)
    {
        if(i) cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main()
{
    int L[250000], R[250000], A[500000];
    int n;
    count = 0;
    cin >> n;
    for(int i=0;i<n;++i) cin >> A[i];
    mergeSort(L, R, A, 0, n);
    printArray(A, n);
    cout << count << endl;
}


Measured memory_bytes: 7000
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <cctype>
#include <cstring>
#include <sstream>
#define MOD 1000000007LL

using namespace std;

typedef long long ll;
typedef string::const_iterator State;
typedef pair<int,int> P;
int n[4];
int all;
int m;
string str[51];
map<string,int> ind;
vector<P> vec[51];
vector<int> rule;
ll dp[2][51][51][51][51];

void make_rule(int v){
	if(all<rule.size())return;
	for(int i=0;i<vec[v].size();i++){
		if(vec[v][i].first==0){
			rule.push_back(vec[v][i].second);
		}else{
			make_rule(vec[v][i].second);
		}
	}
}

void parse_2(State &begin,State &end,int par){
	if(*begin==' ')begin++;
	if(begin==end)return;
	if(*begin=='['){
		begin++;
		int bit=0;
		while(*begin!=']'){
			if(*begin=='A')bit|=(1<<0);
			if(*begin=='T')bit|=(1<<1);
			if(*begin=='G')bit|=(1<<2);
			if(*begin=='C')bit|=(1<<3);
			begin++;
		}
		begin++;
		vec[par].push_back(P(0,bit));
	}else{
		string st="";
		while(*begin!=' ' && begin!=end){
			st+=*begin;
			begin++;
		}
		if(ind.find(st)==ind.end()){
			int next=ind.size();
			ind[st]=next;
		}
		vec[par].push_back(P(1,ind[st]));
	}
	parse_2(begin,end,par);
	return;
}

void parse_1(State &begin,State &end){
	string st="";
	while(*begin!=':'){
		st+=*begin;
		begin++;
	}
	if(ind.find(st)==ind.end()){
		int next=ind.size();
		ind[st]=next;
	}
	int par=ind[st];
	begin++;
	begin++;
	parse_2(begin,end,par);
	return;
}

int main(void){
	for(int i=0;i<4;i++){
		scanf("%d",&n[i]);
		all+=n[i];
	}
	scanf("%d%*c",&m);

	for(int i=0;i<m;i++){
		getline(cin,str[i]);
		State begin=str[i].begin();
		State end=str[i].end();
		parse_1(begin,end);
	}
	make_rule(0);
	int prev=0,now=1;
	dp[prev][0][0][0][0]=1;
	for(int i=0;i<rule.size();i++){
		int g[4];
		for(g[0]=0;g[0]<=n[0];g[0]++){
			if(g[0]>i)continue;
			for(g[1]=0;g[1]<=n[1];g[1]++){
				if(g[0]+g[1]>i)continue;
				for(g[2]=0;g[2]<=n[2];g[2]++){
					if(g[0]+g[1]+g[2]>i)continue;
					for(g[3]=0;g[3]<=n[3];g[3]++){
						if(g[0]+g[1]+g[2]+g[3]>i)continue;
						if(dp[prev][g[0]][g[1]][g[2]][g[3]]>=1){
							if((rule[i]>>0 & 1) && g[0]+1<=n[0]){
								dp[now][g[0]+1][g[1]][g[2]][g[3]]+=dp[prev][g[0]][g[1]][g[2]][g[3]];
								if(dp[now][g[0]+1][g[1]][g[2]][g[3]]>=MOD)dp[now][g[0]+1][g[1]][g[2]][g[3]]-=MOD;
							}
							if((rule[i]>>1 & 1) && g[1]+1<=n[1]){
								dp[now][g[0]][g[1]+1][g[2]][g[3]]+=dp[prev][g[0]][g[1]][g[2]][g[3]];
								if(dp[now][g[0]][g[1]+1][g[2]][g[3]]>=MOD)dp[now][g[0]][g[1]+1][g[2]][g[3]]-=MOD;
							}
							if((rule[i]>>2 & 1) && g[2]+1<=n[2]){
								dp[now][g[0]][g[1]][g[2]+1][g[3]]+=dp[prev][g[0]][g[1]][g[2]][g[3]];
								if(dp[now][g[0]][g[1]][g[2]+1][g[3]]>=MOD)dp[now][g[0]][g[1]][g[2]+1][g[3]]-=MOD;
							}
							if((rule[i]>>3 & 1) && g[3]+1<=n[3]){
								dp[now][g[0]][g[1]][g[2]][g[3]+1]+=dp[prev][g[0]][g[1]][g[2]][g[3]];
								if(dp[now][g[0]][g[1]][g[2]][g[3]+1]>=MOD)dp[now][g[0]][g[1]][g[2]][g[3]+1]-=MOD;
							}
						}
					}
				}
			}
		}
		swap(now,prev);
		memset(dp[now],0,sizeof(dp[now]));
	}
	printf("%lld\n",dp[prev][n[0]][n[1]][n[2]][n[3]]);
	return 0;
}

Measured memory_bytes: 107012
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define INF 1145141919810364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s;
int cnt1, cnt2;

signed main() {
	cin >> s;
	int n = (int)s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] == '0')cnt1++;
		else cnt2++;
	}
	cout << min(cnt1, cnt2) * 2 << endl;
}

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

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int,int>
#define mii map<int,int>
#define mci map<char,int>
#define fir first
#define sec second
#define eline "\n"

int main() {

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

	string s;
	cin >> s;
	if (s == "ABC") cout << "ARC" << eline;
	else cout << "ABC" << eline;

	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;

    rep(i, N) {
        int a;
        cin >> a;
        if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {
            cout << "DENIED" << endl;
            return 0;
        }
    }

    cout << "APPROVED" << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(_) for _ in input().split()]

ans = 3**n

if a[0] % 2 == 0:
    cnt = 2
else:
    cnt = 1
for i in range(1, n):
    if a[i] % 2 == 0:
        cnt *= 2
    else:
        pass

print(ans-cnt)


Measured memory_bytes: 2940
#include <iostream>
#include <queue>
#include <math.h>
using namespace std;

main(){
	int n,k,tmp;
	int a[100010];
	long long ans;
	ans = 0;
	priority_queue<int> pq;
	
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		pq.push(a[i]);
	}
	
	while(k--){
		tmp = pq.top();
		tmp -= round(double(tmp)/2);
		pq.pop();
		pq.push(tmp);
	}
	for(int i=1;i<=n;i++){
		ans += pq.top();
		pq.pop();
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll MAX=500000;
const ll INF=(1ll<<62)-1;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=finv[1]=finv[0]=inv[0]=inv[1]=1;
    rep(i,2,MAX){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=modpow(i,MOD-2);
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
signed main(){
    ll A,B,N; cin>>A>>B>>N;
    ll ans;
    if(N>=B-1) ans=A*(B-1)/B;
    else ans=N*A/B;
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <numeric>
#include <map>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;

//繰り返し二乗法
ll power(ll a,ll b){
	ll res=1;
	while(b>0){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}

struct perm{
private:
	int sz;
	vector<ll> p,invp;
public:
	perm(int n){
		sz=n+1;
		p.resize(sz),invp.resize(sz);
		p[0]=1;
		for(int i=1;i<=sz-1;i++){
			p[i]=p[i-1]*i%mod;
		}
		invp[sz-1]=power(p[sz-1],mod-2);
		for(int i=sz-2;i>=0;i--){
			invp[i]=invp[i+1]*(i+1)%mod;
		}
	}
	ll comb(ll x,ll y){
		if(x<y||y<0)return 0;
		return (p[x]*invp[x-y]%mod)*invp[y]%mod;
	}
};
perm p(1<<20);

template<typename T>
map<T,ll> factorize(T x){
	map<T,ll> res;
	for(ll i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
			res[i]++;
		}
	}
	if(x!=1) res[x]++;
	return res;
}


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	ll ans=1;
	auto pp=factorize(m);
	for(auto ppp:pp){
		(ans*=p.comb(n-1+ppp.second,ppp.second))%=mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 16768
package main

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

// https://qiita.com/tnoda_/items/b503a72eac82862d30c6
// Scannerのサンプル
// https://baubaubau.hatenablog.com/entry/2017/11/17/214635

const (
	initialBufSize = 1e4
	maxBufsize     = 1e6 + 7
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufsize)
}

func main() {
	sc.Scan()
	// Bytesでそのまま入れるとbufferが足りなくなる？
	S := append(make([]byte, 0, 1e6), sc.Bytes()...)

	sc.Scan()
	Q, _ := strconv.Atoi(sc.Text())
	rev := false
	t := make([]byte, 0, 1e6)
	for i := 0; i < Q; i++ {
		sc.Scan()
		T, _ := strconv.Atoi(sc.Text())
		if T == 1 {
			rev = !rev
		} else {
			sc.Scan()
			F, _ := strconv.Atoi(sc.Text())
			F--
			sc.Scan()
			C := sc.Text()
			if rev {
				F = 1 - F
			}
			if F == 0 {
				t = append(t, C[0])
			} else {
				S = append(S, C[0])
			}
		}
	}
	t = ReverseByte(t)
	ans := append(t, S...)
	if rev {
		ans = ReverseByte(ans)
	}
	fmt.Println(string(ans))
}

func ReverseByte(s []byte) []byte {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
	return s
}


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

int main(){
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  sort(a.begin(), a.end(), greater<ll>());
  
  ll one=0,two=0;
  int count=0;
  for(int i=0;i<n-1;i++){
    if(a.at(i) == a.at(i+1) && count==0){
      one = a.at(i);
      i++;
      count++;
    }
    else if(count==1 && a.at(i) == a.at(i+1)){
      two = a.at(i);
      break;
    }
  }
  cout << one * two << endl;
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;

int main() {
  string s;
  cin>>s;
  for(int i:irange(0,(int)s.size(),2)){
    cout<<s[i];
  }
  cout<<'\n';
  return(0);
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;
int n,a[22],res=0,maxa=0;
int main()
{
    //freopen("B.INP","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        if (maxa <= a[i]) res++;
        maxa=max(maxa,a[i]);
    }
    cout << res;
}


Measured memory_bytes: 256
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    n=int(input())
    print('Yes' if n in [4*x+7*y for x in range(101) for y in range(101)] else 'No')


resolve()

Measured memory_bytes: 3316
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	a, b, c := NextIntArray(), NextIntArray(), NextIntArray()

	sort.Ints(a)
	sort.Ints(b)
	sort.Ints(c)

	count := 0
	for _, v := range b {
		count += lesserCount(v, a) * largerCount(v, c)
	}
	fmt.Println(count)
}

func largerCount(compared int, list []int) int {
	count := 0
	lis := list
	for len(lis) > 0 {
		if len(lis) == 1 {
			if compared < lis[0] {
				count += 1
			}
			lis = []int{}
		} else {
			left, right := SplitAt(lis, len(lis)/2)
			if compared < right[0] {
				count += len(right)
				lis = left
			} else {
				lis = right
			}
		}
	}
	return count
}

func lesserCount(compared int, list []int) int {
	count := 0
	lis := list
	for len(lis) > 0 {
		if len(lis) == 1 {
			if compared > lis[0] {
				count += 1
			}
			lis = []int{}
		} else {
			left, right := SplitAt(lis, len(lis)/2)
			if left[len(left)-1] < compared {
				count += len(left)
				lis = right
			} else {
				lis = left
			}
		}
	}
	return count
}

func SplitAt(list []int, i int) ([]int, []int) {
	if len(list) <= 1 {
		return list, []int{}
	} else if len(list) <= 3 {
		return list[0:1], list[1:]
	} else {
		r1, r2 := list[0:i-1], list[i-1:]
		return r1, r2
	}
}

// reader

var size = 1000000
var rdr = bufio.NewReaderSize(os.Stdin, size)

func ReadLine() string {
	buf := make([]byte, 0, size)
	for {
		line, isPrefix, err := rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func NextArray() []string {
	s := ReadLine()
	return strings.Split(s, " ")
}

func NextIntArray() []int {
	a := NextArray()
	na := make([]int, 0)

	for _, v := range a {
		if n, e := strconv.Atoi(v); e == nil {
			na = append(na, n)
		}
	}

	return na
}


Measured memory_bytes: 15360
n = int(input())
x_str = input().split()
xs = [int(c) for c in x_str]

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = xs[:]
c_xs.sort()

for x in xs:
    print(c_xs[center+1] if x <= c_xs[center] else c_xs[center])


Measured memory_bytes: 93780
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#include <limits>
#include <numeric>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

ll gcd(ll n, ll m) {
    if (m > n) {
        return gcd(m, n);
    }
    if (m == 0) {
        return n;
    }
    return gcd(m, n - n/m * m);
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    ll N, M;
    string S, T;
    cin >> N >> M >> S >> T;
    
    if (M > N) {
        swap(M, N);
        swap(S, T);
    }
    ll g = gcd(N, M);
    ll L = N*M/g;
    
    if (S[0] != T[0]) {
        cout << -1 << endl;
        return 0;
    }
    
    for (ll k = 0; k < g; ++k) {
        if (S[k * L/M] != T[k * L/N]) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    cout << L << endl;

    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x1,x2,x3,x4,x5,y;

int main(){
  ll ans=0;
  cin >> x1>>x2>>x3>>x4>>x5;
  if (x1==0)ans=1;
  if (x2==0)ans=2;
  if (x3==0)ans=3;
  if (x4==0)ans=4;
  if (x5==0)ans=5;
  cout<<ans<<endl;
  return 0;
}

/*
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k;
  string s;cin>>s;
  vi a(n),b(n);
  REP(i,n) cin>>a[i];
  cout<<ans<<endl;
  return 0;
}
*/

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> X(N), Y(N), idx(N);
    REP(i,N) cin >> X[i];
    REP(i,N) cin >> Y[i];
    iota(idx.begin(), idx.end(),1);
    int p = -1, q = -1;
    int cnt = 1;
    do{
        if(X == idx) p = cnt;
        if(Y == idx) q = cnt;
        cnt++;
    }while(next_permutation(idx.begin(),idx.end()));
    cout << abs(p - q) << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
		}

		boolean flg = false;

		a:for(int i = 0;i < a.length;i++ ){
			if(a[i] % 2 == 0){
				if(a[i] % 3 == 0 || a[i] % 5 == 0){

				} else {
					flg = true;
					break a;
				}
			}
		}

		if(flg){
			System.out.println("DENIED");
		} else{
			System.out.println("APPROVED");
		}
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23124