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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

bool isprime(LL x){
    if(x == 2) return true;
    if(x < 2 || x % 2 == 0) return false;
    LL i = 3;
    LL sqrtx = sqrt(x);
    while(i <= sqrtx){
        if(x % i == 0) return false;
        i += 2;
    }
    return true;
}
// maxまでの素数をvectorに入れて返す
vector<LL> eratos(LL max){
    vector<LL> primeVec;
    vector<bool> isprime;
    double sqrtmax = sqrt(max);
    isprime.resize(max + 1);
    isprime[0] = false; isprime[1] = false;
    FOR(i, 2, max + 1){
        isprime[i] = true;
    }
    FOR(i, 2, sqrtmax){
        if(isprime[i]){
            for(int j = 0; i * (j + 2) < max + 1; ++j){
                isprime[i * (j + 2)] = false;
            }
        }
    }
    REP(i, max + 1){
        if(isprime[i])  primeVec.pb(i);
    }
    return primeVec;
}

/*************** using variables ***************/
int n;
/**********************************************/

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

    cin >> n;
    vector<LL> sosuu_list = eratos(55555);
    vector<LL> ans;
    
    int cnt = 0;
    while(1){
        if(ans.size() >= n) break;

        if(sosuu_list[cnt] % 10 == 3) ans.pb(sosuu_list[cnt]);

        cnt++;
    
    }
    REP(i, n) cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

bitset<11> bs;

bool solve(const string& s, int a, int b)
{
    if(s[a] == '-')
        return !solve(s, a+1, b);
    if(s[a] == 'T')
        return true;
    else if(s[a] == 'F')
        return false;
    else if(isalpha(s[a])) 
        return bs[s[a] - 'a'];

    int i = a+1;
    int bracket = 0;
    while(bracket != 0 || (s[i] != '*' && s[i] != '+' && s.substr(i, 2) != "->")){
        if(s[i] == '(')
            ++ bracket;
        else if(s[i] == ')')
            -- bracket;
        ++ i;
    }

    if(s[i] == '*')
        return solve(s, a+1, i-1) && solve(s, i+1, b-1);
    else if(s[i] == '+')
        return solve(s, a+1, i-1) || solve(s, i+1, b-1);
    else
        return !solve(s, a+1, i-1) || solve(s, i+2, b-1);
}

int main()
{
    for(;;){
        string s;
        cin >> s;
        if(s == "#")
            return 0;

        int j = s.find('=');
        bool ret = true;
        for(int i=0; i<(1<<11); ++i){
            bs = i;
            if(solve(s, 0, j-1) != solve(s, j+1, s.size()-1))
                ret = false;
        }

        if(ret)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}

Measured memory_bytes: 960
#include <iostream>
#include <vector>
using namespace std;
#define ll long long int
const ll mod = 1e9 + 7;
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector< ll > sum(26);
  for ( int i = 0; i < n; ++i ) {
    char x = s[i];
    for (int j = 0; j < 26; ++j){
      char y = 'a' + j;
      if ( x == y) ++sum[j];  
    }
  }
  ll ans = 1;
  for (int i = 0; i < 26; ++i){
    ans *= sum[i] + 1;
    ans %= mod;
  }
  cout << ans - 1 << endl;
  return 0;
}


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

int main() {
	int N;
	int t[110000], x[110000], y[110000];
	cin >> N;
	t[0] = x[0] = y[0] = 0;
	for (int i = 0; i < N; ++i) cin >> t[i+1] >> y[i+1] >> x[i+1];

	bool can = true;
	for (int i = 0; i < N; ++i) {
		int dt = t[i+1] - t[i];
		int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
		if (dt < dist) can = false;
		if (dist % 2 != dt % 2) can = false;
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

using namespace std;

int main(){

    int n, counter = 0;

    cin >> n;

    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j+=2){

            counter++;
        }
    }

    cout << counter << endl;

    return 0;

}



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

using namespace std;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int D, G;
  cin >> D >> G;
  vector<pii> PC(D);
  for (int i = 0; i < D; i++) {
    int p, c;
    cin >> p >> c;
    PC[i] = make_pair(p, c);
  }
  int res = 1 << 28;
  for (int k = 0; k < (1 << D); k++) {
    int score = 0, cnt = 0;
    for (int i = 0; i < D; i++) {
      if ((k >> i) & 1) {
        cnt += PC[i].first;
        score += 100 * (i + 1) * PC[i].first + PC[i].second;
      }
    }

    if (score >= G) {
      res = min(res, cnt);
      continue;
    }

    for (int i = D - 1; i >= 0; i--) {
      if ((k >> i) & 1) continue;
      for (int j = 0; j < PC[i].first; j++) {
        cnt++;
        score += 100 * (i + 1);
        if (score >= G) break;
      }
      break;
    }

    if (score >= G) {
      res = min(res, cnt);
    }
  }
  cout << res << '\n';
  return 0;
}


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

