akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define _rep(i,ra,re) for((i)=ra;(i)>(re);(i)--)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define _rep_(i,ra,re) for((i)=ra;(i)>=(re);(i)--)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define pu(n) cout << n;
#define mod 1000000007
int i,j,k,l;
static const int MAX_N=10e5;

int main(void){
	int N;
		cin >> N;
	int m=N;
	while(m!=0){
		i++;m/=10;
	}
	if(i==1 || i==2){
		puts(min(N,9));
	}else if(i==3||i==4){
		puts(min(9+N-100+1,909));
	}else{
		puts(min(909+N-10000+1,90909));
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<lli>>;
using P = pair<int, int>;
// }}} End Header

int main(){
	string s;
	cin >> s;
	rep(i,s.size()){
		if(s[i] == '?') s[i] = 'D';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3728
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  str s;
  cin >> s;
  bool isin[26];
  fill(isin,isin+26,false);
  REP(i,s.length()){
    isin[s[i]-'a']=true;
  }
  REP(i,26){
    if(isin[i]==false){
      cout << (char)(i+'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int k;
    cin >> k;
    int sum = 0;
    rep(a, 1, k + 1) rep(b, 1, k + 1) {
        int xx = __gcd(a, b);
        rep(c, 1, k + 1) {
            sum += __gcd(xx, c);
        }
    }
    cout << sum << '\n';
}

Measured memory_bytes: 3620
#define MYDEBUG
//
#include <bits/stdc++.h>
#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
using namespace std;
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  out << "{" << p.first << "," << p.second << "}";
  return out;
}

static const int M = 1046597;
static const int L = 12;
char T[M][L];
char com[6], word[L];
int getChar(char ch) {
  if (ch == 'A') {
    return 1;
  } else if (ch == 'C') {
    return 2;
  } else if (ch == 'G') {
    return 3;
  } else {
    return 4;
  }
}

int getKey(char str[]) {
  int key = 0;
  rep(i,0,(int) strlen(str))
  {
    key += getChar(str[i]);
    key *= 5; //左シフト(5進数)
  }
  return key;
}

int h1(int key) {
  return key % M;
}

//mとh2は互いに素に
int h2(int key) {
  //素数Mより小さい数はみなMと互いに素
  //h2の周期はM未満であればなんでも可
  //1を加えるのはkey%(M-1)==0のときにずれなくなるのを防ぐため
  //この関数は1 ~ M-1の間の値をとる
  return 1 + (key % (M - 1));
}

int insert(char str[]) {
  int key, i, h;
  key = getKey(str);
  for (i = 0;; ++i) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(T[h], str) == 0) {
      return 1; //すでに格納済
    } else if (strlen(T[h]) == 0) {
      strcpy(T[h], str);
      return 0;
    }
  }
  return 0;
}

bool find(char str[]) {
  ll key, i, h;
  key = getKey(str);
  for (i = 0;; ++i) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(T[h], str) == 0) {
      return true;
    } else if (strlen(T[h]) == 0) {
      return false;
    }
  }
  return false;
}

void solve() {
  rep(i,0,M)
  {
    T[i][0] = '\0'; //すべて空文字列で初期化
  }
  int n;
  scanf("%d", &n);
  rep(i,0,n)
  {
    scanf("%s %s", com, word);
    if (com[0] == 'i') {
      insert(word);
    } else {
      if (find(word)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
}
int main() {
  solve();
  return 0;
}



Measured memory_bytes: 15396
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=2e5+10;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,mx;
string s[maxn];
map<string,int> mp,vis;
vector<string> st;

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        mp[s[i]]++;
        mx=max(mx,mp[s[i]]);
    }
    for(int i=1;i<=n;i++)
        if(mp[s[i]]==mx&&vis[s[i]]==0)
            st.push_back(s[i]),vis[s[i]]++;
    sort(st.begin(),st.end());
    for(unsigned int i=0;i<st.size();i++)
        cout<<st[i]<<endl;

    return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 2);
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r;
    a[l]++;
    a[r + 1]--;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    a[i] += a[i - 1];
    if (a[i] == m) ans++;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3976
from pprint import pprint
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, K = rl()
H = rl()

H.sort()
H.reverse()
print(sum(H[K:]))



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

using namespace std;

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

#define F first
#define S second

const int MAXN = 1e5 + 10;
const int LOG = 16;

int n;

int get(){
	string s; cin >> s;
	if (s[0] == 'V'){
		exit(0);
	}
	if (s[0] == 'M')
		return 1;
	return 0;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	cout << 0 << endl;
	int last = get();
	int l = 0, r = n;	
	while (r - l > 1){
		int mid = l+r>>1;
		cout << mid << endl;
		int t = get();

		int exp = last ^ (mid - l & 1);
		if (t == exp)
			l = mid, last = exp;
		else
			r = mid;
	}
	cout << l << endl;
	return 0;
}



Measured memory_bytes: 852
void main() {
	(N => readAs!(int[]).sort().enumerate.filter!(i => i.index % 2 == 0).map!(i => i.value).sum)(ri).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M = list(map(int, sys.stdin.readline().split()))
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
sys.setrecursionlimit(200000)

graph = [[] for _ in range(N + 1)]

for a, b, c in ABC:
    graph[b].append((a, c))
graph[1].append((0, 0))

vd = [(N, 0)]
# N までの最長距離
ans = [-INF] * (N + 1)
ans[N] = 0
for _ in range(N + 1):
    nexts = []
    for v, d in vd:
        for u, c in graph[v]:
            if ans[u] < d + c:
                ans[u] = d + c
                nexts.append((u, d + c))
    vd = nexts
if vd:
    print('inf')
else:
    print(ans[0])


Measured memory_bytes: 4076
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

ll gcd(ll a, ll b){
  ll x;
	while(a!=b){
    if(b==0)break;
    a=a%b;
    x=b;
    b=a;
    a=x;
  }
  return a;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;
    ll ans = 0;
    ll g = c*d/gcd(c,d);
    ans = (b - b/c - b/d + b/g) - (a - a/c - a/d + a/g);
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
	}
	int ans=1;
	int tmp=n-k;
	if(tmp>0){
		ans+=tmp/(k-1);
		if(tmp%(k-1))ans++;
	}
	cout<<ans<<endl;
}


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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	if (n % 2) {
		cout << "No" << endl;
		return 0;
	}
	int half = n / 2;
	for (int i = 0; i < half; i++) {
		if (s[i] != s[i + half]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

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

    int n;
    cin >> n;
    string s[n];
    rep(i,n) cin >> s[i];
    
    ll ans = 0;
    
    rep(i,n){
        sort(s[i].begin(), s[i].end());
    }
    
    map<string, int> m;
    rep(i,n){
        m[s[i]]++;
    }
    
    for(auto itr=m.begin(); itr!=m.end(); itr++){
        // cout << itr->first << ":" << itr->second << endl;
        ans += (itr->second * (ll)(itr->second-1)) / 2;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16640
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
fact = [1]
for i in range(1, n + 1):
    fact.append(fact[-1] * i % 1000000007)
max_a = 0
for i in range(k - 1, n):
    max_a += a[i] * fact[i] * pow(fact[i - k + 1], 1000000005, 1000000007) * pow(fact[k - 1], 1000000005, 1000000007) % 1000000007
a = a[::-1]
min_a = 0
for i in range(k - 1, n):
    min_a += a[i] * fact[i] * pow(fact[i - k + 1], 1000000005, 1000000007) * pow(fact[k - 1], 1000000005, 1000000007) % 1000000007
print(int((max_a - min_a) % 1000000007))

Measured memory_bytes: 14416
/*
    C - Dice and Coin
    https://atcoder.jp/contests/abc126/tasks/abc126_c
*/
#include <bits/stdc++.h>
using namespace std;

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

    double probability = 0.0;
    double n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        int count = 0;
        int dice = i;
        while (dice < k) {
            dice *= 2;
            count++;
        }
        probability += (double)pow(0.5, count) / n;
    }

    cout << fixed;
    cout << setprecision(15) << (probability) << endl;
}


Measured memory_bytes: 256
def F z,c;f=G[c].size==2?1:0;r=[0,c];G[c].map{|e|e!=z&&(x,y=F c,e;r=[r,[x+f,y]].max)};r end
N=gets.to_i
G=N.times.map{[]}
(N-1).times{a,b=gets.split.map &:to_i;G[a-1]<<b-1;G[b-1]<<a-1}
p F(-1,F(-1,0)[1])[0]+G.count{|e|e.size==1}

Measured memory_bytes: 15996
#include<bits/stdc++.h>
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int> 
#define vl vector<ll>
#define vpi vector<pi> 
#define vpl vector<pl>
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ss second
#define ff first
#define endl "\n"
#define mod 1000000007
#define MAX 100010
//#define fill(a,x) memset(x,a,sizeof x)
#define all(x) x.begin(),x.end()
//#define clr(x) memset(x,0,sizeof(x))
#define rep(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n,b) for(int i=n-1;i>=b;i--)
#define repit(itr,x) for(auto itr=x.begin();itr!=x.end();itr++)
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main(){
	int n; cin>>n;
	int myxor=0;
	vi a(n);
	rep(i,0,n){
		cin>>a[i];
		myxor^=a[i];
	}
	cout<<(myxor==0?"Yes":"No");
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, D;
int A[MAX_N][20];

void solve() {
	cin >> N >> D;
	rep(i, 0, N) {
		rep(j, 0, D) cin >> A[i][j];
	}
	vector<int> vec;
	for(int i = 1; i * i <= 20000; i++) {
		vec.pb(i * i);
	}
	int res = 0;
	rep(i, 0, N) {
		rep(j, i + 1, N) {
			int tmp = 0;
			rep(k, 0, D) {
				int x = A[i][k] - A[j][k];
				tmp += x * x;
			}
			auto it = lower_bound(all(vec), tmp);
			if(*it == tmp) res++;
		}
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

using namespace std;

const int NMAX = 305;

long long v[NMAX][NMAX];
bool muc[NMAX][NMAX];

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= n; j ++)
            cin >> v[i][j];

    for(int i = 1; i <= n; i ++) {
        for(int j = i + 1; j <= n; j ++) {
            for(int k = 1; k <= n; k ++) {
                if(i != k && j != k && v[i][j] > (v[i][k] + v[k][j])) {
                    cout << -1;
                    return 0;
                }
            }
        }
    }

    for(int i = 1; i <= n; i ++) {
        for(int j = i + 1; j <= n; j ++) {
            for(int k = 1; k <= n; k ++) {
                if(i != k && j != k && v[i][j]) {
                    if(v[i][j] == v[i][k] + v[k][j]) {
                        muc[i][j] = 1;
                        muc[j][i] = 1;
                    }
                }
            }
        }
    }
    long long sol = 0;
    for(int i = 1; i <= n; i ++)
        for(int j = i + 1; j <= n; j ++)
            if(muc[i][j] == 0)
                sol += v[i][j];
    cout << sol;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

template <class Function>
double ternary_search(double l, double r, Function f) {
    for (int i = 0; i < 200; i++) {
        double a = (l + l + r) / 3;
        double b = (l + r + r) / 3;
        if (f(a) > f(b))
            l = a;
        else
            r = b;
        //dump(a); dump(b); el;
    }
    return l;
}

int main(void) {
    lint n; cin >> n;
    vector<lint> a(n);
    repeat (i, n) cin >> a[i];
    
    auto f = [&a](lint start) -> lint {
        lint ans = 0;
        lint sz = a.size();
        repeat (i, sz) {
            ans += abs(a[i] - (start + i));
        }
        return ans;
    };
    
    lint m = ternary_search(-1e13, 1e13, f);
    lint ans = 1e18;
    
    repeat_from_to (i, m-3, m+3) {
        ans = min(ans, f(i));
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1792
def gcd(a,b):
    c = 0
    if a<b:
        c = b
        b = a
        a = c
    while(a%b!=0):
        c = a%b
        a = b
        b = c
    return b

n = int(input())
a = list(map(int, input().split()))
ans = a[0] 
for i in range(n):
    ans = gcd(ans,a[i])

print(ans)

Measured memory_bytes: 14252
#include<stdio.h>
int main (){
	int a,b;
	scanf("%d %d", &a, &b);
	if(a>b){
		printf("a > b\n");
	}else if (a<b){
		printf("a < b\n");
	}else if (a=b){
		printf("a == b\n");
}
	return 0;
}

Measured memory_bytes: 2640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int l,a,b,c,d;
  cin >> l >> a >> b >> c >> d;
  cout <<max(0,l-max((a+c-1)/c,(b+d-1)/d)) << endl;
}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 998244353
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=200001 ;
int main()
{
   fast ;
   ld r ;
   cin>>r ;
   ld ans=r*6.28318530717958623200 ;

   cout<<fixed<<setprecision(20)<<ans ;





}


Measured memory_bytes: 3808
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005];
int dp[100005];
const int inf=0x3f3f3f3f;
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++){
		for(int j=1;j<=k;j++){
			if(j==1){
				dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
			}
			if(i>=j&&j!=1){
				dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));	
			}
	    }
	} 
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
/*やったぜ。　投稿者：変態糞土方 (8月16日（水）07時14分22秒)

昨日の8月15日にいつもの浮浪者のおっさん（60歳）と先日メールくれた汚れ好きの土方のにいちゃん

（45歳）とわし（53歳）の3人で県北にある川の土手の下で盛りあったぜ。

今日は明日が休みなんでコンビニで酒とつまみを買ってから滅多に人が来ない所なんで、

そこでしこたま酒を飲んでからやりはじめたんや。

3人でちんぽ舐めあいながら地下足袋だけになり持って来たいちぢく浣腸を3本ずつ入れあった。

しばらくしたら、けつの穴がひくひくして来るし、糞が出口を求めて腹の中でぐるぐるしている。

浮浪者のおっさんにけつの穴をなめさせながら、兄ちゃんのけつの穴を舐めてたら、

先に兄ちゃんがわしの口に糞をドバーっと出して来た。

それと同時におっさんもわしも糞を出したんや。もう顔中、糞まみれや、

3人で出した糞を手で掬いながらお互いの体にぬりあったり、

糞まみれのちんぽを舐めあって小便で浣腸したりした。ああ～～たまらねえぜ。

しばらくやりまくってから又浣腸をしあうともう気が狂う程気持ちええんじゃ。

浮浪者のおっさんのけつの穴にわしのちんぽを突うずるっ込んでやると

けつの穴が糞と小便でずるずるして気持ちが良い。

にいちゃんもおっさんの口にちんぽ突っ込んで腰をつかって居る。

糞まみれのおっさんのちんぽを掻きながら、思い切り射精したんや。

それからは、もうめちゃくちゃにおっさんと兄ちゃんの糞ちんぽを舐めあい、

糞を塗りあい、二回も男汁を出した。もう一度やりたいぜ。

やはり大勢で糞まみれになると最高やで。こんな、変態親父と糞あそびしないか。

ああ～～早く糞まみれになろうぜ。

岡山の県北であえる奴なら最高や。わしは163*90*53,おっさんは165*75*60、や

糞まみれでやりたいやつ、至急、メールくれや。

土方姿のまま浣腸して、糞だらけでやろうや。*/
#include "bits/stdc++.h"
#include <numeric>
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define llMIN numeric_limits<long long>::min()
#define intMIN numeric_limits<int>::min()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define Sort(a) sort(a.begin(),a.end())
#define reSort(a) sort(a.rbegin(), a.rend())
ll digitpower(ll a,ll b){//aのb乗を計算
  if(b==1){
    return a;
  }else if(b==0){
    return 1;
  }
  if(b%2==1){
    ll tmp = digitpower(a,(b-1)/2);
    tmp%=d9_7;
    tmp*=tmp;
    tmp%=d9_7;
    tmp*=a;
    return (tmp)%d9_7;
  }else{
    ll tmp = digitpower(a,(b)/2);
    tmp%=d9_7;
    tmp*=tmp;
    tmp%=d9_7;
    return (tmp)%d9_7;
  }
}
unordered_map<int,int> prime_factor(int64_t n) {
  unordered_map<int,int> ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
int main(void){
  ll n;
  cin>>n;
  vl a(n);
  rep(i,n){
    cin>>a[i];
  }
  //ll Pnum = searchprime(1000000);
  //cout<<Pnum<<" "<<primes[Pnum-1]<<endl;
  unordered_map<int,int> maxnums;
  vector<unordered_map<int,int>> an(n);
  rep(i,n){
    unordered_map<int,int> tmp = prime_factor(a[i]);
    an[i]=tmp;
    for(auto i:tmp){
      if(maxnums.find((int64_t)i.first)!=maxnums.end()){
        maxnums[(int64_t)i.first]=max(maxnums[(int64_t)i.first],i.second);
      }else{
        maxnums.insert({i.first,i.second});
      }
    }
  }
  //cout<<"ttt"<<endl;
  ll ans=0;
  rep(i,n){

    ll tmp=1;
    for(auto j:maxnums){
      if(an[i].find(j.first)!=an[i].end()){
        tmp*=digitpower(j.first,(j.second)-an[i][j.first]);
      }else{
        tmp*=digitpower(j.first,j.second);
      }
      tmp%=d9_7;
    }
    ans+=tmp;
    ans%=d9_7;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
while True :
    (a, op, b) = [int(i) if i.isdigit() else i for i in input().split()]

    if op == '?' :
        break
    elif op == '+' :
        print(a + b)
    elif op == '-' :
        print(a - b)
    elif op == '*' :
        print(a * b)
    elif op == '/' :
        print(a // b)

Measured memory_bytes: 6728
using System;

namespace GreatOceanView
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            String[] sh = Console.ReadLine().Split(' ');
            int[] h = new int[n];
            for(int i = 0; i<n; i++){
                h[i] = int.Parse(sh[i]);
            }

            int ans = 0;
            int height = 0;

            for(int i = 0; i < n; i++){
                if(height<=h[i]){
                    ans++;
                    height = h[i];
                }
            }

            Console.WriteLine(ans.ToString());
        }
    }
}


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

int main(){
  ll n;cin>>n;
  
  ll m=n/15;
  ll x=n%15;
  
  ll ans=0;
  ans+=60*m+120*m*(m-1)/2;
  for(int i=1;i<=x;i++){
    int y=15*m+i;
    if(y%3!=0&&y%5!=0)ans+=y;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3644
fun main(args: Array<String>) {
    val k = readLine()!!.toInt()
    val a = arrayOf(1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)

    println(a[k - 1])
}

Measured memory_bytes: 31772
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N, ll K, ll X, ll Y) {
  cout << (K < N ? K * X + (N - K) * Y : N * X) << endl;
}

int main() {
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  ll X;
  cin >> X;
  ll Y;
  cin >> Y;
  solve(N, K, X, Y);
  return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE TupleSections #-}
import Control.Monad
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as C

type View = (Int, Int)
type Spot = (Int, Int)

viewsFor :: (Int, Int) -> [Spot] -> [View]
viewsFor (w, h) spots = do
  (x, y) <- spots
  let is = [(max 1 (x - 2)) .. (min (w - 2) x)]
      js = [(max 1 (y - 2)) .. (min (h - 2) y)]
  (,) <$> is <*> js

readLine = do
  [Just (y, _), Just(x, _)] <- (fmap C.readInt . C.words) <$> C.getLine
  return (x, y)

main :: IO ()
main = do
  [h, w, n] <- (fmap read . words) <$> getLine
  spots <- replicateM n $ readLine
  let spotCounts = Map.fromListWith (+) $ (,1) <$> viewsFor (w, h) spots
      viewCounts = IntMap.fromListWith (+) $ (,1) <$> Map.elems spotCounts
      zero = (w - 2) * (h - 2) - sum (IntMap.elems viewCounts)
      nums = flip (IntMap.findWithDefault 0) viewCounts <$> [1..9]
  mapM_ print (zero:nums)


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

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

	int zero = 0;
	rep(i, N) {
		if(A[i] == 0) zero++;
	}
	if(zero > 0) {
		cout << 0 << endl;
		return 0;
	}

	ll prod = 1;
	rep(i, N) {
		if(A[i] <= 1000000000000000000 / prod) {
			prod *= A[i];
		} else {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << prod << endl;

	return 0;
}

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

W = [0]*n
E = [0]*n

if s[0] == 'W':
	W[0] = 1
if s[-1] == 'E':
	E[-1] = 1

for i in range(1, n):
	if s[i] == 'W':
		W[i] = W[i-1] + 1
	else:
		W[i] = W[i-1]

for j in range(n-2, -1, -1):
	if s[j] == 'E':
		E[j] = E[j+1] + 1
	else:
		E[j] = E[j+1]

ans = [0]*n

for k in range(0, n):
	if k == 0:
		ans[0] = E[1]
	elif k == n-1:
		ans[n-1] = W[-2]
	else:
		ans[k] = W[k-1] + E[k+1]

print(min(ans))

Measured memory_bytes: 29472
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  long long n;
  cin >> n;
  long long count = 0;
  long long start = 100;
  while (true) {
    count++;
    start *= 1.01;
    if (start >= n) {
      cout << count << endl;
      return 0;
    }
  }
  return 0; 
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

int main()
{
    while (true)
    {
        long long n;
        cin >> n;
        if (n == 0)
        {
            break;
        }
        vector<long long> s(n);
        double m = 0;
        for (long long i = 0; i < n; i++)
        {
            long long x;
            cin >> x;
            s.at(i) = x;
            m += (double)x;
        }
        m /= n;
        double v = 0;
        for (long long i = 0; i < n; i++)
        {
            v += pow(s.at(i) - m, 2);
        }
        double a = sqrt(v / n);
        cout << std::fixed << std::setprecision(10) << a << endl;
    }
    return 0;
}


Measured memory_bytes: 3276
#include <iostream>
#include <cstring>
using namespace std;
#define SMAX 100000
int main(){
	char C[SMAX];
	cin >> C;
	int mozisu = strlen(C);
	int count_0=0;
	int count_1=0;
	int i;
	for(i=0;i<mozisu;i++){
		if(C[i] == '1'){
			count_1++;
		}else{
			count_0++;
		}
	}
	if(count_1 > count_0){
		cout << count_0 * 2 << endl;
	}else{
		cout << count_1 * 2 << endl;
	}

}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
	int a,b,i,x,min=1000000,max=-1000000;
	long int sum=0;
	scanf("%d",&x);
	for(i=0;i<x;i++){
		scanf("%d",&a);
		if(min>a)min=a;
		if(max<a)max=a;
		sum=sum+a;
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s;
    cin>>s;

    int i=0;
    int j=s.size()-1;
    while(s[i]!='A')i++;
    while(s[j]!='Z')j--;
    cout<<j-i+1<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
int map[N][N],row[N],col[N],dpos[2*N],dneg[2*N];

void printBoard(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(map[i][j]){
	if(row[i] != j) return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void putQueen(int i){
  int j;
  
  if(i==N){
    printBoard();
    return;
  }

  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)
          continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    putQueen(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }

}

int main(){
  int n,r,c;
  int i,j;

  for(i=0;i<N;i++) for(j=0;j<N;j++) map[i][j] = 0;
  for(i=0;i<N;i++) row[i] = col[i] = FREE;
  for(i=0;i<2*N;i++) dpos[i] = dneg[i] = FREE;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    map[r][c] = 1;
  }

  putQueen(0);  
  
  return 0;
}



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

int main() {

    string S;

    cin >> S;

    int i;
    int cnt = 0, cnt_M = 0;
    int a[S.size()];


    //S.at(0);

    for(i=0;i<S.size();i++){
        if(S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'C' || S.at(i) == 'G'){
            a[i] = 1;
            //cout << "Hello" << endl;
        }else{
            a[i] = 0;
        }
        //cout << i << "=>" << a[i] << endl;
    }

    for(i=0;i<S.size();i++){
        if(a[i] == 1){
            cnt++;
            if(cnt > cnt_M){
                cnt_M = cnt;
            }else{
            }
        }else{
            cnt = 0;
        }
    //cout << "a = " << a[i] << "cnt=" << cnt << "cnt_M=" << cnt_M << endl;
    }
    cout << cnt_M << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	ll n,t,x; cin>>n>>t;
	ll px=-1,ans=0;
	for(ll i=0;i<n;i++){
		cin>>x;
		ans+=t;
		if(px!=-1) ans-=max((ll)0,px-x+t);
		px=x;
	}
	cout<<ans;
}


Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通

string S;
vector<pair<int, int>> V;
int A[100010] = { 0 };
int main() {
	cin >> S;
	int r = 1;
	int l = 0;
	for (int i = 1; i < S.length(); i++) {
		if (i == S.length() - 1) {
			l++;
			auto p = make_pair(r, l);
			V.push_back(p);
			r = 1;
			l = 0;
		}
		else if (S[i] == 'R' && l == 0) {
			r++;
		}
		else if (S[i] == 'L') {
			l++;
		}
		else if (S[i] == 'R' && l >= 1) {
			auto p = make_pair(r, l);
			V.push_back(p);
			r = 1;
			l = 0;
		}
	}

	int point = 0;
	for (int i = 0; i < V.size(); i++) {
		A[point + V[i].first - 1] = A[point + V[i].first] = (V[i].first + V[i].second) / 2;
		if ((abs(V[i].first - V[i].second)) % 2 == 1) {
			int a = max(V[i].first, V[i].second);
			if ((V[i].first > V[i].second) ^ (a % 2 == 0)) {
				A[point + V[i].first - 1]++;
			}
			else {
				A[point + V[i].first]++;
			}

		}

		point += V[i].first + V[i].second;
	}

	for (int i = 0; i < S.length(); i++) {
		cout << A[i] << ' ';
	}
}

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

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

interface Query {
	t: number;
	x: number;
	y: number;
}

const q: Array<Query> = [];
for (let i = 0; i < n; i++) {
	const [t, x, y] = input[i + 1].split(" ").map((x: string): number => +x);
	q.push({t, x, y});
}

let current_t = 0;
let pos_x: number = 0;
let pos_y: number = 0;

console.log((() => {
	for (const {t, x, y} of q) {
		const dist = Math.abs(x - pos_x) + Math.abs(y - pos_y);
		const dt = t - current_t;
		if (dist > dt) {
			return false;
		}
		else if (dist % 2 !== t % 2) {
			return false;
		}
	}
	return true;
})() ? "Yes" : "No");



Measured memory_bytes: 52308
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $dp = [];
  $dp[0] = explode(" ", trim(fgets(STDIN)));

  for($i=1;$i<$n;$i++){
    $dp[$i] = explode(" ", trim(fgets(STDIN)));
    if($dp[$i-1][1]>$dp[$i-1][2]){
      $dp[$i][0] = $dp[$i][0]+$dp[$i-1][1];
    }else{
      $dp[$i][0] = $dp[$i][0]+$dp[$i-1][2];
    }

    if($dp[$i-1][2]>$dp[$i-1][0]){
      $dp[$i][1] = $dp[$i][1]+$dp[$i-1][2];
    }else{
      $dp[$i][1] = $dp[$i][1]+$dp[$i-1][0];
    }

    if($dp[$i-1][0]>$dp[$i-1][1]){
      $dp[$i][2] = $dp[$i][2]+$dp[$i-1][0];
    }else{
      $dp[$i][2] = $dp[$i][2]+$dp[$i-1][1];
    }  
  }
  
  echo max($dp[$n-1]);

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

int main(){
    int N;
    cin >> N;
    char S[N],T[N];
    for ( int i = 0; i < N; ++i){
        cin >> S[i];
    }
    for ( int i = 0; i < N; ++i){
        cin >> T[i];
    }
    char ans[2*N];
    for ( int i = 0; i < N; ++i){
        ans[2*i] = S[i];
        ans[2*i+1] = T[i];
    }
    
    for ( int i = 0; i < 2*N; ++i){
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;

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

int h, w;

bool inRange(int y, int x) {
  return y >= 0 && y < h && x >= 0 && x < w;
}

int main(void) {
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
  cout.tie(NULL);
  //freopen("in.txt", "r", stdin);
  cin >> h >> w;
  vector<string> brd(h);
  rep(i,0,h) {
    cin >> brd[i];
  }
  vector<vi> dist(h, vi(w,-1));
  queue<pair<int, int> > Q;
  rep(i,0,h) rep(j,0,w) {
    if(brd[i][j] == '#') {
      Q.push(mp(i,j));
      dist[i][j] = 0;
    }
  }
  while(!Q.empty()) {
    int y = Q.front().F;
    int x = Q.front().S;
    Q.pop();
    rep(dir,0,4) {
      int ny = y + dy[dir];
      int nx = x + dx[dir];
      if(inRange(ny, nx) && dist[ny][nx] == -1) {
        dist[ny][nx] = dist[y][x] + 1;
        Q.push(mp(ny,nx));
      }
    }
  }
  int maxD = 0;
  rep(i,0,h) rep(j,0,w) {
    maxD = max(maxD, dist[i][j]);
  }
  cout << maxD << endl;
  return 0;
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
ll n,m,k,ans;
string s,t;
const ll powll = 1LL<<1;

int main(){
  /*
  int t; cin >> t;
  vector<string> ans = {};
  while(t--){
    
  }
  rep(i,ans.size()) cout << ans[i];
  */
 int h,a; cin >> h>> a;
 if(h % a == 0){
   cout << h/a << "\n";
 }else{
   cout << h/a + 1 << "\n";
 }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
typedef map<string,ll> mapstl;
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
int main()
{
	ll n;
	cin>>n;
	vector<ld> vd(n);
	for(int i=0;i<n;i++)
	{
		cin>>vd[i];
	}
	sort(all(vd));
	ld cnt = 0;
	for(int i=0;i<n;i++){
		if(i == 0)
		{
			cnt = vd[i];con;
		}
		cnt = (cnt+vd[i])/2.0;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

struct P {
    int counter;
    int order;
};
int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    vector<int> v;
    int count = 1;
    REP(i,1,n) {
        if(s[i]!=s[i-1]) {
            v.push_back(count);
            count = 1;
        }
        else {
            count++;
        }
    }
    v.push_back(count);

    int ans = 0;

    for(auto val : v) {
        ans += val-1;
    }

    if(v.size()==2) {
        ans++;
        cout << ans << endl;
    }
    else if(v.size()==1) {
        cout << ans << endl;
    }
    else{
        if(v.size()/2<=k) {
            cout << n-1 << endl;
        }
        else {
            ans += k*2;
            cout << ans << endl;
        }
    }
    

    return 0;
}

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

long inv(int a, int m) {
	long i = 1, j = 0;
	for (int b = m; a > 1; swap(i, j), swap(a, b)) {
		j = (j + b / a * (m - i)) % m;
		b %= a;
	}
	return i;
}
long f[222222] = { 1 };
int main() {
	int n, a, b, c, p = 1e9 + 7;
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n * 2; i++)
		f[i + 1] = f[i] * (i + 1) % p;
	long A = 0, B = 0, x = 1, y = 1;
	for (int i = n - 1; i < n * 2 - 1; i++) {
		(A += ((x*f[i]) % p*(i + 1)) % p*inv(f[n - 1] * f[i - n + 1] % p, p)) %= p;
		(x *= b * inv(100 - c, p) % p) %= p;
		(B += ((y*f[i]) % p*(i + 1)) % p*inv(f[n - 1] * f[i - n + 1] % p, p)) %= p;
		(y *= a * inv(100 - c, p) % p) %= p;
	}
	long aa = A * y%p*inv(100 - c, p) % p;
	long bb = B * x%p*inv(100 - c, p) % p;
	cout << (aa + bb) * 100 % p << endl;
	return 0;
}


Measured memory_bytes: 1792
import heapq
n = int(input())
edge = [[] for _ in range(n)]
for i in range(n-1):
  a,b,c = map(int,input().split())
  a-=1;b-=1 #0index
  edge[a].append([c,b])
  edge[b].append([c,a])
#print(edge)
Q,K = map(int,input().split())
K-=1 #0index

#d = [INF for _ in range(N)]
#d[K] = 0

def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定。始点として探索されたか。というかdが更新されたか。
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中からスタートから最小の距離のものを探す
        if not used[minedge[1]]: #すでに探索済みの場合にはスキップして次のプライオリティーキューへ。
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False #ここで始点として探索済みにする。
        for e in edge[v]:
            if used[e[1]]: #行き先がすでに始点として探索済みでない場合には値を更新。
                heapq.heappush(edgelist,[e[0]+d[v],e[1]]) #重みをスタートからの最短重みにするため+d[v]
    return d ##始点sから各頂点への最短距離がアウトプットとなる。

d = dijkstra_heap(K)
#print(d)
for i in range(Q):
  x,y = map(int,input().split())
  x-=1;y-=1
  ans = d[x]+d[y]
  print(ans)

Measured memory_bytes: 55716
MOD = 10**9 + 7

n,k = (int(num) for num in input().split())
a = [int(num) for num in input().split()]
cnt_in = 0
for i in range(n):
    for j in range(i+1,n):
        if a[i] > a[j]:
            cnt_in += 1
dic = {}
for num in a:
    if num not in dic.keys():
        dic[num] = 1
    else:
        dic[num] += 1

        
dic = sorted(dic.items(), key = lambda x:x[0])
#print(dic)
cnt_out = 0
v = [item[1] for item in dic]

lv = len(v)
for i in range(lv):
    for j in range(i+1,lv):
        cnt_out += v[i] * v[j]
        
ans = int(cnt_in*k + k*(k-1)//2*cnt_out) % MOD
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(Math.min(A * N, B));
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
#define N 100000

typedef struct{
  char name[100];
  int time;
}process;

int initialize();
int isEmpty();
void enqueue(process);
process dequeue();
int min(int,int);

process Q[N];
int head ,tail;

int main(){
  int i;
  int num,quantum;
  int elaps=0,c;
  process variable;

  scanf("%d %d",&num,&quantum);

  for(i=1;i<=num;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }
  head=1;
  tail=num+1;

  while(head!=tail){
    variable=dequeue();
    c=min(quantum,variable.time);
    variable.time-=c;
    elaps+=c;
    if(variable.time>0)enqueue(variable);
    else{
      printf("%s %d\n",variable.name,elaps);
    }
  }

  return 0;
}

int isFull(){
  if(head==(tail+1)%N){
    return 1;
  }else{
    return 0;
  }
}

int isEmpty(){
  if(head==tail){
    return 1;
  }else{
    return 0;
  }
}

void enqueue(process x){
  if(isFull()==1){
    printf("OverFlow\n");
  }else{
    Q[tail]=x;
    if(tail+1==N){
      tail=0;
    }else{
      tail++;
    }
  }
}

process dequeue(){
  process x;

  if(isEmpty()==1){
    printf("Error\n");
  }else{
    x=Q[head];
    if(head+1==N){
      head=0;
    }else{
      head++;
    }
  }
  return x;
}

int min(int a,int b){
  if(a>=b){
    return b;
  }else{
    return a;
  }
}

Measured memory_bytes: 10756
#include <stdio.h>

int main(void) {
	int n;
	long long a[] = { 1, 4, 16, 61, 230, 865, 3247, 12185, 45719, 171531, 643550, 2414454, 9058467, 33985227, 127504505, 478366600, 794717734, 733354121, 261943303, 776803305, 580025381, 51688048, 44657419, 737209731, 604119499, 159693437, 858533109, 639056669, 549054109, 996291083, 531294469, 23314687, 783022045, 855462856, 649970414, 68697295, 409213624, 604356692, 88638656, 978442997, 534833116, 763737161, 785892908, 123883652, 639213333, 181836645, 998121103, 124885216, 501575626, 39816123, 113468411, 799008836, 775465589, 256852905, 664630886, 971550783, 751629411, 51018086, 702530485, 725438992, 696683714, 792638194, 221791721, 149602322, 414054379, 986519078, 981760191, 305799096, 515140586, 406959393, 975058685, 245601370, 324759692, 673385295, 191483611, 570246669, 427196161, 781042769, 569725155, 842176273, 25328739, 847501730, 206282374, 353770801, 323137024, 371653459, 940737264, 123820509, 915711339, 847205021, 252858375, 718889563, 866398347, 738390145, 133009077, 333099663, 170591295, 329869205, 616680192, 597534442, 388130742 };
	scanf("%d", &n);
	printf("%d", a[n]);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

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

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define eps 1e-6
main(){
	double a,b,x,value;
	cin>>a>>b>>x;
	value=a*a*b;
	double limit=atan(b/a);
	limit=limit/(2*acos(0))*180;
	double ans=atan((value-x)*2/(a*a*a));
	ans=ans/(2*acos(0))*180;
	if(ans>limit){
		ans=atan(a*b*b/(2*x));
		ans=ans/(2*acos(0))*180;
	}
	cout<<fixed<<setprecision(10)<<ans<<"\n";
}

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

#define int long long

using namespace std;

const int N = 1e5 + 5;
int a[N], n;

signed main(){
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);

    int sum = 0;

    for (int i = 1; i <= n; i++) sum += a[i];
    int tot = n * (n + 1) / 2;

    if (sum % tot == 0) {
        int res = sum / tot;
        bool f = true;

        for (int i = 1; i <= n; i++) {
            int j = i + 1;
            if (j > n) j = 1;
            int val = a[j] - a[i] - res;
            if (val > 0 || val % n != 0) f = false;
        }

        if (f) printf("YES");
        else printf("NO");
    }
    else printf("NO");
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()

using namespace std;

typedef vector<int> vi;
typedef long long  ll;

int dx[] = {0 , 0 , 1 , -1 , 1 , 1 , -1 , -1};
int dy[] = {1 ,-1 , 0 , 0 , -1 , 1 ,  1 , -1};
const int N = 1e5 + 10;

bool p[N];
void sieve(){
    p[0] = p[1] = true;
    for(int i = 2 ; i < N ; ++i){
        if(!p[i]){
            for(int j = i * 2 ; j < N ; j += i){
                p[j] = true;
            }
        }
    }
}

int cum[N];

int main()
{
    sieve();
    for(int i=1;i<N;++i){
        cum[i] = cum[i-1] + (!p[i] && !p[(i+1)/2]);
    }
    int q;
    cin >> q;
    while(q--){
        int l , r;
        cin >> l >> r;
        cout << cum[r] - cum[l - 1] << endl;
    }
    return 0;
}



Measured memory_bytes: 1152