akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<ll,ll>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////
template<typename T>inline T ceil(T a,T b){return (a + b - 1) / b;}
void solve(){
  ini(N);
  vp v(N); in(v);
  ll t,a;
  tie(t,a) = v[0];
  rep1(i,N-1){
    P x = v[i];
    ll t1 = ceil(t,x.fi)*x.fi , a1 = t1 / x.fi * x.se ;
    ll a2 = ceil(a,x.se)*x.se , t2 = a2 / x.se * x.fi ;
    trc(t,a,x);
    trc(t1,a1,t2,a2);
    if(t1 > t2) swap(t1,t2) , swap(a1,a2);
    if(a1 >= a && t1 >= t) t=t1,a=a1;
    else t=t2,a=a2;
    trc(t , a);
  }
  out(t + a);
}



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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, M;
  cin >> N >> M;
  map< int, int > ac, ng;
  int add = 0;
  for(int i = 0; i < M; i++) {
    int x;
    string s;
    cin >> x >> s;
    if(s == "AC") {
      ac[x] = true;
      if(ng[x] >= 0) add += ng[x];
      ng[x] = -inf;
    } else {
      ng[x]++;
    }
  }
  cout << ac.size() << " " << add << endl;
}

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

X = list(map(int,input().split()))

def cnt(m):
	count = 0
	while m % 2 == 0:
		count += 1
		m //= 2
	return(count)

ans = 0
for i in range(N):
	ans += cnt(X[i])

print(ans)	

Measured memory_bytes: 4148
#include <stdio.h>

