akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

bool cmp(pair<int, int> x, pair<int, int> y) {
	return x.second > y.second;
}

int main()
{
	int n;
	map<int, int> a, b;
	vector<int> v1, v2;
	vector<pair<int, int>> va, vb;
	cin >> n;
	for(int i=0;i<n;i++) {
		int t;
		cin >> t;
		if(i % 2) {
			if(b[t] == 0)
				v2.push_back(t);
			b[t]++;
		} else {
			if(a[t] == 0)
				v1.push_back(t);
			a[t]++;
		}
	}
	for(int x:v1) {
		va.push_back({x, a[x]});
	}
	for(int x:v2) {
		vb.push_back({x, b[x]});
	}
	int k = (n+1)/2, m = n/2;
	sort(va.begin(), va.end(), cmp);
	sort(vb.begin(), vb.end(), cmp);
	int v = k - va[0].second,
	    u = m - vb[0].second;
	int ans = u + v;
	if(va[0].first == vb[0].first) {
		int u1, v1;
		if(va.size()>1)
			u1 = k - va[1].second;
		else
			u1 = k;
		if(vb.size()>1)
			v1 = m - vb[1].second;
		else
			v1 = m;
		ans = min(v+v1, u+u1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 6516
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

var (
	// ErrLineNotFound -
	ErrLineNotFound = errors.New("lines: line not found")
)

type onError int

const (
	onErrorPanic onError = iota
	onErrorError
)

// Lines represents multi line.
type Lines struct {
	r       io.Reader
	w       io.Writer
	onError onError

	store []string
}

// NewLines create lines from provided input reader.
func New(r io.Reader) *Lines {
	lines, err := newLines(r, ioutil.Discard, onErrorPanic)
	if err != nil {
		panic(err)
	}
	return lines
}

// Line represents single line.
type Line struct {
	store string
	field int
}

// Line return given n line.
func (ls *Lines) Line(n int) *Line {
	line, err := ls.line(n)
	if err != nil {
		panic(err)
	}
	return line
}

func (ls *Lines) line(n int) (*Line, error) {
	if n >= len(ls.store) {
		return nil, ErrLineNotFound
	}
	return &Line{store: ls.store[n]}, nil
}

func (l *Line) Ints() []int {
	ints, err := l.ints()
	if err != nil {
		panic(err)
	}
	return ints
}

func (l *Line) ints() ([]int, error) {
	var ints []int
	fields := strings.Fields(l.store)
	for _, s := range fields {
		i, err := strconv.Atoi(s)
		if err != nil {
			return nil, err
		}
		ints = append(ints, i)
	}
	return ints, nil
}

// Field specify current field scope.
func (l *Line) Field(n int) *Line {
	clone := l.clone()
	clone.field = n
	return clone
}

func (l *Line) Int() int {
	ints, err := l.ints()
	if err != nil {
		panic(err)
	}
	return ints[l.field]
}

func newLines(r io.Reader, w io.Writer, onError onError) (*Lines, error) {
	lines := &Lines{
		r:       r,
		w:       w,
		onError: onErrorError,
	}
	return lines, lines.init()
}

func (ls *Lines) init() error {
	s := bufio.NewScanner(ls.r)
	for s.Scan() {
		ls.store = append(ls.store, s.Text())
	}
	return s.Err()
}

func (l *Line) clone() *Line {
	clone := *l
	return &clone
}

func main() {
	lines := New(os.Stdin)
	num := lines.Line(0).Int()

	var answer string
	for i := num; i <= 999; i++ {
		s := strconv.Itoa(i)
		if isOK(s) {
			answer = s
			break
		}
	}
	fmt.Println(answer)
}

func isOK(s string) bool {
	cc := s[0]
	for _, c := range s {
		if c != rune(cc) {
			return false
		}
	}
	return true
}


Measured memory_bytes: 640
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,6);
  if(input[0] != "A"){
     myout("WA");
    return;
  }
  var cCount = 0;
  var cIndex = 0;
  for(var i = 2; i < input.length -1; i++){
    if(input[i] == "C"){
       cCount++;
      cIndex = i;
    }
  }
  if(cCount != 1){
    myout("WA");
    return;
  }
  var strlist = "abcdefghijklmnopqrstuvwxyz";
  for(var i = 0; i < input.length; i++){
    if(i == 0 || i == cIndex){
       continue;
    }
    if(strlist.indexOf(input[i]) == -1){
       myout("WA");
      return;
    }
  }
  myout("AC");
}
Main(myin());

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int N, X;
    cin >> X >> N;
    vector<int>p(N);
    for (int i = 0; i < N; i++) cin >> p[i];
    int i = 0;
    while (true) {
        auto result = std::find(p.begin(), p.end(), X - i);
        if (result == p.end()) {
            cout << X - i << endl;
            break;
        }
        result = std::find(p.begin(), p.end(), X + i);
        if (result == p.end()) {
            cout << X +i << endl;
            break;
        }
        i++;
    }

    
}



