akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

int main()
{
    for(;;){
        double x1, y1, x2, y2, xq, yq;
        char tmp;
        if(!(cin >> x1 >> tmp >> y1 >> tmp >> x2 >> tmp >> y2 >> tmp >> xq >> tmp >> yq))
            return 0;

        double x, y;
        if(abs(y2 - y1) < EPS){
            x = xq;
            y = 2*y2 - yq;
        }else if(abs(x2 - x1) < EPS){
            x = 2*x2 - xq;
            y = yq;
        }else{
            double a = - (x2 - x1) / (y2 - y1);
            double b = yq - a * xq;
            double c = (y2 - y1) / (x2 - x1);
            double d = 2*y1 - yq + (xq - 2*x1) * c;

            x = (d - b) / (a - c);
            y = a * x + b;
        }

        printf("%.10f %.10f\n", x, y);
    }
}

Measured memory_bytes: 0
n=int(input())
a=[-1000000]+[int(x) for x in str(input()).split()]
for i in range(1,n+1):
  a[i]-=i

a.sort()
s=0
b=[-10000000]
for i in range(1,n+1):
  s+=a[i]
  b.append(s)

ave=n//2

s1=0
s2=0
s3=0
for i in range(1,n+1):
  s3+=abs(a[i]-a[(ave-1)])
  s1+=abs(a[i]-a[ave])
  s2+=abs(a[i]-a[(ave+1)])
print(min(s1,s2,s3))


Measured memory_bytes: 26016
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

inline void up(int &x,const int &y){if(x<y)x=y;}
inline void down(int &x,const int &y){if(x>y)x=y;}
const int maxn = 210000;

int n;
int a[maxn];

bool judge(const int N)
{
	int c1=0,c2=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==N-1) c1++;
		else if(a[i]==N) c2++;
		else return false;
	}
	if(c2==1) return false;
	int l=c1+(c2>0?1:0),r=c1+c2/2;
	if(l<=N&&N<=r) return true;
	return false;
}

int main()
{
	scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	
	if(judge(a[1])) puts("Yes");
	else if(judge(a[1]+1)) puts("Yes");
	else puts("No");
	
	return 0;
}


Measured memory_bytes: 640
public class Main {
	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < 10; j++) {
				sb.append(i).append("x").append(j).append("=").append(i * j).append("\n");
			}
		}
		sb.setLength(sb.length() - 1);
		System.out.println(sb.toString());
	}
}

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