int main(void){
	int a, b;
	char op;

	while(1){
		scanf("%d %c %d", &a, &op, &b);
		if(op == '+')
			printf("%d\n", a+b);
		else if(op == '-')
			printf("%d\n", a-b);
		else if(op == '*')
			printf("%d\n", a*b);
		else if(op == '/')
			printf("%d\n", a/b);
		else if(op == '?')
			break;
	}

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;

long long powmod(long long x, long long n) {
    long long ret = 1;
    while(n > 0) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

int main() {
    int N; cin >> N;
    vector<pair<int, int>> D(N);
    for(int i=0; i<N; ++i) {
        cin >> D[i].first;
        D[i].second = i;
    }

    if(D[0].first != 0) {
        cout << 0 << endl;
        return 0;
    }
    sort(begin(D), end(D));
    for(int i=1; i<N; ++i) {
        if(D[i].first - D[i - 1].first > 1) {
            cout << 0 << endl;
            return 0;
        }
    }

    map<int, int> cnt;
    for(int i=0; i<N; ++i) cnt[D[i].first] += 1;
    if(cnt[0] > 1) {
        cout << 0 << endl;
        return 0;
    }

    long long res = 1;
    for(auto it = begin(cnt); it!=end(cnt); ) {
        long long prev = it->second;
        ++it;
        if(it == end(cnt)) break;
        res = res * powmod(prev, (it->second)) % MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000000000000ll
#define N 200009
#define M 600009
using namespace std;

int n,m,a[N],pos[N]; ll tg;
struct node{ ll l,r; }mn[M];
void build(int k,int l,int r){
	mn[k].l=mn[k].r=inf;
	if (l==r){ pos[l]=k; return; }
	int mid=l+r>>1;
	build(k<<1,l,mid); build(k<<1|1,mid+1,r);
}
void ins(int x,ll l,ll r){
	int i=pos[x];
	mn[i].l=min(mn[i].l,l); mn[i].r=min(mn[i].r,r);
	for (i>>=1; i; i>>=1)
		mn[i]=(node){min(mn[i<<1].l,mn[i<<1|1].l),min(mn[i<<1].r,mn[i<<1|1].r)};
}
node qry(int k,int l,int r,int x,int y){
	if (x<=l && r<=y) return mn[k];
	int mid=l+r>>1; node ans=(node){inf,inf},tmp;
	if (x<=mid){
		tmp=qry(k<<1,l,mid,x,y);
		ans.l=min(ans.l,tmp.l); ans.r=min(ans.r,tmp.r);
	}
	if (y>mid){
		tmp=qry(k<<1|1,mid+1,r,x,y);
		ans.l=min(ans.l,tmp.l); ans.r=min(ans.r,tmp.r);
	}
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	int i,x,y; ll tmp; scanf("%d%d",&x,&y);
	a[0]=x; build(1,1,n);
	ins(y,-y,y);
	for (i=1; i<=m; i++){
		scanf("%d",&a[i]);
		tmp=min(qry(1,1,n,1,a[i]).l+a[i],qry(1,1,n,a[i],n).r-a[i])+tg;
		tg+=abs(a[i]-a[i-1]);
		ins(a[i-1],tmp-a[i-1]-tg,tmp+a[i-1]-tg);
	}
	ll ans=inf;
	for (i=1; i<=n; i++) ans=min(ans,mn[pos[i]].l+i);
	printf("%lld\n",ans+tg);
	return 0;
}


Measured memory_bytes: 11136
a=int(input()) #500
atani=500
b=int(input())
btani=100
c=int(input())
ctani=50
x=int(input())

asum=0
bsum=0
csum=0
cnt=0

for aa in range(0, a+1):
  if asum > x:
    break
  elif asum == x:
    cnt += 1
    break
    #print('asum:{} bsum:{} csum:{}'.format(asum , bsum,csum))
  
  bsum=0
  for bb in range(0, b+1):
    if asum + bsum > x:
      break
    elif asum + bsum == x:
      cnt += 1
      break
      #print('asum:{} bsum:{} csum:{} asum+bsum:{}'.format(asum , bsum,csum,asum + bsum))
      
    csum=0
    for cc in range(0, c+1):
      if asum + bsum + csum > x:
        break
      elif asum + bsum + csum == x:
        cnt += 1
        #print('asum:{} bsum:{} csum:{} asum+bsum+csum:{}'.format(asum , bsum,csum,asum + bsum+csum))
        
      csum += ctani
    
    bsum += btani
  
  asum += atani

print(cnt)


Measured memory_bytes: 3064
<?php
// Your code here!
$n = trim(fgets(STDIN));
$arr = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$n;$i++) {
    $str[] = $arr[0][$i];
    $str[] = $arr[1][$i];
}
foreach($str as $val) {
    echo $val;
}
?>

Measured memory_bytes: 4728
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = ns()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
n,m=map(int,input().split())

#階乗
F = 10**6+5
mod = 10**9+7
fact = [1]*F
inv = [1]*F
for i in range(2,F):
    fact[i]=(fact[i-1]*i)%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(F-2,1,-1):
    inv[i] = (inv[i+1]*(i+1))%mod
def comb(n,k):
    ans=(fact[n]*inv[n-k])%mod
    return (ans*inv[k])%mod

ans=0
for i in range(1,n+1):
    tmp=fact[m-i]*inv[m-n]*comb(n,i)
    ans+=(1 if i%2==1 else -1)*tmp
    ans%=mod
ans=fact[m]*inv[m-n]-ans
ans%=mod
ans*=fact[m]*inv[m-n]
ans%=mod

print(ans)

Measured memory_bytes: 99560
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------
int x2000, r, d;
int g(int n){
    if(n == 2000){
        return x2000;
    }
    else{
        return g(n - 1) * r - d;
    }
}
void solve(){
}
int main(){
    cin >> r >> d >> x2000;
    for(int i = 1; i <= 10; i++){
        cout << g(2000 + i) << endl;
    }
    solve();
    return 0;
}



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 str = br.readLine();
		String[] strs = str.split(" ");
		int a = Integer.parseInt(strs[0]);
		int b = Integer.parseInt(strs[1]);
		int c = Integer.parseInt(strs[2]);
		int cnt = 0;
		for(int i = a; i <= b; i++){
			if((c % i) == 0){
				cnt++;
			}//if
		}//for
		System.out.println(cnt);
		br.close();
	}
}

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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a + b + c >= 22 ? "bust" : "win") << '\n';
  return 0;
}

