akhauriyash/Code-Regression huggingface dataset:
import sys
a = [list(map(int,input().split())) for i in range(3)]

b = [a[0][0],a[1][0],a[2][0]] 

for i in range(2):
    if  not a[0][i+1] - b[0] == a[1][i+1] - b[1] == a[2][i+1] - b[2]:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 3064
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys  # def input(): return sys.stdin.readline().rstrip() # sys.setrecursionlimit(10**6)

n = int(input())
A = list(int(x) for x in input().split())
q = int(input())
BC = [tuple(int(x) for x in input().split()) for _ in range(q)]

d = defaultdict(int)
for a in A:
    d[a] += 1

ans = sum(key*value for key, value in d.items())
for b, c in BC:
    db = d[b]
    dc = d[c]
    d[b] = 0
    d[c] = dc + db
    ans += c*(dc+db) - (b*db + c*dc)
    print(ans)

Measured memory_bytes: 107328
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string str;

void C(int len){
    char tmp = str[0];
    for(int i = 1 ; i < len; i++){
        str[i-1] = str[i];
    }
    str[len-1] = tmp;
}

void J(int len){
    char tmp = str[len-1];
    for(int i = len-2; i >=0 ; i--){
        str[i+1] = str[i];
    }
    str[0] = tmp;
}

void E(int len){
    int div = len/2;
    
    if(len%2==0){
        string f = str.substr(0,div) , g = str.substr(div,len-1);
        str = "";
        str += g+f;
    }
    else{
        string f = str.substr(0,div), g = str.substr(div+1,len);
        string mid = str.substr(div,1);
        str = "";
        str += g+mid+f;
    }
}

void A(){
    reverse(str.begin(),str.end());
}

void M(int len){
    for(int i = 0 ; i < len ; i++){
        if('0' <= str[i] && str[i] <= '8'){
            str[i] += 1;
        }
        else if(str[i] == '9') str[i] = '0';
    }
}

void P(int len){
    for(int i = 0 ; i < len ; i++){
        if('1' <= str[i] && str[i] <= '9'){
            str[i] -= 1;
        }
        else if(str[i] == '0') str[i] = '9';
    }
}

