akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n, m, k;
    cin >> n >> m >> k;
    vi a, b;
    a.resize(n);
    b.resize(m);
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, m)
    {
        cin >> b[i];
    }
    rep(i, n - 1)
    {
        a[i + 1] += a[i];
    }

    rep(i, m - 1)
    {
        b[i + 1] += b[i];
    }
    int ans = 0;
    rep(i, n)
    {
        int tmp = i + 1;
        if (a[i] > k)
            continue;
        int head = lower_bound(b.begin(), b.end(), k - a[i]) - b.begin();
        if (head < m)
        {
            if (b[head] + a[i] > k)
            {
                tmp += head;
            }
            else
            {
                tmp += head + 1;
            }
        }
        ans = max(ans, tmp);
    }
    rep(i, m)
    {
        int tmp = i + 1;
        if (b[i] > k)
            continue;
        int head = lower_bound(a.begin(), a.end(), k - b[i]) - a.begin();
        if (head < m)
        {
            if (a[head] + b[i] > k)
            {
                tmp += head;
            }
            else
            {
                tmp += head + 1;
            }
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6368
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
# define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
int main()
{
    ll u,v,n;
    cin>>n;
    ll ans=((n*(n+1))*(n+2))/6;
    for(int i=1;i<n;i++)
    {
        cin>>u>>v;
        if(u>v) swap(u,v);
        ans=ans-(u)*(n+1-v);
    }
    cout<<ans;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;

	scanf("%d",&N);

	int tmp,sum = 0,ans = BIG_NUM;

	for(int day = 1; day <= N; day++){

		scanf("%d",&tmp);
		sum += tmp;

		ans = min(ans,sum/day);
	}

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

	return 0;
}



Measured memory_bytes: 3212
t = int(input())
for _ in range(t):
    n, k = map(int, input().split())
    x = [int(y) for y in input().split()]
    d = []
    for i in range(n-1):
        d.append(x[i+1] - x[i])
    d.sort(reverse=True)
    ans = x[n-1] - x[0] - sum(d[:k-1])
    print(ans)


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

const int N = 1e6;
const int mod = 1e9 + 7;

inline int mul(int a , int b){
  return a*1ll*b%mod;
}
inline int add(int a , int b){
  a += b;
  if(a >= mod) a -= mod;
  return a;
}
inline int power(int a , int b){
  int res = 1;
  while(b){
    if(b&1)
      res = mul(res , a);
    a = mul(a , a);
    b >>= 1;
  }
  return res;
}
int fac[3*N] , inv[3*N];

int nCr(int n , int r){
  if(r > n || r < 0) return 0;
  return mul(fac[n] , mul(inv[r] , inv[n-r]));
}

int main(){
  fac[0] = 1;
  inv[0] = 1;
  for(int i = 1 ;i < 3*N ; ++i){
    fac[i] = mul(fac[i-1] , i);
    inv[i] = power(fac[i] , mod-2);
  }
  int k ;cin >> k;
  string s; cin >> s;

  int c = 0 , b = 0;
  b = s.size();
  c = 1;
  /*
   *for(int i = 1; i < s.size(); ++i){
   *    ++b;
   *}
   */
  //cout << a <<  ' ' << b << endl;

  int ans = 0;
  for(int i = 0;i <= k ; ++i){
    int coff = nCr(b+i-1 , i);
    int oth = k-i;
    int coff2 = nCr(c+oth-1 , oth);
    coff = mul(coff , power(25 , i));
    coff2 =mul(coff2 , power(26 , oth));
    ans = add(ans , mul(coff , coff2));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 28704
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
    if (b <= 0) { return 1; } if (b == 1) { return a % mod; } if (b == 2) { return (a * a) % mod; }
    return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod;
}
constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) {
    return (a * mpow(b, mod - 2, mod)) % mod;
}

int main() {
    int a, b; cin >> a >> b;
    if (10 <= a + b) {
        cout << "error" << endl;
    }
    else {
        cout << a + b << endl;
    }
}



Measured memory_bytes: 3584
from collections import namedtuple
from functools import partial
from operator import attrgetter

Path = namedtuple('Path', ('length', 'left_seat', 'right_seat'))

m = set()
f = set()


def is_suitable_path(p: 'Path', m: 'set', f: 'set') -> 'bool':
    if p.length <= 1:
        return False
    if p.length % 2 == 0:
        return (p.left_seat in m and p.right_seat in f) or (p.left_seat in f and p.right_seat in m)
    else:
        return (p.left_seat in m and p.right_seat in m) or (p.left_seat in f and p.right_seat in f)


is_suitable_path = partial(is_suitable_path, m=m, f=f)

n = int(input())

checked = [n]
x = 0
for _ in range(20):
    print(x, flush=True)

    checked.append(x)
    checked.sort()

    res = input()
    if res[0] == 'V':
        break
    else:
        if res[0] == 'M':
            m.add(x)
            if x == 0:
                m.add(n)
        else:
            f.add(x)
            if x == 0:
                f.add(n)

        t = sorted(filter(is_suitable_path,
                          (Path(length=t - s, left_seat=s, right_seat=t) for s, t in zip(checked, checked[1:]))),
                   key=attrgetter('length'))
        x = (t[0].left_seat + t[0].right_seat) // 2


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

vector<int> able;

bool func(int x){
    while(1){
        int y;
        y = x%10;
        x /= 10;
        bool flag=false;
        for(int i=0; i<able.size(); i++){
            if(y == able[i]){
                flag = true;
                break;
            }
        }
        if(!flag) return false;
        if(x==0) break;
    }
    return true;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> D(K);
    vector<int> d(10,0);    // first:0~9, second:Dkでの出現回数

    for(int i=0; i<K; i++){
        cin >> D[i];
        d[D[i]]++;
    }

    for(int i=0; i<10; i++){
        if(d[i]==0){
            able.push_back(i);
        }
    }

    for(int i=N; i<100000; i++){
        if(func(i)){
            cout << i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256
#!usr/bin/bash

read n
ok=0
for num in `seq 0 $n`
do
    if [ $(($n-${num}*4)) -ge 0 ]; then
	a=$(((($n-${num}*4)/7)*7 + $num*4))
	if [ $a -eq $n ]; then	
	    ok=1
	    break
	fi
    else
	break
    fi
    
done
if [ $ok -eq 1 ]; then
    echo "Yes"
else
    echo "No"
fi


Measured memory_bytes: 540
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
 
using namespace std;
 
 
int main(int argc, char **argv) {
    std::string s;
    cin >> s;
    cout << ((s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) ? "Bad": "Good") << endl;
 
    return 0;
}

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

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

    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }

    int ans=0;
    for (int j=0; j<n; j++) {
        if (j%2) ans -= a.at(n-1-j);
        else ans += a.at(n-1-j);
    }

    cout << ans << ' ';
    
    for (int i=0; i<n-1; i++) {
        ans = (a.at(i) - (ans/2))*2;
        cout << ans << ' ';
    }
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
using namespace std;
#define int long long
const int N=2020,INF=1e9;
int n,a[N];
int read(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
#undef int
int main()
{
	#define int long long
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read(); a[n+1]=-1; a[0]=INF;
	int now=1000,gp=0;
	for(int i=1;i<=n;i++){
		if((a[i-1]>=a[i]) && (a[i]<a[i+1]))
			gp+=now/a[i],now-=now/a[i]*a[i];
		if((a[i-1]<a[i]) && (a[i]>=a[i+1]))
			now+=gp*a[i],gp=0;
	} cout<<now+gp*a[n]<<endl;
	return 0;
}

Measured memory_bytes: 3636
w, h, x, y = map(int, input().split())

ans2 = 0
if w == 2*x:
    ans1 = x*h
    if h == 2*y and ans1==y*w:
        ans2 = 1
elif h == 2*y:
    ans1 = y*w
    if w == 2*x and ans1==x*h:
        ans2 = 1
else:
    a = -(h-2*y)/(2*x-w)
    b = -a*x+y
    ans1 = min(w*(a*w+2*b)/2, (2*h-a*w-2*b)*w/2)

print(ans1,' ',ans2)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int W = sc.nextInt();
        if(S > W){
            System.out.println("safe");
        }else{
            System.out.println("unsafe");
        }
        
    }
    
}

Measured memory_bytes: 27084
#include<cstdio>
#include<algorithm>
#define ll long long
#define mod 1000000007
using namespace std;
ll a[100010];
ll c[100010];
ll fac[100010];
ll rev[100010];
ll ch1,ch2;
ll mypow(ll x, ll y) {
	if (!y)return 1;
	if(y % 2)
		return (x*mypow(x, y - 1)) % mod;
	return mypow((x * x) % mod, y / 2) % mod;
}
int main()
{
	fac[0] = 1;
	rev[0] = 1;
	for (int i = 1; i <= 100001; i++)
	{
		fac[i] = fac[i - 1] * i;
		rev[i] = rev[i - 1] * mypow(i, mod - 2);
		fac[i] %= mod;
		rev[i] %= mod;
	}
	int n;
	scanf("%d", &n);
	n++;
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		if (c[a[i]])
		{
			ch2 = c[a[i]];
			ch1 = i;
		}
		else
		{
			c[a[i]] = i;
		}
	}
	ch2--;
	ch1 = n - ch1;
	ch2 += ch1;
	printf("%d\n", n - 1);
	for (int i = 2; i <= n; i++)
	{
		ll dap = fac[n]*rev[i];
		dap %= mod;
		dap *= rev[n - i];
		dap %= mod;
		ll ch = i - 1;
		ll gap1=0;
		if (ch2 >= ch)
		{
			gap1 = fac[ch2] * rev[ch];
			gap1 %= mod;
			gap1 *= rev[ch2 - ch];
			gap1 %= mod;
		}
		dap = (dap - gap1 + mod) % mod;
		printf("%lld\n", dap);
	}
}

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int H = reader.nextInt();
		int W = reader.nextInt();
		int h = reader.nextInt();
		int w = reader.nextInt();
		reader.close();
		int remain = H * W;
		remain -= h * W;
		H -= h;
		remain -= w * H;


		System.out.print(remain);
	}
}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