Measured memory_bytes: 3596
#include <iostream>
using namespace std;
typedef long long ll;

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

    ll nc, nd, nl;
    nc = (B - B/C) - ((A-1) - (A-1) / C);
    nd = (B - B/D) - ((A-1) - (A-1) / D);

    ll quot, rem; 
    int d = D;
    int c = C;
    ll G, L;
    while(true) {
        quot = d / c; 
        rem = d % c;
        if (rem == 0) {
            G = c;
            L = C * D / G;
            break;
        }

        d = c;
        c = rem;
    }

    nl = (B - B/L) - ((A-1) - (A-1) / L);

    cout << (nc + nd - nl) << endl;
    
    return 0;
}

Measured memory_bytes: 1144
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N+2];
		A[N+1] = A[0] = 0;
		int sum = 0;

		for (int i = 1; i <= N; i++) {
			A[i] = sc.nextInt();
		}

		for (int i = 1; i <= N+1; i++) {
			sum += Math.abs(A[i-1] - A[i]);
		}

		for (int i = 1; i <= N; i++) {
			int ans = sum + Math.abs(A[i-1] - A[i+1]) - Math.abs(A[i-1] - A[i]) - Math.abs(A[i] - A[i+1]);
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 66156
#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;

bool solve(ll n, string s)
{
    if (n % 2 != 0)
        return false;

    REP(i, n / 2)
    {
        if (s[i] != s[n / 2 + i])
            return false;
    }
    return true;
}
int main()
{
    ll N;
    string S;
    cin >> N >> S;
    if (solve( N, S))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	s, _ := r.ReadString('\n')
	s = strings.TrimRight(s, " \t\n")
	slice := strings.Split(s, " ")
	k := string(slice[0])
	K, _ := strconv.Atoi(k)

	pair := K / 2
	var odd = 0
	if K%2 == 0 {
		odd = K / 2
	} else {
		odd = K/2 + 1
	}

	fmt.Println(pair * odd)

}


Measured memory_bytes: 1772
#include<stdio.h>

int main(void) {
	int H, W;
	while (1) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)break;
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli r;
	cin>>r;
	cout<<fixed<<setprecision(6)<<2*pi*r;
	
	return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define ll long long
#define ii pair <int, int>
#define dl pair <ll, ll>
#define vi vector <int>
#define vl vector <ll>
#define vii vector <ii>
#define tam 300005

using namespace std;

vi r;
vi c;
vi ic;
vi ir;

bool compr(int a, int b) {
    return r[a] > r[b];
}

bool compc(int a, int b) {
    return c[a] > c[b];
}

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

    int h, w, m;
    cin >> h >> w >> m;
    int in1, in2;
    r.assign(h + 5, 0);
    c.assign(w + 5, 0);
    ir.assign(h + 5, 0);
    ic.assign(w + 5, 0);
    set <ii> pares;
    for (int i = 0; i < h + 5; i++) ir[i] = i;
    for (int i = 0; i < w + 5; i++) ic[i] = i;
    for (int i = 0; i < m; i++) {
        cin >> in1 >> in2;
        r[in1]++;
        c[in2]++;
        pares.insert({in1, in2});
    }
    sort(ir.begin(), ir.end(), compr);
    sort(ic.begin(), ic.end(), compc);
    while (r[ir.back()] < r[ir[0]]) ir.pop_back();
    while (c[ic.back()] < c[ic[0]]) ic.pop_back();
    for (int i = 0; i < ir.size(); i++) {
        for (int j = 0; j < ic.size(); j++) {
            if (pares.find({ir[i], ic[j]}) == pares.end()) {
                cout << r[ir[0]] + c[ic[0]] << "\n";
                return 0;
            }
        }
    }
    cout << r[ir[0]] + c[ic[0]] - 1 << "\n";
	return 0;
}

Measured memory_bytes: 21940
#include "iostream"
#include "vector"
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int max_l = 1, min_r = n + 1;
    for (int i = 0; i < m; ++i)
    {
        int l, r;
        cin >> l >> r;
        max_l = max(max_l, l);
        min_r = min(min_r, r);
    }
    if(min_r>=max_l)
    {
    cout <<  min_r - max_l + 1<<endl;
    }
    else
        cout<<"0"<<endl;
        return 0;
}


Measured memory_bytes: 256
#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>
using namespace std;
typedef long long unsigned int ll;

