akhauriyash/Code-Regression huggingface dataset:
H, W, D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int,input().split())) for _ in range(Q)]

number_list = [[0] * 2 for _ in range(H*W+1)]
for h in range(H):
    for w in range(W):
        number_list[A[h][w]] = [h, w]

d = [0] * (H*W+1)
for idx in range(H*W+1):
    pre_idx = idx - D
    if pre_idx <= 0:
        continue
    diff = abs(number_list[idx][0] - number_list[pre_idx][0])
    diff += abs(number_list[idx][1] - number_list[pre_idx][1])
    d[idx] = d[pre_idx] + diff

for l, r in LR:
    cnt = 0
    print(d[r] - d[l])


Measured memory_bytes: 86620
import sys
from fractions import gcd
import bisect
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ps = LI()
    if n % 2 != 0:
        print(0)
        return
    sr = sorted(ps)
    print(sr[n//2] - sr[n//2 - 1])





if __name__ == "__main__":
    main()

Measured memory_bytes: 16040
#include<stdio.h>
#include<string.h>
 
int main(void) {
  int i, j, k;
  int N;
  
  scanf("%d", &N);
  char str[N][11];
  
  for(i=0; i<N; i++){
    scanf("%s", str[i]);
    for(j=0; j<i; j++){
      if(strcmp(str[j], str[i])==0){
        puts("No");
        return 0;
      }
      if(j == i-1){
        if(str[j][strlen(str[j])-1] != str[i][0]){
          puts("No");
          return 0;
        }
      }
    }
  }
    puts("Yes");
    
    return 0;
  
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int i,h,max1=0,max2=0,max3=0;
	for(i=0;i<10;i++){
		scanf("%d",&h);
		if(max1 < h){
			max3 = max2;
			max2 = max1;
			max1 = h;
		}
		else if(max2 < h){
			max3 = max2;
			max2 = h;
		}
		else if(max3 < h){
			max3 = h;
		}
	}
	printf("%d\n%d\n%d\n",max1,max2,max3);
	return 0;
}

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

using namespace std;

int main()
{
    int a[3], b[2];
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }

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

    sort(a, a + 3);
    sort(b, b + 2);
    cout << a[0] + b[0] - 50 << endl;
    return 0;
}

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

int main ()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    vector<int> res(5);
    vector<int> num(2);
    num[0] = v[0];
    num[1] = v[1];
    for (int i = 2; i < n; i++) {
        int crl = num.size()-1;
        if (num[crl] == v[i]) {
            if (num[crl] != num[crl-1]) num.push_back(v[i]);
        } else if (num[crl] == num[crl-1]) {
            num.push_back(v[i]);
        } else if (num[crl] > num[crl-1]) {
            if (num[crl] < v[i]) num[crl] = v[i];
            else num.push_back(v[i]);
        } else if (num[crl] < num[crl-1]) {
            if (num[crl] > v[i]) num[crl] = v[i];
            else num.push_back(v[i]);
        } 
    }

    for (int i = 0; i < num.size()-2; i++) {
        if (num[i] > num[i+1] && num[i+1] < num[i+2]) {
            res[4]++;
        } else if (num[i] < num[i+1] && num[i+1] > num[i+2]) {
            res[3]++;
        } else if (i && i + 2 < num.size() && num[i] == num[i+1]) {
            if (num[i-1] < num[i] && num[i+1] > num[i+2]) {
                res[0]++; 
            } else if (num[i-1] > num[i] && num[i+1] < num[i+2]) {
                res[1]++;
            } else {
                res[2]++;
            }
        }
    }

    cout << res[0];
    for (int i = 1; i < res.size(); i++) {
        cout << " " << res[i];
    } cout << endl;

    return 0;
}


Measured memory_bytes: 2068
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

int main(void) {
    int vs, es;
    cin >> vs >> es;
    set<int> vs1;
    set<int> vs2;
    for(int i = 0; i < es; i++) {
        int v1, v2;
        cin >> v1 >> v2;
        if(v1 > v2) swap(v1, v2);
        if(v1 == 1) vs1.insert(v2);
        if(v2 == vs) vs2.insert(v1);
    }
    int sum = vs1.size() + vs2.size();
    for(int val: vs2) {
        vs1.insert(val);
    }
    int intersection = vs1.size();
    cout << (sum == intersection ? "IMPOSSIBLE" : "POSSIBLE") << endl;;
    return 0;
}