ll alph(char x){
	if (x=='a') return 0;
	else if (x=='b') return 1;
	else if (x=='c') return 2;
	else if (x=='d') return 3;
	else if (x=='e') return 4;
	else if (x=='f') return 5;
	else if (x=='g') return 6;
	else if (x=='h') return 7;
	else if (x=='i') return 8;
	else if (x=='j') return 9;
	else if (x=='k') return 10;
	else if (x=='l') return 11;
	else if (x=='m') return 12;
	else if (x=='n') return 13;
	else if (x=='o') return 14;
	else if (x=='p') return 15;
	else if (x=='q') return 16;
	else if (x=='r') return 17;
	else if (x=='s') return 18;
	else if (x=='t') return 19;
	else if (x=='u') return 20;
	else if (x=='v') return 21;
	else if (x=='w') return 22;
	else if (x=='x') return 23;
	else if (x=='y') return 24;
	else if (x=='z') return 25;
	else return 100;
}

char ralp(ll x){
	if (x==0) return 'a';
	else if (x==1) return 'b';
	else if (x==2) return 'c';
	else if (x==3) return 'd';
	else if (x==4) return 'e';
	else if (x==5) return 'f';
	else if (x==6) return 'g';
	else if (x==7) return 'h';
	else if (x==8) return 'i';
	else if (x==9) return 'j';
	else if (x==10) return 'k';
	else if (x==11) return 'l';
	else if (x==12) return 'm';
	else if (x==13) return 'n';
	else if (x==14) return 'o';
	else if (x==15) return 'p';
	else if (x==16) return 'q';
	else if (x==17) return 'r';
	else if (x==18) return 's';
	else if (x==19) return 't';
	else if (x==20) return 'u';
	else if (x==21) return 'v';
	else if (x==22) return 'w';
	else if (x==23) return 'x';
	else if (x==24) return 'y';
	else if (x==25) return 'z';
	else return '-';
}


