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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int h,w,ans=0;
    cin>>h>>w;
    Vs s(h);
    VVi yoko(h,Vi(w)),tate(h,Vi(w));
    REP(i,0,h) cin>>s[i];
    
    REP(i,0,h){
        REP(j,0,w){
            if(j>0){
                if(s[i][j]=='.' && yoko[i][j-1]>0){
                    yoko[i][j]=yoko[i][j-1];
                    continue;
                }
            }
            int tj=j,t=0;
            while(s[i][tj]=='.' && tj<w){t++;tj++;}
            yoko[i][j]=t;
        }
    }
    REP(i,0,w){
        REP(j,0,h){
            if(j>0){
                if(s[j][i]=='.' && tate[j-1][i]>0){
                    tate[j][i]=tate[j-1][i];
                    continue;
                }
            }
            int tj=j,t=0;
            while(s[tj][i]=='.'){t++;tj++;if(tj==h)break;}
            tate[j][i]=t;
        }
    }
    
    
    REP(i,0,h){
        REP(j,0,w){
            chmax(ans,yoko[i][j]+tate[i][j]-1);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 67200
import sys;
import numpy as np;
sys.stdin.readline()
a=np.sort(np.array(sys.stdin.readline()[:-1].split(),dtype=np.int32))[::-1]
if a.size%2:
 a=np.append(a,0)
a=np.reshape(a,(-1,2)).T
print(np.sum(a[0]-a[1]))


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

int main(){
  long long int n;
  int k;
  double r;
  cin >> n >> k;
  r = log(n) / log(k);
  if(r - ceil(r) == 0) r=ceil(r) + 1;
  else r  =ceil(r);
  cout << r << endl;
  return 0;
}

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


int main() {
  int N, M; cin >> N >> M;
  if(N >= M) {
    cout << 0 << endl;
    return 0;
  }
  
  vector<int> x(M);
  for(int i = 0; i < M; i++){
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  
  vector<int> dif(M - 1);
  for(int i = 0; i < M - 1; i++){
    dif[i] = x[i + 1] - x[i];
  }
  sort(dif.begin(), dif.end());
  
  long long ans = 0;
  for(int i = 0; i < M - N; i++){
    ans += dif[i];
  }
  
  cout << ans << endl;
  
}

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

int main() {
  int N;
  cin >> N;
  map<int, int> A;
  A[1] = 0;
  for (int i = 2; i < N + 1; i++){
    A[i] = 0;
    int x;
    cin >> x;
    A[x] += 1;
  }
  for (int i = 1; i < N + 1; i++)
    cout << A[i] << endl;
}

Measured memory_bytes: 13012
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second

 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  int n;
  cin >> n;
  vi a (n + 1);
  F0R (i, n) {
    cin >> a[i + 1];
  }
  int trip_cost = 0;
  FOR (i, 1, n + 1) {
    trip_cost += abs (a[i - 1] - a[i]);
  }
  trip_cost += abs(a.back());
  a.eb(0);
  FOR (i, 1, n + 1) {
    int disconnect = abs (a[i] - a[i - 1]) + abs (a[i] - a[i + 1]);
    int connect = abs (a[i - 1] - a[i + 1]);
    cout << trip_cost - disconnect + connect << '\n';
  
    
  }
  
  return 0;
}


Measured memory_bytes: 1656
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"

using namespace std;
typedef long long ll;

int n, wmax;
int w[110];
ll v[110];
ll dp[110][100100];
ll ans;

//x以降がy以下
ll rec(int x, int y)
{
  if (dp[x][y] >= 0)
  {
    return dp[x][y];
  }
  else
  if (x == n)
  {
    ans = 0;
  }
  else
  {
    if (y < w[x])
    {
      ans = rec(x + 1, y);
    }
    else
    {
      ans = max(rec(x + 1, y), v[x] + rec(x + 1, y - w[x]));
    }
  }
  return dp[x][y] = ans;
}

int main()
{
  cin >> n >> wmax;
  for (int i = 0; i < n; i++)
  {
    cin >> w[i] >> v[i];
  }
  for (int i = 0; i < 110; i++)
  {
    for (int j = 0; j < 100100; j++)
    {
      dp[i][j] = -1;
    }
  }
  cout << rec(0, wmax) << "\n";
}

Measured memory_bytes: 86272
k = int(input())
if k in [0, 1]:
    print(["4\n3 3 3 3", "3\n1 0 3"][k])
    __import__("sys").exit()
n = 50
coef = k // n

if k <= 50: coef, n = 1, k
a = list(reversed(range(coef, coef + n)))
for i in range(k - coef * n):
    a[i] += 1
print(n)
print(*a)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

int main()
{
    int n, k;
    cin >> n >> k;
    set<int> d;
    rep(i, k)
    {
        int input;
        cin >> input;
        d.insert(input);
    }

    int answer = n;
    while (true)
    {
        int digit_num = to_string(answer).size();
        bool is_ok = true;
        for (int i = 0; i < digit_num; i++)
        {
            int ith_num = ctoi(to_string(answer).at(i));
            if (d.count(ith_num) == 1)
            {
                is_ok = false;
                break;
            }
        }
        if (is_ok)
        {
            break;
        }
        else
        {
            answer++;
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const int N=5010;
const int mod=1000000007;
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
int tot=1;
int fir[N],nex[N<<1],got[N<<1];
inline void AddEdge(int x,int y) { 
    nex[++tot]=fir[x],fir[x]=tot,got[tot]=y; 
}
int g[N],f[N][N],siz[N],tmp[N];
inline void dfs(int x,int fa) {
    f[x][siz[x]=1]=1;
    for (int i=fir[x];i;i=nex[i]) {
        if (got[i]==fa) continue;
        int y=got[i]; dfs(y,x);
        for (int j=1;j<=siz[x]+siz[y];j++) tmp[j]=0;
        for (int j=1;j<=siz[x];j++) 
            for (int k=0;k<=siz[y];k++)
                (tmp[j+k]+=1LL*f[x][j]*f[y][k]%mod)%=mod;
        for (int j=1;j<=siz[x]+siz[y];j++) f[x][j]=tmp[j];
        siz[x]+=siz[y];
    }
    for (int i=1;i<=siz[x];i++) 
        (f[x][0]+=mod-1LL*f[x][i]*g[i]%mod)%=mod;
}
int main() {
    int n=read(); g[0]=1;
    for (int i=2;i<=n;i++) g[i]=1LL*g[i-2]*(i-1)%mod;
    for (int i=1;i<=n-1;i++) {
        int x=read(),y=read();
        AddEdge(x,y),AddEdge(y,x);
    }
    dfs(1,0),cout<<mod-f[1][0]<<endl;
    return 0;
}

Measured memory_bytes: 97024
#include <iostream>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;
#define c(v) cout << fixed << setprecision(10) << v << endl;
int x[110]; int y[110];
int main()
{
    int che;
    long long int n, sum, dis, man; sum = dis = man = 0;
    cin >> n; 
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> y[i];
    }
    che = abs(x[0] - y[0]);
    for (int i = 0; i < n; i++) {
        sum += abs(x[i] - y[i]);
        dis += pow(x[i] - y[i], 2);
        man += pow(abs(x[i] - y[i]), 3);
        che = max(che, abs(x[i] - y[i]));
    }
    double r = sqrt(dis);
    double s = cbrt(man);
    c(sum) c(r) c(s) c(che)
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
    
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;

ll t=1;

void solve()
{
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++)cin>>v[i];
    ll cnt=0;
    for(ll i=0;i<=n-3;i++)
    {
        for(ll j=i+1;j<=n-2;j++)
        {
            for(ll p=j+1;p<n;p++)
            {
                if(v[i]==v[j] or v[j]==v[p] or v[i]==v[p])continue;
                if(v[i]+v[j]>v[p] and v[i]+v[p]>v[j] and v[j]+v[p]>v[i])
                cnt++;
            }
        }
    }
    cout<<cnt;
 if(t>0)cout<<"\n";
}



int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 3644
#/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  // #define MAX 100001
  #define md 998244353
  #define add accumulate
  #define ll long long int
  #define ld long double
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  #define repa(a,n) for(int i=a;i<n;i++)
  const int MAX=1e5+5;
  const int mod=1e9+7;
  const int N=3e5+9;
  const long double eps=1e-9;
  const ld PI=acos(-1.0);
    ll dx[]={1,0,-1,0};
	ll dy[]={0,1,0,-1};
  //
  //
  int main(){
  	ll n;	cin>>n;
  	int dp[n][3];
  	ll a,b,c;
  	rep(i,0,3){
  		cin>>a;
  		dp[0][i]=a;
  	}
  	rep(i,1,n){
  		cin>>a>>b>>c;
  		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
  		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
  		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
  	}
  	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  	return 0;
  }

Measured memory_bytes: 1408
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let input = read_vec::<i32>();
    let ans = if input[0] <= input[1] {
        input[0]
    } else {
        input[0] - 1
    };
    println!("{}",ans);
}

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

using namespace std;

const long long base = 1ll << 57;
const int LOG = 60;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector<long long> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    x[i] += base;
    y[i] += base;
  }
  vector<bool> equal(3), less(3), new_equal(3), new_less(3);
  auto solve = [&](long long p, int remainder) {
    bool ans = false;
    for (int i = 0; i < n; ++i) {
      if (p > y[i]) {
        long long high = p - y[i];
        for (int j = 0; j < 3; ++j) {
          equal[j] = less[j] = false;
        }
        equal[0] = 1;
        for (int j = LOG - 1; ~j; --j) {
          for (int k = 0; k < 3; ++k) {
            new_equal[k] = new_less[k] = false;
          }
          {
            int l = 0, r = min(x[i] >> j & 1, high >> j & 1);
            for (int k = 0; k < 3; ++k) {
              if (equal[k]) {
                for (int w = l; w <= r; ++w) {
                  int kk = (k + w * ((j & 1) + 1)) % 3;
                  if (w == (high >> j & 1)) {
                    new_equal[kk] = !new_equal[kk];
                  } else {
                    new_less[kk] = !new_less[kk];
                  }
                }
              }
            }
          }
          {
            int l = 0, r = x[i] >> j & 1;
            for (int k = 0; k < 3; ++k) {
              if (less[k]) {
                for (int w = l; w <= r; ++w) {
                  int kk = (k + w * ((j & 1) + 1)) % 3;
                  new_less[kk] = !new_less[kk];
                }
              }
            }
          }
          swap(equal, new_equal);
          swap(less, new_less);
        }
        ans ^= less[(remainder - y[i] % 3 + 3) % 3];
      }
    }
    return ans;
  };
  auto check = [&](long long p) {
    bool ans = false;
    for (int i = 0; i < n; ++i) {
      if (p - y[i] >= 0 && p - y[i] <= x[i] && (x[i] & (p - y[i])) == p - y[i]) {
        ans = !ans;
      }
    }
    return ans;
  };
  int remainder = 0;
  while (!solve(1ll << LOG, remainder)) {
    ++remainder;
  }
  long long p = 0;
  for (int i = LOG - 1; ~i; --i) {
    if (solve(p, remainder) == solve(p + (1ll << i), remainder)) {
      p += 1ll << i;
    }
  }
  long long l = p;
  for (int i = LOG - 1; ~i; --i) {
    if (check(l - (1ll << i))) {
      l -= 1ll << i;
    }
  }
  long long r = p;
  for (int i = LOG - 1; ~i; --i) {
    if (check(r + (1ll << i))) {
      r += 1ll << i;
    }
  }
  cout << r - l - base << " " << l - base << "\n";
  return 0;
}


Measured memory_bytes: 384
from collections import deque

T = input()
A = deque()
d = 0
s = 0
for i, token in enumerate(T):
    if token == "\\":
        s += d + 0.5
        if not d:
            l = i
        d += 1
    elif token == "/":
        if not d:
            continue
        d -= 1
        s += d + 0.5
        if not d:
            A.append((l, s))
            s = 0
    else:
        s += d
B = deque()
d = 0
s = 0
for i in range(len(T) - 1, -1, -1):
    token = T[i]
    if token == "/":
        s += d + 0.5
        d += 1
    elif token == "\\":
        if not d:
            continue
        d -= 1
        s += d + 0.5
        if not d:
            B.appendleft((i, s))
            s = 0
    else:
        s += d
S = set(A) | set(B)
S = list(S)
S.sort()
S = [round(s[1]) for s in S]
print(sum(S))
print(len(S), *S)



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

using namespace std;


#define MOD 1000000007
#define ll long long int
#define ff first
#define ss second
#define N 100001


template <typename T,typename G>
ostream& operator << (ostream& out, const pair<T,G> &a) 
{return out<<"( "<<a.ff<<", "<<a.ss<<")";}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &a) 
{out<<"[ ";for(const auto &i:a)out<<i<<", ";return out<<"]"<<endl;}

