akhauriyash/Code-Regression huggingface dataset:
mod = 10**9 + 7
N = 2002
f = [1]*N

for i in range(1,N):
    f[i] = (i*f[i-1])%mod

def mod_inv(x):
    return pow(x,mod-2,mod)

def C(n,k):
    return (f[n] * mod_inv(f[k]) * mod_inv(f[n-k]))%mod

n,k = map(int,input().split())
for i in range(k):
    ans = 0
    if n-k >= i:
        rem = n-k-i
        ans = C(k-1,i)*C(rem+i+1,rem)
    print(ans%mod)


Measured memory_bytes: 3444
#include<cstdio>
#include<cmath>
int main(){
  int n;
  while(scanf("%d",&n) && n){
    int s[1000]={},sum=0;
    for(int i=0;i<n;i++){
      scanf("%d",&s[i]);
      sum += s[i];
    }
    double m = (double)sum / (double)n,ssum=0;
    for(int i=0;i<n;i++) ssum += pow((s[i]-m),2);
    printf("%.7f\n",sqrt(ssum/(double)n));
  }
}


Measured memory_bytes: 2596
using System;

public class Test
{
	public static void Main()
	{
            int i = 1; 
            int x = 0;
            while (true)
            {
                x = int.Parse(Console.ReadLine());
                if (x==0) {
                    break;
                }
                else
                {
                    Console.WriteLine("Case {0}: {1}",i,x);
                    i =i+1;
                }
            }

	}
}

Measured memory_bytes: 9324
#include <stdio.h>

int b[100000], b_tmp[100000];