Measured memory_bytes: 17608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	ll h, w;
	cin >> h >> w;
	string a[h];
	ll cnt[30];
	memset(cnt, 0, sizeof(cnt));
	zep(i, 0, h){
		cin >> a[i];
		zep(j, 0, w){
			cnt[a[i][j] - 'a']++;
		}
	}
	ll cnt4 = 0;
	ll cnt2 = 0;
	ll cnt1 = 0;
	rep(i, 0, 25){
		cnt4 += cnt[i]/4;
		cnt[i] %= 4;
		cnt2 += cnt[i]/2;
		cnt[i] %= 2;
		cnt1 += cnt[i];
	}
	bool ans = true;
	if(h%2 == 0 && w%2 == 0){
		if(cnt2 > 0 || cnt1 > 0){
			ans = false;
		}
	}
	if(h%2 == 1 && w%2 == 0){
		if(cnt2 > w/2 || cnt1 > 0){
			ans = false;
		}
	}
	if(h%2 == 0 && w%2 == 1){
		if(cnt2 > h/2 || cnt1 > 0){
			ans = false;
		}
	}
	if(h%2 == 1 && w%2 == 1){
		if(cnt2+cnt1 > w/2+h/2+1 || cnt1 > 1){
			ans = false;
		}
	}
	if(ans){
		print("Yes")
	}
	else{
		print("No")
	}
	return 0;
}

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

