akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <climits>
#include <string>
#include <vector>

using namespace std;

int main () {
    long long n = 0, k = 0;
    cin >> n >> k;
    vector<long long> candle(n);
    for (int i=0; i<n; i++) {
        cin >> candle.at(i);
    }
    int zero = lower_bound(candle.begin(), candle.end(), 0) - candle.begin();
    if (zero < n && candle.at(zero) < 0) cout << candle.at(zero) << endl;
    long long mini = (n - zero >= k) ? candle.at(zero-1+k) : LLONG_MAX;
    for (int i=0; i<zero; i++) {
        if (zero - i > k) continue;
        if (zero - i == k) mini = min(abs(candle.at(i)), mini);
        if (k + i - 1 > n-1) break;
        mini = min(abs(candle.at(i)) + candle.at(k + i - 1) + min(abs(candle.at(i)), abs(candle.at(k+i-1))), mini);
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main(){
	int K,P,n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>K>>P;
		int a;
		if(K%P<P&&K%P!=0){
			cout<<K%P<<endl;
		}else if(K%P==0){
			cout<<P<<endl;
		}else if(K<P){
			cout<<K<<endl;
		}
	}
}

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

int main() {
  int n;
  char str[255];

  scanf("%d", &n); getchar();
  scanf("%s", str);

  int len = strlen(str);
  if(len > n) {
    for(int i = 0; i < n; i++) {
      printf("%c", str[i]);
    }
    puts("...");
  } else {
    printf("%s\n", str);
  }
}

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

int main() {
  short int h, w, H;
  string s;
  char W;
  cin >> h >> w;
  for (short int i = 0; i < h; ++i) {
    for (short int j = 0; j < w; ++j) {
      cin >> s;
      if (s == "snuke") {
        H = i;
        W = 'A' + j;
      }
    }
  }
  cout << W << H + 1 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <utility>
using namespace std;

#define fi first
#define se second
typedef long long ll;

ll recursive_parse(const string & s, int & indx, map<string,ll>& symbol_table, map<pair<string,ll>,ll>& vals) {
	if('0' <= s[indx] && s[indx] <= '9') {
		ll res = 0;
		while(s[indx] != ']' && indx < s.size()) {
			res *= 10;
			res += s[indx]-'0';
			indx++;
		}
		return res;
	}
	string symbol = "";
	while(s[indx] != '[') {
		symbol += s[indx];
		indx++;
	}
	indx++;
	ll num = recursive_parse(s, indx, symbol_table, vals);
	indx++;

	if(num < 0) return -1;
	if(vals.find(make_pair(symbol, num)) == vals.end() /*not assigned */
			|| num >= symbol_table[symbol] /* out of range*/) {
		return -1;
	}
	return vals[make_pair(symbol,num)];
}

int main() {
	while(1) {
		string s_tmp;
		vector<string> program;
		while(cin >> s_tmp, s_tmp != ".") {
			program.push_back(s_tmp);
		}
		if(!program.size()) {
			// end of the input
			break;
		}
		map<string,ll> symbol_table;
		map<pair<string,ll>,ll> vals;
		int res = 0;
		for(int line = 0; line < program.size(); line++) {
			string s = program[line];
			if(s.find('=') == string::npos) {
				string symbol = string(s.begin(), s.begin() + s.find('['));
				ll size = atol(string(s.begin() + s.find('[')+1, s.begin() + s.find(']')).c_str());
				symbol_table[symbol] = size;
			}
			else {
				string l = string(s.begin(), s.begin()+s.find('='));
				string r = string(s.begin()+s.find('=')+1, s.end());
				ll l_val, r_val;

				int arg_indx = 0;
				string symbol = string(l.begin(), l.begin() + l.find('['));
				arg_indx = l.find('[')+1;

				l_val = recursive_parse(l,arg_indx,symbol_table,vals);
				assert(arg_indx+1 == l.size());
				arg_indx = 0;
				r_val = recursive_parse(r,arg_indx,symbol_table,vals);
				assert(arg_indx == r.size());

				if(l_val < 0 || r_val < 0 || symbol_table.find(symbol) == symbol_table.end() 
						|| symbol_table[symbol] <= l_val) {
					res = line+1;
					break;
				}

				vals[make_pair(symbol, l_val)] = r_val;
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 3364
package main

import (
	"fmt"
)

func main() {
	var m1, d1, m2, d2 int
	fmt.Scan(&m1, &d1, &m2, &d2)
	if m2 == (m1+1)%13 && d2 == 1 {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 512
let cnt = ref 0

let merge a l m r =
  let init_ary n p = Array.init (n + 1) (fun i -> if i = n then max_int else a.(p + i)) in
  let ai = init_ary (m - l) l in
  let aj = init_ary (r - m) m in
  let rec doit = function
    | (_, _, k) when k = r -> ()
    | (i, j, k) ->
      incr cnt;
      if ai.(i) <= aj.(j) then begin
        a.(k) <- ai.(i);
        doit (i + 1, j, k + 1)
      end else begin
        a.(k) <- aj.(j);
        doit (i, j + 1, k + 1)
      end in
  doit (0, 0, l)

let rec merge_sort a l r =
  if (l + 1) < r then begin
    let m = (l + r) / 2 in
    merge_sort a l m;
    merge_sort a m r;
    merge a l m r
  end

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  merge_sort a 0 n;
  Array.iteri (fun i e -> Printf.printf (if i = 0 then "%d" else " %d") e) a;
  print_newline ();
  Printf.printf "%d\n" !cnt

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

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

int main() {

    int a; cin >> a;

    cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3584
N, K, Q = map(int, input().split())

point_list = [0 for i in range(N)]

for i in range(Q):
  num = int(input()) - 1
  point_list[num] += 1

for i in point_list:
  if 0 < K - Q + i:
    print('Yes')
  else:
    print('No')

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

ll x;
ll ans, money;

int main() {
  cin >> x;
  money = 100;
  ans = 0;
  while (money < x) {
    ans++;
    money *= 1.01;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
//
//  main.cpp
//  ABC161C
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    long long N,K;
    cin >> N>>K;
    long long num=(N/K+1)*K-N;
    cout<<min(N%K,num)<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N, ans = 0;
    cin >> N;

    ll before = -1;
    REP(i, N) {
        ll A;
        cin >> A;
        if (A < before) {
            ans += before - A;
            A = before;
        }
        before = A;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch AlterAltar | diff AlterAltar.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address AlterAltar.cpp && ./a.out

/*

 8/2/2020

 5:26-

 */

string S;
int N;

void solve() {
  VI cum(N+1,0);
  REP(i,N) cum[i+1]=cum[i]+(S[i]=='R');

  int res=0;
  REP(i,N) if(S[i]=='R'&&i>=cum[N]) ++res;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>S;
  solve();

  return 0;
}


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

int main(){
    int n, y, b, r, t;
    while(cin >> n, n){
	cin >> y;
	int ans = 0;
	double res = -1;
	for(int i = 0;i < n;i++){
	    cin >> b >> r >> t;
	    double tmp;
	    if(t == 1){
		tmp = 1.0 + y * r * 0.01;
	    }
	    else{
		tmp = pow(1.0 + r * 0.01, y);
	    }
	    if(tmp > res){
		res = tmp;
		ans = b;
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
N = int(input())
a = list(map(int, input().split()))
 
b = [ 0 for _ in range(N)]
#M = 0
for i in reversed(range(1, N+1)):
    summ = 0
    for j in range(i, N+1, i):
        summ += b[j-1]
    if summ % 2 != a[i-1]:
    	b[i-1] = 1
    
 
cnt = sum(b)
print(cnt)
not_first = False
if cnt > 0:
 
    for j in range(N):
        if b[j] == 1:
            if not_first:
                print(" ", end="")
            print(j+1, end="")
            not_first = True
    print()

Measured memory_bytes: 7760
#include <stdio.h>

int main(){
  long a,b,c,d;
  long m;
  long a_C,a_D,a_M,b_C,b_D,b_M;
  long a_ans,b_ans;
  long x,y,tmp,r;
  scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
  
  x = c;
  y = d;
  if(x < y){
    tmp = x;
    x = y;
    y = tmp;
  }
  r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  m = (c * d) / y;
  
  a_C = (a-1) / c;
  a_D = (a-1) / d;
  a_M = (a-1) / m;
  a_ans = (a-1) - a_C - a_D + a_M;
  
  b_C = b / c;
  b_D = b / d;
  b_M = b / m;
  b_ans = b - b_C - b_D + b_M;
  
  printf("%ld\n",b_ans - a_ans);
  return 0;
  
}

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

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

    sort(v.begin(), v.end());
    
    int ans = 0;
    for (int i = 0; i < 2; ++i) ans += v[i];

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
int gcd(int a,int b){
	int r;
	int temp;
	if(b > a){
		temp = a;
		a = b;
		b = temp;}
	r = a % b;
	while(r > 0){
		a = b;
		b = r;
		r = a % b;
		}
	return b;
}
int main(void){
	int a,b,c;
	int k;
	int sum = 0;
	scanf("%d",&k);
	for(a = 1;a < k+1 ;a++){
		for (b = 1;b < k+1;b++){
			for (c = 1;c < k+1;c++){
				sum += gcd((gcd(a,b)),c);
						}
					}
				}
	printf("%d",sum);
	return 0;
}

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

int main()
{
	int a, b, c, d;
	
	scanf("%1d%1d%1d%1d", &a, &b, &c, &d);
	for (int i = 0; i < 9; i++) {
		int x = i;
		int tmp = a;
		if (x & 1) tmp += b;
		else tmp -= b;
		if (x & 2) tmp += c;
		else tmp -= c;
		if (x & 4) tmp += d;
		else tmp -= d;
		if (tmp == 7) {
			printf("%d%c%d%c%d%c%d=7\n", a, (x & 1) ? '+' : '-', b, (x & 2) ? '+' : '-', c, (x & 4) ? '+' : '-', d);
			return 0;
		}
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

int n;
char c[107][17];
int a[107];

bool judgec (int x, int lens)
{
	int i,j;
	for (i=1;i<x;i++)
	{
		if (lens==a[i])
		{
			bool pd=true;
			for (j=1;j<=lens;j++)
			{
				if (c[i][j]!=c[x][j])
				{
					pd=false;
					break;
				}
			}
			if (pd)
			{
			    return true;
			}
		}
	}
	return false;
}

	
int main()
{
    cin>>n;
    int i,l;
    scanf ("%s\n",c[1]+1);
    l=strlen (c[1]+1);
    a[1]=l;
    for (i=2;i<=n;i++)
    {
    	scanf ("%s\n",c[i]+1);
    	l=strlen (c[i]+1);
    	a[i]=l;
    	if (c[i-1][a[i-1]]!=c[i][1] || judgec(i,l))
    	{
    		cout<<"No"<<endl; 
    		return 0;
    	}
	}
	cout<<"Yes"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll N,taka=0,aoki=0;

int main(){
    cin>>N;
    ll A[N],B[N];
    vector<pair<ll, ll> > pairs(N);
    rep(i,N){
        cin>>A[i]>>B[i];
        pairs[i] = make_pair(A[i]+B[i],i);
    }
    sort(pairs.begin(),pairs.end());
    for(int i=N-1;i>=0;i--){
        if(i%2==(N-1)%2){
            taka+=A[pairs[i].second];
        }
        else{
            aoki+=B[pairs[i].second];
        }
    }
    out(taka-aoki);
}


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

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


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

ll INF = 1e+18;
int iINF = 1e9;

int 
main()
{
  int N; cin >> N;
  vector<ll> arr(5);
  rep(i, 0, N){
    string s; cin >> s;
    char ini = s[0];
    if('M' == ini) arr[0] += 1;
    if('A' == ini) arr[1] += 1;
    if('R' == ini) arr[2] += 1;
    if('C' == ini) arr[3] += 1;
    if('H' == ini) arr[4] += 1;
  }

  ll ans = 0;
  rep(i, 0, 3){
    rep(j, i + 1, 4){
      rep(k, j + 1, 5){
        ans += arr[i] * arr[j] * arr[k];
      }
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 3624
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

# dp[(i, x, flg)] := i番目までみてx個選んでいる時の最大値。flgは最後の１つをとったかどうか。
dp = defaultdict(lambda: -float('inf'))
dp[(0, 0, 0)] = 0

for i, a in enumerate(A, start=1):
    for x in range((i - 1) // 2, (i + 1) // 2 + 1):
        dp[(i, x, 0)] = max(dp[(i - 1, x, 0)], dp[(i - 1, x, 1)])
        dp[(i, x, 1)] = dp[(i - 1, x - 1, 0)] + a

print(max(dp[(N, N // 2, 0)], dp[(N, N // 2, 1)]))


Measured memory_bytes: 189984
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <cctype>
#include <cstdlib>
#include <string.h>
#include <utility>
#include <cstdio>
#include <set>
#include <boost/multiprecision/cpp_int.hpp>
#include <assert.h>
using namespace std;
namespace mp = boost::multiprecision;

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

#define ll mp::cpp_int
#define LL mp::cpp_int

#define MAX_N 200000
#define MOD 1000000007ll

int flg[MAX_N+1];
int p[MAX_N+1];

//最大公約数を求める
ll gcd(ll a, ll b) {
	if (a == 0 && b == 0) return INF;
	if (a == 0 || b == 0) return a + b;
	while (a % b != 0) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return b;
}

//最小公倍数を求める
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}


int n;
ll period[2 * MAX_N - 1], sum[2 * MAX_N - 1];

//O(n)
//セグメント木の初期化
void init(int n_) {
	// 簡単のため、要素数は２のべき乗にする
	n = 1;
	while (n < n_) n *= 2;
	for (int i = 0; i < 2 * MAX_N - 1; ++i) period[i] = 1, sum[i] = 0;
}

//O(logn)
//k番目の値(0-origin)を変更
void update(int k, ll per, ll s) {
	//葉の節点
	k += n - 1;
	period[k] = per;
	sum[k] = s;
	while (k > 0) {
		k = (k-1) / 2;
		period[k] = lcm(period[k * 2 + 1], period[k * 2 + 2]);
		assert(period[k] >= 0);
		sum[k] = period[k] / period[k * 2 + 1] * sum[k * 2 + 1] + period[k] / period[k * 2 + 2] * sum[k * 2 + 2];
		assert(sum[k] >= 0);
	}
}

//O(logn)
//[l, r)のうちの[a, b)の答えを求める。
//kは節点の番号。呼ぶときは根である0を呼ぶこと。
//例：[0, n)のうち[a, b)の部分の答えを求める：query(a, b, 0, 0, n)
ll query(ll a, ll b, int k, ll l, ll r, ll& per) {
	//cout << "k" << k << endl;
	//cout << "sum[k]" << sum[k] << endl;
	//cout << "period[k]" << period[k] << endl;

	//[l, r) && [a, b) == null    {l r a b} or {a b l r}
	if (r <= a || b <= l) return 0;

	//[l, r) && [a, b) == [l, r)    {a l r b}
	if (a <= l && r <= b) {
		per = lcm(per, period[k]);
		return sum[k];
	}

	//{a l b r} or {l a r b} or {l a b r}
	ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2, per);
	ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r, per);
	assert(period[k] % period[k * 2 + 1] == 0 && period[k] % period[k * 2 + 2] == 0);
	return period[k] / period[k * 2 + 1] * vl + period[k] / period[k * 2 + 2] * vr;
}

int main() {
	int N, Q;
	cin >> N >> Q;
	init(N);
	for (int i = 0; i < N; ++i) {
		int data;
		cin >> data;
		p[i+1] = data;
	}
	for (int i = 1; i <= N; ++i) {
		if (flg[i]) continue;
		flg[i]++;
		int cur = p[i];
		ll s = i;
		ll per = 1;
		while (cur != i) {
			flg[cur]++;
			s += cur;
			++per;
			cur = p[cur];
		}
		cur = p[i];
		update(i-1, per, s);
		while (cur != i) {
			update(cur-1, per, s);
			cur = p[cur];
		}
	}
	for (int i = 0; i < Q; ++i) {
		int l, r;
		cin >> l >> r;
		ll per = 1;
		ll ret = query(l-1, r, 0, 0, n, per);
		//cout << "ret" << ret << "\nper" << per << "\nperiod[0]" << period[0] << endl;
		assert((ret * per) % period[0] == 0);
		ret = ret * per / period[0];
		cout << ret % MOD << endl;
		l++;
	}
	return 0;
}

Measured memory_bytes: 29020
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  ll n, T;
  cin >> n >> T;
  vector<ll> t(n), dt(n-1);
  rep(i, n) cin >> t[i];
  rep(i, n-1) dt[i] = t[i+1] - t[i];
  ll ans = 0, start = t[0];
  for (int i = 0; i < n-1; i++) {
    if (dt[i] > T) {
      ans += (t[i] - start) + T;
      start = t[i+1];
    }
  }
  ans += (t[n-1] - start) + T;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, i, ans = 0;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n; i++)
    cin >> b[i];
  for (i = 0; i < n-1; i++)
    cin >> c[i];
  for (i = 0; i < n; i++) {
    ans += b[a[i]-1];
    if (i >= 0 && i <= n-2 && a[i+1]-a[i] == 1)
      ans += c[a[i]-1];
  }
  cout << ans << endl;
}

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


int main(){
	long long k,s;
	long long count = 0;
	bool flag = false;

	cin >>k >>s;

	for(int i=0;i<k+1;i++){
		for(int j=0;j<k+1;j++){
			long long l = s - (i+j);
			if(0 <= l && l <=k){
				count++;
			}
		}
	}


	cout << count <<endl;
}

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

int main(){
    string S,T;
    cin >> S >> T;

    int swap_num = 0;
    for (int i=0; i<S.size(); i++) {
        if (S[i]!=T[i]) {
            swap_num+=1;
        }
    }
    cout << swap_num << endl;
} 


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

int MAX=1e5;

int main(){
    int q;
    cin >> q;
    bool is_prime[MAX+1];
    for(int i=0;i<=MAX;i++){
        is_prime[i]=true;
    }
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=MAX;i++){
        if(is_prime[i]==true){
            for(int j=2*i;j<=MAX;j+=i){
                is_prime[j]=false;
            }
        }
       
    }
    int cnt[MAX+2]={};
    for(int i=2;i<=MAX;i++){
        if(i%2==1&&is_prime[i]==true&&is_prime[(i+1)/2]==true){
            cnt[i]=cnt[i-1]+1;
        }else{
            cnt[i]=cnt[i-1];
        }
    }

    while(q--){
        int l,r;
        cin >> l >> r;
        cout << cnt[r]-cnt[l-1] << endl;
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N);
    for(auto& x:A) cin >> x;
    sort(A.begin(),A.end());
    ll inf = 1e18;
    ll ans = 1;
    bool ok = true;
    for(int i=0;i<N;i++){
        if(A[i]>0 && inf/A[i]<ans) ok = false;
        ans *= A[i];
    }
    cout << (ok? ans:-1) << "\n";
}

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

Measured memory_bytes: 512
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int A, B;

    cin >> A >> B;

    cout << ((16.0 / A >= 2.0 && 16.0 / B >= 2.0) ? "Yay!" : ":(") << endl;
}


Measured memory_bytes: 256
H,W,D=map(int,input().split())

masu=[]

for j in range(H):
  L=list(map(int,input().split()))
  for i in range(W):
    masu.append(tuple((L[i],j+1,i+1)))
masu=sorted(masu,key=lambda x:x[0])
#print(masu)

dp=[0]*(H*W)
#print(dp)

for i in range(D,H*W):
  dp[i]=dp[i-D]+abs(masu[i][1]-masu[i-D][1])+abs(masu[i][2]-masu[i-D][2])
#print(dp)

Q=int(input())

for _ in range(Q):
  L,R=map(int,input().split())
  print(dp[R-1]-dp[L-1])

Measured memory_bytes: 18320
#include <iostream>
using namespace std;
void ABC100(void);
void ABC101(void);
void ABC102(void);
void ABC103(void);
void ABC104(void);
void ABC105(void);
void ABC106(void);
void ABC107(void);
void ABC108(void);
void ABC109(void);

int main(void){
    ABC101();
}

void ABC101(){
    string a;
    cin>>a;
    int i,sum=0;
    for(i=0;i<=3;++i){
        if(a[i]=='+')++sum;
        if(a[i]=='-')--sum;
    }
    cout<<sum;
}

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

int main() {
    
    long long N,S;
    cin >> N >> S;
    long long A[N];
    for(int i = 0; i < N;i++)cin >> A[i];
    
    long long DP[N+1][S+1];
    
    for(int i = 0; i <= N;i++){
        for(int j = 0; j <= S;j++)DP[i][j] = 0;
    }
    
    DP[0][0] = 1;
    long long MOD = 998244353;
    
    for(int i = 0; i < N ;i++){
        for(int j = 0; j <= S;j++){
            
            DP[i+1][j] += DP[i][j]*2 % MOD;
            if(j - A[i]>=0)DP[i+1][j] += DP[i][j-A[i]];
            DP[i+1][j] %= MOD;
            
        }
    }
    cout << DP[N][S]<<endl;
}


Measured memory_bytes: 73948
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	bool f = false;
	int n, a; int count1, count2;
	cin >> n;
	count1 = 0; count2 = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 1) {
			count2++;
		}
		else if (a % 4 == 0) {
			count1++;
		}
		else f = true;
	}
	if (f)count2++;
	if (count1 >= count2 - 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
/*
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n);

    for (int i = 0; i < n; i++)
        std::cin >> a[i];

    long num = 0, sum = 0;
    int abs_min = std::abs(a[0]);
    for (int i = 0; i < n; i++)
    {
        if (a[i] < 0)
            num++;
        abs_min = std::min(abs_min, std::abs(a[i]));
        sum += std::abs(a[i]);
    }

    if (num % 2 == 0)
        std::cout << sum << std::endl;
    else
        std::cout << sum - abs_min * 2 << std::endl;
    return 0;
}

Measured memory_bytes: 640
s = input()
t = input()

def z_algorithm(s):
    a = [0] * len(s)
    i = 1
    j = 0
    a[0] = len(s)
    while i < len(s):
        while i + j < len(s) and s[j] == s[i+j]:
            j += 1
        a[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < len(s) and k + a[k] < j:
            a[i+k] = a[k]
            k += 1
        i += k
        j -= k
    return a

def solve(i, li):
    ans = 0
    while True:
        if i < 0 or len(li) <= i or visited[i]:
            break
        if li[i] < len(t):
            visited[i] = True
            break
        if li[i] >= len(t):
            visited[i] = True
            ans += 1
            i += len(t)
    return ans

#sを伸ばす
new_s = s
while True:
    if len(new_s) > len(t):
        s = new_s
        break
    new_s += new_s

s = s*3
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans1 = 0
for i in range(len(li)):
    ans1 = max(ans1, solve(i, li))

s += s
li = z_algorithm(t + s)[len(t):]
visited = [False] * len(li)
ans2 = 0
for i in range(len(li)):
    ans2 = max(ans2, solve(i, li))

if ans1 == ans2:
    print(ans1)
else:
    print(-1)


Measured memory_bytes: 258512
/*
title:

url:D - Remainder Reminder

数学的な考察で解けた。
O(n)で解けるのでは？という直感（見通し）が役に立った。
*/

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007
#define int long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))

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

signed main()
{
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = k + 1; i <= n; i++)
    {
        int rm = (n + 1) / i;
        int quo = (n + 1) % i;
        ans += rm * (i - k) + MAX(0, quo - k);
    }
    //(0, ?)のものを数えてしまった分を消す
    if (k == 0)
    {
        ans -= n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def input_from_console():
    n = int(input())
    p_list = list(map(int, input().split()))
    return n, p_list


def solve(n, p_list):
    p_list_sorted = sorted(p_list)
    diff_count = 0
    for i in range(len(p_list)):
        if p_list_sorted[i] != p_list[i]:
            diff_count += 1

    if diff_count > 2:
        return 'NO'
    return 'YES'


def main():
    n, p_list = input_from_console()
    print(solve(n, p_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 3060
N,M = map(int,input().split())
counter = 0
X =[]
for i in range(N):
    A,B = map(int,input().split())
    X.append([A,B])
ansX = sorted(X)
rest = M
ans = 0
for i in range(N):
    if rest <= ansX[i][1]:
        ans +=rest*ansX[i][0]
        rest= 0
        break
    elif rest > ansX[i][1]:
        ans+= ansX[i][1]*ansX[i][0]
        rest-=ansX[i][1]

print(ans)

Measured memory_bytes: 20840
#include <stdio.h>
int main(void) {
    int a,b,temp;
    scanf("%d %d",&a,&b);
    if (b>a) {
        temp=b;
        b=a;
        a=temp;
    }
    while (1) {
        temp=a%b;
        if (temp==0) {
            printf("%d\n",b);
            break;
        } else {
            a=b,b=temp;
        }
    }
    return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int n;
	cin >> n;
	syc(n,2,100);
	int w[n];
	int sum = 0;
	for(int i=0;i<n;i++){
		cin >> w[i];
		syc(w[i],1,100);
		sum += w[i];
	}
	int l=0,r=0,s,temp;
	for(int i=0;i<n;i++){
		l=0;
		for(int j=0;j<=i;j++){
			l += w[j];
		}
		r=sum-l;
		s=(r-l)*(r-l);
		if(i==0){
			temp=s;
		}else if(temp>s){
			temp=s;
		}
	}
	cout << sqrt(temp) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int



int main()
{
    fast
    ll a,b,c,k;
  cin>>a>>b>>c>>k;
  ll sum=0;
  	if(k>a)
    {
    	  sum=sum+a;
      	k=k-a;
    }
  	else 
    {
     	 sum=sum+k;
      	k=0;
    }
  if(k>b)
  {
    k=k-b;
  }
  else
  {
    k=0;
  }
  sum=sum-k;
  cout<<sum<<"\n";
  
  	
  	
  
    return 0;
}

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

#define INF 1000000000

int n, num;

void mergeSort(int *, int, int);
void merge(int *, int, int, int);

int main(){
        int *S;
        int i, left, right;

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

        left = 0;
        right = n;

        mergeSort(S, left, right);

        for(i = 0; i < n ; i++){
          printf("%d", S[i]);
          if(i + 1 != n)printf(" ");
        }
        printf("\n");

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

        return 0;
}

void mergeSort(int *S, int left, int right){
        int mid,i;
        if(left+1 < right){
                mid = (left + right) / 2;
                mergeSort(S, left, mid);
                mergeSort(S, mid, right);
                merge(S, left, mid, right);
        }
}

void merge(int *S, int left, int mid, int right){
        int n1, n2, i, j, k;
        n1 = mid - left;
        n2 = right - mid;

        int *L, *R;
        L = malloc(sizeof(int) * (n1 + 1));
        R = malloc(sizeof(int) * (n2 + 1));

        for(i = 0 ; i < n1;i++){
                L[i] = S[left + i];
        }
        for(i = 0 ; i < n2;i++){
                R[i] = S[mid + i];
        }
        L[n1] = INF; R[n2] = INF;

        i = 0; j = 0;
        for(k = left ; k < right ; k++){
          if(L[i] <= R[j]){
            S[k] = L[i];
            i++; num++;
          }else{
            S[k] = R[j];
            j++; num++;
          }
        }
}



Measured memory_bytes: 64456
'use strict';

const main = (arg) => {
  const input = arg.trim().split('\n');
  const [a, b, c] = input[0].split(' ');
  let ans = 0;
  if (b >= a * c) {
    ans = c;
  } else {
    ans = Math.floor(b / a);
  }
  console.log(ans);
};

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


Measured memory_bytes: 29616
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 1e5 + 123;
int n, a[N];
ll s[N];
vector <int> adj[N];
vector <ll> c[N];

void dfs(int v, int p) {
    for (int to : adj[v]) {
        if (to == p) {
            continue;
        }
        dfs(to, v);
        ll w = 2 * a[to] - s[to];
        if (adj[to].size() == 1) {
            w = a[to] - s[to];
        }
        c[v].pb(w);
        c[to].pb(w);
        if (w < 0) {
            cout << "NO";
            exit(0);
        }
        s[v] += w;
        s[to] += w;
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    if (n == 2) {
        if (a[1] == a[2]) {
            cout << "YES";
        }   else {
            cout << "NO";
        }
        return 0;
    }
    for (int i = 1; i <= n - 1; i++) {
        int x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1, 1);
    if (adj[1].size() == 1 && s[1] != a[1]) {
        cout << "NO";
        return 0;
    }
    if (adj[1].size() > 1 && s[1] != 2 * a[1]) {
        cout << "NO";
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        if (adj[i].size() == 1) {
            continue;
        }
        for (int j : c[i]) {
            if (j > s[i] / 2) {
                cout << "NO";
                return 0;
            }
        }
    }
    cout << "YES";
}


Measured memory_bytes: 20352
#include <stdio.h>

int main(void){
    int a, b;
    while(~scanf("%d%d", &a, &b)){
        int x = 0;
        for(int i = a;i < 10e18;i += a){
            if(a % b == 0)break;
            if(i % a == 0 && i % b != 0){
                printf("%d\n", i);
                x = 1;
                break;
            }
        }
        if(x == 0)
            printf("-1\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */
int main(){
    ll H; cin >> H;
    ll ans = 0;
    ll count = 1;
    while(H > 0){
        H /= 2;
        ans += count;
        count *= 2;
    }
    cout << ans;
}


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

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int64_t MOD = 1'000'000'007;
int64_t dp[101][4][4][4];

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

    dp[0][3][3][3] = 1;

    for(int len=0;len<N;len++){

        for(int c1=0;c1<4;c1++){

            for(int c2=0;c2<4;c2++){

                for(int c3=0;c3<4;c3++){

                    if(dp[len][c1][c2][c3] == 0) continue;

                    for(int a=0;a<4;a++){

                        int A=0, C=1, G=2, T=3;
                        if(c2==A && c1==G && a==C) continue;    //AGC
                        if(c2==G && c1==A && a==C) continue;    //GAC
                        if(c2==A && c1==C && a==G) continue;    //ACG
                        if(c3==A && c1==G && a==C) continue;    //A?GC
                        if(c3==A && c2==G && a==C) continue;    //AG?C

                        dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
                        dp[len+1][a][c1][c2] %= MOD;
                    }
                }
            }
        }
    }

    int64_t ans=0;
    for(int c1=0;c1<4;c1++){
        for(int c2=0;c2<4;c2++){
            for(int c3=0;c3<4;c3++){
                ans += dp[N][c1][c2][c3];
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const int MAXN = 1e5+1;

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

	int ans = 0;
	for(int i = 1; i < MAXN; i++){
		int c = cnt[i-1]+cnt[i]+cnt[i+1];
		if(c > ans){
			ans = c;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type pair struct {
	val int
	idx int
}

func main() {
	W, H, x, y := getStdinInt4()
	ans := float64(W) * float64(H) / 2.0
	flag := 0
	if float64(W)/2.0 == float64(x) && float64(H)/2.0 == float64(y) {
		flag = 1
	}
	fmt.Printf("%f %d", ans, flag)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt4() (int, int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2], list[3]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

int main(){
	long long n,sum=0;
//	vector<int> res;
	cin>>n;
	int arr[n+1];
	int b[n];
	for(int i=0;i<=n;i++)
		cin>>arr[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
	for(int i=1;i<=n;i++){
		if(b[i-1]>=arr[i]+arr[i-1]){
			sum+=arr[i]+arr[i-1];
			arr[i]=0;
		}
		else{
			if(arr[i-1]<=b[i-1])
				arr[i]=arr[i]+arr[i-1]-b[i-1];
			sum+=b[i-1];
		}
		arr[i-1]=0;
	}
	cout<<sum<<endl;	
}

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

int main(){
  ll n,k,a;
  cin>>n>>k>>a;
  ll num=a,ma=a;
  for(ll i=1;i<n;i++){
    cin>>a;
    num=__gcd(num,a);
    ma=max(ma,a);
  }
  cout<<((k<=ma&&k%num==0)?"POSSIBLE":"IMPOSSIBLE")<<endl;
  return 0;
}

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

using ll =  long long;
using pint =  pair<int,int>;

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}

signed main(void){
  int n,m;cin>>n>>m;
  vint c(m);vin(c);
  vsort(c);
  vint dp(n+10,0);
  repi(i,1,n+2){
    int min=dp[i-1]+1;
    repi(j,1,m){
      if(i>=c[j]){
        chmin(min,dp[i-c[j]]+1);
      }
    }
    dp[i]=min;
  }
  //rep(i,n+1)cout << i << " yen: " << dp[i] << endl;
  cout << dp[n] << endl;

}


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

using namespace std;

int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  if((b - a)&1ll)
  {
    long long q = min(n - b, a - 1ll) + 1;
    cout << q + (b - a)/2ll;
  }
  else
    cout << (b - a)/2ll;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		boolean judge = true;

		do{
			int num1 = sc.nextInt();
			String op = sc.next();
			int num2 = sc.nextInt();

			if(op.equals("+")){
				System.out.println(num1 + num2);
			}else if(op.equals("-")){
				System.out.println(num1 - num2);
			}else if(op.equals("*")){
				System.out.println(num1 * num2);
			}else if(op.equals("/")){
				System.out.println((int)num1 / num2);
			}else {
				judge = false;
			}
		}while(judge);

	}
}


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

int a[1010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int q;
	scanf("%d", &q);
	for(int i = 0; i < q; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		swap_ranges(a+x, a+y, a+z);
	}
	for(int i = 0; i < n-1; i++)
		printf("%d ", a[i]);
	printf("%d\n", a[n-1]);
}



Measured memory_bytes: 3208
#include<stdio.h>

int main(){
  long long a[100000] = {};
  long long p[100000] = {};
  long long n = 0;
  long long i = 0;
  long long cnt = 1;
  long long ck = 0;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
    if(a[i] == 0){
      ck++;
    }
  }
  for(i=0;i<n;i++){
    if(a[i] != 0){
      if((3-p[a[i]]) >= 0){
        cnt = (cnt*(p[a[i]-1]-p[a[i]]))%1000000007;
      }else{
        cnt = 0;
      }
    }
    //printf("%lld/",cnt);
    p[a[i]]++;
  }
  if(ck == 1){
    cnt = (cnt * 3)%1000000007;
  }else if(ck == 2){
    cnt = (cnt * 6)%1000000007;
  }else if(ck == 3){
    cnt = (cnt * 6)%1000000007;
  }else{
    cnt = 0;
  }
  printf("%lld",cnt);

  return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	
	if(a==b&&b!=c)
	puts("Yes");
	
	else if(a==c&&a!=b)
	puts("Yes");
	
	else if(b==c&&b!=a)
	puts("Yes");
	
	
	else
	puts("No");
	

	return 0;
}

Measured memory_bytes: 1644
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,K,c=0;
cin>>A>>B>>K;
set<int>s;
if(K>B-A+1)K=B-A+1;
for(int i=A;;i++){
    s.insert(i);
    c++;
    if(c==K)break;
}
c=0;
for(int i=B-K+1;;i++){
    s.insert(i);
    c++;
    if(c==K)break;
}
for(int x:s)cout<<x<<endl;

return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair

int n,a[100005],c[3];

int main () {
	scanf("%d",&n);
	FOE(i,1,n) {
		scanf("%d",&a[i]);
		if (a[i]%4==0) ++c[2];
		else if (a[i]%2==0) ++c[1];
		else ++c[0];
	}
	if (c[1]==n) {
		printf("Yes\n");
		return 0;
	}
	if (c[2]!=0)
	c[2]=c[2]+1;
	c[2]-=c[0];
	if (c[2]<0) {
		printf("No\n");
		return 0;	
	}
	if (c[1]==1 && c[2]==0) {
		printf("No\n");
		return 0;	
	}
	if (c[1]>=1 && c[2]==0 && n>c[1]) {
		printf("No\n");
		return 0;	
	}
	printf("Yes\n");
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<25)     //33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

bool a[100010] = {false};
int b[100010];
signed main(void)
{
  int n, m;
  cin >> n >> m;
  FOR(i, 1, n+1) b[i] = 1;
  a[1] = true;
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    if(a[x]) {
      a[y] = true;
    }
    b[x]--;
    b[y]++;
    if(b[x] == 0) a[x] = false;
    //FOR(i, 1, n+1) cout << a[i] << " "; cout << endl;
    //FOR(i, 1, n+1) cout << b[i] << " "; cout << endl;
  }
  int ret = 0;
  FOR(i, 1, n+1) {
    if(a[i]) ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 768
n = int(input())
lisa = list(map(int, input().split()))
lisb = list(map(int, input().split()))
lisc = []
total = 0
for i in range(n):
    lisc.append(lisa[i] - lisb[i])
for j in lisc:
    if j > 0:
        total += j
print(total)

Measured memory_bytes: 3060
using System;
public class Hello{
    public static void Main(){
        int i = 1;
        while(true){
            int n = int.Parse(Console.ReadLine());
            if(n == 0){
                break;
            }else{
                Console.WriteLine("Case " + i + ": " + n);
                i++;
            }
        }
    }
}


Measured memory_bytes: 15884