akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    static ArrayList<Integer>[] graph;
    static int[] res;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out,false);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        graph = new ArrayList[n];
        for(int i =0; i < n; i++) {
            graph[i] = new ArrayList<>();
        }
        for(int i= 0; i < n-1; i++) {
            int a = scanner.nextInt()-1, b = scanner.nextInt()-1;
            graph[a].add(b); graph[b].add(a);
        }
        res = new int[n];
        for(int i = 0; i < q; i++) {
            res[scanner.nextInt()-1]+= scanner.nextInt();
        }
        dfs(0,0);
        for(int i = 0; i < n; i++) {
            if (i > 0) out.print(" ");
            out.print(res[i]);
        }
        out.println();
        out.flush();
    }
    static void dfs(int v, int p) {
        for(int edge: graph[v]) {
            if (edge == p) continue;
            res[edge] += res[v];
            dfs(edge, v);
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

#define dump(a) cerr << #a << " " << a << endl
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using vi = vector<int>;
int s[101010];

int check(int n,int m,int x){
    int cnt=0,l=1;
    while(cnt<m){
        cnt++;
        if(l+x>s[n-1]){
            break;
        }
        if(s[0]>=l){
            l+=max(1,x-abs(l-s[0]));
        }else{
            int idx=lower_bound(s,s+n,l)-s;
            if(s[idx]==l){
                l+=max(1,x-abs(l-s[idx]));
            }else{
                if(s[idx]<l+x){
                    if(max(1,x-abs(l-s[idx]))<max(1,x-abs(l-s[idx-1]))){
                        l+=max(1,x-abs(l-s[idx-1]));
                    }else{
                        l+=max(1,x-abs(l-s[idx]));
                    }               
                }else{
                    l+=max(1,x-abs(l-s[idx-1]));
                }
                
            }
        }
    }
    return cnt;
}

int main()
{
    while(1){
        int n,m;
        cin>>n>>m;
        if(n==0)break;
        rep(i,n)cin>>s[i];
        int l=max(s[0],1),r=1001000,mm=(l+r)/2;
        if(check(n,m,l)<m){
            cout<<-1<<endl;
            continue;
        }
        while(mm!=l){
            if(check(n,m,mm)>=m){
                l=mm;
            }else{
                r=mm;
            }
            mm=(l+r)/2;
        }

        cout<<mm<<endl;
    }
    
    return 0;
}


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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

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

int main()
{
	int a[3];cin >> a[0] >> a[1] >> a[2];
	int ans = 100000000;
	
	for(int i = -60;i <= 100;i++){
		int tmp = 0;
		REP(j,3){
			if(a[j] > i){
				int A = a[j] - i;
				tmp += A;
			}
			else{
				int A = i - a[j];
				int B = A % 2;
				A -= B;
				tmp += A / 2;
				tmp += B*2;
			}
		}
		ans = min(ans,tmp);
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(){
    ll n,m=1e10,ans;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a[i];
        m = min(a[i],m);
    }
    ans = m;
    while(a.size()!=1){
        ll m1 = m;
        for(int i = 0;i < a.size();i ++){
            a[i] %= m;
            if(a[i]==0){
                a.erase(a.begin()+i);
                i --;
            }else{
                m1 = min(a[i],m1);
            }
        }
        a.push_back(m);
        m = m1;
    }
    ans = m;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	string s=in<string>();

	out(N>=3200 ? s : "red");
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int n;
   cin>>n;
   vector<int>v;
   for(int i=0;i<n;i++)
   {
       int x;
       cin>>x;
       v.push_back(x);
   }
   int z=0;
   for(int i=0;i<n;i++)
   {
       for(int j=i+1;j<n;j++)
       {
          z=z+(v[i]*v[j]);
       }
   }
   cout<<z<<endl;



    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n,l,t := input.Next3Ints()
  a := make([]Ant,n)
  w1 := 2*n
  for i:=0;i<n;i++ {
    x,w := input.Next2Ints()
    a[i] = Ant{i,x,w}
    w1 -= w
  }
  w2 := n-w1
  x1 := []int{}
  x2 := []int{}
  r := t/l
  for i:=0;i<n;i++ {
    if a[i].w == 1 {
      t := (int64(a[i].i)+int64(2*w2)*int64(r))%int64(n)
      a[i].i = int(t)
      x1 = append(x1,a[i].x)
    } else {
      t := (int64(a[i].i)-int64(2*w1)*int64(r))%int64(n)
      if t < 0 { t += int64(n) }
      a[i].i = int(t)
      x2 = append(x2,a[i].x)
    }
  }
  r = t%l
  for i:=0;i<n;i++ {
    if a[i].w == 1 {
      c := count(x2,a[i].x,a[i].x+2*r,l)
      a[i].i = (a[i].i+c)%n
      a[i].x = (a[i].x+r)%l
    } else {
      c := count(x1,a[i].x-2*r,a[i].x,l)
      a[i].i = (a[i].i-c)%n
      if a[i].i < 0 { a[i].i += n }
      a[i].x = (a[i].x-r)%l
      if a[i].x < 0 { a[i].x += l }
    }
  }
  ans := make([]int,n)
  for i:=0;i<n;i++ { ans[a[i].i] = a[i].x }
  for i:=0;i<n;i++ { fmt.Println(ans[i]) }
}
func count(x []int,fm,to,ln int) int {
  n := len(x)
  ret := 0
  if fm < 0 {
    d := -fm
    if d >= ln {
      d -= ln
      ret += n
    }
    ret += search(x,ln-d,ln)
    fm = 0
  }
  if to >= ln {
    d := to-ln
    if d >= ln {
      d -= ln
      ret += n
    }
    ret += search(x,0,d)
    to = ln-1
  }
  return ret+search(x,fm,to)
}
func search(x []int,fm,to int) int {
  lb := lowerBound(x,fm)
  ub := upperBound(x,to)
  return ub-lb
}
func lowerBound(x []int,d int) int {
  l := 0
  r := len(x)
  for l < r {
    m := (l+r)/2
    if x[m] < d {
      l = m+1
    } else {
      r = m
    }
  }
  return l
}
func upperBound(x []int,d int) int {
  l := 0
  r := len(x)
  for l < r {
    m := (l+r)/2
    if x[m] > d {
      r = m
    } else {
      l = m+1
    }
  }
  return l
}

type Ant struct { i,x,w int }

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) Next2Ints() (int,int) {
  s := strings.Split(i.NextLine()," ")
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}
func(i *Input) Next3Ints() (int,int,int) {
  s := strings.Split(i.NextLine()," ")
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  z,_ := strconv.Atoi(s[2])
  return x,y,z
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 200001
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        int a,b,c; cin>>a>>b>>c;
        int temp ;
        temp=a;
        a=b;
        b=temp;
        temp=a;
        a=c;
        c=temp;
        cout<<a<<" "<<b<<" "<<c;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define in inline
#define int long long
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9') {
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
map<int,int>v;
int n,m,ans,a[200002];
signed main(){
	n=read();
	for(re int i=1;i<=n;++i){
		a[i]=read();
	}
	for(re int i=n;i;--i){
		ans+=v[-(i+a[i])];
		++v[a[i]-i];
	}
	printf("%lld",ans);
}

Measured memory_bytes: 28036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);

  int A,B;
  cin >> A >> B;
  cout << A * B << endl;
  return 0;
}


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

int main(){
  long N;
  cin >> N;
  long long a,b,time=0;
  bool flag=1;
  vector<pair<long long,long long>> vec(N);
  for(long i=0;i<N;i++){
    cin >> a >> b;
    vec[i]=make_pair(b,a);
  }
  sort(vec.begin(),vec.end());
  for(long j=0;j<N;j++){
    time+=vec[j].second;
    if(time<=vec[j].first)
      continue;
    else{
      flag=0;
      break;
    }
  }
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3328
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        l: u64,
        r: u64,
    }
    let rr = std::cmp::min(r, l+2019);
    let mut m = std::u64::MAX;
    for i in l..rr+1 {
        for j in i+1..rr+1 {
            m = std::cmp::min(m, i*j % 2019)
        }
    }
    println!("{}", m);
}