int main(){
    int a,b,c,k,max=0,count=0,max1=0,max2=0;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> k;
    if(a<k){
        max=max+a;
    }else{
        max1=k;
    }
    max2=a;
    count=k-a;

    if(a+b<=k){
        max=max+0;
    }else{
        max2=a;
    } 
    count=count-b;
    max=max-count;
    if(a>=k){
        cout << max1 <<endl;
    }else if (a+b>=k){
        cout << max2 <<endl;
    }else{
        cout << max <<endl;
    }
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    ll T,A;
    cin >> T >> A;
    for(int i = 1;i < n;i++)
    {
        ll t,a;
        cin >> t >> a;
        if(t < T && a >= A)
        {
            ll k = ceil((long double)T / t);
            t *= k;
            a *= k;
        }
        else if(t >= T && a < A)
        {
            ll k = ceil((long double)A / a);
            t *= k;
            a *= k;
        }
        else if(t < T && a < A)
        {
            ll k = max(ceil((long double)T / t),ceil((long double)A / a));
            t *= k;
            a *= k;
        }
        T = t;
        A = a;
    }
    cout << A + T << "\n";

    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
 
main = do
  [n, t] <- map read . words <$> getLine
  ts <- map read . words <$> getLine
  putStr . show . f t $ ts

f t [] = 0
f t [u] = t
f t (u:us) = ((head us - u) `min` t) + f t us 

Measured memory_bytes: 72060
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn count(s: &str,s_cnt: &str) -> i64 {
	let mut c = 0;
	let s_iter = s.split_whitespace().collect::<Vec<&str>>();
	for i in s_iter.iter() {
		if i.to_string() == s_cnt {
			c+=1;
		}
	}
	c
}

fn main () {
	let s = read_line();
	let n = s.split_whitespace().collect::<Vec<&str>>();

	let a = count(&s,n[0]);
	let b = count(&s,n[1]);
	let c = count(&s,n[2]);

	let r = a+b+c;
	if r == 3 {
		println!("3");
	}else if r == 5 {
		println!("2");
	}else if r == 9 {
		println!("1");
	}
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=100000+10;
int n,q;
struct Item
{
    char name[12];
    int time;
};

int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&q);
     queue<Item *> que;
    for(int i=0;i<n;i++)
    {
        getchar();
        Item *item=new Item();
        scanf("%s%d",&item->name,&item->time);
        que.push(item);
    }
    int total_time=0;
    while(!que.empty())
    {
        Item* curItem=que.front();que.pop();
        if(curItem->time>q)
        {
            curItem->time-=q;
            que.push(curItem);
            total_time+=q;
        }
        else
        {
            total_time+=curItem->time;
            printf("%s %d\n",curItem->name,total_time);
            delete curItem;
        }
    }
    return 0;
}

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

using namespace std;

#define F 		first
#define S 		second
#define ll 		long long
#define ld 		long double
#define pii		pair<int, int>
#define vi 		vector<int>
#define mii 	map<int, int>
#define umii 	unordered_map<int, int>
#define pb		push_back
#define mk		make_pair
#define all(a)	a.begin(), a.end()
#define ask(x) 	cerr << #x << " = " << x << "\n";
#define INF 	1000000007
#define hell 	998244353

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

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

	cout << max(0, b + c - a);

	return 0;
}

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


int main()
{
	int n, x;
	std::cin >> n >> x;
	int ar[110];
	int rslt = 0;
	int cost = 0;
	for (int i : ar)i = 0;
	
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
		rslt += 1;
		cost +=  ar[i];
	}
	std::sort(ar, ar + n);
	rslt += (x - cost) / ar[0];
	cout << rslt;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long lli;

const int MAXN = 100005;

lli N, S, W, Q;
lli a[MAXN];

void generate() {
  int g = S;
  for(int i=0; i<N; i++) {
    a[i] = (g/7) % 10;
    if( g%2 == 0 ) { g = (g/2); }
    else           { g = (g/2) ^ W; }
  }
}

lli solve25() {
  lli res = 0;
  for(lli i = 0, c = 0; i < N; ++i) {
    c += (a[i] != 0);
    if(a[i]%Q == 0) {
      res += c;
    }
  }
  return res;
}

lli solve() {
  lli res = 0;
  map<lli,lli> m;
  ++m[0];
  for(lli i = N-1, s = 0, t = 1; i >= 0; --i, t = t*10%Q) {
    s = (s + t*a[i]) % Q;
    if(a[i]) res += m[s];
    ++m[s];
  }
  return res;  
}