template <typename T>
ostream& operator << (ostream& out, const set<T> &a) 
{out<<"{ ";for(const auto &i:a)out<<i<<", ";return out<<"}"<<endl;}

template <typename T,typename G>
ostream& operator << (ostream& out, const map<T,G> &a) 
{out<<"< ";for(const auto &i:a)out<<i<<", ";return out<<">"<<endl;}
    
vector<vector<char>> grid;
int vis[N];
ll dp[1001][1001]={-1};
int h,w;

bool isValid(int x,int y)
{
	if(x>=1 && x<=h && y>=1 && y<=w && grid[x][y]!='#')
		return true;
	return false;
}

int dfs(int x,int y)
{
	if(dp[x][y]!=-1)
		return dp[x][y];

	if(x==h && y==w)
		return 1;
	ll ans=0;
	if(isValid(x+1,y))
		ans=(ans+dfs(x+1,y))%MOD;
	if(isValid(x,y+1))
		ans=(ans+dfs(x,y+1))%MOD;

	 if(dp[x][y]==-1)
	 	dp[x][y]=0;
	 	
	dp[x][y]=(dp[x][y]+ans)%MOD;


	return dp[x][y]%MOD;
}

void solve()
{
	cin>>h>>w;
	grid.clear();

	grid.resize(h+1,vector<char>(w+1,0));
	for(int i=0;i<1001;i++)
		for(int j=0;j<1001;j++)
			dp[i][j]=-1;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>grid[i][j];

	cout<<dfs(1,1)<<"\n";
}
	


