akhauriyash/Code-Regression huggingface dataset:
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

void precalc() {
}

int n;
int cnt[2];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    cnt[a & 1]++;
  }
  return true;
}

void solve() {
  cnt[0] += cnt[1] / 2;
  cnt[1] = cnt[1] % 2;
  if (cnt[0] && cnt[1]) {
    printf("NO\n");
  } else {
    printf("YES\n");
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int  h, n;
    cin >> h >> n;
    ivec a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    int dp[10001];
    dp[0] = 0;
    for (int i = 1; i < h+1; i++){
        dp[i] = 1e8+1;
        for (int j = 0; j < n; j++) dp[i] = fmin(dp[i], dp[(int)fmax(0, i-a[j])] + b[j]);
    }
    //cout << *min_element(dp.begin()+h, dp.end()) << endl;
    cout << dp[h] << endl;

}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

times = [A, B, C, D, E]

def calRest(times):
	rest = 10
	for time in times:
		if time % 10 == 0:
			continue
		elif time % 10 < rest:
			rest = time % 10
	return 10 - rest

sumTime = sum([10 * (int((time-1)/10)+1) for time in times])
rest = calRest(times)
neatTime = sumTime - rest
print(neatTime)

Measured memory_bytes: 3064
r, D, x_2000 = list(map(int, input().split()))
x = []
for i in range(0,10):
    if i == 0:
        x.append(r * x_2000 - D)
        print(x[i])
    else:
        x.append(r * x[i-1] - D)
        print(x[i])

Measured memory_bytes: 3060
from copy import copy

N,M,X = map(int,input().split())
A = list(map(int,input().split()))

goal0 = 0
goaln = 0

X2 = copy(X)

#0へ
while True:
    if X-1 == 0:
        break
    else:
        if X-1 in A:
            goal0 += 1

        X -= 1

while True:
    if X2+1 == N:
        break
    else:
        if X2+1 in A:
            goaln += 1

        X2 += 1

print(min(goal0,goaln))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
string A, B, C;
int main() {
    cin >> A >> B >> C;
    A += 'e'; B += 'e'; C += 'e';
    int a = 0, b = 0, c = 0;
    char next = 'a';
    while(1) {
        if(next == 'a') {
            if(A.at(a) == 'e') {
                cout << 'A' << endl;
                return 0;
            }else {
                next = A.at(a);
                a++;
            }
        }else if(next == 'b') {
            if(B.at(b) == 'e') {
                cout << 'B' << endl;
                return 0;
            }else {
                next = B.at(b);
                b++;
            }
        }else {
            if(C.at(c) == 'e') {
                cout << 'C' << endl;
                return 0;
            }else {
                next = C.at(c);
                c++;
            }
        }
    }
}

Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let a: usize = read!();
    let b: usize = read!();

    let mut ap = 0;
    let mut bp = 0;
    let mut cp = 0;

    for _ in 0..n {
        let pi: usize = read!();
        if pi <= a {
            ap += 1;
            continue;
        }

        if pi <= b {
            bp += 1;
            continue;
        }

        cp += 1;
    }

    println!("{}", ap.min(bp.min(cp)));
}

Measured memory_bytes: 2184
n = int(input())

a = list(map(int, input().split( )))
a.append(1<<20-1)
left = 0
right = 0
ans = 0
temp = 0#####
while left<n:
    while temp + a[right] == temp^a[right]  and right<n:###
        temp += a[right]
        right += 1
    ans += right - left###
    temp -= a[left]
    left += 1
print(ans)
    
        
        


Measured memory_bytes: 77772
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

int main(void){
  int n, a, b, c;
  string s;
  vector<pair<int, pair<int, string> > > v;

  bool flag = false;
  while(cin >> n, n){
    v.clear();
    if(flag)
      cout << endl;
    else
      flag = true;

    for(int i=0; i<n; i++){
      cin >> s >> a >> b >> c;
      v.push_back(make_pair((a * 3) + c, make_pair(n - i, s)));
    }
    sort(v.begin(), v.end(), greater<pair<int, pair<int, string> > >());

    for(int i=0; i<n; i++){
      cout << v[i].second.second << "," << v[i].first << endl;
    }
  }

  return 0;
}

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