int main() {
  while(cin >> N >> S >> W >> Q && (N|S|W|Q)) {
    generate();
    if(Q == 2 || Q == 5) {
      cout << solve25() << endl;
    } else {
      cout << solve() << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 7596
import java.util.Scanner;
import java.util.Arrays;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long sum = 0;
    long[] scoreList = new long[N*3];
    for(int i =0; i < N*3; i++)
      scoreList[i] = sc.nextLong();
    
    Arrays.sort(scoreList);
    
    for(int i = 0; i < N; i++){
        int s = N * 3 - (1 + 2 * i);
    	sum += scoreList[s - 1];
    }
    System.out.println(sum); 
  }
}


Measured memory_bytes: 96632
//ABC079C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(4);
	a.at(0) = n/1000;
	a.at(1) = (n/100)%10;
	a.at(2) = (n%100)/10;
	a.at(3) = n%10;
	for(int i=0;i<(1 << 3);i++){
		int sigma = a.at(0);
		bitset<3> s(i);
		for(int j=0;j<3;j++){
			if(s.test(j)){
				sigma += a.at(j+1);
			}else{
				sigma -= a.at(j+1);
			}
		}
		if(sigma == 7){
			cout << a.at(0);
			for(int i=0;i<3;i++){
				if(s.test(i)){
					cout << "+";
				}else{
					cout << "-";
				}
				cout << a.at(i+1);
			}
			cout << "=7" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	mainA()
}

func mainA() {
	var a, b, c int64

	fmt.Scan(&a, &b, &c)
	var res = solveA(a, b, c)
	fmt.Print(res)

}

func solveA(a int64, b int64, c int64) int64 {

	var res = b / a

	if res > c {
		return c
	} else {
		return res
	}

}


Measured memory_bytes: 512
import math

import sys

sys.setrecursionlimit(10000)
INF = float('inf')

Q = int(input())
A, B = zip(*[list(map(int, input().split())) for _ in range(Q)])


def solve2(a, b):
    a, b = min(a, b), max(a, b)
    assert a <= b

    if a == b:
        # print('c', a, b)
        # a * b > (a-n) * (b+n) なので、
        # (a-1, b+1), (a-2, b+2), ..., (1, b*2-1) まで選ぶ。x, y 逆にしても同じなので * 2
        return (a - 1) * 2
    if a == b - 1:
        # print('d', a, b)
        # 上と同じ
        # (a-1, b+1), (a-2, b+2), ..., (1, b*2-1) まで選ぶ。x, y 逆にしても同じなので * 2
        # y == a == b-1 は選べない。(a+1)*(b-1) == a*b なので x は a 以下にする必要があるため
        return (a - 1) * 2

    # (a-1, b+1), (a-2, b+2), ..., (1, b+a-1) を選ぶ
    ret = a - 1
    c = int(math.sqrt(a * b))
    if c ** 2 == a * b:
        c -= 1
    if c * (c + 1) < a * b:
        # print('a', a, b)
        # (c, c+1), (c-1, c+2), ..., (a+1, c+(c-a)+1) まで
        ret += c - a
        # (c+1, c), (c+2, c-1), ..., (c+c-1, 1)
        ret += c
    else:
        # print('b', a, b)
        # (c, c), (c-1, c+1), ..., (a+1, c+(c-a)) まで
        ret += c - a
        # (c+1, c-1), (c+2, c-2), ..., (c+c-1, 1)
        ret += c - 1
    return ret


for a, b in zip(A, B):
    print(solve2(a, b))


Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;cin>>s;
    string dh="ATGC";
    ll ans=0;
    ll now=0;
    bool flag;
    rep(i,0,s.size()){
        flag=false;
        rep(j,0,4){
            if(s[i]==dh[j])flag=true;
        }
        if(!flag){
            now=0;
            continue;
        }
        now++;
        if(now>ans)ans=now;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,d,a;cin>>n>>d>>a;
    vector<pair<ll,ll>> xh;
    xh.resize(n);
    rep(i,n){
        cin>>xh[i].first>>xh[i].second;
    }
    sort(all(xh));
    ll ans = 0;
    queue<pair<ll, ll>> q; //pair<終了点、ダメージ>
    ll tot = 0; //今効果が残っているダメージ

    for(int le=0;le<n;le++){
        ll x=xh[le].first;
        ll h=xh[le].second;
        // ダメージ計算
        while(q.size() && q.front().first < x) {
            tot -= q.front().second;
            q.pop();
        }
        h -= tot; // 効果が残っているダメージをひく

        if(h > 0){
            ll t=(h+a-1)/a;
            ans += t;
            ll damage = t*a;
            tot += damage;
            q.emplace(x+2*d, damage);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

ll N,M,Q;
ll A[123],B[123],C[123],D[123];
ll a[12];

ll dfs(ll n, ll m){
    ll ret=0;
    if(n==N){
        REP(q,0,Q){
            if(a[B[q]]-a[A[q]]==C[q]){
                ret+=D[q];
            }
        }
    }else{
        REP(mm,m,M+1){
            a[n]=mm;
            ret=max(ret,dfs(n+1,mm));
        }
    }
    return ret;
}

int main(){
    N=ii();M=ii(),Q=ii();
    REP(i,0,Q){
        A[i]=ii()-1;
        B[i]=ii()-1;
        C[i]=ii();
        D[i]=ii();
    }
    oie(dfs(0,1));

    return 0;
}


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

using namespace std;

int write(int x,int y)
{
	for(int k=0;k<x-2;k++)
	{
		cout<<"#";
		for(int l=0;l<y-2;l++)
		{
			cout<<".";
		}
		cout<<"#";
		cout<<endl;
	}
	return(0);
}
int bar(int x)
{
	for(int i=0;i<x;i++)
		cout<<"#";
		cout<<endl;
	return(0);
}
int main()
{
	int a,b;
	unsigned int i=0;
	unsigned int j;
	vector<int> n;
	vector<int> m;
	
	while(1)
	{
		cin>>a>>b;
		
		if(a==0&&b==0)
			break;
		else
		{
		n.push_back(a);
		m.push_back(b);
		i++;
		}
	}
	for(j=0;j<i;j++)
	{
		bar(m[j]);
		write(n[j],m[j]);
		bar(m[j]);
		cout<<endl;
	}
	return(0);
}



Measured memory_bytes: 3120
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
using ll = long long;

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

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

	if (S == "SUN") { cout << 7 << endl; }
	if (S == "MON") { cout << 6 << endl; }
	if (S == "TUE") { cout << 5 << endl; }
	if (S == "WED") { cout << 4 << endl; }
	if (S == "THU") { cout << 3 << endl; }
	if (S == "FRI") { cout << 2 << endl; }
	if (S == "SAT") { cout << 1 << endl; }
}

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

int main() {
	int n, m, state[100000] = {}, cc = 0, penalty = 0;

	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int p;
		string s;
		cin >> p >> s;
		if (state[p] == -1) continue;
		if (s == "AC") {
			penalty += state[p];
			cc++;
			state[p] = -1;
		} else {
			state[p]++;
		}
	}
	cout << cc << ' ' << penalty << endl;
	return 0;
}




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

int main(void){
  int n, a, b, max_a = 0, max_b = 0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    if(max_a < a){
      max_a = a;
      max_b = b;
    }
  }
  cout << max_a + max_b << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int h,w,n,dp[1010][1010];
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
int gx[15],gy[15],cnt;
char fi[1010][1010];

int bfs(int x,int y){
	queue<pair<int,int> > q;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			dp[i][j]=1e9;
		}
	}
	dp[x][y]=0;
	q.push(make_pair(x,y));
	while(q.size()){
		auto p=q.front(); q.pop();
		if(p.first==gx[cnt]&&p.second==gy[cnt])break;
		for(int i=0;i<4;i++){
			int nx=p.first+dx[i],ny=p.second+dy[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&fi[nx][ny]!='X'&&dp[nx][ny]==1e9){
				dp[nx][ny]=dp[p.first][p.second]+1;
				q.push(make_pair(nx,ny));
			}
		}
	}
	return dp[gx[cnt]][gy[cnt]];
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> h >> w >> n;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> fi[i][j];
			if(fi[i][j]=='S'){
				gx[0]=i;
				gy[0]=j;
			}
			else if(fi[i][j]!='X'&&fi[i][j]!='.'){
				gx[fi[i][j]-'0']=i;
				gy[fi[i][j]-'0']=j;
			}
		}
	}
	ll ans=0;
	cnt=1;
	for(int i=0;i<n;i++){
		ans+=bfs(gx[i],gy[i]);
		cnt++;
	}
	cout << ans << endl;
}


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

