akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	string str;cin>>str;
	int i,n=str.size();
	if(n%2>0){cout<<"No"<<endl;return 0;}
	for(i=0;i<n;i++){
		if(i%2==0&&str[i]!='h'){cout<<"No"<<endl;return 0;}
		if(i%2==1&&str[i]!='i'){cout<<"No"<<endl;return 0;}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
/*****************************************************************\
    |     IN THE NAME OF ALLAH, MOST GRACIOUS AND MOST MERCIFUL       |
    |                                                                 |
    |     Author     : Mahabub Rahman                                 |
    |     Email      : mahabubrahman618@gmail.com                     |
    |     University : Comilla University, Bangladesh		          |
    |                  Department of Computer Science & Engineering   |
    \*****************************************************************/


    /*...................................Data_Types............................................*/
    #include<bits/stdc++.h>

    using namespace std;
    #define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
    #define       ll                  long long int
    #define       ull                  unsigned long long int
    #define       veci                 vector<int>
    #define       vecc                 vector<char>
    #define       vecs                 vector<string>
    #define       vecl                 vector<long long int>
    #define       vecp                 vector<  pair<int,int> >
    #define       mapstrint            map< string , int >
    #define       mapstrstr            map< string , string >
    #define       mapint               map< int, int >
    #define       pb                   push_back
    #define       pob                  pop_back
    #define       mp                   make_pair
    #define       F                    first
    #define       S                    second
    ////============ CONSTANT ===============////
    #define mx9   1000000007
    #define mx7   10000007
    #define mx6   1000006
    #define mx5   200005
    #define inf   1<<30                                           //infinity value
    #define eps   1e-9

    #define mod   1000000007
    ////=====================================////

    long double PI = acosl(-1);
    bool compare_int(int a, int b) //This function is use for descending order.
    {
        return (a>b);
    }
    bool compare_string (string a, string b)
    {
        return a.size() < b.size();
    }
    bool compare_pair(const pair<int,int> &a,
                  const pair<int,int> &b)
    {
        if(a.second==b.second) return a.first>b.first;
        else return (a.second > b.second);
    }
    /*ll fact(ll n)
    {
        if(n==0 || n==1) return 1;
        else return n*fact(n-1);
    }*/

    ////======================================////
    /*bool check(int n)
    {
        for(int i=2; i<=sqrt(n); i++)
        {
            if(n%i==0)
            {
                return false;
            }
        }
        return true;
    }*/

    int32_t main()
    {
        //Don't see test case until get 7/8 times wrong submission..!!
        //Try to make Corner, Even, Odd or Prime case..!!
        FastIO;
        ll n, m, x, tot=0;
        cin >> n >> m ;

        for(int i=0; i<m; i++)
        {
            cin >> x;
            tot+=x;
        }
        if(tot>n) cout << -1 << endl;
        else cout << n-tot << endl;
    }


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


int main(void){
	int n, b, a;
	string s;
	cin >> a >> b;
	if(a%2==1 && b%2==1){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
using namespace std;
long long c=1e9+7;
long long fast_pow(long long base, long long power){
	long long result =1;
	while(power>0){
		if(power&1) result = (result*base)%c;
		base = (base*base)%c;
		power >>= 1;
	}
	return result;
}
int main(){
	long long n;
	cin>>n;
	cout<<((fast_pow(10,n)-2*fast_pow(9,n)+fast_pow(8,n))%c+c)%c;
	return 0;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, a, b, c, d;
    cin >> n;
    a = 100000000;
    b = 0;
    while (a > 0) {
        b += (n % a*10)/ a;
        a /= 10;
    }
    if(n % b == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[410], F[410];
int Deg[410], n, H, m;
void Make_Edge(int a, int b){
    E[a].push_back(b);
    F[b].push_back(a);
    Deg[b]++;
    Deg[a]--;
}
int v[410], cnt, SCC[410], ord[410];
void DFS(int a){
    int i;
    v[a]=1;
    for(i=0;i<E[a].size();i++){
        if(!v[E[a][i]])DFS(E[a][i]);
    }
    ord[++cnt] = a;
}
void DFS2(int a){
    int i;
    SCC[a] = cnt;
    for(i=0;i<F[a].size();i++){
        if(!SCC[F[a][i]])DFS2(F[a][i]);
    }
}
int main(){
    int i, a, b, c, d;
    scanf("%d%d",&n,&H);
    for(i=1;i<=n;i++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if(!c && !d) Make_Edge(a, H+1+b);
        if(!c && d)Make_Edge(a, d);
        if(c && !d)Make_Edge(H+1+c, H+1+b);
        if(c && d)Make_Edge(H+1+c, d);
    }
    for(i=0;i<=(H+1)*2;i++){
        if((Deg[i] < 0 && i >= H+1) || (Deg[i] > 0 && i < H+1)){
            printf("NO\n");
            return 0;
        }
        while(Deg[i]!=0){
            if(Deg[i] < 0)Make_Edge(0, i);
            else Make_Edge(i, 0);
        }
    }
    m = (H+1)*2;
    for(i=0;i<=m;i++){
        if(!v[i])DFS(i);
    }
    cnt = 0;
    for(i=m+1;i>=1;i--){
        if(!SCC[ord[i]]){
            cnt++;
            DFS2(ord[i]);
        }
    }
    for(i=0;i<=m;i++){
        if(!E[i].empty() && SCC[i] != SCC[0]){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
}

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

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)

int32_t N;
std::vector<int32_t> edge[101000];

int32_t F(std::vector<int32_t>& a, int32_t K)
{
	std::sort(a.begin(),a.end());
	int lb = -1, ub = a.size();
	while (ub - lb>1) {
		int mid = (ub + lb) / 2;

		bool f = true;
		int l = 0, r = a.size() - 1;
		for (int i = 0; i < a.size() / 2;++i) {
			if (l == mid)l++;
			if (r == mid)r--;
			if (a[l] + a[r]>K)f = false;
			l++; r--;
		}
		if (f)ub = mid;
		else lb = mid;
	}
	return ub;
}

volatile bool func_ok = false;
int32_t len_max;
int32_t func(int32_t v, int32_t parent)
{
	//if (edge[v].size() == 1) {
	//	return 0;
	//}
	//if (edge[v].size() == 2) {
	//	for (auto& e : edge[v]) {
	//		if (e != parent) { return 1 + func(e, v); }
	//	}
	//}

	std::multiset<int32_t, std::greater<int32_t>> L;
	for (auto& e : edge[v]) {
		if (e != parent) {
			L.insert(1 + func(e, v));
		}
	}
	if (L.size() % 2 == 0) {
		L.insert(0);
	}

	std::vector<int32_t> T;
	for (auto& i : L) { T.push_back(i); }
	auto R = F(T, len_max);
	if(R==T.size()){
		func_ok = false;
		return 0;
	}
	else {
		return T[R];
	}

	//while (L.size()>=2) {
	//	auto iter2 = L.begin();
	//	auto iter1 = L.lower_bound(len_max - *iter2);
	//	if (iter1 == L.end()) {
	//		func_ok = false;
	//		return 0;
	//	}
	//	if (iter1 == iter2) {
	//		++iter1;
	//	}
	//	L.erase(iter1);
	//	L.erase(iter2);
	//}
	//return *L.begin();
}
bool func_2(int32_t v)
{
	func_ok = true;
	auto res = (func(edge[v][0], v) + 1 <= len_max);
	return func_ok&&res;
}

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

	in >> N;
	for (int32_t i = 0; i < N-1; i++)
	{
		int a, b;
		in >> a >> b; --a; --b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	int32_t A = 1;
	for (int32_t i = 0; i < N; i++)
	{
		A += (edge[i].size() - 1) / 2;
	}
	out << A << ' ';

	int32_t root = 0;
	for (int32_t i = 0; i < N; i++)
	{
		if (edge[i].size() == 1) {
			root = i; break;
		}
	}

	using BS_INT = int64_t;
	BS_INT ok_range = N, ng_range = 0;
	while (std::abs(ok_range - ng_range) > 1) {
		BS_INT mid = (ok_range + ng_range) / 2;
		bool is_ok = false;

		//ここに書く
		len_max=mid;
		is_ok = func_2(root);

		if (is_ok) {
			ok_range = mid;
		}
		else {
			ng_range = mid;
		}
	}
	out << ok_range << endl;


	return 0;
}
#endif


Measured memory_bytes: 18304
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e15+100)
#define N 100005



// Driver code to tes above functions
int32_t main()
{
    
 
    
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    
    int a, b;
    cin >> a >> b;
    if(1<=a and a<=9 and 1<=b and b<=9)
        cout << a*b;
    else
        cout << -1;

    return 0;
    
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  int n,T;
  cin>>n>>T;
  vector<int> c(n),t(n);
  rep(i,n)cin>>c[i]>>t[i];
  vector<int> v;
  rep(i,n){
  if(t[i]<=T)v.push_back(c[i]);
}
  if(v.size()==0)cout<<"TLE"<<endl;
  else cout<<*min_element(v.begin(),v.end())<<endl;
}

Measured memory_bytes: 256
import math
N = int(input())
P = list(map(str,input().split()))
Q = list(map(str,input().split()))
r = [1]*N
R = [1]*N
a = 0
b = 0

def number(P,a,N,r):
  for i in range(N):
    k = 0
    s = int(P[i])
    for j in range(s):
      k += r[j]
    t = math.factorial(N-i-1)
    a += (k-1)*t
    r[s-1] = 0
  return a+1
p = number(P,a,N,r)
q = number(Q,b,N,R)
if p > q:
  print(p-q)
else:
  print(q-p)

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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;

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;
}

string s;

void solve() {
  cin >> s;
  int ans = 0;
  rep(i, 0, s.size()) {
    if (i % 2 == 0 and s[i] == '0') {
      ans++;
    }
    if (i % 2 == 1 and s[i] == '1') {
      ans++;
    }
  }
  int nans = s.size() - ans;
  bool flag = chmin(ans, nans);
  cout << ans << endl;
}

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

  // cout << fixed << setprecision(10);

  solve();

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  int arr[n];
  long long int minTotal = INT_MAX,total=0;
  for(int i=0;i<n;i++)cin>>arr[i];
  for(int i=0;i<=100;i++){
  		for(int j=0;j<n;j++){
        	total+= ((arr[j]-i)*(arr[j]-i));
        }
  		minTotal = total<minTotal?total:minTotal;
    total=0;
  }
  cout<<minTotal<<endl;

}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> f,s,t;
  rep(i, n){
    int c;
    cin >> c;
    if(c <= a) f.push_back(c);
    else if(c <= b) s.push_back(c);
    else t.push_back(c);
  }
  cout << min(f.size(), min(s.size(), t.size())) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;


int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n,0);
    vector<ll> b(m,0);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,m){
        cin >> b[i];
    }
    ll t=0;
    rep(i,m){
        t += b[i];
    }
    int j = m;
    int ans=0;
    rep(i,n+1){
        while(j > 0 && t > k){
            --j;
            t -= b[j];
        }

        if (t>k) break;

        ans = max(ans,i+j);
        if(i==n) break;
        t += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 6428
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	long double a, b, h, m, d1, d2, x1, y1, x2, y2, ans, pi = 3.14159265358979323846;

	cin >> a >> b >> h >> m;
	
	h += m / 60.0; 
	d1 = 2.0 * pi / 12 * h;
	d2 = 2.0 * pi / 60 * m;

	x1 = sin(d1) * a;
	y1 = cos(d1) * a;

	x2 = sin(d2) * b;
	y2 = cos(d2) * b;

	ans = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	ans = sqrt(ans);

	cout << setprecision(12) << fixed << ans << "\n";



	return 0;
}




Measured memory_bytes: 3612
from functools import reduce

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

#combination高速化の裏技
def comb(N, A, MOD):
    num = reduce(lambda x, y: x * y % MOD, range(N, N - A, -1))
    den = reduce(lambda x, y: x * y % MOD, range(1, A + 1))
    return num * pow(den, MOD - 2, MOD) % MOD

#powはmodを引数にしてあまりを計算してくれる
print((pow(2, n, mod = mod) - 1 - comb(n, a, mod) - comb(n, b, mod)) % mod)

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

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define V vector<int>

using namespace std;
using ll = long long;

int main() {
    string S, T;
    IN(S);
    IN(T);
    size_t S_size = S.size();
    char tmp;
    REP(i, S_size) {
        if(S == T) {
            OUT("Yes");
            return 0;
        }
        else {
            tmp = S[0];
            S.erase(S.begin());
            S.push_back(tmp);
        }
    }
    OUT("No");
}

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

int main() {
 string s;
  cin>>s;
  int n=s.size();
  long long ans=0;
  for(int i=0;i<(1<<n-1);i++){
    long long sum=0,x=0;
    for(int j=0;j<n-1;j++){
      x*=10;
      if(i>>j&1) {
        sum+=x+(s[j]-'0');
        x=0;
      }
      else {
        x+=s[j]-'0';
      }
    }
      sum+=x*10+(s[n-1]-'0');
      ans+=sum;
  }
    cout<<ans<<endl;
}
        

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

void solve(){
  int n; cin >> n;
  string ans = "";
  while(n != 0){
    if(n % 2 != 0){
      n--;
      ans = "1" + ans;
    }
    else ans = "0" + ans;
    n /= -2;
  }
  if(ans == ""){
    ans = "0";
  }
  cout << ans << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOPSIC
{
    partial class Program
    {
        static void Main(string[] args)
        {
          string NK = Console.ReadLine();

            int N = int.Parse(NK);

            int ans;

            if (N % 2 == 0)
            {
                ans = N / 2;
            }
            else
            {
                ans = (N / 2) + 1;
            }


            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int calc_digit(ll n) {
	int res = 0;
	while (n) {
		++res;
		n /= 10;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n;
	cin >> n;

	ll res = inf;

	for (ll a = 1; a * a <= n; a++) {
		if (n % a == 0) {
			ll b = n / a;
			ll f = max(calc_digit(a), calc_digit(b));
			chmin(res, f);
		}
	}

	out(res);

	return 0;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  vl acc(n + 1);
  acc[0] = 0;
  rep(i, n) acc[i + 1] = acc[i] + a[i];
  dump(a, acc);
  ll l, r;
  int m = 0;
  l = a[0];
  r = acc[n] - a[0];
  rep(i, n - 1) {
    if (l >= r) {
      m = i;
      break;
    }
    l += a[i + 1];
    r -= a[i + 1];
    dump(l, r);
  }
  dump(m);
  ll d1 = LINF;
  ll d2 = LINF;
  l = acc[m + 1];
  r = acc[n] - acc[m + 1];
  d1 = abs(l - r);
  dump(l, r, d1);
  if (m > 0) {
    l = acc[m];
    r = acc[n] - acc[m];
    d2 = abs(l - r);
    dump(l, r, d2);
  }
  cout << min(d1, d2) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 3456
xs, ys, xt, yt = map(int, input().split())
n = int(input())
X = [[0, 0, 0] for _ in range(n+2)]
X[0] = [xs, ys, 0]
X[n+1] = [xt, yt, 0]
R = [0]*n
for i in range(n):
    x, y, r = map(int, input().split())
    X[i+1] = [x, y, r]

import math
edge = [[] for _ in range(n+2)]
for i in range(n+1):
    x1, y1, r1 = X[i]
    for j in range(i+1, n+2):
        x2, y2, r2 = X[j]
        l = math.sqrt((x1-x2)**2+(y1-y2)**2)
        edge[i].append((max(l-r1-r2, 0), j))
        edge[j].append((max(l-r1-r2, 0), i))

import heapq
def dijkstra_heap(s):
    d = [float("inf")] * (n+2)
    used = [True] * (n+2) #True: not used
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d

d = dijkstra_heap(0)
print(d[-1])

Measured memory_bytes: 145164
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  for(int i=0; i<s.size(); i++) {
    s[i]=(char)('A'+(s[i]-'A'+n)%26);
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10;
int n,m;
ll f[N];
vector<pa>e[N];

const ll inf = 1e15;
ll v[N<<2];
inline void Build(int u,int l,int r){
	v[u]=inf;
	if (l==r) return;
	int mid=l+r>>1;
	Build(u<<1,l,mid),Build(u<<1^1,mid+1,r);
}
inline void update(int u,int l,int r,int ql,ll x){
	if (l==r) return v[u]=x,void(0);
	int mid=l+r>>1;
	if (ql<=mid) update(u<<1,l,mid,ql,x);
		else update(u<<1^1,mid+1,r,ql,x);
	v[u]=min(v[u<<1],v[u<<1^1]);
}
inline ll Query(int u,int l,int r,int ql,int qr){
	if (l>=ql&&r<=qr) return v[u];
	int mid=l+r>>1;
	if (qr<=mid) return Query(u<<1,l,mid,ql,qr);
	if (ql>mid) return Query(u<<1^1,mid+1,r,ql,qr);
	return min(Query(u<<1,l,mid,ql,qr),Query(u<<1^1,mid+1,r,ql,qr));
}

int main(){
	n=read(),m=read();
	For(i,1,m){
		int l=read(),r=read(),c=read();
		e[r].pb(mp(l,c));
	}
	Build(1,1,n),f[1]=0,update(1,1,n,1,0);
	For(i,2,n){
		f[i]=inf;
		for (auto j:e[i]) f[i]=min(f[i],Query(1,1,n,j.fi,i)+j.se);
		update(1,1,n,i,f[i]);
	}
	if (f[n]==inf) puts("-1");
		else printf("%lld\n",f[n]);
}

Measured memory_bytes: 11872
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

const int N = 1e5 + 5;
vector<int> g[N], b[N];
int comp[N], cc = 0;
int sz[N];

void dfs(int x){
	if(comp[x] == 0){
		comp[x] = cc;
		++sz[cc];
		for(int a:g[x]){
			dfs(a);	
		}
	}
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m,k,x,y;
	cin >> n >> m >> k;
	rep(i,0,m){
		cin >> x >> y;	
		--x,--y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	rep(i,0,k){
		cin >> x >> y;	
		--x,--y;
		b[x].push_back(y);
		b[y].push_back(x); 
	}
	rep(i,0,n){
		if(comp[i] == 0){
			++cc;
			dfs(i);
		}
	}
	rep(i,0,n){
		int res = sz[comp[i]] - g[i].size();
		for(int a:b[i])res -= (comp[a] == comp[i]);
		--res;
		cout << res << ' ';
	}
	cout << '\n';
}


Measured memory_bytes: 12288
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

//union-find
#define UFLIMIT (1<<24)
ll unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int ufroot(int x){return unicnt[x]<=0?-(unicnt[x]=-ufroot(-unicnt[x])):x;}
int ufsame(int x,int y){return ufroot(x)==ufroot(y);}
void uni(int x,int y){if((x=ufroot(x))==(y=ufroot(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT

int uniquell(ll*a,ll*ans,int cnt){
	sortup(a,cnt);
	int c=0;
	ans[0]=a[0];
	rep(i,1,cnt)if(a[i]!=ans[c])ans[++c]=a[i];
	return c+1;
}

ll cocompf(ll n,ll*comp,ll compcnt){
	//comp[i]<=n<comp[i+1]なるiを返す
	ll l=0,r=compcnt;
	while(r-l>1){
		ll m=(l+r)/2;
		if(comp[m]<=n)l=m;
		else r=m;
	}
	return l;
}

int a[1010],b[1010],c[1010],d[1010],e[1010],f[1010];
ll x[3010],y[3010],xcnt,ycnt;

int dp[3010][3010];//x-,y-

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,0,n){
		scanf("%d%d%d",a+i,b+i,c+i);
		x[xcnt++]=a[i];
		x[xcnt++]=b[i];
		y[ycnt++]=c[i];
	}
	rep(i,0,m){
		scanf("%d%d%d",d+i,e+i,f+i);
		x[xcnt++]=d[i];
		y[ycnt++]=e[i];
		y[ycnt++]=f[i];
	}
	x[xcnt++]=y[ycnt++]=-1e9-10;
	x[xcnt++]=y[ycnt++]=1e9+10;
	x[xcnt++]=y[ycnt++]=0;
	
	xcnt=uniquell(x,x,xcnt)-1;
	ycnt=uniquell(y,y,ycnt)-1;
	
	rep(i,0,n){
		int aa=cocompf(a[i],x,xcnt);
		int bb=cocompf(b[i],x,xcnt);
		int cc=cocompf(c[i],y,ycnt);
		rep(xx,aa,bb)dp[xx][cc]|=1<<1;//y-方向ダメ
	}
	rep(i,0,m){
		int dd=cocompf(d[i],x,xcnt);
		int ee=cocompf(e[i],y,ycnt);
		int ff=cocompf(f[i],y,ycnt);
		rep(yy,ee,ff)dp[dd][yy]|=1<<0;//x-方向ダメ
	}
	ufinit(xcnt*ycnt);
	rep(i,0,xcnt)rep(j,0,ycnt)unicnt[i*ycnt+j]=(x[i+1]-x[i])*(y[j+1]-y[j]);
	rep(i,1,xcnt)rep(j,1,ycnt){
		if(!bit(dp[i][j],0))uni(i*ycnt+j,(i-1)*ycnt+j);
		if(!bit(dp[i][j],1))uni(i*ycnt+j,i*ycnt+(j-1));		
	}
	int flag=0;
	int pos=cocompf(0,x,xcnt)*ycnt+cocompf(0,y,ycnt);
	rep(i,1,xcnt)flag|=ufsame(pos,i*ycnt+0)|ufsame(pos,i*ycnt+(ycnt-1));
	rep(j,1,ycnt)flag|=ufsame(pos,0*ycnt+j)|ufsame(pos,(xcnt-1)*ycnt+j);
	if(flag)puts("INF");
	else printf("%lld\n",unicnt[ufroot(pos)]);
}

Measured memory_bytes: 107484
# include <cstdio>
# include <algorithm>
# include <cstring>
# include <cmath>
# include <climits>
# include <iostream>
# include <string>
# include <queue>
# include <vector>
# include <set>
# include <map>
# include <cstdlib>
# include <stack>
# include <ctime>
using namespace std;

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=1e5+5;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
	x*=f;
}

ll a,b;
ll x;
ll ans=1;

int main()
{
	read(a),read(b);
	x=__gcd(a,b);
	for(ll i=2;i*i<=x;i++){
		if(x%i==0)ans++;
		while(x%i==0){
			x/=i;
			if(x==1)break;
		}
	}
	if(x>1)ans++;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char s[1024];
	int i,k = 0,u = 0,p = 0,c = 0;
	scanf("%s",s);
	for(i = 0;i <= 299;i++){
		switch(s[i]){
			case 'K':
			k++;
			break;
			case 'U':
			u++;
			break;
			case 'P':
			p++;
			break;
			case 'C':
			c++;
			break;
		}
	}
	if (k > u){
		k = u;
	}
	if (k > p){
		k = p;
	}
	if (k > c){
		k = c;
	}
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 540
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int MOD = 1_000_000_007;
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		long[][] dp = new long[H+1][W+2];
		dp[0][1] = 1;
		int[] x = new int[W+2];
		int tot = 0;
		LOOP:for(int j = 0; j < 1<<(W-1); j++) {
			boolean[] r = new boolean[W-1];
			for(int k = 0; k < W-1; k++)
				if((1 & j >> k) == 1)
					r[k] = true;
			for(int k = 1; k < W-1; k++)
				if(r[k] && r[k-1])
					continue LOOP;
			for(int k = 0; k < W-1; k++)
				if(r[k])
					x[k+1]++;
			tot++;
		}
		for(int i = 0; i < H; i++)
			for(int j = 1; j <= W; j++)
				dp[i+1][j] = (dp[i][j] * (tot - x[j] - x[j-1]) % MOD + dp[i][j-1] * x[j-1] % MOD + dp[i][j+1] * x[j] % MOD) % MOD;
		System.out.println(dp[H][K]);
	}

}

Measured memory_bytes: 23636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
ll K, A, B;
ll bis[100000000];
ll dfs(ll b, ll c,ll count) {
	if (count > K)return bis[K];
	if (c == 1) {
		bis[count + 1] = bis[count] + B;
		return  dfs(b + B, 0, count + 1);
	}
	else if (b < A) {
		bis[count + 1] = bis[count] + 1;
		return dfs(b + 1, c, count + 1);
	}
	else if (count == K - 1) {
		bis[count + 1] = bis[count] + 1;
		return dfs(b + 1, c, count + 1);
	}
	else {
		bis[count + 1] = bis[count] - A;
		return  dfs(b - A, c+1, count + 1);
	}
}
int main() {
	cin >> K >> A >> B;
	if (B - A <= 2) {
		cout << K + 1 << endl;
	}
	else {
		ll ans = 0;
		if (K <= A) {
			ans += 1 + K;
		}
		else {
			int x = K - (A - 1);
			if (x % 2 == 0) {
				ans += A+(x/2) * (B - A);
			}
			else {
				ans += A+(B - A)*(x / 2) + 1;
			}
		}
		cout << ans << 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 REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	string s;
	int x=-1,y=-1;
	bool b=false,c=false;
	cin >> s;
	rep(i,s.size()){
		if(s[i]=='C'){
			b=true;
			x=i;
		}
		if(s[i]=='F'){
			c=true;
			y=i;
		}
	}
	if(b && c && x<y) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
from collections import Counter


N = int(input())
A = list(map(int, input().split()))

C = Counter(A)

isAble = True
k = N - 1
while k >= 0:
    if k == 0:
        if C[k] != 1:
            isAble = False
    else:
        if C[k] != 2:
            isAble = False
    k -= 2

if isAble:
    print(pow(2, N // 2, 10 ** 9 + 7))
else:
    print(0)


Measured memory_bytes: 14812
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t, n;
    while(cin >> t >> n, t, n){
        string s = to_string(n);
        int l = s.size();
        int MAX = -1;
        vector<int> ans;
        bool f = false;
        rep(i, 0, (1LL << (l - 1))){
            int now = s[0] - '0';
            int sum = 0;
            vector<int> tmp;
            rep(j, 0, l - 1){
                if(i & (1LL << j)){
                    tmp.push_back(now);
                    sum += now;
                    now = s[j + 1] - '0';
                }else{
                    now = now * 10 + s[j + 1] - '0';
                }
            }
            tmp.push_back(now);
            sum += now;
            if(sum <= t && MAX < sum){
                MAX = sum;
                ans = tmp;
                f = true;
            }else if(sum <= t && MAX == sum){
                f = false;
            }
        }
        if(MAX == -1) cout << "error" << endl;
        else if(f == false) cout << "rejected" << endl;
        else{
            cout << MAX << " ";
            for(int ii = 0; ii < ans.size(); ii++){
                if(ii) cout << ' ';
                cout << ans[ii];
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3308
#include<bits/stdc++.h>
#include <iostream>
#include <utility>
#include <vector>

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int temp = a;
    a = b;
    b = temp;
    temp = a;
    a = c;
    c = temp;
    cout << a << " " << b << " " << c;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    int N;
    cin>>N;
    int *P = new int[N];    
    rep(i,N) cin>>P[i];
    int mi = N+1;
    int ans=0;
    rep(i,N){
        if(mi>P[i]) ans++;
        mi = min(mi,P[i]);
    }
    cout<<ans<<endl;
    delete[] P;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
const ll INF = 1e10;
const ld eps = 1e-9, pi = acos(-1.0);
typedef pair<ll, ll> P;

int main(){
  ll H, W;
  cin >> H >> W;
  vector<vector<ll> > dist(10, vector<ll>(10, INF));
  for(int y=0;y<10;y++)
    for(int x=0;x<10;x++)
      cin >> dist[y][x];
  for(int k=0;k<10;k++)
    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++){
	if(i==j)
	  dist[i][j]=0;
	else
	  dist[i][j]=min(dist[i][j], dist[i][k] + dist[k][j]);
      }
  ll ans = 0;
  for(int y=0;y<H;y++)
    for(int x=0;x<W;x++){
      ll a;
      cin >> a;
      if(a==-1)
	continue;
      ans += dist[a][1];
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
bool pairCompareS(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}
int main()
{
    ll n;
    cin >> n;
    map<ll, ll> odd;
    map<ll, ll> even;
    map<ll, ll> all;
    rep(i, n) {
        ll v;
        cin >> v;
        if (i % 2 == 0) {
            odd[v]++;
        } else {
            even[v]++;
        }
        all[v]++;
    }
    if (all.size() == 1) {
        print(n/2);
        return 0;
    }
    vector<P> vo;
    vector<P> ve;
    for(P p : odd) vo.push_back(p);
    for(P p : even) ve.push_back(p);
    sort(all(vo), pairCompareS);
    vo.push_back(make_pair(-1, 0));
    sort(all(ve), pairCompareS);
    ve.push_back(make_pair(-1, 0));
    if (vo[0].first == ve[0].first) {
        ll ans = min(n - vo[0].second - ve[1].second, n - vo[1].second - ve[0].second);
        print(ans);
    } else {
        print(n - vo[0].second - ve[0].second);
    }
    return 0;
}

Measured memory_bytes: 15092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
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 c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 300002;




ll n,k,q,ans=INF;
vector<ll> a;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k>>q;
	FOR(i,0,n){
		ll ooo;cin>>ooo;
		a.pb(ooo);
	}


	FOR(i,0,n){
		ll minl=a[i],maxl;
		vector<vector<ll> > v;
		vector<ll> w;	
		FOR(j,0,n){
			if(a[j]<minl){
				SORT(w);
				v.pb(w);
				w.clear();
			}else{
				w.pb(a[j]);
			}
		}
		SORT(w);
		if(w.size()!=0)v.pb(w);
		vector<ll> toru;
		FOR(j,0,v.size()){
			ll si=v[j].size();
			FOR(dd,0,min(q,si-k+1)){
				toru.pb(v[j][dd]);
			}
		}
		SORT(toru);
		if(toru.size()<q)continue;
		maxl=toru[q-1];
		ans=min(ans,maxl-minl);
	}
	pri(ans);
	return 0;
}


Measured memory_bytes: 384
require "bigdecimal"
require "bigdecimal/util"

def gi() gets.to_i end
def gs() gets.chomp end
def gmi() gets.split.map(&:to_i) end
def gms() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end

def comb(n,k)
  return nil if k > n
  result = 1
  1.upto() do |d|
    result *= n
    result /= d
    n -= 1
  end
  result
end

def perm(n,k)
  return nil if k > n
  result = 1
  k.times do
    result *= n
    n -= 1
  end
  result
end

def kaibun(str)
  str == str.reverse
end

#####

n,k = gmi
nums = gmi
puts ((n-1)/(k-1).to_f).ceil

Measured memory_bytes: 8108
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll a,b,c,x;
  cin >> a >> b >> c >> x;
  ll ans = 0;
  rep(i,a+1){
    if(500*i>x) break;
    rep(j,b+1){
      if(500*i+100*j>x) break;
      rep(k,c+1){
        if(500*i+100*j+50*k>x) break;
        if(500*i+100*j+50*k==x) {
          ans++;}
      }
    }
  }
  pri(ans);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *x, int *y){
  int temp = *x;
  *x = *y;
  *y = temp;
}

int gcd(int x, int y){
  if(x < y){
    swap(&x ,&y);
  }
  while( y > 0){
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}


int main(void){

  int x, y;

  scanf("%d %d", &x, &y);
  printf("%d\n", gcd(x, y));

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

ll a[100010];
ll sa[100010];
int main(void){
	ll n; cin >> n;
	ll allsum = 0;
	rep(i, n){
		cin >> a[i];
		allsum += a[i];
	}
	
	if(allsum % (n * (n + 1) / 2) != 0){
		printf("NO\n");
		return 0;
	}
	
	ll k = allsum / (n * (n + 1) / 2);
	rep(i, n - 1){
		sa[i] = a[i + 1] - a[i];
	}
	sa[n - 1] = a[0] - a[n - 1];
	rep(i, n){
		sa[i] -= k;
	}

	ll cnt = 0;
	rep(i, n){
		if(sa[i] > 0){
			printf("NO\n");
			return 0;
		}
		sa[i] *= -1;
		// printf("%lld\n", sa[i]);
		if(sa[i] % n != 0){
			printf("NO\n");
			return 0;
		}else{
			cnt += sa[i] / n;
		}
	}
	if(cnt == k){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N, M;
    cin >> N >> M;

    rep(i, M) {        
        int Ai;
        cin >> Ai;
        N -= Ai;
    }

    if (N < 0) {
        cout << -1 << endl;
    } else {
        cout << N << endl;
    }
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

void fail() {
    printf("Impossible\n");
    exit(0);
}

int h, w;
char grid[8][9];
int main() {
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; ++i) {
        scanf("%s", grid[i]);
    }
    if (grid[0][0] != '#') fail();
    int x = 0, y = 0;
    while (x < h - 1 || y < w - 1) {
        grid[x][y] = '.';
        bool r = x < h - 1 && grid[x + 1][y] == '#';
        bool d = y < w - 1 && grid[x][y + 1] == '#';
        if (r == d) fail();
        if (r) ++x;
        else ++y;
    }
    if (x != h - 1 || y != w - 1) fail();
    grid[x][y] = '.';
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i][j] == '#') fail();
        }
    }
    printf("Possible\n");
	return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let x: i64 = input();
    let a: i64 = input();
    let b: i64 = input();
    println!(
        "{}",
        if (x - a).abs() < (x - b).abs() {
            "A"
        } else {
            "B"
        }
    );
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		String line = scanner.nextLine();
		int N = Integer.parseInt(line);
		HashMap<String, Integer> hashmap = new HashMap<String, Integer>();

		long answer = 0;

		for (int i = 0; i < N; i++) {
			String[] readlines = scanner.nextLine().split("");
			Arrays.sort(readlines);

			String lines = "";
			for (int j = 0; j < readlines.length; j++)
				lines = lines + readlines[j];

			if (hashmap.containsKey(lines)) {
				answer = answer + hashmap.get(lines);
				hashmap.replace(lines, hashmap.get(lines) + 1);
			} else {
				hashmap.put(lines, 1);
			}
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 172256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int count_0 = 0;
    for(int i = 0;i<s.length();i++){
        if(i%2==0) {
            if(s[i]=='0') {
                count_0++;
            } 
        } else {
            if(s[i]=='1') {
                count_0++;
            }
        }
    }

    int count_1 = 0;
    for(int i = 0;i<s.length();i++){
        if(i%2==0) {
            if(s[i]=='1') {
                count_1++;
            } 
        } else {
            if(s[i]=='0') {
                count_1++;
            }
        }
    }

    int m;
    m = max(count_0, count_1);
    cout << s.length() -m << endl;
}

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

int main(){
  int n; std::cin >> n;
  int64_t l[n];
  l[0] = 2; l[1] = 1;
  if (n == 1) std::cout << l[1] << '\n';
  else{
    for (size_t i = 2; i < n+1; i++) {
      l[i] = l[i-1] + l[i-2];
    }
    std::cout << l[n] << '\n';
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef priority_queue<int> pqmaxi;  //push(xx) top->maxi,pop();
const int mod=1e9+7;
typedef pair<ll,ll> P;
typedef tuple<int,int,int> TP;

template <class T>bool chmax(T& a, T b){
    if (a < b){
        a = b; 
        return 1; 
    } 
    return 0; 
    }

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<P> a(n);
  ll tot=0;
  rep(i,n){
    cin>>a[i].first;
    a[i].second=i;
  }
  sort(a.begin(),a.end(),greater<P>());
  vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
  rep(i,n){
      for(int j=0;i+j<n;j++){
        chmax(dp[i+1][j],dp[i][j]+a[i+j].first*abs(a[i+j].second-i));
        chmax(dp[i][j+1],dp[i][j]+a[i+j].first*abs(n-1-j-a[i+j].second));
      }
  }

  ll res=0;
  rep(i,n+1)chmax(res,dp[i][n-i]);
  cout<<res<<endl;
  return 0;
  }


Measured memory_bytes: 34616