Measured memory_bytes: 4352
n,k = map(int, input().split())
ttl = 0
res = []
for i in range(1,n+1):
  ttl = i
  cnt = 0
  while True:
    if ttl >= k:
      break
    ttl = ttl*2
    cnt+=1
  p = 0.5**cnt
  res.append(p)
ans = sum(res)/n
print(float(ans))

Measured memory_bytes: 6296
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
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; cin >> N;
	vector<pair<string,pair<int,int>>> A;
	rep(i,N)
	{
		int P; string S; cin >> S >> P;
		A.PB(MP(S,MP(-P,i+1)));
	}
	sort(ALL(A));
	rep(i,N)
	{cout << A.at(i).second.second << endl;}
}

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

using namespace std;

typedef pair < vector <int>, int> kotori;
const int INF = 1001001001;

map < vector <int>, int > memo;

void print(vector <int> arr)
{
	for (int i = 0; i < 8; i++){
		cout << arr[i] << " ";
	}
	cout << endl;
}
bool last(vector <int> arr){
	for (int i = 0; i < 8; i++){
		if (arr[i] != i) return false;
	}
	return true;
}
void calc(void)
{
	queue <kotori> q;
	int pos;
	vector <int> ar(8);
	for (int i = 0; i < 8; i++){
		ar[i] = i;
	}
	q.push(make_pair(ar, 1));
	memo.clear();
	while (!q.empty()){
		kotori hanayo = q.front(); q.pop();
		vector <int> now = hanayo.first;
		int steps = hanayo.second;

		if (memo.count(now)) continue;
		// print(now);
		memo[now] = steps;

		for (int i = 0; i < 8; i++){
			if (now[i] == 0){
				if (0 <= i && i <= 3){
					pos = i + 4;
					swap(now[i], now[pos]);
					if (!memo.count(now)) q.push(make_pair(now, steps + 1));
					swap(now[i], now[pos]);
				}
				if (4 <= i && i <= 7){
					pos = i - 4;
					swap(now[i], now[pos]);
					if (!memo.count(now)) q.push(make_pair(now, steps + 1));
					swap(now[i], now[pos]);
				}
				if (i != 3 && i != 7){
					pos = i + 1;
					swap(now[i], now[pos]);
					if (!memo.count(now)) q.push(make_pair(now, steps + 1));
					swap(now[i], now[pos]);
				}
				if (i != 0 && i != 4){
					pos = i - 1;
					swap(now[i], now[pos]);
					if (!memo.count(now)) q.push(make_pair(now, steps + 1));
					swap(now[i], now[pos]);
				}
			}
		}
	}
}

