akhauriyash/Code-Regression huggingface dataset:
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

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

#if 0
	auto possible = [&](LL t) {

		return false;
	};
	LL left = 1, right = 1000000000;
	while (right - left > 1) {
		LL mid = (left + right) / 2;
		if (possible(mid)) {
			left = mid;
		} else {
			right = mid;
		}
	}
#endif

static const long long MOD = 1000000007;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll combination(LL n, LL r) {
	static modll fact[MAX_N + 1], inv[MAX_N + 1];
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

void solve(long long N, std::vector<long long> &A) {
	modll ans = 0, sum = 0;
	for (LL i = 0; i < N; ++i) {
		ans += sum * (int)A[i];
		sum += (int)A[i];
	}
	cout << ans << endl;
}

int main() {
    long long N;
	scanf("%lld", &N);
	std::vector<long long> A(N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]); // A[i]--;
	}
	solve(N, A);
	return 0;
}


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

int main() {
  long long r, d, x;
  cin >> r >> d >> x;
  for(int i = 0; i < 10; i++) {
    x = r*x - d;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#define lli long long int

using namespace std;

struct info{
	string era;
	lli eby;
	lli wy;
};

bool comp(const info& i1, const info& i2)
{
	return i1.wy < i2.wy;
}

int main()
{
	int n, q;
	info a[1001];
	lli p;
	
	while(1){
		cin >> n >> q;
		if(n == 0 && q == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> a[i].era >> a[i].eby >> a[i].wy;
		}
		sort(a, a+n, comp);
		
		for(int i = 0; i < q; i++){
			cin >> p;
			bool f = true;
			for(int j = 0; j < n; j++){
				lli t = (a[j].eby+p)-a[j].wy;
				if(t > 0 && a[j].wy >= p){
					cout << a[j].era << " " << t << endl;
					f = false;
					break;
				}
			}
			if(f){
				cout << "Unknown" << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1000
import sys
a,b,c,d = input()
for i in ["+","-"]:
  for j in ["+","-"]:
    for k in ["+","-"]:
      if eval(a+i+b+j+c+k+d) == 7:
        print(a+i+b+j+c+k+d+"=7")
        sys.exit()

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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int k,a,b; cin >> k >> a >> b;
    int ok = 0;
    int v1 = (a/k)*k;
    if(v1>=a && v1<=b) ok = 1;
    v1 += k;
    if(v1>=a && v1<=b) ok = 1;
    cout << (ok ? "OK\n":"NG\n") ;
    return 0;
}

Measured memory_bytes: 3616
n=int(input())
a=sorted([int(_) for _ in input().split()])
b=[int(_) for _ in input().split()]
c=sorted([int(_) for _ in input().split()])
x=0
for i in range(n):
    oa=-1
    na=n
    while na-oa>1:
        ma=(oa+na)//2
        if a[ma]<b[i]:oa=ma
        else:na=ma
    ob=n
    nb=-1
    while ob-nb>1:
        mb=(ob+nb)//2
        if c[mb]>b[i]:ob=mb
        else:nb=mb
    x+=(oa+1)*(n-ob)
print(x)

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


int func(int num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtnum = sqrt(num);
    int i;
    for (i = 3; i <= sqrtnum; i += 2){
        if (num % i == 0){
            return 0;
        }
    }
    return 1;
}

int main(void){
    int x;
    scanf("%d",&x);
    while (1){
        if(func(x) == 1) break;
        else x++;
    }
    

    printf("%d\n",x);
    
    return 0;
}

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

int main(){
  string s,alpha;
  alpha = "abcdefghijklmnopqrstuvwxyz";
  cin >> s;
  for(int i=0;i<26;i++){
    if(s.find(alpha[i]) == string::npos){
      cout << alpha[i] << endl;
      break;
    }
    if(i==25 && s.find("z") != string::npos){
      cout << "None" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int gc(int x, int y) { return y == 0 ? x : gc(y, x%y); }
int chk[30030];
int mark[30030];

void solve() {
	vector <int> v;
	for(int i=2;i<=11;i++) for(int j=i;j<=30000;j+=i) chk[j] = 1;
	for(int i=2;i<=30000;i++) if(chk[i]) v.pb(i);
	srand(123);
	int n; scanf("%d", &n);
	while(1) {
		random_shuffle(v.begin() + 2, v.end());
		vector <int> ans;
		ll sum = 0;
		memset(mark, 0, sizeof mark);
		rep(i, n-1) ans.pb(v[i]), sum += v[i], mark[v[i]] = 1;
		int t = 27720 - (sum % 27720);
		if(chk[t] && mark[t] == 0) {
			ans.pb(t);
			for(int e : ans) printf("%d ", e); puts("");
			break;
		}
	}
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
ll lucas(int n, vector<ll> &luca)
{
  if (luca.at(n) == 0)
  {
    luca.at(n) = lucas(n - 1, luca) + lucas(n - 2, luca);
  }
  else
  {
    return luca.at(n);
  }
}

int main()
{
  int n;
  cin >> n;
  vector<ll> luca(87, 0);
  luca.at(0) = 2;
  luca.at(1) = 1;
  cout << lucas(n, luca) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
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;}
 
 int main(){
string s ; cin>>s ;
ll k= s.size() ;
ll now=0 ;
map<ll,ll> mp ;
mp[now]++ ;
ll keta=1 ;
rep(i,k){
  keta *= 10 ;
  keta %= 2019 ;
  
now+= keta*ll(s[k-1-i]-'0') ;
now %=2019 ;
mp[now]++ ;
}
ll ans= 0 ;
for( auto u : mp){
   ans+= u.se*(u.se-1) ;
}
 cout<<ans/2<<endl ;
   return 0 ;
}



Measured memory_bytes: 3736
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,D,X,A[1001];
	int ans=0;
	scan(N>>D>>X);
	rep(i,N){
		scan(A[i]);
		ans+=D/A[i]+(D%A[i]!=0);
	}
	prin(ans+X);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<vector<int>> g(n);
    rep(i,n-1) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<bool> seen(n,false);
    queue<int> q;
    mint ans = k;
    seen[0] = true;
    int i = 0;
    for(int next: g[0]) {
        q.push(next);
        ans*= k-1-i;
        i++;
    }
    while(!q.empty()) {
        int now = q.front();
        q.pop();
        seen[now] = true;
        i = 0;
        for(int next: g[now]) {
            if(seen[next] == true) continue;
            q.push(next);
            ans*=k-2-i;
            i++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6520
#include <iostream>
#include <vector>

typedef long long ll;

int main(){
   std::string S;
   std::cin >> S;

   int N = S.size();
   std::vector<ll> index;
   for(int i=0; i<N-1; ++i){
      if(S[i]=='R' && S[i+1]=='L') index.push_back(i);
   }
   std::vector<ll> ans(N);
   ll k = 0;
   for(ll i=0; i<N; ++i){
      //if(k<N-1 && i==index[k+1]) ++k;
      if(index[k]<i && S[i]=='R') ++k;
      ll dx = index[k] - i;
      if(dx<0) dx = -dx;
      if(dx%2==0){
	 ans[index[k]]++;
      }else{
	 ans[index[k]+1]++;
      }	
   }
   for(int i=0; i<N; ++i)
      std::cout << ans[i] << ' ';
   std::cout << std::endl;
   return 0;

}


Measured memory_bytes: 1912
ab = [list(map(int,input().split())) for i in range(3)]
num = [0,0,0,0]
for i in range(3):
    num[ab[i][0]-1]+=1
    num[ab[i][1]-1]+=1
if max(num) == 2 and min(num) == 1:
    print("YES")
else:
    print("NO")

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

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

  if(s.at(0)!=s.at(1) && s.at(1)!=s.at(2) && s.at(2)!=s.at(0)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main() {
	int t[2];
	ll a[2], b[2];
	rep(i,2) cin >> t[i];
	rep(i,2) cin >> a[i];
	rep(i,2) cin >> b[i];
	
	ll da = t[0]*a[0] + t[1]*a[1];
	ll db = t[0]*b[0] + t[1]*b[1];
	// inf loop の条件
	if(da == db){
	    puts("infinity");
	    return;
	}
	
	if(da < db){
	    swap(a, b);
	    swap(da, db);
	}
	
	if(a[0] > b[0]){
	    cout << 0 << endl;
	    return;
	}
	
	ll dx = da - db;
	/*
	k セット目前半
	da = t[0]*a[0] + k * dx;
	db = t[0]*b[0];
	db >= da なら cnt++;
	t[0]*b[0] >= t[0]*a[0] + k * dx
	k * dx <= t[0](b[0]-a[0])
	*/
    ll cnt = t[0]*(b[0]-a[0])/dx;
    cnt = cnt*2 + 1;
    if(t[0]*(b[0]-a[0]) % dx == 0) cnt--;
    cout << cnt << endl;
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N, M;
  int ans = 0;

  cin >> N >> M;

  vector<int> k(M);
  vector<int> p(M);
  vector<vector<int>> s(M, vector<int>(N));
  for(int i = 0; i < M; i++){
    cin >> k[i];
    for(int j = 0; j < k[i]; j++){
      cin >> s[i][j];
    }
  }
  for(int i = 0; i < M; i++){
    cin >> p[i];
  }
  int cnt = 0;

  // {0, 1, ..., n-1} の部分集合の全探索
  for (int bit = 0; bit < (1<<N); ++bit) {
    vector<int> ss(M);//各電球に対して, onになっているスイッチ数
    // cout << "bit: " << bit << endl;

    vector<int> s_on(1);//onになっているスイッチ番号?
    int tm = 0;
    for (int i = 0; i < N; ++i) {
      if (bit & (1<<i)) { // i が bit に入るかどうか
        //onになっているスイッチを記録
        if(tm==0){
          s_on[0] = (i+1);
        }else{
          s_on.push_back((i+1)); 
        }
        // cout << "  push: "<< i+1 << ">> " << s_on[tm] << ": in size=" << s_on.size()<< endl;
        tm++;
      }
    }
    // cout << "  s_on:  ";
    // for (int i = 0; i < s_on.size(); ++i) {
    //   cout << s_on[i] << " ";
    // }
    // cout << endl;

    //各電球に対応するスイッチの内、ONのものカウント
    for(int i_k = 0; i_k < M; ++i_k){
      int tmp = 0;
      int tmpsize = s_on.size();
      for(int i_s = 0; i_s < k[i_k]; ++i_s){
        for(int tmp = 0; tmp < tmpsize; ++tmp){
          if(s[i_k][i_s] == s_on[tmp]){
            ss[i_k]++;
          }
        }
      }
    }

    int tmpcnt=0;
    for(int i_ = 0; i_ < M; ++i_){
      //ssの各結果を2で割り, pと比較
      // cout << "  " << i_ << "th ss: " << ss[i_] << endl;
      if(ss[i_]%2 == p[i_]){
        tmpcnt++;
      }
    }
    if(tmpcnt == M){
      //全部ついてる場合カウント
      cnt++;
      // cout << "  all ON" << endl;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	string s;
	cin>>s;
	cout<<count(s.begin(),s.end(),'1')<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
edgecolor=[0]*(n-1)
nodecolorset=[set() for i in range(n)]
G=[[]*n for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1;b-=1
    G[a].append((b,i))
    G[b].append((a,i))

def dfs(node,color):
    i=1
    for gi,edgenum in G[node]:
        if edgecolor[edgenum]:continue
        if i!=color:
            edgecolor[edgenum]=i
        else:
            i+=1
            edgecolor[edgenum]=i
        dfs(gi,i)
        i+=1
# print(G)
# edgecolor[0]=1
dfs(0,0)
print(max(edgecolor))
for ci in edgecolor:
    print(ci)
        
    


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

ll d[2000][2000];

int fcn(int x1, int y1, int x2, int y2){
    if(x1==0 && y1==0) return d[x2][y2];
    if(x1>0 && y1==0) return d[x2][y2]-d[x1-1][y2];
    if(x1==0 && y1>0) return d[x2][y2]-d[x2][y1-1];
    return d[x2][y2]-d[x2][y1-1]-d[x1-1][y2]+d[x1-1][y1-1];
}

int main(){
    int n, k;
    cin >> n >> k;
    ll x[n], y[n];
    for(int i=0; i<n; i++){
        char c;
        cin >> x[i] >> y[i] >> c;
        if(c=='W') x[i]+=k;
        x[i]%=2*k;
        y[i]%=2*k;
    }

    for(int i=0; i<n; i++){
        d[x[i]][y[i]]++;
    }
    for(int i=0; i<2*k; i++){
        for(int j=1; j<2*k; j++){
            d[i][j]+=d[i][j-1];
        }
    }
    for(int j=0; j<2*k; j++){
        for(int i=1; i<2*k; i++){
            d[i][j]+=d[i-1][j];
        }
    }

    int ans=0;
    for(int i=0; i<=k; i++){
        for(int j=0; j<=k; j++){
            int s=fcn(i, j, i+k-1, j+k-1);
            if(i<k && j<k) s+=fcn(i+k, j+k, 2*k-1, 2*k-1);
            if(i>0 && j>0) s+=fcn(0, 0 , i-1, j-1);
            if(i>0 && j<k) s+=fcn(0, j+k, i-1, 2*k-1);
            if(i<k && j>0) s+=fcn(i+k, 0, 2*k-1, j-1);
            s=max(s, n-s);
            ans=max(ans, s);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 33024
#include <iostream>
#include <iomanip>
#include <tuple>
#include <list>
#include <iterator>
#define _USE_MATH_DEFINES
#include <cmath>

using point_t = std::tuple<double, double>;
using pointList = std::list<point_t>;
using pointItr = pointList::iterator;

template <typename T>
class Vector {

public:
   Vector(T x = T{}, T y = T{}) {
      vector = std::tie(x, y);
   }

   Vector(point_t to, point_t from = point_t{}) :
      Vector(std::get<0>(to) - std::get<0>(from),
            std::get<1>(to) - std::get<1>(from)) {
   }

   T getRadius() {
      return hypot(std::get<0>(vector), std::get<0>(vector));
   }

   void setRadius(T radius) {
      auto power = getRadius();

      std::get<0>(vector) *= radius / power;
      std::get<1>(vector) *= radius / power;
   }

   static Vector<T> rotate(Vector<T> base, double angle) {
      auto x = std::get<0>(base.vector) * std::cos(angle) - std::get<1>(base.vector) * std::sin(angle);
      auto y = std::get<1>(base.vector) * std::cos(angle) + std::get<0>(base.vector) * std::sin(angle);

      return { x, y };
   }

   point_t getTarget(point_t from) {
      auto x = std::get<0>(from) + std::get<0>(vector);
      auto y = std::get<1>(from) + std::get<1>(vector);

      return std::make_tuple(x, y);
   }

private:
   std::tuple<T, T> vector;

};

point_t operator +(point_t from, Vector<double> direction) {
   return direction.getTarget(from);
}

point_t operator +(Vector<double> direction, point_t from) {
   return from + direction;
}

void _getKochCurve(pointList & list, pointItr begin, pointItr end, int count) {
   if (count <= 0)  { return; }

   auto start = begin;
   auto next = std::next(start);
   while (start != end) {
      auto s_to_t = Vector<double>{ *next, *start };
      s_to_t.setRadius(s_to_t.getRadius() / 3);
      auto s = *start + s_to_t;
      auto t = s + s_to_t;

      auto s_to_u = Vector<double>::rotate(s_to_t, M_PI / 3);
      auto u = s + s_to_u;

      list.insert(next, { s, u, t });

      start = next;
      ++next;
   }

   return _getKochCurve(list, begin, end, count - 1);
}

pointList getKochCurve(point_t begin, point_t end, int count) {
   pointList list = { begin, end };
   _getKochCurve(list, list.begin(), std::next(list.begin()), count);

   return list;
}

int main() {

   int n;
   std::cin >> n;
   auto list = getKochCurve(point_t{ 0, 0 }, point_t{ 100, 0 }, n);

   for (auto && point : list) {
      std::cout << std::fixed << std::setprecision(8) << std::get<0>(point) << " " << std::get<1>(point) << std::endl;
   }

   return 0;

}

Measured memory_bytes: 3372
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int ss(int N,string S){
  int x=1;
  for(int i=0;i<N;i++){
    if(S[i]!=S[i+N]){
      x*=0;
      break;
    }
  }
  return x;}

int main(){
  int N;
  string S;
  cin>>S;
  N=S.size()/2;
  for(int i=N-1;i>=0;i--){
    if(ss(i,S)==1){
      cout<<i*2;
      break;
    }
  }
return 0;}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
int main()
{
    ll n,k;
    in(n);in(k);
    n%=k;
    n=min(n,abs(n-k));
    out(n);endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n; cin>>n;
    set<ll> s;
    rep(i,n){
        ll d; cin>>d;
        s.insert(d);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
int ctoi(char c){
  if(c>='0'&&c<='9'){
    return c-'0';
  }
  return 0;
}


//cout << setprecision(123)<<ans;
//int a=atoi(S.c_str());
//string S=to_string(a);
//int &a=b;
int main(){
  ll N,ans=1LL,a;
  bool ok=false;
  vector<ll>W(3,0);
  cin>>N;
  vector<ll>V(N);
  REP(i,N)cin>>V[i];
  
  if(V[0]!=0)ans=0;
  for(int i=1;i<N;i++){
    if(V[i]!=0&&V[i]!=V[i-1]+1&&ok==false)ans==0;
    if(V[i]==0&&ok==false){
      ok=true;
      a=i;
      W[0]=a;
      W[1]=1;
      continue;
    }
    if(ok){
      if(V[i]==W[0]){
        W[0]++;
        if(V[i]==W[1]){
          if(V[i]==W[2]){
            ans*=3;
          }
          else{
            ans*=2;
          }
        }
        else if(V[i]==W[2]){
          ans*=2;
        }
      }
      else if(V[i]==W[1]){
        W[1]++;
        if(V[i]==W[2]){
          ans*=2;
        }
      }
      else if(V[i]==W[2]){
        W[2]++;
      }
      else ans=0;
      ans%=mod;
    }
  }
  if(ok){
    ans%=mod;
  ans*=3;
  ans%=mod;
  ans*=2;
  ans%=mod;
  cout<<ans<<endl;
  }
  else{
    ans*=3;
    ans%=mod;
    cout<<ans<<endl;
  }
  
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>

using namespace std;

typedef unsigned long long ull ;
ull X, Y ;

int main(void){
  cin >> X >> Y ;
  int cnt = 0;
  ull  a = X ;

  while(a <= Y){
    cnt++ ;
    a *= 2 ;
  }

  cout << cnt << endl;

  return 0;





}

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

int main(){
	string str;
	int count = 0;
	while(cin >> str){
		int tmp = 0;
		for(int i = 0; i <= (int)str.size(); i++){
			if('0' <= str[i] && str[i] <= '9'){
				tmp = tmp * 10 + str[i] - '0';
			}else{
				count += tmp;
				tmp = 0;
			}
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3196
from bisect import bisect_right
N = int(input())
A = []
for i in range(N):
    A.append(-int(input()))
INF = float('inf')
D = [INF] * N
for i in range(len(A)):
    D[bisect_right(D, A[i])] = A[i]

print(N - D.count(INF))

Measured memory_bytes: 55512
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int n = Integer.parseInt(s[0]);
		int w = Integer.parseInt(s[1]);
		int[][] items = new int[n+1][2];
		for (int i = 1; i < n+1; i++) {
			s = br.readLine().split(" ");
			items[i][0] = Integer.parseInt(s[0]);
			items[i][1] = Integer.parseInt(s[1]);
		}

		long[][] dp = new long[w + 1][n + 1];
		for (int i = 1; i < w + 1; i++) {
			for (int j = 1; j < n + 1; j++) {
				if (items[j][0] <= i)
					dp[i][j] = Math.max(dp[i][j-1], items[j][1] + dp[i - items[j][0]][j - 1]);
				else 
					dp[i][j] = dp[i][j-1];
			}
		}
		
//		for (int i = 0; i < n + 1; i++) {
//			for (int j = 0; j < w + 1; j++) {
//				System.out.print(dp[j][i] + " ");
//			}
//			System.out.println();
//		}

		System.out.println(dp[w][n]);
	}

}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}


int main() {
int a,b;
cin>>a>>b;
cout<<6-a-b<<endl;
return 0;
}


Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}

int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	ll a=read(),b=read(),c=read();
	printf("%lld",min(a+b+1,c)+b);
	return 0;
}

Measured memory_bytes: 3140
# 2019/07/02

n,m=map(int,input().split())

ab=[]
for i in range(m):
    ab.append(tuple(map(int,input().split())))

ab.sort(key=lambda x: x[1])

pre=0
cnt=0
for i in range(m):
    if pre<=ab[i][0]:
        pre=ab[i][1]
        cnt+=1
    else:
        pre=min(pre,ab[i][1])
print(cnt)

Measured memory_bytes: 18240
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let mut a = vec![vec![0; 10]; 10];
    for i in 1..10 {
        for j in 1..10 {
            a[i][j] = calc(i, j, n);
        }
    }

    let mut ans = 0;
    for i in 1..10 {
        for j in 1..10 {
            ans += a[i][j] * a[j][i];
        }
    }
    println!("{}", ans);
}

fn calc(a: usize, b: usize, n: usize) -> usize {
    let mut count = 0;
    for i in 1..(n + 1) {
        let len = i.to_string().len();
        let msd = i / 10usize.pow(len as u32 - 1);
        let lsd = i % 10;

        if msd == a && lsd == b {
            count += 1;
        }
    }

    count
}


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

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

string rot1( string s ){
	string res = s;
	res[0] = s[1];
	res[1] = s[5];
	res[5] = s[4];
	res[4] = s[0];
	return res;
}

string rot2( string s ){
	string res = s;
	res[0] = s[2];
	res[2] = s[5];
	res[5] = s[3];
	res[3] = s[0];
	return res;
}

string rot3( string s ){
	string res = s;
	res[1] = s[2];
	res[2] = s[4];
	res[4] = s[3];
	res[3] = s[1];
	return res;
}

int main(){
	int n;
	while( cin >> n, n ){
		string obj[30];
		rep(i,n){
			rep(j,6){
				string in;
				cin >> in;
				obj[i] += in[0];
			}
		}
		int cnt = 0;
		rep(i,n){
			if( obj[i] == "" ) continue;
			for(int j=i+1; j<n; j++){
				if( obj[j] == "" ) continue;
				bool found = false;
				rep(k,6){
					rep(l,4){
						if( obj[i] == obj[j] ){
							found = true;
						}
						obj[j] = rot3(obj[j]);
					}
					if(k%2)	obj[j] = rot1(obj[j]);
					else	obj[j] = rot2(obj[j]);
				}
				if(found){
					cnt++;
					obj[j] = "";
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  set<pair<ll, ll>> st;
  ll n;
  cin >> n;
  for(ll i = 1; i < n; i++){
     if(i == n-i) continue;
     st.insert(mp(max(i, n-i), min(i, n-i)));
  }
  cout << st.size() << endl;
  return 0;

} //good night.

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

int color[100010];

struct edge {
    int v,w;
};
vector<edge> es[100010];

void dfs(int u, int c) {
    color[u] = c;
    for (int i=0; i<es[u].size(); i++) {
        int v = es[u][i].v;
        int w = es[u][i].w;
        if (color[v] != -1) continue;
        if (w % 2) {
            dfs(v, c^1);
        } else {
            dfs(v, c);
        }
    }
}

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

    for (int i=0; i<N-1; i++) {
        int u,v,w; cin >> u >> v >> w;
        edge e1 = {v,w};
        edge e2 = {u,w};
        es[u].push_back(e1);
        es[v].push_back(e2);
    }

    // init
    for (int i=0; i<100010; i++) color[i] = -1;

    dfs(1, 0);

    for (int i=1; i<=N; i++) {
        cout << color[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,x;
  cin >> n >> x;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  vec b(n,inf);
  ll ans=inf;
  for(ll i=0;i<n;i++) {
    ll tans=0;
    for(ll j=0;j<n;j++) {
      b[j]=min(b[j],a[(j-i+n)%n]);
      tans+=b[j];
    }
    tans+=i*x;
    ans=min(ans,tans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val H, W = sc.nextInt
    val A = Array.fill(10)(Array.fill(10)(sc.nextInt))
    for (k <- 0 until 10) {
      for (i <- 0 until 10) {
        for (j <- 0 until 10) {
          A(i)(j) = math.min(A(i)(j), A(i)(k) + A(k)(j))
        }
      }
    }
    for (k <- 0 until 10) {
      for (i <- 0 until 10) {
        for (j <- 0 until 10) {
          A(i)(j) = math.min(A(i)(j), A(i)(k) + A(k)(j))
        }
      }
    }
    val B = Array.fill(H * W)(sc.nextInt).filter(a => a != -1)
    var ans = 0
    for (i <- 0 until 10) {
      ans += B.count(a => a == i) * A(i)(1)
    }
    println(ans)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 44540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=10000020;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	#ifdef LOCAL
		freopen("E.txt","r",stdin);
	#endif
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
const int maxn=100002;
int fa[maxn];
ll sum[maxn];
int sz[maxn];
int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
struct edge{
	int u,v,w;
	bool operator <(const edge& rhs)const{
		return w<rhs.w;
	}
}e[maxn];
int main(){
	init();
	int n=readint(),m=readint();
	for(int i=1;i<=n;i++)
		fa[i]=i,sum[i]=readint();
	for(int i=1;i<=m;i++)
		e[i].u=readint(),e[i].v=readint(),e[i].w=readint();
	stable_sort(e+1,e+m+1);
	int ans=0;
	for(int i=1;i<=m;i++){
		int u=e[i].u,v=e[i].v,w=e[i].w;
		u=getf(u),v=getf(v);
		if (u!=v)
			fa[u]=v,sz[v]+=sz[u],sum[v]+=sum[u];
		sz[v]++;
		if (w<=sum[v])
			ans+=sz[v],sz[v]=0;
	}
	printf("%d",m-ans);
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
//using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
using pii=pair<ll,ll>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(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 fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
#define dcl(...) int __VA_ARGS__;get(__VA_ARGS__);


int main(){
    dcl(k,t);
    vi c(t);
    rep(i,t)cin>>c[i];
    sort(rall(c));
    cout<<max(c[0]*2-k-1,0)<<endl;
}


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

mod = 10 ** 9 + 7

yama = [0] * n

# tは、t[i] == t[i + 1]だったら左の以外全部ありうる
yama[0] = t[0]
if t[0] > a[0]:
    print(0)
    exit()
for i in range(n - 1):
    if t[i] < t[i + 1]:
        # i + 1の高さ確定
        yama[i + 1] = t[i + 1]
        if t[i + 1] > a[i + 1]:
            print(0)
            exit()
for i in range(n - 1, 0, -1):
    if a[i - 1] > a[i]:
        yama[i - 1] = a[i - 1]
        if a[i - 1] > t[i - 1]:
            print(0)
            exit()
if a[n - 1] > t[n - 1]:
    print(0)
    exit()
yama[n - 1] = a[n - 1]

ans = 1
for i in range(1, n - 1):
    if yama[i] == 0:
        ans = (ans * min(a[i], t[i])) % mod
print(ans)


Measured memory_bytes: 24604
#include<stdio.h>

int main(void){
	char str[2000];
	int cut_i;
	gets(str);

	for(cut_i=0;str[cut_i];cut_i++){
		str[cut_i]-=3;
		if(str[cut_i]<'A'){
			str[cut_i]+=26;
		}
	}
	puts(str);
	return 0;
}

Measured memory_bytes: 920
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

//WA

int main(void){
	ll N,xs,ys,xt,yt,x[1010],y[1010],r[1010];
	double d[1010],dist[1010][1010];
	scanf("%lld%lld%lld%lld",&xs,&ys,&xt,&yt);
	scanf("%lld",&N);
	reg(i,1,N)scanf("%lld%lld%lld",&x[i],&y[i],&r[i]);
	x[0]=xs; y[0]=ys; r[0]=0;
	x[N+1]=xt; y[N+1]=yt; r[N+1]=0;
	rep(i,N+2){
		reg(j,0,i){
			double c=0,l=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
			if(l-r[i]-r[j]>0)c=l-r[i]-r[j];
			dist[i][j]=c;
			dist[j][i]=c;
		}
	}
	rep(i,N+2)d[i]=1e16;
	queue<ll> Q;
	d[0]=0;
	Q.push(0);
	while(!Q.empty()){
		ll p = Q.front();Q.pop();
		rep(i,N+2){
			if(d[i]>d[p]+dist[i][p]){
				d[i]=d[p]+dist[i][p];
				Q.push(i);
			}
		}
	}
	cout.precision(15);
	cout<<d[N+1]<<endl;
	return 0;
}

Measured memory_bytes: 10240
using System;
 
class program
{
    public static void Main()
    {
        while (true)
        {
            char[] str = Console.ReadLine().ToCharArray();
            int sum = 0;
 
            if (str[0] == '0') break;
 
            for (int i = 0; i < str.Length; i++)
            {
                sum += int.Parse(str[i].ToString());
            }
            Console.WriteLine(sum);
        }
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int x, y, z;
int main() {
    cin >> x >> y >> z;
    int ans = (x - z) / (y + z);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
N,M=map(int,input().split())
H=[0]+list(map(int,input().split()))
G=[[] for index1 in range(N+1)]
for index1 in range(M):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)

ans=0
for i in range(1,N+1):
    temp=1
    for j in G[i]:
        if H[j]>=H[i]:
            temp=0
            break
    ans+=temp

print(ans)



    

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

void fnInput(vector<int>& rvnMonstr, vector<int>& rvnBrave)
{
  int nMonstrSiz;
  cin >> nMonstrSiz;
  rvnMonstr.resize(nMonstrSiz + 1);
  rvnBrave.resize(nMonstrSiz);

  for (int& rnMonstr : rvnMonstr)
    cin >> rnMonstr;

  for (int& rnBrave : rvnBrave)
    cin >> rnBrave;
}
  
llong fnStrikMonstr(vector<int>& rvnMonstr, vector<int>& rvnBrave)
{
  llong nSumStrikMon = 0;

  for (int nBgn = 0; nBgn < rvnBrave.size(); ++nBgn)
    for (int nFwd = nBgn; nFwd < nBgn + 2; ++nFwd)
    {
      int nStrikMonstr = min(rvnBrave[nBgn], rvnMonstr[nFwd]);

      rvnMonstr[nFwd] -= nStrikMonstr;
      rvnBrave[nBgn]  -= nStrikMonstr;
      nSumStrikMon += nStrikMonstr;
    }

  return nSumStrikMon;
}
  
int main()
{
  vector<int> vnMonstr, vnBrave;

  fnInput(vnMonstr, vnBrave);
  cout << fnStrikMonstr(vnMonstr, vnBrave) << endl;

  return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	ll A, B;
	cin >> A >> B;

	if ((A + B) % 2 == 0) { cout << (A + B) / 2; }
	else { cout << "IMPOSSIBLE"; }

	system("PAUSE");
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
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; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    map<string, ll> count;
    ll N;
    cin >> N;
    vector<string> S(N);
    rep(i,N){
        cin >> S[i];
        count[S[i]]++;
    }
    cout << "AC" << " " << "x" << " " << count["AC"] << endl;
    cout << "WA" << " " << "x" << " " << count["WA"] << endl;
    cout << "TLE" << " " << "x" << " " << count["TLE"] << endl;
    cout << "RE" << " " << "x" << " " << count["RE"] << endl;
}

Measured memory_bytes: 6312
import java.util.Scanner;


public class Main {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		int width= scanner.nextInt();
		int height = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int r = scanner.nextInt();
		
		String ans = "Yes";
		if(x+r > width || x-r < 0 || y+r > height || y-r < 0)
			ans="No";
		
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 17324
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    int A = sc.nextInt();
    int B = sc.nextInt();
    String U = sc.next();
    if (U.equals(S)) A--;
    if (U.equals(T)) B--;
    System.out.print(A + " " + B);
  }
}

Measured memory_bytes: 22868
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        double h = sc.nextInt();
        double m = sc.nextInt();
        double theta = (h * 60 + m) / 720 - m / 60;
        theta *= Math.PI * 2;
        System.out.println(Math.sqrt(- Math.cos(theta) * 2 * a * b + a * a + b * b));
    }
}

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

using namespace std;

int main() {
  long long n, a = 1;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    a = i * a % 1000000007;
  }
  printf("%lld\n", a);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
int main(){
    ll k,i,ans=0;
    cin>>k;
    for(i=1;i<1000001;i++){
        ans=ans*10+7;
        ans=ans%k;
        if(ans==0) {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1";
    
    }

Measured memory_bytes: 3624
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[])=>{for(let i=0;i<a.length;i+=2)if(s==a[i])return a[i+1]};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};
const main = ()=>{
  let [a,b]=nrin(2);
  out(a-(b-1));
}
main();

Measured memory_bytes: 7372