using namespace std;

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

int main() {
    int H, W;
    cin >> H >> W;
    char field[H + 2][W + 2];
    memset(field, '.', sizeof(field));
    string s;
    for (int i = 1; i < H + 1; ++i) {
        cin >> s;
        for (int j = 1; j < W + 1; ++j) {
            field[i][j] = s[j - 1];
        }
    }

    for (int i = 1; i < H + 1; ++i) {
        for (int j = 1; j < W + 1; ++j) {
            if (field[i][j] == '#') {
                bool near = false;
                for (int k = 0; k < 4; ++k) {
                    if (field[i + dy[k]][j + dx[k]] == '#') {
                        near = true;
                        break;
                    }
                }
                if (!near) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

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


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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;

    int x;
    x = digitsum(n);

    if (n % x == 0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1000;
const int maxm = 8e3;
const ll inf = 1e18;
const ll mx = 3e9;
struct edge
{
    int to;
    ll c;
    ll f;
    ll w;
    int nxt;
}e[31000];
int head[maxm + 10];
int tot;
int n;
int S,T;
void addedge(int u,int v,ll w,ll c)
{
    //cout<<u << v << w<< c<<endl;
    e[tot].to = v;
    e[tot].w = w;
    e[tot].c = c;
    e[tot].nxt = head[u];
    head[u] = tot++;

    e[tot].to = u;
    e[tot].w = -w;
    e[tot].c = 0;
    e[tot].nxt = head[v];
    head[v] = tot++;

}

ll dis[maxm+10];
bool vis[maxm+10];
int pre[maxm+10];
bool spfa()
{
    for(int i=0;i<=T;i++)
        dis[i] = inf;
    //memset(dis,inf,0,sizeof(dis));
    memset(pre,-1,sizeof(pre));
    memset(vis,false,sizeof(vis));
    dis[S] = 0;
    vis[S] = true;
    queue<int>q;
    q.push(S);
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        vis[u] = false;
        for(int i = head[u];i != -1;i = e[i].nxt)
        {
            int v = e[i].to;
            if(e[i].c)
            {
                if(dis[u] + e[i].w < dis[v])
                {
                    dis[v] = dis[u] + e[i].w;
                    pre[v] = i;
                    if(!vis[v])
                    {
                        vis[v] = true;
                        q.push(v);
                    }
                }
            }
        }
    }
    return dis[T] != inf;
}

ll MCMF()
{
    ll ret = 0;
    while(spfa())
    {
        ll flow = inf;
        for(int i = T;i != S;i = e[pre[i]^1].to)
        {
            flow = min(e[pre[i]].c,flow);
        }
        for(int i = T; i != S; i = e[pre[i]^1].to)
        {
            e[pre[i]].c -= flow;
            e[pre[i]^1].c += flow;
            ret += e[pre[i]].w * flow;
        }
    }
    return ret;
}

int main()
{
    while(~scanf("%d",&n))
    {
        tot = 0;
        memset(head,-1,sizeof(head));
        S = 1,T = S + 2*n + 5;
        for(int i=1;i<=n;i++)
        {
            int x,y,c;
            scanf("%d%d%d",&x,&y,&c);
            addedge(S,S+i,0,c);
            addedge(S+i,S+n+1,x+y,c);
            addedge(S+i,S+n+2,x-y,c);
            addedge(S+i,S+n+3,-x+y,c);
            addedge(S+i,S+n+4,-x-y,c);
        }

        for(int i=1;i<=n;i++)
        {
            int x,y,c;
            scanf("%d%d%d",&x,&y,&c);
            addedge(S+n+4+i,T,0,c);
            addedge(S+n+1,S+n+4+i,-x-y,c);
            addedge(S+n+2,S+n+4+i,-x+y,c);
            addedge(S+n+3,S+n+4+i,x-y,c);
            addedge(S+n+4,S+n+4+i,x+y,c);
        }

        printf("%lld\n",-MCMF());
    }
    return 0;
}


Measured memory_bytes: 1280
from collections import deque
from copy import deepcopy

length,kaisu=map(int,input().split())
A=deque(map(int,input().split()))
maxhist=[0]
for left in range(kaisu+1):
  for right in range(kaisu-left+1):
    l=deepcopy(A)
    point=[]
    dropable=kaisu-left-right
    for i in range(left):
      try:
        num=l.popleft()
        point.append(num)
      except:
        pass
    for j in range(right):
      try:
        num2=l.pop()
        point.append(num2)
      except:
        pass
    droptime=0
    while(droptime<dropable):
      if point==[]:
        break
      elif min(point)>0:
        break
      else:
        try:
          point.sort(reverse=True)
          point.pop(-1)
          droptime+=1
        except:
          break
    maxhist.append(sum(point))
print(max(maxhist))

Measured memory_bytes: 3724
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		String s;
		String p;
		StringBuilder ling = new StringBuilder();
		final int MAX_LENGTH = 100;

		Scanner stdIn = new Scanner(System.in);

		s = stdIn.nextLine();
		p = stdIn.nextLine();

		while(ling.length() <= MAX_LENGTH) {
			ling.append(s);
		}

		if(ling.indexOf(p) == -1) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

	}

}

Measured memory_bytes: 26320
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 

template <class T>
class SegTree {
    int n;// 葉の数
    vector<T> data;// データを格納するvector
    T def; // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;// 点更新で使う処理

    // 区間[a,b)の総和。ノードk=[l,r)に着目している。
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def; // 交差しない
        if (a <= l && r <= b)
            return data[k]; // a,l,r,bの順で完全に含まれる
        else {
            T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
            T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
            return operation(c1, c2);
        }
    }

    public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    SegTree(size_t _n, T _def, function<T(T, T)> _operation,
        function<T(T, T)> _update)
        : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }

    // 場所i(0-indexed)の値をxで更新
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    // [a, b)の区間クエリを実行
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    // 添字でアクセス
    T operator[](int i) {
        return data[i + n - 1];
    }
};