int32_t main()
{
    //your code goes here...
    int t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }    
}

Measured memory_bytes: 9216
n,a,b,c = map(int,input().split())
l = [int(input()) for _ in range(n)]
ans = 10000
for i in range(2 ** (2*n)):
  v = [0,0,0,0]
  assign = [(i>>(2*j)) & 3 for j in range(n)]
  cost = 0
  for j in range(n):
    if assign[j] > 0 and v[assign[j]] > 0:
      cost += 10
    v[assign[j]] += l[j]
  if v[1] == 0 or v[2] == 0 or v[3] == 0:
    continue
  ans = min(ans, cost + abs(v[1]-a) + abs(v[2]-b) + abs(v[3]-c))
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int gcd[1000];
int c_gcd;
int lcm[1000];
int c_lcm;
int main()
{
  int a,b,i,s;
  while((scanf("%d%d",&a,&b)) != EOF) {
    c_gcd = c_lcm = 0;
    memset(gcd,0,sizeof(gcd));
    memset(lcm,0,sizeof(lcm));
    i = 2;
    while(a != 1 || b != 1){
      if (a % i == 0 && b % i == 0) {
	gcd[c_gcd++] = i;
	lcm[c_lcm++] = i;
	a /= i;
	b /= i;
      } else if (a % i == 0) {
	lcm[c_lcm++] = i;
	a /= i;
      } else if (b % i == 0) {
	lcm[c_lcm++] = i;
	b /= i;
      } else {
	i++;
      }
      if (c_gcd >= 1000 || c_lcm >= 1000) return -1;
    }
    s = 1;
    for(i=0; i<c_gcd; i++) {
      s *= gcd[i];
    }
    printf("%d ", s);
    s = 1;
    for(i=0; i<c_lcm; i++) {
      s *= lcm[i];
    }
    printf("%d\n", s);
  }
  return 0;
}