int main(){
    int n;
    cin >> n;
    unordered_map<char, int> counter;
    rep(i,n){
        string s;
        cin >> s;
        counter[s[0]]++;
    }
    vector<ll> cnt = { counter['M'],
                        counter['A'],
                        counter['R'],
                        counter['C'],
                        counter['H']};
    ll ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            for(int k = j+1; k < 5; k++){
                ans += cnt[i]*cnt[j]*cnt[k];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

g = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

import sys

sys.setrecursionlimit(10 ** 6)


class Tree:
    WHITE = 0
    GRAY = -1
    BLACK = 1

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def init(self):
        self.__init__(self.adj)

    def dfs(self, u):
        if self.colors[u] == self.BLACK:
            return

        self.colors[u] = self.GRAY
        self.depths[u] = self.depth

        for v, w in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.depth += w
                self.dfs(v)
                self.depth -= w

        self.colors[u] = self.BLACK

    def bipartite_graph(self, u, c):
        self.colors[u] = c
        for v in self.adj[u]:
            if self.colors[v] == c:
                return False
            if self.colors[v] == self.WHITE and not self.bipartite_graph(v, -c):
                return False

        return True


tree = Tree(g)
if tree.bipartite_graph(0, tree.GRAY):
    black = tree.colors.count(tree.GRAY)
    white = tree.colors.count(tree.BLACK)
    ans = black * white - m

else:
    ans = n * (n - 1) // 2 - m

print(ans)


Measured memory_bytes: 54104
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int dp[3][100005];
int a[105];
int n, k;
int compute(int i, int cur)
{
    //cout<<i<<" "<<cur<<endl;
    if(dp[i][cur]!=-1) return dp[i][cur];
    int j;
    int ans = ninf;
    FOR0(j, n)
    {
        if(cur-a[j] >= 0)
        {
            ans = compute(1-i, cur - a[j]);
            if(ans == i) break;
        }
    }
    if(ans == ninf)
    {
        if(i==0) ans = 1;
        else ans = 0;
    }
    return dp[i][cur] = ans;
}
int main()
{
    she_told_me_dont_worry
    cin>>n>>k;
    int i, j;
    memset(dp, -1, sizeof dp);
    FOR0(i, n) cin>>a[i];
    bool is = false;
    if(compute(0, k)==0) cout<<"First";
    else cout<<"Second";
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 6144
n = int(input())
 
if n <10:
    count = n
elif n <100:
    count = 9
elif n <1000:
    count = n-90
elif n < 10000:
    count = 909
elif n < 100000:
    count = n-9090
else:
    count = 90909
 
print(count)

Measured memory_bytes: 3064
k,n = (int(x) for x in input().split())
la = list(map(int, input().split()))

l1 = la[:-1]
l2 = la[1:]

ls= [x - y for (x, y) in zip(l2, l1)]
ls.append(la[0]+k-la[n-1])

print(k-max(ls))


Measured memory_bytes: 26436
import numpy as np
N=int(input())
v=list(map(int, input().split()))
c=list(map(int, input().split()))
v=np.array(v)
c=np.array(c)
s=(v-c)
s=s.tolist()
s=[x if x>0 else 0 for x in s]
print(sum(s))

Measured memory_bytes: 12480
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main(){
  int n;
  cin >> n;
  int min = 1000000;
  int max = -1000000;
  long int sum = 0;
  for (int i=0; i<n; i++) {
    int a;
    cin >> a;

    if (max < a) {
      max = a;
    }
    if (a < min) {
      min = a;
    }
    sum += a;
  }

  printf("%d %d %ld\n", min, max, sum);

  return 0;
}



Measured memory_bytes: 3232
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = readInts()
    dic = defaultdict(int)
    ok = 0
    for i in range(n):
        if 1 <= A[i] <= 399:
            dic['g'] = 1
        elif 400 <= A[i] <= 799:
            dic['b'] = 1
        elif 800 <= A[i] <= 1199:
            dic['gr'] = 1
        elif 1200 <= A[i] <= 1599:
            dic['w'] = 1
        elif 1600 <= A[i] <= 1999:
            dic['bl'] = 1
        elif 2000 <= A[i] <= 2399:
            dic['f'] = 1
        elif 2400 <= A[i] <= 2799:
            dic['bbb'] = 1
        elif 2800 <= A[i] <= 3199:
            dic['adava'] = 1
        else:
            ok += 1
    cnt = 0
    for k,v in dic.items():
        cnt += 1
    if cnt != 0:
        print(cnt,cnt+ok)
    else:
        print(1,ok)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5148
import sys
import os

def file_input():
    f = open('../Beginner_Contest_164/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    S,W=map(int, input().split())

    if S <= W:
        print("unsafe")
    else:
        print("safe")

if __name__ == '__main__':
    main()


Measured memory_bytes: 9160
import numpy as np
n = int(input())
s = np.array(input().split(), np.int64)
mod = 10 ** 9 + 7

res = 0
po2 = 1
for i in range(61):
    bit = (s >> i) & 1
    x = np.count_nonzero(bit)
    y = n - x
    res += x * y % mod * po2
    res %= mod
    po2 *= 2 % mod
print(res)


Measured memory_bytes: 62796
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void)
{
    double a, b;
        cin >> a >> b;
        
    if (a > b) {
        printf("safe");
    }else printf("unsafe");
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

char tmp[100];
int place;

int m_minus(int num){
	return 2 - num;
}

int m_op(int a,int b,char c){
	if(c == '*'){
		if(a * b == 0)return 0;
		else if(a * b < 3)return 1;
		return 2;
	}
	else{
		if(a == 2 || b == 2)return 2;
		else if(a == 1 || b == 1)return 1;
		return 0;
	}
}

int dfs(){
	if(tmp[place] == '-'){
		place++;
		return m_minus(dfs());
	}
	else if(tmp[place] == '('){
		place++;
		int a = dfs();
		char c = tmp[place];
		place++;
		int b = dfs();
		place++;
		return m_op(a,b,c);
	}
	else{
		int ret = tmp[place] - '0';
		place++;
		return ret;
	}
}

int main(){
	
	string str;
	while(cin >> str,str[0] != '.'){			
		int ans = 0;
		
		REP(i,3){
			REP(j,3){
				REP(k,3){
					REP(l,str.size()){
						if(str[l] == 'P'){
							tmp[l] = '0' + i;
						}
						else if(str[l] == 'Q'){
							tmp[l] = '0' + j;
						}
						else if(str[l] == 'R'){
							tmp[l] = '0' + k;
						}
						else tmp[l] = str[l];
					}
					place = 0;
					DBG(
					cout << tmp << endl;
					cout << "ijk : " << i << ' ' << j << ' ' << k << endl;
					cout << "place : " << place << endl;)
					if(dfs() == 2){
						DBG(cout << "OK" << endl;)
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3016
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
###############################################################################\
n=int(input())
A=INPUT()
B=[A[0]]

currmax=A[0]
ans=0
for i in range(1,n):
    if A[i]<=currmax:
        ans+=currmax-A[i]
    currmax=max(currmax,A[i])
print(ans)


Measured memory_bytes: 91712
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Control.Monad

main = do
  li <- BS.getLine
  let Just (n,_) = BS.readInt li
  abs <- forM [1..n] (\_ -> do
    li <- BS.getLine
    let [a,b] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
    return (a,b)
    )
  print $ compute n abs

compute :: Int -> [(Int,Int)] -> Int
compute n abs = max (maximum ps - minimum ps) (maximum qs - minimum qs)
  where
    (ps,qs) = unzip [ (a+b,b-a) | (a,b) <- abs ]

{-
それぞれの点をy=xに投影した位置と、y=-xに投影した位置を計算して、それぞれについて、
maximum-minimumを求める。その大きい方が答え。
-}

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

int dp[300001];
int ar[300001];
int j,k,l,m,n;


int solve(int x)
{

    if(dp[x] != -1)return dp[x];
    if(x == 0)return dp[x] = 0;
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        if(ar[i] > x)continue;

        if(solve(x-ar[i]) == 0)
        {
            ans = 1;
            break;

        }
    }
    return dp[x] = ans;
}

int main()
{
    cin >> n >> k;
memset(dp,-1,sizeof dp);

    for(int i=0;i<n;i++)cin >> ar[i];

    if(solve(k))cout<<"First"<<endl;
    else cout << "Second" << endl;
}


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

int main() {
    long long q,h,s,d;cin>>q>>h>>s>>d;
    long long low=min(8*q,min(4*h,min(2*s,d)));
    long long n;cin>>n;
    if(n==1){
        long long one=min(s,min(h*2,q*4));
        cout<<one<<endl;
    }else{
        long long price;
        if(n%2==0) price=low*n/2;
        else price=low*(n-1)/2;
        n=n%2;
        if(n==0) cout<<price<<endl;
        else{
            long long rest_min=min(q*4,min(h*2,s));

            price+=rest_min;
            cout<<price<<endl;
        }
    }

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[] dh = { 1, -1, 0, 0 };
		int[] dw = { 0, 0, 1, -1 };
		char map[][] = new char[h][w];
		for (int i = 0; i < h; i++) {
			map[i] = sc.next().toCharArray();
		}
		int hh, ww;
		boolean b = true, bb;
		loop: for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (map[i][j] == '#') {
					bb = false;
					for (int k = 0; k < 4; k++) {
						hh = i + dh[k];
						ww = j + dw[k];
						if (hh >= 0 && hh < h && ww >= 0 && ww < w) {
							if (map[hh][ww] == '#') {
								bb = true;
							}
						}
					}
					if (!bb) {
						b = false;
						break loop;
					}
				}

			}
		}

		if (b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    int cnt=0; 
    for(int i=0;i<a.size();i++){
        if(a[i]=='C'){
            cnt=1;
        }
        if(a[i]=='F'&&cnt==1){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
# A = int(input())
# B = int(input())
# C = int(input())
# D = int(input())
# E = int(input())
M = []
for i in range(5):
    M.append(int(input()))

print(math.ceil(N / min(M)) + 5 - 1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int N;
    cin >> N;
    vector<LL> X(N);
    vector<LL> X2(N);
    REP(i,N){
        cin>>X[i];
        X2[i]=X[i];
    }

    int n_1 = (N/2);

    sort(X.begin(), X.end());
    LL val1 = X[n_1];
    LL val2 = X[n_1-1];
    
    REP(i,N){
        if(X2[i]<val1){
            cout << val1 << endl;
        }else{
            cout << val2 << endl;
        }
    }
    return 0;


}

Measured memory_bytes: 6396
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 350000;
const int K = 19;
int n, q;
int mod =  1e9 + 7;
int s1[N], s2[N], a[N], ans[N], f[N], invf[N];
string t[N], d[N], s;
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int c(int n, int k){
    if (k < 0) return 0;
    return f[n] * invf[k] % mod * invf[n - k] % mod;
}
int check (int x){
    for (int i = 1; i <= q; i++){
        if (s[x - 1] == t[i][0]){
            if (d[i] == "L"){
                if (x == 1) return -1;
                x--;
            } else{
                if (x == n) return 1;
                x++;
            }
        }
    }
    return 0;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    if (k <= (n + 1) / 2) cout << "YES"; else cout << "NO";
}


Measured memory_bytes: 6400
# -*- coding: utf-8 -*-
a,b,c = map(int, input().split())

res = 0
s = set((a,b,c))
while True:
    if a%2==1 or b%2==1 or c%2==1:
        break
    res += 1
    a,b,c = b//2+c//2,a//2+c//2,a//2+b//2

    if (a,b,c) in s:
        # print(s,a,b,c)
        print(-1)
        exit()
    s.add((a,b,c))
print(res)


Measured memory_bytes: 3060
n=input()
anslist=[]

def saiki(n,x,a,k):
    if k==len(n):
        anslist.append(eval(x))
        return
    else:
        for i in a:
            y=x
            x=x+i+n[k]
            saiki(n,x,a,k+1)
            x=y       

saiki(n,n[0],['','+'],1)
print(sum(anslist))

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

template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    long long N; cin >> N;
    vector<int> a(N); for (int i = 0; i < N; ++i) cin >> a[i];
    int low = 0, high = 1<<30;
    const int geta = N+1;
    while (high - low > 1) {
        int mid = (low + high) / 2;
        long long num = 0;
        BIT<long long> bit(N*2+10);
        int sum = 0;
        bit.add(sum+geta, 1);
        for (int i = 0; i < N; ++i) {
            int val;
            if (a[i] <= mid) val = 1; else val = -1;
            sum += val;
            num += bit.sum(1, sum+geta);
            bit.add(sum+geta, 1);
        }
        //cout << mid << ": " << num << endl;
        if (num > (N+1)*N/2/2) high = mid;
        else low = mid;
    }
    cout << high << endl;
}


Measured memory_bytes: 2176
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll

int32_t main(){ _
    int n, t;
    cin >> n >> t;
    int ans = inf;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        if(b <= t){
            if(a < ans){
                ans = a;
            }
        }
    }
    if(ans == inf){
        cout << "TLE\n";
        return 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    ll a,b,n;

    cin>>a>>b>>n;

    

    ll x = min(b-1,n);

    ll ans = floor(a*x/b)-a*floor(x/b);

    
 
    cout<<ans<<endl;
}

Measured memory_bytes: 3156
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
   string S; cin >> S;
   vector<int> sum(S.size()+1);
   for(int i = S.size(); i >= 1; i--){
       if(S[i-1] == 'W') sum[i-1] = sum[i] + 1;
       else sum[i-1] = sum[i];
   }
   ll ans = 0;
   rep(i,S.size()){
       if(S[i] == 'B') ans += (ll)sum[i+1];
   }
   cout << ans << endl;

}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}

int l(int a, int b){
    return a / gcd(a, b) * b;
}

signed main(){
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, 0, n) cin >> t[i];
    int ans = 1;
    rep(i, 0, n){
        ans = l(ans, t[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
	int N,M;
	cin >> N >> M;

	const int nmmax=50;
	char A[nmmax][nmmax],B[nmmax][nmmax];


	for(int y=0;y<N;++y){
		for(int x=0;x<N;++x){
			cin >> A[y][x];
		}
	}

	for(int y=0;y<M;++y){
		for(int x=0;x<M;++x){
			cin >> B[y][x];
		}
	}

	bool exist=false;
	
	for(int ly=0;ly<N;++ly){
		for(int lx=0;lx<N;++lx){
			if(ly+M-1>=N or lx+M-1>=N) continue;

			bool match=true;
			for(int y=0;y<M;++y){
				for(int x=0;x<M;++x){
					if(A[ly+y][lx+x]!=B[y][x]) match=false;
				}
			}
			if(match) exist=true;
		}
	}

	if(exist)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題164

            string[] line = Console.ReadLine().Split(' ');
            int s = int.Parse(line[0]);
            int w = int.Parse(line[1]);

            if (s <= w)
            {
                Console.WriteLine("unsafe");
            }
            else
            {
                Console.WriteLine("safe");
            }


        }


    }
}


Measured memory_bytes: 27404
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	scanf("%lld",&n);
	int i;
	for( i=sqrt(n);;i--)
	{
	if(n%i==0)
	break;
	}
	printf("%d\n",(int)log10(n/i)+1);
	return 0;
	
}

Measured memory_bytes: 640
(function main() {
  let line = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('');
  let height_list = [0];
  let current_height = 0;

  // 初めの上昇と平坦を除去
  while (line.length > 0 && line[0] !== '\\') line.shift();
  // 終わりの下降と平坦を除去
  while (line.length > 0 && line[line.length - 1] !== '/') line.pop();

  line.forEach(function(e, i){
      if (e === '\\') current_height -= 1
      else if (e === '_') current_height += 0
      else current_height += 1
      height_list.push(current_height);
  });

  let sum = 0;
  let holes = [];
  for (;height_list.length > 1;) {
    let h = makeHole(height_list);
    if (h > 0) {
      sum += h;
      holes.push(h);
    }
  }

  console.log(sum);
  console.log(holes.length && holes.length + ' ' + holes.join(' '));
})();

function makeHole(list) {
    begin = list.shift();
    if (list[0] < begin && begin <= list.reduce((a, b) => Math.max(a, b), -100000)) {
    let area = 0;
      while (true) {
      if (list.length == 0 || begin <= list[0]) break;
        area += begin - list.shift();
      }
      return area;
    } else {
      return 0;
    }
}



Measured memory_bytes: 21064
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	char c;
	int T = 0, H = 0;
	for (int a, b, d; cin >> a >> c >> b >> c >> d;) {
		if (a*a + b*b == d*d)T++;
		else if (a == b)H++;
	}
	cout << T << endl << H << endl;
	return 0;
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N), B(N);
	REP(i, N) cin >> A[i];
	REP(i, N) cin >> B[i];

	ll res{0};

	REP(i, N)
	{
		ll tmp{0};
		for (ll a = 0; a <= i ;++a)
		{
			tmp += A[a];
		}
		for (ll a = i; a < N; ++a)
		{
			tmp += B[a];
		}

		res = max(res, tmp);
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (H, W) = rd.readIntArray()
    val G = Array(H){""}
    for (i in 0 until H) {
        G[i] = rd.readString()
    }

    val dp = Array(H){IntArray(W){INF} }

    dp[0][0] = if (G[0][0]=='#') 1 else 0
    for (i in 0 until H) {
        for (j in 0 until W) {
            if (i>0) {
                dp[i][j] = min(dp[i][j], dp[i-1][j]
                        + if (G[i][j]!=G[i-1][j]) 1 else 0)
            }
            if (j>0) {
                dp[i][j] = min(dp[i][j], dp[i][j-1]
                        + if (G[i][j]!=G[i][j-1]) 1 else 0)
            }
        }
    }

    val ans = (dp[H-1][W-1]+1)/2
    println(ans)
}


//val rd = debug.Reader("agc", "046", "a", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 36804
#include<iostream>
#include<queue>
#include<cassert>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
int W, H;
char G[62][22];
bool stable, V[62][22];
int dy[4] = {0, -1, 0, 1};
int dx[4] = {1, 0, -1, 0};

pair<double, int> dfs(int y, int x, char ch){
  double c = 0.0;
  int cnt = 0;
  queue<pair<int, int> > Q;
  V[y][x] = true;
  pair<int, int> u;
  int ny, nx;
  int minx = x, maxx = x+1;
  for (Q.push(make_pair(y, x)); !Q.empty(); ){
    u = Q.front(); Q.pop();
    int b = u.first+1;
    if ( u.first == H-1 || (b < H && G[b][u.second] != '.' && G[b][u.second] != ch )){
      minx = min(minx, u.second);
      maxx = max(maxx, u.second+1);
    }
    c += u.second + 0.5;
    cnt++;
    rep(r, 4){
      ny = u.first + dy[r];
      nx = u.second + dx[r];
      if ( ny < 0 || nx < 0 || ny > H-1 || nx > W-1 || V[ny][nx]) continue;
      if ( G[ny][nx] == ch ){
	V[ny][nx] = true;
	Q.push(make_pair(ny, nx));
      } else if ( G[ny][nx] != '.' && r == 1 ) {
	pair<double, int> np = dfs(ny, nx, G[ny][nx]);
	c += np.first;
	cnt += np.second;
      }
    }
  }

  if ( ! ( minx < c/cnt && c/cnt < maxx ) ) stable = false;

  return make_pair(c, cnt);
}

main(){
  while( cin >> W >> H && W ){
    rep(i, H) rep(j, W) { cin >> G[i][j]; V[i][j] = false; }
    stable = true;
    rep(j, W){ 
      if ( G[H-1][j] != '.' ){
	dfs(H-1, j, G[H-1][j]);
	break;
      }
    }
    cout << (stable?"STABLE":"UNSTABLE") << endl;
  }
}

Measured memory_bytes: 0
//............Created by:- Arth Raj...........................//
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector<pair<int,int>>
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lp(i,a,b) for(int i=a;i<b;i++)
#define rlp(i,a,b) for(int i=b;i>=a;i--)
#define ld long double
#define tl tuple<ll,ll,ll>
#define all(x) (x).begin(),(x).end()
#define bs(x,b) binary_search(all(x),b)
#define vip vector<pair<int,pair<int,int>>>
#define pip pair<int,pair<int,int>>
#define INF 1e18
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll abm(ll a, ll b, ll m) {ll ans = 1; a = a % m; while (b > 0) {if (b & 1)ans = (ans * a) % m; a = (a * a) % m; b = b / 2;} return ans % m;}
ll ncr(ll n, ll r, ll m) {if (r == 0)return 1; ll fac[n + 5]; fac[0] = 1; lp(i, 1, n + 1) {fac[i] = fac[i - 1] * i % m;} return (((fac[n] * abm(fac[r], m - 2, m)) % m) * (abm(fac[n - r], m - 2, m))) % m;}
int main()
{
	int k;
	cin >> k;
	lp(i, 0, k)
	cout << "ACL";
	cout << endl;
	return 0;
}

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

int main() {
  int N;
  string A, B, C;
  cin >> N >> A >> B >> C;
  int ans = 0;
  int a, b, c;
  for (int i = 0; i < N; i++) {
    a = 1, b = 0, c = 0;
    if (B[i] == A[i]) a++;
    else b++;

    if (C[i] == A[i]) a++;
    else if (C[i] == B[i]) b++;
    else c++;

    if (a == 2 || b == 2) ans++;
    else if (a != 3) ans += 2;
  }
  cout << ans << endl;
  return 0;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
int main()
{
	ll a, b;cin>>a>>b;
	cin>>b;
	if(a^b) cout<<"1";
	else cout<<"0";
}


Measured memory_bytes: 256
/*-------property of the half blood prince-----*/

#include <bits/stdc++.h>
#include <dirent.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define MIN(X,Y) X<Y?X:Y
#define MAX(X,Y) X>Y?X:Y
#define ISNUM(a) ('0'<=(a) && (a)<='9')
#define ISCAP(a) ('A'<=(a) && (a)<='Z')
#define ISSML(a) ('a'<=(a) && (a)<='z')
#define ISALP(a) (ISCAP(a) || ISSML(a))
#define MXX 10000000000
#define MNN -MXX
#define ISVALID(X,Y,N,M) ((X)>=1 && (X)<=(N) && (Y)>=1 && (Y)<=(M))
#define LLI long long int
#define VI vector<int>
#define VLLI vector<long long int>
#define MII map<int,int>
#define SI set<int>
#define PB push_back
#define MSI map<string,int>
#define PII pair<int,int>
#define PLLI pair<LLI,LLI>
#define PDD pair<double,double>
#define FREP(i,I,N) for(int (i)=(int)(I);(i)<=(int)(N);(i)++)
#define eps 0.0000000001
#define RFREP(i,N,I) for(int (i)=(int)(N);(i)>=(int)(I);(i)--)
#define SORTV(VEC) sort(VEC.begin(),VEC.end())
#define SORTVCMP(VEC,cmp) sort(VEC.begin(),VEC.end(),cmp)
#define REVV(VEC) reverse(VEC.begin(),VEC.end())
#define INRANGED(val,l,r) (((l)<(val) || fabs((val)-(l))<eps) && ((val)<(r) || fabs((val)-(r))<eps))
#define INRANGEI(val,l,r) ((val)>=(l) && (val)<=(r))
#define MSET(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace __gnu_pbds;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction


//typedef tree < int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

LLI dp[89];
int main(){
    dp[0]=2; dp[1]=1;
    FREP(i,2,86){
        dp[i]=dp[i-1]+dp[i-2];
    }
    int n;
    cin>>n;
    cout<<dp[n]<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <string>
using namespace std;
#define ll long long
const int maxn = 1e2 + 9;
const ll mod = 1e9 + 7;
int main() {
    int n, x;
    scanf("%d", &n);
    while (n--) {
        scanf("%d", &x);
        if (x & 1 || x % 3 == 0 || x % 5 == 0)
            continue;
        else
            break;
    }
    if (n == -1)
        printf("APPROVED\n");
    else
        printf("DENIED\n");
    return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
var n=Arr.shift();
for(var i=0;i<n;i++){
   if(/^>'(=+)#\1~$/.test(Arr[i]))console.log("A");
   else if(/^>\^(Q=)+~~$/.test(Arr[i]))console.log("B");
   else console.log("NA");
}

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

int main()
{
  int n;
  cin >> n;
  valarray<int> h(n + 1);
  for (auto i = 0; i < n; i++) {
    cin >> h[i];
  }
  cout << (h - h.cshift(-1)).apply([](int x){return x > 0 ? x : 0;}).sum() << endl;
}


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

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

let reader: Reader = new Reader();
let N = reader.readInt();
/**
 *
 * D[1]/2+D[2]/2=A[1]
 * D[2]/2+D[3]/2=A[2]
 * D[3]/2+D[1]/2=A[3]
 * D[1]=A[1]-A[2]+A[3]
 *
 */
let A = reader.readInts();
let D: number[] = new Array(N).fill(0);
let S = 0, sign = 1;
for(let i=0; i<N; i++) {
	S += sign*A[i];
	sign = -sign;
}
D[0] = S;
D[N-1] = 2*A[N-1]-D[0]
for(let i=1; i<N-1; i++) {
	D[i] = 2*A[i-1]-D[i-1];
}
console.log(D.map((value) => value.toString()).join(" "));


Measured memory_bytes: 49680
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int n;
    cin>>s>>n;
    for (int i = 0; i < n; i++){
        string que;
        cin>>que;
        if(que=="print"){
            int b,e;
            cin>>b>>e;
            cout<<s.substr(b,e-b+1)<<'\n';
        }else if(que=="reverse"){
            int b,e;
            cin>>b>>e;
            string s1=s;
            for (int j = b; j <= e; j++)s1[j]=s[e-j+b];
            s=s1;
        }else{
            int b,e;
            string s1;
            cin>>b>>e>>s1;
            s=s.replace(b,e-b+1,s1);
        }
    }
}


Measured memory_bytes: 3236
#include <stdio.h>
    #include <algorithm>
    #include <utility>
    using namespace std;
    #define F first
    #define S second
    const int N=1e5+10;
    int main(){
    int n;
      long long int ans=0;
      bool f=true;
      pair<int,int> a[N];
      scanf("%d",&n);
      for(int i=0;i<n;i++){scanf("%d%d",&a[i].F,&a[i].S);
                          a[i].F+=a[i].S;}
      sort(a,a+n);
      for(int i=n-1;i>=0;i--){
        if(f){
        ans+=a[i].F-a[i].S;
        }
        else ans-=a[i].S;
        f=!f;
      }
      printf("%lld\n",ans);
    }

Measured memory_bytes: 896
S = list(input())
Q = int(input())
A = []
a = 0
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    a += 1
  else:
    if (q[1] == '1' and a % 2 == 0) or (q[1] == '2' and a % 2 == 1):
      A.append(q[2])
    else:
      S.append(q[2])
A = A[::-1]
S = A + S
if a % 2 == 1:
  S = S[::-1]
ans = ''.join(S)
print(ans)
      
  

Measured memory_bytes: 14192
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LL long long
#define LD long double
#define REP(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define RREP(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define int LL
#define PR(arr,a,b) REP(unique,a,b) cout<<arr[unique]<<" \n"[unique==b] 
#define V(x) int x;cin>>x
#define V2(a,b) int a,b;cin>>a>>b
#define V3(a,b,c) int a,b,c;cin>>a>>b>>c
#define SC(arr,a,b) REP(unique,a,b) cin>>arr[unique]
using namespace std;

typedef pair<int,int> PII;
typedef pair<int,PII> PIII;
typedef vector<int> VI;

const int MX = 1e6+1;
const int MOD = 1e9+7;

void pre();


signed main()
{
    //pre();
   
    V(n);

    LD ans = 0;
    string jpy = "JPY";
    REP(i,1,n)
    {
        LD x;
        string s;
        cin>>x>>s;

        if(jpy.compare(s)==0)
            ans = ans + x;
        else
            ans = ans + ((LD)380000.0)*x;
    }
    cout<<fixed;
    cout<<setprecision(6);
    cout<<ans;

    return 0;
}


void pre()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  

}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define mp make_pair
#define v vector
#define inp_push(no, v) \
    ll no;              \
    cin >> no;          \
    v.push_back(no);
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define UN(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define N 200005
#define mod 1000000009
#define INF INT64_MAX

//////////////////////////IMPORTANT FUNCTIONS/////////////////////////////////////////////

/* Guidlines berfore submitting solution
1. Check N value before submitting
2. Check all constant kind of values you are using. Might give WA. Think
3. Check mod value
*/

v<ll> fact(N);
v<ll> prime_check(1e7 + 2);
v<ll> primes;

long long powmod(long long x, long long y, long long m)
{
    long long res = 1LL;
    while (y)
    {
        if (y & 1)
            res = (res * x) % m;
        x = (x * x) % m;
        y /= 2;
    }
    return res;
}

void init_fact()
{
    fact[0] = 1;
    for (ll i = 1; i < N; i++)
    {
        fact[i] = (fact[i - 1] * i) % mod;
    }
}

ll C(ll n, ll r)
{
    if (n < r)
        return 0;
    ll temp = fact[n] * powmod(fact[r], mod - 2, mod) % mod;
    temp *= powmod(fact[n - r], mod - 2, mod);
    temp %= mod;
    return temp;
}

void Sieve()
{
    for (ll i = 2; i <= 1e7 + 1; i++)
    {
        if (prime_check[i])
            continue;
        primes.pb(i);
        for (ll j = 2 * i; j <= 1e7 + 1; j += i)
            prime_check[j] = i;
    }
}
ll phi(ll n)
{
    ll i, res = n;
    for (i = 2; i * i <= n; i++)
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            res -= res / i;
        }
    if (n > 1)
        res -= res / n;
    return res;
}

/////////////////////////////////////START CODE HERE/////////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // init_fact();
    // Sieve();
    ll n;
    cin >> n;
    string ans;
    string arr;
    for (ll i = 0; i <= 25; i++)
        arr += ('a' + i);
    v<ll> nos;
    while (n > 0)
    {
        ll temp = n % 26;
        if (temp == 0)
            nos.pb(26), n--;
        else
            nos.pb(temp);
        n /= 26;
    }
    for (auto y : nos)
    {
        ll x = y;
        x--;
        ans += arr[x];
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
}

Measured memory_bytes: 82792
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
source:
    ll a, b, c;
    cin >> a >> b >> c;
    ll num[10] = {};
    num[a]++;
    num[b]++;
    num[c]++;

    bool ans = false;
    rep(i, 10) {
        if (num[i] == 2) {
            ans = true;
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}



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

int main()
{
	int N, X;
	vector<int> L;
	int l;
	cin >> N >> X;
	for (int i = 0; i < N; i++) {
		cin >> l;
		L.push_back(l);
	}
	int D = 0;
	int count = 0;
	if (D <= X) {
		count++;
	}
	for (int t=0; t < L.size(); t++) {
		D = D + L[t];
		if (D <= X)
			count++;
	}
	cout << count;
	return 0;
}


Measured memory_bytes: 256
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe


readInt = fst . fromJust . BS.readInteger

getInt = readInt <$> BS.getLine
getIntNList n = map BS.unpack <$> replicateM (fromIntegral n) BS.getLine

solve :: [Int] -> [String] -> [String]
solve (a:b:c:[d]) [] = ["AC x " <> show a, "WA x " <> show b, "TLE x " <> show c, "RE x " <> show d]
solve (a:b:c:[d]) (x:xs)
  | x == "AC" = solve [a+1,b,c,d] xs
  | x == "WA" = solve [a,b+1,c,d] xs
  | x == "TLE" = solve [a,b,c+1,d] xs
  | x == "RE" = solve [a,b,c,d+1] xs

main = do
  n <- getInt
  ln <- getIntNList n
  putStr $ unlines $ solve [0,0,0,0] ln


Measured memory_bytes: 22296