int main(){
	string s; cin >> s;
	ll k; cin >> k;
	vector<ll> indl;
	REP(i,s.size()){
		ll y = alph(s[i]);
		if (y!=0 && k>=26-y) {
			indl.pb(0);
			k -= 26-y;
		}
		else {
			indl.pb(alph(s[i]));
		}
	}
	k %= 26;
	ll ind = s.size();
	while (k>0){
		indl[ind-1]++;
		k--;
	}
	REP(i,s.size()){
		cout << ralp(indl[i]);
	}
	cout << endl;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    if(n == 1) {
        cout << 1 << endl;
        return 0;
    }
    int ans = 0;
    int pos = 0;
    for(int i = 1; i <= n; i++) {
        int tmp = i;
        int cnt = 0;
        while(tmp % 2 == 0) {
            tmp /= 2;
            cnt++;
        }
        if(cnt > ans) {
            ans = cnt;
            pos = i;
        }
    }
    cout << pos << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

num = 0
for i in reversed(range(N)):
    res = (A[i] + num) % B[i]
    if res > 0:
        mul = int((A[i] + num) / B[i]) + 1
        sub = A[i] + num
        plus = B[i] * mul - sub
        num += plus

print(num)


Measured memory_bytes: 11052
#include <stdio.h>

int main() {
  char S[11];
  char c;

  int i = 0, j = 0;

  scanf("%s", S);

  if (S[0] != 'A') {
    printf("WA\n");
    return 0;
  }

  while ((c = S[++i]) != '\0') {
    if (c == 'C') {
      if (i == 1 || j != 0) {
        printf("WA\n");
        return 0;
      }
      j = i;
    } else if (c < 'a' || 'z' < c) {
      printf("WA\n");
      return 0;
    }
  }

  if (j == 0 || j > i - 2) {
    printf("WA\n");
    return 0;
  }
  printf("AC\n");
  return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007

#define MAXN 100000
long long inv[MAXN + 1];//MODを法とする乗法の逆元
long long fact[MAXN + 1];//階乗
long long ifact[MAXN + 1];//階乗の逆元
void init() {
	inv[1] = 1;
	for (int i = 2; i <= MAXN; i++) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
	fact[0] = ifact[0] = 1;
	for (int i = 1; i <= MAXN; i++) {
		fact[i] = i * fact[i - 1] % MOD;
		ifact[i] = ifact[i - 1] * inv[i] % MOD;
	}
}
long long C(int n, int r) {
	if (n < 0 || r < 0 || r > n)return 0;
	if (r > n / 2)r = n - r;
	return fact[n] * ifact[n - r] % MOD * ifact[r] % MOD;
}


int n, k;
int a[100000];

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

	init();

	cin >> n >> k;
	rep(i,n) {
		cin >> a[i];
	}
	sort(a, a + n);

	long long ans = 0;
	for (int i = k - 1; i < n; i++) {
		ans += a[i] * C(i, k - 1);
		ans %= MOD;
	}
	for (int i = n - k; i >= 0; i--) {
		ans -= a[i] * C(n - i - 1, k - 1);
		ans %= MOD;
	}
	ans += MOD;
	ans %= MOD;
	cout << ans << endl;


	return 0;
}

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

using ll = long long;

int main(){
	ll H,W;cin >> H >> W;
	if(H == 1 || W == 1){
		cout<<1<<endl;
		return 0;
	}
	ll ans = 0;
	ans = (H / 2 + H % 2) * (W / 2 + W % 2);
	ans += (H / 2) * (W / 2);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(H: int):
    if H == 1:
        print(1)
        return
    i = 2
    c = 3
    while True:
        i *= 2
        if i > H:
            print(c)
            break
        c = c * 2 + 1


    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    solve(H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61968
#include <stdio.h>
#include <stdlib.h>

int cmp(const void* x, const void* y) {
	int a = *(const int*)x, b = *(const int*)y;
	return a > b ? -1 : a < b;
}

int N, H;
int a[114514], b[114514];

int main(void) {
	int i;
	int furi_max = 0;
	int answer;
	int nage = 0;
	if (scanf("%d%d", &N, &H) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d%d", &a[i], &b[i]) != 2) return 1;
		if (furi_max < a[i]) furi_max = a[i];
	}
	qsort(b, N, sizeof(*b), cmp);
	answer = (H + furi_max - 1) / furi_max;
	for (i = 0; i < N; i++) {
		int candidate;
		nage += b[i];
		candidate = i + 1;
		if (H <= nage) {
			if (answer > candidate) answer = candidate;
			break;
		} else {
			candidate += ((H - nage) + furi_max - 1) / furi_max;
			if (answer > candidate) answer = candidate;
		}
	}
	printf("%d\n", answer);
	return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 339496729633

int gcd(int a, int b){return (a%b)?gcd(b, a%b):b;}

signed main(){
	int N, X;
	int xx ,  ans = INF;
	
	cin>>N>>X;
	
	
	for(int i = 1; i <= N; i++){
		cin>>xx;
		int temp = abs(X-xx);
		if(ans == INF) ans = temp;
		else if(temp%ans == 0) ;
		else  ans = gcd(temp,ans);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

// answerstring2が"第二引数"文字目から"第三引数"文字目までになる。
// 2つに分けたいときは、"第三引数"文字目までと、
//"第二引数"文字目から~に分ける。
//方法としては、第二引数=第三引数-1にする。
vector<string> split(string splitstring, int stringnum1,
                     int stringnum2) {
  vector<string> stringanswer;
  string answerstring1 = splitstring;
  string answerstring2 = splitstring;
  string answerstring3 = splitstring;
  answerstring1.erase(
      answerstring1.begin() + stringnum1 - 1,
      answerstring1.end());
  answerstring2.erase(answerstring2.begin() + stringnum2,
                      answerstring2.end());
  answerstring2.erase(
      answerstring2.begin(),
      answerstring2.begin() + stringnum1 - 1);
  answerstring3.erase(answerstring3.begin(),
                      answerstring3.begin() + stringnum2);
  stringanswer.push_back(answerstring1);
  stringanswer.push_back(answerstring2);
  stringanswer.push_back(answerstring3);
  return stringanswer;
}
// requiredstringがstringlistに含まれているかどうか
template <class T>
bool strcontain(const string stringlist,
                const T& requiredstring) {
  return stringlist.find(requiredstring) != string::npos;
}

int n, maxk;
string s[51], mother = "aiueo";

bool solve(int k);

int main() {
  int i;
  while(1) {
    cin >> n;
    if(n == 0) break;
    maxk = 0;
    for(i = 0; i < n; ++i) {
      cin >> s[i];
      maxk = max(maxk, (int)s[i].size());
    }
    for(i = 1; i <= maxk; ++i) {
      if(solve(i)) {
        cout << i << endl;
        break;
      }
      if(i == maxk) cout << -1 << endl;
    }
  }
  return 0;
}

bool solve(int x) {
  map<string, bool> mp;
  int i, j;
  for(i = 0; i < n; ++i) {
    string now;
    for(j = 0; j < s[i].size(); ++j) {
      if(j == 0)
        now += s[i][j];
      else if(strcontain(mother, s[i][j - 1]))
        now += s[i][j];
      if((int)now.size() == x) break;
    }
    if(mp.find(now)!=mp.end())return 0;
    mp[now] = 1;
  }
  return 1;
}


Measured memory_bytes: 3180
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    int sum = 0;

    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }

    Collections.sort(list);

    for(int i = 0; i < k ; i++){
        sum += list.get(i);
    }
    System.out.println(sum);

    
    

    


    
    


    


    
    


    
	}
}

Measured memory_bytes: 38792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int count = 0;
  if (N % 2 == 1) {
    for (int i = 0; i < (N-1)/2; i++) {
      if (S[i] != S[(N-1) - i]) count++;
    }
  }
  else {
    for (int i = 0; i < N/2; i++) {
      if (S[i] != S[(N-1) - i]) count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
class ModCombination
  attr_reader :fac, :inv, :finv, :mod

  MOD = 10 ** 9 + 7

  def initialize(n, mod: MOD)
    @mod = mod
    @fac = [1, 1]
    @inv = [1, 1]
    @finv = [1, 1]

    (2..n).each do |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
    end
  end

  def combination(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fac[n] * (finv[k] * finv[n - k] % mod) % mod
  end

  def repeated_combination(n, k)
    combination(n + k - 1, k)
  end
end

MOD = 998244353
N, A, B, K = gets.split.map(&:to_i)

ans = 0
mc = ModCombination.new(N + 1, mod: MOD)

0.upto(N) do |x|
  t = K - A * x
  y, m = t.divmod(B)

  next if m != 0

  ans += mc.combination(N, x) * mc.combination(N, y)
  ans %= MOD
end

puts ans


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int c[4]={10,50,100,500};
int numc[4],rest[4];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	while(1){
		memset(rest,0,sizeof(rest));
		int sum=0;
		rep(i,4){
			cin>>numc[i];
			sum+=numc[i]*c[i];
		}
		sum-=n;
		for(int i=3;i>=0;i--){
			if(sum/c[i]>0){
				rest[i]=sum/c[i];
				sum-=rest[i]*c[i];
			}
		}
		rep(i,4){
			if(numc[i]-rest[i]>0)cout<<c[i]<<" "<<numc[i]-rest[i]<<endl;
		}
		cin>>n;
		if(n==0)break;
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3032
players = Array.new(gets.to_i, 0)
m = gets.to_i
targets = gets.split.map{|n| n.to_i - 1}

m.times do |i|
  target = targets[i]
  gets.split.map{|n| n.to_i - 1}.each_with_index{|guess, j|
    guess == target ? (players[j] += 1) : (players[target] += 1)
  }
end

puts players

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

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

#define ll long long
#define ld long double

const int N = 1e5+7;

int n,m;
vector<pair<int,int>> g[N],gg[N];
int parity[N];
pair<int,int>eds[N];
bool used[N];
int up[N][20], tin[N], tout[N], T=0;
int sum[N];

void dfs(int v) {
    used[v]=1;
    tin[v] = T++;
    for (int i=1; i<20; i++) up[v][i]=up[up[v][i-1]][i-1];
    for (auto ed:g[v]) {
        if (!used[ed.x]){
            gg[v].pb(ed);
            up[ed.x][0] = v;
            dfs(ed.x);
        }
    }
    tout[v] = T;
}

void DFS(int v) {
    for (auto ed:gg[v]) {
        DFS(ed.x);
        sum[v] ^= sum[ed.x];
        if (sum[ed.x] & 1)swap(eds[ed.y].x,eds[ed.y].y);
    }
}

bool ancestor(int v, int u) {
    return tin[v] <= tin[u] && tout[v] >= tout[u];
}

int get_lca(int v, int u) {
    if (ancestor(v,u)) return v;
    if (ancestor(u,v)) return u;
    for (int i=19;i>-1;i--) {
        if (!ancestor(up[v][i],u)) v = up[v][i];
    }
    return up[v][0];
}

void query(int v, int u){
    int w = get_lca(v,u);
    sum[v] ^= 1;
    sum[u] ^= 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i=0; i<m; i++) {
        cin >> eds[i].x >> eds[i].y;
        eds[i].x--;
        eds[i].y--;
        parity[eds[i].x] ^= 1;
        g[eds[i].x].pb({eds[i].y, i});
        g[eds[i].y].pb({eds[i].x, i});
    }
    if (m&1) {
        cout << -1;
        return 0;
    }
    dfs(0);
    vector<int>ones;
    for (int i=0; i<n; i++) {
        if (parity[i]) ones.pb(i);
    }
    assert(ones.size()%2==0);
    for (int i=0; i*2+1<ones.size(); i++)query(ones[i*2],ones[i*2+1]);
    DFS(0);
    for (int i=0; i<m; i++) cout << eds[i].x+1 << " " << eds[i].y+1 << '\n';
    return 0;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 5000100, MAXK = 30;
const ll MOD = 998244353;
const int INF = 1e8;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}



int main() {
	setIO();

    ll n, k;
    cin >> n >> k;
    n %= k;
    ll ans = min(n, k-n);
    cout << ans << endl;

	return 0;
}


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

int main(){
    char set[1001];
    while(1){
        int sum = 0, i = 0;
        cin >> set;
        if(set[0]=='0') break;
        
        while(set[i]!='\0'){
            sum += set[i] - '0';
            i++;
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
ABCD = input()

for i in range(2**3):
  f = ABCD[0]
  for j in range(3):
       if ((i >> j) & 1):
        f += "-"
       else:
        f += "+"
       f += ABCD[j+1]

  if eval(f) == 7:
    print(f+"=7")
    exit()

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

int main()
{
    int n,o=0;
    cin>>n;
    long side[n],a[2]={0,0};
    for(int i=0;i<n;i++)cin>>side[i];
    if(n<4)cout<<"0";
    else{
        sort(side,side+n,greater<long>());
        for(int i=1;i<n&&o<2;i++)
        {
            if(side[i]==side[i-1])
            {
                a[o++]=side[i++];
            }
        }
        if(o==2)cout<<a[0]*a[1]<<endl;
        else cout<<"0";
    }
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF (1<<29)

const int N=100010;
int n,ans;
int d1[N],d2[N];
vi G[N];

void dfs(int u, int last, int *d){//uは現在値

    for(int i=0; i<G[u].size(); i++){
        int v=G[u][i];
        if(v==last)continue;
        d[v]=d[u]+1;
        dfs(v,u,d);
    }
}

int main(){
    scanf("%d",&n);
    for(int i=1; i<n; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1,0,d1);
    dfs(n,0,d2);

    for(int i=1; i<=n; i++){
        if(d1[i]<=d2[i])ans++;
        else ans--;
    }
    cout<<(ans>0 ? "Fennec":"Snuke")<<endl;
    return 0;
}

Measured memory_bytes: 14336
#include <numeric>
#include <vector>
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;

int main(const int args, const char* argv[])
{
    vector<double> xVec;
    vector<double> yVec;
    vector<double> deltaVec;
    int nums;
    cin >> nums;
    for(int i = 0; i < nums; i++)
    {
        double tmp;
        cin >> tmp;
        xVec.push_back(tmp);
    }
    for(int i = 0; i < nums; i++)
    {
        double tmp;
        cin >> tmp;
        yVec.push_back(tmp);
    }
    for(int i = 0; i < nums; i++)
    {
        deltaVec.push_back(abs(xVec[i] - yVec[i]));
    }
    
    for(int i = 1; i <= 3; i++)
    {
        double Total(0);
        for(auto& it:deltaVec)
        {
            Total += pow(it, i);
                
        }
        cout << setprecision(6) << fixed << pow(Total, 1/double(i)) << endl;
    }
    cout << *max_element(deltaVec.begin(), deltaVec.end()) << endl;
    

    return 0;
}


Measured memory_bytes: 3428
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string a,s,b;
    cin >>a>>s>>b;
    
    cout << a[0]<<s[0]<<b[0]<< endl;
    
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
char S[3],T[3];
int f=0;
cin>>S>>T;
if(S[0]==T[0])f++;
if(S[1]==T[1])f++;
if(S[2]==T[2])f++;
   cout<<f;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
    int n;
    cin>>n;
    V<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll sum=0;
    for(int i=2;i<n;i++)sum^=a[i];
    ll d=((a[0]+a[1])-sum)/2;
    if(d<0||(d&sum)!=0||d>a[0]||(a[0]+a[1])%2!=(sum&1)){
        cout<<-1<<"\n";
        return 0;
    }
    ll ans=d;
    for(int i=60;i>=0;i--){
        if(!(sum&(1ll<<i)))continue;
        if(ans+(1ll<<i)<=a[0])ans+=(1ll<<i);
    }
    cout<<(ans==0?-1:a[0]-ans)<<"\n";
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    map<int, bool> is_visited;
    int now = 0;
    while (true) {
        int left = (A + B) * now;
        int right = (A + B) * now + A;
        int c_pos = (left / 60) * 60 + C;
        if (is_visited[left % 60]) {
            cout << -1 << endl;
            return 0;
        }
        if (left <= c_pos && c_pos <= right) {
            cout << c_pos << endl;
            return 0;
        }
        is_visited[left % 60] = true;
        now++;
    }
    return 0;
}


Measured memory_bytes: 3212
#include <iostream>

void go(int sx, int sy, int gx, int gy) {
    while (sx < gx) {
        ++sx;
        std::cout << 'R';
    }
    while (sx > gx) {
        --sx;
        std::cout << 'L';
    }

    while (sy < gy) {
        ++sy;
        std::cout << 'U';
    }
    while (sy > gy) {
        --sy;
        std::cout << 'D';
    }
}

void solve() {
    int sx, sy, gx, gy;
    std::cin >> sx >> sy >> gx >> gy;

    go(sx, sy, gx, gy);
    go(gx, gy, sx, sy);

    go(sx, sy, sx, sy - 1);
    go(sx, sy - 1, gx + 1, gy);
    go(gx + 1, gy, gx, gy);

    go(gx, gy, gx, gy + 1);
    go(gx, gy + 1, sx - 1, sy);
    go(sx - 1, sy, sx, sy);
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
long long dp[51][51][3010] = {};
 
int main(){
	int N,A;
	cin >> N >> A;
	vector<int> X(N);
	rep(i,N) cin >> X[i];
	int M = *max_element(X.begin(),X.end());
	int sum = accumulate(X.begin(),X.end(),0);
	dp[0][0][0] = 1;
	rep(i,N){
		rep(j,N){
			rep(k,2501){
				if(dp[i][j][k]){
					dp[i+1][j][k] += dp[i][j][k];
					dp[i+1][j+1][k+X[i]] += dp[i][j][k];
				}
			}
		}
	}
	long long res=0;
	rep(i,N) res += dp[N][i+1][(i+1)*A];
	cout << res << endl;

    return 0;
}

Measured memory_bytes: 58240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll A[N];
  ll B[N];
  int halfN = N/2;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  ll ans;
  if (N % 2 == 1) {
    sort(A,A+N);
    sort(B,B+N);
    ll r = B[halfN];
    ll l = A[halfN];
    ans = r - l + 1;
  } else {
    sort(A,A+N);
    sort(B,B+N);
    ll r1 = B[halfN];
    ll l1 = A[halfN];
    ll r2 = B[halfN - 1];
    ll l2 = A[halfN - 1];
    ans = ((r1 + r2) - (l1 + l2)) + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6764
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
typedef long long int lli;

vector<lli> a_vec(MAXSIZE);

void display(lli size){
    cout << "a_vec: [";
    for(lli i = 0; i < size; ++i){
        cout << " " << a_vec[i];
    }
    cout << " ]" << endl;
}

void display_rewrite(vector<pair<lli, lli>> rewrite){
    cout << "rewrite: [";
    for(lli i = 0; i < rewrite.size(); ++i){
        cout << " (" << rewrite[i].first << ", " << rewrite[i].second << ")";
    }
    cout << " ]" << endl;
}

int main(){
    lli n, m;
    lli ans = 0;

    cin >> n >> m;
    for(lli i = 0; i < n; ++i){
        cin >> a_vec[i];
        ans += a_vec[i];
    }

    sort(a_vec.begin(), a_vec.begin() + n);
    //display(n);

    vector<pair<lli, lli>> rewrite;
    for(lli i = 0; i < m; ++i){
        lli b, c;
        cin >> b >> c;
        pair<lli, lli> rewrite_add = make_pair(c, b); // (書き換え後の数, 書き換える最大個数)
        rewrite.push_back(rewrite_add);
    }

    sort(rewrite.begin(), rewrite.end(), greater<pair<lli, lli>>());
    //display_rewrite(rewrite);

    lli cnt = 0;
    lli rewrite_index = 0;
    for(lli i = 0; i < n; ++i){
        if(a_vec[i] >= rewrite[rewrite_index].first){
            break;
        }

        if(rewrite_index == rewrite.size()){
            break;
        }

        ans -= a_vec[i];
        a_vec[i] = rewrite[rewrite_index].first;
        ans += rewrite[rewrite_index].first;
        cnt++;

        if(cnt == rewrite[rewrite_index].second){
            cnt = 0;
            rewrite_index++;
        }
    }

    //display(n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>

#include <string>

using std::cin;
using std::cout;
using std::endl;

using std::string;

int
main()
{
  string S;
  cin >> S;
  cout << 700 + 100 * ((S[0] == 'o') + (S[1] == 'o') + (S[2] == 'o')) << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
mod = 10**9 + 7
memo = [{}for i in range(n+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1],t[i] = t[i],t[i-1]
        if ''.join(t).count('AGC') >= 1:
                return False
    return True

def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == n:
        return 1
    ret = 0
    for i in 'ACGT':
        if ok(last3 + i):
            ret = (ret + dfs(cur+1,last3[1:]+i)) % mod
    memo[cur][last3] = ret
    return ret
print(dfs(0,'   '))

Measured memory_bytes: 3812
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

// 200000*7
#define BUF_SIZE 1500000

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define NUM_MAX 200000

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX+1];
    fget_array(arr, num);
    static int map[NUM_MAX+1];

    int i, j;
    for(i = 0; i < num; i++) {
        map[arr[i]]++;
    }

    static uint64_t base[NUM_MAX];
    uint64_t base_sum = 0;
    for(i = 1; i <= NUM_MAX; i++) {
        uint64_t cnt = map[i];
        base[i] = cnt * (cnt-1) / 2;
        base_sum += base[i];
    }
#ifdef DEBUG
    printf("%d\n", base_sum);
#endif

    for(i = 0; i < num; i++) {
        int cnt = map[arr[i]];
        // n*(n-1)/2 - (n-1)*(n-2)/2 = (n-1)
        uint64_t res = base_sum - (cnt-1);
        printf("%llu\n", res);
    }
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int k;
    cin >> k;
    int A = 60 * a + b;
    int B = 60 * c + d;
    if (B < A)
    {
        B += 60 * 24;
    }
    int sum = B - A;
    int ans = sum - k;
    cout << ans << endl;
    return 0;
}


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

const int nax = 10005;
const int mod = 1e9+7;

// std::vector<char> v(nax, nax);
char sl[nax][nax];

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

void print(std::vector<std::vector<int> > A){
	for(int i = 0; i<A.size(); i++){
		for(int j = 0; j<A[i].size(); j++){
			cout<<A[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
}

int main(){
	int h, w;
	cin>>h>>w;

	for(int r = 0; r<h; ++r){
		scanf("%s", sl[r]);
	}

	vector<vector<int>> dp(h, vector<int>(w));
    dp[0][0] = 1;

    for(int row = 0; row < h; ++row) {
        for(int col = 0; col < w; ++col) {
            for(int r2 : {row, row + 1}) {
            	// cout<<"r2: "<<r2<<endl;
                int c2 = col;
                if(r2 == row) {
                    c2 = col + 1;
                    // cout<<"r2: "<<r2<<"c2: "<<c2<<endl;
                }
                if(r2 < h && c2 < w && sl[r2][c2] == '.') {
                    add_self(dp[r2][c2], dp[row][col]);
                    // cout<<dp[r2][c2]<<" "<<dp[row][col]<<endl;
                    // print(dp);
                }
            }
        }
        // print(dp);
    }
    // print(dp);
    printf("%d\n", dp[h-1][w-1]);

}

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

int main() {
  int A, B, ans;
  char op;
  cin >> A >> op >> B;
  
  if (op == '+') {
    ans = A+B;
  }
  else {
    ans = A-B;
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
    string s,t;

    cin>>s>>t;

    int ans=t.size();

    for(int i=0;i<=s.size()-t.size();i++){
        int diff=0;
        for(int j=0;j<t.size();j++){
            if(t[j]!=s[i+j]){
                diff++;
            }
        }
        ans=min(diff,ans);
    }

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define mp make_pair

vector<vector<pair<ll,ll>>> out(1e5);
vector<vector<ll>> in(1e5);
ll inf=1e18;
ll p=1e9+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,i,j,t,a,b,temp,m,k,x,y,ctr;
	ld r;
	cin>>n>>m;
	ll sum=0;
	for(i=0;i<m;i++)
	{
	    cin>>x;
	    sum+=x;
	}
	if(sum>n)
	cout<<"-1";
	else
	cout<<n-sum;

	return 0;
	
	
}


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

#define DEBUG(x) 			   cout << '>' << #x << ':' << x << endl;
#define D(x)        		   cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         		   cerr << __LINE__ << ": Hi" << '\n'
#define fresh                  {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define read                   freopen("in.txt","rt",stdin)
#define write                  freopen("out.txt","wt",stdout)
#define PI                     3.1415926535897932384626433832795
#define mems(ds_name,val)      memset(ds_name,val,sizeof(ds_name))
#define ll					   long long

int main()
{
    fresh;
//    read;
	//write;

    int t;
    cin>>t;
    if(t==1)cout<<"Hello World\n";
    else{
        int x,y;cin>>x>>y;
        cout<<x+y<<endl;
    }

}






Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

if N == 1:
    print("Yes")
else:
    f = 1
    for i in range(1, N-1):
        if H[-i-1] <= H[-i]:
            continue
        elif H[-i-1]-1 == H[-i]:
            H[-i-1] -= 1
        else:
            f = 0
            break
    if f:
        print("Yes")
    else:
        print("No")


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

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

int main() {
  int MAX = (int)1e6;
  vector<int> Prime(MAX+1, 0);

  for (int i = 2; i <= sqrt(MAX); i++) {
    if (Prime[i] == 0) {
      for (int j = 2; j <= MAX; j++) {
        if (i * j > MAX) break;
        if (Prime[i * j] == 0)
        Prime[i * j] = -1;
      }
    }
  }
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N){
      cin >> A[i];
  }
  vector<int> P;
  for (int i = 2; i <= MAX; i++) {
    if (Prime[i] != -1) P.push_back(i);
  }
  vector<bool> check((int)1e6 + 1, false);
  bool flag = true;
  int allgcd = A[0];
  for(auto x : A){
    allgcd = gcd(allgcd, x);
    // xを素因数分解する
    vector<int> num;
    for(int j = 0; Prime[x] == -1; j++){
      if(x % P[j] == 0){
        num.push_back(P[j]);
        while(x % P[j] == 0) x /= P[j];
      }
    }
    if(x != 1)num.push_back(x);
    for(auto y : num){
      if(!check[y]){
        check[y] = true;
      }
      else{
        flag = false;
        break;
      }
    }
    num.clear();
  }
  if(flag){
    cout << "pairwise coprime" << "\n";
  }
  else if(allgcd == 1){
    cout << "setwise coprime" << "\n";
  }
  else{
    cout << "not coprime" << "\n";
  }
  return 0;
}

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

typedef long long ll;

int n,k;
int h[200005];
ll ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>h[i];
    sort(h,h+n);
    for(int i=0;i<n-k;i++){
        ans+=h[i];
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <set>
#include <iostream>
#include <cassert>
#include <queue>
using namespace std;


int main() {
    int N = 0;
    long long M = 0;
    cin >> N >> M;
    vector<int> A;
    int val = 0;
    for (int i = 0; i < N; ++i) {
        cin >> val;
        A.push_back(val);
    }
    sort(A.begin(), A.end());
    int low = 0, high = 200001;
    //找到最小的 k, 使得 happiness > k 的 组合数 < M.
    while (low < high) {
        int mid = (low + high) / 2;
        long long cnt = 0;
        int i = 0, j = N-1;
        while (i < N) {
            while (j >= 0 && A[i] + A[j] > mid) j--;
            cnt += N - j - 1;
            i++;
        }
        // cnt 与 mid 成反比
        if (cnt >= M) {
            low = mid + 1;
        } else {
            high = mid;
        }
    }
    int k = low;
    long long ans = 0;
    int i = 0, j = N-1;
    long long pre = 0;
    long long cnt = 0;
    while (i < N) {
        while (j >= 0 && A[i] + A[j] > k) {
            pre += A[j--];
        }
        long long t = N-j-1;
        cnt += t;
        ans += pre + t * A[i];
        i++;
    }
    ans += (M - cnt) * k;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 892
X,Y,T[90][90],r;
R(x,y,d){
	if(0<=x&&x<X&&0<=y&&y<Y&&T[y][x]){
		T[y][x]=0;
		R(x-1,y,d+1);
		R(x+1,y,d+1);
		R(x,y-1,d+1);
		R(x,y+1,d+1);
		T[y][x]=1;
	}else if(r<d)r=d;
}
main(i,j){
	for(;scanf("%d%d",&X,&Y),X;printf("%d\n",r)){
		for(j=0;j<Y;j++)for(i=0;i<X;i++)scanf("%d",T[j]+i);
		for(r=j=0;j<Y;j++)for(i=0;i<X;i++)R(i,j,0);
	}
}

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

int main(){
    int a,b,n ;
    cin >> a >> b >> n ;
    int c = (n+499)/500 ;
    if(a<b){
        cout << (c+1)/2*a << endl ;
    }else if(a<b*2){
        cout << (c/2)*a+(c%2)*b << endl ;
    }else{
        cout << c*b << endl ;
    }
}


Measured memory_bytes: 3132