int main(void)
{
	vector <int> arr(8);

	calc();
	// cout << "ok" << endl;
	while (1){
		for (int i = 0; i < 8; i++){
			cin >> arr[i];
			if (cin.eof()) return 0;
		}
		cout << memo[arr] - 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;

int main(void){
    ll result = 0;
    
    ll A, B;
    cin >> A >> B;
    
    result = (A-1) * (B-1);
    
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

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


Measured memory_bytes: 256
def main():
    N = int(input())
    m = 1
    min_value = N**2
    while m**2 <= N:
        if N % m == 0:
            n = N // m
            value = (n - 1) + (m - 1)
            min_value = min([min_value, value])
        m += 1
    print(min_value)


if __name__ == '__main__':
    main()

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

int main(){
    char S[1000];
    int N=0;
    cin>>S;
    N = strlen(S);

    for(int a=0;a<N;a++){
        if(S[a]==S[N-1-a]){

        }else{
            cout<<"No"<<endl;
          return 0;
        }
    } 

    for(int b=0;b<N/2;b++){
        if(S[b]==S[N/2+1+b]){

        }else{
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
    return 0;
  
  

}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

std::string S;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> S;
	const char target[] = "keyence";
	int len = 0;
	while (len < 7 && S[len] == target[len]) {
		++len;
	}

	auto len1 = len;
	len = 6;
	while (len1<= len && S[S.size()-7 + len] == target[len]) {
		--len;
	}
	if (len < len1) {
		out << "YES" << endl;
	}
	else {

		out << "NO" << endl;
	}

	return 0;
}
#endif


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

namespace AtCoder {
    class Practice {
        static void Main() => CustomMain();

        static void Solve() {
            var a = ReadIntArray();
            var l = new List<int>();
            l.Add(a[0] + a[1]);
            l.Add(a[0] - a[1]);
            l.Add(a[0] * a[1]);
            WriteAnswer(l.Max());
        }


        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }

        static long GCD(long a, long b) {
            return b != 0 ? GCD(b, a % b) : a;
        }
    }
}

Measured memory_bytes: 13268
fun main(args: Array<String>) {
    val (countApple, flavor) = readLine()!!.split(" ").map { it.toInt() }

    when {
        flavor <= 0 && Math.abs(flavor) < countApple -> {
            print(calc(countApple, flavor, isEatZero = true))
        }
        else -> {
            print(calc(countApple, flavor, isEatZero = false))
        }
    }
}

fun calc(count: Int, flavor: Int, isEatZero: Boolean): Int {
    return when (isEatZero) {
        true -> calcSequence(flavor, flavor + count - 1, count)
        false -> {
            when {
                flavor >= 0 -> calcSequence(flavor + 1, flavor + count - 1, count - 1)
                else -> calcSequence(flavor, flavor + count - 2, count - 1)
            }
        }
    }
}

fun calcSequence(min: Int, max: Int, count: Int): Int = ((min + max) * count) / 2

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

using namespace std;

int main()
{
  int64_t N, D;
  cin >> N >> D;

  int64_t ans = N/(2*D + 1);

  if(N % (2*D + 1) != 0)
    {
      ++ans;
    }

  cout <<  ans  << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()
S = S[::-1]
candidacies = ["dream", "dreamer", "erase", "eraser"]
candidacies = [c[::-1] for c in candidacies]

fi_flg = False
while fi_flg is False:
  if S[:7] in candidacies:
    S = S[7:]
  elif S[:6] in candidacies:
    S = S[6:]
  elif S[:5] in candidacies:
    S = S[5:]
  else:
    fi_flg = True

if len(S) == 0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 78708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;
// const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// struct edge {int to, cost;};
// vector<edge> graph[MAX];
// bool visited[MAX];
// int dist[MAX];

int main() {
    // input
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i, n) {
        cin >> h[i];
    }
    // solve
    sort(h, h+n, greater<int>());
    ll cnt = 0;
    rep(i, n) {
        if (k > 0) k--;
        else cnt += h[i];
    }
    // output
    cout << cnt << endl;
}

Measured memory_bytes: 4392
#include <iostream>
#include <cstring>
#include <string> 
#include <vector>
using namespace std;


bool vis[15];
int a[15];

bool ok = false;


void dfs(int cnt, int last){
	if(ok){
		return;
	}
	if(cnt > 9)
		return;
	if(cnt <= 9){
		vector<int> ver;
		for (int i = 0; i < 10; i++){
			if(!vis[i]){
				ver.push_back(a[i]);
			}
		}
		bool flag = true;
		for (int i = 1; i < ver.size(); i++){
			if(ver[i] < ver[i - 1]){
				flag = false;
			}
		}
		if(flag){
			ok = true;
		}
		//return;
	}
	
	for (int i = cnt; i < 10; i++){
		if(a[i] > last){
			vis[i] = true;
			dfs(i + 1, a[i]);
			vis[i] = false;
		}
	}
	return;
}
 


int main(){
	int n;
	cin >> n;
	while(n--){
		ok = false;
		memset(a, 0, sizeof(a));
		memset(vis, false, sizeof(vis));
		for (int i = 0; i < 10; i++){
			cin >> a[i];
		}
		
		dfs(0, 0);
		if(ok){
			cout << "YES" << endl;
		}else cout << "NO" << endl; 
		
		
		
	}
	return 0;
}


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

int main(){
    ll n,y;
    cin>>n>>y;
    y/=1000;
    for(int a=0; a<=n; a++){
        for(int b=0; b<=n-a; b++){
            int c = n - a - b;
            if(10*a+5*b+c==y){
                cout<<a<<" "<<b<<" "<<c;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};
int n,m,i,j,t,dis[505][505],mp[505][505];
deque<int> qx,qy;
long long ans;
int main()
{
	read(n);
	fz1(i,n){
		dis[i][0]=dis[0][i]=dis[n+1][i]=dis[i][n+1]=0;
	}
	fz1(i,n)fz1(j,n){
		mp[i][j]=1;
		dis[i][j]=min(min(i,j),min(n-i+1,n-j+1));
	}
	fz1(t,n*n){
		int d,x,y;read(d);
		x=(d-1)/n+1;
		y=(d-1)%n+1;
		mp[x][y]=0;
		int s=dis[x][y];
		fz0k(i,4) s=min(s,dis[x+dx[i]][y+dy[i]]);
		if(s<dis[x][y]){
			dis[x][y]=s;
			qx.push_back(x);qy.push_back(y);
			while(!qx.empty()){
				int x=qx.front(),y=qy.front();
				qx.pop_front();qy.pop_front();
				fz0k(i,4){
					int xx=x+dx[i],yy=y+dy[i];
					if(dis[xx][yy]>dis[x][y]+mp[xx][yy]){
						dis[xx][yy]=dis[x][y]+mp[xx][yy];
						if(mp[xx][yy]){
							qx.push_back(xx);
							qy.push_back(yy);
						}
						else{
							qx.push_front(xx);
							qy.push_front(yy);
						}
					}
				}
			}
		}
		ans+=dis[x][y];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5760
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())

    # if k == 1:
    #     return 0

    amari = n % k
    sabun = abs(amari - k)

    if amari > sabun:
        return sabun

    return amari


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


Measured memory_bytes: 2940
a,b = map(int, input().split())

ans1 = str()
for i in range(0,b):
  ans1 += str(a)
ans2 = str()
for i in range(0,a):
  ans2 += str(b)

#print(ans1)
if ans1<ans2:
  print(ans1)
else:
  print(ans2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N, K;
    cin >> N >> K;
    long double prob = 0.0;
    for(int i=1; i<=N; i++){
        double subprob = 1.0;
        if(i>=K){
            prob += subprob;
        }
        else{
            int j=i;
            while(j<K){
                subprob *= 0.5;
                j *= 2;
            }
            prob += subprob;
        }
    }
    cout << fixed << setprecision(10) << prob /N << endl;
}

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  rep(i,M) {
    cin >> B.at(i);
  }
  vector<vector<int>> A(N, vector<int>(M));
  rep(i,N) {
    rep(j,M) {
      cin >> A.at(i).at(j);
    }
  }
  int answer = 0;
  rep(i,N) {
    int value = 0;
    rep(j,M) {
      value += A.at(i).at(j) * B.at(j);
    }
    value += C;
    if ( value > 0 ) {
      answer++;
    }
  }
  cout << answer << endl;
}

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

using namespace std;

int N, K;
long long int A[200006];

int main(void) {

	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	for (int i = K + 1; i <= N; i++) {
		if (A[i] > A[i - K]) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}

	return 0;
}

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

int main() {
	int a , b, c;
  	cin >> a >> b >> c;
  
  	int cos1 = abs(a - b), cos2 = abs(b - c), cos3 = abs(c - a);
  	int maximum = max(max(cos2,cos3), cos1);
  
  	int ans = cos1 + cos2 + cos3 - maximum;
  	cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
len_s = len(s)
sum_dict = {}

for i in range(2 ** (len_s)):
    total_sum = 0
    position = 0
    eq = ""
    for j in range(len_s):
        if position == 0:
            total_sum += int(s[position:position+1])
            eq += s[position:position+1]
        elif (i >> j) & 1:
            total_sum += int(s[position:position+1])
            eq += "+" + s[position:position+1]
        else:
            total_sum -= int(s[position:position+1])
            eq += "-" + s[position:position+1]
        position += 1
    if total_sum == 7:
        print(eq + "=7")
        break

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN 201
#define max(x,y) (x) < (y)?(y):(x)
char s[LEN], t[LEN];
int first,second;
int len1, len2;
int right(int left, char text[]){
    int r=left;
    char c;
    while(1){
        c=text[++r];
        if(c=='\"') break;
    }
    return r;
}
int search(void){
    int count=0;
    while(1){
        //printf("first=%d second=%d\n",first,second);
        if(first==len1-1 && second==len2-1) return 1;
        if(s[first]!=t[second]) return 0;
        else{
            if(s[first]=='\"'){
                int r1=right(first,s),r2=right(second,t);
                int n=max(r1-first,r2-second);
                for(int i=1;i<n;i++){
                    if(s[++first]!=t[++second]){
                        count++; break;
                    }
                }
                if(count == 2) return 0;
                if(r1==len1-1 && r2==len2-1) return 1;
                first=r1+1; second=r2+1;
            }
            else{
                first++; second++;
            }
        }
        if(first==len1-1 && second==len2-1) return 1;
    }
}
int main(void){
    while(1){
        first=second=0;
        scanf("%s",s);
        if(strcmp(s,".")==0) break;
        scanf("%s",t);
        len1=strlen(s); len2=strlen(t);
        int flag=1;
        //printf("%s\n%s\n",s,t);
        int n=max(len1,len2);
        for(int i=0; i<n; i++){
            if(s[i]!=t[i]) {flag=0; break;}
        }
        if(flag==1) printf("IDENTICAL\n");
        else{
            if(search()==0) printf("DIFFERENT\n");
            else printf("CLOSE\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2060
#include <cstdio>
#include <algorithm>
#include <utility>
#include <queue>
#include <vector>

#define INF 100

using namespace std;
typedef pair<int, int> P;

int main() {
    int K;
    scanf("%d", &K);
    vector<P> G[K]; // modKのグラフ 1たすか10倍するかの遷移
    for (int i=0; i<K; i++) {
        G[i].push_back(P(1, (i+1)%K));
        G[i].push_back(P(0, (i*10)%K));
    }
    int d[K];
    fill(d, d+K, INF); d[1] = 1;
    priority_queue< P, vector<P>, greater<P> > que;
    que.push(P(0, 1));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int now = p.second;
        if (d[now] < p.first) continue;
        for (size_t j=0; j<G[now].size(); j++) {
            int to = G[now][j].second; int newd = G[now][j].first + d[now];
            if (d[to] > newd) {
                d[to] = newd;
                que.push(P(d[to], to));
            }
        }
    }
    printf("%d\n", d[0]);
    return 0;
}

Measured memory_bytes: 6780
#[allow(unused_imports)]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars,
        t: Chars,
    }
    let mut ans = 0;
    for i in 0..s.len() {
        if s[i] != t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B;
  C = 0;

  for(int i=A; i<B+1; i++){
    if(i % 10 == i/10000 && (i/10)%10 == (i/1000)%10){
      C++; 
    }
  }
  cout << C << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	
	static int mx;
	static boolean[] visit;
	static ArrayList<ArrayList<Integer>> adj;
	
	public static void bfs(int s) {
		Queue<Integer> q=new LinkedList<Integer>();
		q.add(s);
		visit[s]=true;
		
		int ctr=1;
		
		while(!q.isEmpty()) {
			int u=q.poll();
			
			for(int e=0;e<adj.get(u).size();e++) {
				int v=adj.get(u).get(e);
				if(!visit[v]) {
					visit[v]=true;
					ctr++;
					q.add(v);
				}
			}
		}
		
		mx=Math.max(mx, ctr);
	}
	
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		Rf.init(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		
		int N=Rf.nextInt();
		int M=Rf.nextInt();
		
		mx=1;
		adj=new ArrayList<ArrayList<Integer>>();
		for(int r=0;r<N;r++) {
			adj.add(new ArrayList<Integer>());
		}
		
		for(int w=0;w<M;w++){
			int A=Rf.nextInt();
			int B=Rf.nextInt();
			A--;
			B--;
			adj.get(A).add(B);
			adj.get(B).add(A);
		}	
		
		visit=new boolean[N];
		Arrays.fill(visit,false);
		
		for(int w=0;w<N;w++) {
			if(!visit[w]) {
				bfs(w);
			}
		}
		
		pw.println(mx);
		pw.close();
		
	}

}

/** Class for buffered reading int and double values */
class Rf {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	/** call this method to initialize reader for InputStream */
	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	/** get next word */
	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens()) {
			// TODO add check for eof if necessary
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	
	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}


Measured memory_bytes: 69916
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>  
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
  int a,b,nom=0;
  cin>>a>>b;
  for (int i=a;i<=b;i++)
  if ((i / 10000 == i % 10) and (i % 10000 / 1000 == i % 100 / 10))
  nom++;
  cout<<nom;
  system ("pause");
  return 0;
  }

Measured memory_bytes: 504
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
#define yy cout<<"YES\n"
#define nn cout<<"NO\n"
#define rt return
#define ct continue
#define br break
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mmod 1000000007
#define pmod 998244353
using namespace std;
int gcd(int a,int b){
    while (b) b^=a^=b^=a%=b;
    return a;
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int bigmod(int b,int p,int m){
    int ans=1;
    b%=m;
    if (!b) return 0;
    while (p){
        if (p&1) ans=(ans*b)%m;
        p>>=1;
        b=(b*b)%m;
    }
    return ans;
}
int f[1000001];
void recur(){
	f[1]=1;
	for (int i=1; i<1000001; i++) f[i]=i;
	for (int i=4; i<1000001; i+=2) f[i]=2;
	for (int i=3; i*i<1000001; i++){
		if (f[i]==i){
			for (int j=i*i; j<1000001; j+=i){
				if (f[j]==j) f[j]=i;
			}
		}
	} 
}
int fac(int n){
	if (n==1) return 1;
	int ans=1;
	int d=f[n],c=1,j=n/f[n];
	while (j!=1){
		if (f[j]==d) c++;
		else {
			d=f[j];
			ans*=(c+1);
			c=1;
		}
		j/=f[j];
	}
	return ans*(c+1);
}
void solve(){
	recur();
	int n;
	cin>>n;
	int ans=0;
	for (int i=1; i<n; i++){
		ans+=fac(n-i);
	}
	cout<<ans;
	
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while (t--) solve();
}

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

int main() {
    int n, l;
    cin >> n >> l;
    string ans = "";
    vector<string> str(n);
    rep(i, n) cin >> str.at(i);
    sort(str.begin(), str.end());
    rep(i, n) ans += str.at(i);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader

fun main() = aising2019c()

@OptIn(ExperimentalStdlibApi::class)
fun aising2019c() = SimpleIO_aising2019c().exec {
    val (h, w) = readLine().split(" ").map { it.toInt() }
    val board = Array(h) { readLine().map { it == '#' }.toBooleanArray() }

    val around = listOf(-1 to 0, 1 to 0, 0 to -1, 0 to 1)
    val visited = Array(h) { BooleanArray(w) }
    var answer = 0L

    for (i in 0 until h) for (j in 0 until w) {
        if (!board[i][j] || visited[i][j]) continue
        visited[i][j] = true

        var blackCount = 0L
        var whiteCount = 0L

        val queue = ArrayDeque(listOf(i to j))

        while (queue.isNotEmpty()) {
            val (y, x) = queue.removeFirst()
            if (board[y][x]) blackCount++ else whiteCount++
            queue += around.map { y - it.first to x - it.second }
                .filter { (ny, nx) ->
                    ny in 0 until h && nx in 0 until w && board[ny][nx] != board[y][x] &&
                            visited.let {
                                if (it[ny][nx]) false else {
                                    it[ny][nx] = true
                                    true
                                }
                            }
                }
        }

        answer += blackCount * whiteCount
    }

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleIO_aising2019c(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private val sb: StringBuilder = StringBuilder()
    fun readLine(): String = br.readLine()!!
    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = print(any.toString() + separator)
    fun exec(action: SimpleIO_aising2019c.() -> Unit) = run {
        Thread(null, { action() }, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()
    }.run { kotlin.io.print(sb) }
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 69432
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[5000],d,f=0,g,h[5000],i,j,z;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&s[i]);
		f+=s[i];
		h[i]=s[i];
	}
	z=f;
	d=s[0];
	g=210000000;
	for(i=0;i<=d;i++){
		f=z;
		s[0]=i;
		for(j=1;j<a;j++) s[j]=h[j];
		for(j=0;j<a-1;j++){
			if(s[j]>0){
				s[j+1]-=s[j];
				s[j]=0;
			}
			else f+=(s[j]*-1);
		//printf("%d\n",s[j]);
		}
		//printf("%d\n",s[a-1]);
		//if(s[a-1]>0) f+=s[a-1];
		if(s[a-1]<0) f+=(s[a-1]*-1);
		//printf("\n");
		if(g>f) g=f;
	}
	printf("%d\n",g);
	return 0;
}

Measured memory_bytes: 2800
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=input().split()
  for i in range(N):
    p[i]=int(p[i])
    p[i]=X-p[i]
  i=0
  if i in p:
    while True:
      i+=1
      if i in p:
        if -i in p:
          pass
        else:
          print(X+i)
          break
      else:
        print(X-i)
        break
  else:
    print(X)

Measured memory_bytes: 9204
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Drawing;
using System.Runtime.CompilerServices;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, M) = Slice2<long>();
            long L = long.MinValue, R = long.MaxValue;
            for (var i = 0; i < M; ++i)
            {
                var (l, r) = Slice2<long>();
                L = Max(L, l);
                R = Min(R, r);
            }
            WriteLine(Max(0, R - L + 1));
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 45840
//#include<iostream>
//#include<vector>
//#include<math.h>
#include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i = 0; i<(int)(n);i++)
#define rep2(i,n) for(int i = 2; i<(int)(n); i++)

int main (void){

    int N, K;
    cin >> N >> K;
    
    vector <int> a (N);

    rep(i, N) cin >> a[i];

    sort(a.begin(), a.end());

    int head,tail, score=10000000000, min , max, temp;

    rep(i, N-K+1){
        head = i;
        tail = i + K-1;
        min = a[head];
        max = a[tail];

        temp = max -min;

        if(score>temp) score = temp;


    }

    cout << score;


}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	cin >> s;
	
	int n = s.size();
	map<int, int> mp;
	for(int i = 0; i < n; ++i) {
		mp[s[i] - '0']++;
	}
	
	cout << 2 * min(mp[0], mp[1])<< endl;
	
	return 0;
}


Measured memory_bytes: 512
n = int(input())
s_array = [input() for x in range(n)]
a_count = 0
b_count = 0
ab_count = 0
flag = False
for s in s_array:
    if s[-1] == "A" and s[0] != "B":
        a_count += 1
    elif s[0] == "B" and s[-1] != "A":
        b_count += 1
    elif s[0] == "B" and s[-1] == "A":
        ab_count += 1
    else:
        flag = True

res = sum([x.count("AB") for x in s_array])

if n == 1:
    print(res)
elif ab_count == 0:
    print(res + min(a_count, b_count))
elif a_count == 0 and b_count == 0:
    print(res - 1 + ab_count)
else:
    print(res + min(a_count, b_count) + ab_count)


Measured memory_bytes: 9788
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;
const long double E = 0.00000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << h2*60+m2-h1*60-m1-k << endl;
    return 0;
}


Measured memory_bytes: 3652
N = int(input())
max1 = [0,[]]
max2 = 0
for i in range(N):
  a = int(input())
  if a > max1[0]:
    max2 = max1[0]
    max1[0] = a
    max1[1] = [i]
  elif a == max1[0]:
    max1[1].append(i)
  elif a > max2:
    max2 = a

if len(max1[1]) == 1:
  max1_idx = max1[1][0]
  for i in range(0,max1_idx):
    print(max1[0])
  print(max2)
  for i in range(max1_idx + 1 , N):
    print(max1[0])
else:
  for i in range(N):
    print(max1[0])
  

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

int calcNumOfCombination(int n, int r){
        int num = 1;
        for(int i = 1; i <= r; i++){
            num = num * (n - i + 1) / i;
        }
        return num;
    }

int main(){
    ll N,M;
    cin >> N >> M;
    int a = calcNumOfCombination(N,2);
    int b = calcNumOfCombination(M,2);
    cout << a+b << endl;
}


Measured memory_bytes: 256