int main() {
  string s,t;
  int count = 0;
  cin >> s >> t;
  for(int i = 0;i<3;i++){
    if(s.at(i) == t.at(i)){
      count++;
    }
  }
  cout << count << endl;

  

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_program(s) cout << s <<endl;return 0
int kai_size = 120001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int RE() {
	vel v(3, 2);
	return v.at(4); 
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, kai_size-1) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, kai_size) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

int per(int a, int b) {
	int ans = a % b;
	if (ans < 0) { ans += b; }
	return ans;
}
V<pin> uni(V<pin> &v) {
	sor(v);
	V<pin> ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i-1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
bool win_first(vel &a) {
	int n = a.size();
	int sum = 0;
	vel odd;
	rep(i, n) {
		sum += a[i] - 1;
		if (a[i] % 2 == 1) { odd.push_back(i); }
	}
	if (sum % 2 == 1) { return true; }
	if (odd.size() == 1) {
		if (a[odd[0]] != 1) {
			a[odd[0]]--;
			int gcd0 = a[0];
			for (int i = 1; i < n; i++) {
				gcd0 = gcd(gcd0, a[i]);
			}
			rep(i, n) { a[i] /= gcd0; }
			return !win_first(a);
		}
	}
	return false;
}
signed main() {
	int n; cin >> n;
	vel a(n);
	rep(i, n) { cin >> a[i]; }
	if (win_first(a)) { cout << "First" << endl; }
	else { cout << "Second" << endl; }
}


Measured memory_bytes: 4216
import sys
import math

for line in sys.stdin:
    N = int(line.rstrip())
    count = 0
    for i0 in range(10):
        for i1 in range(10):
           for i2 in range(10):
              for i3 in range(10):
                  if sum([i0,i1,i2,i3]) == N:
                      count += 1
                      break
    print(count)

Measured memory_bytes: 7580
n, m, q = map(int, input().split())
edges = [[0]*n for _ in range(n)]

for _ in range(m):
    L, R = map(lambda x: int(x)-1, input().split())
    edges[L][R] += 1


S = [[0]*(n+1)for _ in range(n+1)]
for i in range(n):
    for j in range(n):
        S[i][j+1] = S[i][j] + edges[i][j]

for _ in range(q):
    p, q = map(int, input().split())
    lines = S[p-1:q]
    ans = 0
    for row in lines:
        ans += row[q]-row[p-1]
    print(ans)

Measured memory_bytes: 57292
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int t,d,l,x;
    while(cin>>t>>d>>l,t|d|l){
        int cur=0,cnt=0;
        rep(i,t){
            cin>>x;
            if(x>=l) cur=d;
            if(cur>0&&i<t-1) ++cnt;
            if(cur>0)--cur;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

int calc(string& s, int i) {
  int res = s[i] - '0';
  while (i + 2 < s.size()) {
    i += 2;
    if (s[i - 1] == '+') res += s[i] - '0';
    else res *= s[i] - '0';
  }
  return res;
}

int term(string& s, int& i) {
  int res = s[i++] - '0';
  while (s[i] == '*') res *= s[++i] - '0', i++;
  return res;
}

int expr(string& s, int& i) {
  int res = term(s, i);
  while (s[i] == '+') i++, res += term(s, i);
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  string s;
  int a;
  cin >> s >> a;  

  int i = 0;
  bool M = expr(s, i) == a, L = calc(s, 0) == a;
  cout << (M && L ? "U" : M ? "M" : L ? "L" : "I") << endl;

  return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const ll max_W = 100100;
ll dp[max_W];

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

  int N, W;
  cin >> N >> W;
  vector<P> V(N);
  ll w, v;
  rep(i, N){
    cin >> w >> v;
    V[i] = P(w, v);
  }

  rep(i, max_W){
    dp[i] = -1;
  }
  dp[0] = 0;

  rep(i, N){
    for(int j = 1e5; j >= 0; j--){
      if(dp[j] >= 0 && j + V[i].first <= 1e5){
        chmax(dp[j + V[i].first], dp[j] + V[i].second);
      }
    }
  }

  ll ans = 0;
  for(int i = 0; i <= W; i++){
    chmax(ans, dp[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

typedef long long ll;

map <ll , int> mp;

int n;
ll ans = 0;
int main(){
	cin >> n;
	mp[0] ++;
	ll cur = 0;
	for(int i = 1 ; i <= n ; ++ i){
		int x;
		cin >> x;
		cur += x;
		ans += mp[cur];
		mp[cur] ++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12800
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
 
parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

res = 1000000000 + 7

main = do
  [n, m] <- readIntList
  arr <- map (`div` 2) <$> readIntList
  let initNum = foldl1' lcm arr
  print $ if any (\val -> (initNum `div` val) `mod` 2 == 0) arr
    then 0
    else m `div` initNum - m `div` (2 * initNum)


Measured memory_bytes: 8572
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
  int s;
  
  cin >> s;
  
  bool card_list[4][13];
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      card_list[i][j] = false;
    }
  }
  
  string t;
  int c;
  while (cin >> t >> c) {
    if (t == "S") {
      card_list[0][c - 1] = true;
    } else if (t == "H") {
      card_list[1][c - 1] = true;
    } else if (t == "C") {
      card_list[2][c - 1] = true;
    } else if (t == "D") {
      card_list[3][c - 1] = true;
    }
  }
  
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      if (!card_list[i][j]) {
        if (i == 0) {
          cout << "S " << j + 1 << endl; 
        } else if (i == 1) {
          cout << "H " << j + 1 << endl;
        } else if (i == 2) {
          cout << "C " << j + 1 << endl;
        } else if (i == 3) {
          cout << "D " << j + 1 << endl;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t N,A,B;
  cin>>N>>A>>B;
  vector<int64_t>X(N);
  for(int64_t i=0;i<N;i++){
  int64_t x;
    cin>>x;
    X.at(i)=x;
  
  }int64_t ans=0;
  for(int64_t i=0;i<N-1;i++){
  int64_t cost=A*(X.at(i+1)-X.at(i));
    ans+=min(cost,B);
  
  }cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = [input() for _ in range(n)]


def bracket(x):
    # f: final sum of brackets '(':+1, ')': -1
    # m: min value of f
    f = m = 0
    for i in range(len(x)):
        if x[i] == '(':
            f += 1
        else:
            f -= 1
        m = min(m, f)
    # m <= 0
    return f, m


def func(l):
    # l = [(f, m)]
    l.sort(key=lambda x: -x[1])
    v = 0
    for fi, mi in l:
        if v + mi >= 0:
            v += fi
        else:
            return -1
    return v


l1 = []
l2 = []
for i in range(n):
    fi, mi = bracket(s[i])
    if fi >= 0:
        l1.append((fi, mi))
    else:
        l2.append((-fi, mi - fi))

v1 = func(l1)
v2 = func(l2)
if v1 == -1 or v2 == -1:
    ans = 'No'
else:
    ans = 'Yes' if v1 == v2 else 'No'

print(ans)


Measured memory_bytes: 92056
H, N = map(int, input().split())
ab_list = [list(map(int, input().split())) for _ in range(N)]

max_a = max(a for a,b in ab_list)
W = H + 1 + max_a
dp = [0] * W

for i in range(W):
    dp[i] = min(dp[i-a]+b for a,b in ab_list)

print(min(dp[H-1:]))

Measured memory_bytes: 3676
main(n,i,j,s){
  for(;scanf("%d",&n),n;){
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
        scanf("%d",m[i]+j);
    for(i=0;i<n;m[i][j]=s,i++)
      for(s=j=0;j<n;j++)s+=m[i][j];
    for(i=0;i<n+1;m[j][i]=s,i++)
      for(s=j=0;j<n;j++)s+=m[j][i];
    for(i=0;i<n+1;puts(""),i++)
      for(s=j=0;j<n+1;j++)printf("%5d",m[i][j]);
  }
  return 0;
}

Measured memory_bytes: 0
n,l = map(int,input().split())
mina = 300
s = 0
plus = True
for  i in range(1,n+1):
    if mina > abs(i+l-1):
        mina = abs(i+l-1)
        if i+l-1 > 0:
            plus = True
        else:
            plus = False
    s += i+l-1
if plus:
    print(s-mina)
else:
    print(s+mina)

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

typedef long long ll;
typedef unsigned long long ull;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll N,P,Q;
ll C[500010];
ll idx[500010];
ll sum=0;

int main(){
  cin>>N>>P>>Q;
  rep(i,N){
    cin>>C[i];
    sum+=C[i];
  }
  rep(i,N)idx[i]=i;
  sort(idx,idx+N,[=](const int& a,const int& b){ return P*a+C[a] < P*b+C[b]; });
  ll res=-INF;
  rep(i,N){
    maxch(res,sum+P*Q*i+P*i*(i-1));
    sum-=P*idx[i]+C[idx[i]];
  }
  maxch(res,sum+P*Q*N+P*N*(N-1));
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 10972
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long  int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        300005
#define mod         998244353  
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1){
        c=c-b;
        if(c<=0){
            cout<<"Yes";
            return 0;
        }
        a=a-d;
        if(a<=0){
            cout<<"No";
            return 0;
        }
    }
}

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

int main() {
 int N ;
  cin >> N ;
  
  if(((N / 1000) % 10 == (N / 100) % 10 && (N / 100) % 10 == (N / 10) % 10) || ((N / 100) % 10 == (N / 10) % 10 && (N / 10) % 10 == N % 10)){
  cout << "Yes" << endl; 
  }
  else {
    cout << "No" << endl;
  }
  }

Measured memory_bytes: 256
import heapq
n, m, *a = map(int, open(0).read().split())
a = list(map(lambda x: -x, a))

heapq.heapify(a)
for i in range(m):
    b = -heapq.heappop(a)
    heapq.heappush(a, -(b >> 1))

print(-sum(a))


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define REP(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, 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; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int num[10][10];

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

	for (int i = 1; i <= n; ++i) {
		vi d;
		int v = i;

		while (v) {
			int b = v % 10;
			v /= 10;
			d.push_back(b);
		}
		int s = d[0], e = d.back();
		if (!s || !e) continue; 
		num[s][e]++;
	}

	ll ans = 0;
	for (int i = 1; i < 10; ++i) {
		for (int j = 1; j < 10; ++j) {
			ans += num[i][j] * num[j][i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		long A = sc.nextLong();
		long B = sc.nextLong();

		List<Long> a = new ArrayList<>();
		List<Long> b = new ArrayList<>();

		long K = A;
		long L = B;

		a.add((long) 1);
		b.add((long) 1);

		for (long i = 2; i <= Math.sqrt(A); i++) {
			if (K % i == 0)
				a.add(i);
			while (K % i == 0)
				K = K / i;
		}
		if (K > 1)
			a.add(K);

		for (long i = 2; i <= Math.sqrt(B); i++) {
			if (L % i == 0)
				b.add(i);
			while (L % i == 0)
				L = L / i;

		}
		if (L > 1)
			b.add(L);

		long ans = 0;
		for (int i = 0; i < a.size(); i++) {
			if (b.contains(a.get(i)))
				ans++;
		}
		System.out.println(ans);

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 22484
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static long f(String s, int end, long acc) {
		long n = Long.parseLong(s.substring(0, end));
		if (end == s.length()) {
			return acc + n;
		} else {
			return f(s, end + 1, acc) + f(s.substring(end), 1, acc + n);
		}
	}

	static void exec(MyScanner in, PrintWriter out) {
		String S = in.next();
		out.println(f(S, 1, 0));
	}

	public static void main(String[] args) {
		PrintWriter w = new PrintWriter(System.out);
		exec(new MyScanner(System.in), w);
		w.flush();
	}

	static class MyScanner {
		static final int BUFFER_SIZE = 1024;
		private final InputStream in;
		private final byte[] buffer = new byte[BUFFER_SIZE];
		private int point;
		private int readLength;
		MyScanner(InputStream in) {
			this.in = in;
		}
		private int readByte() {
			if (point < readLength) {
				int result = buffer[point];
				point += 1;
				return result;
			}
			try {
				readLength = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (readLength == -1) {
				return -1;
			}
			point = 1;
			return buffer[0];
		}
		static boolean isPrintableCharExceptSpace(int c) {
			return 33 <= c && c <= 126;
		}
		String next() {
			StringBuilder b = new StringBuilder();
			int c = readByte();
			while (!(c == -1 || isPrintableCharExceptSpace(c))) {
				c = readByte();
			}
			if (c == -1) {
				throw new NoSuchElementException();
			}
			do {
				b.appendCodePoint(c);
				c = readByte();
			} while (c != -1 && isPrintableCharExceptSpace(c));
			return b.toString();
		}
		long nextLong() {
			int c = readByte();
			while (!(c == -1 || isPrintableCharExceptSpace(c))) {
				c = readByte();
			}
			if (c == -1) {
				throw new NoSuchElementException();
			}
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long result = 0L;
			do {
				if (!('0' <= c && c <= '9')) {
					throw new InputMismatchException();
				}
				result = result * 10L + (c - '0');
				c = readByte();
			} while (c != -1 && isPrintableCharExceptSpace(c));
			return minus ? -result : result;
		}
		int nextInt() {
			long n = nextLong();
			if (Integer.MIN_VALUE <= n && n <= Integer.MAX_VALUE) {
				return (int) n;
			}
			throw new InputMismatchException();
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

}


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

using namespace std;

int main(void)
{
	char b;

	cin>>b;

	if(b=='A') cout<<'T'<<endl;
	else if(b=='T')	cout<<'A'<<endl;
	else if(b=='C')	cout<<'G'<<endl;
	else cout<<'C'<<endl;

	return 0;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
Number=0
count =0
 
for i in range (55):
    MAX=max(A,B,C)
    Number=0
    if MAX==A:
        Number=Number+1
    if MAX==B:
        Number=Number+1
    if MAX==C:
        Number=Number+1
 
    if Number ==1:
        MAX=max(A,B,C)
        if MAX!=A:
            A=A+1
        if MAX!=B:
            B=B+1
        if MAX!=C:
            C=C+1
        count=count +1
        Number=0
 
    if Number ==2:
        MAX=max(A,B,C)
        if MAX!=A:
            A=A+2
        if MAX!=B:
            B=B+2
        if MAX!=C:
            C=C+2
        count=count +1
        Number=0
    
    if Number ==3:
        print('%d'%(count))
        break

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>

using namespace std;

const int A = 100000;

int kk[A + 1];

int main() {
	int n; cin >> n;
	long long x = 0;
	while (n--) {
		int a; cin >> a;
		x += a;
		kk[a]++;
	}
	int q; cin >> q;
	while (q--) {
		int b, c; cin >> b >> c;
		cout << (x += (long long) (c - b) * kk[b]) << '\n';
		kk[c] += kk[b];
		kk[b] = 0;
	}
	return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	string s2;
	for(int i = 0; i < s.size(); ++i) {
		if(s[i] != 'x') s2.push_back(s[i]);
	}
	deque<int> d;
	for(int i = 0; i < s.size(); ++i) {
		d.push_back(s[i]);
	}
	int ans = 0;
	while(d.size() > 1) {
		if(d.front() == d.back()) {
			d.pop_back();
			d.pop_front();
			continue;
		}
		if(d.front() == 'x') {
			++ans;
			d.pop_front();
			continue;
		}
		if(d.back() == 'x') {
			++ans;
			d.pop_back();
			continue;
		}
		cout<<-1<<'\n';
		return 0;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 896
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

int main()
{
    int a,b,c,d;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        int sum,e;
        if(a>b)
            sum=b;
        else
            sum=a;
        if(c>d)
            sum=sum+d;
        else
            sum=sum+c;
        printf("%d\n",sum);
    }
    return 0;
}




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

sa=set()
sb=set()

for i in range(m):
    a,b=map(int,input().split())
    if a==1:sb.add(b)
    if b==n:sa.add(a)

print('IMPOSSIBLE' if len(sa&sb)==0 else 'POSSIBLE')

Measured memory_bytes: 19024
k = int(input())
s = input()
MOD = 10**9+7

class Facts():
   # O(max_num)
   def __init__(self, max_num=10**5, p=10**9+7):
      self.p = p
      self.max_num = max_num
      self.fact = [1] * (self.max_num + 1)
      self.rev = [1] * (self.max_num + 1)
      for i in range(1, self.max_num + 1):
         self.fact[i] = (self.fact[i-1] * i) % self.p
      self.rev[self.max_num] = self.power_func(self.fact[self.max_num], self.p-2)
      for i in range(self.max_num-1, 0, -1):
         self.rev[i] = self.rev[i+1] * (i + 1) % self.p

   def comb(self, n, k):
      if n < 0 or k < 0 or n < k:
         return 0
      if n == 0 or k == 0:
         return 1
      res = ((self.fact[n] * self.rev[k] % self.p) * 
               self.rev[n - k]) % self.p
      return res

   def power_func(self, a, b):
      # a^b mod p
      # O(log(b))
      ans = 1
      while b > 0:
         if b & 1:
               ans = ans * a % self.p
         a = a * a % self.p
         b >>= 1
      return ans

r26 = [1 for _ in range(k + 1)]
r25 = [1 for _ in range(k + 1)]
for i in range(1, k+1):
   r26[i] = (r26[i-1] * 26) % MOD
   r25[i] = (r25[i-1] * 25) % MOD
facts = Facts(max_num=len(s)+k+1, p=MOD)

total = len(s) + k
ans = 0
for s_n in range(len(s), total+1):
   d = total - s_n
   ans += facts.comb(total - d - 1, len(s) - 1) * r25[k-d] * r26[d]
   ans %= MOD

print(ans)


Measured memory_bytes: 166576
import sys
sys.setrecursionlimit(1000000)
def FF(E, s, t):
    NN = H+W+2
    G = [[] for _ in range(NN)]
    for a, b, f in E:
        G[a].append([b, f, len(G[b])])
        G[b].append([a, 0, len(G[a])-1])
    
    def dfs(s, t, f):
        if s == t:
            return f
        used[s] = 1
        for i, (b, _f, r) in enumerate(G[s]):
            if used[b] or _f == 0: continue
            d = dfs(b, t, min(f, _f))
            if d > 0:
                G[s][i][1] -= d
                G[b][r][1] += d
                return d
        return 0
    
    flow = 0
    while 1:
        used = [0] * NN
        f = dfs(s, t, 10**100)
        if f == 0:
            return flow
        flow += f

E = []

H, W = map(int, input().split())
for i in range(H):
    A = input()
    for j in range(W):
        if A[j] == "o":
            E.append((i, j+H, 1))
            E.append((j+H, i, 1))
        elif A[j] == "S":
            S = (i, j+H)
        elif A[j] == "T":
            T = (i, j+H)
E.append((H+W, S[0], 10**6))
E.append((H+W, S[1], 10**6))
E.append((T[0], H+W+1, 10**6))
E.append((T[1], H+W+1, 10**6))

ff = FF(E, H+W, H+W+1)
print(ff if ff < 10**6 else -1)


Measured memory_bytes: 55772
#include<iostream>
using namespace std;
int main()
{
	char s[20];
	cin>>s;
	int i,r=0;
	for(i=0;s[i]!='\0';i=i+2)
	{
		if(s[i]!='h'||s[i+1]!='i')
		
		r=1;
	}
	if(r==0)
	cout<<"Yes";
	else
	cout<<"No";
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

#define P 1000000007

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a;
  vector<int> c;
  a.resize(n);
  c.resize(n);
  for(int i = 0; i < n; i++) {
    a[i].resize(m);
    for(int j = 0; j < m; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  int ans = n;
  set<int> excep;
  for(int i = 0; i < m; i++) {
    int sum = m;
    vector<int> ret;
    ret.resize(m);
    for(int j = 0; j < n; j++) {
      for(int k = 0; k < m; k++) {
        if(excep.find(a[j][k]) == excep.end()) {
          ret[a[j][k]]++;
          break;
        }
      }
    }
    int id = 0;
    for(int j = 0; j < m; j++) {
      if(ret[id] < ret[j]) {
        id = j;
      }
    }
    ans = min(ans, ret[id]);
    excep.insert(id);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<int> facts(N + 1);
    rrep(i, N, 1)
    {
        int n = i;
        rep(j, 2, n + 1)
        {
            int cnt = 0;
            while (n % j == 0)
            {
                n /= j;
                ++cnt;
            }

            if (cnt > 0)
            {
                facts[j] += cnt;
            }
        }
    }

    int ans = 0;

    rep(i, 0, facts.size())
    {
        // 75
        if (facts[i] >= 74) ++ans;
    }

    rep(i, 0, facts.size())
    {
        rep(j, i + 1, facts.size())
        {
            // 3 * 25
            if (facts[i] >= 2 && facts[j] >= 24) ++ans;

            // 25 * 3
            if (facts[i] >= 24 && facts[j] >= 2) ++ans;

            // 5 * 15
            if (facts[i] >= 4 && facts[j] >= 14) ++ans;

            // 15 * 5
            if (facts[i] >= 14 && facts[j] >= 4) ++ans;
        }
    }

    rep(i, 0, facts.size())
    {
        rep(j, i + 1, facts.size())
        {
            rep(k, j + 1, facts.size())
            {
                // 3 * 5 * 5
                if (facts[i] >= 2 && facts[j] >= 4 && facts[k] >= 4) ++ans;

                // 5 * 3 * 5
                if (facts[i] >= 4 && facts[j] >= 2 && facts[k] >= 4) ++ans;

                // 5 * 5 * 3
                if (facts[i] >= 4 && facts[j] >= 4 && facts[k] >= 2) ++ans;
            }
        }
    }

    cout << ans << endl;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#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 pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------


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

	string ls[7]={"mon","tue","wed","thu","fri","sat","sun"};
	int x;cin>>x;
	cout<<ls[(x+3)%7]<<endl;

	return 0;
}



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

typedef long long ll;
const ll INF = 1LL << 60;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

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

    k = min(k, n - 1);
    combination c(n);
    mint ans;
    for (int i = 0; i <= k; i++) {
        ans += c(n, i) * c(n - i - 1 + i, i);
    }
    cout << ans.x << endl;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))


int solve(string& x) {
    stack<char> st;
    for (char ch:x) {
        if (st.empty()) {
            st.push(ch);
        } else {
            if (st.top() == 'S' && ch == 'T') {
                st.pop();
            } else {
                st.push(ch);
            }
        }
    }
    return st.size();
}

int main() {
    string x; cin >> x;
    cout << solve(x) << endl;
    // cout << (solve(N,a) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,c=1;
  cin>>n;
  for(int i=0;i<n;i++){
    int p=0;
    cin>>a;
    for(;a%2==0;a/=2){
      p++;
    }
    if(p<c||i==0)
      c=p;
  }
  cout<<c;
}

Measured memory_bytes: 256
/*==========================================================================*/
/*
    AUTHOR:    BPZ
	CREATED:   30.08.2020 11:02:46

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, t;
  cin >> n >> x >> t;
  n % x == 0 ? cout << n / x * t << '\n' : cout <<  (n / x + 1) * t << '\n';
  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
const ll MOD=1000000007;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin>>N;
    int maxd=1;
    for(int i=1;i<=sqrt(N);i++){
        if(N%i==0)maxd=i;
    }
    cout<<maxd-1+N/maxd-1<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=2e5+10;
typedef long long LL;
#define x first
#define y second

int n;
LL k;
LL a[maxn];
pair<LL,int> sum[maxn];
int rnk[maxn];
LL ans,bit[maxn];

int lowbit(int p)
{
	return p&(-p);
}

LL search(int p)
{
	LL ans=0;
	while(p>0)
	{
		ans+=bit[p];
		p-=lowbit(p);
	}
	return ans;
}

void add(int p)
{
	while(p<=n)
	{
		bit[p]++;
		p+=lowbit(p);
	}
	return;
}

int main()
{
	scanf("%d%lld",&n,&k);
	ans=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		a[i]-=k;
		sum[i].x=sum[i-1].x+a[i];
		sum[i].y=i;
		if (sum[i].x>=0) ans++; 
	}
	sort(sum+1,sum+n+1);
	
	for(int i=1;i<=n;i++)
	    rnk[sum[i].y]=i;
	
	for(int i=1;i<=n;i++)
	{
		ans+=search(rnk[i]-1);
		add(rnk[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int A,B,C,D,X,Y ;
  cin >>A>>B>>C>>D;
  X=A+B;
  Y=C+D;
  
  if ( X>Y ){
    cout<< "Left" << endl;
  }
  else if ( X<Y ){
    cout << "Right" << endl;
  }
    else{
      cout << "Balanced" << endl;
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string st;
int ans;
int main()
{
	getline(cin,st);
	int len=st.size();
	for(int i=1;i<len;i++)
	if(st[i]!=st[i-1])
	ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

int main()
{
	int A, P;
	
	std::cin >> A >> P;

	std::cout << (A * 3 + P) / 2 << "\n";
}


Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
st=array(N)
N.times do|i|
    st[i]=get
    st[i][1]=st[i][1].to_i
end
X=gets.chomp
flag=false
ans=0
N.times do|i|
  if flag 
      ans+=st[i][1]
  elsif st[i][0]==X
      flag=true
  end
end
puts ans

Measured memory_bytes: 1788
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E solver = new E();
        solver.solve(1, in, out);
        out.close();
    }

    static class E {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] A = new int[N];
            int[] B = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.Int();
                B[i] = in.Int();
            }

            Arrays.sort(A);
            Arrays.sort(B);
            if (N % 2 == 0) {
                int a = (A[N / 2 - 1] + A[N / 2]);
                int b = (B[N / 2 - 1] + B[N / 2]);
                out.println(b - a + 1);
            } else {
                int a = A[N / 2];
                int b = B[N / 2];
                out.println(b - a + 1);
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 57856
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: Vec<char> = sc.chars();
    let mut rem = 0;
    for i in 0..N.len() {
        let d = (N[i] as u8 - b'0') as usize;
        rem += d;
        rem %= 9;
    }
    if rem == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 3088
#include <iostream>

using namespace std;

int main()
{
  int n=0, a;
  
  for (int i = 0; i < 3; i++) {
    cin >> a;
    n = 10 * n + a;
  }
  
  cout << ((n % 4 == 0) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256