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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

typedef long long ll;
const int INF = 1001001001;

const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

mint dp[61][2][2][2];

int main() {
    ll l, r;
    cin >> l >> r;

    dp[60][0][0][0] = 1;

    for (int i = 59; i >= 0; i--) {
        int lb = l >> i & 1;
        int rb = r >> i & 1;

        rep(j, 2) rep(k, 2)rep(s, 2) {
                    mint pre = dp[i + 1][j][k][s];
                    rep(x, 2)
                        rep(y, 2) {
                            if (x && !y) continue;

                            int nj = j, nk = k, ns = s;

                            if (!s && x != y) continue;
                            if (x && y) ns = 1;

                            if (!j && !x && lb) continue;
                            if (x && !lb) nj = 1;

                            if (!k && y && !rb) continue;
                            if (!y && rb) nk = 1;

                            dp[i][nj][nk][ns] += pre;
                        }

                }
    }

    mint ans;
    rep(j, 2) {
        rep(k, 2) {
            rep(s, 2) {
                ans += dp[0][j][k][s];
            }
        }
    }
    cout << ans.x << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int sx=stdIn.nextInt();
		int sy=stdIn.nextInt();
		int tx=stdIn.nextInt();
		int ty=stdIn.nextInt();
		boolean fin=false;
		int x=sx,y=sy;
		while(true){
			if(x==tx)
				break;
			if(x<tx){
				System.out.print("R"); x++;
			}
			else{
				System.out.print("L"); x--;
			}
		}
		while(true){
			if(y==ty)
				break;
			if(y<ty){
				System.out.print("U"); y++; fin=true;
			}
			else{
				System.out.print("D"); y--; fin=false;
			}
		}
		if(fin){
			System.out.print("U"); y++;
		}
		else{
			System.out.print("D");y--;
		}
		while(true){
			if(x==sx)
				break;
			if(x<sx){
				System.out.print("R"); x++; fin=true;
			}
			else{
				System.out.print("L"); x--; fin=false;
			}
		}
		if(fin){
			System.out.print("R"); x++;
		}
		else{
			System.out.print("L");x--;
		}
		while(true){
			if(y==sy)
				break;
			if(y<sy){
				System.out.print("U"); y++;
			}
			else{
				System.out.print("D"); y--;
			}
		}
		if(fin){
			System.out.print("L"); x--;
		}
		else{
			System.out.print("R");x++;
		}
		while(true){
			if(y==ty)
				break;
			if(y<ty){
				System.out.print("U"); y++;
			}
			else{
				System.out.print("D"); y--;
			}
		}
		while(true){
			if(x==tx)
				break;
			if(x<tx){
				System.out.print("R"); x++; fin=true;
			}
			else{
				System.out.print("L"); x--; fin=false;
			}
		}
		if(fin){
			System.out.print("R"); x++;
		}
		else{
			System.out.print("L");x--;
		}
		while(true){
			if(y==sy)
				break;
			if(y<sy){
				System.out.print("U"); y++; fin=true;
			}
			else{
				System.out.print("D"); y--; fin=false;
			}
		}
		if(fin){
			System.out.print("U"); y++;
		}
		else{
			System.out.print("D");y--;
		}
		while(true){
			if(x==sx)
				break;
			if(x<sx){
				System.out.print("R"); x++;
			}
			else{
				System.out.print("L"); x--;
			}
		}
		if(fin){
			System.out.print("D"); y--;
		}
		else{
			System.out.print("U");y++;
		}
	}
}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
int n,m,K;
int in[105];
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&in[i]);
	int B[5];
	int ans=0;
	for(int i=2;i<n;i++){
		B[1]=in[i-1],B[2]=in[i],B[3]=in[i+1];
		sort(B+1,B+3+1);
		if(in[i]==B[2])ans++;
	}
	printf("%d\n",ans);
}
int main(){
	solve();
	return 0;
}

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

const int mod = 1000000007;

long long memo[2048];

long long solve(long long current) {
  if (memo[current] != -1) {
    return memo[current];
  }
  if (current <= 2) {
   memo[current] = 0;
   return memo[current]; 
  }
  if (current <= 5) {
    memo[current] = 1;
    return memo[current];
  }
  long long sum = 1;
  for (long long i = 3; i <= current-3; ++i) {
  	sum += solve(i);
    sum %= mod;
  }
  return memo[current] = sum;
}

int main() {
  memset(memo, -1, sizeof(memo));
  long long S;
  cin >> S;
  cout << solve(S) << endl;
  return 0; 
}

Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

struct edge {
    ll to, cost;
};

int N;
VV<edge> G(1000000);
V<ll> d(1000000);

void addedge(VV<edge>& G, int st, int ed, ll co) {
    edge e;
    e.to = ed;
    e.cost = co;
    G[st].push_back(e);
}