int main(){
    ll n;cin >> n;
    vl v(n);rep(i,n)cin >> v[i];
    vl pls=v;sort(all(pls));
    rep(i,n)v[i]=lower_bound(all(pls),v[i])-pls.begin();
    SegTree<ll> st(
        n,0,[](ll a,ll b){return a+b;},[](ll a,ll b){return a+b;}
    );
    ll ans=0;
    rep(i,n){
        ans+=i-st.query(0,v[i]);
        st.change(v[i],1);
    }
    cout << ans <<endl;
}


Measured memory_bytes: 9852
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    if (S.charAt(1) == 'R') {
      System.out.println("ABC");
    } else {
      System.out.println("ARC");
    }
  }
}

Measured memory_bytes: 26944
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  if(n == 1) {
    cout << "Hello World" << endl;
  } else {
    int a,b ;
    cin >> a>>b;
    cout << a + b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll A, B;

int main() {
	scanf("%lld %lld", &A, &B);
	if(B % A == 0) {
		printf("%lld\n", A + B);
	}
	else {
		printf("%lld\n", B - A);
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
import sys
from collections import deque
import copy
def main():
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    count = sum(A)
    if N - count < 0:
        print(-1)
    else:
        print(N - count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10440
/*
the top of the losers
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    Lcm(a,b)  ((a*b)/(__gcd(a,b)))
#define    X            real()
#define    Y            imag()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
#define     point        complex<double>
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    PI  acos(-1)
typedef  long long     ll ;
typedef  unsigned long long     ull ;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
void solve(ll n){
   ll mi=n*2;
   for(ll i=1;i*i<=n;i++){
      if(n%i==0){
        mi=min(mi,(i-1)+(n/i-1));
      }
   }
   cout<<mi<<endl;

}
int main(){
    ll n;
    cin>>n;
    solve(n);
}


Measured memory_bytes: 256
from math import gcd
from itertools import combinations_with_replacement

def readlines(n):
    for _ in range(n):
        a, b, c, d = map(int, input().split())
        yield a-1, b-1, c, d

def main():
    n, m, q = map(int, input().split())
    X = list(readlines(q))

    for comb in combinations_with_replacement(range(1, m+1), n):
        x = 0
        for a, b, c, d in X:
            if comb[b] - comb[a] == c:
                x += d
        yield x

print(max(main()))



Measured memory_bytes: 9196
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Mon Aug  6 00:33:42 2018
//
package main

import "fmt"

var R int

func main() {
	fmt.Scan(&R)
	if R < 1200 {
		fmt.Println("ABC")
	} else if R < 2800 {
		fmt.Println("ARC")
	} else {
		fmt.Println("AGC")
	}
}


Measured memory_bytes: 512
main = do
  li <- getLine
  let [a,b,c] = map read $ words li
  print $ compute a b c

-- 偶数があれば0
-- 全て奇数なら、小さい方ふたつの積

compute :: Int -> Int -> Int -> Int
compute a b c
  | even a || even b || even c = 0
  | a < b = a * min b c
  | True  = b * min c a


Measured memory_bytes: 508
#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)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

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

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 1e3 + 5;

int n;
ld x[MAXN], y[MAXN];

ld dist(ld x1, ld y1, ld x2, ld y2){
  ld tmp1 = (x1 - x2), tmp2 = (y1 - y2);
  return sqrt( tmp1 * tmp1 + tmp2 * tmp2 );
}

ld check(ld x1, ld y1){
  ld ret = 0;
  REP(i, n)
    ret = max(ret, dist(x1, y1, x[i], y[i]));
  return ret;
}

const int IT = 50;
const ld eps = 1e-9;

ld solve_y(ld X){
  ld lo = -2000, hi = 2000;
  REP(i, IT){
    ld mid = (lo + hi) / 2;
    if(check(X, mid) > check(X, mid + eps))
      lo = mid;
    else
      hi = mid;
  }
  return check(X, lo);
}

ld solve_x(){
  ld lo = -2000, hi = 2000;
  REP(i, IT){
    ld mid = (lo + hi) / 2;
    if(solve_y(mid) > solve_y(mid + eps))
      lo = mid;
    else
      hi = mid;
  }
  return solve_y(lo);
}

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

  cin >> n;
  REP(i, n)
    cin >> x[i] >> y[i];
  cout << setprecision(6) << fixed << solve_x() << "\n";
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	N := readInt()
	d := make([]int, N)
	for i := range d {
		d[i] = readInt()
	}
	sort.Ints(d)
	j := N / 2
	println(d[j] - d[j-1])
}

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


Measured memory_bytes: 2048
using System;
using System.Collections.Generic;

class Program
{
    #region library
    static int n = 0;
    static int m = 0;
    static int r = 0;
    static int c = 0;
    static int x = 0;
    static int y = 0;
    static int[] arr;
    static string s = "";
    static string[] ss;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static long sum = 0;
    static long cnt = 0;
    static long max = -1;
    static long min = 2147483647;
    static bool flg = false;
    static bool flg2 = false;
    static char[,] map;
    static int[,] imap;
    static string rl()
    {
        return Console.ReadLine();
    }
    static string[] rls()
    {
        return Console.ReadLine().Split();
    }
    static void wl(object obj = null)
    {
        Console.WriteLine(obj);
    }
    static void w(object obj)
    {
        Console.Write(obj);
    }
    static int Int(string s)
    {
        return int.Parse(s);
    }
    static long Max(long a, long b)
    {
        return Math.Max(a, b);
    }
    static long Min(long a, long b)
    {
        return Math.Min(a, b);
    }
    static long Abs(long a)
    {
        return Math.Abs(a);
    }
    static void yes()
    {
        wl("YES");
    }
    static void no()
    {
        wl("NO");
    }
    static void Sum()
    {
        wl(sum);
    }
    static void Cnt()
    {
        wl(cnt);
    }
    static void setmap(char def = '@')
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        map = new char[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == '@') s = rl();
            for (int j = 0; j < c; j++)
            {
                map[i, j] = (def == '@') ? s[j] : def;
            }
        }
    }
    static void setimap(int def = -1)
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        imap = new int[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == -1) s = rl();
            for (int j = 0; j < c; j++)
            {
                imap[i, j] = (def == -1) ? Int(s[j].ToString()) : def;
            }
        }
    }
    #endregion

    static void Main(string[] args)
    {
        s = rl();
        for (int i = 0; i < s.Length; i++)
        {
            sum += Int(s[i].ToString());
        }

        if(Int(s.ToString()) % sum == 0)
        {
            wl("Yes");
        }
        else
        {
            wl("No");
        }
    }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
 
int main() {
  string S; cin >> S;
  bool f=true;
  for(int i=0; i<3; i++) {
    if(S[i]==S[i+1]) {f=false; cout << "Bad" << endl; break;}
  }
  if(f) cout << "Good" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;

//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
/*
vector<int> d(100000);
vector<int> b(100000);
class UnionFind{
	public:
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	signed find(signed x){
		if(d[x]==x){
			return x;
		}else{
			return d[x]=find(d[x]);
		}
	}
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	void unite(signed x,signed y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(b[x]<b[y]){
			d[x]=y;
		}else{
			d[y]=x;
			if(b[x]==b[y])b[x]++;
		}
	}
	bool same(signed x,signed y){return (find(x)==find(y));}
};
*/
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int m,n;
	cin>>n>>m;
	vector<string> a(n);
	vector<string> b(m);

	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];

	rep(i,n-m+1)rep(j,n-m+1){
		rep(k,m)rep(l,m)if(a[i+k][j+l]!=b[k][l])goto BB;
		cout<<"Yes"<<endl;
		return 0;
BB:
		continue;
	}
	cout<<"No"<<endl;


	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
x = 100
count1 = 0
for i in a:
    count1 += (i - x)**2

for X in range(-100, 100):
    count = 0
    for i in a:
        count += (i - X)**2
    if count < count1:
        count1 = count

print(count1)


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int number;
  vector<char> alphabet = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < 26; j++) {
      if (S.at(i) == alphabet.at(j)) {
        number = j;
        S.at(i) = alphabet.at((number+N)%26);
        break;
      }
    }
    
  }
  cout << S << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
ll n, ans = 0, a[300010];
int main() {
	cin >> n;
	for (int i = 0; i < 3 * n; i++)cin >> a[i];
	sort(a, a + 3 * n);
	for (int i = 0; i < n; i++)ans += a[3 * n - 2 * i - 2];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main()
{
  cout << setprecision(6);
  cout << setiosflags(ios::scientific);
  cout.flags(ios::fixed);

  //  while(true){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++)
      {
	cin >> a[i];
      }
    for(int i=n-1; i>=0; i--){
      cout << a[i];
      if(i==0)
	cout << endl;
      else
	cout << " ";
    //  }
    }
}

Measured memory_bytes: 1160
H, W = map(int, input().split())
c = [
    list(map(int, input().split()))
    for _ in range(10)
]
 
for k in range(10):
    for i in range(10):
        for j in range(10):
            c1 = c[i][j]
            c2 = c[i][k] + c[k][j]
            if c1 > c2:
                c[i][j] = c2

ans = 0
for _ in range(H):
    for a in map(int, input().split()):
        if a != -1:
            ans += c[a][1]

print(ans)

Measured memory_bytes: 3064
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('\n');
  var params = inputs[0].split(' ').map(Number);

  (function(a, b) {
    console.log(a*b, 2*(a + b));

  })(params[0], params[1]);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15532
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> mylist;
int main()
{
	string S1, T;
	int match=0;
	cin >> S1 >> T;
	int len;
	len = S1.size() - T.size();
	for (int i = 0; i <= len; i++)
	{
		string S;
		S = S1;
		
		match = 1;
		for (int j = 0; j < T.size(); j++)
		{
			if (S[i + j] == T[j] || S[i + j] == '?')
				S[i + j] = T[j];
			else
			{
				match = 0;
				break;
			}
		}
		if (match == 0)
			continue;
		else
		{
			for (int k = 0; k < S.size(); k++)
			{
				if (S[k] == '?')
					S[k] = 'a';
			}
			mylist.push_back(S);
		}
		
	}
	if (mylist.size())
	{
		sort(mylist.begin(),mylist.end());
		cout << mylist.front() << endl;
	}
	else
		cout << "UNRESTORABLE " << endl;
	return 0;
}

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

int main(void) {

	int S;
	cin >> S;

	int h, m, s;
	h = S / 3600;
	m = (S - h * 3600) / 60;
	s = S % 60;

	cout << h << ":" << m << ":" << s << endl;


	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    fastio;
    string str;
    cin >> str;
    
    int n = str.size();
    
    int DP[2][2020];
    int rem[21000];
    ll ans = 0;
    
    for (int i = 0; i < 21000; i++)
    	rem[i] = i % 2019;
    	
    DP[0][str[0] - '0'] = 1;
    
    for (int i = 1; i < n; i++) {
    	
    	for (int j = 0; j < 2019; j++) {
    		
    		int index = rem[j * 10 + (str[i] - '0')];
    		DP[i & 1][index]  += DP[(i - 1) & 1][j];
		}
		
		ans += DP[i & 1][0];
		DP[i & 1][str[i] - '0']++;
		memset(DP[(i - 1) & 1], 0, sizeof DP[(i - 1) & 1]);
	}
	
	cout << ans << "\n";
	//code
	return 0;
}


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

int main()
{
    string deck, buffer1, buffer2, result;
    int m, h, decklen;

    while(1){
        cin >> deck;
        if(deck == "-") break;
        decklen = deck.length();
        cin >> m;

        for(int i = 0; i < m; i++){
            scanf("%d", &h);
            buffer1 = deck.substr(0, h);
            buffer2 = deck.substr(h);
            deck = buffer2 + buffer1;
        }
        cout << deck << endl;
    }
    return 0;
}

Measured memory_bytes: 1264
#include <stdio.h>
#include <string.h>

int main(void) {
    int N;
    int i;
    int input[100];
    int num[110] = {0};
    int count = 0;
    
    scanf("%d", &N);
    
    for (i = 0; i < N; i ++) {
        scanf("%d", &input[i]);
    }
    
    for (i = 0; i < N; i ++) {
        num[input[i]] ++;
    }
    
    for (i = 1; i <= 100; i ++) {
        if (num[i] > 0) {
            count ++;
        }
    }
    
    printf("%d\n", count);
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;
const string ye = "Yay!", no = ":(";

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return x * modpow(x * x % mod, n / 2) % mod;
	return  modpow(x * x % mod, n / 2) % mod;
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int n;
P p[55];
int ans = inf;
map<int,bool> used;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n);
	rep(i, n) {
		rep(j, n) {
			if (i == j) continue;
			rep(k, n) used[k] = false;
			used[i] = true, used[j] = true; 
			int a = p[j].first - p[i].first, b = p[j].second - p[i].second;
			P q = p[j];
			int cnt = 1;
			int w = 2;
			while (w != n) {
				bool can = false;
				rep(k, n) {
					if (!used[k] && p[k] == P(q.first + a, q.second + b)) {
						q = p[k];
						used[k] = true;
						can = true;
						w++;
						break;
					}
				}
				if (!can) {
					if (w == n) break;
					cnt++;
					rep(k, n) {
						if (!used[k]) {
							q = p[k];
							used[k] = true;
							w++;
							break;
						}
					}
				}
				
			}
			ans = min(ans, cnt);
		}
	}
	if (n == 1) ans = 1;
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const int N = 30;

int n, x, ans;
int a[N];

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++ )
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; i ++ ){
        scanf("%d", &x);
        ans += x;
    }
    for (int i = 1; i < n; i ++ ){
        scanf("%d", &x);
        for (int j = 1; j < n; j ++ )
            if (a[j] == i && a[j + 1] == i + 1)
                ans += x;
    }
    printf("%d\n", ans);
    return 0;
}

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

