akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    int upper = (N - 1) * (N - 2) / 2 - K;
    if (upper < 0) {
        cout << -1 << '\n';
        return 0;
    }
    upper = N * (N - 1) / 2 - K;
    cout << upper << '\n';
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            if (upper <= 0) return 0;
            cout << i + 1 << ' ' << j + 1 << '\n';
            upper--;
        }
    }
}


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

int main() {
  int64_t a,k,b;
  cin >> a >> b >> k;
  if(a >= k) cout << a - k << ' ' << b << endl;
  else if(a < k && k <= a+b) cout << 0 << ' ' << (a+b) - k << endl;
  else if(a+b < k) cout << 0 << ' ' << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H, vector<char>(W));
  for(int h=0; h<H; h++){
    for(int w=0; w<W; w++){
      cin >> maze.at(h).at(w);
    }
  }
 
  
  int ans = 0;
  for(int s_h=0; s_h<H; s_h++){//スタートするpositionをループしていく
    for(int s_w=0; s_w<W; s_w++){
      if(maze[s_h][s_w] == '#') continue;
      queue<P> q;//q(h_position, w_position)
      vector<vector<int>> min_num(H, vector<int>(W, INF));//スタートがかわる毎にINFで初期化
      q.push(P(s_h, s_w));//スタートするpositionをはじめにqueueに入れる
      min_num[s_h][s_w] = 0;//スタート地点に行くのにかかる手数は0
      
      //int loop=0;
      while(!q.empty()){
        //cout << " s_h:" << s_h << " s_w: " << s_w << " loop:  " << loop << " : " << "yah1" << endl;
        //loop++;
        //queueから取り出し，
        //その上下左右のマスに移動する手数をmin_numに値を入れて，
        //移動後のマスをqueueに入れる
        int now_x = q.front().first, now_y = q.front().second;
        q.pop();
        for(int i=0; i<4; i++){//上下左右(4回)ループ
          int next_x = now_x + dx[i], next_y = now_y + dy[i];
          //cout << "next_x: " << next_x << " next_y: " << next_y << endl;
          if(next_x<0||next_x>=H || next_y<0||next_y>=W) continue;
          if(maze[next_x][next_y] == '#') continue;
          if(min_num[next_x][next_y] != INF) continue;//すでに値があるなら
          min_num[next_x][next_y] = min_num[now_x][now_y]+1;
          q.push(P(next_x, next_y));
          //cout<<"next_x: "<<next_x<<" next_y: "<<next_y<<" min_num: " <<min_num[next_x][next_y]<<endl;
        }
      }
      
      for(int h=0; h<H; h++){//s_h,s_wでスタートしたときの最大を探しだし，
        for(int w=0; w<W; w++){//それをansに代入
          if(min_num[h][w] == INF) continue;
          ans = max(ans, min_num[h][w]);
        }
      }
    }
  }

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

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;

class Program
{


    static void Main(string[] args)
	{
        string[] input = Console.ReadLine().Split(' ');

        long a = long.Parse(input[0]);
        long b = long.Parse(input[1]);
        long c = long.Parse(input[2]);
        long d = long.Parse(input[3]);


        long ac = a * c;
        long ad = a * d;
        long bc = b * c;
        long bd = b * d;

        long max = ac;
        if (ad > max) max = ad;
        if (bc > max) max = bc;
        if (bd > max) max = bd;

        Console.WriteLine(max);


    }
}

Measured memory_bytes: 17896
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
int main(){
	long long int n;
	long long int a[100001];
	long long int b[100000];
	long long int count = 0;
	cin >> n;
	for(long long int i = 0;i < n + 1;i++){
		cin >> a[i];
	}
	for(long long int i = 0;i < n;i++){
		cin >> b[i];
		if(b[i] <= a[i]){
			a[i] -= b[i];
			count += b[i];
		}else{
			if(a[i + 1] >= (b[i] - a[i])){
				count += b[i];
				a[i + 1] -= (b[i] - a[i]);
			}else{
				count += (a[i + 1] + a[i]);
				a[i + 1] = 0;
			}
			a[i] = 0;
		}
	}
	cout << count << endl;
}

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

const long long MOD = 1000000007;
long long dy[100010] = { 1 };
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= 100000; i++) {
		dy[i] = (dy[i - 1] * i)%MOD;
	}
	if (n < m)std::swap(n, m);
	if (n == m) {
		printf("%lld", (((dy[n] * dy[m])%MOD) * 2)%MOD);
	}
	else if (n - m == 1) {
		printf("%lld", (dy[n] * dy[m]) % MOD);
	}
	else {
		printf("0");
	}
}

Measured memory_bytes: 1024
<?php
$n=trim(fgets(STDIN));
$h=explode(" ",trim(fgets(STDIN)));
$ans=0;
$m=$h[0];
$i=0;
while($i<$n){
  if($h[$i]>=$m){
    ++$ans;
    $m=$h[$i];
  }
  ++$i;
}
echo $ans;

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

using namespace std;

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

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

  sort(L, L + N, greater<int>());

  int answer = 0;
  for (int i = 0; i < K; i++) {
    answer += L[i];
  }

  cout << answer << endl;
}


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