using namespace std;
const int mx=2*1e5+7;
long long int arr[mx];
int main(void){
  int n;
  long long int ans=0;
  cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n,greater<int>());
    ans+=arr[0];
    n-=2;
    int i;
    for(i=1;i<=n/2;i++)
    {
        ans+=(arr[i]*2);
    }
    if(n&1 && n!=0)
        ans+=arr[i];

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


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

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

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int K; cin >> K;
  vector<bool> vis(K);
  deque<pair<int, int>> q;
  q.push_back({1, 1});
  while (true) {
    int v, c;
    tie(v, c) = q.front(); q.pop_front();
    if (vis[v]) continue;
    vis[v] = true;
    if (v == 0) {
      cout << c << '\n';
      return;
    }
    q.push_back({(v + 1) % K, c + 1});
    q.push_front({(v * 10) % K, c});
  }
}


Measured memory_bytes: 1152
from collections import defaultdict
n, m = map(int, input().split())
city = []
for i in range(m):
    p, y = map(int, input().split())
    city.append([i, p, y, 0])

city = sorted(city, key=lambda x: x[2])
d = defaultdict(int)
for i in range(m):
    d[city[i][1]] += 1
    city[i][3] = d[city[i][1]]
for _, p, _, x in sorted(city, key=lambda x:x[0]):
    print('%06d%06d' % (p, x))