typedef long double ld;									// XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
#define mem(a,x) memset(a,x,sizeof(a))
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9+7;
const int INF = 1e18;
const int maxn = 2e5+5;


void solve(){
	int x, k, d; cin>>x>>k>>d;
	x = abs(x);
	int ans = 0;
//	cout<<ceil(1.0*(x)/d)<<" ";
	if(ceil(1.0*(x)/d) > k){
		ans = x - d*k; ans  = abs(ans);
		cout<<ans; return;
	}
	if(x%d == 0){
		if((k - x/d)%2 == 1){
			ans = d; 
		} //cout<<"xx";
		cout<<ans;
	}else{
		int z = x/d; //cout<<"x";
		if((k - z)%2 == 0) ans = abs(x - d*(x/d));
		else{
			ans = abs(x - (d)*(x/d+1)); //cout<<"zzz";
		} 
		cout<<ans;
	}
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    cout<<setprecision(16);
    
    int tc=1;// cin>>tc; 
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3612
<?php
fscanf(STDIN, "%d", $N);
$a = [];
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%s %d", $S, $P);
    $a[] = sprintf("%s%03d", $S, 100 - $P);    
}
asort($a);
$b = [];
foreach ($a as $k => $v) {
    $b[] = $k + 1;
}
echo implode(" ", $b);


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	int a[52],c=0;
	for(int i=1;i<=N;i++){
		scanf("%d",&a[i]);
		if(a[i]!=i) c++;
	}
	if(c<3) printf("YES");
	else printf("NO");
	return 0;
}

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