Measured memory_bytes: 3632
import sys

sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
graph = [[] for _ in range(N + 1)]
for _ in range(M):
    x, y = map(int, input().split())
    graph[x].append(y)

dp = [-1] * (10 ** 5 + 1)


def dfs(v):
    if dp[v] != -1:
        return dp[v]

    res = 0
    for child in graph[v]:
        res = max(res, dfs(child) + 1)
    dp[v] = res
    return res


def solve():
    ans = 0
    for v in range(1, N + 1):
        ans = max(ans, dfs(v))
    print(ans)


if __name__ == '__main__':
    solve()


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 55, M = 3e3, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    string s;   cin >> s;   int n = s.size();
    string st = ""; st.push_back(s[0]);


    int j = 0, p = 0;
    for(int i = 1;i < n;i++){

        while(j > 0 && st[j - 1] != s[i]){
            p++;
            st.pop_back();  j--;
        }

        st.push_back(s[i]); j++;
    }


    cout << (p & 1 ? "First" : "Second");
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    int N = (int)s.size();
    for (int i = 0; i < N - 1; i++) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }
    for (int i = 0; i < N - 2; i++) {
        if (s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
n = int(input())
a = input()
s = a

i = 0
while i<len(s) and s[i] == '.':
  i+=1
j = n-1
while j>=0 and s[j] == '#':
  j-=1

s = s[i:j+1]
r = min(s.count('#'), s.count('.'))

w = s.count('.')
b = 0
c = 0
for i in range(len(s)):
  if s[i] == '#':
    b += 1
  else:
    w -= 1
  r = min(r, w+b)

print(r)


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

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;





int main() {
    string s,t; cin >> s >> t;
    int ans = 0;
    for(int i = 0;i < s.length();i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans;
}


Measured memory_bytes: 3852
#include <iostream>
using namespace std;
int qzh[200005],hzh[200005];
int main(int argc, char** argv) {
	int n,ans=1e9;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		char x;
		cin >> x;
		if(x=='#') ++qzh[i];
		else ++hzh[i];
	}
	for(int i=1;i<=n;i++) qzh[i]+=qzh[i-1];
	for(int i=n;i>=1;i--) hzh[i]+=hzh[i+1];
	for(int i=0;i<=n;i++) ans=min(ans,qzh[i]+hzh[i+1]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long M = sc.nextLong();
        
        long[] a = new long[(int)(A)];
        for(int i = 0 ; i < A ; i++){
                a[i] = sc.nextLong();    
        }
        long[] b = new long[(int)(B)];
        for(int i = 0 ; i < B ; i++){
                b[i] = sc.nextLong();
        }
        int[] x = new int[(int)(M)];
        int[] y = new int[(int)(M)];
        long[] c = new long[(int)(M)];
        for(int i = 0 ; i < M ; i++){
                x[i] = sc.nextInt();
                y[i] = sc.nextInt();
                c[i] = sc.nextInt();
        }
        long minA = a[0];
        for(int i = 1 ; i < a.length ; i++){
                minA = Math.min(minA, a[i]);
        }
        long minB = b[0];
        for(int i = 1 ; i < b.length ; i++){
                minB = Math.min(minB, b[i]);
        }
        //int z = x[1];
        //System.out.println(z);
        //System.out.println(a[z-1]);
        long min = minA + minB;
        //System.out.println(min);
        
        long[] n = new long[(int)(M)];
        for(int i = 0 ; i < M ; i++){
            n[i] = a[x[i]-1] + b[y[i]-1] - c[i];
            //System.out.println(n[i]);
            if(min > n[i]){
                min = n[i];
            }
        }
        System.out.print(min);
    }    
}

Measured memory_bytes: 158988
#include <stdio.h>

int main(){
    int a, b, c, d, e, f, ans1, ans2;
    double con = 0;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);

    ans1 = 100 * a;
    for(int w = 0; w <= 30; w++){
        for(int x = 0; x <= 30; x++){
            int water = 100 * (a * w + b * x);
            for(int y = 0; y <= (f - water) / c + 1; y++){
                for(int z = 0; z <= (f - water) / d + 1; z++){
                    int sugar = c * y + d * z;
                    if((water + sugar <= f) && (sugar <= e * water / 100)){
                        if(con < (double)sugar / (water + sugar)){
                            con = (double)sugar / (water + sugar);
                            ans1 = water + sugar;
                            ans2 = sugar;
                        }
                    }
                }
            }
        }
    }

    printf("%d %d\n", ans1, ans2);
    return 0;
}

Measured memory_bytes: 128
// AOJ 417 Gas Station
// 2019.12.7

#include <stdio.h>

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 正整数の表示（出力）
	int i; char b[30];

	i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
	while (i--) pc(b[i]);
	pc('\n');
}