void dijkstra(int s) {
    priority_queue<plglg, vector<plglg>, greater<plglg> > que;
    fill(d.begin(), d.end(), inf);
    d[s] = 0;
    que.push(plglg(0, s));

    while (!que.empty()) {
        plglg p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) {
            continue;
        }
        int len = G[v].size();
        for (int i = 0; i < len; i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(plglg(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll M;
    cin >> N >> M;
    REP(i, 0, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        addedge(G, a, b, 1);
        addedge(G, b, a, 1);
    }
    dijkstra(0);
    cout << "Yes" << endl;
    REP(i, 1, N) {
        ll val = d[i];
        REP(j, 0, G[i].size()) {
            edge e = G[i][j];
            if (d[e.to] == val - 1) {
                cout << e.to + 1 << endl;
                break;
            }
        }
    }
}


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

int main(){
int H,W;

while(1){
cin>>H>>W;
if(W==0&&H==0)break;
for(int i=0;i<H;i++){
for(int x=0;x<W;x++){
if(i==0||i==H-1||x==0||x==W-1)cout<<'#';
else{cout<<'.';}
}
cout<<endl;
}
cout<<endl;
}
return 0;
}


Measured memory_bytes: 3084
import sys
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

import math

N, D = mi()

X = [li() for _ in range(N)]

count = 0
for i in range(N):
  for j in range(N):
    if i == j:
      continue
    distance = math.sqrt(sum([(X[i][index] - X[j][index]) ** 2 for index in range(D)]))
    if int(distance) == distance:
      count += 1

print(count // 2)

Measured memory_bytes: 3064
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  int n;
  while(cin >> n){

    int ans = 0;
    rep(a,10)rep(b,10)rep(c,10)rep(d,10){
      if(a+b+c+d == n)ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int rem1 = X/500; // 1024/500=2
    int rem2 = (X-(rem1*500))/5; // 24/5=4
    System.out.println(1000*rem1+5*rem2);
  }
}

Measured memory_bytes: 35676
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    string s;cin >> s;
    map<char,int> mp;
    rep(i, s.size()) mp[s[i]]++;
    if(((mp['S']*mp['N']==0)&&(mp['S']+mp['N']!=0))||((mp['E']*mp['W']==0)&&(mp['E']+mp['W']!=0))) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <math.h>

int n,x[55],y[55];
double gx,gy;

int main()
{
  scanf ("%d",&n);
  for (int i=0;i<n;i++) scanf ("%d %d",&x[i],&y[i]), gx +=x[i], gy += y[i];
  gx /= n, gy /= n;
  
double ans;
  for (double p=1;p>=1e-8;p*=0.999){
int idx = -1; double dist = -1;
    for (int i=0;i<n;i++){
		double d = hypot(x[i]-gx,y[i]-gy);
      if (dist < d) dist = d, idx = i;
    }
    gx += (x[idx] - gx) * p;
    gy += (y[idx] - gy) * p;
    ans = dist;
  }
  
  printf ("%.12lf\n",ans);
return 0;
}


Measured memory_bytes: 3228
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int a, b;
    map<int, int> m;
    set<int> s;
    while (scanf("%d,%d", &a, &b)) {
        if (a==0 && b==0) break;
        m[a]=-b;
        s.insert(-b);
    }
    while (scanf("%d", &a) != EOF) {
        int res=1;
        for (set<int>::iterator it=s.begin(); it != s.end(); ++it, res++)
            if (*it == m[a]) break;
        printf("%d\n", res);
        //printf("%d\n", distance(s.find(m[a]), s.begin())+1);
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;

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

    int i, a, z;
    for(i=0; i<str.length(); i++) {
        if(str[i]=='A') {
            a = i;
            break;
        }
    }

    for(i=str.length()-1; i>-1; i--) {
        if(str[i]=='Z') {
            z = i;
            break;
        }
    }

    cout << z-a+1 << endl;


    return 0;

}

Measured memory_bytes: 640
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//

struct scr
{
    int a, b, c, d;
};

scr ck[60];
vi sq(20);
int n,m, q, ans;

void dfs(int num, int pos)
{
    if(pos >= n)
    {
        int ac = 0;
        for(int i = 0; i < q; i++)
            if(sq[ck[i].b] - sq[ck[i].a] == ck[i].c)
                ac+= ck[i].d;
        ans =  max(ans, ac);
        sq.clear();
        return;
    }
    sq[pos] = num;
    for(int j = num; j <= m; j++)
        dfs(j, pos + 1);
}

int32_t main()
{
    io;
    cin>>n>>m>>q;
    for(int i = 0; i< q; i++)
    {
        cin>>ck[i].a >>ck[i].b>>ck[i].c >>ck[i].d;
        ck[i].a--;
        ck[i].b--;
    }
    for(int i = 1; i <= m; i++)
        dfs(i, 0);
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3592
#include<iostream>

using namespace std;

int main(){
  int ans,n,m,price1,price2;

  cin >> n >> m >> price1 >> price2;

  int sa = n-m;
  if(sa<=0){
    ans = n*price1;
    cout << ans;
  }
  else{
    ans = m * price1;
    ans += sa * price2;
    cout << ans;
  }

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>> n;
    vector<double> V(n,0);
    REP(i,n) cin >> V[i];
    sort(ALL(V));
    // reverse(ALL(V));
    
    double ans;
    REP(i,n-1){
        V[i+1] = (V[i]+V[i+1]) / 2;
        // cout << V[i+1] << endl;
    }
    cout << fixed << setprecision(10) << V[n-1] << endl;
    return 0;
}

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

int main() {
  long long n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll sum = 1;
  ll tmp = 1;
  ll Max = 1000000000000000000;
  

  
  rep(i,n) {
    tmp = Max / sum;
    if (a[i]==0) {
      sum = 0;
      break;
    }
    if(tmp<a[i]) {
      sum = -1;
      continue;
    }else sum *= a[i];
  }
  
  cout << sum << endl;
  
  return 0;
}

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

int main(){

    int n,a[200];
    int temp=0,ans=0;
    bool no=true;

    cin>>n;

    for(int i=0;i<n;i++) cin>>a[i];

    while(no){

        temp=0;
        for(int i=0;i<n;i++){
            if(a[i]%2==0) temp++;
            else no=false;

        }
        

        if(temp==n){
            for(int i=0;i<n;i++) a[i]/=2;
            ans++;
        }

        


    }

    cout<<ans<<endl;












    return 0;
}

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

int main() {
    int n;
    cin >> n;

    unordered_map<int, bool> a;

    int b, ans = 0;

    for (int i = 0; i < n; i++) {
        cin >> b;

        if (a.find(b) == a.end()) {
            a[b] = false;
        }

        a[b] = !a[b];

        if (a[b]) {
            ans++;
        } else {
            ans--;
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9 + 7, INF = 1e9, MAXN = 1e9;
int n, k; vector<vector<int>>sum;

int func(int i, int j) {
	return sum[i][j] - sum[i - k][j] - sum[i][j - k] + sum[i - k][j - k];
}

int main() {
	cin >> n >> k;
	int t = 2 * k, f = 4 * k;
	sum.resize(f + 5, vector<int>(f + 5, 0));
	for (int i = 0; i < n; i++) {
		int x, y; char c;
		cin >> x >> y >> c;
		x %= t; y %= t;
		if (c == 'B')x += k;
		x %= t;
		sum[x][y]++; sum[x + t][y]++; sum[x][y + t]++; sum[x + t][y + t]++;
	}
	for (int i = 1; i < f; i++) {
		for (int j = 1; j < f; j++) {
			sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		}
	}
	int ans = 0;
	for (int i = 0; i < t; i++) {
		for (int j = 0; j < t; j++) {
			int tmp = func(i + k, j + k) + func(i + t, j + t);
			ans = max(ans, tmp);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 63104
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
#define fst first
#define sec second
using namespace std;
typedef pair<int, int> pii;
int main(){
    int n;
    while (cin>>n,n) {
        --n;
        vector<pii>v;
        vector<pii>u;
        pii ans=pii(0,0);
        v.push_back(pii(0,0));
        rep(i,n){
                int m,l; cin>>m>>l;
                if(!l)v.push_back(pii(v[m].first-1,v[m].second));
                else if(l==1)v.push_back(pii(v[m].first,v[m].second-1));
                else if(l==2)v.push_back(pii(v[m].first+1,v[m].second));
                else if(l==3)v.push_back(pii(v[m].first,v[m].second+1));
            }
        //cout<<"size :"<<v.size()<<endl;
        sort(all(v));
        ans.second=abs(v[0].first-v.back().first);
        rep(i,v.size())swap(v[i].first,v[i].second);
        sort(all(v));
        ans.first=abs(v[0].first-v.back().first);
        cout<<ans.sec+1<<" "<<ans.fst+1<<endl;
    }
}

Measured memory_bytes: 3076
def solve(i, s):
    global A
    global M

    if i < len(A):
        M.add(s + A[i])
        solve(i + 1, s + A[i])
        solve(i + 1, s)


n = int(input())
A = [int(x) for x in input().split()]
M = set()

solve(0, 0)

q = int(input())

for m in [int(x) for x in input().split()]:
    if m in M:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 5660
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int i,n,m,j;
  vector<int> ans;
  while(1){
    cin>>n>>m;
    if(n==0 && m==0) break;
    vector<int> item(n);
    for(i=0; i<n; i++){
      cin>>item[i];
    }
    int max=0;
    int sum;
    for(i=0; i<n; i++){
      for(j=i+1; j<n; j++){
	sum=0;
	sum=item[i]+item[j];
	if(sum>max && sum<m+1){
	  max=sum;
	}
      }
    }
    if(max==0){
      ans.push_back(-1);
    }else{
    ans.push_back(max);
    }
  }
  for(i=0; i<ans.size(); i++){
    if(ans[i]==-1){
      cout<<"NONE";
    }else{
      cout<<ans[i];
    }
    cout<<endl;
  }
  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    string S;
    cin >> S;
    ll ue = 10*(S[0] - '0') + (S[1] - '0');
    ll shita = 10*(S[2] - '0') + (S[3] - '0');
    //dump(ue)
    //dump(shita)
    bool flag1 = (ue <= 12 && ue >= 1);
    bool flag2 = (shita <= 12 && shita >= 1);
    if(flag1 && flag2){
    	cout << "AMBIGUOUS" << endl;
    }else if(flag1){
    	cout << "MMYY" << endl;
    }else if(flag2){
    	cout << "YYMM" << endl;
    }else{
    	cout << "NA" << 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++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n, m;
    cin>>n>>m;
    int a[n], b[n], c[m], d[m];
    int i, j;
    REP(i, n){
        cin>>a[i]>>b[i];
    }
    for(i=0; i<m; i++){
        cin>>c[i]>>d[i];
    }
    int min = INF;
    int bango = 0;
    for(i=0; i<n; i++){
        min = INF;
        for(j=m-1; j>=0; j--){
            if(min>=abs(a[i]-c[j])+abs(b[i]-d[j])){
                min = abs(a[i]-c[j])+abs(b[i]-d[j]);
                bango = j+1;
            }
        }
        //cout<<min<<endl;
        cout<<bango<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


n, m = map(int, input().split())
MOD = 10 ** 9 + 7
facts, finvs = prepare(m, MOD)
c = 1
ans = 0
base = facts[n] * facts[m] * finvs[m - n] * finvs[m - n] % MOD
for k in range(n + 1):
    tmp = base * facts[m - k] * finvs[k] * finvs[n - k] % MOD
    ans = (ans + c * tmp) % MOD
    c *= -1
print(ans)


Measured memory_bytes: 48544
package main

import "fmt"

var n, m int
var graph [][]int
var seen []bool
var ans int

func dfs(v int) {
	var visited int
	for i := 0; i < len(seen); i++ {
		if seen[i] {
			visited++
		}
	}
	if visited == n-1 {
		ans++
		return
	}
	for j := 0; j < len(graph[v]); j++ {
		if graph[v][j] != 0 {
			if !seen[graph[v][j]] {
				seen[graph[v][j]] = true
				dfs(graph[v][j])
				seen[graph[v][j]] = false
			}
		}
	}
}

func main() {
	fmt.Scan(&n, &m)
	// グラフ入力
	graph = make([][]int, n)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a--
		b--
		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}
	seen = make([]bool, n)
	dfs(0)
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
const long long INF = numeric_limits<long long>::max();
int main() {
    ll N;
    cin >> N;

    vector<ll> anss(N + 1, 0);

    bool isBreak = false;
    ll MAX       = 105;
    REP2(i, 1, MAX) {
        REP2(j, 1, MAX) {
            REP2(k, 1, MAX) {
                ll ans = i * i + j * j + k * k + i * j + j * k + i * k;
                if (ans <= N) {
                    anss[ans]++;
                }
            }
        }
    }

    REP2(i, 1, anss.size()) {
        PR(anss[i]);
    }

    return 0;
}

Measured memory_bytes: 3588
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
float R,G;
int main(){
	while(~scanf("%f %f",&R,&G)){
	if (R>=0,G<=4500)
		printf("%.0f\n",2*G-R);
	}
	}

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

struct UF{
  const int N = 1e5+10;
  vector<int> par;
  vector<int> depth;
  vector<int> diff;

  void init(int n){
    par.resize(n); depth.resize(n); diff.resize(n);
    for(int i = 0; i < n; i++){
      par[i] = i;
      depth[i] = 0;
      diff[i] = 0;
    }
  }

  //木の根を求める
  int find(int x){
    if(par[x] == x){
      return x;
    }
    else {
      int r = find(par[x]);
      diff[x] += diff[par[x]];
      return par[x] = r;
    }
  }

  int weight(int x){
    find(x); //経路圧縮
    return diff[x];
  }

  //xとyの属する集合を併合
  void unite(int x,int y,int w){
    w += weight(x) - weight(y);
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(depth[x] < depth[y]) swap(x,y),w = -w;
    if(depth[x] == depth[y]) depth[x]++;
    par[y] = x;
    diff[y] = w;
  }
}uf;

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

  int n,q; cin >> n >> q;
  uf.init(n);
  for(int i = 0; i < q; i++){
    int l,r,d; cin >> l >> r >> d;
    l--,r--;
    if(uf.find(l) == uf.find(r)){
      if(uf.weight(r)-uf.weight(l) != d){
        cout << "No" << endl;
        return 0;
      }
    }
    else uf.unite(l,r,d);
  }
  cout << "Yes" << endl;

  return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<char>S(N);
  for(int i=0;i<N;i++)cin>>S[i];
  set<char>s;
  for(int i=0;i<N;i++){
    s.insert(S[i]);
  }
  if(s.size()==3)cout<<"Three"<<endl;
  else cout<<"Four"<<endl;
  return 0;
}


Measured memory_bytes: 256
import kotlin.math.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main() {
    val n = readInt() % 10
    println(if (n == 3) "bon" else if (n in listOf(0, 1, 6, 8)) "pon" else "hon")
}


Measured memory_bytes: 37956
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int num,dig,sum=0,N,A,B,ans = 0;
	cin >> N >> A >> B;
		num = N;
		for (int i = 0; i <= N; i++)
		{
			dig = 0;
			num = i;
			sum = 0;
			while (num) {
				dig = num % 10;
				sum = sum + dig;
				num = num / 10;
			}
			if (sum<=B&&sum>=A)
			{
				ans+=i;
			}
		}
	cout << ans;
}


Measured memory_bytes: 256
from bisect import *
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = [0] + list(accumulate(A))
res = float("inf")
for i in range(2,N-1):
    j = bisect_left(S,S[i]//2)
    if abs(S[i]-2*S[j]) >= abs(S[i]-2*S[j-1]):
        P =[S[j-1], S[i]-S[j-1]]
    else: P = [S[j], S[i]-S[j]]
    T = S[-1] - S[i]
    j = bisect_left(S,S[-1]-T//2)
    U1, U2 = S[j]-S[i],S[j-1]-S[i]
    if abs(T-2*U1) >= abs(T-2*U2):
        P += [U2, T-U2]
    else: P += [U1, T-U1]
    tmp = max(P)-min(P)
    res = min(res, tmp)
print(res)

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

int main()
{
    int a, b, c, d, e, f, g, ans;

    cin >> a >> b >> c;

    g = a + b + c;
    d = max(a, max(b, c));
    e = min(a, min(b, c));
    f = g - d - e;
    ans = (d * 10) + (e + f);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define ll long long
using namespace std;
const int N=2e5+10;
const ll mod=1e9+7;
int n,m,a,b,maxx;
ll fac1[N]={1},inv[N]={0,1},fac2[N]={1},ans,x,y;
inline ll C(int nn,int mm){return fac1[nn]*fac2[mm]%mod*fac2[nn-mm]%mod;}
int main()
{
//	freopen("Iroha and a Grid .in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d%d%d",&n,&m,&a,&b); maxx=n+m;
	for(RG int i=1;i<=maxx;i++) fac1[i]=fac1[i-1]*i%mod;
	for(RG int i=2;i<=maxx;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(RG int i=1;i<=maxx;i++) fac2[i]=fac2[i-1]*inv[i]%mod;
	for(RG int i=1;i<=n-a;i++)
	{
		x=C(b+i-2,b-1), y=C(n+m-i-b-1,m-b-1);
		(ans+=(x*y%mod))%=mod;
	}
	printf("%lld",ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 4992
#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 lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int n,r;
    cin >> n >> r;
    if(n>=10){
        cout << r << endl;
    }
    else{
        cout << r+100*(10-n) << endl;
    }
}


Measured memory_bytes: 256
A ,B ,C ,D = map(int, input().split())

taka = 0
hashi = 0

if B*(C//B)==C:
    taka = C//B
else:
    taka = C//B +1
    
if D*(A//D)==A:
    hashi = A//D
else:
    hashi = A//D +1

if taka <= hashi:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include <iostream>

using namespace std;

int map[50][50];

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

void dfs(int x, int y,int w, int h){
	if(x<0 || y<0 || w<=x || h<=y || map[y][x] == 0) return;
	else{
		map[y][x] = 0;
		for(int i=0;i<8;++i){
			dfs(x+dx[i],y+dy[i],w,h);
		}
	}
}

int solve(int w,int h){
	int ans;
	
	int i,j,k;
	ans = 0;
	for(i=0;i<h;++i){
		for(j=0;j<w;++j){
			if(map[i][j]==1){
				map[i][j] = 0;
				for(int k=0;k<8;++k){
					dfs(j+dx[k],i+dy[k],w,h);
				}
				ans++;
			}
		}
	}
	return ans;
}

int main(void){
	int w,h;
	int i,j;
	
	while(cin>>w>>h,w){
		for(i=0;i<h;++i){
			for(j=0;j<w;++j){
				cin >> map[i][j];
			}
		}
		
		cout << solve(w,h) << endl;
	}
	
}

Measured memory_bytes: 3116
#include<cstdio>

int main(void){
    int akunnnootosidama, bkunnnootosidama;
    scanf("%d %d", &akunnnootosidama, &bkunnnootosidama);
    printf("%d\n", (akunnnootosidama+bkunnnootosidama)>>1);
    return(0);
}


Measured memory_bytes: 2740
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX=200005;

int main()
{
    ll x,y;
    double d;
    int n,c=0;
    scanf("%d %lf",&n,&d);
    while(n--){
        scanf("%lld %lld",&x,&y);
        double z=sqrtl(x*x+y*y);
        if(z<=d) c++;
    }
    printf("%d\n",c);
    return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define MIN(c) (*min_element(ALL(c))) 
#define MAX(c) (*max_element(ALL(c)))
#define ACC(c) (accumulate(ALL(c), 0))
#define SLL(x, n) ((x) << (n))
#define SRL(x, n) ((x) >> (n))
#define MIN2(a, b) ((a) < (b)) ? (a) : (b)
#define MAX2(a, b) ((a) > (b)) ? (a) : (b)
#define MP(a, b) (make_pair((a), (b)))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

using namespace std;
using ll = long long;
using pint = pair<int, int>;

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


signed main(){
    int A, P;
    cin >> A >> P;
    PRINT((3 * A + P) / 2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int a,b;
  a=abs(y-x);
  b=abs(z-x);
  if(a<b) cout<<'A';
  else cout<<'B';
  cout<<endl;
}

Measured memory_bytes: 256
s = " " + gets.chomp
max = s.size - 1
(2..max).each{|r|
  if s[r-1]==s[r]
    puts "#{r-1} #{r}"
    exit
  end
}
(3..max).each{|r|
  if s[r-2]==s[r]
    puts "#{r-2} #{r}"
    exit
  end
}
puts "-1 -1"

Measured memory_bytes: 2044
package main

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

type Point struct {
	x int
	y int
}

type Points []Point

func (l Points) Len() int {
	return len(l)
}

func (l Points) Less(i, j int) bool {
	return l[i].x < l[j].x
}

func (l Points) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func pow(x, n int) int {
	r := 1
	for i := 0; i < n; i++ {
		r *= x
	}
	return r
}

func main() {
	s := wordScanner()

	var n int
	scanInts(s, &n)

	reds := make(Points, n)
	for i := range reds {
		scanInts(s, &reds[i].x, &reds[i].y)
	}

	blues := make(Points, n)
	for i := range blues {
		scanInts(s, &blues[i].x, &blues[i].y)
	}

	sort.Sort(reds)
	sort.Sort(blues)

	c := 0
	for _, b := range blues {
		i := -1
		for j, r := range reds {
			if isInner(r, b) {
				if i == -1 || reds[i].y < reds[j].y {
					i = j
				}
			}
		}
		if i != -1 {
			c++
			reds = append(reds[:i], reds[i+1:]...)
		}
	}
	fmt.Println(c)
}

func isInner(inner, outer Point) bool {
	return outer.x > inner.x && outer.y > inner.y
}

func wordScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func scanInts(s *bufio.Scanner, vals ...*int) {
	for i := range vals {
		s.Scan()
		n, _ := strconv.Atoi(s.Text())
		*vals[i] = n
	}
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define INT long long
#define MOD (int)1e9 +7
using namespace std;

int n, m, red[200020], no[200020], ans;
int main()
{
    scanf("%d%d", &n, &m);
    red[1] = 1;
    for(int i = 1 ; i <= n ; i++ ) no[i] = 1;
    for(int i = 0, x, y ; i < m ; i++ )
    {
        scanf("%d%d", &x, &y);
        no[x]--, no[y]++;
        if( red[x] ) red[y] = 1;
        if( !no[x] ) red[x] = 0;
    }
    for(int i = 1 ; i <= n ; i++ )
        if( red[i] ) ans++;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long int
#define ld double
using namespace std;
int n,i,x,c[4];
ld dp[301][301][301];
ld rec(int a,int b,int c){
	if(b<0||c<0||n-a-b-c<0||a==n)return 0;
	if(dp[a][b][c]!=0)return dp[a][b][c];
	return dp[a][b][c]=(rec(a+1,b-1,c)*b/n+rec(a,b+1,c-1)*c/n+rec(a,b,c+1)*(n-a-b-c)/n+1)*n/(n-a);
}
main(){
	cin>>n;
	for(i=0;i<n;i++)cin>>x,c[x]++;
	cout<<fixed<<setprecision(15)<<rec(c[0],c[1],c[2]);
}


Measured memory_bytes: 213248
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll ret=a*b;
    ll u=gcd(a,b);
    return ret/u;
}
ll f(ll a,ll b,ll n){
    ll ret=b/n-a/n;
    if(a%n==0)ret++;
    return ret;
}
int main(){
    int n,k;cin>>n>>k;
    if(n+k-1>(n*(n-1))/2){
        cout<<-1<<endl;
        return 0;
    }
    vector<int> v[n+1];
    rep(i,1,n){
        rep(j,i+1,n+1)v[i].push_back(j);
    }
    //rep(i,1,n+1)rep(j,0,v[i].size())cout<<v[i][j]<<" ";
    int now=0;
    int cnt[n+1];
    fill(cnt,cnt+n+1,0);
    for(int i=1;;i++){
        if(now+n-i-1>=k){
            rep(j,0,v[i].size()){
                if(now==k)break;
                cnt[i]++;
                now++;
                //cout<<v[1].size()<<" ";
                
            }
        }
        else{
            rep(j,0,v[i].size()-1){
                cnt[i]++;
                now++;
            }
        }
        if(now==k)break;
    }
    int sum=n*(n-1);
    sum/=2;
    rep(i,1,n+1)sum-=cnt[i];
    cout<<sum<<endl;
    rep(i,1,n+1){
        rep(j,cnt[i],v[i].size())cout<<i<<" "<<v[i][j]<<endl;
    }
}


Measured memory_bytes: 256
n = int(input())
l = [list(map(str, input().split())) for i in range(n)]
for row in l:
    row[1] = int(row[1])
    row.append(l.index(row))

s = sorted(l, key=lambda x:(x[0],-x[1]))

for i in s:
  print(i[2]+1)


Measured memory_bytes: 38640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (Math.abs(x - a) < Math.abs(x - b)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }

    }

}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =  double;
const ld eps = 1e-6;

/* ??????????????¬ */

#include <complex>

typedef complex<ld> Point;


const ld pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;

namespace std {
	bool operator<(const Point &lhs, const Point &rhs) {
		if (lhs.real() < rhs.real() - eps) return true;
		if (lhs.real() > rhs.real() + eps) return false;
		return lhs.imag() < rhs.imag();
	}
}

// ????????\???
Point input_Point() {
	ld x, y;
	cin >> x >> y;
	return Point(x, y);
}

// ????????????????????????
bool eq(const ld a, const ld b) {
	return (abs(a - b) < eps);
}

// ??????
ld dot(const Point& a, const Point& b) {
	return real(conj(a) * b);
}

// ??????
ld cross(const Point& a, const Point& b) {
	return imag(conj(a) * b);
}

// ??´????????????
class Line {
public:
	Point a, b;
	Line() : a(Point(0, 0)), b(Point(0, 0)) {}
	Line(Point a, Point b) : a(a), b(b) {}
	Point operator[](const int _num)const {
		if (_num == 0)return a;
		else if (_num == 1)return b;
		else {
			assert(false);
			return Point();
		}
	}
};

// ?????????????????????
bool isis_sp(const Line& s, const Point& p) {
	return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}

// ??????????¶?
Point proj(const Line &l, const Point& p) {
	ld t = dot(p - l.a, l.b - l.a) / norm(l.a - l.b);
	return l.a + t * (l.b - l.a);
}



// ????????¨???????????¢
ld dist_sp(const Line& s, const Point& p) {
	Point r = proj(s, p);
	return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
}



int main() {

	int N, M, X, Y; cin >> N >> M >> X >> Y;
	vector<Line>ls;
	vector<Point>ps(1, Point(X, Y));
	vector<int>ids(1, -1);
	vector<Point>foods;
	for (int i = 0; i < N; ++i) {
		int px, py; cin >> px >> py;
		foods.push_back(Point(px, py));
	}
	vector<int>caneats(N, true);
	ld sum = 0;
	vector<ld>diss(N, 1e18);

	for (int i = 0; i < M; ++i) {
		pair<ld, int>next(1e18, 0);
		for (int j = 0; j < foods.size(); ++j) {
			if (caneats[j]) {

				auto f(foods[j]);
				ld dis = diss[j];
				if (ps.size()==1) {
					auto p(ps.back());
					dis = min(dis, abs(p - f));
				}

				if (!ls.empty()) {
					auto l(ls.back());
					dis = min(dis, dist_sp(l, f));
				}
				diss[j] = dis;
				if (next.first - eps > dis || (abs(next.first - dis) < eps&&next.second < j)) {
					next = make_pair(dis, j);
				}
			}
		}
		{
			auto f(foods[next.second]);
			pair<ld, int>connect(1e18, 0);
			for (int j = 0; j < ps.size(); ++j) {
				ld dis = abs(f - ps[j]);
				if (connect.first - eps > dis || (abs(connect.first - dis) < eps&&connect.second < ids[j])) {

					connect = make_pair(abs(f - ps[j]), j);
				}
			}
			sum += connect.first;
			Line l{ f,ps[connect.second] };
			ls.push_back(l);
			ps.push_back(f);
			ids.push_back(next.second);
			caneats[next.second] = false;
		}

	}
	cout << fixed << setprecision(10) << sum << endl;
	return 0;
}

Measured memory_bytes: 3588
package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

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

	for {
		n, _ := nextInt()
		x, _ := nextInt()
		if n == 0 && x == 0 {
			break
		}

		found := 0
		for i := 1; i <= n; i++ {
			if i > x {
				break
			}
			for j := i + 1; j <= n; j++ {
				if i+j > x {
					break
				}
				for k := j + 1; k <= n; k++ {
					if i+j+k > x {
						break
					}
					if i+j+k == x {
						// fmt.Println(i, j, k)
						found++
					}
				}
			}
		}
		fmt.Println(found)
	}
}



Measured memory_bytes: 1096
N, T = map(int, input().split())
c = [10000 for _ in range(N)]
for i in range(N):
    c_tmp, t = map(int, input().split())
    if t <= T:
        c[i] = c_tmp
if min(c) > 1000:
    print('TLE')
else:
    print(min(c))

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

using namespace std;

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

#define N 100010
#define M 200010
#define A 110
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	int s, w;
	
	cin >> s >> w;
	
	if(w >= s){
		cout << "unsafe" << endl;
	}
	else{
		cout << "safe" << endl;
	}
	
	return 0;
}

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

using namespace std;

typedef pair< int,int > PII;
typedef long long int lo;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

lo n,m,cev,b[li],a[li],dp[105][li];
string s;
vector<int> v;

lo f(lo sira,lo kac){
	lo cevv=MAX;
	if(kac>m) return MAX;
	if(sira>n) return 0;
	if(~dp[sira][kac]) return dp[sira][kac];
	cevv=max(cevv,f(sira+1,kac+a[sira])+b[sira]);
	cevv=max(cevv,f(sira+1,kac));
	return dp[sira][kac]=cevv;
}

int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&m);
	FOR{
		scanf("%lld %lld",&a[i],&b[i]);
	}
	printf("%lld\n",f(1,0));
	return 0;
}


Measured memory_bytes: 82304
#include<cstdio>
#include<queue>
#include<climits>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stack>
#include<map>
#include<string>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long ll;
#define me(a,b) memset(a,b,sizeof a)
const int maxn=1e5+100;
//ll a[maxn];
//ll sum[maxn];
struct node{
    ll s,e;
    bool operator < (const node &a)const{
        if(s==a.s)
            return e<a.e;
        return s<a.s;
    }
}num[maxn];
int main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("in.txt","r",stdin);
//    #endif //ONLINE_JUDGE
   ll n,c,k;
   scanf("%lld%lld%lld",&n,&c,&k);
   for(int i=0;i<n;i++){
    scanf("%lld",&num[i].s);
    num[i].e+=k+num[i].s;
   }
   ll ans=0;
   sort(num,num+n);
   ll t=num[0].e;
   ll sum=0;
   for(int i=0;i<n;i++){
    if(sum==0){
        sum=1;
        ans++;
        t=num[i].e;
    }
    else if(num[i].s<=t&&sum<c){
        sum++;
    }
    else
    {
        t=num[i].e;
        ans++;
        sum=1;
    }
   }
   printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int length;
    scanf("%d", &length);

    char *str;
    str = (char *)malloc((length+1)*sizeof(char));
    scanf("%s", str);

    int i, max = 0, current_value = 0;
    for(i = 0; str[i] != '\0'; i++){
        if(str[i] == 'I'){
            current_value++;
            if(current_value > max){
                max = current_value;
            }
        }else{
            current_value--;
        }
    }

    printf("%d\n", max);
    free(str);
    return 0;
}

Measured memory_bytes: 128
/*
Original problem: https://atcoder.jp/contests/abc133/tasks/abc133_d
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
    void main() {
    	int n;
    	cin >> n;
    	VLL A(2 * n);
    	VLL suf(2 * n); // suf[i] gives the sum of A[i] + A[i+2] ... end
    	ll t = 0;

    	REP(i, 0, n) {
    		cin >> A[i];
    		A[n + i] = A[i];
    		t += A[i];
    	}

    	suf[2 * n - 1] = A[n - 1];
    	suf[2 * n - 2] = A[n - 2];
    	RREP(i, 2 * n - 3, 0) {
    		suf[i] = suf[i + 2] + A[i];
    	}

    	REP(i, 0, n) {
    		ll ans = t - 2 * (suf[i + 1] - suf[i + n]);
    		cout << ans;
    		if (i != n - 1) {
    			cout << " ";
    		}
    	}
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;

    while(scanf("%d",&a)!=EOF)
    {
        int i;
        if(a>1)
        {
            i=2;
            while(i<a)
                i*=2;
        }
        else
            i=1;
        if(i>a)
            i/=2;
        cout<<i<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
n,a,d=map(int,input().split())

dic={}

ans=0

if d==0:
    if a==0:
        print(1)
    else:
        print(n+1)
else:
    for k in range(n+1):
        l=k*a+k*(k-1)*d//2
        r=l+k*(n-k)*d
        idx=l%d
        l//=d
        r//=d
        if idx in dic:
            prel,prer=dic[idx]
            #共通部分ありか、なしかで分岐
            if prer<l or prel>r:
                dic[idx]=(l,r)
                ans+=r-l+1 
            else:
                nl=min(prel,l)
                nr=max(prer,r)
                ans+=prel-nl+nr-prer
                dic[idx]=(nl,nr)
        else:
            ans+=r-l+1 
            dic[idx]=(l,r)
    print(ans)

Measured memory_bytes: 63316
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int main(){
	string s;
	cin >> s;
	cout << (s[2] == s[3] && s[4] == s[5] ? "Yes":"No") << '\n';
	return 0;
}
    

Measured memory_bytes: 256