akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=300+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
}




































typedef pair<int,int>pii;
#define mk make_pair
#define fir first
#define sec second
#define pb push_back
vector<pii>q[N];
int n,m;
void input()
{
	int l,r,x;
	n=read<int>(),m=read<int>();
	For(i,1,m)
	{
		l=read<int>(),r=read<int>(),x=read<int>();
		q[r].pb(mk(l,x));
	}
}
const int mo=1e9+7;
int dp[N][N][N];
void add(int &x,int y)
{
	x+=y;x-=(x>=mo?mo:0);
}
void work()
{
	int now,num,flag;
	dp[0][0][0]=1;
	int ans=0;
	For(i,0,n)For(j,0,n)For(k,0,n)if(dp[i][j][k])
	{
		
		now=max(i,max(j,k));
		flag=1;
		for(pii t:q[now])
		{
			num=0;
			num=(i>=t.fir)+(j>=t.fir)+(k>=t.fir);
			if(num!=t.sec)flag=0;
		}
		if(flag==0)dp[i][j][k]=0;
		else
		{
			add(dp[now+1][j][k],dp[i][j][k]);
			add(dp[i][now+1][k],dp[i][j][k]);
			add(dp[i][j][now+1],dp[i][j][k]);
		}
		if(now==n)add(ans,dp[i][j][k]);
	}
	write(ans,'\n');
}
int main()
{
	//file();
	input();
	work();
	return 0;
}

Measured memory_bytes: 110848
import sys
f = sys.stdin


def take2(iterable):
    i = iter(iterable)
    while True:
        yield next(i) + next(i) * 1j
def cross(ab, cd):
    return ab.real * cd.imag - ab.imag * cd.real

n = int(f.readline())
for _ in range(n):
    a, b, c, d = [xiyi for xiyi in take2(map(float, f.readline().split()))]
    print('YES' if abs(cross(a - b, c - d)) < 1e-10 else 'NO')

Measured memory_bytes: 6756
using System;
    public class Test
    {
        static void Main(string[] args)
        {
            double money = 100000;
            int answer = 0;
            int n =  int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < n; i++)
            {
                answer = (int)Math.Ceiling(money*1.05 / 1000) * 1000;
                money = answer;
            }
            Console.WriteLine(money);
        }
    }