Measured memory_bytes: 0
from collections import*
from heapq import*
(n,m),a,*q=[[*map(int,o.split())]for o in open(0)]
t=[-1]*n
def r(x):
 while t[x]>=0:x=t[x]
 return x
def u(x,y):
 x,y=r(x),r(y)
 if x!=y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
d=defaultdict(list)
for x,y in q:u(x,y)
i=c=0;b=[]
for v in a:d[r(i)]+=v,;i+=1
if(k:=n+~m)<1:exit(print(0))
k*=2
for r,p in d.items():p.sort();c+=p.pop(0);b+=p;k-=1
print(k>len(b)and'Impossible'or c+sum(sorted(b)[:k]))

Measured memory_bytes: 35544
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double d = sc.nextDouble();
		int n = sc.nextInt();
		
		int first = (int) Math.pow(100, d);
		
		if(n == 100) {
			System.out.println(first * n + 1 * first);
		}else {
			System.out.println(first * n);
		}
	}
}

Measured memory_bytes: 23252
#include <stdio.h>
int main(void) {
   int a, b, c;
   for(a=1;a<10;a++) {
      for(b=1;b<10;b++) {
      c = a * b;
      printf("%dx%d=%d\n", a, b, c);
      }
   }
   return 0;
}

Measured memory_bytes: 520
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
int main()
{
    int N,K;
    cin >> N >> K;
    int now = 1;
    for(int i = 0;i < N;i++)
        now = min(now * 2,now + K);
    std::cout << now << '\n';
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


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

class BSnakeToy {
public:
	void solve(std::istream& cin, std::ostream& cout) {
	    int n, k;
	    cin >> n >> k;
        vector<int> vec(n, 0);
        for (int i = 0; i < n; ++i) {
            cin >>vec[i];
        }
        sort(vec.begin(), vec.end());
        int ans = 0;
        for (int j = n-1; j >= n-k; --j) {
            ans += vec[j];
        }
        cout << ans << endl;
	}
};


int main() {
	BSnakeToy solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import bisect

def rank(m, f, r):
    if m == -1 or f == -1:
        return 'F'
    sum = m + f
    if 30 <= sum < 50 and r >= 50:
        return 'C'
    return 'FDCBA'[bisect.bisect([30,50,65,80],sum)]

while True:
    m, f, r = input().split()
    if m == f == r == '-1':
        break
    print(rank(int(m),int(f),int(r)))


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;

main(){
	string s,t;
	cin>>s>>t;
	int mini = -100000;
	int n = s.size();
	int m = t.size();
	int dp[n+1][m+1];
	dp[0][0]=0;
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++) dp[i][0] = 0;
	for(int j=1;j<=m;j++) dp[0][j] = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			int op1 = dp[i-1][j-1] + (s[i-1]==t[j-1] ? 1 : mini);
			int op2 = dp[i-1][j];
			int op3 = dp[i][j-1];
			dp[i][j] = max(op1,max(op2,op3));
		}
	} 
	string ans = "";
	while(n>0 && m>0){
		if(s[n-1] == t[m-1]){
			ans+= s[n-1];
			n--;m--;
		}
		else if(dp[n-1][m] > dp[n][m-1]) n--;
		else m--;
	}
	reverse(ans.begin(),ans.end());
	if(ans.empty()) cout<<" ";
	else cout<<ans;
}

Measured memory_bytes: 38748
N,K = map(int,input().split())
A = list(map(int,input().split()))
max = 0
for i in range(K-1):
  value = A[i+1] - A[i]
  if max < value:
    max = value
value = (N - A[K-1]) + A[0]
if max < value:
  max = value
print(N - max)



