akhauriyash/Code-Regression huggingface dataset:
<?php

fscanf(STDIN, "%d %d", $n, $k);
$list = explode(" ", trim(fgets(STDIN)));

for($i = $n; $i <= 100000; $i++){

    $na = str_split($i);
    $cnt = 0;

    foreach($na as $value){

        if(in_array($value, $list)){
            continue 2;
        };

        $cnt += 1;

        if($cnt == count($na)){
            print($i);
            exit;
        }

    }

}

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

long long a[100001], n, k, sum, p, m, d;

int main(){
	cin >> n;
	m = (n * (n + 1)) / 2;
	for(int i = 0; i < n; i++) cin >> a[i], sum += a[i];
	if(sum % m){
		cout << "NO";
		return 0;
	}
	k = sum / m;
	for(int i = 0; i < n; i++){
		d = a[(i + 1) % n] - a[i];
		if(k < d || (k - d) % n){
			cout << "NO";
			return 0;
		}
		p += (k - d) / n;
	}
	if(k == p) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
long long fibo(int n){
    long long fibodp[200];
        fibodp[0]=1;
        fibodp[1]=1;
        for(int i=2; i<=n; i++){
            fibodp[i]=fibodp[i-1]+fibodp[i-2];
        }
        return fibodp[n];
}
int main(void){
    int n;
    
    cin>>n;
    std::cout << fibo(n) << std::endl;
    return 0;
    
}



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

typedef pair<int,int> P;
typedef pair<P,P> PP;

int main() {
    int H,W,i,j;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    vector<pair<P,P>> r;

    for(i=0; i<H; i++)
        for(j=0; j<W; j++)
            cin >> a.at(i).at(j);
    
    for(i=0; i<H; i++) {
        for(j=0; j<W; j++) {
            if(i+j == H+W-2)
                continue;
            if(i%2==0 && a.at(i).at(j)%2) {
                if(j != W-1) {
                    a.at(i).at(j+1)++;
                    r.push_back(PP(P(i+1,j+1), P(i+1,j+2)));
                } else {
                    a.at(i+1).at(j)++;
                    r.push_back(PP(P(i+1,j+1), P(i+2,j+1)));
                }
                a.at(i).at(j)--;
            }
            if(i%2 && a.at(i).at(W-1-j)%2) {
                if(W-j != 1) {
                    a.at(i).at(W-2-j)++;
                    r.push_back(PP(P(i+1,W-j), P(i+1,W-1-j)));
                } else {
                    a.at(i+1).at(W-1-j)++;
                    r.push_back(PP(P(i+1,W-j), P(i+2,W-j)));
                }
                a.at(i).at(W-1-j)--;
            }
        }
    }

    cout << r.size() << endl;
    for(auto x : r)
        cout << x.first.first << " " << x.first.second << " " << x.second.first << " " << x.second.second << endl;
}

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

int main(){
    int n; cin>>n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    vector<vector<char>> ss(n,vector<char>(10));
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            ss[i][j]=s[i][j];
        }
        sort(ss[i].begin(),ss[i].end());
        for(int j=0;j<10;j++){
            s[i][j]=ss[i][j];
        }
    }
    sort(s.begin(),s.end());
    ll a=0; ll ans =0;
    for(int i=1;i<n;i++){
        
        if(s[i]==s[i-1]) {a++;
            if(i==n-1){ans+=a*(a+1)/2;}
        }else if(a>0) {ans+= a*(a+1)/2; a=0;}
    }
    cout <<ans<<endl;

}

Measured memory_bytes: 14848
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
cin>>x;
if(x>=400 && x<=599)
cout<<"8";
else if(x<=799)
cout<<"7";
else if(x<=999)
cout<<"6";
else if(x<=1199)
cout<<"5";
else if(x<=1399)
cout<<"4";
else if(x<=1599)
cout<<"3";
else if(x<=1799)
cout<<"2";
else if(x<=1999)
cout<<"1";

return 0;
}

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

using namespace std;

