akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using pii = pair<i32, i32>;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
using vpii = vector<pii>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

char board[110][110];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  int A, B;
  cin >> A >> B;
  vector<string> board(100);
  rep(i, 100) {
    if (i < 50) {
      board[i] = string(100, '#');
    } else {
      board[i] = string(100, '.');
    }
  }
  rep(i, A - 1) {
    int y = ((i * 2) / 100) * 2;
    int x = (i * 2) % 100;
    board[y][x] = '.';
  }
  rep(i, B - 1) {
    int y = 99 - ((i * 2) / 100) * 2;
    int x = (i * 2) % 100;
    board[y][x] = '#';
  }
  cout << 100 << " " << 100 << endl;
  rep(i, 100) {
    cout << board[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

ll ans[1000000];
int checked[1000000];
vector< vector<ll> > childs(1000000); // N nodes

ll add_recursive(ll node_index, ll parent_number){
  if (checked[node_index] == 1) { // do not double check
    return 0;
  }

  checked[node_index] = 1;
  ans[node_index] += parent_number;
  vector<ll>::iterator itr;
  for(itr = childs[node_index].begin(); itr != childs[node_index].end(); ++itr){
    add_recursive(*itr, ans[node_index]);
  }
  return 0;
}

int main(){
  ll N;
  cin >> N;
  ll Q;
  cin >> Q;

  ll a;
  ll b;
  REP(i, 0, N-1){
    cin >> a;
    cin >> b;
    a = a-1;
    b = b-1;
    childs[a].push_back(b);
    childs[b].push_back(a);
  }

  REP(i, 0, 1000000) { ans[i] = 0; checked[i] = 0;}

  ll p;
  ll x;
  REP(i, 0, Q){
    cin >> p;
    cin >> x;
    p = p-1;
    ans[p] += x;
  }

  add_recursive(0, 0); // add x recursively from node p

  REP(i, 0, N){
    cout << ans[i] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 50048
#include <stdio.h>

int main()
{
    int a, b, c, x, y;
    int total = 0;
    int total2 = 0;
    scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
    int dif = x - y;
    if ((a + b) > 2 * c)
    {
        if (dif > 0)
        {
            total += (2 * c * y) + (dif * a);
            total2 += 2 * c * x;
        }
        else
        {
            total += ((2 * c * x) - (dif * b));
            total2 += 2 * c * y;
        }
        if (total > total2)
        {
            printf("%d\n", total2);
        }
        else
        {
            printf("%d\n", total);
        }
    }
    else
    {
        total = a * x + b * y;
        printf("%d\n", total);
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	clock_t begin = clock();
	int n;
	cin >> n;
	vector<ll>v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<vector<ll>>dp(n + 2, vector<ll>(2, 0));
	dp[0][0] = v[0];
	dp[0][1] = -v[0];
	for (int i = 0; i < n - 1; i++) {
		dp[i + 1][0] = max(dp[i][0] + v[i + 1], dp[i][1] - v[i + 1]);
		dp[i + 1][1] = max(dp[i][0] - v[i + 1], dp[i][1] + v[i + 1]);
	}
	cout << dp[n - 1][0] << endl;
	clock_t end = clock();
	cerr << "Time run: " << (float)(end - begin) / CLOCKS_PER_SEC << " s" << endl;
}

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

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

int main() {
  ll n,a; cin >> n >> a;
  cout << n*n-a << endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define MOD 1e9+7
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
template<typename T> inline T gcd(T&a,T&b){return b==0?a:gcd(b,a%b);}
template<typename T> inline T lcm(T&a,T&b){return a/gcd(a,b)*b;}
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int n,k;
ll a[maxn];
ll sum[maxn];
void init(){

}
inline bool cmp(int a,int b){return a>b;}
int main(){
    read(n);
    sum[0]=0;
    for (int i=1;i<=n;i++) read(a[i]),sum[i]=a[i]+sum[i-1];
    ll ans=abs(sum[n]-sum[1]-sum[1]);
    for (int i=2;i<n;i++){
        ans=min(ans,abs(sum[n]-sum[i]-sum[i]));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define     debug       printf("\n<<CameHere<<\n")
#define     mem(x,y)    memset(x, y, sizeof(x))
#define     all(qz)     qz.begin(),qz.end()
#define     rall(qz)    qz.rbegin(),qz.rend()
#define     inf         LLONG_MIN
#define     INF         LLONG_MAX
#define     mod         1000000007
#define     Sqr(x)      ((x)*(x))
#define     ll          long long
#define     mk          make_pair
#define     pb          push_back
#define     pi          acos(-1.0)
#define     cos(a)      cos(a*pi/180)
#define     sin(a)      sin(a*pi/180)
#define     tan(a)      tan(a*pi/180)

ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll n;
    cin>>n;
    ll x=(n/1000)*1000;
    if(x==n) cout<<0<<endl;
    else cout<<(x+1000)-n<<endl;
    return 0;
}



















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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

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

	ll a, b; std::cin >> a >> b;
	std::cout << a * b / gcd(a, b) << "\n";;
}


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

int main() {
  int A, B;
  char op;
  cin >> A >> op >> B;
  
  int n = 0;
  if (op == '+') {
    n = A + B;
  } else {
    n = A - B;
  }
  
  cout << n << endl;
}


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

using namespace std;

int main() {

    int n; cin >> n;
    vector<int> v(n,0); for (int i=0; i<n; i++) cin >> v[i];

    int ans = 0;

    sort(v.begin(), v.end());

    for (int i=1; i<n; i++) {
        if (v[i]!=v[i-1]) ans += 1;
    }

    cout << ans + 1 << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>L;
    vec a(L);
    rep(i,L) cin>>a[i];
    mat dp(5, vec(L + 1,0));
    reps(i,1,L+1){
        rep(j,5){
            dp[j][i] = dp[j][i-1];
            if(j == 0 || j == 4) dp[j][i] += a[i-1];
            if(j == 1 || j == 3) dp[j][i] += (a[i-1] == 0 ? 2 : a[i-1]%2);
            if(j == 2) dp[j][i] += (a[i-1] + 1)%2;
        }
        ll mini = dp[0][i];
        reps(j,1,5) mini = dp[j][i] = min(dp[j][i], mini);
    }
    cout<<dp[4][L]<<endl;
    /*rep(i,L+1){
        rep(j,5) cout<<dp[j][i]<<' ';
        cout<<endl;
    }*/
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  i64 n, x, d;
  cin >> n >> x >> d;
  if (d == 0) {
    if (x == 0) kek(1);
    kek(n + 1);
  }
  if (x == 0) kek(1LL + n * (n - 1) / 2);
  map<i64, vector<pair<i64,i64>>> m;
  for (i64 take = 0; take <= n; ++take) {
    i64 b = take * x;
    i64 sum = take * (take - 1) / 2LL;
    i64 rsum = (n - take) * take + sum;
    i64 c = b / d;
    m[b % d].emplace_back(c + sum, c + rsum);
  }
  i64 ans = 0LL;
  for (auto &pr : m) {
    auto &v = pr.second;
    sort(ALL(v));
    i64 l, r;
    int f = 0;
    for (auto &p : v) {
      if (!f) {
        f = 1;
        l = p.first;
        r = p.second;
      } else {
        if (p.first <= r) {
          uax(r, p.second);
        } else {
          ans += r - l + 1;
          l = p.first;
          r = p.second;
        }
      }
    }
    ans += r - l + 1;
  }
  kek(ans);
  
  
  return 0;
}


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

int oddt[100001];
int event[100001];

int main(void) {
  
  for(int i = 0; i < 100001; i++)
  {
    oddt[i] = event[i] = 0;
  }

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if (i % 2 == 0) {
      event[v]++;
    }
    else {
      oddt[v]++;
    }
  }

  int maxO = 0;
  int maxON = 0;

  int smaxO = 0;
  
  int maxE = 0;
  int maxEN = 0;

  int smaxE = 0;
  for(int i = 0; i < 100001; i++)
  {
    if (event[i] > maxE){
      maxE = event[i];
      maxEN = i;
    }
    if (oddt[i] > maxO) {
      maxO = oddt[i];
      maxON = i;
    }
  }

  for(int i = 0; i < 100001; i++)
  {
    if (event[i] > smaxE && i != maxEN){
      smaxE = event[i];
    }
    if (oddt[i] > smaxO && i != maxON) {
      smaxO = oddt[i];
    }
  }

  if (maxEN == maxON){
    if (smaxE + maxO < smaxO + maxE) {
      cout << (n / 2) - maxE + (n / 2) - smaxO << endl;
    }
    else {
      cout << (n / 2) - smaxE + (n / 2) - maxO << endl;
    }
  }
  else {
    cout << (n / 2) - maxE + (n / 2) - maxO << endl;
  }

  return 0;
}

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

int main() {
    int n; string s;
    cin >> n >> s;
    int t = 0;
    for (int i = 1; i < n; i++) t += (s[i] == 'E');
    int ans = 1 << 30;
    for (int i = 0; i < n; i++) {
        ans = min(ans, t);
        t += (s[i] == 'W') - (s[i + 1] == 'E');
    }
    cout << ans << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for (int i = 0; i < N; ++i) {
    cin >> V.at(i);
  }
  for (int i = 0; i < N; ++i) {
    cin >> C.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int x = V.at(i) - C.at(i);
    if (x > 0) {
      ans += x;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A,B = (int(i) for i in input().split())
P = [int(i) for i in input().split()]
s=t=u=0
for i in range(N):
    if P[i]<=A:
        s+=1
    if P[i]>A and P[i] <= B:
        t+=1
    if P[i] > B:
        u+=1
re = min(s,t,u)
print(re)


Measured memory_bytes: 3060
# def binary_search_original(ary, target):

#     if ary:
#         ind = len(ary) // 2
#         if target == ary[ind]:
#             return True
#         elif target < ary[ind]:
#             return binary_search(ary[:ind], target)
#         else:
#             return binary_search(ary[ind + 1:], target)

#     else:
#         return False


def binary_search(ary, target):

    left = 0
    right = len(ary)

    while left < right:
        mid = (left + right) // 2

        if ary[mid] == target:
            return True
        elif ary[mid] < target:
            left = mid + 1
        else:
            right = mid

    return False


if __name__ == '__main__':

    n = int(input())
    S = [int(_) for _ in input().split()]
    q = int(input())
    T = [int(_) for _ in input().split()]
    cnt = 0

    for target in T:
        if binary_search(S, target):
            cnt += 1

    print(cnt)



Measured memory_bytes: 16896
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#define ll long long 
using namespace std;
const int maxn=500010,inf=1e9;
int n,K,now,mx,x;
void read(int &k)
{
	int f=1;k=0;char c=getchar();
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
	k*=f;
}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main()
{
	read(n);read(K);read(now);mx=now;
	for(int i=1;i<n;i++)read(x),now=gcd(now,x),mx=max(x,mx);
	if(mx>=K&&K%now==0)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
line = gets
data = line.split(" ")
num = Array.new(9, 0)
n.times do |i|
  idx = data[i].to_i / 400
  if idx >= 8
    num[8] += 1
  else
    num[idx] += 1
  end
end
min = 0
8.times do |i|
  if num[i] != 0
    min += 1
  end
end
max = min
if num[8] != 0
  max += num[8]
  if min == 0
    min = 1
  end
end
puts "#{min} #{max}"

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

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


using namespace std;
using ll = long long;

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

ll pow(ll a,ll b)
{
    ll num=1;
    rep(i,b)
    {
        num *= a;
    }
    return num;
}


int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<int> a(n),b(n),root;
    rep(i,n) {
        cin >> a[i];
        --a[i];
    }
    root.push_back(0);
    ll t=0,way =1;
    while(b[t] == 0){
        
       
        b[t] = -way;
        way++;
        t = a[t];
        root.push_back(t);
        
    }
    
    if(k <= -b[t] -1){
        cout << root[k]+1 << endl;
    }else{
        ll jo = (k+b[t]+1)%(way+b[t]);
        
        cout << root[-b[t]-1+jo]+1 << endl;
    }


   
    
    
    return 0;
}


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

int main(void){
	
	int n,r,t;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> r >> t;
		if(r % 100 == 0 && t % 30 == 0){
			cout << r/100+t/30*5 << endl;
		}else if(r % 100 == 0){
			cout << r/100+(t-t%30)/30*5 << " " << r/100+(t+(30-t%30))/30*5 << endl;
		}else if(t % 30 == 0){
			cout << (r-r%100)/100+t/30*5 << " " << (r+(100-r%100))/100+t/30*5 << endl;
		}else {
			cout << (r-r%100)/100+(t-t%30)/30*5 << " " << (r+(100-r%100))/100+(t-t%30)/30*5 << " " << (r-r%100)/100+(t+(30-t%30))/30*5 << " " <<(r+(100-r%100))/100+(t+(30-t%30))/30*5<< endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int dp[5][35000]={0};
int main(){
	dp[0][0]=1;
	rep(i,299)rep(j,5)rep(k,35000)if(dp[j][k]){
		int I=i+1,J=j+1,K=k+I*I;
		if(K<35000&&J<5)dp[J][K]+=dp[j][k];
	}
	int n;
	while(cin>>n,n){
		int out=0;
		rep(i,5)out+=dp[i][n];
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1712
#include <stdio.h>

int main(){
    int N=0, data[3] ,c,i;
    scanf("%d",&N);
    char *judge[N];
    for (i=0; i<N; i++) {
        scanf("%d %d %d",&data[0],&data[1],&data[2]);
        if (data[0]<data[1]) {
            c=data[1];
            data[1]=data[0];
            data[0]=c;
        }
        if (data[0]<data[2]) {
            c=data[2];
            data[2]=data[0];
            data[0]=c;
        }
        if (data[0]*data[0]==(data[1]*data[1]+data[2]*data[2])) {
            judge[i]="YES";
        }
        else
            judge[i]="NO";
    }
    for (i=0; i<N; i++) {
        printf("%s\n",judge[i]);
    }
    
    return 0;
}

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

using namespace std;

using ll = long long;

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

    int h, w, n;
    cin >> h >> w >> n;

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

    vector<vector<int>> c(h, vector<int>(w));

    int x = 0, y = 0, dir = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < a[i]; ++j) {
            c[y][x] = i + 1;
            if (dir == 0) { // to right
                ++x;
                if (x == w) {
                    ++y;
                    x = w - 1;
                    dir = 1;
                }
            }
            else { // to left
                --x;
                if (x == -1) {
                    ++y;
                    x = 0;
                    dir = 0;
                }
            }
        }
    }

    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
            cout << c[i][j] << (j == w - 1 ? '\n' : ' ');

    return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
B = [0 for i in range(N)]

for i in range(N):
    if i%2 == 0:
        B[0] += A[i]
    else:
        B[0] -= A[i]

for i in range(N-1):
    B[i+1] = 2 * A[i] - B[i]

print(*B)

Measured memory_bytes: 14028
#include<stdio.h>
#define FREE -1
#define NOT_FREE -2
#define N 8
#define M 15
#define QUEEN 100

void printBoard(int a[N][N]){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(a[i][j]==j||a[i][j]==QUEEN){
	printf("Q");
      }else printf(".");
    }
    printf("\n");
  }
  return;
}
void putQueen(int i,int col[N],int row[N],int dpos[M],int dneg[M],int a[N][N],int k){
  int j,x;
  static int F=0;
  if(i==N&&F!=1){
    F=1;
    printBoard(a);
    return;
  }
  for(j=0;j<N;j++){
    if(a[i][j]!=QUEEN){
      if(row[i]==NOT_FREE || col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)
	continue;
      a[i][j]=j;
      row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    
      putQueen(i+1,col,row,dpos,dneg,a,k);
      a[i][j]=row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    }else putQueen(i+1,col,row,dpos,dneg,a,k);
  }
}

int main(){
  int i,j,k,r,c,col[N],row[N],dpos[M],dneg[M],a[N][N];
  for(i=0;i<N;i++){
    col[i]=row[i]=dpos[i]=dneg[i]=FREE;
    for(j=0;j<N;j++)
      a[i][j]=FREE;
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    a[r][c]=QUEEN;
    row[r]=col[c]=dpos[r+c]=dneg[r-c+N-1]=NOT_FREE;
  }

  putQueen(0,col,row,dpos,dneg,a,k);
  return 0;
}



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

int main(void)
{
    int A,B,C,D;
    
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);

    int E,F,G;
    
    if(A > B){
        E = B;
    }else{
        E = A;
    }
    
    
    if(C > D){
        F = D;
    }else{
        F = C;
    }
    
    
    G = E + F;
    
    printf("%d",G);
    
    
    
    return EXIT_SUCCESS;
}

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

int main() {
  int a;
  int b;
  cin  >> a >> b ;
  
  int x ;
  x= a*b ;
    
  if ( x % 2 ==1 ) {
    cout << " Odd " << endl;
  }
  else {
    cout << " Even " << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int count = 0;
		if(b != 1) {
			count = 1;
		}
		int sum = a;
		while(b > sum) {
			sum += a-1;
			count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <vector>
using namespace std;

const int maxn = 310;
const int mod = 1000000007;

vector<int> ter[maxn];
int f[maxn][maxn][maxn];
set<int> s;
int l[maxn], r[maxn], x[maxn];

bool check(int r,int g, int b)
{
	if ((r==g && r!=0) || (g==b&&g!=0) || (r==b&&r!=0)) return false;
	int k = max(r,max(g,b));
	int t1,t2;
	if (k == r) t1 = g, t2 = b;
	if (k == g) t1 = r, t2 = b;
	if (k==b) t1 = r, t2 = g;
		
	for (int i=0;i<(int)ter[k].size();i++)
	{
		if (l[ter[k][i]]<=k && l[ter[k][i]] >= max(t1,t2)+1)
		{
			if (x[ter[k][i]] != 1) return false;
		}
		if (l[ter[k][i]] <= max(t1,t2) && l[ter[k][i]] > min(t1,t2))
		{
			if (x[ter[k][i]] != 2) return false;
		}
		if (l[ter[k][i]] <= min(t1,t2))
		{
			if (x[ter[k][i]] != 3) return false;
		}
	}
	return true;
}

int main()
{
	//freopen("E.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&l[i], &r[i], &x[i]); 
		ter[r[i]].push_back(i);
	}
	
	f[0][0][0] = 1;
	
	for (int r=0;r<=n;r++)
	{
		for (int g=0;g<=n;g++)
		{
			for (int b=0;b<=n;b++)
			{
				if (!check(r,g,b)) 
				{
					f[r][g][b] = 0;
					continue; 
				}
				//cout<<r<<" "<<g<<" "<<b<<" "<<f[r][g][b]<<endl;
				int k = max(r,max(g,b));
				// R
				f[k+1][g][b] = (f[k+1][g][b] + f[r][g][b]) % mod;
				// G
				f[r][k+1][b] = (f[r][k+1][b] + f[r][g][b]) % mod;
				// B
				f[r][g][k+1] = (f[r][g][k+1] + f[r][g][b]) % mod;
				
			}
		}
	}
	
	int sum = 0;
	for (int r=0;r<=n;r++)
	{
		for (int g=0;g<=n;g++)
		{
			for (int b=0;b<=n;b++) 
				if (max(r,max(g,b)) == n) sum = (sum + f[r][g][b]) % mod;
		}
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 114944
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        int M = nextInt();

        Map<Integer, List<Integer>> map = new HashMap<>();
        for(int i=0; i<M; i++){
            List<Integer> list = new ArrayList<>();
            int a = nextInt()-1;
            int b = nextInt()-1;
            if(map.containsKey(b)){
                list = new ArrayList<>(map.get(b));
            }
            list.add(a);
            map.put(b, list);
        }

        List<Integer> keys = new ArrayList<>(map.keySet());
        Collections.sort(keys);

        int x = 0;
        int count = 1;
        for(int i=0; i<keys.size(); i++){
            if(i == 0) x = keys.get(i)-1;
            for(int j=0; j<map.get(keys.get(i)).size(); j++){
                int key = keys.get(i);
                int num = map.get(key).get(j);
                if(x < num){
                    count++;
                    x = keys.get(i)-1;
                    break;
                }
            }
        }

        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 360500
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define pb push_back
#define endl '\n'
ll solve(){
	ll r,g,b;
	cin>>r>>g>>b;
	ll k;
	cin>>k;
	while(k--){
		if(r>=g) g*=2;
		else if(g>=b) b*=2;
		else break;
	}
	if(r<g&&g<b) cout<<"Yes";
	else cout<<"No";
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て

int		main(void)
{
	int N;
	cin >> N;
	vector<int> V(N);
	for (int i = 0; i < N; i++)
		cin >> V[i];
	sort(all(V));
	double sum = (double)(V[0] + V[1]) / 2;
	for (int i = 2; i < N; i++)
		sum = (sum + V[i]) / 2;
	printf("%.10f\n", sum);
}



Measured memory_bytes: 256
def mempow(a,b,m):
    temp = 1
    yield temp
    for i in range(b):
        temp = temp * a % m
        yield temp

L = open(0).read().split()[0]
m = 1000000007
mem2 = []
mem3 = []
m2append = mem2.append
m3append = mem3.append
for x in mempow(2,L.count('1'),m):
    m2append(x)
for x in mempow(3,len(L)-1,m):
    m3append(x)
ans = mem3[len(L)-1]
appeared = 1
for i in range(1,len(L)):
    if L[i] == '1':
        ans = (ans+mem2[appeared]*mem3[len(L)-i-1]) % m
        appeared += 1
ans = (ans+mem2[appeared]) % m
print(ans)

Measured memory_bytes: 11124
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int a, b;
    char c;
    cin >> a >> c >> b;
    if (c == '+')
        cout << a+b;
    else 
        cout << a-b;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    long int num, total;
    int fivehundred, five;

    scanf("%ld", &num);
    fivehundred = num/500;
    five = (num - fivehundred*500) / 5;
    total = fivehundred*1000 + five * 5;
    printf("%ld",total);

    return 0;
}

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

typedef pair<int,int> P;
char s[5010][5];

// 初期化 (y == 0 のところを番兵でブロックにしておく)
void ini(){
	for(int y=0 ; y < 5010 ; y++ ){
		for(int x=0 ; x < 5 ; x++ ){
			s[y][x] = y? '.' : '#' ;
		}
	}
}

void debug(int ay){
	cout << "[debug]" << endl;
	for(int y=ay ; y > 0 ; y-- ){
		for(int x=0 ; x < 5 ; x++ ){
			cout << s[y][x];
		}
		cout << endl;
	}
	cout << endl;
}

// ブロックの初期位置を返す.
vector<P> block(int d, int p, int q, int y){
	vector<P> v;
	if( d == 1 ){ // 横向きのブロック
		for(int i=0 ; i < p ; i++ ){
			int mx = q + i;
			int my = y;
			v.push_back( P(mx,my) );
		}
	}else{ // 縦向きのブロック
		for(int i=0 ; i < p ; i++ ){
			int mx = q;
			int my = y + i;
			v.push_back( P(mx,my) );
		}
	}
	return v;
}

// ブロックを落とす, ay := ブロックの一番高い位置 + 10
void fall(vector<P> v, int& ay){
	// flag := ブロックが1マス落下できるかどうか
	bool flag = true;
	for(int i=0 ; i < v.size() ; i++ ){
		int x = v[i].first;
		int y = v[i].second;
		if( s[y-1][x] == '#' ){
			flag = false;
		}
	}
	
	if( flag ){ // 1マス落下させるとき
		for(int i=0 ; i < v.size() ; i++ ){
			v[i].second--;
		}
		fall( v , ay );
	}else{ // ブロックの落下位置が決まる
		int my = v[0].second;
		for(int i=0 ; i < v.size() ; i++ ){
			int x = v[i].first;
			int y = v[i].second;
			s[y][x] = '#';
			my = max( my , y );
		}
		ay = max( ay , my + 10);
	}
}

// 高さ y が揃ったかどうか
bool is_line(int y){
	return (s[y][0] == '#' && s[y][1] == '#' && s[y][2] == '#' && s[y][3] == '#' && s[y][4] == '#');
}

// 高さ l の列を消す.
void remove(int l, int ay){
	for(int y=l ; y < ay ; y++ ){
		s[y][0] = s[y+1][0];
		s[y][1] = s[y+1][1];
		s[y][2] = s[y+1][2];
		s[y][3] = s[y+1][3];
		s[y][4] = s[y+1][4];
	}
}

// 揃った列があるか調べて消す.
void check(int ay){
	for(int y=1 ; y < ay ; y++ ){
		if( is_line(y) ){
			remove(y,ay);
			y--;
		}
	}
}

int block_count(int ay){
	int ans = 0;
	for(int y=1 ; y < ay ; y++ ){
		for(int x=0 ; x < 5 ; x++ ){
			if( s[y][x] == '#' ) ans++;
		}
	}
	return ans;
}

int main(){
	int n;
	while( cin >> n , n ){
		ini();
		int y=10;
		for(int i=0 ; i < n ; i++ ){
			int d, p, q;
			cin >> d >> p >> q;
			vector<P> v = block(d,p,q-1,y);
			fall(v,y);
			check(y);
			// debug(y);
		}
		int ans = block_count(y);
		cout << ans << endl;
	}
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int w,h,n;
  cin>>w>>h>>n;
  int minx=0,maxx=w,miny=0,maxy=h;
  vector<int> x(n),y(n),a(n);
  rep(i,n) cin>>x[i]>>y[i]>>a[i];
  rep(i,n){
    if(a[i]==1){
      minx=max(minx,x[i]);
    }
    if(a[i]==2){
      maxx=min(maxx,x[i]);
    }
    if(a[i]==3){
      miny=max(miny,y[i]);
    }
    if(a[i]==4){
      maxy=min(maxy,y[i]);
    }
  }
  int ans=(maxx-minx)*(maxy-miny);
  if(maxx-minx<0 || maxy-miny<0){
    cout<<0<<endl;
  }else{
    cout<<ans<<endl;
  }
  
  
  
}
///////////////////////////

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

int main() {
  int NN,MM;
  cin >> NN >> MM;
  vector<int> N(NN);
  vector<int> M(MM*2);
  for (int i=0; i<MM*2 ; i++){
    cin >> M[i];
    N[M[i]-1]++;
  }
  for (int i=0; i<NN; i++){
    cout << N[i] << endl;
  }
  return 0;
}


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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if ((B - A) % 2 == 0) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Borys" << endl;
	}
}

Measured memory_bytes: 3636
import sys
import collections
input = sys.stdin.readline

N, M, K = map(int, input().split())
F = []
for i in range(M):
	F.append(list(map(int, input().split())))
B = []
for i in range(K):
	B.append(list(map(int, input().split())))

def get_group(F):
	def root(a):
		p = G[a]
		while p != G[p]:
			p = G[p]
		while a != p:
			a, G[a] = G[a], p
		return p
	def union(a, b):
		ra = root(a)
		rb = root(b)
		if ra == rb: return
		G[ra] = rb
	G = [i for i in range(N)]
	for a, b in F:
		a -= 1
		b -= 1
		union(a, b)
	for i in range(N):
		G[i] = root(i)
	return G

def calc_count(F, G):
	edges = collections.defaultdict(set)
	for a, b in F:
		a -= 1
		b -= 1
		if G[a] == G[b]:
			edges[a].add(b)
			edges[b].add(a)
	cnt = [0] * N
	for i in range(N):
		cnt[i] = len(edges[i])
	return cnt

def get_num(c, f, b):
	ret = (c-1) - f - b
	return ret

G = get_group(F)
C = collections.Counter(G)
FC = calc_count(F, G)
BC = calc_count(B, G)
ans = [0] * N
for i in range(N):
	ans[i] = get_num(C[G[i]], FC[i], BC[i])

print(' '.join(map(str, ans)))


Measured memory_bytes: 113352
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = set(A)
    if len(A) % 2 == 0:
        print(len(A) - 1)
    else:
        print(len(A))



if __name__ == "__main__":
    main()

Measured memory_bytes: 98248
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int k, n;
	int i, j;

	cin >> n >> k;
	int *p = new int[n+1];
	for (i = 0; i < n; i++) {
		cin >> p[i];
	}

	sort(p, p+n);

	int ans = 0;
	for (i = 0; i < k; i++) {
		ans += p[i];
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string a,b;cin >> a >> b;
	
	sort(ALL(a));
	sort(ALL(b),greater<char>());
	
	if(a < b)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

def main():
    if len(s) < 1 and len(s) > 10:
        print('No')
        return

    if (s.isalpha() == False or s.islower() == False):
        print('No')
        return

    if (t[-1].isalpha() == False or t[-1].islower() == False):
        print('No')
        return

    if len(t) == len(s) + 1 and t[:-1] == s:
        print('Yes')
    else:
        print('No')
    return

main()


Measured memory_bytes: 9136
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<double, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const double inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
double x[1010], y[1010], r[1010];

const int MAX = 1010;
struct edge {
    int to;
    double cost;
};

vector<edge> G[MAX];
double d[MAX];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    for (int i = 0; i < MAX; i++) d[i] = inf;
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

double dist(int i, int j) {
    return max(0.0, sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j])) - r[i] - r[j]);
}

double solve() {
    n += 2;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i != j)
                G[i].push_back(edge{j, dist(i, j)});
        }
    }
    dijkstra(0);
    return d[n-1];
}

void input() {
    double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    cin >> n;
    x[0] = xs; y[0] = ys; r[0] = 0;
    for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> r[i];
    x[n+1] = xt; y[n+1] = yt; r[n+1] = 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 20592
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N;
    cin >> N;
    int cnt = 0;
    vector<string> S(N);
    bool no = false;
    REP (i, N) {
        cin >> S[i];
        if (S[i] == "A") cnt++;
        else cnt--;
        if (cnt < 0) no = true;
    }
    if (cnt) no = true;
    cout << (no ? "NO" : "YES") << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


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

using namespace std;

int main(void)
{
  int N;
  cin >> N;
  vector<vector<int>> S(N, vector<int>(N, 0));

  if (N == 2)
  {
    cout << 2 << endl;
    return 0;
  }

  int num = 0;
  int check;
  for (int i = 0; i < N; i++)
  {
    string Ss;
    cin >> Ss;
    for (int j = 0; j < N; j++)
    {
      S[i][j] = Ss[j] - '0';
    }
  }

  int vmax = 0;

  for (int t = 0; t < N; t++)
  {
    vector<int> Ns(N, -1);
    Ns[t] = 0;
    int p = 0;

    while (true)
    {
      for (int i = 0; i < N; i++)
      {
        if (Ns[i] == p)
        {
          for (int j = 0; j < N; j++)
          {
            if (S[i][j] == 1)
            {
              if (Ns[j] == -1)
              {
                Ns[j] = p + 1;
              }
              else
              {
                if ((p + 1) % 2 != Ns[j] % 2)
                {
                  cout << -1 << endl;
                  return 0;
                }
              }
            }
          }
        }
      }

      //deback
      /*
      for (int i = 0; i < N; i++)
      {
        cout << Ns[i] << " ";
      }
      cout << " " << endl;
      */
      //end
      if (find(Ns.begin(), Ns.end(), p+1) == Ns.end())
      {
        break;
      }

      p++;
    }
    if (vmax < p)
    {
      vmax = p;
    }
  }

  cout << vmax+1 << endl;

  return 0;
}

Measured memory_bytes: 512
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;

int main(){
    while(cin >> n && n){
        n /= 4;
        int sum = 0;
        int a;
        REP(i, n){
            cin >> a;
            sum += a;
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 2992
<?php
$stdin = explode(' ',trim(fgets(STDIN)));
if($stdin[0]<$stdin[1]){
    echo 'a < b';   
}elseif($stdin[0]>$stdin[1]){
    echo 'a > b';
}elseif($stdin[0]===$stdin[1]){
    echo 'a == b';
}
?>

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, M;
    map<ll, ll> D;
    cin >> N;
    for(ll i = 0;i < N;i++) {
        ll temp;
        cin >> temp;
        D[temp]++;
    }
    cin >> M;
    for(ll i = 0;i < M;i++) {
        ll temp;
        cin >> temp;
        D[temp]--;
    }
    for(auto &i: D) {
        if(i.second < 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;cin>>S;
    for(int i=0;i<3;i++){
        if(S[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000



int main(){
	
	int M,K;
	cin>>M>>K;
	
	if((1<<M)<=K){
		cout<<-1<<endl;
		return 0;
	}
	
	if(M==1&&K==1){
		cout<<-1<<endl;
		return 0;
	}
	
	vector<int> ans;
	
	if(K==0){
		for(int i=0;i<(1<<M);i++){
			ans.push_back(i);
			ans.push_back(i);
		}
	}
	else{
		for(int i=0;i<(1<<M);i++){
			if(i==K)continue;
			ans.push_back(i);
		}
		ans.push_back(K);
		for(int i=(1<<M)-1;i>=0;i--){
			if(i==K)continue;
			ans.push_back(i);
		}
		ans.push_back(K);
	}
	
	for(int i=0;i<ans.size();i++){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 2932
#!/usr/bin/perl

$line = 0;
while (<>) {
    if ($line == 0) {
        chomp;
        $n = $_;
    } else {
        @a = split /\s+/, $_;
    }
    $line++;
}

if ($#a % 2) {
    $i = 1;
} else {
    $i = 0;
}

foreach (@a) {
    if ($i % 2) {
        push @s, $_;
    } else {
        unshift @s, $_;
    }
    $i++;
}

$n = 0;
foreach (@s) {
    print ;
    if ($n == $#s) {
        print "\n";
    } else {
        print " ";
    }
    $n++;
}


Measured memory_bytes: 40396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const string YES = "Yes";
const string NO = "No";

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll num_r = 0;
    for(char c : s){ num_r += c == 'R'; }
    if(2 * num_r > n){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
    return 0;
}


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

const int MOD = 1e9 + 7;
const int INF = 1 << 30;

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.InputMismatchException;
 
public class Main {
    public static void main(String[] args) {
      try {
      	Scanner scanner = new Scanner(System.in);
    
      	int x = scanner.nextInt();
     	int y = scanner.nextInt();
		int z = scanner.nextInt();
      	scanner.close();
        if (x+y >= z){
       	    System.out.printf("%s","Yes");
        }else{
         	System.out.printf("%s","No");
        }
    } catch (InputMismatchException e) { 
      System.out.println("error");
    }
      
    }
}

Measured memory_bytes: 21844
while True:
    n = int(input())
    if not n: break
    a = [list(map(int, input().split())) for _ in range(n)]
    s = max(min(a[i]) for i in range(n))
    c = [max(a[i][j] for i in range(n)) for j in range(n)]
    for j in range(n):
        if c[j] == s:
            print(s)
            break
    else:
        print(0)

Measured memory_bytes: 7628