Measured memory_bytes: 32164
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{

  int N;
  cin >> N;

  vector<int> student(N);

  for(int i = 0; i < N; i++){
    int order;
    cin >> order;

    student[order-1] = i+1;
  }

  for(int i = 0; i < N; i++){
    cout << student[i] << " ";
  }

  return 0;
}


Measured memory_bytes: 1152
n=int(input())
p=list(map(float,input().split()))
dp=[p[0],1-p[0]]
if n==1:
    print(p[0])
    exit()
for i in range(n-1):
    tmp=[]
    tmp.append(dp[0]*p[i+1])
    for j in range(i+1):
        tmp.append(dp[j]*(1-p[i+1])+dp[j+1]*p[i+1])    
    tmp.append(dp[-1]*(1-p[i+1]))
    dp=tmp
print(sum(dp[:n//2+1]))

Measured memory_bytes: 41948
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
C = [list(map(int,input().split())) for i in range(m)]

V = [0] * (n+1)
P = [-1] * (n+1)

M = [[] for i in range(n+1)]
for i in range(m):
    M[C[i][0]].append(C[i][1])
    M[C[i][1]].append(C[i][0])

# 1始まりの場合
Q = [1]
s = 0
V[1] = 1
while s < len(Q):
    i = Q[s]
    for x in M[i]:
        # print(i,x)
        if V[x] == 0:
            V[x] = 1
            P[x] = i
            Q.append(x)
    s += 1
print("Yes")
for i in range(2, len(P)):
    print(P[i])

Measured memory_bytes: 122840
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll MOD = 1e9 + 7;
const ll INF = 1e10;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};
const vector<int> d = {-1,0,1};

int main() {
    int k; cin >> k;
    vector<ll> lunlun;
    for (int i = 1; i < 10; i++) lunlun.push_back(i);

    int i = 0;
    int cnt = 9;
    while (cnt < k) {
        ll n = lunlun[i];
        int x = n%10;
        rep(j,3) {
            if (x + d[j] < 0 || x + d[j] > 9) continue;
            lunlun.push_back(n * 10 + x + d[j]);
            cnt ++;
        }
        i ++;
    }
    cout << lunlun[k - 1] << endl;
}

Measured memory_bytes: 1400
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
 
public class Main {    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        String[] list = new String[26];
        char temp = 'a';
        for(int i=0;i<26;i++){
            list[i] = String.valueOf(temp++);
        }

        String ans = "";
        while(0<n){
            n--;
            int mod = (int)( n % 26 );
            ans =ans +  list[mod];
            n = n /26;
        }
        StringBuilder sb = new StringBuilder(ans);
        String s = sb.reverse().toString();
        System.out.println(s);
    }
}

Measured memory_bytes: 39264
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

struct Job
{
	int cost;
	int deadLine;
};

Job jobs[200010];
int n;

bool compare(const Job &a, const Job &b)
{
	if (a.deadLine == b.deadLine)
		return a.cost < b.cost;
	else
		return a.deadLine < b.deadLine;
}


int main()
{
	scanf("%d", &n);
	
	for (int i = 0 ; i < n ; i++)
		scanf("%d%d", &(jobs[i].cost), &(jobs[i].deadLine));
		
	sort(jobs, jobs + n, compare);
	
	int curTime = 0;
	int nextTime;
	for (int i = 0 ; i < n ; i++)
	{
		nextTime = curTime + jobs[i].cost;
		if (nextTime > jobs[i].deadLine)
		{
			printf("No\n");
			return 0;
		}
		curTime = nextTime;
	}
	
	printf("Yes\n");
	
	return 0;
}



Measured memory_bytes: 1664
#include<bits/stdc++.h>
 
#define lli long long int
#define endl "\n"
 
using namespace std;
 
typedef long long int LLI;
typedef double DB;
 
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
 
 
bool comparator(pair<lli,lli> a,pair<lli,lli> b)
{
    if(a.first>b.first)
        return true;
    else if (a.first==b.second)
    {
        if(a.second>=b.second)
            return false;
        return true;
    }
    return false;
}
 
int mods(int x)
{
    if(x>0)
        return x;
    return -x;
}
 
lli gcd(lli a,lli b)
{
    return __gcd(a,b);
}
 
lli lcm(lli x,lli y,lli z)
{
    lli j=gcd(x,y);
    lli k=gcd(y*x/j,z);
    return (((x*y)/j)*z)/k;
} 
 
int main()
{
    fastio();
    int a,b,k=1,count=0; cin>>a>>b;
    while(k<b)
    {
        --k; k+=a; count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    int N,K;
    cin >> N >> K;
    vint p(N);
    vector<double> q(N+1);
    rep(i,N)cin >> p[i];
    q[0] = 0.0;
    rep(i,N) q[i+1] =q[i] + (double)(p[i]+1)/2;
    
    double ans =0;
    rep(i,q.size()-K){
        ans = max(q[i+K]-q[i],ans);
    }
    cout << fixed << setprecision(7);
    cout << ans;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a,b,c,k;

int main(){
	cin>>a>>b>>c>>k;
	cout<<min(a,k)-min(c,max(0,k-a-b))<<endl;
}

Measured memory_bytes: 3636
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int x, y, z;
	scanf("%d%d%d", &x, &y, &z);
	x -= z;
	printf("%d\n", x / (y + z));

	Please AC;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int A, B;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> B;
  // A.resize(N);
  // for (int i = 0; i < N; i++) {
  //   int tmp;
  //   cin >> tmp;
  //   A[i] = tmp;
  // }

  int ans = -1;
  for (int i = 1; i <= 2000; i++) {
    int a = i * 0.08;
    int b = i * 0.1;
    if (a == A && b == B) {
      ans = i;
      break;
    }
  }

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


Measured memory_bytes: 888
n,m,q=map(int,input().split())
line=[[0]*(n+1) for _ in range(n+1)]
for i in range(m):
  l,r=map(int,input().split())
  line[l][r]+=1
for i in range(n+1):
  for j in range(n):
    line[i][j+1]+=line[i][j]
for i in range(n+1):
  for j in range(n):
    line[j+1][i]+=line[j][i]
for i in range(q):
  x,y=map(int,input().split())
  print(line[y][y]-line[x-1][y]-line[y][x-1]+line[x-1][x-1])

Measured memory_bytes: 13300
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL X,Y;
	cin >> X >> Y;
	if( abs(X-Y) <= 1 ){
		cout << "Brown" << endl;
	}else{
		cout << "Alice" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
 int n,q;
 int ne[200002];

  vector <int> G[200002]{};
 ll val[200002];

void dfs(int z){
  int si=G[z].size();
  for(int i=0;i<si;i++){
    int pv=G[z][i];
    if(ne[pv]==0){
      ne[pv]=z;
    val[pv]+=val[z];
      dfs(pv);
    }
  }
 
  }





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

 
  rep(i, n+1){
    ne[i]=0;}
  ne[1]=10000000;

  for(int i=1;i<=n-1;i++){
    int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
 
  rep(i, n+1){
    val[i]=0;}
  
  rep(i, q){
    int p,x;
    cin>>p>>x;
    val[p]+=x;
  }
  
  dfs(1);
  
  for(int j=1;j<=n-1;j++){
  cout<<val[j]<<" ";}
  cout<<val[n]<<endl;
    
  
  
  
  
 
}


Measured memory_bytes: 25088
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,H[100009];
    int i,j,max;
    bool flag;
    cin >> n;
    for (i=1; i<=n; i++)
    {
    	cin >> H[i];
	}
    if (n==1) {
      cout << "Yes" << endl;      
	}
    else 
    {
  	    max = H[1];
  	    flag = true;
    	for (i=2; i<=n; i++)
    	{    		
    		if (H[i]>max)
    		{
    		  max = H[i];
   			  flag = true;
			}
			else if (H[i]<max)
			{
			  if (flag == true)
			  {
			  	flag = false;
			  	max -= 1;
			  }			  
			  if (H[i] < max)
			  {
			  	cout << "No" << endl;
			  	return 0;
			  }		  
			} 
		}
		cout << "Yes" << endl;
	}    
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  vector<int> a(3);
  for(int &i:a)cin>>i;
  sort(a.begin(),a.end());
  int A=a[0],B=a[1],C=a[2];
  if((C-A)%2==(C-B)%2)cout<<(C*2-A-B)/2<<endl;
  else cout<<(C*2-A-B+3)/2<<endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N=sc.nextInt();
        int[] a =new int[N];
        double sum=0;
        double ave=0;
        double d=0;
        double ans=100000000;
        int result=0;
        for(int i=0;i<N;i++){
            a[i]=sc.nextInt();
            sum+=a[i];
        }
        ave = sum/N;
        for(int i=0;i<N;i++){
            d=Math.abs(ave-a[i]);
            if(ans>d){
                ans =d;
                result=i;
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 35944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

vector<ll> par(100000);
vector<ll> rnk(100000);
 
void init(ll n){
  rep(i, n){
    par.at(i) = i;
    rnk.at(i) = 1;
  }
}
 
ll root(ll x){
  if(par.at(x) == x){
    return x;
  }
  else{
    par.at(x) = root(par.at(x));
    return par.at(x);
  }
}
 
bool same(ll x, ll y){
  if(root(x) == root(y)){
    return true;
  }
  else{
    return false;
  }
}
 
void unite(ll x, ll y){
  x = root(x);
  y = root(y);
  if(x == y){
    return;
  }
  if(rnk.at(x) < rnk.at(y)){
    par.at(x) = y;
    rnk.at(y) += rnk.at(x);
  }
  else{
    par.at(y) = x;
    rnk.at(x) += rnk.at(y);
  }
}

int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  init(N);
  vector<ll> A(M), B(M), C(K), D(K);
  vector<set<ll>> F(N);
  rep(i, M){
    cin >> A.at(i) >> B.at(i);
    A.at(i)--;
    B.at(i)--;
    unite(A.at(i), B.at(i));
    F.at(A.at(i)).insert(B.at(i));
    F.at(B.at(i)).insert(A.at(i));
  }
  vector<set<ll>> bl(N);
  rep(i, K){
    cin >> C.at(i) >> D.at(i);
    C.at(i)--;
    D.at(i)--;
    bl.at(C.at(i)).insert(D.at(i));
    bl.at(D.at(i)).insert(C.at(i));
  }
  vector<ll> ans(N, 0);
  vector<ll> bf(N);
  rep(i, N){
    for(auto j : bl.at(i)){
      if(same(i, j)){
        bf.at(i)++;
      }
    }
    ans.at(i) = rnk.at(root(i)) - sz(F.at(i)) - 1 - bf.at(i);
  }
  rep(i, N){
    cout << ans.at(i) << " ";
  }
}

Measured memory_bytes: 35200
// author : ayush_nishad
// Road to Expert since : 30 Aug 2020
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define all(x)  x.begin(),x.end()
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

}
/*
think fast
think simple
*/
void mysol()
{
	int cnt = 0;
	bool ok = 0;
	w(q)
	{
		int a, b; cin >> a >> b;
		if (a == b)
			cnt++;
		else
			cnt = 0;
		if (cnt == 3)
			ok = 1;
	}
	cout << (ok ? "Yes" : "No");
}

int32_t main()
{
	fast();
	// w(t)
	{
		mysol();
	}
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;

  if(s.size()>k){
    rep(i,k)  cout << s.at(i);
    cout << "..." << endl;
  }
  else cout << s << endl;
  return 0;
}

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

#define ll long long
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

int n, r;
string s;

main(){
    cin >> n >> s;
    for (int i = 0; i < n; i++)
        if (s[i] == 'R')
            r++;
    if (r > n - r)
        puts("Yes");
    else
        puts("No");
}


Measured memory_bytes: 256
using namespace std;
int main(){
	int n,c; int coin[]={500,100,50,10,5,1};
	while(cin>>n,n){
		c=0,n=1000-n; for(int i=0;i<6;i++)c+=n/coin[i],n%=coin[i];
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#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>
#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;
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(){
	ll K,A,B;
	scan(K);scan(A);scan(B);
	ll ans=K+1;
	if(K>=A-1&&B>A){
		if((K-A+1)%2==0) ans=max(ans,(K-A+1)/2*(B-A)+A);
		else ans=max(ans,(K-A+1)/2*(B-A)+A+1);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
map<ii, int> cnt;
li binpow(int a, int b)
{
	if(b==0) return 1LL;
	int temp=binpow(a, b/2);
	if(b%2) return (temp*temp%MOD)*a%MOD;
	return temp*temp%MOD;
}
ii modif(ii x)
{
	if(x.se<0) 
	{
		x.fi=-x.fi;
		x.se=-x.se;
	}
	return x;
}
ii get_inv(ii x)
{
	return modif({-x.se, x.fi});
}
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	int n, cnt1=0, cnt2=0, cnt3=0;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		int a, b;
		cin>>a>>b;
		if(!a and !b) cnt1++;
		else if(!a and b) cnt2++;
		else if(a and !b) cnt3++;
		else 
		{
			int d=__gcd(a, b);a/=d;b/=d;
			cnt[modif({a, b})]++;
		}
	}
	int ans=(1+(binpow(2, cnt2)-1+binpow(2, cnt3)-1))%MOD;
	set<ii> us;
	for(auto temp: cnt)
	{
		ii a=temp.fi, b=modif(get_inv(temp.fi));
		if(us.count(a) or us.count(b)) continue;
		ans=ans*((binpow(2, cnt[a])+binpow(2, cnt[b])-1)%MOD)%MOD;
		us.insert(a);
		us.insert(b);
	}
	ans=ans+cnt1-1;
	while(ans<0) ans+=MOD;
	cout<<ans;
}




Measured memory_bytes: 53572
from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,k=MI()
    xx=set()
    yy=set()
    xy=[]
    for _ in range(n):
        x,y=MI()
        xy.append((x,y))
        xx.add(x)
        yy.add(y)
    xy.sort()
    xx=list(sorted(xx))
    yy = list(sorted(yy))
    xn=len(xx)
    yn=len(yy)
    ans=10**20
    for t in range(yn):
        y2=yy[t]
        for b in range(t):
            y1=yy[b]
            r=-1
            s=0
            i=j=0
            for l,x1 in enumerate(xx):
                while i<n and xy[i][0]<x1:
                    if y1 <= xy[i][1] <= y2: s -= 1
                    i += 1
                while s<k and r+1<xn:
                    r+=1
                    x2=xx[r]
                    while j<n and xy[j][0]<=x2:
                        if y1<=xy[j][1]<=y2:s+=1
                        j+=1
                if s>=k:
                    cur=(x2-x1)*(y2-y1)
                    if cur<ans:ans=cur
    print(ans)

main()

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

int main(void){
    lli h, w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    for(lli i = 0; i < h; i++){
        for(lli j = 0; j < w; j++){
            cin >> a.at(i).at(j);
        }
    }
    queue<pair<lli, lli>> q;
    for(lli i = 0; i < h; i++){
        for(lli j = 0; j < w; j++){
            if(a.at(i).at(j) == '#'){
                q.push({i, j});
            }
        }
    }
    lli k = -1;
    while(!q.empty()){
        lli s = q.size();
        while(s > 0){
            auto tmp = q.front();
            q.pop();
            lli i, j;
            i = tmp.first;
            j = tmp.second;
            if(i > 0 && a.at(i-1).at(j) != '#'){
                a.at(i-1).at(j) = '#';
                q.push({i-1, j});
            }
            if(i < h-1 && a.at(i+1).at(j) != '#'){
                a.at(i+1).at(j) = '#';
                q.push({i+1, j});
            }
            if(j > 0 && a.at(i).at(j-1) != '#'){
                a.at(i).at(j-1) = '#';
                q.push({i, j-1});
            }
            if(j < w-1 && a.at(i).at(j+1) != '#'){
                a.at(i).at(j+1) = '#';
                q.push({i, j+1});
            }
            s--;
        }
        k++;
    }
    cout << k << endl;
    return 0;
}


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

int main(){
	int n,start,end,S,E,m;
	while(cin>>n>>start>>end,n){
		int date[2400]={0},ans=0,tmp=0;
		for(;n>0;n--){
			int DATE[2400]={0};
			for(cin>>m;m;m--)for(cin>>S>>E;S<E;S++)DATE[S]=1;
			for(int i=0;i<2400;i++)date[i]+=(DATE[i]+1)%2;
		}
		for(;start<end;ans=max(ans,tmp),start++){
			if(start%100<60){
				if(date[start])tmp++;
				else tmp=0;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n)cin >> a[i];
  vector<ll> b(n);
  ll sum = 0;
  REP(i, n) b[i] = a[i] - i - 1;
  VSORT(b);
  ll mid[3] = {b[n / 2 - 1], b[n / 2], b[n / 2 + 1]};
  ll ans[3] = {0};
  REP(i, n){
    REP(j, 3) ans[j] += abs(b[i] - mid[j]);
  }
  SORT(ans, 3);
  cout << ans[0];
}


Measured memory_bytes: 3328
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>

using namespace std;

#define ll long long
#define pb push_back

vector<ll> v;
vector<ll> in;
ll dp[51][51];
ll n,a,b,c,sum,tail,num;
int rep,ina;
double ans;

void pre() {
	for(int i = 0; i <= n; i++) dp[i][i] = dp[i][0] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j < i; j++) {
			dp[i][j] = dp[i-1][j]+dp[i-1][j-1];
		}
	}
}

int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> a >> b;
	for(int i = 0; i < n; i++) {
		cin >> c;
		in.pb(c);
	}
	sort(in.begin(),in.end(),greater<ll>());
	for(int i = 0; i < a; i++) {
		sum += in[i];
	}
	cout << setprecision(6);
	cout << fixed;
	ans = (double) sum/a;
	tail = a-1;

	for(int i = a; i < b; i++) {
		sum += in[i];
		if((double) sum/(i+1) > ans) {
			tail = i;
		}
		ans = max(ans,(double)sum/(i+1));
	}
	pre();
	for(int i = 0; i <= n; i++) {
		if(in[i] == in[tail]) {
			rep++;
			if(i < a) {
				ina++;
			}
		}
	}
	if(ina < a) {
		num = dp[rep][ina];
	} else {
		for(int i = a; i <= b; i++) {
			num += dp[rep][i];
		}
	}
	cout << ans << "\n";
	cout << num << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int R,G,B,N;
    cin >> R >> G >> B >> N;
    int answer = 0;
    for(int i=0; i<=(N/R); i++){
        for(int j=0; j<=(N-R*i)/G; j++){
            if((N-R*i-G*j)%B==0) answer++;
        }
    }
    cout << answer;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    char num[1024];
    while(1) {
        fgets(num, 1024, stdin);
        if(*num=='0') break;
        int sum=0;
        char *p;
        for(p=num; *p&&*p!='\n'; p++)
            sum+=*p-'0';
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int R;
	cin>>R;
	if(R<1200){cout<<"ABC";}
	else if(R<2800){cout<<"ARC";}
	else cout<<"AGC";
}

Measured memory_bytes: 256
N=int(input())
X=list(map(int, input().split()))
"""
minX=min(X)
maxX=max(X)
"""
minE = 1000000000
for P in range(101):
  sum = 0
  for Xi in X:
    sum = sum + (Xi-P)**2
  if minE>sum:
    minE=sum
print(minE)

Measured memory_bytes: 3060
#include <array>
#include <iostream>
#include <vector>

int main()
{
    std::string s;
    std::cin >> s;
    int l, r;
    for (int a = 0; a < s.size(); a++) {
        if (s.at(a) == 'A') {
            l = a;
            break;
        }
    }
    for (int a = s.size() - 1; a >= 0; a--) {
        if (s.at(a) == 'Z') {
            r = a;
            break;
        }
    }
    std::cout << r - l + 1 << std::endl;
}

Measured memory_bytes: 3748