int main() {
    long long N, u, v, ans;
    cin >> N;
    
    //https://noimin.hatenablog.com/entry/2020/07/07/235034
    //ans = N*(N+1)*(N+2)/6;
    ans = (N*(N+1)*(2*N+1)/6 + N*(N+1)/2) / 2;
    for(int i=0;i<N-1;++i) {
        cin >> u >> v;
        if(u < v) ans -= u*(N-v+1);
        else ans -= v*(N-u+1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3580
var lines =　[];
var readline = require('readline');

rl = readline.createInterface({
  input: process.stdin,
  output:process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});

rl.on('close',function(){
  var n=Number(lines[0]);
  var a=lines[1].split("");
  var b=lines[2].split("");
  var c=lines[3].split("");
  var count=0;

    while(1){
    for(var i = 0;i<n;i++){
      if(a[i]===b[i] && b[i]===c[i]){}
      else if(a[i]===b[i]){
        c[i]=a[i];
        count++;
      }
      else if(a[i]===c[i]){
        b[i]=a[i];
        count++;
      }
      else if(b[i]===c[i]){
        a[i]=b[i];
        count++;
      }
      else{
        a[i]=b[i];
        count++;
      }
    }
    if(a.toString() === b.toString() && b.toString() === c.toString()){break;}
  }
  console.log(count);
});


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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

int main() {
    ll n;
    cin >> n;
    ll a[n];
    map<ll, ll> mp;

    repll(i, n) {
        cin >> a[i];
        mp[a[i]] = i;
    }

    ll ans = 0;

    set<ll> st;
    st.insert(-1);
    st.insert(n);

    repll2(num, n) {
        ll i = mp[num];
        auto itr = st.upper_bound(i);
        ll r = *itr;
        itr--;
        ll l = *itr;
        ans += (i - l)*(r - i) * num;
        st.insert(i);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 23680
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main(){
    int N;
    while((N = readln.chomp.to!int, N)){
        int[] sum = new int[N];
        foreach(i; 0..N){
            int[] data = readln.chomp.split.map!(to!int).array;
            sum[] += data[];
            data.map!(a => (writef("%5d", a), 0)).array;
            writefln("%5d", data.reduce!"a + b");
        }
        sum.map!(a => (writef("%5d", a), 0)).array;
        writefln("%5d", sum.reduce!"a + b");
    }
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t a,b,c;
  cin>>a>>b>>c;
  vector<int64_t> t;
  t={a,b,c};
  sort(t.begin(),t.end());
  if(a%2==0||b%2==0||c%2==0){
    cout<<0;
  }
  else{
   cout<<t.at(0)*t.at(1);
  }
}


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

int main() {
    int n; cin >> n;
    unordered_set<int> d;
    for(int i = 0; i < n; i ++) {
        int tmp; cin >> tmp;
        d.insert(tmp);
    }
    cout << d.size() << endl;
}

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

int main(){
    int n, v;
    scanf("%d", &n);
    std::vector<int> dp(3, 0);
    for(int d=0; d<n; ++d){
      std::vector<int> tmp_dp(3, 0);
      for(int i=0; i<3; ++i) {
        scanf("%d", &v);
        for(int j=0; j<3; ++j){
          if(i!=j){
            tmp_dp[i] = std::max(tmp_dp[i], dp[j] + v);
          }
        }
      }
      dp = tmp_dp;
    }
    printf("%d\n", std::max({dp[0], dp[1], dp[2]}));
    return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

const ll mod = 1e9 + 7;
const int mxn = 1e5 + 5;

int n;
vector<int> adj[mxn];
vector<ll> dpW(mxn,1), dpB(mxn,1);

void dfs(int u, int parent)
{
    for(int v : adj[u])
    {
        if(v == parent) continue;
        dfs(v,u);
        dpW[u] *= (dpW[v]+dpB[v]);
        dpB[u] *= dpW[v];
        dpW[u] %= mod;
        dpB[u] %= mod;
    }
}

int main()
{
  	FASTIO
    cin >> n;
    int x, y;
    for(int i=0; i<n-1; i++)
    {
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(0,-1);
    cout << (dpW[0]+dpB[0])%mod << "\n";
    return 0;
}

Measured memory_bytes: 17096
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	#S = int(input())
	#S = list(input())
	N,L = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	azi = []
	for i in range(1, N+1):
		azi.append(i+L-1)

	tmp = bisect_left(azi, 0)

	ans = 0
	flg = False
	for i,val in enumerate(azi):
		if i == tmp:
			flg = True
			continue
		ans += val
	
	if flg == False:
		ans -= azi[-1]
	print(ans)

if __name__ == "__main__":
	main()

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

#define fi first
#define se second
#define sz(v) (int)((v).size())
#define pb push_back
#define sq(x) (x)*(x)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int MAX = 1e5 + 5;

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

	int n; ll k; cin >> n >> k;
	vector<int> adj(n);
	for (int i=0; i<n; i++){
		cin >> adj[i];
		adj[i]--;
	}

	int pos=0, lboucle, iboucle, depBoucle;
	vector<int> vuA(n,-1), ordre={1};
	vuA[0]=0;
	for (int t=1; t<=n+1; t++){
		pos = adj[pos];
		//cout << "t : " << t << "pos : " << pos+1 << "\n";
		if (vuA[pos]>=0){
			iboucle = t;
			depBoucle = vuA[pos];
			lboucle = t-vuA[pos];
			break;
		}
		else{
			vuA[pos]=t;
			ordre.pb(pos+1);
		}
	}
	//cout << iboucle << " " << lboucle << "\n";
	if (k<iboucle)
		cout << ordre[k] << "\n";
	else{
		ll i = (k-iboucle)%lboucle;
		cout << ordre[depBoucle+i] << "\n";
	}
}


Measured memory_bytes: 5852
h,w=map(int,input().split())
a=['.'*(w+2)]+['.'+input()+'.' for _ in range(h)]+['.'*(w+2)]
for i in range(h):
  for j in range(w):
    if a[i][j]=='#':
      if not(a[i+1][j]=='#' or a[i-1][j]=='#' or a[i][j+1]=='#' or a[i][j-1]=='#'):
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 65188
#include <bits/stdc++.h>
#define mod 1e9+7
#define pb push_back
#define F first
#define S second

using namespace std;
typedef long long ll;
typedef long double ld;
int dx[4] = {-1, 0, +1, 0}, dy[4] = {0, -1, 0, +1};

deque <char> dq;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans = a * (n / (a + b));
    n %= (a + b);
    if (n <= a) ans += n;
    else ans += a;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, m, dist[300000];
vector<vi> e;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> m;
	e.resize(n);
	rep(i, m){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
	}
	int s, t; cin >> s >> t; s--; t--;
	
	rep(i, 3 * n) dist[i] = inf;
	queue<int> q;
	q.push(3 * s);
	dist[3 * s] = 0;
	while(!q.empty()){
		int cost = dist[q.front()], v = q.front() / 3; q.pop();
		for(int i : e[v]){
			int to = i * 3 + (cost + 1) % 3;
			if(dist[to] <= cost + 1) continue;
			dist[to] = cost + 1;
			q.push(to);
		}
	}
	if(dist[3 * t] < inf){
		cout << dist[3 * t] / 3 << endl;
	}
	else{
		cout << -1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int W = sc.nextInt();
			int[] hist = new int[11];
			for (int i = 0; i < N; ++i) {
				hist[sc.nextInt() / W]++;
			}
			int maxV = 0;
			int maxI = 0;
			for (int i = 0; i < 11; ++i) {
				maxV = Math.max(maxV, hist[i]);
				if (hist[i] > 0) maxI = i;
			}
			double ans = 0.01;
			for (int i = 0; i <= maxI; ++i) {
				ans += (1 - i * 1.0 / maxI) * hist[i] / maxV;
			}
			System.out.printf("%.9f\n", ans);
		}
	}
}

Measured memory_bytes: 23728
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long n;
    long long ans=0;
    long long tmp=2;
    
    cin >> n;
    
    for(long long i=1; tmp<=n; i++){
        
        tmp *= 5;
        ans += n / tmp;
        
    }
    
    if(n%2==0){
        
        cout << ans << endl;
        
    } else {
        
        cout << "0" << endl;
        
    }
    
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

void solve1();
int score1();
int change(int, int, int);
vector<int> changeT(vector<int>);

int ti;
int D;
int sumC;
int k = 26;
int score;
vector<int> c(k), t;
vector<vector<int>> s;

int main() {
	srand((unsigned)time(NULL));
	cin >> D;
	s.resize(D);

	rep(i, k) {
		cin >> c[i];
		sumC += c[i];
	}
	rep(i, D) {
		s[i].resize(k);
		rep(j, k) {
			cin >> s[i][j];
		}
	}
	t.resize(D);

	rep(i, D) {
		t[i] = rand() % 26;
	}
	score = score1();

	solve1();

	rep(i, D) {
		cout << t[i] + 1 << endl;
	}

}

void solve1() {

	ti = clock();

	while (1) {
		double time = (double)(clock() - ti) / CLOCKS_PER_SEC;
		if (time > 1.9) {
			break;
		}

		int no = 5;
		int sz = score;
		vector<P> temp;
		rep(i, no) {
			int d = rand() % D;
			int q = rand() % k;
			sz = change(sz, d, q);
			temp.push_back(mp(d, q));
		}
		if (sz > score) {
			score = sz;
			rep(i, temp.size()) {
				t[temp[i].first] = temp[i].second;
			}
		}
		
	}
}

vector<int> changeT(vector<int> t) {
	int no = 5;
	rep(i, no) {
		int d = rand() % D;
		int q = rand() % k;
		t[d] = q;
	}
	return t;
}

int score1() {
	//最後にコンテストが行われた日
	vector<int> last(k, -1);
	int ans = 0;

	rep(i, D) {
		ans += s[i][t[i]];
		last[t[i]] = i;
		rep(j, k) {
			ans -= c[j] * (i - last[j]);
		}
		//cout << ans << endl;
	}
	return ans;
}

int change(int score, int d, int q) {
	score += s[d][q] - s[d][t[d]];
	int x = d + 1;
	while (x != D && t[x] != q) {
		x++;
	}
	int y = d - 1;
	while (y >= 0 && t[y] != q) {
		y--;
	}
	score += c[q] * (d - y) * (x - d);

	x = d + 1;
	while (x != D && t[x] != t[d]) {
		x++;
	}
	y = d - 1;
	while (y >= 0 && t[y] != t[d]) {
		y--;
	}
	score -= c[t[d]] * (d - y) * (x - d);
	t[d] = q;

	return score;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define fo(i, n) for(int i = 1; i <= n; ++i)
#define rep(i, a, b) for(int (i) = (a); (i) < (b); ++(i))

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

const int N = 200200;
const int mod = 1e9 + 7;
const ll INF = 1e18;
deque<int> q;
int used[N];
vector<int> g[N];
int u, v;
int n, m;

inline void dfs(int v, int where = 0)
{
	if(!used[v])
	{
		if(where)
			q.push_back(v);
		else
			q.push_front(v);
	}
	used[v] = 1;
	for(int to : g[v])
	{
	 	if(!used[to])
	 	{
	 		dfs(to, where);
			return;
		}
	}
}

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

	cin >> n >> m;
	fo(i, m)
	{
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1, 1);
	dfs(1, 0);
	cout << q.size() << "\n";
	while(!q.empty())
	{
		cout << q.front() << ' ';
		q.pop_front();
	}
	return 0;	
}   	

Measured memory_bytes: 9472
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
#define int long long int
#define mod 1000000007
void dfs(int src,vector<int> adj[],int &here,bool visited[])
{
	if(visited[src])
	   return ;
	else
	{
		visited[src]=true;
		here++;
		for(int x:adj[src])
		   dfs(x,adj,here,visited);
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int d,t,s;
	cin>>d>>t>>s;
	if(s*t>=d)
	{
		cout<<"Yes"<<endl;
	}
	else
	   cout<<"No"<<endl;
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main()
{
    int N, X;
    cin >> N >> X;
    int m[N];
    for(int i = 0; i < N; i++)
        cin >> m[i];
    int min = 100000;
    for(int i = 0; i < N; i++)
    {
        if(min > m[i])
            min = m[i];
    }
    for(int i = 0; i < N; i++)
        X -= m[i];
    cout << X / min + N << endl;
    return 0;
}

Measured memory_bytes: 256
n,m,x = map(int,input().split())
a = [list(map(int,input().split())) for x in range(n)]
total = [0]*(m+1)
flg = False
mflg = True
min_num = 100100100100100
for i in range(1,2**n):
    for j in range(n):
        if ((i >> j) & 1):
            total = [x + y for (x, y) in zip(a[j], total)]
    for k in range(m):
        if total[1+k] < x:
            mflg = False
            break
    if mflg and total[0] < min_num:
        min_num = total[0]
        flg = True
    total = [0]*(m+1)
    mflg = True
if flg:
    print(min_num)
else:
    print('-1')

    

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
using ll = long long;
using vi = vector<int>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    int N;
    cin >> N;
    vi a1(N+2);
    vi a2(N+2);

    FOR(i, 1, N + 1) cin >> a1[i];
    FOR(i, 1, N + 1) cin >> a2[i];

    vi s1(N + 2), s2(N + 2);    // 大きくする
    FOR(i, 1, N + 1) s1[i] = a1[i] + s1[i-1];
    for(int i = N; i > 0; --i) s2[i] = a2[i] + s2[i+1];
    
    // FOR(i, 1, N + 1) cout << s1[i] << endl;
    // FOR(i, 1, N + 1) cout << s2[i] << endl;

    int ans = 0;
    FOR(i, 1, N + 1) {
        ans = max(ans, s1[i] + s2[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long gcdf(long a,long b){
  long p = a;
  long q = b;
  long c = 0;
  c = a%b;
  while(c != 0){
    p = q;
    q = c;
    c = p%q;
  }
  return q;
}
  
int main(){
  long n=0;
  long a[100000] = {};
  long i = 0;
  long gcd = 0;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  for(i=0;i<n;i++){
    if(i==0){
      gcd = a[i];
    }else{
      gcd = gcdf(gcd,a[i]);
    }
  }
  printf("%ld",gcd);
  return 0;
}
          

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,A,B;
  cin >> N >> A >> B;
  string s;
  cin >> s;
  int sum = 0;
  int bsum = 0;
  rep(i,N) {
    if(s[i] == 'a') {
      if(sum < A+B) {
        sum++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else if(s[i] == 'b') {
      bsum++;
      if(sum < A+B && bsum <= B) {
        sum++;
        cout << "Yes" << endl;
      }  else {
        cout << "No" << endl;
      }
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 896
n = int(input())
A = list(map(int, input().split()))
A2 = A[:]
RAW = A[:]

# +-にするとき
su = 0
for i, a in enumerate(A):
    su += a
    if i % 2 == 0:
        if su <= 0:
            # a[i] を増やす
            t = (-su + 1)
            A[i] += t
            su += t
    else:
        if su >= 0:
            # a[i] をへらす
            t = (su + 1)
            A[i] -= t
            su -= t

# -+にするとき
su = 0
for i, a in enumerate(A2):
    su += a
    t = 0
    if i % 2 ==0:
        if su >= 0:
            # a[i]をへらす
            t = (su + 1)
            A2[i] -= t
            su -= t
    else:
        if su <= 0:
            # a[i]をふやす
            t = (-su + 1)
            A2[i] += t
            su += t
# print(A)
# print(A2)

ans1 = sum([abs(a-b) for a,b in zip(A, RAW)])
ans2 = sum([abs(a-b) for a,b in zip(A2, RAW)])
print(min(ans1, ans2))

Measured memory_bytes: 19980
import copy
H, W = map(int, input().split())
fields = []


def black_white(x):
    if x == '.':  # 白ならば0
        return 0
    elif x == '#':
        return 1  # 黒ならば1


for i in range(H):
    fields.append(list(map(black_white, list(input()))))

DP_map = [[0 for i in range(W)] for j in range(H)]

if fields[0][0] == 1:
    DP_map[0][0] = 1
for h in range(H):
    for w in range(W):
        if h == 0 and w == 0:
            continue
        elif h == 0:
            if fields[h][w] - fields[h][w-1] == 1:
                DP_map[h][w] = DP_map[h][w-1] + 1
            else:
                DP_map[h][w] = DP_map[h][w-1]
            # 白から黒に変わった時だけプラス1点
        elif w == 0:
            if fields[h][w] - fields[h-1][w] == 1:
                DP_map[h][w] = DP_map[h-1][w] + 1
            else:
                DP_map[h][w] = DP_map[h-1][w]
        else:
            if fields[h][w] - fields[h][w-1] == 1:
                horizontal_cnt = DP_map[h][w-1] + 1
            else:
                horizontal_cnt = DP_map[h][w-1]
            if fields[h][w] - fields[h-1][w] == 1:
                vertical_cnt = DP_map[h-1][w] + 1
            else:
                vertical_cnt = DP_map[h-1][w]
            DP_map[h][w] = min(horizontal_cnt, vertical_cnt)
print(DP_map[H-1][W-1])


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

int main(void){
     string s;

    cin >> s;

    if(s.at(0) == s.at(1) && s.at(1) == s.at(2) ){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import std.stdio,std.string,std.conv,std.algorithm;

int main()
{
	int n = readln.chomp.to!int;
	while(n--)
	{
		string s = readln.chomp;
		int[] a;
		a.length = s.length;
		foreach(i;0..s.length)
		{
			a[i] = cast(int)(s[i] - '0');
		}

		sort(a);
		int count = 1;
		int num_max = 0,num_min = 0;
		foreach(i;0..a.length)
		{
			num_max += a[i]*count;
			num_min += a[a.length - i -1]*count;
			count *= 10;
		}

		writeln(num_max - num_min);
	}
	return 0;
}

Measured memory_bytes: 1056
A = list(map(int, input().split()))
res = 0
if A[0]%2 + A[3]%2 + A[4]%2 >=2 and A[0]*A[3]*A[4]>0:
    A[0] -= 1
    A[3] -= 1
    A[4] -= 1
    res += 3
res += A[0]//2*2
res += A[1]
res += A[4]//2*2
res += A[3]//2*2
print(res)


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

#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define endl        '\n'
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

namespace InOp{
template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
}
using namespace InOp;

namespace ModOp{
template<class x,class y,class z> z add(x a,y b,z m){return (a+b)%m;}
template<class x,class y,class z> z sub(x a,y b,z m){return (a-b+m)%m;}
template<class x,class y,class z> z mul(x a,y b,z m){return ((ll)a*b)%m;}
template<class y,class z> z expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;}
template<class x,class z> z inv(x b,z m){return expo(b,m-2,m);}
template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;}
template<class x,class y,class z> z div(x a,y b,z m){ll c=inv(b,m);return mul(a,c,m);}
}
using namespace ModOp;

namespace Debug{
template<class x> void deb(x a){cerr<<"a"<<": "<<a<<endl;}
template<class x,class y> void deb(x a,y b){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<endl;}
template<class x,class y,class z> void deb(x a,y b,z c){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<endl;}
template<class x,class y,class z,class xy> void deb(x a,y b,z c,xy d){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<" | "<<"d"<<": "<<d<<endl;}
}
using namespace Debug;

#define N  1000005

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,r,x,y,m,n;
    	cin>>n;
    	vi v(n);
    	cin>>v;
    	double ch=1e18;
    	ch=ch*2;
    	ll ans=1;
    	sort(all(v));
    	for(i=0;i<n;i++)
    	{
    		if(ans>ch/v[i])
    		{
    			cout<<-1;return 0;
    		}
    		ans=ans*v[i];
    		if(ans>1000000000000000000)
    		{
    			cout<<-1;
    			return 0;
    		}
    	}
    	cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
using namespace std;

void solve()	{
	int n,m;
	cin >> n >> m;
	string s[n];
	for(int i=0; i<n; i++)	cin >> s[i];
	for(int i=0; i<n; i++)	{
		for(int j=0; j<m; j++)	{
			int b=0;
			if(s[i][j]!='#')	{
				if(i-1>=0 && j-1>=0 && s[i-1][j-1]=='#')	b++;
				if(i-1>=0 && s[i-1][j]=='#')	b++;
				if(j-1>=0 && s[i][j-1]=='#')	b++;
				if(i-1>=0 && j+1<m && s[i-1][j+1]=='#')	b++;
				if(j+1<m && s[i][j+1]=='#')	b++;
				if(i+1<n && j+1<m && s[i+1][j+1]=='#')	b++;
				if(i+1<n && s[i+1][j]=='#')	b++;
				if(i+1<n && j-1>=0 && s[i+1][j-1]=='#')	b++;
				cout << b;
			}
			else	cout << '#';
		}
		cout << endl;
	}
}

int main()	
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <iomanip>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
double a[1919];
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	double n;
	double iwa = 0;
	cin >> n;
	rep(i, n) { cin >> a[i]; }
	rep(i, n) { iwa += a[i]; }
	iwa = iwa / (n*1.0000000);
	rep(i, n) { a[i] = abs(iwa - a[i]); }
	double ta = 10000;
	int se = 0;
	for(int i=n-1;i>=0;i--) {
		if (a[i] <= ta) { ta = a[i]; se = i; }
	}
	cout << se << endl;
}

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

ll const mod = 1e9+7;



int main() {
  int K,A,B;
  cin >> K >> A >> B;
  rep2(i,A,B+1) {
    if (i%K==0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <vector>

using namespace std;

bool check(const vector<int> &v, int hf)
{
    // 0 dp初期値
    // 要素数分(1 indexed)
    // 要素を -1 で初期化
    vector<int> dp(hf + 1, -1);

    dp[0] = 0;

    for (int i = 0; i < (signed)v.size(); i++)
    {
        for (int j = 0; j <= hf; j++)
        {
            // 最大で「1」 「0」→「1」 「1」→「1」
            if (0 <= dp[j]) dp[j] = 1;
            // 組合せで構築できない「-1」
            else if (j < v[i] || dp[j - v[i]] <= 0) dp[j] = -1;
            // 組合せで構築できる「0」
            else dp[j] = 0;
        }
    }

    return 0 <= dp[hf];
}

int main()
{
    const char *Yes = "Yes";
    const char *No = "No";

    char s[8001];
    if (scanf("%s", s) < 1) return 0;

    int x, y;
    if (scanf("%d%d", &x, &y) < 2) return 0;

    // 要素数 2 (x と y)
    vector<int> ar[2];

    int xy = 0, cnt = 0;

    for (int i = 0; i < (signed)strlen(s); i++)
    {
        if (s[i] == 'F')
        {
            cnt++;
        }
        else
        {
            ar[xy].push_back(cnt);
            cnt = 0;
            xy ^= 1;    // ビット排他的論理和 反転(0 ⇔ 1)
        }
    }

    // 最後が T でない場合の考慮
    ar[xy].push_back(cnt); 

    // x の先頭を参照
    // 最初だけ 右確定 目標地点を左にずらす
    x -= ar[0][0];

    // x の先頭を削除
    ar[0].erase(ar[0].begin());

    // 正負を意識する必要はない
    // 先に左にずらしている為
    x = abs(x);
    // y は 0 始点の為
    y = abs(y);

    // x 合計
    int xs = accumulate(ar[0].begin(), ar[0].end(), 0);
    // y 合計
    int ys = accumulate(ar[1].begin(), ar[1].end(), 0);

    // 不足
    if (xs < x || ys < y) return !printf("%s\n", No);

    // 全力 Just
    if (xs == x && ys == y) return !printf("%s\n", Yes);

    // 奇数 行って帰れず
    if ((xs - x) % 2 || (ys - y) % 2) return !printf("%s\n", No);

    // 行き過ぎ 確定
    // ソート 昇順
    sort(ar[0].begin(), ar[0].end());   // x
    sort(ar[1].begin(), ar[1].end());   // y

    if (check(ar[0], (xs - x) / 2) && check(ar[1], (ys - y) / 2))
    {
        // 行き過ぎた距離の半分を
        // 組合せで構築できる
        return !printf("%s\n", Yes);
    }
    else
    {
        // 行き過ぎた距離の半分を
        // 組合せで構築できない
        return !printf("%s\n", No);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int n,m;cin >> n >> m;
    vector<LL> a(m),b(m);
    vector<LL> c(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        int x=0;
        for (int j = 0; j < b[i]; j++) {
            int C;cin >> C;
            C--;
            x|=(1<<C);
        }
        c[i] = x;
    }
    vector<LL> dp((1<<n)+1,LINF);
    dp[0] = 0;
    for (int i = 0; i < (1<<n); i++) {
        for (int j = 0; j < m; j++) {
            dp[i|c[j]] = min(dp[i|c[j]],dp[i] + a[j]);
        }
    }
    if(dp[(1<<n)-1]==LINF) puts("-1");
    else cout << dp[(1<<n)-1] << endl;
    return 0;
}


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

int main(){
	ll n,k,s; cin >> n >> k >> s;
	rep(i,k)cout << s << " ";
	if(s == 1e9){rep(i,n-k)cout << 1 << " ";}
	else if(s < 1e9){rep(i,n-k)cout << 1000000000 << " ";}
	cout << endl;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int LB = 62;

#define bit(x,i) (((x)>>(i))&1)

int a[MAXN], to[MAXN][LB];

int main(void)
{
	int n;
	ll d;
	scanf("%d%lld",&n,&d);
	for(int i=1; i<=n; ++i)
		scanf("%d",&a[i]);
	
	for(int i=1; i<=n; ++i)
		to[i][0] = a[i];
	
	for(int j=1; j<LB; ++j)
		for(int i=1; i<=n; ++i)
			to[i][j] = to[to[i][j-1]][j-1];
	
	int now = 1;
	for(int i=LB-1; i>=0; --i)
		if(bit(d,i))
			now = to[now][i];
	printf("%d",now);
	return 0;
}

Measured memory_bytes: 50948
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,c;
	cin >> n >> c;
	vector< vector<int> > D = vector< vector<int> >(c,vector<int>(c,0)); //Change from X to Y => Cost is D[X][Y].
	vector< vector<ll> > Dif = vector< vector<ll> > (3,vector<ll>(c,0));

	//入力
	REP(i,c){
		REP(j,c){
			int d;
			cin >> d;
			D[i][j] = d;
		}
	}
	DUMP(D);
	//入力＆処理
	REP(i,n){
		REP(j,n){
			int cc;
			cin >> cc;
			cc--;
			REP(k,c){
				Dif[(i+j)%3][k] += D[cc][k];
			}
		}
	}
	DUMP(Dif);
	ll ans = 1e18;
	REP(i,c){
		REP(j,c){
			if(i == j)continue;
			REP(k,c){
				if(i == k)continue;
				if(j == k)continue;
				ans = min(ans,(Dif[0][i]+Dif[1][j]+Dif[2][k]));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int main(){
	FIO
	
	int n, k;cin >> n >> k;
	vector<long long> cors(n);
	for(int i = 0; i < n; i++)cin >> cors[i];
	sort(cors.begin(), cors.end());
	if(n == 1){
		cout << cors[0];
		return 0;
	}
	vector<long long> pre(n + 1);
	pre[0] = 0;
	for(int i = 1; i < n; i++)pre[i] = pre[i - 1] + abs(cors[i] - cors[i - 1]);
	//deb(pre);
	long long ans = LLONG_MAX;
	for(int i = k - 1; i < n; i++){
		long long now;
		if(abs(cors[i]) > abs(cors[i - k + 1]))now = abs(cors[i - k + 1]);
		else now = abs(cors[i]);
		now += pre[i] - pre[i - k + 1];
		ans = min(ans, now);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;


int main(){
   
	long long n, k;
	cin >> n >> k;

	if (k > n) {
		cout << 1;
		return 0;
	}

	long long rez = 0;
	for (long long i = k; i <= n; ++i) {
		long long small = 0, big = 0;

		small = ((i - 1) * i) / 2;
		big = ((n * (n + 1)) / 2) - (((n - i) * (n - i+ 1)) / 2);
		rez += big - small + 1;
		//cout << rez << ' ' << small << ' ' << big << '\n';
	}
	cout << (rez + 1) % (1000000000 + 7);
}



Measured memory_bytes: 3676
def f(a):
	q=a[:n];s=sum(q);heapify(q)
	for e in a[n:n-~n]:yield s;s+=e-heappushpop(q,e)
from heapq import*;n,*a=map(int,open(0).read().split());print(max(map(sum,zip(f(a),list(f([-e for e in a[::-1]]))[::-1]))))

Measured memory_bytes: 36308
a = []
for i in range(5):
    a.append(int(input()))
import itertools
a = list(itertools.permutations(a, 5))
ans = int(1e10)
for i in range(len(a)):
    cnt = 0
    for j in range(5):
        if j != 4:
            cnt += (a[i][j]+9)//10*10
        else:
            cnt += a[i][j]
    ans = min(ans, cnt)
print(ans)




Measured memory_bytes: 38384
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    data class Edge(val node: Int, val distance: Int)

    val graph = mutableMapOf<Int, MutableList<Edge>>()
    repeat(n - 1) {
        val (n1, n2, l) = readLine()!!.split(" ").map(String::toInt)
        graph.getOrPut(n1 - 1, { mutableListOf() }).add(Edge(n2 - 1, l))
        graph.getOrPut(n2 - 1, { mutableListOf() }).add(Edge(n1 - 1, l))
    }

    val even = 0
    val odd = 1

    val result = IntArray(n) { -1 }
    fun dfs(i: Int, dSum: Int) {
        val edges = graph[i]!!

        if (dSum % 2 == 0) {
            result[i] = even
        } else {
            result[i] = odd
        }

        for ((next, distance) in edges) {
            if (result[next] != -1) {
                continue
            }
            dfs(next, dSum + distance)
        }
    }

    dfs(0,0)

    result.forEach(::println)
}

Measured memory_bytes: 98556
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];

    vector<ll> guess(n+1); guess[0] = 0;
    for(int i=1; i<n+1; i++){
        guess[i] = A[i-1] - guess[i-1];
    }
    vector<ll> res(n);
    res[0] = guess[n];
    for(int i=1; i<n; i++){
        res[i] = (A[i-1] -  res[i-1]/2)*2;
    }
    rep(i, n) cout << res[i] << " ";
    cout << ln;
}


Measured memory_bytes: 3712
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var num1 = Convert.ToInt32(input[0]);
        var num2 = Convert.ToInt32(input[1]);

        if (num1 + num2 >= 10) Console.WriteLine("error");
        else Console.WriteLine(num1 + num2);
    }
}


Measured memory_bytes: 11220
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func increment(bits []bool) bool {
	i := 0
	for i < len(bits) && bits[i] {
		bits[i] = false
		i++
	}
	if i < len(bits) {
		bits[i] = true
	} else {
		return false
	}
	return true
}

func check(bits uint, k uint) bool {
	b := fmt.Sprintf("%b", bits)
	nOnes := uint(0)
	for i := 0; i < len(b); i++ {
		if b[i:(i+1)] == "1" {
			nOnes++
		}
		if nOnes > k {
			break
		}
	}
	return nOnes == k
}

func compress(b []bool) uint {
	n := len(b)

	queryBits := uint(0)
	for i := n - 1; i >= 0; i-- {
		if b[i] {
			queryBits++
		}
		if i != 0 {
			queryBits = queryBits << 1
		}
	}

	return queryBits
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	k := uint(nextInt())

	i := uint(0)
	iMax := uint(math.Pow(2.0, float64(n)))
	for i < iMax {
		// fmt.Println(i, k)
		if check(i, k) {
			cache := []string{}
			for j := 0; j < n; j++ {
				if (i & (1 << uint(j))) > 0 {
					cache = append(cache, strconv.Itoa(j))
				}
			}
			if i == 0 {
				fmt.Println("0:")
			} else {
				fmt.Printf("%v: %v\n", i, strings.Join(cache, " "))
			}
		}
		i++
	}
}



Measured memory_bytes: 6172
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n;
	cin>>n;
	vl t(n), a(n);
	rep(i, n) cin>>t[i]>>a[i];
	ll ans = t[0]+a[0];
	ll aa = a[0], tt = t[0];
	REP(i, 1, n){
		// ll k = 1LL;
		// while(k*a[i] < aa || k * t[i] < tt) k++;
		ll k = max((aa-1)/a[i]+1LL, (tt-1)/t[i]+1LL);
		aa = a[i]*k;
		tt = t[i]*k;
	}
	ans = aa+tt;
	cout<<ans<<endl;
}

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

const int N = 2e5 + 5;
typedef long long ll;
//knapsack 2{
 pair<ll,ll>arr[N];

int main(){
    ll n,cap;
    cin>>n>>cap;
    set<pair<double,int> >st;
    map<int,ll>mp;
        map<int, ll>::reverse_iterator it;
    mp[0]=cap;ll ans=0;
    for(int i=0;i<n;i++){
        cin>>arr[i].first>>arr[i].second;
        it=mp.rbegin();

      for(;it!=mp.rend();it++){
           ll val=it->first;
       ll remaincap=it->second;
        if(mp[val+arr[i].second]<=remaincap-arr[i].first){
            mp[val+arr[i].second]=remaincap-arr[i].first;
            ans=max(ans,val+arr[i].second);
        }
      }
    }

    cout<<ans;

   return 0;
}


Measured memory_bytes: 3584
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 整数の入力
    _ <- getLine
    -- スペース区切り整数の入力
    as <- sort . map strToInt . words <$> getLine
    -- 出力
    putStrLn . show $ solve as

solve :: [Int] -> Int
solve as = if null sums then (if length ls == 1 then head ls else (if abs (head as - last as) <= 2 then length as else max (head ls) (last ls))) else maximum sums where
    ls = map length $ group as
    sums = zipWith3 (\a b c -> a + b + c) ls (tail ls) (tail $ tail ls)


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

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

int main() {
  int a, b;

  cin >> a >> b;
  
  if (a%2==0 || b%2==0) {
  	cout << "Even" << endl;
  }
  else {
  	cout << "Odd" << endl;
  }
}

Measured memory_bytes: 3620
/* {{{ */
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! {
        n: u64,
        a: u64,
        b: u64,
    }
    let d = n / (a+b);
    let m = n % (a+b);
    println!("{}", a * d + std::cmp::min(a,m));
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352