int main(){
    int n;
    cin >> n;
    while(n--){
        string order;
        cin >> order >> str;
        
        int len = str.size();
        reverse(order.begin(),order.end());
        
        for(int i = 0 ; i < order.size() ; i++){
            switch(order[i]){
                    case 'J':
                    J(len);
                    break;
                    
                    case 'C':
                    C(len);
                    break;
                    
                    case 'E':
                    E(len);
                    break;
                    
                    case 'A':
                    A();
                    break;
                    
                    case 'M':
                    M(len);
                    break;
                    
                    case 'P':
                    P(len);
                    break;
            }
        }
        cout << str << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
char s[200111];
int main()
{
	scanf("%s", s+1);
	int n = strlen(s+1);
	int cnt = 0;
	ll ans = 0;
	for (int i=n; i>=1; i--)
	{
		if (s[i]=='C'&&s[i-1]=='B') cnt++, i--;
		else if (s[i]=='A') ans += cnt;
		else cnt = 0;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

#define LOCAL  1
#define UPLOAD 2

using namespace std;

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    cout << pow(N, 3) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;
int main(void)
{
    int a, b;
    cin >> a >> b;
    
    for (int i = b - (a - 1); i <= b + (a - 1); i++)
    {
        cout << i << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import math
n,k=map(int, input().split())
a=list(map(int, input().split()))
right=max(a)
left=0
def cutable(a,x):
    count=0
    for i in a:
        count+=math.ceil(i/x)-1
    return count<=k
while right>left+1:
    mid=(right+left)//2
    if cutable(a,mid):
        right=mid
    else:
        left=mid
print(right)

Measured memory_bytes: 31048
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    S = SI()
    l = 0
    r = N - 1
    ans = 0
    if S.count("R") == 0 or S.count("R") == N:
        print(0)
        exit()

    while r - l >= 1:
        if S[l] == "W" and S[r] == "R":
            ans += 1
            l += 1
            r -= 1
        elif S[l] == "W":
            r -= 1
        elif S[r] == "R":
            l += 1
        else:
            l += 1
            r -= 1

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9800
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <math.h>
#include <set>
#define MAXN 100050
#define INF (1<<28)
#define LLINF (1LL<<40)
#define LL long long
#define ri register int
using namespace std;
int n, cnt, a[MAXN], b[MAXN], Cou[MAXN], rt;
struct node{
	int ls, rs, size;
}t[MAXN<<5];
void ins(int &u, int l, int r, int x, int w) {
	if(!u) u = ++cnt;
	t[u].size += w;
	if(l == r) return ;
	int mid = (l+r)>>1;
	if(x <= mid) ins(t[u].ls, l, mid, x, w);
	else ins(t[u].rs, mid+1, r, x, w);
}
int query(int u, int l, int r, int k) {
	if(!u || l > k) return 0;
	if(r <= k) return t[u].size;
	int mid = (l+r)>>1;
	return query(t[u].ls, l, mid, k) + query(t[u].rs, mid+1, r, k);
}
LL calc(int mid) {
	LL ret = 0;
	ins(rt, -n, n, 0, 1);
	for(ri i = 1; i <= n; ++i) {
		if(a[i] >= mid) Cou[i] = Cou[i-1]+1;
		else Cou[i] = Cou[i-1]-1;
		ret += query(rt, -n, n, Cou[i]);
//		cout<<i<<' '<<Cou[i]<<' '<<ret<<endl;
		ins(rt, -n, n, Cou[i], 1);
	}
	ins(rt, -n, n, 0, -1);
	for(ri i = 1; i <= n; ++i) ins(rt, -n, n, Cou[i], -1), Cou[i] = 0;
	return ret;
}
int main()
{
	scanf("%d", &n);
	for(ri i = 1; i <= n; ++i) scanf("%d", &a[i]), b[i] = a[i];
	sort(b+1, b+n+1);
	int ccnt = unique(b+1, b+n+1)-b-1;
	for(ri i = 1; i <= n; ++i) a[i] = lower_bound(b+1, b+ccnt+1, a[i]) - b;
	int l = 1, r = ccnt, mid, ans;
	while(l <= r) {
		mid = (l+r)>>1;
		LL num = calc(mid);
//		cout<<l<<' '<<r<<' '<<mid<<' '<<num<<endl;
		if(num >= 1LL*n*(n+1)/4) ans = mid, l = mid+1;
		else r = mid-1;
	}
	printf("%d", b[ans]);
	return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=200005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N, A[MAXN];
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	FOR(i,1,N) cin >> A[i];
	if (N == 2){
		cout << max(A[1], A[2]);
		exit(0);
	}
	sort(A+1, A+1+N, greater<int>());
	int ans = A[1];
	FOR(i,2,N-1){
		int from = (i/2) + 1;
		ans += A[from];
	}
	cout<<ans;
}


Measured memory_bytes: 5204
#include<bits/stdc++.h> //ABC 170_a
#define ll long long
using namespace std;
int x1,x2,x3,x4,x5;
int main(){
	cin>>x1>>x2>>x3>>x4>>x5;
	if(x1==0)
		cout<<1;
	else if(x2==0)
		cout<<2;
	else if(x3==0)
		cout<<3;
	else if(x4==0)
		cout<<4;
	else if(x5==0)
		cout<<5;
	return 0;
}

Measured memory_bytes: 3588
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#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 all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int CMAX = 1010;
int noinit = 1;
ll memo[CMAX][CMAX];

ll aCb(ll a, ll b){
    if(noinit){
        for(int i = 0; i < CMAX; i++){
            for(int j = 0; j < CMAX; j++){
                memo[i][j] = -1;
            }
        }
        noinit = 0;
    }

    if(b == 0 || a == b) return 1;
    if(0 <= memo[a][b]) return memo[a][b];
    return memo[a][b] = aCb(a-1, b-1) + aCb(a-1, b);
}

int N, P, A[101];

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

    cin >> N >> P;
    for(int i = 0; i < N; i++) cin >> A[i];

    int odd = 0, even = 0;
    for(int i = 0; i < N; i++){
        if(A[i] % 2 == 1) odd++;
        else even++;
    }

    ll ans = 0;
    int c = P;
    //P = 0 の時 2^even * (C(odd,0) + C(odd,2) + C(odd,4) + ...)
    //P = 1 の時 2^even * (C(odd,1) + C(odd,3) + C(odd,5) + ...)
    while(c <= odd) ans += aCb(odd, c), c += 2;
    for(int i = 0; i < even; i++) ans *= 2;

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

    return 0;
}

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

using namespace std;

long long knapsack[105][100005];
int weights[105];
int values[105];


int main(){
	int num_items ,total_weight;
	cin >> num_items >> total_weight;
	for(int i=1;i<=num_items;i++){
		cin >> weights[i] >> values[i];
	}

	for(int avail_weight=1; avail_weight<= total_weight; avail_weight++){
		for(int item=1; item<=num_items;item++){
			if(avail_weight<weights[item])
				knapsack[item][avail_weight] = knapsack[item-1][avail_weight];
			else
				knapsack[item][avail_weight] = max(knapsack[item-1][avail_weight],
										knapsack[item-1][avail_weight-weights[item]]+values[item]);


		}
	}

	cout << knapsack[num_items][total_weight];
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    ld n, k; cin >> n >> k;

    ld ans = 0;
    V<ld> v(n);
    for(int i = 1; i <= n; i++){
        ll t = i, cnt = 0;
        if(t < k){
            while(1){
                t *= 2;
                cnt++;
                if(k <= t) break;
            }
            ans += (1 / (ld)(pow(2, cnt) * n));
        }else{
            ans += (1 / n);
        }
    }
    cout << setprecision(15) << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  
  vector<int> x(N);
  vector<int> y(M);
  
  for(int i=0;i<N;++i){
    cin>>x[i];
  }
  
  for(int i=0;i<M;++i){
    cin>>y[i];
  }
  
  int x_max=X;
  int y_min=Y;
  
  for(int i=0;i<N;++i){
  	x_max=max(x_max,x[i]);
  }
  
  for(int i=0;i<M;++i){
    y_min=min(y_min,y[i]);
  }
  
  if(y_min>x_max)
    cout<<"No War"<<endl;
  else
    cout<<"War"<<endl;
}


Measured memory_bytes: 256
a = input()
b = input()
c = list(b)
d = 0
e = c.count(".")
f = 0
for i in range(len(c)+1): #左からi個を白にする　0<=i<=len(c)
    if i == 0:
        ans = e
    else:
        if c[i-1] == ".":
            d = d + 1 #dは左からi個のうちの白の個数を指す
        f = (i - d) + (e - d) #左側の(i-d)個の黒を白にし、右側(e-d)個の白を黒にする
        ans = min(ans, f)
print(ans)

Measured memory_bytes: 4840
inpl = lambda: list(map(int,input().split()))
R,G,B,N = inpl()
(R,G,B) = sorted([R,G,B])
ans = 0
for b in range(N//B+1):
    N1 = N - b*B
    for g in range(N1//G+1):
        N2 = N1 - g*G
        if N2 % R == 0:
            ans += 1
print(ans)

Measured memory_bytes: 40300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    string s;
    cin >> s;
    string ans = "Good";
    if (s[0] == s[1] or s[1] == s[2] or s[2] == s[3]) {
        ans = "Bad";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>

using namespace std;

long long Sum(vector<int>& a) {
	long long sum = 0;
	for (int i = 1; i < a.size(); ++i) {
		sum += a[i];
	}
	return sum;
}

void Solve() {
	int n;

	cin >> n;

	vector<int> a(n + 1), b(n + 1);

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

	for (int i = 1; i <= n; ++i) {
		cin >> b[i];
	}

	long long have = Sum(b) - Sum(a);
	long long need = 0;

	for (int i = 1; i <= n; ++i) {
		if (a[i] < b[i]) {
			need += (b[i] - a[i] + 1) / 2;
		}
	}

	// cerr << need << " " << have << "\n";

	if (have < need) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
}


int main() {
	int tests = 1;

	for (;tests; --tests) {
		Solve();
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, a, b, l, r = 1e9, m, h[N];

bool f(ll p) {
	ll i, s = 0;
	for (i = 0; i < n; i++)
		s += max(0LL, (h[i] - p * b + a - 1) / a);
	if (s <= p) return 1;
	else return 0;
}

int main()
{
	ll i;
	cin >> n >> a >> b;
	a -= b;
	for (i = 0; i < n; i++) scanf("%lld", &h[i]);
	while (l < r) {
		m = (l + r) / 2;
		if (f(m)) r = m;
		else l = m + 1;
	}
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
		
		public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a))System.out.println("Yes");
		else System.out.println("No");
		
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 10000;

int a[MAXN];

int main() {
  int N;
  cin >> N;
  for(int i = 0;i < N;i++) cin >> a[i];
  int ans = 0;
  for(int i = 0;i < N;i++) {
    int cnt = 0;
    while(a[i]%2 == 0) {
      a[i] /= 2;
      cnt++;
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = N % 1000 / 100;
  c = N % 1000 % 100 / 10;
  d = N % 1000 % 100 % 10;
  if ((a==b && b==c) || (b==c && c==d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
a, b, k = map(int, input().split(" "))
if a + b <= k:
    print('0 0')
    exit()
else:
    if k > a:
        b = b - k + a
        a = 0
    elif k <= a:
        a = a-k
    print(str(a) + ' ' + str(b))

Measured memory_bytes: 2940
#E A, B, C = gets.chomp.split.map(&:to_i)
N = gets.chomp.to_i
H = gets.chomp.split.map(&:to_i)

def can_decrease?
  1.upto(N - 1).each do |i|
    if H[i] < H[i-1]
      return false
    elsif H[i] == H[i-1]
      # continue
    else  # H[i] > H[i-1]
      H[i] -= 1
      # continue
    end
  end
  
  true
end

r = can_decrease?

# p H
if r
  print "Yes\n"
else
  print "No\n"
end

Measured memory_bytes: 9732
n, k = map(int, input().split())
v = list(map(int, input().split()))
maxvalue = 0
for l in range(n+1):
    for r in range(l, n+1):
        ava = sorted(v[:l] + v[r:])
        takeop = len(ava)
        if takeop <= k:
            value = sum(ava)
            for i in range(min(takeop, k - takeop)):
                if ava[i] >= 0:
                    break
                else:
                    value -= ava[i]
            maxvalue = max(maxvalue, value)
print(maxvalue)

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

#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> pi;


int main()
{
    int n;
    string s;
    cin>>n>>s;
    n=n%26;
    for(int i=0; i<s.length(); i++)
    {
        //cout<<s[i]+n<<endl;
        s[i] = char((int(s[i]-'A')+n)%26 + 'A' ) ;
    }
    cout<<s;
}



Measured memory_bytes: 256
S = raw_input()
flag = True
if len(S) % 2 == 1:
    flag = False
else:
    for i in range(len(S)/2):
        if S[i] == "b":
            if S[-i-1] != "d":
                flag = False
                break
        elif S[i] == "d":
            if S[-i-1] != "b":
                flag = False
                break
        elif S[i] == "p":
            if S[-i-1] != "q":
                flag = False
                break
        else:
            if S[-i-1] != "p":
                flag = False
                break
       

if flag:
    print "Yes"
else:
    print "No"

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

int a[15];
int t, m, A, B;

bool dfs(int k, int A, int B)
{
    if(k == 10) return true;
    if(a[k] > A) {
        if(dfs(k + 1, a[k], B))
            return true;
    }
    if(a[k] > B) {
        if(dfs(k + 1, A, a[k]))
            return true;
    }
    return false;
}

int main()
{
    cin >> t;
    while(t--) {
        for(int i = 0; i < 10; ++i) {
            cin >> a[i];
        }

        if(dfs(0, 0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
A = []
x = []
y = []
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    A.append(a)
    if a == 0:
        x.append(None)
        y.append(None)
        continue
    xi, yi = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int64).T
    x.append(xi-1)
    y.append(yi)

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        for i in range(n):
            if not comb >> i & 1:
                continue
            if not A[i]:
                cnt += 1
                continue
            if np.count_nonzero(comb >> x[i] & 1 ^ y[i]):
                break
            cnt += 1
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)


Measured memory_bytes: 14432
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;



signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,sum=0,odd=0;
    cin>>n;
    vector<int>a(n),x(n);
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
        if(i%2)odd+=2*a[i];
    }
    x[0]=sum-odd;
    rep(i,1,n){
        x[i]=2*a[i-1]-x[i-1];
    }
    rep(i,0,n){
        cout<<x[i]<<endl;
    }
}

Measured memory_bytes: 2944
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

sat=sum(b)
for i in range(n-1):
  if a[i+1]-a[i]==1:
    sat+=c[a[i]-1]
    
print(sat)

Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAX 100+5
int num;
int m[MAX][MAX],a[MAX],d[MAX],color[MAX];//color[i]中0--白色；1--灰色；2--黑色； 
void bfs(int v){
	queue<int> q;
	q.push(v);d[v]=0;
	color[v]=1;
	int shou;
	while(!q.empty()){
	shou=q.front();q.pop();
	for(int i=1;i<=num;i++){
		if(m[shou][i]==1&&color[i]==0){
			q.push(i);d[i]=d[shou]+1;color[i]=1;
		}
		color[shou]=2;
	}
	}
	return ;
}
int main(){
	memset(m,0,sizeof(m));
	memset(color,0,sizeof(color));
	memset(d,-1,sizeof(d)); 
	cin>>num;
	for(int i=1;i<=num;i++){
		int cnt;
		cin>>a[i]>>cnt;
		for(int j=0;j<cnt;j++){
			int c;
			cin>>c;
			m[a[i]][c]=1; 
		}
	}
	bfs(1);
	for(int i=1;i<=num;i++){
		cout<<a[i]<<" "<<d[a[i]]<<endl;
	}
	
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, k);
	IN(string, s);
	
	OUT(SI(s) <= k ? s : s.substr(0, k) + "...");
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

struct card {
    char suit;
    int  value;
};

void bubbleSort(card a[], const int n) {
    int flag = 1;
    for (int i = 0; flag; ++i) {
        flag = 0;
        for (int j = n - 1; i < j; --j)
            if (a[j].value < a[j - 1].value) {
                swap(a[j], a[j - 1]);
                flag = 1;
            }
    }
}

void selectionSort(card a[], const int n) {
    for (int i = 0; i < n; ++i) {
        int min = i;
        // iより後でA[i]より最も小さい値の添字を求める
        for (int j = i; j < n; ++j)
            if (a[j].value < a[min].value) min = j;
        // iとminが異なれば交換
        if (i != min) swap(a[i], a[min]);
    }
}

int main() {
    int n;
    cin >> n;
    card a[n], b[n];
    rep(i, n) {
        cin >> a[i].suit >> a[i].value;
        b[i] = a[i];
    }

    bubbleSort(a, n);
    selectionSort(b, n);

    //バブルソートの結果を出力
    rep(i, n) {
        if (0 < i) cout << " ";
        cout << a[i].suit << a[i].value;
    }

    cout << endl;
    cout << "Stable" << endl;

    // //選択ソートの結果を出力
    bool flag = true;
    for (int i = 0; i < n; ++i) {
        if (0 < i) cout << " ";
        cout << b[i].suit << b[i].value;
        if (!(b[i].suit == a[i].suit && b[i].value == a[i].value)) flag = false;
    }
    cout << endl;
    if (flag)
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;

    return 0;
}



Measured memory_bytes: 3100
import java.util.Scanner;

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

		int K = sc.nextInt();
		int count1 = 0;
		int count2 = 0;

		for (int i = 0; i < K; i++ ) {
			if (i%2 == 0) {
				count1++;
			} else {
				count2 ++;
			}
		}
		System.out.println( count1 * count2 );
	}
}

Measured memory_bytes: 21844
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
  long long x = 1;
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

ll popcount(ll x){
  x = (x & 0x5555555555555555ULL) + ((x & 0xAAAAAAAAAAAAAAAAULL)>>1);
  x = (x & 0x3333333333333333ULL) + ((x & 0xCCCCCCCCCCCCCCCCULL)>>2);
  x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x & 0xF0F0F0F0F0F0F0F0ULL)>>4);
  x *= 0x0101010101010101ULL;
  return x >> 56;
}

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

  ll rate[4];
  rep(i,0,4)std::cin>>rate[i];

  ll ans=MOD;

  rep(bit,0,1ll<<4){
    ll a=0,b=0;
    rep(i,0,4){
      if((bit>>i)&1)a+=rate[i];
      else b+=rate[i];
    }
    if(popcount(bit)==2)chmin(ans,std::abs(a-b));
  }

  std::cout<<ans<<"\n";

  return 0;
}



Measured memory_bytes: 3220
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n, sum = 0, maxV = 0, tmp;
    cin >> n;
    while (n--) cin >> tmp, sum += tmp, maxV = max(maxV, tmp);
    cout << sum - maxV / 2 << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back

using namespace std;
typedef long long ll;

int main()
{
  int N; cin >> N;
  vector<int> C(N - 1), S(N - 1), F(N - 1);
  REP(i, N - 1) cin >> C[i] >> S[i] >> F[i];
  REP(s, N) {
    int t = 0;
    for (int i = s; i < N - 1; i++) {
      if (S[i] > t) t = S[i];
      else if (t % F[i] != 0) t += F[i] - (t % F[i]);
      t += C[i];
    }
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())

x = []
for i in range(N - 1):
    c, s, f = map(int, input().split())
    x.append([c, s, f])

ans = []
for i in range(N - 1):
    t = x[i][0] + x[i][1]
    for j in range(i + 1, N - 1):
        if t % x[j][2] == 0:
            t = max(t, x[j][1])
        else:
            t = max(t + (x[j][2] - t % x[j][2]), x[j][1])
        t += x[j][0]
    ans.append(t)
ans.append(0)

for i in range(N):
    print(ans[i])


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    ll a, b, c; cin >> a >> b >> c;
    ll ans = 0;
    if(a + b + 1 >= c) ans = b + c;
    else ans = (a + b + 1) + b;
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 305;
ld dp[N][N][2];
int n, t[4];

void table() {
	for (int t3 = 0; t3 <= t[3]; t3++){
		int pr1 = t3 % 2, pr2 = (pr1 + 1) % 2;
		for (int t2 = 0; t2 <= n; t2++)
			for (int t1 = 0; t1 <= n; t1++) {
				int t0 = n - (t1 + t2 + t3);
				ld &ans = dp[t1][t2][pr1];
				if (t0 == n)
					ans = 0;
				else {
					ans = 1;
					if (t1)
						ans += dp[t1 - 1][t2][pr1] * ((ld) t1 / n);
					if (t2)
						ans += dp[t1 + 1][t2 - 1][pr1] * ((ld) t2 / n);
					if (t3)
						ans += dp[t1][t2 + 1][pr2] * ((ld) t3 / n);
					ans /= (1 - ((ld) t0 / n));
				}
			}
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		t[a]++;
	}
	table();
	cout << fixed << setprecision(12) << dp[t[1]][t[2]][t[3] % 2];
	return 0;
}


Measured memory_bytes: 6636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;

bool check(const vector<int> &A, long long d, int K){
  int c = 0;
  vector<long long> R;
  for(auto a : A) R.push_back(a%d);
  sort(R.begin(), R.end());
  int l = 0, r = (int)R.size()-1;
  while(r-l > 0){
    int t = min(R[l],d-R[r]);
    R[l] -= t;
    R[r] += t;
    if(R[l] == 0) ++l;
    if(R[r] == d) --r;
    c += t;
  }
  return c <= K;
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  long long s = 0;
  for(int i = 0; i < N; ++i) cin >> A[i], s += A[i];
  long long ans = 0;
  for(long long i = 1; i*i <= s; ++i){
    if(s%i) continue;
    if(check(A,i,K)) ans = max(ans,i);
    if(check(A,s/i,K)) ans = max(ans,s/i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
W = list(map(int,input().split()))
min_w = 10000000
for i in range(N):
  T1 = W[:i]
  T2 = W[i:]
  if min_w > abs(sum(T1)-sum(T2)):
    min_w = abs(sum(T1)-sum(T2))
print(min_w)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
char str[200005];
int main() {
	int n, q;
	scanf("%d%d%s", &n, &q, str);
	vector<char> t(q), d(q);
	for (int i = 0; i < q; ++i) {
		scanf(" %c %c", &t[i], &d[i]);
	}
	auto simulate = [&](int p) {
		for (int i = 0; i < q; ++i) {
			if (p == 0 || p == n + 1) continue;
			if (str[p - 1] != t[i]) continue;
			if (d[i] == 'L') --p;
			else ++p;
		}
		return p;
	};
	int lo = 0, hi = n + 1;
	while (lo < hi) {
		int m = (lo + hi) >> 1;
		if (simulate(m) == n + 1) hi = m;
		else lo = m + 1;
	}
	int r = lo;
	lo = 0;
	hi = n + 1;
	while (lo < hi) {
		int m = (lo + hi + 1) >> 1;
		if (simulate(m) == 0) lo = m;
		else hi = m - 1;
	}
	int l = lo;
	int ans = n - (n + 1 - r) - l;
	printf("%d\n", ans);
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
const int max = 205;
char s[max],t[max];
bool _judge(int index,int n){
	bool flag = true;
	int j = 0;
	for(int i = index;i<n; i++){
		if(s[i] != t[j++]){
			flag = false;break;
		}
	}
	for(int i = 0;i<index;i++){
		if(s[i]!=t[j++]){
			flag = false;break;
		}
	}
	return flag;
}
int main()
{
	while(~scanf("%s",s)){
		getchar();
		scanf("%s",t);
		int len = strlen(s);
		bool judge = false;
		for(int i = 0;i<len;i++){
			if(_judge(i,len)){
				judge = true;
				break;
			}
		}
		if(judge)
			printf("Yes\n");
		else printf("No\n");
	}
	
	return 0;
 } 
 /*
asdfdseeffddee
bsdfdsaeffdwss
*/

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

#define ALL(v) v.begin(), v.end()
typedef long long ll;



using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> h(n);

	int maxz =  0;
	int count = 0;
	
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		if (i != 0) {
			if (h[i - 1] >= h[i]) {
				count++;
			}
			else {
				maxz = max(maxz,count);
				count = 0;
			}
		}
	}
	
	maxz = max(maxz, count);


	cout << maxz << endl;
	

}

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

B = []
b = 0
for i in range(N):
    if i % 2 == 0:
        b += A[i]
    else:
        b -= A[i]
B.append(b)
for i in range(1, N):
    b *= -1
    b += A[i-1] * 2
    B.append(b)

print(*B)


Measured memory_bytes: 14028
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,A,B;
  
  cin >> N >> A >> B ;
  
  int C = N * A ;
  
  if ( C >= B ){
    cout << B << endl;
  }
  else {
    cout << C << endl;
  }
}

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

int main() {
  string s;
  cin >> s;
  int sum = 0;
  for (int i ; i < 3; i++) {
    if (s.at(i)=='1') {
      sum += 1;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.*;
public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] data = br.readLine().split(" ");
		
		int a = Integer.parseInt(data[0]);
		int b = Integer.parseInt(data[1]);
		
		System.out.println((a*b)+" "+ 2*(a+b)); 
	}
}

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

int main(){
    vector<vector<vector<int>>>a(4, vector<vector<int>>(3, vector<int>(10)));
    int n;
    cin >> n;
    for(int i=0; i < n; i++){
        int t, f, num, p;
        cin >> t >> f >> num >> p;
        a[t-1][f-1][num-1] += p;
    }
    for(int i=0 ; i < 4; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++){
                cout << ' ' << a[i][j][k];
            }
            cout << endl;
        }
        if(i != 3)for(int i=0; i < 20; i++){
            cout << "#";
        }
        if( i != 3)cout << endl;
        
    }
    return 0;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void){
    string s, t; cin >> s >> t;
    int lens = s.length();
    int lent = t.length();
    string initial[lent];
    for(int i = 0; i < lent; i++){
        if(s[0] == t[i]){
            if(i == 0) initial[0] += s[0];
            else if(initial[i-1].length() == 0) initial[i] = initial[i-1] + s[0];
            else initial[i] = initial[i-1];
        }
        else if(i == 0){
            initial[0] = "";
        }
        else{
            initial[i] = initial[i-1];
        }
    }
    string dp[2][lens];
    dp[0][0] = initial[0];
    for(int i = 1; i < lens; i++){
        if(t[0] == s[i]){
            if(dp[0][i-1].length() == 0) dp[0][i] = dp[0][i-1] + t[0];
            else dp[0][i] = dp[0][i-1];
        }
        else{
            dp[0][i] = dp[0][i-1];
        }
    }
    for(int i = 1; i < lent; i++){
        dp[i&1][0] = initial[i];
        for(int j = 1; j < lens; j++){
            //dp[i&1][j]に書き込む.使う情報はdp[!(i&1)][j-1], dp[!(i&1)][j], dp[i&1][j-1]
            if(t[i] == s[j] && dp[!(i&1)][j-1].length() == dp[!(i&1)][j].length()){
                dp[i&1][j] = dp[!(i&1)][j-1] + s[j];
            }
            else if(t[i] != s[j]){
                if(dp[i&1][j-1].length() > dp[!(i&1)][j].length()){
                    dp[i&1][j] = dp[i&1][j-1];
                }
                else{
                    dp[i&1][j] = dp[!(i&1)][j];
                }
            }
            else{
                dp[i&1][j] = dp[!(i&1)][j];
            }
        }
    }
    cout << dp[!(lent&1)][lens-1] << endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    string s;
    cin >> s;
    ll n = s.size();
    deque<char> dq;
    REP(i, n){
    	dq.push_back(s[i]);
    }
    ll Q;
    cin >> Q;
    ll now = 0;
    while(Q--){
    	ll T;
    	cin >> T;
    	if(T==1){
    		now = 1-now;
    	}else{
    		ll F;
    		char c;
    		cin >> F >> c;
    		if(F==1){
    			if(now==0){
    				dq.push_front(c);
    			}else{
    				dq.push_back(c);
    			}
    		}else{
    			if(now==0){
    				dq.push_back(c);
    			}else{
    				dq.push_front(c);
    			}
    		}
    	}
    }

    if(now==0){
    	while(!dq.empty()){
    		char tmp = dq.front();
    		dq.pop_front();
    		cout << tmp;
    	}
    }else{
    	while(!dq.empty()){
    		char tmp = dq.back();
    		dq.pop_back();
    		cout << tmp;
    	}
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 976
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n,m,l=get_i
a=Array.new(m)
n.times do|i|
  a[i]=get_i
end

b=Array.new(l)
m.times do|i|
  b[i]=get_i
end

ans=Array.new(n).map{Array.new(l){0}}
n.times do|i|
  l.times do|j|
    m.times do|k|
      ans[i][j]+=a[i][k]*b[k][j]
    end
  end
end
n.times do|i|
  puts ans[i].join(" ")
end


Measured memory_bytes: 7416
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<typename T>
vector<T> divisor_enumeration(T n){
    vector<T> ret1, ret2;
    for(T i=1; i*i<=n; i++){
        if(n%i == 0){
            ret1.push_back(i);
            if(i*i != n) ret2.push_back(n/i);
        }
    }
    reverse(ret2.begin(), ret2.end());
    ret1.insert(ret1.end(), ret2.begin(), ret2.end());
    return ret1;
}

ll n, s;

signed main(){
    cin >> n >> s;

    for(ll b=2; b*b<=n+1; b++){
        ll tmp = n;
        ll cnt = 0;
        while(tmp > 0){
            cnt += tmp % b;
            tmp /= b;
        }
        if(cnt == s){
            cout << b << endl;
            return 0;
        }
    }

    auto v = divisor_enumeration(n-s);
    rep(i, v.size()){
        ll b = v[i]+1;
        if(b == 1) continue;
        ll a2 = (n-s)/v[i];
        ll a1 = n%b;
        if(a2 < b && a2+a1 == s && a2*b+a1 == n){
            cout << b << endl;
            return 0;
        }
    }

    if(n == s){
        cout << n+1 << endl;
        return 0;
    }

    cout << -1 << endl;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>

using namespace std;

typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int N,tmp; 
    double sum;
    cin>>N;
    int x[N];
    sum=0;
    for (int i = 0; i < N; i++)
    {
        cin>>tmp;
        x[i]=tmp;
        sum+=tmp;
    }
    sum = round(sum/N);
    tmp=0;
    for (int i = 0; i < N; i++)
    {
        tmp += (x[i]-sum)*(x[i]-sum);
    }
    cout<<tmp;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp::max;
use std::cmp;

fn main() {
    input!{
    	n: i32,
    }
    let m  :i32 = (n + 1)/ 2;
    let ans:f64 = (m as f64/ n as f64);  
    print!("{}",&ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

long long N;
long long K;


bool C1(long long c, vector<ll> A, vector<ll> F) {
	ll sum = 0;
	rep(i, N) {
		if (A[i]*F[i] > c) sum += A[i]-c/F[i];
	}
	return sum > K;
}

int main(){	
	scanf("%lld",&N);
	scanf("%lld",&K);
	vector<long long> A(N);
	vector<long long> F(N);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&F[i]);
	}
	sort(A.begin(), A.end());
	sort(F.begin(), F.end(), greater<ll>() );

	// rep(i, N) {
	// 	cout << A[i] << " ";
	// }
	// cout << endl;
	// rep(i, N) {
	// 	cout << F[i] << " ";
	// }
	// cout << endl;

	long long lb = -1, ub = 1000000000001;
	while (ub - lb > 1) {
		long long mid = (lb + ub) / 2;
		if (C1(mid, A, F)) lb = mid;
		else ub = mid;
	}
	cout << ub << endl;
	return 0;
}



Measured memory_bytes: 6552
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >>n;
  int h[n],ans=0,now=0;
  for (int i=0;i<n;i++)cin >>h[i];
  for (int i=0;i<n;i++){
  	if (h[i]>now) ans+=h[i]-now;
    now=h[i];
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256