Measured memory_bytes: 13872
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> B(N - 1);
	for (int i = 0; i < N-1; i++)cin >> B[i];

	ll ans = 0;
	for (int i = 0; i <= N-1; i++) {
		if (i == 0) ans += B[0];
		if (i == N - 1) ans += B[N - 2];
		else ans += min(B[i - 1], B[i]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

const ll MAX_V = 50;
const ll MAX_S = MAX_V*50;
 
int main() {
    ll n, m, S;
    cin >> n >> m >> S;  
    chmin(S, MAX_S);  
    
    vector<vector<pair<ll, P>>> G(n);  // 辺の重みがすべて0以上のグラフ
    rep(i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;  v--;
        G[u].pb(make_pair(v, make_pair(a, b)));
        G[v].pb(make_pair(u, make_pair(a, b)));
    }

    vl c(n), d(n);
    rep(i, n) {
        cin >> c[i] >> d[i];
    }
    
    // 拡張ダイクストラ法。計算量はO((V+E)*log(V))
    vvl dp(MAX_V, vl(MAX_S+10, INF));  // dp[v][i] : 頂点vに所持金i円でいる状態になるのにかかる時間の最小値
    const ll sv = 0;  // 始点となる頂点
    dp[sv][S] = 0;
    priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> prQ;
    prQ.push(make_pair(dp[sv][S], make_pair(sv, S)));  // (頂点vまでの所持金がiのときの時間t, (いまいる頂点v, 所持金i))
    while(!prQ.empty()) {
        auto p1 = prQ.top();
        prQ.pop();
        ll t = p1.first;  // 頂点vまでの所持金がiのときの時間t
        ll v = p1.second.first;  // いまいる頂点v
        ll i = p1.second.second;  // 所持金i
        if(dp[v][i] < t) {
            continue;
        }
        ll ni = min(MAX_S, i + c[v]);
        if(dp[v][ni] > dp[v][i] + d[v]) {
            dp[v][ni] = dp[v][i] + d[v];
            prQ.push(make_pair(dp[v][ni], make_pair(v, ni)));
        }
        for(auto p2 : G[v]) {
            ll u = p2.first;
            ll a = p2.second.first;
            ll b = p2.second.second;
            if(i < a) {
                continue;
            }
            if(dp[u][i-a] > dp[v][i] + b) {
                dp[u][i-a] = dp[v][i] + b;
                prQ.push(make_pair(dp[u][i-a], make_pair(u, i-a)));
            }
        }
    }

    vl ans(n, INF);
    exrep(i, 1, n-1) {
        rep(j, MAX_S+10) {
            chmin(ans[i], dp[i][j]);
        }
    }

    exrep(i, 1, n-1) {
        out(ans[i]);
    }
    
    re0;
}

Measured memory_bytes: 7368
s = input()

flag = 0
while(1):
  if len(s) == 0:
    flag = 1
    break
  elif s[-7:] == "dreamer":
    s = s[0:-7]
  elif s[-6:] == "eraser":
    s = s[0:-6]
  elif s[-5:] == "dream":
    s = s[0:-5]
  elif s[-5:] == "erase":
    s = s[0:-5]
  else:
    break

if flag == 1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int A,B,C;

signed main(void) {
    cin>>A>>B>>C;
    if (A==B&&B==C) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<char, char>P;
long long GCD(long long A, long long B) {
	if (B == 0) return A;
	else return GCD(B, A % B);
}
int main() {
	long long N, M; cin >> N >> M;
	long long ans = (N * M) / GCD(N, M);
	map<long long, char>A;
	string S; cin >> S;
	for (long long i = 0; i < N; i++) {
		A[(i * (ans / N)) + 1] = S.at(i);
	}
	string T; cin >> T;
	for (long long i = 0; i < M; i++) {
		if (A[i * (ans / M) + 1] >= 97 && A[i * (ans / M) + 1] <= 123 && A[i * (ans / M) + 1] != T.at(i)) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 14164
import numpy as np

d = int(input())
c = list(map(int, input().split()))
c_sum = sum(c)
s = [[] for _ in range(d)]
for i in range(d):
  s[i] = list(map(int, input().split()))
  
last = [0 for _ in range(26)]
plan = [-1 for _ in range(d)]

def loss(today):
  sum = 0
  for i in range(26):
    sum += c[i-1] * (today - last[i-1])
  return sum
  
  
v = 0
for today in range(1, d+1):
  t = np.argmax([s[today-1][i] + c[i]*(today - last[i]) for i in range(26)])
  t += 1
  last[t-1] = today
  plan[today-1] = t
  print(t)

Measured memory_bytes: 27624
import  numpy as np
D = int(input())
c = np.array(list(map(int, input().split())))
s = [list(map(int, input().split())) for _ in range(D)]
last_d = [0]*len(c)

ans = 0
for i in range(D):
  max_s = max(s[i])
  max_s_index = np.argmax(s[i])
  max_c = max(c)
  max_c_index = np.argmax(c)
  if max_s >= max_c:
    print(max_s_index+1)
    ans += max_s
    cc = c*(i+1)
    cc[max_s_index] = c[max_s_index]
    for j in cc:
      ans -= cc
  else:
    print(max_c_index + 1)
    ans += s[i][max_c_index]
    cc = c*(i+1)
    cc[max_c_index] = c[max_c_index]
    for j in cc:
      ans -= cc


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

int main(void)
{
	int H,W,h,w;

	while(1)
	{

	     scanf("%d %d",&H,&W);

	     if((H == 0)&&(W == 0))
		 {
	         break;
		 }

		 for(h=0; h<H; h++)
		 {
			 for(w=0; w<W; w++)
			 {
				 if(( h == 0 )||( h == H-1 )||( w == 0)||( w == W-1 ))
				 {
					 printf("#");
				 }
				 else
				 {
					 printf(".");
				 }
				 
			 }
			 printf("\n");
		 }
		 printf("\n");
	
	}

	return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
int main() {
	int n, t, a, b, c;
	a = b = c = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &t);
		if (t % 4 == 0) a++;
		else if (t % 2 == 0) b++;
		else c++;
	}
	if (b != 0) c++;
	if (a + 1 >= c) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#import<iostream>
#define I(x) i)%M*V(x,M-2,1)%M;F 
#define F for(i=0;i<=N;
long N,a[1<<17],m[1<<17],k[1<<17],b,d,i,A,r,M=1000000007;long V(long n,long A,long r){return A?A&1?V(n*n%M,A/2,r)*n%M:V(n*n%M,A/2,r):1;}main(){std::cin>>N;*m=*k=1;F++i)m[i+1]=m[i]*(N+1-I(i+1)a[b]=++i){std::cin>>b;a[b]?d=i-a[b]:0;}F++i)k[i+1]=k[i]*(N-d-1-I(i+1)std::cout<<(M-k[i]+m[++i])%M<<" ");}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int box[100005],las[200005],edv[200005],cnt=0;
void adde(int u,int v)
{
	las[++cnt]=box[u];
	box[u]=cnt;
	edv[cnt]=v;
}
int dep[100005],dfsin[100005],dfn=0;
int tot=0;
int pre[100005];
void dfs(int now,int fa)
{
	pre[now]=fa;
	dfsin[now]=++dfn;
	for(int i=box[now];i;i=las[i])
		if(edv[i]!=fa)
		{
			dep[edv[i]]=dep[now]+1;
			dfs(edv[i],now);
		}
}
int S,T;
int n;
int ans[100005];
int ans2[100005];
int deg[100005];
bool fg=0;
bool onl[100005];
void solve(int now,int fa)
{
	dfsin[now]=++dfn;
	if(!onl[now])
	{
		if(deg[now]>1)	fg=1;
		return;
	}
	if(now==T)
	{
		ans[tot++]=dfsin[now];
		return;
	}
	int s=0;
	for(int i=box[now];i;i=las[i])
		if(edv[i]!=fa)
		{
			int v=edv[i];
			if(!onl[v])
			{
				solve(v,now);
				ans[tot++]=dfsin[v];
			}
			else
				s=v;
		}
	ans[tot++]=dfsin[now];
	solve(s,now);
}
int main()
{
	read(n);
	int a,b;
	for(int i=1;i<n;i++)
	{
		read(a);
		read(b);
		deg[a]++;
		deg[b]++;
		adde(a,b);
		adde(b,a);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		if(dep[i]>dep[S])	S=i;
	dfn=0;
	dfs(S,0);
	for(int i=1;i<=n;i++)
		if(dep[i]>dep[T])	T=i;
	for(int i=T;i;i=pre[i])	onl[i]=1;
	dfn=tot=0;
	solve(S,0);
	if(fg)
	{
		printf("-1\n");
		return 0;
	}
	for(int i=0;i<n;i++)
		ans2[i]=ans[i];
	swap(S,T);
	tot=dfn=0;
	solve(S,0);
	for(int i=0;i<n;i++)
	{
		if(ans[i]<ans2[i])
		{
			for(int i=0;i<n;i++)
				printf("%d ",ans[i]);
			printf("\n");
			return 0;
		}
		else if(ans[i]>ans2[i])
		{
			for(int i=0;i<n;i++)
				printf("%d ",ans2[i]);
			printf("\n");
			return 0;
		}
	}
	for(int i=0;i<n;i++)
		printf("%d ",ans[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 9856
import java.io.InputStreamReader;
import java.io.LineNumberReader;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_B
 * 
 * @author eitatsuro
 * 
 */
public class Main {
    
    public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));

            String inputStr = null;
            long x = 0;
            int digit = 0;
            int output = 0;
            
            while ((inputStr = lineNumReader.readLine()) != null) {

                output = 0;
                for (int i = 0; i < inputStr.length(); i++) {
                    digit = Integer
                            .parseInt(String.valueOf(inputStr.charAt(i)));
                    output += digit;
                }

                // ????????????
                // ?????°????°?????????????????????????????????§???????????????????????¨?????°????????§???
                if (inputStr.length() == 1) {
                    x = Integer.parseInt(inputStr);
                    if (x == 0) {
                        // do nothing.
                        break;
                    }
                }

                // ??¢???????????????
                System.out.println(output);


            }

            lineNumReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
        
    }
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int gcd(int a,int b){return (a%b==0?b:gcd(b, a%b));}
int lcm(int a,int b){return a*b/gcd(a, b);}

int main()
{
  int64_t n, len_ans = 0;
  vector<char> ans;

  cin >> n;
  while (n != 0)
  {
    ans.push_back((char)('a' + ((n - 1) % 26)));
    n = (n - 1) / 26;
    len_ans++;
  }
  for (int i = 0; i < len_ans; i++)
    cout << ans[len_ans - 1 - i];
  cout << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main() {
	int n, d,i;
	scanf("%d", &n);
	scanf("%d", &d);
	for (i = 1;i <= n;i++) {
		if ((d * 2 + 1)*i >= n) {
			break;
		}
	}
	printf("%d", i);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)
 
using namespace std;
 
int main() {
  int N, M, a = 0, b = 100000;
  cin >> N >> M;
  int L[M], R[M];
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
    a = max(a, L[i]);
    b = min(b, R[i]);
  }
  b = min(b, N);
  cout << (b - a + 1) * (b - a >= 0) * (a - N <= 0) << endl;
}

Measured memory_bytes: 1024
k, n = [int(e) for e in input().split()]
a = [int(e) for e in input().split()]
b = []
sorted(a)
for i in range(len(a)-1):
    b.append(a[i+1]-a[i])
b.append(a[0]+k-a[-1])
print(k-max(b))

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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int N, K;
int cnt;
int ans;
string str;

int main(){
	cin>>N>>K;
	cin>>str;
	cnt = 1;
	for(int i=1; i<N; i++){
		if(str[i]==str[i-1]){
			ans++;
		}else{
			cnt++;
		}
	}
	while(K--){
		if(cnt==1){
			continue;
		}
		if(cnt==2){
			ans++;
			cnt = 1;
		}else{
			ans += 2;
			cnt -= 2;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int d[4]={10,13,16,19}, dd[2]={1,22};
int x[4][5]={ {7,8,9,10,13},
	      {1,2,3,15,19},
	      {1,4,7,10,16},
	      {3,6,9,12,13} };
int y[4][5]={ {22,23,24,12,18},
	      {28,29,30,16,21},
	      {24,27,30,21,18},
	      {22,25,28,19,15} };

int is_puzzle(vector<int> a)
{
  for(int i=0;i<4;i++){
    int e = d[i];
    if(a[e] != a[e+1] || a[e] != a[e+2] || a[e+1] != a[e+2])
      return 0;
  }
  for(int i=0;i<2;i++)
    for(int j=dd[i];j<dd[i]+9;j++)
      if(a[dd[i]] != a[j])
	return 0;
  return 1;
}

vector<int> mawasu(vector<int> a, int idx)
{
  for(int i=0;i<5;i++)
    swap(a[x[idx][i]], a[y[idx][i]]);
  return a;
}

int bfs(vector<int> a)
{
  queue<pair<vector<int>, int> >q;
  q.push(make_pair(a, 0));

  while(!q.empty()){
    vector<int>cur = q.front().first;
    int ret = q.front().second;
    q.pop();
    if(is_puzzle(cur))
      return ret;

    for(int i=0;i<4;i++){
      vector<int>tar = mawasu(cur, i);
      q.push(make_pair(tar, ret+1));
    }
  }
  return 0;
}

int main()
{
  vector<int>p(32);
  int n;
  scanf("%d", &n);
  while(n--){
    p[0] = p[31] = 0;
    for(int i=1;i<=30;i++)
      scanf("%d", &p[i]);

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

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

using namespace std;

int main() {
  int A, B; cin >> A >> B;
  int ans;
  if (A > B) {
    ans = A + (A-1);
  }
  else if (B > A) {
    ans = B + (B-1);
  }
  else {
    ans = A + B;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){

    int N, A, B;
    cin >> N >> A >> B;

    if((A + B > N + 1) or (A * B < N)){
        cout << -1 << endl;
        return 0;
    }

    typedef pair<int, int> pa;
    vector<pa> ans(N);

    int now = 0;
    rep(i, A){
        ans[now] = pa(now, i); now++;
    }

    int remaining = N - A - B + 1;
    rep(i, B - 1){
        ans[now] = pa(now, 0); now++;
        if(remaining < A - 1){
            rep(j, remaining){
                ans[now] = pa(now, j + 1); now++;
            }
            remaining = 0;
        } else {
            rep(j, A - 1){
                ans[now] = pa(now, j + 1); now++;
            }
            remaining -= A - 1;
        }
    }

    sort(all(ans), [](pa x, pa y){
        if(x.second == y.second)return x.first > y.first;
        else return x.second < y.second;
    });

    rep(i, N){
        if(i)cout << ' ';
        cout << ans[i].first + 1;
    }
    cout << endl;

}

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

int main(){
	int W, H;

	while (1){
		cin >> H >> W;

		if (W == 0 && H == 0)break;

		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				if (i == 0 || i == H - 1 || j == 0 || j == W - 1){
					cout << "#";
				}
				else{
					cout << ".";
				}
			}
			cout << "\n";
		}

		cout << endl;
	}

	return 0;
}

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

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

    long long C[10][10] = {};
    for (int i=1; i<=N; i++)
    {
        string s = to_string(i);
        C[s[0]-'0'][s[s.length()-1]-'0']++;
    }
    long long ans = 0;
    for (int i=0; i<10; i++)
        for (int j=0; j<10; j++)
            ans += C[i][j]*C[j][i];
    cout<<ans<<endl;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<vector>
using namespace std;
int main()
{
	int a,b,c;
    cin>>a>>b>>c;
    a-=c;
    cout<<a/(b+c);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
  void Solve()
  {
    var _ = Console.ReadLine().Split();
    var N=int.Parse(_[0]);
    var K = int.Parse(_[1]);

    double ret = 0;
    int ii = 1;
    for (int i=N;i>=1 ;i--)
    {
      for (;; )
      {
        if (i * ii >= K)
        { 
          ret += ((double)1 / ii);
          break;
        }
        ii *= 2;
      }
    }
    Console.WriteLine(ret/N);
  }

  static void Main(string[] args)
  {
    new Program().Solve();
  }
}



Measured memory_bytes: 13140
#include<stdio.h>

int main()
{
	int a , b , c , total , min , max ;
	scanf ("%d %d %d", & a , & b , &c);
	total = a + b + c ;
	if (a > b && a > c)
	{
	    max = a;
	}
	else if (b > a && b > c )
	{
		max = b;
	}
	else
	{
	    max = c;
    }
	if (a < b && a < c)
	{
	    min = a;
	}
	else if (b < a && b < c )
	{
		min = b;
	}
	else
	{
	    min = c;
    }
    printf("%d %d %d\n", min , total-max-min , max);
	return 0;
} 


Measured memory_bytes: 2064
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int d, g;
    cin >> d >> g;

    vector<int> p(d), c(d);
    for(int i = 0; i < d; i++) cin >> p[i] >> c[i];

    int ans = MAX;
    for(int i = 0; i < (1 << d); i++){
        int now = 0;
        int cnt = 0;
        vector<pii> tmp;
        for(int j = 0; j < d; j++){
            if(i & (1 << j)){
                cnt += p[j];
                now += p[j] * (j + 1) * 100 + c[j];
            }
            else tmp.eb(mp(j, p[j]));
        }
//        cerr << i << " " << now << " " << cnt << "\n";

        gsort(tmp);
        for(pii j : tmp){
            int t = iceil(max(0, g - now), (j.F + 1) * 100);
            t = min(t, j.S);
            now += (j.F + 1) * 100 * t;
            cnt += t;
        }

//        cerr << i << " " << now << " " << cnt << "\n";
        if(now >= g) ans = min(ans, cnt);
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int h, w;
	string c[110][110];
	cin >> h >> w;
	for(int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w;++j) {
			cin >> c[i][j];
		}
	}
	
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			cout << c[i][j] << endl << c[i][j] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
    #define all(a)      (a).begin(),(a).end()
    #define sz(x)       (int)x.size()
    
    #define ff first
    #define ss second
    #define mp make_pair
         
    #define pb push_back
    #define endl "\n"
         
    #define int long long 
    #define double long double
         
    #define bp __builtin_popcountll
    #define inf 1e16
    
    const int N=1e5+5; 
    const int M=1e6+6;
    const int MOD=1e9+7;
    void solve()
    {        
    	string s;
    	cin>>s;
    	if(s[2]==s[3] && s[4]==s[5])
    	cout<<"Yes"<<endl;
    	else
    	cout<<"No"<<endl;
    }

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


Measured memory_bytes: 256
def main():
    n = int(input())
    A = []
    tmp = []
    ans = 0
    for _ in range(n):
        a = int(input())
        if a != 0:
            tmp.append(a)
        else:
            A.append(tmp)
            tmp = []
    if tmp != []:
        A.append(tmp)
    for a in A:
        ans += sum(a) // 2
    print(ans)

if __name__ == '__main__':
    main()


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

class Main {

	void solve() {

		double t = in.nextDouble(), x = in.nextDouble();
		out.println(String.format("%.3f", t/x));
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        // ##### 初期読み込み #######################################################################
        // 1行 数字 1文字 ---------------------------------------------------------------------------
        long x = Long.parseLong(scanner.nextLine());

        // ##### メイン処理 #######################################################################

        long m = x % 500;
        long n = m % 5;

        long ureshisa = (x - m) / 500 * 1000 + (m - n) / 5 * 5;

        System.out.println(ureshisa);
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    if(A==0){
        cout<<0<<endl;
    }else{
        ll C=A+B;
        ll a=N/C;
        ll b=N%C;
        a*=A;
        if(b<=A){
            a+=b;
        }else{
            a+=A;
        }
        cout<<a<<endl;
    }

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct segtree{
	static const int N=1<<19;
	int dp[1<<20];

	void update(int k,int v){
		k+=N-1;
		dp[k]+=v;
		while(k>0){
			k=(k-1)/2;
			dp[k]=dp[k*2+1]+dp[k*2+2];
		}
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		if(r<=a || b<=l)return 0;
		if(a<=l && r<=b)return dp[k];
		int vl=query(a,b,k*2+1,l,(l+r)/2);
		int vr=query(a,b,k*2+2,(l+r)/2,r);
		return vl+vr;
	}
};

segtree seg;

int n;
string str;
int cnt[28];
ll ans=0;
int ct=0;
deque<int> deq[30];

void del(int v){
	int vi=deq[v][0];
	seg.update(vi,-1);
	vi=deq[v][deq[v].size()-1];
	seg.update(vi,-1);
	deq[v].pop_front();
	deq[v].pop_back();
}

void solve(int l,int r){
	if(l+1==r)return;
	if(l+2==r)return;
	int lb=0,rb=n;
	while(lb+1<rb){
		int mid=(lb+rb)/2;
		if(seg.query(0,mid)==0)lb=mid;
		else rb=mid;
	}
	int ls=lb;
	lb=0,rb=n;
	while(lb+1<rb){
		int mid=(lb+rb)/2;
		if(seg.query(0,mid)==n-ct*2)rb=mid;
		else lb=mid;
	}
	int rs=lb;
	if(cnt[str[rs]-'a']%2==1){
		int lt=deq[str[ls]-'a'][deq[str[ls]-'a'].size()-1];
		int lv=seg.query(lt+1,n);
		ans+=(ll)lv;
		del(str[ls]-'a');
	}else if(cnt[str[ls]-'a']%2==1){
		int rt=deq[str[rs]-'a'][0];
		int rv=seg.query(0,rt);
		ans+=(ll)rv;
		del(str[rs]-'a');
	}else{
		int lt=deq[str[ls]-'a'][deq[str[ls]-'a'].size()-1];
		int lv=seg.query(lt+1,n);
		int rt=deq[str[rs]-'a'][0];
		int rv=seg.query(0,rt);
		if(lv<=rv){
			ans+=(ll)lv;
			del(str[ls]-'a');
		}else{
			ans+=(ll)rv;
			del(str[rs]-'a');	
		}
	}
	ct++;
	solve(l+1,r-1);
}

int main(void){
	cin >> str;
	n=str.size();
	for(int i=0;i<n;i++){
		cnt[str[i]-'a']++;
	}
	int kis=0;
	for(int i=0;i<26;i++){
		if(cnt[i]%2==1)kis++;
	}
	if(kis>=2){
		printf("-1\n");
		return 0;
	}
	if(kis==1 && n%2==0){
		printf("-1\n");
		return 0;
	}
	if(kis==0 && n%2==1){
		printf("-1\n");
		return 0;
	}
	for(int i=0;i<n;i++){
		deq[str[i]-'a'].push_back(i);
		seg.update(i,1);
	}
	solve(0,n);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

long double a, b, x;

void input() {
    cin >> a >> b >> x;
}

long double f(long double a, long double b, long double x) {
    long double ans;
    if(a * a * b / 2.0 <= x) {
        ans = atan(2 * (a * a * b - x) / (a * a * a));
    } else {
        ans = PI / 2 - atan(2 * x / (a * b * b));
    }
    return ans;
}

void solve() {
    input();
    cout << fixed << setprecision(10) << f(a, b, x) * 180.0 / PI << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;
long long mod=1e9+7;
long long k[100005];
int f[100005];
int main()
{
    int n,z;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%d",&f[i]);
    //int co=0;
    f[1]=1;
    if(f[2]>2) f[2]=3;
    //if(f[1]==f[0]+1) ++co;
    k[1]=1;
    k[2]=2;
    for(int i=3;i<=n;++i)
    {
        if(f[i]>f[i-1]+1) f[i]=f[i-1]+2;
        k[i]=(k[i-1]*(i-(2*(i-1)-f[i-1])/2))%mod;
    }
    cout<<k[n]<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>


int main()
{
	int N, M;
	int Ball[201];


	scanf("%d %d", &N, &M);

	int BallCnt = 0;
	for (int n = 1; n <= N; n++) // even
		Ball[BallCnt++] = 2 * n;

	for (int m = 0; m < M; m++) // odd
		Ball[BallCnt++] = 2 * m + 1;

	int ResultCnt = 0;
	for (int b = 0; b < BallCnt; b++)
		for (int t = 0; t < BallCnt; t++)
			if (b != t)
				if ((Ball[b] + Ball[t]) % 2 == 0)
					ResultCnt++;
		
	printf("%d", ResultCnt / 2);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Comparator;
import java.util.PriorityQueue;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node[] nodes=new Node[n];
		for(int i = 0; i<n; i++){
			nodes[i]=new Node(i,sc.nextInt(),sc.nextInt());
		}
		Arrays.sort(nodes,Comparator.comparingInt(o -> o.x));
		for(int i = 0; i<n-1; i++){
			Node a=nodes[i];
			Node b = nodes[i+1];
			int d=b.x-a.x;
			a.edges.add(new Edge(a,b,d));
			b.edges.add(new Edge(b,a,d));
		}
		Arrays.sort(nodes,Comparator.comparingInt(o -> o.y));
		for(int i = 0; i<n-1; i++){
			Node a = nodes[i];
			Node b = nodes[i+1];
			int d=b.y-a.y;
			a.edges.add(new Edge(a,b,d));
			b.edges.add(new Edge(b,a,d));
		}
		PriorityQueue<Edge> queue=new PriorityQueue<>(Comparator.comparingInt(o ->o.dist));
		Node a=nodes[0];
		queue.addAll(a.edges);
		a.visited=true;
		long d = 0;
		while(!queue.isEmpty()){
			Edge e = queue.poll();
			if(!e.to.visited){
				d+=e.dist;
				e.to.visited=true;
				queue.addAll(e.to.edges);
			}
		}
		System.out.println(d);
	}
	private static class Node{
		final int id;
		final int x;
		final int y;
		final List<Edge> edges=new ArrayList<>();
		boolean visited;
		private Node(int id, int x,int y){
			this.id=id;
			this.x=x;
			this.y=y;
		}
	}
	 
	private static class Edge{
		final Node from;
		final Node to;
		final int dist;
		
		private Edge(Node from, Node to,int dist){
			this.from=from;
			this.to=to;
			this.dist=dist;
		}
	}
}

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

int main(){
  int n,ta_cou=0,ha_cou=0,ba=0,turn=0;
  int ta[111],ha[111];
  while(1){
    cin >> n;
    if(n == 0) break;
    ha_cou=0,ta_cou=0,ba=0,turn=0;
    for(int i=0;i<n;i++){
      cin >> ta[i];
    }
    sort(ta,ta+n);
    for(int i=1;i<=2*n;i++){
      if(ta[ta_cou] != i){
	ha[ha_cou] = i;
	ha_cou++;
      }
      else if(ta[ta_cou] == i){
	ta_cou++;
      }
    }
    while(ta_cou > 0 && ha_cou > 0){
      if(turn == 0){
	for(int i=0;i<n;i++){
	  if(ba < ta[i]){
	    ba = ta[i];
	    ta[i] = 0;
	    ta_cou--;
	    break;
	  }
	  else if(i == n-1){
	    ba = 0;
	  }
	}
	turn++;
      }
      else if(turn == 1){
	for(int j=0;j<n;j++){
	  if(ba < ha[j]){
	    ba = ha[j];
	    ha[j] = 0;
	    ha_cou--;
	    break;
	  }
	  else if(j == n-1){
	    ba = 0;
	  }
	}
	turn--;
      }
    }
    cout << ha_cou << endl << ta_cou << endl;
  }
}
  

Measured memory_bytes: 1180
#include <stdio.h>
#include <assert.h>
int n,i,j,x,a[10][10],list[200][3],size;
void push(int x,int y,int s){list[size][0]=i;list[size][1]=j;list[size][2]=s;size++;}

int check(int x,int y,int s){
	int d;
	if(s<3 && (x<1 || x>9 || y<1 || y>9)) return 0;
	if(s==3 && (x<2 || x>8 || y<2 || y>8)) return 0;
	d=a[x][y];
	if(a[x-1][y]<d)d=a[x-1][y];
	if(a[x+1][y]<d)d=a[x+1][y];
	if(a[x][y-1]<d)d=a[x][y-1];
	if(a[x][y+1]<d)d=a[x][y+1];
	if(s==1 || d==0)return d;
	if(a[x-1][y-1]<d)d=a[x-1][y-1];
	if(a[x+1][y+1]<d)d=a[x+1][y+1];
	if(a[x+1][y-1]<d)d=a[x+1][y-1];
	if(a[x-1][y+1]<d)d=a[x-1][y+1];
	if(s==2 || d==0)return d;
	if(a[x-2][y]<d)d=a[x-2][y];
	if(a[x+2][y]<d)d=a[x+2][y];
	if(a[x][y-2]<d)d=a[x][y-2];
	if(a[x][y+2]<d)d=a[x][y+2];
	return d;
}

void draw(int x,int y,int s,int d){
	if(size==3 && (x<2 || x>8 || y<2 || y>8)) return;
	a[x][y]+=d;
	a[x-1][y]+=d;
	a[x+1][y]+=d;
	a[x][y-1]+=d;
	a[x][y+1]+=d;
	if(s==1)return;
	a[x-1][y-1]+=d;
	a[x+1][y+1]+=d;
	a[x+1][y-1]+=d;
	a[x-1][y+1]+=d;
	if(s==2)return;
	a[x-2][y]+=d;
	a[x+2][y]+=d;
	a[x][y-2]+=d;
	a[x][y+2]+=d;
}

int search(int nn,int from){
	int i,x,y,s,t;
	for(i=from;i>=0;i--){
		x=list[i][0];y=list[i][1];s=list[i][2];
		if(a[x][y]==0 && a[x+1][y]>0)return 0;
		if(x<8){
		if(s<3 && a[x+2][y]>0)return 0;
		if(y==1 && a[x+2][y-1]>0)return 0;
		}
		if(y==1 && s<2 && a[x+1][y-1]>0)return 0;
        if(y==8 && s<2 && a[x+1][y+1])return 0;
		t=check(x,y,s);
		if(t>0){
			draw(x,y,s,-t);
			for(;t>0;t--){
				if(s==1 && a[x+1][y+1]>0 && check(x-1,y+1,3)==0){draw(x,y,s,+1);continue;}
				if(nn-t>0){
					if(search(nn-t,i-1)>0){goto answer;}
				}else{
					int p,q;
					for(p=0;p<10;p++)for(q=0;q<10;q++){{if(a[p][q]!=0)goto miss;}}
					goto answer;
					miss:;
				}
				draw(x,y,s,+1);
			}
		}
	}
	return 0;

	answer:
	for(;t>0;t--)printf("%d %d %d\n",y,x,s);
	return 1;
}

int main(void){
	scanf("%d",&n);size=0;
	for(i=0;i<10;i++){for(j=0;j<10;j++){scanf("%d",&a[i][j]);}}
	for(i=1;i<9;i++){
		for(j=1;j<9;j++){
			x=check(i,j,1); if(x==0)continue; push(i,j,1);
			x=check(i,j,2); if(x==0)continue; push(i,j,2);
			x=check(i,j,3); if(x==0)continue; push(i,j,3);
		}
	}
	search(n,size-1);
	return 0;
}

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

int main(){
  //ツ素ツ青板青カツ青ャ
  const int NUM = 1000000;
  bool prime[NUM];
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<NUM;i++)
    prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;

  while(true){
    int n,x;
    cin>>n>>x;
    if(!n&&!x)break;
    int menu[n];
    for(int i=0;i<n;i++)cin>>menu[i];
    bool money[x+1];
    money[0] = true;
    for(int i=1;i<x+1;i++){
      money[i] = false;
      for(int j=0;j<n;j++){
	if(i>=menu[j]&&money[i-menu[j]]){
	  money[i] = true;
	  break;
	}
      }
    }
    int p = -1;
    for(int i=x;i>0;i--){
      if(money[i]&&prime[i]){
	p=i;
	break;
      }
    }
    if(p==-1)cout<<"NA"<<endl;
    else cout<<p<<endl;
  }
  return 0;
}

Measured memory_bytes: 2820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=1e9+7;


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

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

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

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

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

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

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


int main(){
  int i,j;
  ll n,m;
  cin>>n>>m;
  vector<pair<P,ll> > v;
  for(i=0;i<m;i++){
    int l,r,c;
    cin>>l>>r>>c;
    v.pb(make_pair(P(r,l),c));
  }
  sort(v.begin(),v.end());
  SegTree<ll> st(101010, INF,
                    [](ll s, ll t) {
                        return min(s,t);
                    },
                    [](ll s, ll t) { return t; });
  st.change(1,0);
  for(i=0;i<m;i++){
    ll u=st.query(v[i].fi.se,1+v[i].fi.fi);
    ll t=st.query(v[i].fi.fi,1+v[i].fi.fi);
    st.change(v[i].fi.fi,min(t,u+v[i].se));
  }
  if(st.query(n,1+n)==INF) {
    cout<<-1<<endl;
    return 0;
  }
  cout<<st.query(n,1+n)<<endl;
}


Measured memory_bytes: 5488
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    int w[100];
    cin >> n;
    int sum = 0;
    imfor(i, n) {
        cin >> w[i];
        sum += w[i];
    }
    int kokomade = 0;
    int ans = 1<<10;
    imfor(i, n - 1) {
        kokomade += w[i];
        if (abs((sum - kokomade) - kokomade) < ans) {
            ans = abs((sum - kokomade) - kokomade);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,X,Y;
  cin>>N>>X>>Y;
  X--,Y--;
  vector<int> A(N);
  for(int i=0;i<N;i++)
    for(int j=i+1;j<N;j++){
      A[min(abs(X-i)+abs(Y-j)+1,j-i)]++;
    }
  for(int i=1;i<N;i++)cout<<A[i]<<endl;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <vector>

#include <math.h>

using namespace std;

typedef long long ll;

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

ll calc_dist_two(const int D, vector<ll> a, vector<ll> b) {
    ll res = 0;
    for (int i = 0; i < D; i++) {
        res += (a[i] - b[i]) * (a[i] - b[i]);
    }
    return res;
}

int main(void) {
    int N, D;
    cin >> N >> D;

    vector<vector<ll> > points(N, vector<ll>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> points[i][j];
        }
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            ll dist = calc_dist_two(D, points[i], points[j]);
            for (ll k = 1; k <= dist; k++) {
                if ((k * k) == dist) {
                    count++;
                    break;
                } else if ((k * k) > dist) {
                    break;
                }
            }
        }
    }

    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			if (n == 0)
				break;
			map = new int[n][n];
			v = new boolean[n][n];
			m = 0;
			p = new int[2][n * n];
			int sum = 0;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) {
					map[i][j] = scanner.nextInt();
					sum += map[i][j];
					if (map[i][j] < 0) {
						p[0][m] = i;
						p[1][m++] = j;
						v[i][j] = true;
					}

				}
			if (sum != 0) {
				System.out.println("NO");
				continue;
			}
			System.out
					.println(slove(p[0][0], p[1][0], 0, map[p[0][0]][p[1][0]]) ? "YES"
							: "NO");

		}
	}

	private boolean slove(int y, int x, int k, int sum) {
		if (sum > 0)
			return false;
		if (sum == 0) {
			if (++k == m)
				return true;
			return slove(p[0][k], p[1][k], k, map[p[0][k]][p[1][k]]);
		}
		for (int[] mo : move) {
			int ny = y + mo[0];
			int nx = x + mo[1];
			if (!isOK(ny, nx))
				continue;
			if (v[ny][nx])
				continue;
			v[ny][nx] = true;
			if (slove(ny, nx, k, sum + map[ny][nx]))
				return true;
			v[ny][nx] = false;
		}

		return false;
	}

	private boolean isOK(int ny, int nx) {
		return 0 <= ny && ny < n && 0 <= nx && nx < n;
	}

	int n, m;
	int[][] map;
	int[][] p;
	boolean[][] v;
	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
}

Measured memory_bytes: 26936
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

const ll M = 4e18;
ll n, m;
ll a[100005];
vector<ll> ans;

int main()
{
    scanf("%lld%lld", &n, &m);
    for(ll i = 0; i <= n; i++)
    {
        scanf("%1lld", &a[i]);
    }
    ll t = n;
    while(t > 0)
    {
        ll mn = M;
        for(ll i = 1; i <= min(m, t); i++)
        {
            if(a[t - i] == 0) mn = t - i;
        }
        if(mn == M)
        {
            printf("-1\n");
            return 0;
        }
        ans.push_back(t - mn);
        t = mn;
    }
    for(ll i = ans.size() - 1; i >= 0; i--)
    {
        printf("%lld ", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 2168
#include <iostream>

using namespace std;

int LCS[1001][1001];

int lcs(string X, string Y)
{
    int m = X.size();
    int n = Y.size();
    X = ' ' + X;
    Y = ' ' + Y;
    for(int i = 0; i <= m; i++)
        LCS[i][0] = 0;
    for(int j = 1; j <= n; j++)
        LCS[0][j] = 0;
    
    for(int i = 1; i <= m; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(X[i] == Y[j])
                LCS[i][j] = LCS[i - 1][j - 1] + 1;
            else
                LCS[i][j] = max(LCS[i][j - 1], LCS[i - 1][j]);
        }
    }
    return LCS[m][n];
}

int main()
{
    int q;
    cin >> q;
    string X;
    string Y;
    for(int i = 0; i < q; i++)
    {
        cin >> X;
        cin >> Y;
        cout << lcs(X, Y) << endl;
    }
}


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

using namespace std;
int dp[105][105];
char squ[105][105];

int h,w;
struct mt{
    int first,second,cnt;
    mt(int f,int s,int c){
        first = f;second = s;cnt = c;
    }
};
queue<mt> tovis;

int main()
{
    scanf("%d%d",&h,&w);
    for(int i=0;i<h;++i)
    {
        scanf("%s",squ[i]);
        for(int j=0;j<w;++j)dp[i][j] = 300;
    }
    if(squ[0][0]=='#') tovis.push(mt(0,0,1));
    else tovis.push(mt(0,0,0));

    while(!tovis.empty())
    {
        mt now = tovis.front();
        tovis.pop();
        if(dp[now.first][now.second]<=now.cnt) continue;
        dp[now.first][now.second]=now.cnt;
        int j=1;

        if(now.first+1<h){
            int k = 0;
        if(squ[now.first][now.second]=='.'&&squ[now.first+1][now.second]=='#')
            ++k;
            tovis.push(mt(now.first+1,now.second,now.cnt+k));
        }
        if(now.second+1<w)
        {
            int k=0;
        if(squ[now.first][now.second]=='.'&&squ[now.first][now.second+1]=='#')++k;
            tovis.push(mt(now.first,now.second+1,now.cnt+k));
        }
    }
    printf("%d\n",dp[h-1][w-1]);
    return 0;
}


Measured memory_bytes: 384
package main 

import (
  "fmt"
)

func main() {
  var n int
  fmt.Scan(&n)
  
  p := make([]int ,n)
  for i := 0; i < n; i++ {
    fmt.Scan(&p[i])
  }
  
  ans := 0
  min := 2000000
  
  for i := 0; i < n; i++ {
    if min > p[i] {
      min = p[i]
      ans ++
    }
  }
  
  fmt.Println(ans)
  
}

Measured memory_bytes: 6400
// finish date: 2018/02/24

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    string N;
    cin >> N;
    int sum1=0;
    rep(i,N.length()) sum1+=N[i]-'0';
    int digit = N.length();
    cout << max(sum1,(N[0] - '0' - 1) + 9 * (digit - 1)) << endl;


    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
#include <numeric>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int, int> P;
#define PB push_back
#define INF 100000000000000000

int main()
{
  ll N, M, ans,tmp , i,j,LRange,RRange;
  cin >> N >> M;
  ans = 0;
  LRange=0;
  RRange=1000000;
  vector <long long > L(10000000);
  vector <long long > R(10000000);
  vector <long long > S(10000000);
  for (i = 1; i <= M; i++)
  {
    cin >> L.at(i) >> R.at(i);
    LRange=max(LRange,L.at(i));
    RRange=min(RRange,R.at(i));
  }
  for (i=LRange;i<=RRange;i++ ){
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 234624
#include <stdio.h>

int main(int argc, const char * argv[]) {
    double max=0,min=1000000,mt;
    
    while(scanf("%lf",&mt)!=EOF){
        if(mt<min)
            min=mt;
        if(mt>max)
            max=mt;
    }
    printf("%lf\n",max-min);
    
    return 0;
}

Measured memory_bytes: 1812
@_[glob<>]=$&*$_..$&*$_+$&for<>=~/ .* /..$`;$s[$_+$']=$s[$_]+abs((($b=$_[$_+$'])/$&|0)-(($a=$_[$_])/$&|0))+abs$b%$&-$a%$&for 1..9e4;<>;/ /,print$s[$']-$s[$`],$/for<>

Measured memory_bytes: 22272