int main() {

  string N;
  cin >> N;
  char a = N.at(0);
  char b = N.at(1);
  char c = N.at(2);
  char d = N.at(3);

  if(a==b&&b==c){
    cout << "Yes" << endl;
  }else if(b==c&&c==d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
	int N,M;
	cin >> N>>M;
	vector<int>a(N);

	int chk = 0,su=0;
	for (size_t i = 0; i < N; i++)
	{
		cin >> a.at(i);
		su += a.at(i);
	}
	for (size_t i = 0; i < N; i++)
	{
		if (ceil((double)(1.0*su / 4/M )) <= a[i])chk++;
	}
	if (chk >= M)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    int ans = 0;
    REP(maski,1<<h) REP(maskj,1<<w){
        int cnt = 0;
        REP(i,h) REP(j,w){
            if (((maski >> i) & 1) == 0) continue;
            if (((maskj >> j) & 1) == 0) continue;
            cnt += (s[i][j] == '#');
        }
        if (cnt == k) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-

from collections import Counter

def main(N,A):
    count = 0
    A_count = Counter(A)
    for a in A_count:
        if a==A_count[a]:
            continue
        else:
            if A_count[a]-a<0:
                count += A_count[a]
            else:
                count += A_count[a]-a
    print(count)

if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Measured memory_bytes: 18676
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define modInv(a) binExp(a,mod-2)
#define mod 1000000007
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define os_find(k) find_by_order(k)
//#define os_order(k) order_of_key(k)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

signed main()
{
    fast

    int n;
    cin>>n;

    int abc[n][3];
    int dp[n][3];
    f0(i,0,n) f0(j,0,3) cin>>abc[i][j];
    dp[0][0] = abc[0][0];
    dp[0][1] = abc[0][1];
    dp[0][2] = abc[0][2];

    f0(i,1,n)
    {
        f0(j,0,3)
        {
            dp[i][j] = 0;
            f1(k,1,2)
            {
                dp[i][j] = max(dp[i][j], dp[i-1][(j+k)%3]);
            }
            dp[i][j] += abc[i][j];
        }
    }
    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}

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

public static class combi
{
    public static IEnumerable<IEnumerable<T>> Comb<T>(this IEnumerable<T> items, int r)
    {
        if (r == 0)
        {
            yield return Enumerable.Empty<T>();
        }
        else
        {
            var i = 1;
            foreach (var x in items)
            {
                var xs = items.Skip(i);
                foreach (var c in Comb(xs, r - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items)
            yield return i;
    }
}
public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var s = int.Parse(line[1]);
            if (n == 0 && s == 0) break;
            var a = Enumerable.Range(0, 10).Comb(n);
            var ans = 0;
            foreach (var x in a)
                if (x.Sum() == s) ans++;
            Console.WriteLine(ans);
        }
    }
}

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

int main() {
	int a,b;
	cin>>a>>b;
	if(a>b){
	            cout<<"a > b"<<endl;	
	}else if(a<b){
		cout<<"a < b"<<endl;
	}else{
		cout<<"a == b"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string, int> P;

int main() {
	int h, w;
	while(scanf("%d %d", &h, &w), h && w) {
		rep(i, h) {
			rep(j, w) printf("#");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>

int main(){
  int S[1000000];
  int T[1000000];
  int n;
  int q;
  int c=0;
  int m;
  int r;
  int l;
  int i,j;

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    r=n;
    l=0;
    while(l<r){
      m=(r+l)/2;
      if(T[i]==S[m]){
	c++;
	break;
      }
      if(T[i]>S[m]){
	l=m+1;
      }
      else if(T[i]<S[m]){
	r=m;
      }
    }
  }

  printf("%d\n",c);

  return 0;
}

Measured memory_bytes: 4944
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define int ll
ll n,a,b;
bool judge(vector<ll> vec,ll k){
  for(int i=0;i<n;i++) vec[i]-=k*b;
  queue<ll> que;
  for(int i=0;i<n;i++) if(vec[i]>0) que.push(vec[i]);
  ll cnt=0;
  if(que.empty()) return true;
  while(!que.empty()){
    ll val=que.front();
    que.pop();
    cnt+=val/(a-b);
    if(val%(a-b)!=0) cnt++;
  }
  if(cnt<=k) return true;
  else return false;
}
signed main(){
  cin>>n>>a>>b;
  vector<ll> vec;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    vec.push_back(a);
  }
  ll lb=0,rb=1744174417;
  while(rb-lb>1){
    ll mid=(lb+rb)/2;
    if(judge(vec,mid)) rb=mid;
    else lb=mid;
  }
  cout<<rb<<endl;
}


Measured memory_bytes: 2684
#include<iostream>
#include<cctype>
using namespace std;
int main(){
    int C=0,u=0;
    string s;
    cin>>s;
    for(int i=2;i<s.size()-1;i++)if(s[i]=='C')C++;
    for(int i=0;i<s.size();i++)if(isupper(s[i]))u++;
    cout<<(s[0]=='A'&&C==1&&u==2?"AC":"WA")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, k, arr[100001], dp[100001];
int main()
{
    IOS
    //bfreopen("balalance.in", "r", stdin);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    memset(dp, INF, sizeof dp);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= k && i + j < n; ++j) {
            dp[i+j] = min(dp[i+j], dp[i] + abs(arr[i] - arr[i+j]));
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 2 * (x[-1] - x[0])
for i in range(n - k + 1):
    a, b = x[i], x[i + k - 1]
    if a * b < 0:
        ans = min(ans, min(abs(a), abs(b)) + b - a)
    else:
        ans = min(ans, max(abs(a), abs(b)))

print(ans)


Measured memory_bytes: 14252
#include <iostream>

using namespace std;

int main(){
    int N, X, min = 1000;
    cin >> N >> X;
    int m[N];
    for(int i = 0; i < N; i++){
        cin >> m[i];
        X -= m[i];
        if(min > m[i]) min = m[i];
    }
    cout << N + X / min << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[[] for i in range(n)]
a[0]=[0]
k=0
s=['a']*n
t=[0]*n
while k>=0:
  if a[k]==[]:
    k-=1
    continue
  t[k]=a[k].pop(0)
  s[k]=chr(ord('a')+t[k])
  if k==n-1:
    print("".join(s))
  else:
    k+=1
    a[k]+=list(range(max(t[:k])+2))

Measured memory_bytes: 46428
N,M = map(int,input().split())
G = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
cnt = [0]
def dfs(V,s):
    V[s] = 1
    if sum(V) == N:
        cnt[0] += 1
    else:
        for adj in G[s]:
            if V[adj] == 0:
                dfs(V[:adj] + [1] + V[adj + 1:], adj)
dfs([0] * N,0)
print(cnt[0])


Measured memory_bytes: 3188
#include<stdio.h>
#define M 100

int S[M][M];
int T[M+1];

void cul(int u,int v){
  int i,j;
  j=S[u][u]+S[u+1][v]+T[u]*T[u+1]*T[v+1];
  for(i=u;i<v;i++)if(j>S[u][i]+S[i+1][v]+T[u]*T[i+1]*T[v+1])j=S[u][i]+S[i+1][v]+T[u]*T[i+1]*T[v+1];
  S[u][v]=j;
  //printf("%d\n",j);
}

int main(){
  int a,b,i,j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    S[i][i]=0;
    scanf("%d",&T[i]);
    scanf("%d",&b);
    //printf(" %d\n",b);
  }
  T[a]=b;
  for(i=1;i<a;i++)for(j=0;i+j<a;j++)cul(j,j+i);
  printf("%d\n",S[0][a-1]);
  
  //for(i=0;i<a+1;i++)printf(" %d\n",T[i]);
}



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

int main(){
    while(1){
        int n, m; cin>>n>>m;
        if(n == 0) return 0;

        string s = "";
        for(int i=0; i<n; i++){
            s += "#";
        }

        while(m--){
            char a; cin>>a;
            if(a == 'A'){
                for(int i=0; i<n; i++){
                    if(s[i] == '#'){
                        s[i] = 'A';
                        break;
                    }
                }
            }
            else if(a == 'B'){
                bool valid = false;
                for(int i=n-1; i>=0; i--){
                    if(s[i] != '#') continue;

                    if((i + 1 < n && s[i+1] == 'A') || (0 <= i - 1 && s[i-1] == 'A')) continue;
                
                    s[i] = 'B';
                    valid = true;
                    break;
                }

                if(valid) continue;

                for(int i=0; i<n; i++){
                    if(s[i] == '#'){
                        s[i] = 'B';
                        break;
                    }
                }
            }
            else if(a == 'C'){
                bool valid = false;
                for(int i=0; i<n; i++){
                    if(s[i] != '#'){
                        if(i + 1 < n && s[i+1] == '#'){
                            s[i+1] = 'C';
                            valid = true;
                            break;
                        }
                        
                        if(0 <= i - 1 && s[i-1] == '#'){
                            s[i-1] = 'C';
                            valid = true;
                            break;
                        }
                    }
                }

                if(valid) continue;

                s[n/2] = 'C';
            }
            else{
                int dist = 0;
                int id = -1;
                for(int i=0; i<n; i++){
                    if(s[i] != '#') continue;
                    int near = 1e9;
                    for(int j=0; j<n; j++){
                        if(i == j || s[j] == '#') continue;
                        
                        near = min(near, abs(i - j));
                    }

                    if(near == 1e9) continue;

                    if(dist < near){
                        dist = near;
                        id = i;
                    }
                }

                if(id != -1){
                    s[id] = 'D';
                }
                else{
                    s[0] = 'D';
                }
            }
        }

        cout << s << endl;
    }
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
#define ld long double

using namespace std;	

const int N = 1e5;

int ans[N];

int main() {	
	int n;
	scanf ("%d", &n);
	rep(i, 1, 100)
		rep(j, 1, 100)
			rep(k, 1, 100)
				ans[i * i + j * j + k * k + i * j + i * k + j * k]++;
	rep(i, 1, n)
		printf ("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 3916
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    vector<ll> a(n), l(n + 1), r(n + 1), c(n - k + 1);
    rep (i, n) cin >> a[i];
    rep (i, n) l[i + 1] = l[i] + (a[i] > 0LL ? a[i] : 0LL);
    reprev (i, n) r[i] = r[i + 1] + (a[i] > 0LL ? a[i] : 0LL);
    rep (i, k) c[0] += a[i]; rep (i, n - k) c[i + 1] = c[i] - a[i] + a[i + k];
    for (ll i : l) eprintf("%lld ", i); eprintf("\n");
    for (ll i : r) eprintf("%lld ", i); eprintf("\n");
    for (ll i : c) eprintf("%lld ", i); eprintf("\n");

    ll ans = 0;
    rep (i, n - k + 1) chmax(ans, l[i] + r[i + k] + (c[i] > 0LL ? c[i] : 0LL));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string s;
  
  cin >> s;
  
  for (int i = 0; i < s.size(); i += 2) {
    if (s[i] != 'h' || s[i+1] != 'i') {
      cout << "No" << endl;
      return (0);
    }
  }
  
  cout << "Yes" << endl;
}

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

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1<<30;
const ll MOD = 1e9+7;

vector<ll> tree;
int n;

int st_idx(){
	int l = ceil(log2(n));
	int idx = pow(2, l);
	return idx;
}

void upd(int k, ll x){
	k += st_idx();
	tree[k] = x;
	k/=2;
	while(k!=0){
		tree[k] = max(tree[2*k], tree[2*k+1]);
		k/=2;
	}
}

void build(vector<ll> arr){
	int sz = st_idx()*2;
	tree.assign(sz, 0);
	for(int i=0;i<arr.size();i++){
		upd(i, arr[i]);
	}
}

ll rmq(int l, int r){
	l += st_idx(); r += st_idx();
	ll ans = 0;
	while(l<=r){
		if(l%2 == 1)
			ans = max(ans, tree[l++]);
		if(r%2 == 0)
			ans = max(ans, tree[r--]);
		l/=2; r/=2;
	}
	return ans;
}

int main(){
	vector<pair<int, int> > h;
	vector<ll> dp;
	vector<ll> a;

	cin>>n;
	a.assign(n, 0);
	h.assign(n, {0, 0});
	dp.assign(n, 0);
	build(dp);

	for(int i=0;i<n;i++){
		cin>>h[i].first;
		h[i].second = i;
	}
	for(int i=0;i<n;i++)
		cin>>a[i];

	sort(h.rbegin(), h.rend());

	for(int i=0;i<n;i++){
		int ht = h[i].first;
		int idx = h[i].second;
		ll maxi = rmq(idx, n-1);
		/*for(int j=idx;j<n;j++)
			maxi = max(maxi, dp[j]);*/
		upd(idx, maxi+a[idx]);
		dp[idx] = maxi+a[idx];
	}
	
	ll ans = 0;
	for(int i=0;i<n;i++)
		//cout<<i<<" : "<<dp[i]<<"\n";
		ans = max(ans, dp[i]);

	cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 13944
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    vector<lint> h(n);
    for(auto& elem : h)  cin >> elem;

    sort(begin(h), end(h));
    reverse(begin(h), end(h));

    lint sum = 0;
    for(lint i=0; i<n; i++) {
        if(i < k)  continue;
        sum += h[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 1792
/* 
	  WHEN YOU DONT FEEL LIKE DOING IT ,
	  THATS THE TIME YOU GOTTA DO IT
	*/	  
	#include <bits/stdc++.h>
	using namespace std;
		     
	#define ll long long int
	#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
		     
	#define mp make_pair
	#define pb push_back
	#define ld long double
	#define F first
	#define S second
	const ll N =(1e6);  
	const ll mod = (1e9+7);
	
	//ll arr[N];

	int main(){
	fast;
	ll n;
	cin >> n ;
	ll a[n+1] , b[n+1] , c[n];
	for(ll i =1 ; i <= n ; i++){
		cin >> a[i];
	}
	for(ll i = 1 ; i <= n ; i++){
		cin >> b[i];
	}

	for(ll i = 1 ; i < n ; i++){
		cin >> c[i];
	}
		ll sum=b[a[1]];

	for(ll i = 2 ; i<=n; i++){
		if(a[i] - a[i-1] == 1)
			sum+=b[a[i]] + c[a[i] - 1];
			else
				sum+=b[a[i]];
	}
		cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<ll> A(N), cum(N+1);
    REP(i,N) cin >> A[i];
    sort(A.rbegin(), A.rend());
    REP(i,N) cum[i+1] = cum[i] + A[i];
    ll ans = P;
    for(int i=P;i<N;i++){
        if(A[i] + M < A[P-1]) continue;
        ll cur = V - (N - (i - P + 1));
        if(cur <= 0){
            ans++;
            continue;
        }
        if(cur * M <= (i - P + 1) * (A[i] + M) - (cum[i] - cum[P-1])) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K



int main(){
    ll n,x;
    cin >> n >> x;
    ll m,min_m=114514810;
    REP(i,n){
        cin >> m;
        x -= m;
        min_m = min(min_m,m);
    }
    cout << n+(x/min_m) << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, w = sc.nextInt()
  val wv = List.fill(n)((sc.nextLong(), sc.nextInt()))
  val x = wv.head._1
  val w0 = wv.filter(_._1 == x).map(_._2).sorted.reverse.scanLeft(0)(_ + _)
  val w1 = wv.filter(_._1 == x+1).map(_._2).sorted.reverse.scanLeft(0)(_ + _)
  val w2 = wv.filter(_._1 == x+2).map(_._2).sorted.reverse.scanLeft(0)(_ + _)
  val w3 = wv.filter(_._1 == x+3).map(_._2).sorted.reverse.scanLeft(0)(_ + _).toArray

  var ans = 0
  for {
    (v0, i0) <- w0.zipWithIndex
    (v1, i1) <- w1.zipWithIndex
    (v2, i2) <- w2.zipWithIndex
  } {
    val rest = w - (i0 * x + i1 * (x+1) + i2 * (x+2))
    if (rest >= 0) {
      val i3 = (rest / (x+3)).min(w3.length-1).toInt
      ans = ans.max(v0 + v1 + v2 + w3(i3))
    }
  }
  println(ans)
}


Measured memory_bytes: 56096
/*
string ver.
*/
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
	long ans=0;
	string s;
	cin>>s;
	long j=0,old=0;
	for(long i=0;s[i]!=0;i++){
		for(j=0;s[i+j]=='A';j++);
		if(j>0 || old>0){
			if(s[i+j]=='B' && s[i+j+1]=='C'){
				ans+=j+old;
				old+=j;
				i+=j+1;
			}else{
				old=0;
				i+=j-1;
			}
		}else{
			old=0;
		}
	}
	printf("%ld",ans);
	return 0;
}


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

using namespace std;


int main()
{
    string s;
    cin>>s;
    if(s=="Sunny"){
        printf("Cloudy\n");
    }else if(s=="Cloudy"){
        printf("Rainy\n");
    }else if(s=="Rainy"){
        printf("Sunny\n");
    }
    return 0;
}




Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $S);
$n = strlen($S);
$dp[0][0] = 0;
for ($i = 0; $i < $n; $i++) {
  $c1 = $c2 = '';
  if (isset($dp[$i][0])) {
    if (!isset($dp[$i + 1][1])) {
      $dp[$i + 1][1] = $dp[$i][0] + 1;
    } else {
      $dp[$i + 1][1] = max($dp[$i + 1][1], $dp[$i][0] + 1);
    }
  }
  if (isset($dp[$i][2])) {
    if (!isset($dp[$i + 1][1])) {
      $dp[$i + 1][1] = $dp[$i][2] + 1;
    } else {
      $dp[$i + 1][1] = max($dp[$i + 1][1], $dp[$i][2] + 1);
    }
  }
  // 1文字取る
  $c1 = substr($S, $i, 1);
  if (isset($dp[$i][1])) {
    if (substr($S, $i - 1, 1) !== $c1) {
      if (!isset($dp[$i + 1][1])) {
        $dp[$i + 1][1] = $dp[$i][1] + 1;
      } else {
        $dp[$i + 1][1] = max($dp[$i + 1][1], $dp[$i][1] + 1);
      }
    }
  }
  if ($i > 0) {
    if (isset($dp[$i - 1][0])) {
      if (substr($S, $i - 2, 2) !== $c2) {
        if (!isset($dp[$i + 1][2])) {
          $dp[$i + 1][2] = $dp[$i - 1][0] + 1;
        } else {
          $dp[$i + 1][2] = max($dp[$i + 1][2], $dp[$i - 1][0] + 1);
        }
      }
    }
    if (isset($dp[$i - 1][1])) {
      if (!isset($dp[$i + 1][2])) {
        $dp[$i + 1][2] = $dp[$i - 1][1] + 1;
      } else {
        $dp[$i + 1][2] = max($dp[$i + 1][2], $dp[$i - 1][1] + 1);
      }
    }
    // 2文字取る
    $c2 = substr($S, $i - 1, 2);
    if (isset($dp[$i - 1][2])) {
      if (substr($S, $i - 2, 2) !== $c2) {
        if (!isset($dp[$i + 1][2])) {
          $dp[$i + 1][2] = $dp[$i - 1][2] + 1;
        } else {
          $dp[$i + 1][2] = max($dp[$i + 1][2], $dp[$i - 1][2] + 1);
        }
      }
    }
  }
}
printf("%d", max($dp[$n]));


Measured memory_bytes: 86768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long ans = 0;
		for(long i = n;; i--) {
			double a = Math.sqrt(i);
			if(a == Math.ceil(a)) {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
	}
}

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

class WithIndex<T>
{
    public T Value;
    public int Index;
    public WithIndex(T value, int index)
    {
        this.Value = value;
        this.Index = index;
    }
}

static class Template
{
    public static int LineToInt()
    {
        return int.Parse(Console.ReadLine());
    }

    public static string[] LineToStrings()
    {
        return Console.ReadLine().Split();
    }

    public static int[] LineToInts()
    {
        return LineToStrings()
            .Select(s => int.Parse(s))
            .ToArray();
    }


    public static int[,] LinesToIntTable(int lineCount, int columnCount)
    {
        var value = new int[lineCount, columnCount];
        foreach (var y in Enumerable.Range(0, lineCount))
        {
            var ints = LineToInts();
            foreach (var x in Enumerable.Range(0, columnCount))
            {
                value[y, x] = ints[x];
            }
        }
        return value;
    }

    public static IEnumerable<WithIndex<T>> WithIndex<T>(this IEnumerable<T> sequence)
    {
        int index = 0;
        foreach (var item in sequence)
        {
            yield return new WithIndex<T>(item, index);
            index++;
        }
    }

    static void Main(string[] args)
    {
        var num = LineToInt();
        var nums = new int[num];
        foreach (var i in Enumerable.Range(0, num))
        {
            nums[i] = LineToInt();
        }
        var ordered = nums.WithIndex().OrderBy(x => x.Value).ToArray();
        var max = ordered.Last();
        var secondMax = ordered[ordered.Length - 2];

        foreach(var i in Enumerable.Range(0, num))
        {
            if (i == max.Index)
            {
                Console.WriteLine(secondMax.Value);
            }
            else
            {
                Console.WriteLine(max.Value);
            }
        }
    }
}



Measured memory_bytes: 34388
import heapq
N = int(input())
S = list(map(int, input().split()))
heapq.heapify(S)

for i in range(N-1):
    a = heapq.heappop(S)
    b = heapq.heappop(S)
    heapq.heappush(S, (a+b)/2)

print(heapq.heappop(S))

Measured memory_bytes: 9044
#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 A, B, C;
    cin >> A >> B >> C;

    if(B+C > A) {
    cout << B+C-A << endl;
    } else {
        cout << 0 << endl;
    }


    return 0;
}

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;
  cin >> N;
  vector< int64 > A(N);
  cin >> A;
  int64 ret = 0;
  while(*max_element(begin(A), end(A)) >= N) {
    int64 add = 0;
    vector< int64 > pre(N);
    for(int i = 0; i < N; i++) {
      pre[i] = A[i] / N;
      add += pre[i];
    }
    ret += add;
    for(int i = 0; i < N; i++) {
      A[i] -= pre[i] * N;
      A[i] += add - pre[i];
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define INF 1e9
#define MAX_V 10000
using namespace std;

typedef pair<int,int> P;

//辺を表す構造体(行き先、容量、逆辺)
struct edge{int to, cap, rev, num;};

vector<edge> G[MAX_V]; //グラフの隣接リスト
bool used[MAX_V];      //DFSですでに調べたかのフラグ

int t_idx[MAX_V];

//fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from,int to,int cap,int num){
  t_idx[num] = to;
  G[from].push_back((edge){to,cap,(int)G[to].size(),num});
  G[to].push_back((edge){from,0,(int)G[from].size()-1,num});  
}

//増加パスをDFSで探す
int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to ,t , min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

//sからtへの最大流を求める
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}

int N, M, S, T;
int used1[MAX_V], used2[MAX_V];

void dfs1(int x){
  
  if( used1[x] ) return;
  used1[x] = 1;
  
  for(edge nx : G[x] ){
    
    if( t_idx[nx.num] == x && nx.cap == 1 ) dfs1( nx.to );
    
    if( t_idx[nx.num] == nx.to && nx.cap == 1 ) dfs1( nx.to );
    
  }
  
}

void dfs2(int x){
  
  if( used2[x] ) return;
  used2[x] = 1;

  for(edge nx : G[x] ){
    
    if( t_idx[nx.num] == x && nx.cap == 0 ) dfs2( nx.to );
    
    if( t_idx[nx.num] == nx.to && nx.cap == 0 ) dfs2( nx.to );
    
  }
  
}

signed main(){

  while(1){
  
    cin>>N>>M>>S>>T;
    if( !N && !M && !S && !T ) break;
    
    S--, T--;
    
    for(int i=0;i<N;i++) G[i].clear();
    
    for(int i=0;i<M;i++){
      int a, b;
      cin>>a>>b;
      add_edge( a-1, b-1, 1, i );
    }
    
    int ans = max_flow( S, T ), cnt = 0;
    
    memset( used1, 0, sizeof(used1) );
    memset( used2, 0, sizeof(used2) );
    
    dfs1(S);
  
    dfs2(T);
  
    for(int i=0;i<N;i++){
    
      for(edge ni : G[i] ){
      
	if( used2[i] && used1[ni.to] && t_idx[ni.num] == ni.to && ni.cap == 1 ) cnt++;
      
      }
    
    }
  
    if( cnt ) ans++;
  
    cout<<ans<<' '<<cnt<<endl;
  
  }
  
  return 0;
}



Measured memory_bytes: 4668
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN = 1005;
int n;
long long lasta,lastb;
int main()
{
	cin>>n;
	while(n--){
		long long a,b;
		scanf("%lld%lld",&a,&b);
		if(a>=lasta && b>=lastb)lasta=a,lastb=b;
		else {
			long long ta,tb;
			ta=(lasta/a+bool(lasta%a))*a,tb=(lasta/a+bool(lasta%a))*b;
			if(ta>=lasta && tb>=lastb){lasta=ta,lastb=tb;continue;}
			ta=(lastb/b+bool(lastb%b))*a,tb=(lastb/b+bool(lastb%b))*b;
			if(ta>=lasta && tb>=lastb){lasta=ta,lastb=tb;continue;}
		}
	}
	cout<<lasta+lastb<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char st[10000];
    int len,n,i;
    scanf("%s",st);
    scanf("%d",&n);
    len=strlen(st);
    for(i=0;i<len;i=i+n){
        printf("%c",st[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
r, c, k = gets.split.map(&:to_i)

v = Array.new(r+1) {Array.new(c+1)}
k.times do
    i, j, vv = gets.split.map(&:to_i)
    v[i][j] = vv
end

dp = Array.new(c+1) {Array.new(4,0)}
s = Array.new(c+1) {Array.new(4,0)}

1.upto(r) do |i|
    1.upto(c) do |j|
        vv = v[i][j]

        dp[j][0] = dp[j-1][0] if dp[j][0] < dp[j-1][0]
        dp[j][1,3] = dp[j-1][1,3]
        3.downto(1) {|m| dp[j][m] = dp[j][m-1] + vv if dp[j][m] < dp[j][m-1] + vv} if vv

        s[j][0] = dp[j].max
    end
    dp, s = s, dp
end

p dp[c][0]

Measured memory_bytes: 86796
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    ABC = il()
    N = ii()
    m = max(ABC)
    for n in range(N):
        m*=2
    print(sum(ABC) + m - max(ABC))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;


int main() {
        while(1){
                int n,x;
                cin >> n >>x;
                if(n==0 && x ==0) break;
                int ans = 0;
                for(int i=1;i<=n;i++){
                        for(int j= i+1;j<=n;j++){
                                for(int k = j+1;k<=n;k++){
                                        if(i+j+k == x) ans ++;
                                }
                        }
                }
                cout << ans <<endl;
        }
                
        return 0;
}




Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n;
	int m,a[10001];
	cin>>n>>m;

	ll t=0;
	rep(i,m){
		cin>>a[i];
		t+=a[i];
	}
	if(t>n)cout<<"-1"<<endl;
	else cout<<n-t<<endl;

	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <unordered_map>
 
using namespace std;
typedef long long ll;
 
int main()
{
    ll N;
    cin >> N;
    ll* v = new ll[N];
    std::unordered_map<ll, ll> map1;
    std::unordered_map<ll, ll> map2;
    for(ll i = 0; i < N; i ++){
        cin >> v[i];
    }
    for(ll i = 0; i < N; i += 2){
        try{
            map1[v[i]] = map1[v[i]] + 1;
        }
        catch(std::out_of_range&) {
            map1[v[i]] = 1;
        }
    }
    for(ll i = 1; i < N; i += 2){
        try{
            map2[v[i]] = map2[v[i]] + 1;
        }
        catch(std::out_of_range&) {
            map2[v[i]] = 1;
        }
    }
    ll max1 = 0;
    ll max1num = 0;
    ll max2 = 0;
    for(auto itr = map1.begin(); itr != map1.end(); ++itr) {
        if(itr->second > max1){
            max1 = itr->second;
            max1num = itr->first;
        }
    }
    for(auto itr = map2.begin(); itr != map2.end(); ++itr) {
        if(itr->second > max2 && itr->first != max1num){
            max2 = itr->second;
        }
    }

    ll maxtemp = N - max1 - max2;

    max1 = 0;
    ll max2num = 0;
    max2 = 0;
    for(auto itr = map2.begin(); itr != map2.end(); ++itr) {
        if(itr->second > max2){
            max2 = itr->second;
            max2num = itr->first;
        }
    }
    for(auto itr = map1.begin(); itr != map1.end(); ++itr) {
        if(itr->second > max1 && itr->first != max2num){
            max1 = itr->second;
        }
    }

    if((N - max1 - max2) > maxtemp){
        cout << maxtemp;
    }
    else{
        cout << (N - max1 - max2);
    }

    return 0;
}

Measured memory_bytes: 5132
#include<stdio.h>

int main() {
	int a,i;
	char s[100], t[100];
	scanf("%d", &a);
	scanf("%s", s);
	scanf("%s", t);
	
	
	
	for (i = 0; i < a; i++) {
		printf("%c", s[i]);
		printf("%c", t[i]);
	}
	
	return 0;
}

Measured memory_bytes: 128
#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 all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

ll a, b;
ll f(int x) {
   return (a * x) / b - a * (x / b);
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   ll a, b, n;
   cin >> a >> b >> n;

   cout << (a * min(b - 1, n)) / b << endl;
   return 0;
}

Measured memory_bytes: 3656
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
const int MAX=200005;
int n,a,b;
ll fac[MAX],finv[MAX],inv[MAX],com[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll comCalc(int n, int k){
    if(n < k) return 0;
    com[0] = 1;
    com[1] = n;
    for(int i = 2; i < MAX; i++){
        com[i] = com[i-1]*(n-i+1) % MOD;
    }
    return com[k]*finv[k] % MOD;
}
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;
}
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll ans,mi;
  cin >> n >> a >> b;
  COMinit();
  ans=(modpow(2,n,MOD)-1+MOD)%MOD;
  mi=(comCalc(n,a)+comCalc(n,b))%MOD;
  ans=(ans-mi+MOD)%MOD;
  cout << ans << endl;
}

Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest20191025
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int x = int.Parse(s[0]);
            int a = int.Parse(s[1]);

            if (x < a)
                Console.WriteLine(0);

            else
                Console.WriteLine(10);

        }
    }
}


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

using namespace std;

using int64 = long long;

int main()
{
  int N;
  string S;

  cin >> N;
  cin >> S;

  for(int i = 0; i < 2; i++) {


    for(int j = 0; j < 2; j++) {

      vector< int > x(N + 2);
      x[0] = i;
      x[1] = j;

      for(int k = 1; k <= N; k++) {
        x[k + 1] = x[k] ^ (S[k % N] == 'x') ^ x[k - 1];
      }
      if(x[0] == x[N] && x[1] == x[N + 1]) {
        for(int k = 0; k < N; k++) {
          if(x[k]) cout << "W";
          else cout << "S";
        }
        cout << endl;
        return (0);
      }
    }
  }

  cout << -1 << endl;
}

Measured memory_bytes: 1016
N, M = map(int, input().split())
X = [int(x) for x in input().split()]
X.sort()

if N >= M:
    print(0)
else:
    dX = [(i, X[i + 1] - X[i]) for i in range(M - 1)]
    dX.sort(key=lambda x: x[1], reverse=True)
    print(sum(d[1] for d in dX[N - 1:]))

Measured memory_bytes: 18388