Measured memory_bytes: 34380
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef unsigned long long lu;
const ll mod = 1e9 + 7, N = 1e5 + 35;
vll fac(N, -1);
ll factorial(ll n)
{
    if (n == 0)
        return 1;
    return fac[n] == -1 ? fac[n] = (n * factorial(n - 1)) % mod : fac[n];
}
ll power(ll a, ll b, ll m = mod)
{
    if (b == 0)
    {
        return 1 % m;
    }
    ll u = power(a, b / 2, m);
    u = (u * u) % m;
    if (b % 2 == 1)
    {
        u = (u * a) % m;
    }
    return u;
}
int32_t main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, ans = 1;
    vll arr;
    cin >> n >> m;
    for (ll i = 2; i * i <= m; i++)
    {
        if (m % i == 0)
        {
            ll cnt = 0;
            while (m % i == 0)
            {
                cnt++;
                m /= i;
            }
            arr.pb(cnt);
        }
    }
    if (m > 1)
    {
        arr.pb(1);
    }
    for (ll i = 0; i < sz(arr); i++)
    {
        ans = (ans * ((factorial(arr[i] + n - 1) * power((factorial(n - 1) * factorial(arr[i])) % mod, mod - 2)) % mod)) % mod;
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int>A(M);
  for(int i=0; i<M; i++)
    cin >> A.at(i);

  for(int i=0; i<M; i++)
    N-=A.at(i);

  if(N<0)
    cout << -1;

  else
    cout << N;
    
 
  }

Measured memory_bytes: 3680
#配るDP
n,k=map(int,input().split())
l=[0]*k
r=[0]*k
for j in range(k):
  l[j],r[j] = map(int,input().split())
p=998244353
dp=[0]*(n+max(r)+100)
dp[1]=1
dp[2]=-1
for i in range(1,n+1):
  dp[i] += dp[i-1]
  dp[i] %= p
  
  for lj,rj in zip(l,r):
    dp[i+lj] += dp[i]
    dp[i+lj] %= p
    dp[i+rj+1] -= dp[i]
    dp[i+rj+1] %= p
print(dp[n])

Measured memory_bytes: 24460
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String token1 = sc.next();
      if(N>=3200){
        System.out.println(token1);
      }else{
        System.out.println("red");
      }
  }
}

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

using namespace std;

int N;
int a[101];
int sum;
int ans;

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

  if(sum % N == 0) {
    int tmp = sum / N;
    for(int i = 0; i < N; i++) {
      int s = abs(tmp - a[i]);
      ans += s * s;
    }
  }
  else {
    if(sum % N > N - (sum % N)) {
      int tmp = sum / N + 1;
      for(int i = 0; i < N; i++) {
	int s = abs(tmp - a[i]);
	  ans += s * s;
      }
    }
    else {
      int tmp = sum / N;
      for(int i = 0; i < N; i++) {
	int s = abs(tmp - a[i]);
	ans += s * s;
      }
    }
  }
  cout << ans <<endl;
}
	
      
    

  


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
int root;
int *p = new int[500000];    //    p---|  Unit
int *left2 = new  int[500000]; // left2 --|--------> T
int *right2 = new int[500000];//right2---|
int *key = new int[500000];  // key----|
 
void Init(){
  rep(i,500000){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}
 
 
int FindRoot(){
  rep(i,n){
    if(p[i] == NIL){
      return i;
    }
  }
}
 
 
 
void TREE_INSERT(int z){
  int y = NIL; 
  int x = root;
 
  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }
 
}
 
void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}
 
void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}
 
 
int main(){
  int val;
  string op;
  int zr;                    
 
 
  scanf("%d",&n);
  Init(); 
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;        
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
  }
 
  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;
 
  return 0;
}

Measured memory_bytes: 8780
#include <iostream>
#include <algorithm>
using namespace std;
int a[200];
int b[10];
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a,a+n);
    int i;
    for(i = 0; i < n; i++)
    {
        if(a[i] < 400)
            b[1] = 1;
        else if(a[i] < 800)
            b[2] = 1;
        else if(a[i] < 1200)
            b[3] = 1;
        else if(a[i] < 1600)
            b[4] = 1;
        else if(a[i] < 2000)
            b[5] = 1;
        else if(a[i] < 2400)
            b[6] = 1;
        else if(a[i] < 2800)
            b[7] = 1;
        else if(a[i] < 3200)
            b[8] = 1;
        if(a[i] >= 3200)
            break;
    }
    int cnt = 0;
    for(int j = 0; j < 10; j++)
        if(b[j] == 1)
            cnt++;
    int sum = n-i;
    sum+=cnt;
    if(cnt == 0)
        cnt = 1;
    cout << cnt << ' ' << sum << endl;;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }

int main() {
	int t;
	// cin >> t;
    t = 1;

	while(t--) {
		int n;
		cin >> n;
        
        int var = ceil(n / 1000.0) * 1000;
        cout << (var - n) << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n % 1000 == 0) {
			System.out.println(0);
		} else {
			System.out.println((n/1000+1)*1000-n);
		}
	}

}


Measured memory_bytes: 35652
/*
Ashutosh Singh
Indian Institute of Information Technology Sri City
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

/*---------------------------------------------------------------------------------------------------*/

void solve()
{
 string s;
 cin >> s;
 int cnt=0;
 int len=0;
 f(i,s.length())
{
    if(s[i]=='R')
        cnt++;
    else
        {
            len=max(cnt,len);
            cnt=0;
        }
}
len=max(cnt,len);
cout << len << '\n';
  return;
} 

