akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
using namespace std;


int main(){

    FAST_IO;
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if(k<=a){
        cout << k << endl;
    }
    else if(k<=(a+b)){
        cout << a<< endl;
    }
    else{
        cout << a - (k-(a+b)) << endl;
    }

    return 0;
}


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

int main()
{
	int n, q, head = -1, tail, time_queue[100001] = { }, now = 0;
	char name_queue[100001][15];
	cin >> n >> q;
	for (int i = 0; i < n; i++)
		cin >> name_queue[i] >> time_queue[i];
	tail = (n - 1) % 100001;
	while (tail != head)
	{
	    head = (head + 1) % 100001;
		if (time_queue[head] <= q)
		{
			now += time_queue[head];
			cout << name_queue[head] << " " << now << endl;
		}
		else
		{
			now += q;
			time_queue[(tail + 1) % 100001] = time_queue[head] - q;
			strcpy(name_queue[(tail + 1) % 100001], name_queue[head]);
			tail = (tail + 1) % 100001;
		}
	}

	return 0;
}


Measured memory_bytes: 4884
#include <stdio.h>

int main(void)
{
	int life1, atk1;
	int life2, atk2;

	scanf("%d%d%d%d", &life1, &atk1, &life2, &atk2);

	while (life1 > 0 && life2 > 0)
	{
		life2 -= atk1;
		life1 -= atk2;
	}

	if (life2 <= 0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 1608
#include <cstdio>

using namespace std;

int a[100000];

int main() {
    int n, i;
    long long ans = 0;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n; i++) {
        if (i > 0 && a[i - 1] > 0 && a[i] > 0) {
            a[i]--;
            ans++;
        }
        
        ans += a[i] / 2;
        a[i] %= 2;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc060/tasks/abc060_b

int main() {
    int A, B, C; cin >> A >> B >> C;

    for (int i = 1; i <= A*B; i++) if (A*i%B==C){
            cout << "YES" << "\n";
            return 0;
    }

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


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
    int i;

    int N;
    scanf("%d", &N);
    int f[N], a[N], t[N], x[N], y[N];
    for( i = 0; i < N; ++i )
        scanf("%d%d%d%d%d", &f[i], &a[i], &t[i], &x[i], &y[i]);

    double distance[2] = { -1, -1 }, time[2] = { -1, -1 }, tmp_dist, tmp_time;
    for( i = 0; i < N-1; ++i )
        if( a[i] != a[i+1] && t[i] == t[i+1] ){
            tmp_dist = sqrt(pow(x[i]-x[i+1], 2) + pow(y[i]-y[i+1], 2));
            tmp_time = (double)(f[i+1] - f[i]) / 60;

            if( distance[t[i]] < tmp_dist ){
                distance[t[i]] = tmp_dist;
                time[t[i]] = tmp_time;
            } else if( distance[t[i]] == tmp_dist ){
                if( tmp_time < time[t[i]] )
                    time[t[i]] = tmp_time;
            }
        }

    for( i = 0; i < 2; ++i )
        printf("%lf %lf\n", distance[i], time[i]);

    return 0;
}

Measured memory_bytes: 636
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#ifdef _WIN64
#define __builtin_popcountll __popcnt64
#else
inline int __builtin_popcountll(__int64 a) {
	return __builtin_popcount((unsigned int)a) + __builtin_popcount(a >> 32);
}
#endif
#endif
using ll = long long;
using ull = unsigned long long;
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y
//sin(x* pi / 180)
//be careful from the multiplication while using this define 
//alot of memset may couse TLE
#define TC int t;cin>>t;while(t--)
int dx[] = { 0,0,-1,1,1,1,-1,-1 };
int dy[] = { 1,-1,0,0,1,-1,1,-1 };
//</DEFINE>
ll OO = 1e18;
ll dp[3000][3000][2];
int v[3000];
int main() {
	Fast(), File();
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> v[i],dp[i][i][1] = v[i], dp[i][i][0] = -v[i];
	for (int i = 1; i < n; i++) {
		int l = 0;
		for (int r = i; r < n; r++, l++) {
			dp[l][r][0] = OO, dp[l][r][1] = -OO;
			dp[l][r][0] = min(dp[l + 1][r][1] - v[l], dp[l][r][0]);
			dp[l][r][1] = max(dp[l + 1][r][0] + v[l], dp[l][r][1]);
			dp[l][r][0] = min(dp[l][r - 1][1] - v[r], dp[l][r][0]);
			dp[l][r][1] = max(dp[l][r - 1][0] + v[r], dp[l][r][1]);
		}
	}
	cout << dp[0][n - 1][1] << endl;
}

Measured memory_bytes: 85520
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	n := getInt()

	numMap1 := make(map[int]int)
	numMap2 := make(map[int]int)

	for i := 0; i < n; i++ {
		v := getInt()
		if i % 2 == 1 {
			numMap1[v]++
		} else {
			numMap2[v]++
		}
	}

	if len(numMap1) == 1 && len(numMap2) == 1 {
		num1 := 0
		for num := range numMap1 {
			num1 = num
		}

		num2 := 0
		for num := range numMap2 {
			num1 = num
		}

		if num1 == num2 {
			fmt.Println(n / 2)
			return
		}
	}

	maxNum1 := [][]int{{0, 0}, {0, 0}}
	for num, cnt := range numMap1 {
		if maxNum1[0][1] < cnt {
			if maxNum1[1][1] < maxNum1[0][1] {
				maxNum1[1][0], maxNum1[1][1] = maxNum1[0][0], maxNum1[0][1]
			}

			maxNum1[0][0], maxNum1[0][1] = num, cnt
		} else if maxNum1[1][1] < cnt {
			maxNum1[1][0], maxNum1[1][1] = num, cnt
		}
	}

	maxNum2 := [][]int{{0, 0}, {0, 0}}
	for num, cnt := range numMap2 {
		if maxNum2[0][1] < cnt {
			if maxNum2[1][1] < maxNum2[0][1] {
				maxNum2[1][0], maxNum2[1][1] = maxNum2[0][0], maxNum2[0][1]
			}

			maxNum2[0][0], maxNum2[0][1] = num, cnt
		} else if maxNum2[1][1] < cnt {
			maxNum2[1][0], maxNum2[1][1] = num, cnt
		}
	}

	//fmt.Println(maxNum1)
	//fmt.Println(maxNum2)

	var changeCnt1, changeCnt2 int

	if maxNum1[0][0] != maxNum2[0][0] {
		changeCnt1 = n/2 - maxNum1[0][1]
		changeCnt2 = n/2 - maxNum2[0][1]
	} else {
		if maxNum1[0][1] + maxNum2[1][1] >= maxNum1[1][1] + maxNum2[0][1] {
			changeCnt1 = n/2 - maxNum1[0][1]
			changeCnt2 = n/2 - maxNum2[1][1]
		} else {
			changeCnt1 = n/2 - maxNum1[1][1]
			changeCnt2 = n/2 - maxNum2[0][1]
		}
	}

	fmt.Println(changeCnt1 + changeCnt2)
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 6784
#include <cstdio>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void) {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  puts(a == b && b == c ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	long long a[n], sum[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(i == 0) sum[i] = a[i];
		else sum[i] = sum[i-1] + a[i];
	}

	long long res = abs(sum[n-1] - 2 * sum[0]);
	for (int i = 1; i < n-1; i++)
	{
		res = min(res, abs(sum[n-1] - 2 * sum[i]));
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 6712
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        PriorityQueue<Double> v = new PriorityQueue<>();
        for(int i=0;i<n;i++){
            v.add(sc.nextDouble());
        }
        while(v.size()>1){
            Double a = v.poll();
            Double b = v.poll();
            Double c = (a+b)/2.0;
            v.add(c);
        }
        System.out.println(v.poll());
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
typedef pair<int, int> P;

vector<P> prime_factorize(int N){
	vector<P> ans;
	for(int a = 2; a*a <= N; a++){
		if(N%a == 0){
			int ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

//COMinit()で準備　COM(n, k) でnCk(n < 10^6)が求める
const int MAX = 1000001;

int fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
    int N, M; cin >> N >> M;
    int ans = 1;
    vector<P> vec = prime_factorize(M);
    for(int i = 0; i < vec.size(); i++){
        int k = vec[i].second;
        COMinit();
        ans *= COM(N + k - 1, k);
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 23680
#include<stdio.h>
bool panduan (int x, int y, int z);
int main() {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if (panduan(a,c,d)) {
		printf("Yes\n");
		return 0;
	}
	if (panduan(a,b,d) && panduan(b,c,d)) {
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
} 

bool panduan (int x, int y, int z) {
	if (x < y) {
		if (y-x <= z) {
			return 1;
		}
	} else {
		if (x-y <= z) {
			return 1;
		}
	}
	return 0;
}

Measured memory_bytes: 128
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    Q = [0]*N
    for i in range(N):
        Q[read_int()-1] = i
    max_k = 1
    k = 1
    for i in range(1, N):
        if Q[i] > Q[i-1]:
            k += 1
            max_k = max(max_k, k)
        else:
            k = 1
    return N-max_k


if __name__ == '__main__':
    print(solve())


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


int main() {
	long X, Y, Z, K;
	vector<long>vec;

	cin >> X >> Y >> Z >> K;
	vector<long> A (X);
	vector<long> B (Y);
	vector<long> C (Z);

	for (int i=0; i<X; i++) cin >> A[i];
	sort(A.begin(), A.end(), greater<long>());

	for (int i=0; i<Y; i++) cin >> B[i];
	sort(B.begin(), B.end(), greater<long>());

	for (int i=0; i<Z; i++) cin >> C[i];
	sort(C.begin(), C.end(), greater<long>());

	for (int i=0; i<X && i+1<=K; i++) {
		for (int j=0; j<Y && (i+1)*(j+1)<=K; j++) {
			for (int k=0; k<Z && (i+1)*(j+1)*(k+1)<=K; k++) {
				vec.push_back(A[i] + B[j] + C[k]);
			}
		}
	}
/*
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < Y; j++) {
			for (int k = 0; k < Z; k++) {
				if ((i + 1) * (j + 1) * (k + 1) <= K) vec.push_back(A[i] + B[j] + C[k]);
				else break;
			}
		}
	}
*/
	sort(vec.begin(), vec.end(), greater<long>());
	for (int i = 0; i < K; i++) cout << vec[i] << endl;
	return 0;
}



Measured memory_bytes: 1404
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    P = [int(i) for i in input().split()]
    ans = 0
    for i in range(100):
        if X - i < 1 or X - i not in P:
            ans = X - i
            break
        elif X + i > 100 or X + i not in P:
            ans = X + i
            break
    print(ans)

Measured memory_bytes: 61812
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur!=nil&&cur->key!=key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}

Measured memory_bytes: 31788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;

typedef vector<ull> vull;
typedef vector<ll> vll;
typedef vector<ui> vui;
typedef vector<long> vl;
typedef vector<int> vi;

typedef pair<ull, ull> pull;
typedef pair<ll, ll> pll;
typedef pair<ui, ui> pui;
typedef pair<long, long> pl;
typedef pair<int, int> pi;

template <class T>
void printv(vector<T> vc) {
    for (auto e: vc) cout << e << " ";
    cout << endl;
}

int D[10];
int n, k;

int main() {
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
        int d; cin >> d;
        D[d] = 1;
    }

	for (int i = n; i < 100000; i++) {
		string S = to_string(i);

        bool isDislike = false;
		for (int j = 0; j < S.size(); j++) {
			if (D[(S[j] - '0')] == 1) {
                isDislike = true;
                break;
            }
		}

        if (isDislike) continue;
		cout << i << endl; break;
	}

    return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <cstdio>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0) { break; }

    int insert_order = 0;
    unordered_map<int, int> insert_orders;
    unordered_map<int, unsigned long> sales;
    for (int i = 0; i < n; ++i) {
      int id, unit_cost, count;
      scanf("%d %d %d", &id, &unit_cost, &count);
      if (insert_orders.count(id) == 0) {
        insert_orders[id] = ++insert_order;
      }
      sales[id] += unit_cost * count;
    }
    typedef pair<int, unsigned long> Record;
    vector<Record> sales_result(sales.cbegin(), sales.cend());
    sort(
        sales_result.begin(),
        sales_result.end(),
        [&](const Record& a, const Record& b) {
          return insert_orders[a.first] < insert_orders[b.first];
        });
    bool exists = false;
    for (const auto& record : sales_result) {
      if (record.second < 1000000) { continue; }
      exists = true;
      printf("%d\n", record.first, record);
    }
    if (!exists) { puts("NA"); }
  }

  return 0;
}

Measured memory_bytes: 1144
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int n, m;

int x[5005], y[5005];
vi compressed_x, compressed_y;

int a[5005][5005];

int main()
{
    scanf("%d%d",&n,&m);

    rep(i, n) {
        scanf("%d%d",x+i,y+i);
        compressed_x.PB(x[i]);
        compressed_y.PB(y[i]);
    }

    sort(all(compressed_x));
    sort(all(compressed_y));

    compressed_x.erase(unique(all(compressed_x)), end(compressed_x));
    compressed_y.erase(unique(all(compressed_y)), end(compressed_y));

    rep(i, n) {
        int xidx = lower_bound(all(compressed_x), x[i]) - begin(compressed_x);
        int yidx = lower_bound(all(compressed_y), y[i]) - begin(compressed_y);

        a[yidx][xidx]++;
    }

    for (int i = 0; i < compressed_y.size()+1; ++i) {
        for (int j = 0; j < compressed_x.size()+1; ++j) {
            if (i - 1 >= 0) a[i][j] += a[i - 1][j];
        }
    }

    for (int i = 0; i < compressed_x.size()+1; ++i) {
        for (int j = 0; j < compressed_y.size()+1; ++j) {
            if (i - 1 >= 0) a[j][i] += a[j][i - 1];
        }
    }

    compressed_x.PB(inf);
    compressed_y.PB(inf);

    rep(i, m) {
        int x1, y1, x2, y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

        x1 = lower_bound(all(compressed_x), x1) - begin(compressed_x);
        x2 = upper_bound(all(compressed_x), x2) - begin(compressed_x) - 1;
        y1 = lower_bound(all(compressed_y), y1) - begin(compressed_y);
        y2 = upper_bound(all(compressed_y), y2) - begin(compressed_y) - 1;

        if (x2 < 0 || y2 < 0) {
            printf("0\n");
            continue;
        }

        int ans = 0;
        ans += a[y2][x2];
        if (y1 - 1 >= 0) ans -= a[y1 - 1][x2];
        if (x1 - 1 >= 0) ans -= a[y2][x1 - 1];
        if (y1 - 1 >= 0 && x1 - 1 >= 0) ans += a[y1 - 1][x1 - 1];
        
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 101140
n=int(input())

al=["a","b","c","d","e","f","g","h","i","j"]

if n==1:
    print("a")
    exit()

#桁数がi
"""
[
    [[a]]
    [[aa],[ab]]
    [[aaa],[aba,abb],[abc]]
]


"""
result=[["a"]]
for i in range(n-1):
    temp=[]
    for item in result[i]:
        uniqAl=len(''.join(set(item)))
        for alp in al[:uniqAl+1]:
            temp.append(item+alp)
    result.append(temp)


for item in result[-1]:
    print(item)





Measured memory_bytes: 56028
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn=1e6+10;
int n,l[maxn],r[maxn];
/*
inline int ok1(long long x)
{
	int num1=0,num2=0;
	for (int i=1;i<=n;i++)
	if (r[i]<x) num1++;else if (l[i]>x) num2++;
	if (num1>=(n+1)/2) return -1;
	if (num2>=(n+1)/2) return 1;
return 0;
}
int calc1()
{
	//printf("lalal\n");
	long long l=1,r=1e9,rr=l,ll=r;
	while (l<=r)
	{
		long long mid=(l+r)>>1,k=ok1(mid);
		if (!k) rr=max(rr,mid);
		if (k>=0) l=mid+1;else r=mid-1;
	}
	l=1,r=1e9;
	while (l<=r)
	{
		long long mid=(l+r)>>1,k=ok1(mid);
		if (!k) ll=min(ll,mid);
		if (k<=0) r=mid-1;else l=mid+1;
	}
	//printf("lala %d %d\n",ll,rr);
return max(0ll,rr-ll+1);
}

inline int ok2(long long x)
{
	int num1=0,num2=0,num3=0,num4=0;
	for (int i=1;i<=n;i++)
	if (2*r[i]<x) num1++;else if (2*l[i]>x) num2++;
	if (num1>n/2) return -1;
	if (num2>n/2) return 1;
	for (int i=1;i<=n;i++) if (2*r[i]==x) num3++;
	for (int i=1;i<=n;i++) if (2*l[i]==x) num4++;
	if (num1+num3>num2+num4) return -1;
	if (num1+num3<num2+num4) return 1;
return 0;
}
int calc2()
{
	//printf("lalal %d\n",ok2(2));
	long long l=2,r=2e9,rr=l,ll=r;
	while (l<=r)
	{
		//printf("dasda %d %d\n",l,r);
		long long mid=(l+r)>>1,k=ok2(mid);
		if (!k) rr=max(rr,mid);
		//if (mid==6) printf("lsasdad %d\n",k);
		if (k>=0) l=mid+1;else r=mid-1;
	}
	l=2,r=2e9;
	while (l<=r)
	{
		long long mid=(l+r)>>1,k=ok2(mid);
		if (!k) ll=min(ll,mid);
		if (k<=0) r=mid-1;else l=mid+1;
	}
	printf("lala %lld %lld\n",ll,rr);
return max(0ll,rr-ll+1);
}
*/
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]);
	sort(l+1,l+n+1); sort(r+1,r+n+1);
	if (n&1)
	{
		for (int i=1;i<=n;i++)
		if (i==(n+1)/2)
		{
			printf("%d\n",r[i]-l[i]+1);
			return 0;
		}
	}
	else
	{
		for (int i=1;i<=n;i++)
		if (i==n/2)
		{
			printf("%d\n",r[i]+r[i+1]-l[i]-l[i+1]+1);
		}
	}
return 0;
}

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

#define ll long long
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll mod = 1000000007;
ll INF = 1e9 + 5;

int main(){
    FAST;
    ll n;
    cin >> n;
    vector<ll> h(n);
    for(int i=0;i<n;i++)
    {
      cin >> h[i];
    }
    vector<ll> dp(n,INF);
    dp[0] = 0;
    for(int i=0;i<n;i++)
    {
      for(int j=i+1;j<=i+2;j++)
      {
        if(j < n)
        {
          dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
      }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int N,K; cin>>N>>K;
    i64 x[N]; REP(i,N) cin>>x[i];
    i64 ans = 1e14;
    i64 xm[N], xp[N];
    REP(i,N) {
        xm[i] = x[i]-x[0];
        xp[i] = x[N-1]-x[N-1-i];
    }
    REP(i,N-K+1) {
        ans = min({xm[i+K-1]-xm[i]+abs(x[i]),xp[i+K-1]-xp[i]+abs(x[N-1-i]),ans});
    }
    cout<<ans<<endl;
}


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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
    int a,b,c,x,y;
    int ans=0;
    cin>>a>>b>>c>>x>>y;
    if(a+b>c*2){
        ans+=min(x,y)*c*2;
        int m=min(x,y);
        x-=m;
        y-=m;
    }
    //cout<<x<<y<<endl;
    if(x){
        if(a>c*2){
            ans+=x*c*2;
        }else{
            ans+=x*a;
        }
    }
    if(y){
        if(b>c*2){
            ans+=y*c*2;
        }else{
            ans+=y*b;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  int x;
  cin >> x;
  int ans = (x / 11) * 2;
  x %= 11;
  if(x) ans++;
  if(x > 6) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string str[51],x;
char tmp[1001];
int t[52];
int main()
{
	int i,n,sum=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s %d",tmp,&t[i]);
		str[i]=tmp;
	}
	scanf("%s",tmp);
	x=tmp;
	for(i=1;i<=n;i++)
		if(x==str[i])
			break;
	for(i++;i<=n;i++)
		sum+=t[i];
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ns = list(map(int,input().split()))
ans = 0

for i in range(n):
    minj = i
    for j in range(i,n):
        if(ns[j] < ns[minj]):
            minj = j
    if i != minj:
        ans += 1
        k = ns[i]
        ns[i] = ns[minj]
        ns[minj] = k
 
for i in range(n):
    if(i != n-1):
        print(ns[i], end = ' ')
print(ns[n-1])
print(ans)


Measured memory_bytes: 5600
N = int(input())
L = [[]]
for i in range(N):
    a,b=[int(i) for i in input().split()]
    L.append([a,b])
del L[0]
L = sorted(L, key=lambda x:(x[1]))

def main():
    time = 0
    for n in range(N):
        time += L[n][0]
        if time > L[n][1]:
            print("No")
            return
    print("Yes")
    return

main()


Measured memory_bytes: 87000
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

int n;

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read();
	int ans=0;
	rep(i,1,n) if (i&1) {
		int num=0;
		rep(j,1,i) if (i%j==0) num++;
		if (num==8) ans++;
	}
	printf("%d\n",ans);

	return 0;
}



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

using namespace std;

int main() {
    priority_queue<int> q;
    int n,m,h,x,k=1;
    long long sol=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>x;
        q.push(x);
    }
    while(k<=m){
        k++;
        h=q.top();
       // cout<<h<<endl;
        h=h/2;
        q.pop();
        q.push(h);
    }
    while(!q.empty()){
        sol+=q.top();
        q.pop();
    }
    cout<<sol;
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    char ans[h + 2][w + 2];
    for(int i = 0; i < h + 2; i++) {
        for(int j = 0; j < w + 2; j++) {
            if(i == 0 || i == h + 1) ans[i][j] = '#';
            else if (j == 0 || j == w + 1) ans[i][j] = '#';
            else {
                char c;
                cin >> c;
                ans[i][j] = c;
            }
        }
    }
    for(int i = 0; i < h + 2; i++) {
        for(int j = 0; j < w + 2; j++) {
            cout << ans[i][j];
        }
        cout << '\n';
    }
}

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

typedef long long ll;

ll memo[1000000]={0};
const ll MOD = 1000000000+7;

ll factorial(ll n){
    ll res = 1;
  	for(ll i = 2; i <= n; i++){
      res = (res * i) % MOD;
    }
  	return res;
}

ll power(ll a, ll n){
 	ll x = 1;
  	while(n > 0){
     	if (n & 1){
         	x = (a *x) % MOD; 
        }
      	a = (a * a) % MOD;
      	n >>= 1;
    }
  	return x;
}

ll comb(ll n, ll k){
 	ll a = factorial(n) % MOD;
  	ll b = factorial(n-k) % MOD;
  	ll c = factorial(k) % MOD;
  	return (((a * power(b, MOD-2)) % MOD) * power(c, MOD-2)) % MOD;
}

int main(void){

    ll X, Y;
    cin >> X >> Y;
    
    if((X+Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }else{
        ll n = (2*Y - X) / 3;
        ll m = (2*X - Y) / 3;
        if (n < 0 || m < 0){
            cout << 0 << endl;
            return 0;
        }else{
            cout << comb(m+n, m) << endl;
        }
    }
}


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

int main(){
    int n,q ;cin >> n >> q;
    atcoder::dsu uf(n);
    int t,u,v;
    for(int i=0;i<q; i++){
        cin >> t >> u >> v;
        if(t){
            if(uf.same(u,v))cout << 1 << endl;
            else cout << 0 << endl;
        }
        else uf.merge(u, v);
    }
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int(a.size())
typedef vector<int> vi;
#define pb push_back

int n,ans[100010],now[100010],a[100010],have[100010];
set<int> s,in[100010];

void chkmin() {
	for(int i=1;i<=n;i++)
		if(ans[i]!=now[i]) {
			if(now[i]<ans[i]) memcpy(ans,now,sizeof(ans));
			break;
		}
}

bool check() {
	for(int i=1;i<n;i++) if(a[now[i]]==now[i+1]) return 0;
	return 1;
}

void del(int x) {
	in[a[x]].erase(x);
}

void choose(int x,int i) {
	if(!have[a[x]]||sz(in[a[x]])!=n-i) now[i]=x;
	else now[i]=a[x];
}

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n;ans[1]=n+1;
	for(int i=1;i<=n;i++) cin>>a[i],s.insert(i),in[a[i]].insert(i),have[i]=1;
	for(int i=1;i+4<=n;i++) {
		int x=*s.begin();
		if((i==1||a[now[i-1]]!=x)) choose(x,i);
		else s.erase(x),choose(*s.begin(),i),s.insert(x);
		del(now[i]);have[now[i]]=0;s.erase(now[i]);//cerr<<now[i]<<' ';
	}
	int lo=max(1,n-3),p=lo;
	while(!s.empty()) now[p++]=*s.begin(),s.erase(s.begin());
	do {
		if(check()) chkmin();
	} while(next_permutation(now+lo,now+n+1));
	if(ans[1]==n+1) cout<<-1;
	else for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
	return 0;
}


Measured memory_bytes: 16512
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int n;double d,x,res;
int main(){
	scanf("%d%lf%lf",&n,&d,&x);
	for(;n;--n){
		res+=(d+((n<<1)-1)*x*0.5),
		d=(((n<<1)+2)*d+5*x)/(n<<1),
		x=(n+2)*x/n;
	}
	printf("%.12lf\n",res);
	return 0;
}

Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, A, B) = read!(i64, i64, i64);
    println!("{}", min(N * A, B))
}


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

using namespace std;

typedef long long ll;

template<typename T>
struct Gauss {
  int LOGN, sz;
  vector<T> basis;

  Gauss(int LOGN): LOGN(LOGN), sz(0), basis(LOGN) {}

  void insert(T mask) {
    for (int i = LOGN - 1; i >= 0; i--) {
      if (mask & (1LL << i)) {
        if (!basis[i]) {
          basis[i] = mask;
          ++sz;
          return;
        } else {
          mask ^= basis[i];
        }
      }
    }
  }

  T getMax() {
    T ans{};
    for (int i = LOGN - 1; i >= 0; i--) {
      ans = max(ans, ans ^ basis[i]);
    }
    return ans;
  }
};

int main() {
  ios::sync_with_stdio(false); cin.tie(NULL);
  int n;
  cin >> n;
  vector<ll> a(n);
  ll xorSum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    xorSum ^= a[i];
  }
  for (int i = 59; i >= 0; i--) {
    if (xorSum & (1LL << i)) {
      for (int j = 0; j < n; j++) {
        if (a[j] & (1LL << i)) a[j] -= (1LL << i);
      }
    }
  }
  Gauss<ll> g(60);
  for (int i = 0; i < n; i++) g.insert(a[i]);
  cout << g.getMax() + (xorSum ^ g.getMax()) << endl;
  return 0;
}




Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string s, t; cin >> s >> t;
    int ans = 10000;
    for(int i = 0; i+t.size() <= s.size(); i++){
        int tmp = 0;
        for(int j = 0; j < t.size(); j++){
            if(s[i+j] != t[j]) tmp++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    ll N;
    cin >> N;
    ll bai4=0;
    ll bai2=0;
    ll inp;
    REP(i,N){
        cin >> inp;
        if(inp % 4 == 0)
            bai4++;
        else if(inp % 2 == 0)
            bai2++;
    }
    //cout << bai2 << " " << bai4 << endl;
    //cout << N << endl;

    if(bai2 == N){
        cout << "Yes" << endl;
        return 0;
    }
    else if(bai2 >= 2)
        N -= (bai2-1);

    //cout << N << endl;

    if(bai4+1 < (N-bai4))
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define endl "\n"

using namespace std;

//ll const N = 32000;
int cnt[26];

int main()
{
    string w;
    int flag = 0;

    cin >> w;

    for(int i = 0; i < w.size(); i++)
    {
        cnt[w[i] - 97]++;
    }


    for(int i = 0; i < 26; i++)
    {
        if(cnt[i] % 2 != 0)
        {
            flag++;
            break;
        }
    }

    if(flag == 0)printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 3604
n = int(input())
s = [input() for i in range(n)]
march = {'M': [], 'A': [], 'R': [], 'C': [], 'H': []}

s = list(set(s))

a = b = 0
for i in s:
    if i[0] == 'M':
        march['M'].append(i)
    elif i[0] == 'A':
        march['A'].append(i)
    elif i[0] == 'R':
        march['R'].append(i)
    elif i[0] == 'C':
        march['C'].append(i)
    elif i[0] == 'H':
        march['H'].append(i)

nums = []
for i in march.values():
    if not len(i) == 0:
        nums.append(len(i))

count = 0
length = len(nums)
if length < 3:
    print(0)
else:
    for i in range(length):
        if length < 3:
            break
        v = nums[i]
        nums.pop(i)
        length = len(nums)
        for j in range(length):
            count += v * nums[j] * (sum(nums[j+1:]))
    print(count)



Measured memory_bytes: 15912
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m), n | m)
	{
		pint pd[12345];
		rep (i, n)
			scanf("%d%d", &pd[i].second, &pd[i].first);
		sort(pd, pd + n, greater<pint>());

		int res = 0;
		for (int i = 0; i < n; ++i)
		{
			int d = pd[i].second, p = pd[i].first;
			int use = min(d, m);
			m -= use;
			d -= use;

			res += d * p;
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

constexpr int64_t mod = 1000000007;
constexpr int64_t MAX = 2000005;

int64_t modInverse(int64_t a) {
    int64_t m = mod;
    int64_t m0 = m;
    int64_t y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1) {
        // q is quotient
        int64_t q = a / m;
        int64_t t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
        x += m0;

    return x;
}

int64_t F[MAX];
int64_t tP[MAX];
int64_t iF[MAX];

int64_t P(int64_t x, int64_t y) {
    int64_t sum = 0;
    for (int yy=0;yy<=y;++yy) {
        sum = (sum + F[x+yy+1]*iF[x+yy+1-x]%mod*iF[x]%mod) % mod;
    }
    return sum;
}

int main() {
    std::ios_base::sync_with_stdio(0);

    F[0] = 1;
    iF[0] = modInverse(1);
    tP[0] = 1;
    for (int i=1;i<MAX;++i) {
        F[i] = (F[i-1]*i) % mod;
        iF[i] = modInverse(F[i]);
        tP[i] = tP[i-1]*2 % mod;
    }
    int64_t x1,y1,x2,y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    --x1;
    --y1;

    int64_t sol = ((P(x2,y2) + P(x1,y1) - P(x1, y2) - P(x2, y1) ) % mod + mod ) % mod;
    std::cout << sol;
    return 0;
}

Measured memory_bytes: 47104
#include<stdio.h>
#include<string.h>
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int mid=b-c;
	if(mid>=0)
		printf("delicious\n");
	else if(mid<0&&mid>=-a)
		printf("safe\n");
	else
		printf("dangerous\n");
	return 0;
}

Measured memory_bytes: 128
def resolve():
    n = int(input())
    a = list(map(int, input().split()))

    mod = 10 ** 9 + 7
    s = 0
    sq = 0
    for i in range(n):
        s += a[i]
        sq += (a[i]) ** 2
        s %= mod
        sq %= mod
    s2 = (s ** 2) % mod

    ans = s2 - sq
    if ans < 0:
        ans += mod

    divs = pow(2, mod-2, mod)

    print((ans*divs)%mod)

resolve()

Measured memory_bytes: 93940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int n, k; cin >> n >> k;
    vector<int> v(n);
    int a[n];
    int ans = 1;
    n -= k;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    while(n > 0){
        n -= (k-1);
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <map>

int as[200005];

void increment(std::map<int,int>& str,int i,int D){
  while(++str[i]==D){
    str[i--]=0;
  }
}

int main(){
  int N;
  scanf("%d",&N);
  bool inc=true;
  for(int i=1;i<=N;i++){
    scanf("%d",&as[i]);
    if(as[i]<=as[i-1]){
      inc=false;
    }
  }
  if(inc){
    printf("1\n");
    return 0;
  }
  int low=1,high=N;
  while(high-low>1){
    int mid=(low+high)/2;
    std::map<int,int> str;
    for(int i=1;i<=N;i++){
      if(as[i]<=as[i-1]){
	while(str.size()&&str.rbegin()->first>as[i]){
	  str.erase(str.rbegin()->first);
	}
	increment(str,as[i],mid);
      }
    }
    if(str.count(0)){
      low=mid;
    }else{
      high=mid;
    }
  }
  printf("%d\n",high);
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	int i;
	cin >> a>>b;
	if (a > b) {
		for (i = 0; i < a; i++) {
			cout << b;
		}
		cout << endl;
	}
	else {
		for (i = 0; i < b; i++) {
			cout << a;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
a,b,n = map(int,input().split())
ans = 0
q = 0

if(n>=b):
  if((n+1)%b == 0):
    q = (n+1)/b - (n+1)//b
  else:
    tmp = (n//b)*b - 1
    q = tmp/b -tmp//b
else:
  q = n/b

print(int(a*q))

Measured memory_bytes: 61832
from collections import deque

N = int(input())
match_order = [deque(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]


q = deque(range(N))
finish_by = [0] * N
next_opponent = [None] * N

while q:
    a = q.popleft()
    # aの残りの順で一番初めに戦う対戦相手を取り出す
    b = match_order[a].popleft()
    if next_opponent[b] == a:
        finish_by[a] = finish_by[b] = max(finish_by[a], finish_by[b]) + 1
        # a,bについて、まだ対戦相手が残っているならキューに積む
        if match_order[a]:
            q.append(a)
        if match_order[b]:
            q.append(b)
    # bの残りの順で戦う相手がaではないなら、順番が来るまで待つ
    else:
        next_opponent[a] = b

# 対戦相手が残っている人がいる場合、条件通りに終わることができない
if any(match_order):
    print(-1)
else:
    print(max(finish_by))

Measured memory_bytes: 83804
#include <iostream>
#include <array>
#include <algorithm>

int main() {
	std::array<int, 10> heights;
	for (auto& val : heights)
		std::cin >> val;
	std::sort(heights.begin(), heights.end(), [](int x, int y){return x > y;});
	for (int i = 0; i < 3; ++i)
		std::cout << heights[i] << std::endl;
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define Rep(i,a,b) for(ll i=a;i<b;i++)
#define pb emplace_back
#define allv v.begin(),v.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<(#x)<<" "<<x<<endl
ll mod=1e9+7;
template<typename t>
ll Max(ll a,ll b)
{
    return (a>b)?a:b;
    
}
ll Min(ll a,ll b)
{
    return (a>b)?b:a;
}
ll power(ll a,ll b)
{
    ll p=1;
    a=a%mod;
    b=b%mod;
    while(b)
    {
        if(b&1)
        {
            p=((p%mod)*(a%mod))%mod;
        }
        a=((a%mod)*(a%mod))%mod;
        b=(b/2);
    }
    return p%mod;
}
ll h,w,k;
ll ma=1e15;
bool isValid(ll i,ll j)
{
    return (i>=1 && i<=h && j>=1 && j<=w);
}
ll direc[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int main()
{
    int t;
    t=1;
  //  cin>>t;
    while(t--)
    {
      //  ll h,w,k;
      cin>>h>>w>>k;
        ll x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        char mat[h+1][w+1];
        Rep(i,1,h+1)
        {
            Rep(j,1,w+1)
            cin>>mat[i][j];
        }
        ll dist[h+1][w+1];
        bool visited[h+1][w+1];
       // memset(dist,INT_MAX,sizeof(dist));
       for(ll i=1;i<=h;i++){
       for(ll j=1;j<=w;j++)
       {
           dist[i][j]=-1;
           visited[i][j]=false;
       }}
        dist[x1][y1]=0;
        visited[x1][y1]=true;
        queue<pair<ll,ll>> q;
        q.push(make_pair(x1,y1));
        while(!q.empty())
        {
            pair<ll,ll> curr=q.front();
            q.pop();
            ll i=curr.first;
            ll j=curr.second;
            for(ll p=0;p<4;p++)
            {
              for(ll Q=1;Q<=k;Q++)
              {
                ll i1=i+direc[p][0]*Q;
                ll j1=j+direc[p][1]*Q;
                if(isValid(i1,j1) && mat[i1][j1]!='@')
                {
                    if(dist[i1][j1]==-1)
                    {
                        dist[i1][j1]=dist[i][j]+1;
                        q.push(make_pair(i1,j1));
                    }
                    else
                    {
                        if(dist[i1][j1]>=(dist[i][j]+1))
                        dist[i1][j1]=dist[i][j]+1;
                        else
                        break;
                    }
                    
                    

                }
                else
                break;
              }
            }
            
        }
        
        cout<<dist[x2][y2]<<endl;
    }
    return 0;
}


Measured memory_bytes: 14892