int main(){
  int n, d;
  cin >> n >> d;
  
  vector<vector<int>> v(n, vector<int>(d));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> v[i][j];
    }
  }
  
  int cnt = 0;
  for(int k = 0; k < (n-1); k++){
    for(int l = (k+1); l < n; l++){
      double dis = 0;
      for(int m = 0; m < d; m++){
        dis += pow((v[k][m]-v[l][m]), 2);
      }
      dis = pow(dis,.5);
      if(ceil(dis) == floor(dis)) cnt++;
    }
  }
  cout << cnt;
}

Measured memory_bytes: 384
// to be build tomorrow
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update> 
#include <bits/stdc++.h> 
using namespace std; 
ordered_set s[200005];
struct pt {
    long long x, y;
    pt() {}
    pt(long long _x, long long _y) : x(_x), y(_y) {}
    pt operator-(const pt& p) const { return pt(x - p.x, y - p.y); }
    long long cross(const pt& p) const { return x * p.y - y * p.x; }
    long long cross(const pt& a, const pt& b) const { return (a - *this).cross(b - *this); }
};

int sgn(const long long& x) { return x >= 0 ? x ? 1 : 0 : -1; }

bool inter1(long long a, long long b, long long c, long long d) {
    if (a > b)
        swap(a, b);
    if (c > d)
        swap(c, d);
    return max(a, c) <= min(b, d);
}