signed main()
{
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()	
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=1000000000000000000LL;
typedef pair<int,int> P;
int a[100010];
int c1[100010],c2[100010];
vector<P> v1,v2;
int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i%2){
            c1[a[i]]++;
        }else{
            c2[a[i]]++;
        }
    }
    for(int i=0;i<=100000;i++){
        if(c1[i]){
            v1.push_back(P(c1[i],i));
        }
    }
    for(int i=0;i<=100000;i++){
        if(c2[i]){
            v2.push_back(P(c2[i],i));
        }
    }
    sort(all(v1));
    sort(all(v2));
    int n1=v1.size(),n2=v2.size();
    int ans;
    if(v1[n1-1].second==v2[n2-1].second){
        int c,d;
        if(n1==1){
            c=0;
        }else{
            c=v1[n1-2].first;
        }
        if(n2==1){
            d=0;
        }else{
            d=v2[n2-2].first;
        }
        ans=n-max(v1[n1-1].first+d,v2[n2-1].first+c);
    }else{
        ans=n-v1[n1-1].first-v2[n2-1].first;
    }
    cout<<ans<<endl;
}

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

const int DIM = 100005;

vector<int> edg[DIM];

int dfs(int x, int f)
{
    int val = 0;
    for (int y : edg[x]) if (y != f)
        val ^= (dfs(y, x) + 1);
    return val;
}

int main(void)
{
    int n; cin >> n;
    for (int i = 1; i < n; ++i) {
        int x, y; cin >> x >> y;
        
        edg[x].push_back(y);
        edg[y].push_back(x);
    }
    
    cout << (dfs(1, 0) ? "Alice" : "Bob") << endl;
    return 0;
}



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

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
	IOS;
	long long int a,b;
	while(cin>>a>>b){
		if(a>b){
			cout<<a-1<<endl;
		}
		else{
			cout<<a<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for j in range(H):
        for i in range(W):
            if j == 0 or i == 0 or i == W-1 or j == H-1:
                print('#',end = '')
            else :
                print(".",end = '')
        print()
    print()
                


Measured memory_bytes: 7004
import java.util.Scanner;
import java.util.Locale;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();



    System.out.println(X + Y / 2);
  }
}


Measured memory_bytes: 21716
import java.util.*;

public class Main {
    static int INF = 1001001009;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        int left = 1;
        int right = 1001001009;
        
        while (left < right) {
            int center = (left + right) / 2;
            
            // System.out.println(left + " " + right);
            // System.out.println(center);
            boolean ok = false;
            
            // okがどうかの判定
            long count = 0;
            for (int i = 0; i < n; i++) {
                double tmp = (double)array[i];
                
                int tmpcount = (center + array[i] -1) / center;
                
                // int tmpcount = 1;
                // while ((double)array[i] / tmpcount > (double)center) {
                //     tmpcount++;
                // }
                tmpcount--;
                
                count += tmpcount;
                
            }
            
            // if (center == 265890893) {
            //     System.out.println(count);
            // }
            
            if (count <= k) ok = true;
            
            if (ok) {
                right = center;
            } else {
                left = center + 1;
            }
        }
        
        System.out.println(left);
    }
}