int N;
int lane[11][10003], top[11], end[11], sz[11];

int main()
{
	int i, idx, info, M, x;

	N = in(), M = in();
	while (M--) {
		idx = in(), info = in();
		if (idx) {
			x = 1; for (i = 2; i <= N; ++i) {
				if (sz[i] < sz[x]) x = i;
			}
			lane[x][end[x]++] = info, ++sz[x];
		} else out(lane[info][top[info]++]), --sz[info];
	}
	return 0;
}



Measured memory_bytes: 2144
#[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 ) * } };
}
#[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 , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

fn main() {
    input! {
        n: usize,
        p: [f64; n]
    }

    let mut dp = vec_md![0f64;n+1;n+1];
    dp[0][0] = 1.0;
    for i in 0..dp.len() {
        for j in 0..dp[0].len() {
            if i+1<dp.len() && j+1<dp[0].len() {
                dp[i+1][j+1] += dp[i][j] * p[i];
            }
            if i+1<dp.len() {
                dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
            }
        }
    }
    let mut ret = 0.0;
    for i in (n+1)/2..dp[0].len() {
        ret += dp[n][i];
    }
    println!("{}", ret);
}


Measured memory_bytes: 90364
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

vvl mul(vvl A,vvl B){
	vvl C(A.size(),vl(B[0].size()));
	for(int i=0;i<A.size();i++) for(int k=0;k<B.size();k++) for(int j=0;j<B[0].size();j++) (C[i][j]+=A[i][k]*B[k][j])%=mod;
	return C;
}