int main() {

    int i, n, m, cnt, is_tri_num;
    while ( scanf("%d", &n) == 1 && n != 0 ) {

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

	cnt = 0;
	while ( cnt <= 10000 ) {
	
	    //三角形になっているか
	    is_tri_num = 1;
	    if ( b[0] != 1 ) is_tri_num = 0;
	    for ( i=1; i<n; ++i ) {
		if ( b[i] != b[i-1]+1 ) {
		    is_tri_num = 0;
		    break;
		}
	    }
	    if ( is_tri_num ) break;

	    m = 0;
	    for ( i=0; i<n; ++i ) {
		if ( b[i] > 1 ) {
		    b_tmp[m] = b[i] - 1;
		    ++m;
		}
	    }

	    for ( i=0; i<m; ++i ) b[i] = b_tmp[i];
	    b[m] = n;

	    n = m + 1;
	    ++cnt;
	}

	if ( cnt > 10000 ) printf("-1\n");
	else printf("%d\n", cnt);
    }

    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
 
const int Inf = 100000;
const int mod = 1e9 + 7;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
 
int h, w, a, b;
long long ans = 0;
long long Fact[500005], iFact[500005];
 
long long BinPow(long long n, int k)
{
	if(k == 0)
	{
		return 1;
	}
	long long temp = BinPow(n, k >> 1);
	if(k % 2 == 0)
	{
		return temp * temp % mod;
	}
	else
	{
		return temp * temp % mod * n % mod;
	}
}
 
long long C(int k, int n)
{
	if(n < k or k < 0)
	{
		return 0;
	}
	return Fact[n] * iFact[k] % mod * iFact[n - k] % mod;
}
 
signed main()
{
	Fact[0] = 1;
	for(int i = 1; i <= 500000; i++)
	{
		Fact[i] = Fact[i - 1] * i % mod;
	}
	iFact[500000] = BinPow(Fact[500000], mod - 2);
	for(int i = 499999; i >= 0; i--)
	{
		iFact[i] = iFact[i + 1] * (i + 1) % mod;
	} 
	cin >> h >> w >> a >> b;
	for(int i = h - a; i >= 1; i--)
	{
		ans += C(i - 1, i + b - 2) * C(h - i, h - i + w - b - 1) % mod;
		ans %= mod;
	}
	cout << ans;
}

Measured memory_bytes: 11448
// AOJ 	2168 Luigi's Tavern
// 2018.3.12 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*******************************************/
/* Dinic's Max Flow Algorithm 
/*******************************************/

#define INF 0x01010101
#define VMAX 410
typedef struct { int to; int cap; int rev; } EDGE;
EDGE edge[VMAX][VMAX]; int hi[VMAX];
int V;				// 頂点数
int level[VMAX], iter[VMAX];
int queue[2*VMAX], qtop;

void add_edge(int from, int to, int cap)
{
	int f, t;
	EDGE *e;

	f = hi[from]++, t = hi[to]++;
	e = &edge[from][f], e->to = to, e->cap = cap, e->rev = t; 
	e = &edge[to][t], e->to = from, e->cap = 0, e->rev = f;
}

void bfs(int s)
{
	int i, v;
	EDGE *e;
	
	memset(level, -1, V << 2);
	level[s] = 0;
	queue[0] = s, qtop =1;
	while (qtop) {
		v = queue[--qtop];
		for (i = 0; i < hi[v]; i++) {
			e = &edge[v][i];
			if (e->cap > 0 && level[e->to] < 0) {
				level[e->to] = level[v] + 1;
				queue[qtop++] = e->to;
			}
		}
	}
}
 
int dfs(int v, int t, int f)
{
	int *i, d;
	EDGE *e;
	
	if (v == t) return f;
	for (i = &iter[v]; *i < hi[v]; (*i)++) {
		e = &edge[v][*i];
		if (e->cap > 0 && level[v] < level[e->to]) {
			d = dfs(e->to, t, f <= e->cap? f: e->cap);
			if (d > 0) {
				e->cap -= d;
				edge[e->to][e->rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
 
int maxFlow(int s, int t)
{
	int f, flow = 0;
	while (1) {
		bfs(s);
		if (level[t] < 0) break;
		memset(iter, 0, V << 2);
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
	return flow;
}

/**********************************************/

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	if (c == '-') {	c = getchar_unlocked();
		do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int H, W, C, M, NW, NC, NM, i, k;
	int n, nw, nc, nm, N, source, sink;

	while ((H = in()) >= 0) {
		W = in(), C = in(), M = in();
		NW = in(), NC = in(), NM = in();

		n = H+W+C+M, nw = n, nc = n+1, nm = n+2, N = n+3;
		source= 2*N, sink = source+1, V = sink+1;
		memset(hi, 0, V << 2);

		for (i = 0; i < H; i++) add_edge(source, N+i, 1);
		for (i = 0; i < n; i++) add_edge(N+i, i, 1);
		add_edge(N+nw, nw, NW), add_edge(N+nc, nc, NC), add_edge(N+nm, nm, NM);
		for (i = 0; i < H; i++) add_edge(i, N+nw, 1);
		for (i = 0; i < W; i++) {
			k = in(); while (k--) add_edge(in()-1, N+H+i, 1);
			add_edge(H+i, N+nc, 1);
		}
		for (i = 0; i < C; i++) {
			k = in(); while (k--) add_edge(in()-1+H, N+H+W+i, 1);
			add_edge(H+W+i, N+nm, 1);
		}
		for (i = 0; i < M; i++) {
			k = in(); while (k--) add_edge(in()-1+H+W, N+H+W+C+i, 1);
			add_edge(H+W+C+i, sink, 1);
		}
		for (i = 0; i < C; i++) add_edge(nw, N+H+W+i, 1);
		for (i = 0; i < M; i++) add_edge(nc, N+H+W+C+i, 1);
		add_edge(nm, sink, NM);

		printf("%d\n", maxFlow(source, sink));
	}
	return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int calculate_digits_total(int x) {
	int digits_total = 0;
	while (x) {
		digits_total += x % 10;
		x /= 10;
	}

	return digits_total;
}


int main(void) {
	int N, A, B;
	cin >> N >> A >> B;

	int sum = 0;
	for (int i = 1; i <= N; i++) {
		int digits_total = calculate_digits_total(i);
		if (A <= digits_total and B >= digits_total) {
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

void solve()
{
    int N,M;
    cin >> N >> M;
    map<int,pair<int,bool>> m;
    int tmp;
    string tmps;
    int account = 0;
    int penacount = 0;
    for(int i = 0;i < M;i++)
    {
        cin >> tmp >> tmps;
        if(m.count(tmp) == 0)
        {
            if(tmps == "AC")
            {
                m.insert(make_pair(tmp,make_pair(0,false)));
                account++;
            }
            else
            {
                m.insert(make_pair(tmp,make_pair(1,true)));
            }
        }
        else
        {
            if(!m[tmp].second)
                continue;
            
            if(tmps == "AC")
            {
                m[tmp].second = false;
                penacount += m[tmp].first;
                account++;
            }
            else
            {
                m[tmp].first++;
            }
        }
    }
    cout << account << " " << penacount << '\n';
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 6528
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t R, G, B, N;

    scanf("%zu %zu %zu %zu", &R, &G, &B, &N);

    size_t cnt = 0;

    for (size_t numR = 0; numR <= N / R; numR++) {
        for (size_t numG = 0; numG <= (N - R * numR) / G; numG++) {
            if ((N - R * numR - G * numG) % B == 0) {
                cnt++;
            }
        }
    }

    printf("%zu", cnt);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 print(s) cout << s << endl
using namespace std;
const int INF = 1e9;
typedef long long ll;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}


int main() {
	int n,l; cin >> n >> l;
	vector<string> v(n);
	rep(i,n){
		cin>>v[i];
	}
	sort(all(v));
	rep(i,n){
		cout<<v[i];
	}
}


Measured memory_bytes: 256
"use strict";

function main(input) {
  var lines = input.split('\n');
  var N = parseInt(lines[0]);
  var as = splitNum(lines[1]).slice(0, N);
  var ads = as.map(function (a, i) {
    return a - i - 1;
  });
  ads.sort(function (a, b) {
    return a - b;
  });
  var med = ads[Math.floor(ads.length / 2)];
  var min = ads.map(function (ad) {
    return Math.abs(ad - med);
  }).reduce(function (a, b) {
    return a + b;
  }, 0);
  console.log(min);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 39768
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 14 10:14:13 2018
ALDS1_11_D
@author: maezawa
"""
import sys
sys.setrecursionlimit(1000000)

n, m = list(map(int, input().split()))
v = [-1 for _ in range(n)]
stack = []
adj = [[] for _ in range(n)]
for i in range(m):
    s, t = list(map(int, input().split()))
    adj[s].append(t)
    adj[t].append(s)
#print(*adj, sep='\n')
def dfs(u, color):
    if v[u] > 0:
        return 0
    v[u] = color
    #print(u, current, stack)
    for k in adj[u]:
        if v[k] > 0:
            continue
        dfs(k, color)
    return 1

color = 1
for start in range(n):
    if dfs(start, color) == 1:
        color += 1
#for i in range(n):        
#    print('color:{} for node:{}'.format(i, v[i]))

q = int(input())
for i in range(q):
    s, t = list(map(int, input().split()))
    if v[s] == v[t]:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 126980
N = gets.to_i
H = gets.split.map(&:to_i)
L = [0]

crn = 0
(1...N).each do |i|
  if H[i-1] >= H[i]
    L[crn] += 1
  else
    crn += 1
    L << 0
  end
end
p L.max

Measured memory_bytes: 8964
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    int num[3];
    int c5 = 0;
    int c7 = 0;

    for(int i=0;i < 3;i++) cin>>num[i];

    for(int i=0;i < 3;i++){
        if(num[i] == 5) c5++;
        if(num[i] == 7) c7++;
    }

    if(c5 == 2 && c7 == 1) cout<<"YES\n";
    else cout<<"NO\n";

}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[5],b[5],sum=0,flag=0;
	memset(b,0,sizeof(b));
	for(int i=0;i<5;i++) cin>>a[i],b[i]=a[i]%10;
	for(int i=0;i<5;i++)
	{
		if(b[i]==0) continue;
		else
		{
			if(b[i]<=b[flag]) flag=i;
			else continue;
		}
	}
	for(int i=0;i<5;i++)
	{
		if(i==flag) sum+=a[flag];
		else if(b[i]==0) sum+=a[i];
		else sum+=(a[i]+10)/10*10;
	}
	cout<<sum;
	return 0;
}

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

int main()
{
    long long int  n;
    cin>>n;
    long long int  hi[n];

    for(int i=0; i<n; i++)
    {
        cin>>hi[i];
    }
    long long int  ans[n];
    ans[0] = 0;
    ans[1] = abs(hi[1] - hi[0]);
    for(int i=2; i<n; i++)
    {
        ans[i] =  min(ans[i - 2]   + abs(hi[i] - hi[i - 2]),ans[i - 1] + abs(hi[i] -hi[i - 1]));

    }
    cout<<ans[n-1];
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = sc.nextInt();
		// 文字列の入力
		int max = a;
		
		if(max < b){
			max = b;
		}
		if(max < c){
			max = c;
		}
		
		// 出力
		int total = a + b + c;
		if(max == total - max){
		System.out.println("Yes");
	}else{
		System.out.println("No");
	}
}
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

int dp[10001];

void solve() {
  rep(i, 10001) dp[i] = 1e9;
  int h, n;
  cin >> h >> n;
  dp[h] = 0;
  rep(_, n) {
    int a, b;
    cin >> a >> b;
    rreps(i, h) {
      amin(dp[max(0, i - a)], dp[i] + b);
    }
  }
  cout << dp[0] << endl;
}


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

typedef pair<int, int> Pii;

void readline(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readline(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}

signed main(){

    int X;
    cin >> X;
    
    int ans = 1;

    FOR(i, 2, 100){
        int tmp = i * i;
        while(tmp <= X){
            if(tmp > ans) ans = tmp;
            tmp *= i;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;



int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


int point[100];
int N;
ll ans = 0;
int main() {
	cin >> N;

	REP(i, N) {
		cin >> point[i];
		ans += point[i];
	}

	SORT(point, N);

	REP(i, N) {
		if (ans % 10 != 0) {
			cout << ans << endl;
			return 0;
		}
		else if(point[i]%10!=0)ans -= point[i];
	}
	cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                      
using namespace std;
int main()
{
  int N,M,C;
  cin >> N;
  cin >> M;
  cin >> C;
  vector<int> B(M);
  for(int i=0; i<M; i++)
    cin >> B.at(i);
  vector<vector<int>> A(N, vector<int>(M));
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
      cin >> A.at(i).at(j);
    }
  }
  int count=0;
  int sum=0;
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
      sum+=B.at(j)*A.at(i).at(j);
      if(j==M-1)
        sum+=C;
    }
    if(sum>0)
      count++;
    sum=0;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    String s = sc.next();
    
    String a = s.substring(0,k-1);
    String b = s.substring(k-1,k).toLowerCase();
    String c = s.substring(k,n);
    
    System.out.println(a+b+c);
  }
}

Measured memory_bytes: 21844
from collections import Counter

class Prime:
    def __init__(self, N):
        smallestPrime = [i for i in range(N + 1)]

        for i in range(2, N + 1):
            if smallestPrime[i] != i:
                continue
            for p in range(i * 2, N + 1, i):
                if smallestPrime[p] == p:
                    smallestPrime[p] = i

        self.smallestPrime = smallestPrime

    def isPrime(self, n):
        return n > 1 and self.smallestPrime[n] == n

    def factorization(self, n):
        ret = Counter()
        while True:
            p = self.smallestPrime[n]
            if p == 1:
                break
            ret[p] += 1
            n //= p
        return ret

from math import gcd

N = int(input())
A = list(map(int, input().split()))
primeFactorization = Prime(max(A) + 10).factorization

def isSetwise(A):
    ret = A[0]
    for a in A:
        ret = gcd(ret, a)
    return ret == 1

def isPairwise(A):
    P = Counter()
    for a in A:
        for p in primeFactorization(a):
            if P[p] >= 1:
                return False
            P[p] += 1
    return True

if not isSetwise(A):
    print('not coprime')
    exit()

if isPairwise(A):
    print('pairwise coprime')
else:
    print('setwise coprime')


Measured memory_bytes: 133088
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
const int MAX_H = 2000;
const int MAX_W = 2000;
int S[MAX_W][MAX_H];
int w[MAX_W][MAX_H];
int h[MAX_W][MAX_H];

int main(void){
    int H, W;
    cin >> H >> W;
    int idx = 0;

    rep(i, H){
        string s;
        cin >> s;
    
        rep(j, W){
            if(s[j] == '#')
                S[j][i] = 0;
            else
                S[j][i] = 1;
            }
    }

    rep(i, H){
        int start = 0;
        int end = 0;
        rep(j, W){
            if (S[j][i] && j != W - 1){
                end ++;
            }
            else{
                For(k, start, end){
                    w[k][i] = end - start + S[j][i];
                }
                w[end][i] = (end - start + S[j][i]) * S[j][i];
                end ++;
                start = end;
            }
    }
    }

    rep(j, W){
        int start = 0;
        int end = 0;
        rep(i, H){
            if (S[j][i] && i != H - 1){
                end ++;
            }
            else{
                For(k, start, end){
                    h[j][k] = end - start + S[j][i];
                }
                h[j][end] = (end - start + S[j][i]) * S[j][i];
                end ++;
                start = end;
            }
    }
    }

    int max_light = 0;

    rep(i, H){
        rep(j, W){
        max_light = max(max_light, w[j][i] + h[j][i] - 1);        
    }
    }

    cout << max_light << endl;
    
    return 0;
}

Measured memory_bytes: 47232
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll mod = 1000000007;
ll minsum(ll k){
  return k*(k-1)/2;
}
ll maxsum(ll n, ll k){
  ll res = n*k;
  res -= k*(k-1)/2;
  return res;
}

int main(){
  ll N, K;
  cin >> N >> K;

  ll ans = 0;
  for(ll k=K;k<=N+1;k++){
    ans += maxsum(N, k) - minsum(k) + 1;
    ans %= mod;
  }

  cout << ans <<endl;

    
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 110;

typedef struct UnionFindTree{
    vector<int> par;

    UnionFindTree(int n){
        par.resize(n, -1);
    }

    bool is_root(int x){
        return par[x]<0;
    }

    int find(int x){
        if(is_root(x)) return x;
        return par[x] = find(par[x]);
    }

    int size(int x){
        return -par[find(x)];
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
}UF;

int n;
int l[55], t[55], r[55], b[55];
vector<int> vx, vy;

int x_id(int x){
    return lower_bound(vx.begin(), vx.end(), x) - vx.begin();
}

int y_id(int y){
    return lower_bound(vy.begin(), vy.end(), y) - vy.begin();
}

void solve(){
    vx.clear();
    vy.clear();

    rep(i, n){
        scanf("%d%d%d%d", &l[i], &t[i], &r[i], &b[i]);
        vx.push_back(l[i]); vx.push_back(r[i]);
        vy.push_back(t[i]); vy.push_back(b[i]);
    }
    vx.push_back(-1); vx.push_back(mod);
    vy.push_back(-1); vy.push_back(mod);
    sort(vx.begin(), vx.end());
    vx.erase(unique(vx.begin(), vx.end()), vx.end());
    sort(vy.begin(), vy.end());
    vy.erase(unique(vy.begin(), vy.end()), vy.end());

    int h = vx.size(), w = vy.size();
    lint color[h][w];
    rep(i, h)rep(j, w) color[i][j] = 0;
    rep(i, n){
        color[x_id(l[i])][y_id(b[i])] ^= (1LL << i);
        color[x_id(l[i])][y_id(t[i])] ^= (1LL << i);
        color[x_id(r[i])][y_id(b[i])] ^= (1LL << i);
        color[x_id(r[i])][y_id(t[i])] ^= (1LL << i);
    }
    rep(i, h)rep(j, w - 1) color[i][j + 1] ^= color[i][j];
    rep(j, w)rep(i, h - 1) color[i + 1][j] ^= color[i][j];

    UF uf(h * w);
    int ans = h * w;
    rep(x, h)rep(y, w){
        if(x + 1 < h && color[x][y] == color[x + 1][y]){
            ans -= uf.unite(x * w + y, (x + 1) * w + y);
        }
        if(y + 1 < w && color[x][y] == color[x][y + 1]){
            ans -= uf.unite(x * w + y, x * w + y + 1);
        }
    }
    printf("%d\n", ans);
}

int main(){
    while(scanf("%d", &n) && n){
        solve();
    }
}


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long llong;

llong N;
llong cnt = 0;
void func(llong cur, int use) {
    if(cur > N) return;
    if(use == 0b111) ++cnt;

    func(cur*10+7, use | 0b100);
    func(cur*10+5, use | 0b010);
    func(cur*10+3, use | 0b001);
}

int main() {
    cin >> N;
    vector<int> v;
    func(0, 0);
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int N = sc.nextInt();
		if (N == 1) {
			System.out.println ("Hello World");
		} else {
			int A = sc.nextInt(), B = sc.nextInt();
			System.out.println(A + B);
		}
	}
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline

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

mass = [0]*(N+1)
for i in range(N):
    mass[i+1] = mass[i] + A[i]

answer = 0
for i in range(N-1):
    answer += (A[i]*(mass[N]-mass[i+1]))


print(answer % (10**9 + 7))

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = a * x + b * y;

  ans = min(ans, 2 * c * max(x, y));
  if (x < y)
    ans = min(ans, 2 * c * x + b * (y - x));
  else
    ans = min(ans, 2 * c * y + a * (x - y));
  cout << ans << '\n';
  return 0;
}


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

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

int main(){
    int N;
    long long p, n;
    cin >> N;

    cin >> p;
    for (int i = 1; i < N; ++i){
        cin >> n;
        long long g = gcd(p, n);
        p = p / g * n; 
    }
    cout << p << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    const int INF = 10000000;
    vector<int> a;
    a.pb(-INF);
    rep(i,m){
        int v;
        cin >>v;
        a.pb(v);
    }
    a.pb(INF);

    int idx = 0;
    int ans = 0;
    for(int i=1; i<=n; ++i){
        ans = max(ans, min(i-a[idx], a[idx+1]-i));
        if(a[idx+1] == i) ++idx;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3272
/*      ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     */

// Author : Udit "luctivud" Gupta @ (https://www.linkedin.com/in/udit-gupta-1b7863135/)


#include <bits/stdc++.h>
#pragma GCC optimize "trapv"

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;


#define       TESTCASES()  cin >> (T3X0); T353 = T3X0; while(T3X0--)
#define       _input(V3C)  for(auto &V3C_I7 : (V3C)) cin >> (V3C_I7)
#define mems(A77AY, V4LU)  memset((A77AY), (V4LU), sizeof((A77AY)))
#define  CH3K(I7, E4, S7)  (((S7)<0) ? (I7)>(E4) : (I7)<(E4))
#define for4(I7,S4,E4,S7)  for(auto I7=(S4); CH3K(I7,E4,S7); (I7)+=(S7))




void solveEachTest(lld T35TC453N = 1) {
    int ans = 0;
    int n ; cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i < n; i++) {
        set <char> se;
        se.insert(a[i]);
        se.insert(b[i]);
        se.insert(c[i]);
        ans += (se.size() - 1);
    }
    cout << ans;
    cout << "\n";

    return;
}


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

    lld T3X0 = 0, T353 = 1;

    // TESTCASES()
    solveEachTest(T353 - T3X0);
    return 0;
}


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

using namespace std;

int main() {
	int n, m, X, Y;
	vector<int> x(100, -99999), y(100, 99999);
	cin >> n >> m >> X >> Y;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> y[i];
	}
	int xm = *max_element(x.begin(), x.end()), ym = *min_element(y.begin(), y.end());
	if (xm < ym && X < ym && Y > xm) {
		cout << "No War";
	} else {
		cout << "War";
	}
	
	
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	int x, y;
	cin >> x >> y;
	bool ans;
	if (x == y) {
		ans = true;
	}
	else {
		if (x == 2 || y == 2) {
			ans = false;
		}
		else if (x == 4 || x == 6 || x == 9 || x == 11) {
			if (y == 4 || y == 6 || y == 9 || y == 11) {
				ans = true;
			}
			else {
				ans = false;
			}
		}
		else {
			ans = !(y == 4 || y == 6 || y == 9 || y == 11);
		}
	}
	Yes(ans);
	return 0;
}


Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s1, s2, s3 = input().split()
    print(chr(ord('A') + ord(s1[0]) - ord('a')), end = '')
    print(chr(ord('A') + ord(s2[0]) - ord('a')), end = '')
    print(chr(ord('A') + ord(s3[0]) - ord('a')), end = '')

solve()


Measured memory_bytes: 3060
/*input
4 2
4 2 3 1

*/

// spoiled

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <numeric>
#include <climits>
#include <fstream>
#include <queue>
#include <bitset>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORA(i, a) for (auto &i : a)
#define FORB(i, a, b) for (int i = a; i >= b; --i)
#define SZ(a) ((int) a.size())
#define ALL(a) begin(a), end(a)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fi first
#define se second

// start of code

const int MAXN = 500010, LOG = 20;

int fenwick[MAXN];
void upd(int i, int x) { for (; i < MAXN; i += i & -i) fenwick[i] += x; }
int get(int i) { int ans = 0; for (; i; i -= i & -i) ans += fenwick[i]; return ans; }
int sch(int x)
{
	int i = 0;
	for (int lg = LOG - 1; lg >= 0; --lg) {
		if (i + (1 << lg) < MAXN && fenwick[i + (1 << lg)] < x) i += 1 << lg, x -= fenwick[i];
	}
	return i + 1;
}

int N, K;
int outDeg[MAXN], P[MAXN], I[MAXN];
priority_queue<int> pq;
vector<int> rG[MAXN];

signed main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> N >> K;

	for (int i = 0; i < N; ++i) {
		cin >> P[i];
		I[P[i]] = i;
		
		upd(P[i], 1);
		if (i >= K) upd(P[i - K], -1);

		int rnk = get(P[i]);

		if (rnk > 1) {
			int j = I[sch(rnk - 1)];
			rG[i].push_back(j);
			++ outDeg[j];
			// cout << j << " -> " << i << endl;
		}

		if (rnk < min(i + 1, K)) {
			int j = I[sch(rnk + 1)];
			rG[j].push_back(i);
			++ outDeg[i];
			// cout << i << " -> " << j << endl;
		}
	}

	for (int i = 0; i < N; ++i) {
		if (outDeg[i] == 0) {
			pq.emplace(i);
		}
	}

	for (int i = N; i >= 1; --i) {
		int u = pq.top(); pq.pop();
		// cout << i << ": " << u << endl;
		P[u] = i;
		for (int v : rG[u]) {
			-- outDeg[v];
			if (outDeg[v] == 0) pq.emplace(v);
		}
	}

	for (int i = 0; i < N; ++i) {
		cout << P[i] << '\n';
	}

	return 0;
}


Measured memory_bytes: 39296
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    B = list(map(int, readline().split()))
    ans = []
    for _ in range(N):
        L = len(B)
        k = -1
        for i in range(L):
            if B[i]==i+1:
                k = i
        if k == -1:
            print('-1')
            sys.exit()
        else:
            ans.append(B.pop(k))
    for i in range(N)[::-1]:
        print(ans[i])

if __name__ == '__main__':
    main()

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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    for(int i = 8; i < 10000; i++){
        if(i * 8 / 100 == a && i / 10 == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    Map<Integer,Integer>map=new TreeMap<>();
    for(int i=1;i<=N;i++){
      map.put(sc.nextInt(),i);
    }
    for(int i=1;i<=N;i++){
    System.out.print(map.get(i)+" ");
    }
  }
}

Measured memory_bytes: 74128
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int a;
int num(string s){
	int out=0;
	while(s.size()!=a&&isdigit(s[a])){out*=10;out+=s[a]-'0';a++;}
	return out;
}
int main(){
	vector<string>in;
	string s;
	while(cin>>s)in.pb(s);
	int n=in.size();
	int tmp[200][200]={0};
	rep(i,n){
		a=0;
		int b=in[i].size();
		int co=0;
		tmp[i][0]=num(in[i]);
		while(1){	
			if(a==b)break;
			a++;
			co++;
			tmp[i][co]=num(in[i]);
		}
	}
	int out[200][200]={0};
	out[0][0]=tmp[0][0];
	loop(i,1,n/2+1){
		out[i][0]=tmp[i][0]+out[i-1][0];
		loop(j,1,i)out[i][j]=tmp[i][j]+max(out[i-1][j-1],out[i-1][j]);
		out[i][i]=tmp[i][i]+out[i-1][i-1];
	}
	loop(i,n/2+1,n)rep(j,n-i)out[i][j]=tmp[i][j]+max(out[i-1][j],out[i-1][j+1]);
	cout<<out[n-1][0]<<endl;
	//rep(i,10){rep(j,10)cout<<" "<<out[i][j];cout<<endl;}
}

Measured memory_bytes: 1528
#include <iostream>
#include <vector>

using namespace std;
constexpr int64_t MOD =   998'244'353;

int main(void) {
    int N;
    cin >> N;
    vector<int> D(N);
    vector<int> num(N);
    for(int i=0; i<N; i++) {
        cin >> D[i];
        num[D[i]]++;
    }

    int64_t ans = 1;
    if(D[0] != 0 || num[0] != 1) {
        ans = 0;
    } else {
        for(int i=0; i<N; i++) {
            for(int j=0; j<num[i+1]; j++) {
                ans = (ans*num[i]) % MOD;
            }
        }
    }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,tmp,ans=0,kuro=0,siro=0;
	cin>>n;
	string s;
	cin>>s;
	rep(i,n)if(s[i]=='#')kuro++;
	ans=tmp=n-kuro;
	rep(i,n){
		if(s[i]=='.')tmp--;
		else tmp++;
		chmin(ans,tmp);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 720
def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

    ans = 0
    for i in range(N-1):
        ans += min(T, t[i+1] - t[i])
    ans += T
    print(ans)


if __name__ == "__main__":
    main()

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

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


Measured memory_bytes: 3092
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
int dfs(vector< vector< int > > &G, vector< int > &deg, int x, int p) {
	int ret = 0, count = 0;
	for (auto j : G[x]) {
		if (j == p)
			continue;
		int tmp = dfs(G, deg, j, x);
		ret += tmp;
		if (tmp > 0)
			count++;
	}
	ret += max(0LL, deg[x] - 1 - (p == -1 ? 0 : 1) - count);
	return ret;
}
signed main() {
	cin >> N;
	vector< vector< int > > G(N);
	vector< int > deg(N, 0);
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}
	int ans;
	int s = -1;
	rep(i, N) if (deg[i] >= 3) s = i;
	if (s == -1) {
		cout << 1 << endl;
		return 0;
	}
	ans = dfs(G, deg, s, -1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11008
////////////////////////////////////////////////////////////////////
// This source code is for Visual C++ 2010 Express
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
//#include "UnionFind.h"

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		(1000000)
#define Rep(i,n) for(int i = 0; i < (n); i++ )

using namespace std;

typedef vector< vector<int> > mat;
typedef pair<int, int> P;
typedef long long ll;
struct Point{
	ll x;
	ll y;
	Point() {};
	Point( ll xx, ll yy ) : x(xx), y(yy) {};
};

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

map<ll, ll> prime_factor(ll N)
{
	// 素因数分解
	map<ll, ll> ret;
	for( ll i = 2; i * i <= N; i++ ){
		while( N % i == 0 ){
			ret[i]++;
			N /= i;
		}
	}
	if(N != 1) ret[N] = 1;
	return ret;
}

int main()
{
	ll N = 0;
	ll ret = 0;

	cin >> N;
	vector<ll> d(N, 0);
	Rep(i, N){
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	if(d[N / 2 - 1] != d[N / 2]){
		ret = d[N / 2] - d[N / 2 - 1];
	}
	cout << ret << endl;

	return 0;
}





Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int A, B, K;
    cin >> A >> B >> K;

    if (A >= K) {
        A = A - K;
        K = 0;
    } else {
        K = K - A;
        A = 0;
    }

    if (K != 0 || B >= K) {
        B = B - K;
    } else {
        B = 0;
    }

    if (B < 0) {
        B = 0;
    }

    cout << A  << " " << B << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <iterator>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 100010;
const LL mod = 1e9 + 7;
const LL INF = 100000000000000LL;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define FOR(c,a,b) for(int c=a;c<=b;++c)
const double PI = acos(-1.0);

int a[5];

int solve() {
	int k;
	cin >> a[1] >> a[2] >> a[3] >> k;
	sort(a + 1, a + 1 + 3);
	cout << (a[3]<<k) + a[2] + a[1] << endl;
	return 0;
}

int main() {
	LL t = 1e18;
	//cin >> t;
	while(t--) {
		if(!solve())break;
	}
	int mark_EOF;
	if(scanf("%d", &mark_EOF) == EOF) return 0;
    return 0;
}

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

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var ai = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var bi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var ci = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var sum = 0;
            var previous = ai[0] - 1;
            for (var i = 0; i < ai.Length; i++)
            {
                var index = ai[i] - 1;
                sum += bi[index];
                if (previous == index - 1) sum += ci[index - 1];
                previous = index;
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396