bool check_inter(const pt& a, const pt& b, const pt& c, const pt& d) {
    if (c.cross(a, d) == 0 && c.cross(b, d) == 0)
        return inter1(a.x, b.x, c.x, d.x) && inter1(a.y, b.y, c.y, d.y);
    return sgn(a.cross(b, c)) != sgn(a.cross(b, d)) &&
           sgn(c.cross(d, a)) != sgn(c.cross(d, b));
}
using pp = pair <ll, ll>;
ll dp[30][30][2];
ll valid(ll f1, ll pos, string s, string cur, ll count)
{
    if (pos == s.length())
    {
        // cout << cur << "\n";
        if (stoull(cur))
        return 1;
        return 0;
    }
    if (dp[pos][count][f1] != -1)
    return dp[pos][count][f1];
    if (f1 == 1)
    {
        dp[pos][count][f1] = valid(f1, pos+1,s, cur+'0', count) + valid(f1, pos+1,s, cur + '1', count+1);   
    }
    else 
    {
        if (s[pos] == '0')
        {
            dp[pos][count][f1] = valid (f1, pos+1, s, cur+'0', count);
        }
        else if (s[pos] == '1')
        dp[pos][count][f1] = valid(0, pos+1, s, cur+'1', count+1) + valid(1, pos+1, s, cur + '0', count);
        else 
        dp[pos][count][f1] = valid(1, pos+1, s, cur+'1',count+1) + valid(1, pos+1, s, cur+'0', count);
    }
    return dp[pos][count][f1];
}
int main ()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        string a;
        ll sum = 0;
        ll tp = 1;
        ll p = 0;
        ll x;
        while (sum < n)
        {
            x = sum;
            p++;
            tp *= 26;
            sum += tp;
        }
        n -= x;
        for (ll i = 0 ; i < p ; i++)
        {
            ll aage = powl(26, p-i-1);
            ll j;
            for (j = 1 ; j < 26 ; j++)
            {
                if (n <= aage*j)
                break;
            }
            a += ('a' + j - 1);
            n -= ((j-1)*aage);
        }
        cout << a ;
}
    return 0;
}