vvl pow(vvl A,ll n){
	vvl B(A.size(),vl(A.size()));
	for(int i=0;i<A.size();i++) B[i][i]=1;
	while(n>0){
		if(n&1) B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

ll n,k;
vvl a;

int main(){
	cin>>n>>k;
	a=vvl(n,vl(n));
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
	vvl b(n,vl(1));
	for(int i=0;i<n;i++) b[i][0]=1;
	a=mul(pow(a,k),b);
	ll res=0;
	for(int i=0;i<n;i++) (res+=a[i][0])%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
	int n;
	while(cin>>n&&n){
		int a,b,c,x; cin>>a>>b>>c>>x;
		int y[n]; rep(i,n) cin>>y[i];

		int ans=-1,lille=0;
		for(int frame=0;frame<=10000;frame++){
			if(frame) x=(a*x+b)%c;
			if(x==y[lille]){
				lille++;
			}
			if(lille==n){
				ans=frame;
				break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

typedef struct {
  int x, y;
} Point;

int W, H;
char mas[20][21];
int i, j;


int main()
{
  while(scanf("%d %d", &W, &H), W) {
    getchar();
    for(i = 0; i < H; i++) {
      scanf("%s", mas[i]);
    }

    const int SIZE = 60000;
    int head = 0, tail = 1;
    int cnt = 0;
    Point z[SIZE], start;

    for(i = 0; i < H; i++) {
      for(j = 0; j < W; j++) {
	if(mas[i][j] == '@') start = (Point){j, i};
      }
    }

    z[head] = start;
    const int dy[] = {0, 1, 0, -1}, dx[] = {-1, 0, 1, 0};

    while(head != tail) {
      int x = z[head].x, y = z[head].y;
      head = (head + 1) % SIZE;
      if(0 <= x && x < W && 0 <= y && y < H && mas[y][x] != '#') {
	mas[y][x] = '#';
	++cnt;
	for(i = 0; i < 4; i++) {
	  int ny = dy[i] + x, nx = y + dx[i];
	  z[(tail + i) % SIZE] = (Point){ny, nx};
	}
	tail = (tail + 4) % SIZE;
      }
    }
    printf("%d\n", cnt);
  }
  return(0);
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000099;
const int OO = 0x3f3f3f3f;

int n, h[MAX];
int dp[MAX], k;

int solve(int x)
{
	if(x == n - 1) return 0;
	if(x >= n) return OO;
	if(dp[x] != -1)
		return dp[x];
	int ans = OO;
	for(int i = 1; i <= k; i++)
		ans = min(ans, solve(x + i) + abs(h[x] - h[x + i]));
	return dp[x] = ans;
}

int main()
{
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> h[i];
	memset(dp, -1, sizeof(dp));
	cout << solve(0) << '\n';

	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/15  Problem: 076_abc_d / Link: https://abc076.contest.atcoder.jp/tasks/abc076_d?lang=en ----- */
/* ------問題------

2168年、AtCoder 社は成長し、ついに "AtCoder特急" という鉄道を建設することを決めた。
さて、社長の高橋君は、"AtCoder特急" の列車を以下のように運行することを計画した。
列車の走行時間は、(t1+t2+t3+…+tN) 秒である。
最初の t1 秒間は、列車は速度 v1 m/s 以内で走っていなければならない。また、次の t2 秒間は、列車は速度 v2 m/s 以内で走っていなければならない。 次の t3 秒間、またそれ以降についても同様である。
最後の tN 秒間は、列車は速度 vN m/s 以内で走っていなければならない。
ただし、列車の性能上、加速度は ±1m⁄s2 以内でなければならない。また、走行開始時と走行終了時には列車は止まっていなければならない。

列車が発車してから停車するまでに走れる最大の距離を求めなさい。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

double ans = 0LL;

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

	cin >> N;
	VI t(N);
	vector<double> v(N);
	vector<double> mx(N + 1, 0);
	FOR(i, 0, N) {
		cin >> t[i];
	}
	double now = 0;
	FOR(i, 0, N) {
		cin >> v[i];
		now = min(now + t[i], v[i]);
		mx[i + 1] = now;
	}
	mx[N] = 0;
	now = 0;
	FORR(i, N - 1, 0 - 1) {
		now = min(now + t[i], v[i]);
		mx[i] = min(mx[i], now);
	}

	FOR(i, 0, N) {
		double top = max(mx[i], mx[i + 1]) + (double)(t[i] - abs(mx[i] - mx[i + 1]) ) / 2.0;
		double S = (mx[i] + top)*(top - mx[i]) / 2.0 + (mx[i + 1] + top)*(top - mx[i + 1]) / 2.0;
		if (top < v[i])ans += S;
		else {
			ans += S;
			ans -= (top - v[i])*(top - v[i]);
		}
	}


	cout << fixed << setprecision(10) << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(ll x){
	char y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
string s;
ll len,mod=1e9+7,dp[15],nx[15];
int main(){
	cin >> s;
	dp[0]=1;
	for(int i=0;i<s.size();i++){
		memset(nx,0,sizeof(nx));
		if(s[i]=='?')
			for(int k=0;k<13;k++)
				for(int j=0;j<10;j++)
					(nx[(k*10+j)%13]+=dp[k])%=mod;
		else
			for(int k=0;k<13;k++)
				(nx[(k*10+s[i]-'0')%13]+=dp[k])%=mod;
		swap(dp,nx);
	}
	print(dp[5]);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>


void Trace(int A[],int N){
    int i;
    for(i = 0; i < N; i++){
        if( i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void Insertion_Sort(int A[],int N){
    int i,j,v;
    for(i = 1; i < N; i++){
        v=A[i];
        j=i-1;
        while( j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        Trace(A,N);
    }
}
int main()
{
    int N,i,j;
    int A[100];

    scanf("%d",&N);
    for(i = 0;i < N; i++)
        scanf("%d", &A[i]);


    Trace(A,N);
    Insertion_Sort(A,N);


    return 0;
}



Measured memory_bytes: 2140
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n);
  VIN(A)
  while(true){
    for (auto it = A.begin(); it != A.end();) {
      if (*it == 0) {
        it = A.erase(it);
      } else {
        ++it;
      }
    }
    SORT(A);
    FOR(i,1,A.size()){
      A[i] %= A[0];
    }
    if(A.size()==1) break;
  }
  OUT(A[0]);
}

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

int main(){
    int n = 0;
    cin >> n;
    vector<double> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    rep(i,n-1){
        v[i+1] = (v[i]+v[i+1])/2;
    }
    cout << v[n-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    string s;
    cin >> s;

    int a = 0, b = 0;
    
    for(int i =0; i < s.size(); i++) {
        if(s[i] == '1')a++;
        else b++;
    }

    cout << min(a, b) * 2 << endl;
  
    return 0;
}



Measured memory_bytes: 512
#

import sys
input=sys.stdin.readline

def main():
    N=int(input())
    r=["AC","WA","TLE","RE"]
    c=[0]*4
    for i in range(N):
        s=input().strip("\n")
        c[r.index(s)]+=1
    for i in range(4):
        print(r[i],"x",c[i])
    
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 67860
N=int(input())
S=input()
c=0
if N%2==1:
  print("No")
else:
  m=N//2
  for i in range(N//2):
    if S[i]==S[m+i]:
      c=c+1
      if c==N//2:
        print("Yes")
    else:
      print("No")


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

using namespace std;
typedef long long intl;
int absi(int a){
	if(a<0){
		return -a;
	}
	return a;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int  n,k;
	cin>>n>>k;
	vector <int> v;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		v.push_back(a);
	}
	int left=n-k,right=n-1,ans=999999999;
	while(left>-1){
		if(v[left]>=0){
			ans=min(ans,v[right]);
		}
		else if(v[right]<0){
			ans=min(ans,absi(v[left]));
		}
		else{
			ans=min(ans,min(absi(v[left])*2+v[right],v[right]*2+absi(v[left])));
		}
		left--;
		right--;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 892
#!/usr/bin/env python
Q = input()

for loop in range(Q):
	n = str(input())
	cnt = 0
	while len(n) > 1:
		cnt += 1
		nmin = 0
		for i in range(len(n) - 1):
			n1 = int(n[:i + 1])
			n2 = int(n[i + 1:])
			nmin = max(nmin, n1 * n2)
		n = str(nmin)
	print(cnt)


Measured memory_bytes: 4664
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n;
	cin >> n;
	vector<int> hoge;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		hoge.push_back(tmp);
	}
	vector<int> ans;
	if (n % 2 == 0) {
		for (int i = n - 1;i >= 0;i -= 2) {
			ans.push_back(hoge[i]);
		}
		ans.push_back(hoge[0]);
		for (int i = 2;i < n;i += 2) {
			ans.push_back(hoge[i]);
		}
	}
	else {
		for (int i = n - 1;i >= 0;i -= 2) {
			ans.push_back(hoge[i]);
		}
		for (int i = 1;i < n;i += 2) {
			ans.push_back(hoge[i]);
		}
	}
	for (int i = 0;i < ans.size();++i) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

const int maxn = 105;
int a[maxn], ans;

int main(){
	int n;
	ans = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		ans += a[i];
	}
	sort(a+1, a+1+n);
	if(!(ans%10)){
		for(int i = 1; i <= n; i++)
			if(a[i]%10){
				ans -= a[i];
				break ;
			}
	}
	if(ans%10){
		cout << ans << endl;
	}
	else{
		cout << "0" << endl;
	}
	

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i+1];
  ll x = 0;
  for (int i = 1; i <= (n); ++i){
    if(i%2) x += a[i];
    else x -= a[i];
  }
  vector<int>ans(n);
  ans[0]=x;
  for(int i=1; i <= n; ++i){
    ans[i]=2*a[i]-ans[i-1];
  }
  rep(i,n) printf("%d ", ans[i]);
  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	char box[]="DEFGHIJKLMNOPQRSTUVWXYZABC";
	cin>>s;
	for(int i=0;i<s.size();i++)
	cout<<box[(s[i]-'A'+20)%26];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 0
n,m=map(int,input().split())
a={int(input()) for i in range(m)}
mod=10**9+7

x=1 if 1 not in a else 0
dp=[1,x]+[0]*(n-1)

for i in range(2,n+1):
    if i in a:
        continue
    dp[i]=(dp[i-1]+dp[i-2])
print(dp[-1]%mod)


Measured memory_bytes: 460004
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
int main(){
  int i, j, l, ct;
  char s[100002];
  cin >> s;
  l=strlen(s);
  ct=l-1;
  while(ct>=0){
    if(ct<4){
      cout << "NO";
      return 0;
    }
    if(s[ct-2]=='e'){
      if(s[ct-4]=='d'&&s[ct-3]=='r'&&s[ct-1]=='a'&&s[ct]=='m') ct-=5;
      else{
	cout << "NO";
	return 0;
      }
    }
    else if(s[ct-2]=='a'){
      if(s[ct-4]=='e'&&s[ct-3]=='r'&&s[ct-1]=='s'&&s[ct]=='e') ct-=5;
      else{
	cout << "NO";
	return 0;
      }
    }
    else if(ct<5){
      cout << "NO";
      return 0;
    }
    else if(s[ct-2]=='s'){
      if(s[ct-5]=='e'&&s[ct-4]=='r'&&s[ct-3]=='a'&&s[ct-1]=='e'&&s[ct]=='r') ct-=6;
      else{
	cout << "NO";
	return 0;
      }
    }
    else if(ct<6){
      cout << "NO";
      return 0;
    }
    else if(s[ct-2]=='m'){
      if(s[ct-6]=='d'&&s[ct-5]=='r'&&s[ct-4]=='e'&&s[ct-3]=='a'&&s[ct-1]=='e'&&s[ct]=='r') ct-=7;
      else{
	cout << "NO";
	return 0;
      }
    }
    else{
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}

Measured memory_bytes: 384
#C
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
tmp = 0
for i in range(n):
    tmp = min(a[i] + a[i + 1], b[i])
    count += tmp
    a[i + 1] -= max(0, tmp - a[i])
print(count)

Measured memory_bytes: 18476
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define Inf 1000000000000000ll
#define ll long long
using namespace std;

ll A[222222];
int main() {
    int N;
    cin>>N;
    ll allsum=0;
    for(int i=0;i<N;i++) {
        cin>>A[i];
        allsum+=A[i];
    }
    ll ans = Inf;
    ll x = 0;
    for(int i=0;i<N-1;i++) {
        x += A[i];
        ll y = allsum - x;
        ans = min(ans, x >= y ? x-y : y-x);
    }
    cout << ans << endl;
}

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

int main(){
  int n;//回数
  cin >> n;
  cin.get();
  for(int i=0;i<n;i++){
  string s;
  getline(cin,s);//１行読み込む
  for(int i=0;i<s.size();i++){
    if(s.substr(i,7)=="Hoshino")
      s[i+6]='a';
  }
  cout << s << endl;
  }
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n , T;
int a[101010];

int main(){
    cin >> n >> T;
    rep(i,0,n) cin >> a[i];
    int Max = 0 , Min = 1<<30;
    rep(i,0,n){
        if(a[i] > Min) Max = max(Max , a[i] - Min);
        Min = min(Min , a[i]);
    }
    Min = 1<<30;
    int ans = 0;
    rep(i,0,n){
        if(a[i] - Min == Max) ++ans;
        Min = min(Min , a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <numeric>
#include <algorithm>
#include <cassert>

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

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    set<size_t> items;
    string s;
    rep(i,n){
        cin >> s;
        items.insert(hash<string>()(s));
    }
    cout << items.size() << '\n';
    return 0;
}


Measured memory_bytes: 13000
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        
        int max1 = 0;
        int max2 = 0;
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            
            if ( max1 < A[i]){
                max1 = A[i];
            } else if ( max2 < A[i] ) {
                max2 = A[i];
            }
            
        }
        
        for(int i = 0; i < N; i++){
            
            if ( A[i] != max1 ){
                System.out.println(max1);
            } else {
                System.out.println(max2);
            }
            
        }
        
    }
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    int A, B;
    cin >> A >> B;

    if (A > 12) {
        cout << B << endl;
    }
    else if (5 < A && A < 13) {
        cout << (B / 2) << endl;
    }
    else {
        cout << "0" << endl;
    }

    return 0;
}


Measured memory_bytes: 3656
n = int(input())
a = str(input())
b = str(input())
c = str(input())
ans = 0
list1 = []
for i in range(n):
    list1.append(a[i])
    list1.append(b[i])
    list1.append(c[i])
    set1 = set(list1)
    ans += len(set1)-1
    list1 = []
print(ans)


Measured memory_bytes: 3060
#![allow(dead_code)]
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let mut l: Vec<usize> = sc.vec(n);
    l.sort_by(|a,b| b.cmp(a));
    let l = l;

    let mut ans = 0;
    for i in 0..l.len() {
        let mut k = l.len()-1;
        for j in i+1..l.len() {
            while l[i]>=l[j]+l[k] { k-=1 }
            if j<k { ans += k-j; }
        }
    }

    format!("{}\n", ans)
}
#[test]
fn test_solve() {
   assert_eq!(solve("4\n3 4 2 1\n"), "1\n");
   assert_eq!(solve("3\n1 1000 1\n"), "0\n");
   assert_eq!(solve("7\n218 786 704 233 645 728 389\n"), "23\n");
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
 
int main(){
    int x, y;
 
    while(1){
        cin >> x >> y;
        if(x==0 && y==0){ 
            break;
        }else if(x <= y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const int NN = 1100;
int n;
int t, sum, m;

char s[NN];

int main(){
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	
	scanf("%s", s+1);
	n = strlen(s+1);
	if (n % 2 == 1){
		printf("No");
		return 0;
	} 
	for (int i=1; i<=n; i++){
		if (i % 2 == 1){
			if (s[i] == 'h');
			else {
				printf("No");
				return 0;
			}
		} else {
			if (s[i] == 'i');
			else {
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define upadj(i,adj) if (adj.size()>0) up(i,0,adj.size()-1)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << "=" <<X << endl
#define debug2(X,Y)  cerr<< #X << "=" <<X << ", " << #Y << "=" <<Y << endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
int n,a[100010];
V<int> res;
long maxL;
void input()
{
    cin>>n>>maxL;
    up(i,1,n) cin>>a[i];
}

void solve()
{
   int imp= 0;
   up(i,1,n-1)
    if (a[i]+ a[i+1]>=maxL)
    {
        imp= i; break;
    }
   if (imp==0) cout<<"Impossible";
   else
   {
       cout<<"Possible"<<endl;
       up(i,1,imp-1) cout<<i<<endl;
       down(i,n-1,imp+1) cout<<i<<endl;
       cout<<imp<<endl;
   }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
    #endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 1280