int main(){
  ull n,a,b;
  cin >> n >> a >> b;
  ull ans = (n-2)*(b-a) + 1;
  if( a > b || ( n == 1 && a != b ) ){
    cout << 0 << endl;
  }else{
    cout << ans << endl;
  }
  
  return 0;
}


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

int main() {
  int X, f = 0;
  cin >> X;
  for (int i = 1; i <= X; i *= 10) {
    f += (X % (i * 10) - X % i) / i;
  }
  if (X % f == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] list = s.toCharArray();
		
		int cnt = 0;
		String ans = "Yes";
		for (int i = 0; i < list.length; i++) {
			for (int j = 0; j < list.length; j++) {
				if (list[i] == list[j]) {
					cnt++;
				}
			}
			if (cnt % 2 == 1) {
				ans = "No";
				break;
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28) 
#define MAX 3003
using namespace std;
typedef pair<int,int> ii;
int dp[MAX],N,T,S,A[MAX],B[MAX];

int main()
{
  while(cin >> N >> T >> S)
    {
      rep(i,N)cin >> A[i] >> B[i];
      int mexico = 0;
      rep(i,N+1)dp[i] = 0;

      rep(i,N)
	{//どの店
	  for(int j=T;j>=0;j--)
	    {//時間
	      if(!(S <= j || j+B[i] <= S))continue;
	      if(j+B[i] > T)continue;
	      dp[j+B[i]] = max(dp[j+B[i]],
			       dp[j]+A[i]);
		 
	      mexico = max(mexico,dp[j+B[i]]);
	    }
	}

      cout << mexico << endl;
    }
  return 0;
}

Measured memory_bytes: 1196
from functools import reduce
import math
import fractions

memo = {}
def gcd(a, b):
    """a = bq + r"""
    if (a, b) not in memo:
        a, b = (max(a, b), min(a, b))
        if b == 0:
            memo[(a, b)] = a
        else:
            r = a % b
            memo[(a, b)] = gcd(b, r)
    return memo[(a, b)]

def steins_gcd(a, b) : 
    a = int(a)
    b = int(b)
  
    # GCD(0, b) == b; GCD(a, 0) == a, 
    # GCD(0, 0) == 0  
    if (a == 0) : 
        return b 
      
    if (b == 0) : 
        return a 
  
    # Finding K, where K is the  
    # greatest power of 2 that  
    # divides both a and b.  
    k = 0
      
    while(((a | b) & 1) == 0) : 
        a = a >> 1
        b = b >> 1
        k = k + 1
          
    # Dividing a by 2 until a becomes odd  
    while ((a & 1) == 0) : 
        a = a >> 1
  
    # From here on, 'a' is always odd.  
    while(b != 0) : 
          
        # If b is even, remove all  
        # factor of 2 in b  
        while ((b & 1) == 0) : 
            b = b >> 1
  
        # Now a and b are both odd. Swap if 
        # necessary so a <= b, then set  
        # b = b - a (which is even). 
        if (a > b) : 
          
            # Swap u and v. 
            a, b = b, a
  
        b = (b - a) 
      
    # restore common factors of 2  
    return int(a << k)

def another_gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x


def lcm(a, b):
    return abs(a*b) // fractions.gcd(a, b)

if __name__ == "__main__":
    n = int(input())
    a_s = list(map(int, input().split(" ")))

    lcm_a = int(reduce(lcm, a_s))

    fm = 0
    for a in a_s:
        fm += (lcm_a-1) % a
    print(fm)


Measured memory_bytes: 5384
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<vector>
using namespace std;
int main()
{
	int a;
	cin >> a;
	int sum=0;
	for(int i=1;i<=a;i++)
	{
		int j=1;
		int k=i;
		while(k/10){
			k/=10;
			j++;
		}
		if(j%2!=0)sum++;
	}
	cout << sum ;
}

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

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


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

bool is_msprime[300001];
int msprime[100001];
int lim = 0;

void set_prime(){
    for(int i = 0; i < 300001; i++){
        is_msprime[i] = true;
    }
    is_msprime[0] = is_msprime[1] = false;
    for(int x = 2; x < 300001; x++){
        if(x % 7 != 1 && x % 7 != 6){
            is_msprime[x] = false;
        }
        if(is_msprime[x]){
            msprime[lim++] = x;
            for(int y = 2 * x; y < 300001; y += x){
                is_msprime[y] = false;
            }
        }
    }
}

int main(){
    set_prime();
    int N;
    while(true){
        scanf("%d", &N);
        if (N == 1) break;
        vector<int> factor;
        for(int i = 0; i < lim; i++){
            if (N % msprime[i] == 0){
                factor.push_back(msprime[i]);
            }
        }
        printf("%d:", N);
        for(int i = 0; i < factor.size(); i++){
            printf(" %d", factor[i]);
        }
        printf("\n");
    }
    
    return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

int bitcount(int x)
{
    int res = 0;

    while (x)
    {
        ++res;
        x &= (x - 1);
    }

    return res;
}

int solve(int N, int M, const vector<int>& xs, const vector<int> &ps)
{
    int ans = 0;

    for (int mask = 0; mask < (1 << N); ++mask)
    {
        bool ok = true;
#ifdef DEBUG
    cout << "mask = " << hex << mask << endl;
#endif
        for (int i = 0; i < M; ++i)
        {
#ifdef DEBUG
    cout << "i = " << i << ", xs = " << xs[i] << ", ps = " << ps[i] << ", count = " << bitcount(xs[
i] & mask) << endl;
#endif

            if (bitcount(xs[i] & mask) % 2 != ps[i])
            {
                ok = false;
                break;
            }
        }

        ans += (ok ? 1 : 0);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<int> xs(M), ps(M);

    for (int i = 0; i < M; ++i)
    {
        int k, mask = 0;
        cin >> k;

        while (k--)
        {
            int s;
            cin >> s;

            mask |= (1 << (s - 1));
        }

        xs[i] = mask;
    }

    for (int i = 0; i < M; ++i)
        cin >> ps[i];

    auto ans = solve(N, M, xs, ps);

    cout << ans << '\n';

    return 0;
}


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

int main(){
    int n, i, j, sum = 0;
    cin >> n;
    int d[n] = {};
    for(i=0; i<n; i++){
        cin >> d[i];
    }
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            sum += d[i] * d[j];
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int A, B, coin;
  cin >> A >> B;
  coin = 0;
  for(int i=0;i < 2;i++){
    if(A >= B){
      coin += A;
      A--;
    }else{
      coin += B;
      B--;
    }
  }
  cout << coin << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#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
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n,k; cin >> n >> k;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	sort(rall(v));
	int count = 0;
	rep(i,k){
		count += v[i];
	}
	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 = sc.nextInt();
    
    if(N % 2 == 0){
      System.out.print(N);
    }else{
      System.out.print(N * 2);
    }
  }
}

Measured memory_bytes: 22996
// ABC062 B - Picture Frame
#include <stdio.h>

int main(void) {
    int H, W;
    scanf("%d %d", &H, &W);
    char a[101][101];
    for (int i = 0; i < H; i++) {
        scanf("%s", &a[i][0]);
    }
    // 上
    for (int i = 0; i < W + 2; i++) {
        printf("#");
    }
    printf("\n");
    // 中身
    for (int i = 0; i < H; i++) {
        printf("#");
        printf("%s", a[i]);
        printf("#\n");
    }
    // 下
    for (int i = 0; i < W + 2; i++) {
        printf("#");
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, y;
  int res1 = -1, res2 = -1, res3 = -1;
  cin >> n >> y;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j + i <= n; j++) {
      int c = n - i - j;
      if (10000 * i + 5000 * j + 1000 * c == y) {
        res1 = i;
        res2 = j;
        res3 = c;
      }
    }
  }
  cout << res1 << " " << res2 << " " << res3 << endl;
}

Measured memory_bytes: 256
program greatoceanview
  implicit none

integer::n,i,ans=1
integer,allocatable::h(:)

read*,n
allocate(h(n))
read*,h(:)
do i=2,n
   if(h(i)>=maxval(h(1:i-1)))then
      ans=ans+1
   end if
end do

print*,ans

end program greatoceanview

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;

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


int main() {
    int height, width;
    cin >> height >> width;
    vector<string> field(height);
    for (int h = 0; h < height; ++h) cin >> field[h];

    int sx=0, sy=0, gx=width-1, gy=height-1;
  
    int block = 0;
    for (int h = 0; h < height; h++) {
        for (int w = 0; w < width; w++) {
            if (field[h][w]== '#')block++;
        }
    }
    vector<vector<int> > dist(height, vector<int>(width, -1));
    dist[sx][sy] = 0; 

    vector<vector<int> > prev_x(height, vector<int>(width, -1));
    vector<vector<int> > prev_y(height, vector<int>(width, -1));

    queue<pair<int, int> > que;
    que.push(make_pair(sx, sy));    

    while (!que.empty()) {
        pair<int, int> current_pos = que.front();
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop(); 

        for (int direction = 0; direction < 4; ++direction) {
            int next_x = x + dx[direction];
            int next_y = y + dy[direction];
            if (next_x < 0 || next_x >= height || next_y < 0 || next_y >= width) continue;
            if (field[next_x][next_y] == '#') continue; 


            if (dist[next_x][next_y] == -1) {
                que.push(make_pair(next_x, next_y));
                dist[next_x][next_y] = dist[x][y] + 1; 
                prev_x[next_x][next_y] = x; 
                prev_y[next_x][next_y] = y;
            }
        }
    }
    if (dist[height - 1][width - 1] == -1) {
        cout << -1 << endl;
    }
    else {
        cout << height*width- dist[height - 1][width - 1]-1-block << endl;
    }
    return 0;
}

Measured memory_bytes: 3568
/**
*    created: 23.05.2020 12:58:10
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    vector<int> l(3);
    cin >> l[0] >> l[1] >> l[2];
    sort(l.begin(), l.end());
    cout << l[0] * l[1] / 2 << endl;
    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 1010;

VI g[MAX];
int IN[MAX];
int OUT[MAX];
bool U[MAX];

int L, R;

void no()
{
	cout<<"NO"<<endl;
	exit(0);
}

void dfs(int x)
{
	U[x] = true;

	if (x & 1)
	{
		if (IN[x] > OUT[x]) no();
		R += IN[x] - OUT[x];
	}
	else
	{
		if (OUT[x] > IN[x]) no();
		L += OUT[x] - IN[x];
	}

	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		if (U[to]) continue;
		dfs(to);
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, n)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);

		int x, y;
		if (d == 0) y = b * 2;
		else y = d * 2 + 1;

		if (c == 0) x = a * 2 + 1;
		else x = c * 2;

	//	cout<<x<<' '<<y<<endl;
	//	cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;

		g[x].PB(y);
		g[y].PB(x);
		OUT[x]++;
		IN[y]++;
	}

	int c1 = 0, c2 = 0;
	FOR (i, 0, MAX)
	{
		if (U[i]) continue;
		if (SZ(g[i]) == 0) continue;
		L = R = 0;

		dfs(i);

		c1++;
		if (L == 0) c2++;
	}
	//cout<<"*"<<endl;
	if (c2) no();
	cout<<"YES"<<endl;

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,X;
	int cnt=0,min=1000;
	int m,a;
	cin >> N >> X;
	rep(i,N){
		cin >> m;
		cnt += m;
		if (m<=min){
			min=m;
		}
	}
	a = N + (X-cnt) / min;
	cout << a << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<ll,int> P;

const ll MAX_N=131072;
int bit[MAX_N*2-1];
ll n;
int main(){
  int N,ans,K;cin>>N>>K;
  ans=1;
  rep(i,N){
    if(i==0) ans*=K;
    else ans*=(K-1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;


int main(void) {

  int A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >> F;

  vector<int> w;
  for(int i=0; i<=30; i++){
    for(int j=0; j<=30; j++){
      int tmp = 100 * A * i + 100 * B * j;
      if( 1 <= tmp && tmp <= 3000 ) w.push_back(tmp);
    }
  }

  vector<int> s;
  for(int i=0; i<=1500; i++){
    for(int j=0; j<=1500; j++){
      int tmp = C * i + D * j;
      if( 1 <= tmp && tmp <= 1500 ) s.push_back(tmp);
      if( tmp > 1500 ) break;
    }
  }

  int mx1 = 0;
  int mx2 = 100*A;
  for(int i=0; i<w.size(); i++){
    for(int j=0; j<s.size(); j++){
      if( w[i] + s[j] > F ) continue;
      if( (100 + E) * s[j] > E * (w[i] + s[j]) ) continue;
      if( mx1 * (w[i]+s[j]) < s[j] * mx2 ){
        mx1 = s[j];
        mx2 = (w[i]+s[j]);
        if( mx1 * (100+E) == E * mx2 ){
          cout << mx2 << " " << mx1 << endl;
          return 0;
        }
      }
    }
  }
  cout << mx2 << " " << mx1 << endl;

  return 0;
}


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

typedef long long ll;
using namespace std;

int co[200000];
int ce[200000];

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

	int n; cin >> n;
	int mo,me;
	mo = me = -1;
	int o,e;
	int tmp;	

	for (int i = 0;i < n/2;i++){
		cin >> tmp;
		ce[tmp]++;
		if(me < ce[tmp]){
			me = ce[tmp];
			e = tmp;
		}
		cin >> tmp;
		co[tmp]++;
		if(mo < co[tmp]){
			mo = co[tmp];
			o = tmp;
		}		
	}

	sort(co,co+200000);
	sort(ce,ce+200000);

	reverse(co,co+200000);
	reverse(ce,ce+200000);

	if(e == o){
		cout << min(n/2-co[0]+n/2-ce[1],n/2-co[1]+n/2-ce[0]) << endl;
	}else{
		cout << n/2-co[0]+n/2-ce[0] << endl;
	}

	return 0;

}



Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
#define ford(i,a,b) for(int i=(a);i>=(b);--i)
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define swap(x,y) ((x)^=(y),(y)^=(x),(x)^=(y))
const int maxn=1e6+7;
typedef long long ll;
const int inf=1<<25;
int read(){
    int s=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1; c=getchar();}
    while(c>='0' && c<='9') {s=s*10+c-48;c=getchar();}
    return s*f;
}
void write(int x){
    if(x<0) {putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+48);
}

int abs(int x){
    return x < 0 ? -x : x; 
}
int a[maxn],b[maxn],n,m,c,flag;
char s[45];

int main(int argc, char const *argv[])
{
    n=read();
    fors(i,1,n){
        a[i]=read(),b[i]=read();
        ((a[i]+b[i]) & 1) ?  ++c : --c;
    }
    
    if(abs(c) != n) return  puts("-1"),0 ;

    m=31 + (c < 0);

    write(m),putchar(10);

    fors(i,0,30){
        printf("%d ", 1<<i );
    }

    if(c < 0) putchar('1');

    putchar(10);
    
    fors(i,1,n){
        int x=a[i],y=b[i];
        if(c < 0) s[31]='R' , --x;
        flag = 0;
        ford(j,30,0){
            if(abs(x) < abs(y)) swap(x,y),flag ^= 1; 
            if(x > 0 ) x-= 1<<j ,s[j] = flag ?  'U' : 'R';
            else x+= 1 << j , s[j] = flag ? 'D' : 'L';    
        }

        puts(s);
    
    }

    return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<map>
#define ll long long
#define MM(arr,x) memset(arr,x,sizeof(arr))
#define INF 10000000
using namespace std;
int main()
{
	int n,ac=0,tle=0,wa=0,re=0;
	cin>>n;
	while(n--)
	{
		string s;
		cin>>s;
		if(s=="AC") ac++;
		else if(s=="WA") wa++;
		else if(s=="TLE") tle++;
		else if(s=="RE") re++;
	}
	cout<<"AC x "<<ac<<'\n';
	cout<<"WA x "<<wa<<'\n';
	cout<<"TLE x "<<tle<<'\n';
	cout<<"RE x "<<re<<'\n';
	return 0;
}

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

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

int card[100];
int box;
for(int i = 0; i < N; i++){
	cin >> card[i];
}

for(int i = 0; i < N; i++){
	for(int j = i; j < N; j++){
		if(card[i] < card[j]){
			box = card[i];
			card[i] = card[j];
			card[j] = box;
		}
	}	
}

int point_alice = 0, point_bob = 0;
for(int i = 0; i < N; i++){
	if(i % 2 == 0)	point_alice += card[i];
	else point_bob += card[i];
}

cout << point_alice - point_bob << endl;

return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
int GCD(int x, int y) {
	return x ? GCD(y % x, x) : y;
}
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int count = 0;
	rep(i, n ){
		if (a[i] < 0)
		{
			count++;
		}
	}
	ll ans=0;
	rep(i, n) {
		a[i] = abs(a[i]);
		ans += abs(a[i]);
	}
	count %= 2;
	//cout << ans << endl;
	if (count != 0) {
		ans -= *min_element(all(a))*2;
	}
	cout << ans << endl;
}


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


#define ll long long
#define pb push_back
#define mp make_pair

int main() {
    string s;
    cin >> s;
    ll ca=0,cb=0;
    for(ll i=0;i<3;i++)
    {
        if(s[i]=='A')
        ca++;
        else
        cb++;
    }
    
    if(ca!=0 &&  cb!=0)
    cout <<"Yes" <<endl;
    else
    cout << "No"<<endl;
}

Measured memory_bytes: 256
FB = (1..10000).map{|x|a=[[:Fizz][x%3],[:Buzz][x%5]]*'';a==''?x.to_s: a}
loop do
  m, n = gets.split.map(&:to_i)
  break if m == 0
  pos = []
  ret = Array.new(m){|i|i+1}
  FB[0,n].zip(n.times.map{gets.chomp}).map.with_index{|(a,b),i| i if a!=b}.compact[0,m-1].unshift(0).each_cons(2).with_index{|(a,b),i| pos << (b-a)%(m-i)}
  pos.reduce(0){|s,t| ret.slice!(t=(s+t)%ret.size); t-1}
  puts ret.join(' ')
end

Measured memory_bytes: 10856
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int a, b, c, k;
        cin >> a >> b >> c >> k;
        if(k <= a + b){
            cout << min(k, a) << '\n';
        }else{
            k -= (a + b);
            cout << a - k << '\n';
        }
    }
}

Measured memory_bytes: 34224
#include<iostream>
using namespace std;
long long n, ans, c, Mod=1000000007;
int main(){
	int i;
	cin >> n;
	if(n==1) ans=0;
	if(n==2) ans=2;
	else{
		ans=1;
		for(i=0; i<n; i++){
			ans*=10;
			ans=ans%Mod;
		}
		c=1;
		for(i=0; i<n; i++){
			c*=8;
			c=c%Mod;
		}
		ans+=c;
		ans=ans%Mod;
		ans+=Mod;
		ans+=Mod;
		c=1;
		for(i=0; i<n; i++){
			c*=9;
			c=c%Mod;
		}
		ans-=c;
		ans-=c;
		ans=ans%Mod;
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long int

int main()
{ 
	ll n,l;
	cin>>n>>l;
	vector<string>vec;
	string ss;

	while(n--){
     
     cin>>ss;
     vec.push_back(ss);

  
	}
	sort(vec.begin(),vec.end());
	for(int i=0;i<vec.size();i++){
		cout<<vec[i];
	}
	
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        long x = sc.nextLong();

        long cnt = (x + 10) / 11 * 2;
        if (cnt / 2 * 11 - 5 >= x) {
            --cnt;
        }

        _out.println(cnt);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main(){

	fastcin
	
	int n, m;
	cin >> n >> m;
	
	int v[m], sum = 0; 
	
	for(int i=0; i<m; i++) cin >> v[i];
	
	for(int i=0; i<m; i++) sum+= v[i];
	
	
	int ans;
	
	(sum > n) ? ans = -1 : ans = n-sum;	
	
	cout << ans << endl;
	      
	return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,h,a[100000]={},b[100000]={},ans=0;
  cin >> n >> h;
  for(int i=0; i<n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a,a+100000,greater<int>());
  int Ma=a[0];
  sort(b,b+100000,greater<int>());
  int j=0;
  while(h>0&&b[j]>Ma) {
    h-=b[j];
    j++;
    ans++;
  }
  if(h<=0) {
    cout << ans << endl;
  }
  else {
    while(h>0) {
      h-=Ma;
      ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Threading;
using System.Xml.Serialization;

namespace AtCoderCs
{

    class Program
    {

        const int mod = 1000000007;

        static void Main()
        {

            var arg = Console.ReadLine().ToList();
            var length = arg.Count();
            var left = new List<KeyValuePair<int, int>>();
            var right = new List<KeyValuePair<int, int>>();
            var result = new int[length];

            for (int i = 0, count = 0, end; i < length; count++)
            {
                var str = (count & 1) != 0 ? 'L' : 'R';
                end = arg.FindIndex(i, x => x != str);
                if (end == -1) end = length;
                ((count & 1) != 0 ? left : right).Add(new KeyValuePair<int, int>(i, end));
                i = end;
            }

            for (int i = 0, l = right.Count, size; i < l; i++)
            {

                size = right[i].Value - right[i].Key;
                result[right[i].Value - 1] += (size >> 1) + (size & 1);
                result[right[i].Value] += (size >> 1);

            }

            for (int i = 0, l = left.Count, size; i < l; i++)
            {

                size = left[i].Value - left[i].Key;
                result[left[i].Key] += (size >> 1) + (size & 1);
                result[left[i].Key - 1] += (size >> 1);

            }

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

                if (i > 0) Console.Write(' ');
                Console.Write(result[i]);

            }

            return;

        }



    }
}


Measured memory_bytes: 18772
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		final int B = sc.nextInt();
		int C = sc.nextInt();
		final int D = sc.nextInt();
		sc.close();
		while(true){
			C -= B;
			if(C <= 0) break;
			A -= D;
			if(A <= 0) break;
		}
		if(C <= 0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35744
n_node, Q = map(int,input().split())
Q_ls = [[0,0] for _ in range(Q)]
for i in range(Q):
    a,b = map(int,input().split())
    Q_ls[i] = [a-1,b-1]
Q_ls.sort(key=lambda x: x[1])

last_r = -1
ans = 0
for i in range(Q):
    if Q_ls[i][1] > last_r and Q_ls[i][0] >= last_r:
        ans += 1
        last_r = Q_ls[i][1]
print(ans)


Measured memory_bytes: 96780
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();
    
    if (isOdd(a, b)) {
    	System.out.println("Odd");
    } else {
      System.out.println("Even");
    }
  }
  
  public static boolean isOdd(int a, int b) {
  	if ((a * b) % 2 == 1) {
    	return true;
    } else {
      return false;
  	}
  }
}

Measured memory_bytes: 21844
#include <iostream>
int main() {
    int W, H, x, y, r;
    std::cin >> W >> H >> x >> y >> r;
    if ((0 <= x - r && x + r <= W) && (0 <= y - r && y + r <= H)) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
}



Measured memory_bytes: 3104
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i + 100*j + 50*k == x:
        ans += 1
print(ans)

Measured memory_bytes: 9120
<?php
// 2020/01/21
// AtCoder Beginner Contest 142 - A

// Input
fscanf(STDIN, "%d", $n);

// Calc
if($n == 1){
    $ans = 1;
} elseif($n % 2 == 0){
    $ans = 0.5;
} else {
    $ans = (($n + 1) / 2) / $n;
}

// Output
echo $ans;

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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const int mod=1e9+7;
const int sze=1e5+2;
signed main(){
  string str;
  cin>>str;
  int len=str.length();
  int pos1=-1,pos2=-1;
  for(int i=0;i<len-1;i++){
	  if(str[i]==str[i+1]){
		  pos1=i+1;
		  pos2=i+2;
		  break;
	  }
  }
  
  if(pos1==-1){
	  for(int i=0;i<len-2;i++){
		 if(str[i]==str[i+2]){
			 pos1=i+1;
			 pos2=i+3;
			 break;
		 }  
	  }
  }
  cout<<pos1<<" "<<pos2<<endl;
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int h, w, n, x;
	int a[10010];
	cin >> h >> w >> n;
	int tmp=0;
	rep(i, n)
	{
		cin >> x;
		repp(j, tmp, tmp+x) a[j]=i+1;
tmp+=x;
	}
	rep(i, h)
	{
		rep(j, w)
		{
			if(j!=0) cout << ' ';
			if(i%2==0) cout << a[w*i+j];
			else cout << a[w*i+(w-1-j)];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
def solve():
    N, M = map(int, input().split())
    WAnum = 0
    ACnum = 0
    WA = [0]*(N+1)
    AC = [False]*(N+1)

    for _ in range(M):
        p, S = map(str, input().split())
        p = int(p)
        if AC[p] == True:
            continue
        if S == 'AC':
            AC[p] = True
            ACnum += 1
            WAnum += WA[p]
        elif S == 'WA':
            WA[p] += 1
        #print(AC, WA)
    #print(AC,WA)
    print(ACnum, WAnum)

solve()

Measured memory_bytes: 4596
x1, x2, x3, x4, x5 = gets.split(" ").map!{|i| i.to_i}

if x1 == 0
  puts 1
elsif x2 == 0
  puts 2
elsif x3 == 0
  puts 3
elsif x4 == 0
  puts 4
else
  puts 5
end



Measured memory_bytes: 14216
n,d=map(int,input().split())
l=[[int(i) for i in input().split()] for j in range(n)]
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        d2=0
        for k in range(d):
            d2+=(l[i][k]-l[j][k])**2
        if d2-round(d2**0.5)**2==0:
            cnt+=1
print(cnt)

Measured memory_bytes: 38384
#include <iostream>

int main() {
	while (1) {
		int N;
		int s[100];
		std::cin >> N;
		if ( N == 0 ) break;
		for ( int i=0; i<N; i++ ) {
			std::cin >> s[i];
		}
		int min=s[0], max=s[0], sum=0;
		for ( int i=0; i<N; i++ ) {
			if ( min > s[i] ) min = s[i];
			if ( max < s[i] ) max = s[i];
			sum += s[i];
		}
		std::cout << (int)((sum-min-max)/(N-2)) << std::endl;
	}
	return 0;
}

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

int getdigit(int num){
  int digit = 0;
  while(num != 0){
    num/=10;
    digit++;
  }
  return digit+1;
}

int main(void){
  int n; cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(getdigit(i)%2 == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define removeDuplicate(a) sort(a.begin(), a.end()); a.resize(distance(a.begin(), unique(a.begin(), a.end())))
 
const int N = 1e2 + 1; 
const int W = 2e5 + 1;
const int MOD = 1e9 + 7; 
const long long INF = 2e16 + 1; 
long long dp[W]; 

 
int main() {
    #define TASK "TASK"	
	// freopen(TASK".inp","r",stdin);
	// freopen(TASK".out","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	long long n, w; 
	cin >> n >> w; 
	long long v = 1000 * n + 1; 
	vector <long long> weights(n + 1), values(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> weights[i] >> values[i]; 
	}
	// for (int i = 0; i <= n; ++i) {
	// 	for (int j = 0; j <= v; ++j) dp[i][j] = INF; 
	// }
	for (int i = 0; i <= v; ++i) dp[i] = INF; 
	dp[0] = 0; 
	for (int i = 1; i <= n; ++i) {
		for(int j = v ; j >= values[i]; --j) {
			dp[j] = min(dp[j], dp[j - values[i]] + weights[i]); 
		}
	}
	// cout << dp[0] << endl; 
	for (int i = v; i >= 0; --i) {
		// cout << dp[i] << endl; 
		if (dp[i] <= w){
			cout << i << endl; 
			return 0; 
		}
	}
  	return 0;
}

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

int main(){
    vector<int> C(10001,0);
    int n,i,j;
    cin>>n;
    vector<int> A(n+1),B(n+1);
    for(i=1;i<=n;++i)
    {
        cin>>A[i];
        C[A[i]]++;
    }
    for(i=1;i<=10001;++i)
    {
        C[i]=C[i]+C[i-1];
    }
    for(j=1;j<=n;++j)
    {
        B[C[A[j]]]=A[j];
        C[A[j]]--;
    }

    for(i=1;i<=n;++i)
    {
        if(i>1)cout<<" ";
        cout<<B[i];
    }
    cout<<endl;

    return 0;
}



Measured memory_bytes: 18424
n = int(input())
s = input()

count = [float('inf')] * n

# 左端
count[0] = 0
for i in range(1, n):
    if s[i] == 'E':
        count[0] += 1

# 尺取
for i in range(1, n):
    count[i] = count[i-1]
    if s[i-1] == 'W':
        count[i] += 1
    if s[i] == 'E':
        count[i] -= 1

print(min(count))

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N, K;
    cin >> N >> K;
    if ((N + 1) / 2 >= K)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
N,T = map(int,input().split())
t = list(map(int,input().split()))
start = t[0]
sumt = 0
for i in range(1,N):
    if start + T >= t[i]:
        sumt += t[i]-start
        start = t[i]
    else:
        sumt += T
        start = t[i]
print(sumt+T)

Measured memory_bytes: 25196
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

x = N // 2
ans = pow(2, x, mod)

c = Counter(A)
if N & 1:
    for i in range(0, N, 2):
        if i == 0 and c[i] == 1:
            continue
        if c[i] == 2:
            continue
        ans = 0
else:
    for i in range(1, N, 2):
        if c[i] == 2:
            continue
        ans = 0

print(ans)


Measured memory_bytes: 14820
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n, c] = input[0].split(" ").map((x: string): number => +x);

type Program = { l: number, r: number, c: number };
const p: Array<Program> = [];
for (let i = 0; i < n; i++) {
	const [l, r, c] = input[i + 1].split(" ").map((x: string): number => +x);
	p.push({l, r, c});
}

p.sort((a: Program, b: Program) => {
	if (a.c !== b.c) return a.c - b.c;
	return a.l - b.l;
});

const v: Array<Program> = [];
for (let i = 0; i < n; i++) {
	if (i !== 0 && p[i - 1].c === p[i].c && p[i - 1].r === p[i].l) {
		v[v.length - 1].r = p[i].r;
	}
	else {
		v.push(p[i]);
	}
}

const rsw: Array<number> = new Array<number>(1e5 * 2 + 2).fill(0); // ruisekiwa

for (let i = 0; i < v.length; i++) {
	rsw[v[i].l * 2 - 1]++;
	rsw[v[i].r * 2]--;
}

let max = 0;
let tmp = 0;
for (let i = 0; i < rsw.length; i++) {
	tmp += rsw[i];
	if (max < tmp) max = tmp;
}
console.log(max);


Measured memory_bytes: 55420
#include <iostream>

using namespace std;

const int MOD = 1000000007;

typedef long long llong;

struct modint {
  llong val;

  modint () {
    val = 0;
  }

  modint (llong _val) {
    val = _val % MOD;
  }
};

modint operator+ (modint p, modint q) {
  return modint((p.val + q.val) % MOD);
}

modint operator- (modint p, modint q) {
  return modint((p.val - q.val + MOD) % MOD);
}

modint operator- (modint p) {
  return modint(0) - p;
}

modint operator* (modint p, modint q) {
  return modint((p.val * q.val) % MOD);
}

modint operator^ (modint p, int q) {
  modint pows [30];

  pows[0] = p;
  for (int i = 1; i < 30; i++) {
    pows[i] = pows[i - 1] * pows[i - 1];
  }

  modint ans (1);
  for (int i = 0; i < 30; i++) {
    if (q & 1 << i) {
      ans = ans * pows[i];
    }
  }

  return ans;
}

modint inv (modint p) {
  return p ^ (MOD - 2);
}

modint operator/ (modint p, modint q) {
  return p * (q ^ (MOD - 2));
}

const int MAX_N = 5005;

modint dp [MAX_N][MAX_N]; /* # of ways to get a string of length j with i moves */

int main () {
  dp[0][0] = modint(1);
  for (int i = 1; i < MAX_N; i++) {
    dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
    for (int j = 1; j < MAX_N - 1; j++) {
      dp[i][j] = modint(2) * dp[i - 1][j - 1] + dp[i - 1][j + 1];
    }
  }
  
  int length;
  string str;
  cin >> length >> str;

  cout << (dp[length][(int) str.size()] / (modint(2) ^ (int) str.size())).val << endl;
}


Measured memory_bytes: 195968
# XをN進数に変換
def base_number(X:int, N:int):
    res = ""
    while True:
        q, mod = divmod(X,N)
        res += str(mod)
        X = q
        if q == 0:
            break
    return res[::-1]

N,*B = map(int,input().split())
L = [int(input()) for _ in range(N)]

ans = float("inf")
for i in range(4 ** N):
    state = list(base_number(i,4).rjust(N, "0"))
    if not set(["0","1","2"]) <= set(state):
        continue
    
    make = [[] for _ in range(3)]
    for j,x in enumerate(state):
        if x == "3":
            continue
        make[int(x)].append(L[j])
    
    MP = 0
    for j,m in enumerate(make):
        if len(m) == 1:
            MP += abs(B[j] - m[0]) # 延長or短縮魔法
        else:
            MP += (len(m) - 1) * 10 # 合成魔法
            MP += abs(B[j] - sum(m))
    
    ans = min(ans, MP)

print(ans)

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

int main(){
  int64_t Xlower,Xupper,Ylower,Yupper;
  cin >> Xlower >> Xupper >> Ylower >> Yupper;

  int64_t ans= max(max(Xlower* Ylower, Xlower* Yupper), max(Xupper* Ylower, Xupper* Yupper));
  
  cout << ans << endl;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    int n, r;
    cin >> n >> r;

    if(n>=10) {
        cout << r << endl;
    }
    else {
        cout << r+100*(10-n) << endl;
    }
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

int cum[200001];
bool BC[200001];

void solve()
{
    string S;
    cin >> S;
    int N = S.length();
    int ptr = 0;
    int i = 0;
    LL ans = 0;
    while (ptr < N)
    {
        if (S[ptr] == 'A')
        {
            cum[i]++;
            if (1 <= i)
                cum[i] += cum[i - 1];
            ptr++;
        }
        else if (ptr + 1 < N and S[ptr] == 'B' and S[ptr + 1] == 'C')
        {
            cum[i] += cum[i - 1];
            ans += cum[i];
            ptr += 2;
        }
        else
        {
            ptr++;
        }
        i++;
    }

    std::cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 1428
//
// Created by tac on 2016/10/19.
//

#include <cstdlib>
#include <vector>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cmath>

namespace {

double mean(const std::vector<double> &vec) {
    return std::accumulate(vec.cbegin(), vec.cend(), 0.0) / vec.size();
}

double dispersion(const std::vector<double> &vec) {
    double m = mean(vec);
    double d = std::accumulate(vec.cbegin(), vec.cend(), 0.0, [m](double init, double s) {
        return init + std::pow(s - m, 2);
    });
    return std::sqrt(d / vec.size());
}

}

int main() {
    int n;
    int s;

    while (true) {
        std::cin >> n;
        if (n <= 0) {
            break;
        }
        std::vector<double> vec {};
        for (int i = 0; i < n; ++i) {
            std::cin >> s;
            vec.push_back(s);
        }
        std::cout << std::fixed << std::setprecision(8);
        std::cout << dispersion(vec) << std::endl;
    }

    return EXIT_SUCCESS;
}

Measured memory_bytes: 3276