Measured memory_bytes: 22480
/*
                        Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}      
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi
    int x;
    cin>>x;
    int res=x/500;
    if(x%500==0)
    cout<<res*1000;
    else
    {   int count=x-(res*500);
        count=count/5;
        cout<<(res*1000)+(count*5);
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int h,w;cin >> h >> w;
	vector<vector<int>> A(h, vector<int>(w));

	int c[10][10];
	rep(i,10)
		rep(j,10)
		cin >> c[i][j];
	
	rep(k,10)
		rep(i,10)
			rep(j,10)
			{
				c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
			}

	rep(i,h)
		rep(j,w)
		cin >> A[i][j];

	int cnt=0;

	rep(i,h)
		rep(j,w)
		if(A[i][j]!=-1)cnt+=c[A[i][j]][1];

	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 384
use std::cmp::*;
use std::io::*;

fn calc(mut n: i64, mut x: i64) -> i64 {
    let mut res = 0;
    while n != 0 {
        if x == 0 {
            return 0;
        }
        n = n % x;
        x = n.count_ones() as i64;
        res += 1;
    }
    res
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: i64 = itr.next().unwrap().parse().unwrap();
    let mut s: Vec<char> = itr.next().unwrap().chars().collect();

    let mut cnt = 0;
    for i in 0..n {
        if s[i as usize] == '1' {
            cnt += 1;
        }
    }
    s.reverse();

    let mut pc1 = vec![1; n as usize + 1];
    let mut pc2 = vec![1; n as usize + 1];
    for i in 0..n {
        pc1[i as usize + 1] = pc1[i as usize] * 2 % (cnt + 1);
        if cnt > 1 {
            pc2[i as usize + 1] = pc2[i as usize] * 2 % (cnt - 1);
        }
    }

    let mut all1 = 0;
    let mut all2 = 0;
    for i in 0..n {
        all1 += if s[i as usize] == '1' {
            pc1[i as usize]
        } else {
            0
        };
        all1 %= cnt + 1;

        if cnt > 1 {
            all2 += if s[i as usize] == '1' {
                pc2[i as usize]
            } else {
                0
            };
            all2 %= cnt - 1;
        }
    }

    let mut out = Vec::new();
    for i in 0..n {
        if s[i as usize] == '1' {
            if cnt <= 1 {
                writeln!(out, "{}", 0).ok();
            } else {
                let tmp = (cnt - 1 + all2 - pc2[i as usize] % (cnt - 1)) % (cnt - 1);
                writeln!(out, "{}", calc(tmp, tmp.count_ones() as i64) + 1).ok();
            }
        } else {
            let mut tmp = all1 + pc1[i as usize];
            tmp %= cnt + 1;
            writeln!(out, "{}", calc(tmp, tmp.count_ones() as i64) + 1).ok();
        }
    }

    out.reverse();
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 6568
N, K = map(int,input().split())
hN = list(map(int,input().split()))
dp = [1000000000]*N
dp[0] = 0
for n in range(N-1):
  for k in range(min(K,N-n-1)):
    dp[n+k+1] = min(dp[n+k+1], dp[n]+abs(hN[n]-hN[n+k+1]))
print(dp[-1])


Measured memory_bytes: 52448
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const ll INF=0x3f3f3f3f;
struct Edge{
    int u,v,d;
}edge[4*maxn];
ll a[maxn];
int head[maxn],ext[4*maxn];
int e;
void addedge(int u,int v,int d){
    edge[e].u=u;edge[e].v=v;edge[e].d=d;ext[e]=head[u];head[u]=e++;
    edge[e].u=v;edge[e].v=u;edge[e].d=-d;ext[e]=head[v];head[v]=e++;
}
bool vis1[maxn];
bool vis2[4*maxn];
void init(){
    memset(head, -1, sizeof(head));
    memset(vis1, false, sizeof(vis1));
    memset(vis2, false, sizeof(vis2));
    e=0;
}
void dfs(int x){
    for(int j=head[x];~j;j=ext[j]){
        int v=edge[j].v;
        if(vis1[v])continue;
        a[v]=a[x]-edge[j].d;
        vis1[v]=true;
        dfs(v);
    }
}
int main(){
    int N,M;
    while (scanf("%d%d",&N,&M)!=EOF) {
        int l,r,d;
        init();
        for(int i=1;i<=M;i++){
            scanf("%d%d%d",&l,&r,&d);
            addedge(r,l, d);
        }
        for(int i=1;i<=N;i++){
            if(vis1[i])continue;
            a[i]=0;vis1[i]=true;
            dfs(i);
        }
        int flag=true;
        for(int i=0;i<e;i++){
            int u=edge[i].u,v=edge[i].v,d=edge[i].d;
            if(vis1[u]&&vis1[v])
                if(a[u]-a[v]!=d)
                {flag=false;break;}
        }
        if(flag)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 9984
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
    int n;
    cin>>n;
    map<string,int>m;
    string s;
    int cnt=1;
    rep(i,n){
        cin>>s;
        if(m.count(s)){
            m[s]+=1;
            if(m[s]>cnt){
                cnt=m[s];
            }
        }else{
            m[s]=1;
        }
    }
    for(auto p:m){
        if(p.second==cnt){
            cout<<p.first<<endl;
        }
    }


    
}


Measured memory_bytes: 19252