Measured memory_bytes: 59756
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int N;
    scanf("%d",&N);
    int num[105]={0};
    int n;
    for(int i=0;i<N;i++)
    {
        scanf("%d",&n);
        int j;
        for(j=0;j<=i;j++)
        {
            if(num[j]<=n)
             {
                 for(int k=i+1;k>j;k--)
              {
                 num[k]=num[k-1];
              }
                 num[j] = n;
                 break;
            }
        }

    }
    int sum = 0;
    for(int i=0;i<N;i++)
        {
            sum+=pow(-1,i)*num[i];
        }
        printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {/*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  
    int n,m;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++){
    	cin>>a[i];
    }
    if(n>=m){
    	cout<<0; return 0;
    }
    sort(a,a+m);
    vector<int> v;
    ll s=0;
    for(int i=0;i<=m-2;i++){
    	v.push_back(a[i+1]-a[i]);
    	s+=(ll)(a[i+1]-a[i]);
    }
    ll x=0;
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=0;i<n-1;i++){
    	x+=(ll)v[i];
    }
    cout<<s-x;
}

Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

int N, X;

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

int main() {
	scanf("%d %d", &N, &X);
	int res = 0;
	for (int i = 1; i <= N; i++) {
		int x;
		scanf("%d", &x);
		int d = abs(x - X);
		res = gcd(res, d);
	}
	printf("%d\n", res);
	return 0;
}

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

int main(){
	int n, q, query, x, t;
	
	cin>>n>>q;
	
	queue<int> hoge[n];
	
	for(int i = 0; i < q; i++){
		cin>>query>>t;
		
		if(query == 0){
			cin>>x;
			hoge[t].push(x);
		} else if(query == 1){
			if(!hoge[t].empty())cout<<hoge[t].front()<<endl;
		} else {
			if(!hoge[t].empty())hoge[t].pop();
		}
	}
	
	return 0;
}


Measured memory_bytes: 4304
#include<stdio.h>
#include<algorithm>
using namespace std;
int v[2000];
long long s[100001];
long long dp[2001][2001];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)scanf("%d",v+i);
	for(int i=0;i<b;i++)scanf("%lld",s+i+1);
	for(int i=0;i<b;i++)s[i+1]+=s[i];
	std::sort(v,v+a);
	for(int i=0;i<2001;i++)
		for(int j=0;j<2001;j++)
			dp[i][j]=999999999999999LL;
	dp[a][a]=0LL;
	for(int i=a;i>1;i--){
		for(int j=a;j>1;j--){
			int next=min(i,j)-1;
			dp[next][j]=min(dp[next][j],dp[i][j]+(s[v[i-1]]-s[v[next-1]-1])/c);
			dp[i][next]=min(dp[i][next],dp[i][j]+(s[v[j-1]]-s[v[next-1]-1])/c);
		}
	}
	long long ret=99999999999999999LL;
	for(int i=2;i<=a;i++){
		ret=min(ret,dp[i][1]+(s[v[i-1]]-s[v[0]-1])/c);
	}
	printf("%lld\n",ret);
}

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

// 插入此處

LL elapsed[55][2505];
bool vis[55][2505];

struct Edge {
    LL to;
    LL cost, time;
};
vector<Edge> edges[55];

struct Ex {
    LL silver, time;
} ex[55];

int main() {
    LL n, m, s;
    cin >> n >> m >> s;
    for (int i = 0; i < m; i++) {
        LL u, v, cost, ti;
        cin >> u >> v >> cost >> ti;
        edges[u].push_back({ v, cost, ti });
        edges[v].push_back({ u, cost, ti });
    }
    for (int i = 1; i <= n; i++) {
        LL si, ti;
        cin >> si >> ti;
        ex[i] = { si, ti };
    }
    using T = tuple<LL, LL, LL>; // elapsed, node_number, silver
    priority_queue<T, vector<T>, greater<T>> pq;
    pq.push(T{0, 1, min(s, 2500LL)});
    elapsed[1][min(s, 2500LL)] = 0;
    vis[1][min(s, 2500LL)] = false;
    while (!pq.empty()) {
        T x = pq.top(); pq.pop();
        LL e = get<0>(x);
        LL node_number = get<1>(x);
        LL silver = get<2>(x);
        // printf("e = %lld, node_number = %lld, silver = %lld\n", e, node_number, silver);

        if (vis[node_number][silver]) { continue; }
        vis[node_number][silver] = true;

        elapsed[node_number][silver] = e;

        for (auto v: edges[node_number]) {
            if (silver < v.cost) { continue; }
            if (vis[v.to][silver - v.cost]) { continue; }
            pq.push(T{e + v.time, v.to, silver - v.cost});
        }

        Ex exx = ex[node_number];
        if (!vis[node_number][silver + exx.silver]) {
            pq.push({e + exx.time, node_number, min(2500LL, silver + exx.silver)});
        }
    }
    for (int i = 2; i <= n; i++) {
        LL ans = 9999999999999;
        for (int j = 0; j <= 2500; j++) {
            if (vis[i][j]) {
                ans = min(ans, elapsed[i][j]);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 10436
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0066
{
    class Program
    {
        static void Main(string[] args)
        {
            const int gridSize = 3 * 3;
            int[][] winRowIndexs = { 
                new int[]{0,1,2}, 
				new int[]{3,4,5},  
				new int[]{6,7,8},

                new int[]{0,3,6}, 
				new int[]{1,4,7},  
				new int[]{2,5,8},
                
				new int[]{0,4,8}, 
				new int[]{2,4,6}
            };
            const char drowJudge = 'd';
            const char winOSide = 'o';
            const char winXSide = 'x';

            while (true)
            {
                var grid = Console.ReadLine();
                if (grid == null || grid.Length != gridSize) break;
                var result = drowJudge;
                foreach (var winRowIndex in winRowIndexs)
                {
                    if (grid[winRowIndex[0]] != grid[winRowIndex[1]]
                        || grid[winRowIndex[0]] != grid[winRowIndex[2]])
                    {
                        continue;
                    }
                    if (grid[winRowIndex[0]] != winOSide
                        && grid[winRowIndex[0]] != winXSide)
                    {
                        continue;
                    }
                    result = grid[winRowIndex[0]];
                    break;
                }
                Console.WriteLine(result);
            }
        }
    }
}

Measured memory_bytes: 5308
#include <stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int p[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&p[i]);
    }
    int count = 0;
    for(int i = 1;i < n-1;i++){
        if ((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])){
        count++;
        }
    }

    printf("%d",count);
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		if (Math.abs(a - c) <= d || Math.abs(a - b) <= d && Math.abs(b - c) <= d)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 23636