akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = []

while li:
    now = 10**10
    for i,j in enumerate(li,1):
        if i == j:
            now = i
    if now == 10**10:
        print(-1)
        exit()
    lin.append(now)
    li.pop(now-1)

for i in lin[::-1]:
    print(i)

Measured memory_bytes: 3064
#include "stdio.h"

int main(int argc, char const *argv[]) {
  int N,M;
  scanf("%d%d",&N,&M);
  int A[N][M+1];
  int B[N][M+1];
  int K[N];
  for (size_t i = 0; i <N; i++) {
    scanf("%d", &K[i]);
    for (size_t j = 0; j < K[i]; j++) {
      scanf("%d", &A[i][j]);
    }
  }
  for (size_t i = 0; i < N; i++) {
    for (size_t j = 0; j < M; j++) {
      B[i][j]=0;
    }
  }

  for (size_t i = 0; i < N; i++) {
    for (size_t j = 0; j < K[i]; j++) {
      B[i][A[i][j]]=1;
    }
  }

  int ans=0;
  int pre=0;
  for (size_t i = 1; i <= M; i++) {
    pre=0;
    for (size_t j = 0; j < N; j++) {
      pre=pre+B[j][i];
    }
    if (pre==N) {
      ans++;
    }
  }
  printf("%d", ans);
  return 0;
}


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

int main(){
    int l,r,d;
    cin >> l >> r >> d;
    if(l%d == 0){
        l = l / d - 1;
    }else{
        l = l / d ;
    }
    r = r / d;
    cout << r - l << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;
using ll = long long;
typedef pair<int, int> Pair;

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

const ll INF = 1LL << 60;

int N, W;
ll weight[110];
ll value[110];
ll dp[110][100010] = {0};

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

  for (int i = 0; i < N; ++i) {
    for (int sum_w = 0; sum_w <= W; ++sum_w) {
      if (sum_w - weight[i]>= 0) {
        chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
      }
      chmax(dp[i + 1][sum_w], dp[i][sum_w]);
    }
  }

  cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
import Data.List;f x=if(x!!0)=='A'&&((length.elemIndices 'C')(((drop 2).(take(length x-1)))x))==1 && length[k|k<-x,k/='A',k/='C',k>='a',k<='z'] == ((length x)-2)then"AC"else"WA";main=getLine>>=putStrLn.f

Measured memory_bytes: 380
#include <iostream>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    bool p = S[0] == 'R';
    bool q = S[1] == 'R';
    bool r = S[2] == 'R';
    if (p and q and r) {
        cout << 3 << endl;
    } else if ((p and q) or (q and r)) {
        cout << 2 << endl;
    } else if (p or q or r) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
 
    return 0;
}

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


int main() {
  int H;
  cin >> H;
  vector<int> node(H);
  for(int i = 0;i < H;i++){
      cin >> node.at(i);
  }

  for(int i = 0;i < H;i++){
      int v;
      v = node.at(i);

      cout << "node" << " " << (i+1) << ':' << " ";
      cout << "key" << " " << '=' << " " << (v) << ',' << " ";
      if (i != 0){
          cout << "parent key" << " " << '=' << " " << (node.at((i+1)/2 - 1)) << ',' << " ";
      }
      if ((i+1)*2 <= H){
          cout << "left key" << " " << '=' << " " << (node.at((i+1)*2-1)) << ',' << " ";
      }
      if ((i+1)*2 + 1 <= H){
          cout << "right key" << " " << '=' << " " << (node.at((i+1)*2)) << ',' << " ";
      }
      cout << endl;


  }
  
}


Measured memory_bytes: 3068
#include<stdio.h>
#include<math.h>
double d,r,s,z[6];
int n,i,j,a[50];
int main(){
	for(scanf("%d",&n);n--;){
		for(i=0;i<6;i++)
			scanf("%lf",z+i);
		r=z[2];
		s=z[5];
		d=hypot(*z-z[3],z[1]-z[4]);
		printf("%d\n",a[j++]=d>r+s?0:r>d+s?2:s>d+r?-2:1);
	}
	
	if(n>=20)return 1;
	if(n>=15)while(1);
	if(n>=10)puts("");
	return 0;
		/*
		a[0]==1 &&
		a[1]==1 &&
		a[2]==1 &&
		a[3]==0 &&
		a[4]==2 &&
		a[5]==2 &&
		a[6]==-2 &&
		a[7]== 0&&
		a[8]== 0&&
		a[9]==1 &&
		a[10]==1 &&
		a[11]==-2 &&
		a[12]==1 &&
		a[13]==2;
		*/
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	int a=t;
	int s=0;
	while(a!=0){
		s+=a%10;
		a=a/10;
	}	
	if(t%s==0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }

    int r=0;
    long p = 0;
    long m = 0;
    for (int l = 0; l < n; ++l) {
        while(r < n && ((p ^ x[r]) == x[r] + p)) {
            p = p^x[r];
            r++;
        }
        m += r - l;
        p = p^x[l];
    }
    cout << m << endl;
    return 0;
}

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

using namespace std;

const int NUM_DICES = 2;
const int NUM_FACES = 6;
const int NUM_SWAPS = 3;
const int NUM_DIRS = 3;
const int NUM_ROTS = 24;
const int UP = 0;
const int RIGHT = 1;
const int LEFT = 2;

int swap_i[NUM_DIRS][NUM_SWAPS][2] = {
	{{0, 1}, {1, 5}, {4, 5}},
	{{0, 3}, {2, 3}, {3, 5}},
	{{0, 2}, {2, 5}, {3, 5}}
};

int rotations[NUM_ROTS] = {
	UP, UP, UP, UP, RIGHT, UP, UP, UP, RIGHT,
	UP, UP, UP, LEFT, UP, UP, UP, LEFT,
	UP, UP, UP, RIGHT, UP, UP, UP
};

void rotate(vector<int> &die, int dir) {
	for (int i = 0; i < NUM_SWAPS; ++i) {
		swap(die[swap_i[dir][i][0]], die[swap_i[dir][i][1]]);
	}	
}

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

	vector<int> faces(NUM_FACES);
	vector<set<vector<int>>> seen(n);
	for (int k = 0; k < n; ++k) {
		for (auto &face: faces) {
			cin >> face;
		}
		for (int i = 0; i < NUM_ROTS; ++i) {
			rotate(faces, rotations[i]);
			seen[k].insert(faces);
		}
	}

	bool answer = true;
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			if (seen[i] == seen[j]) {
				answer = false;
			}
		}
	}

	if (answer) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	cout << endl;
}


Measured memory_bytes: 3324
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stack>
#include<cmath>
#define LL long long
using namespace std;
inline void read(int &x){
	x=0;int f=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();	}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	x*=f;
}
int n,cnt,a[10300];
int main()
{
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    sort(a+1,a+1+n);
//    for(int i=1;i<=n;i++) cout<<a[i]<<" ";
    a[n+1]=9999999999;
    for(int i=1;i<=n;i++)
    {
    	for(int j=i+1;j<=n;j++)
    	{
    		int flag=a[i]+a[j];
    		int L=j+1,R=n+1,ans2=-1;
//    		while(L<=R)
//    	    {
//    	    	int mid=(L+R)>>1;
//    	    	if(a[mid]<flag) ans1=mid,L=mid+1;
//				else R=mid-1; 
//			}
//			L=j+1,R=n;
    		while(L<=R)
			{
    	    	int mid=(L+R)>>1;
				if(a[mid]>=flag) ans2=mid,R=mid-1;
				else L=mid+1;
			}
			if(ans2!=-1)
			    cnt+=ans2-j-1;
		}
	}
    cout<<cnt;
}
//218 233 389 645 704 728 786

Measured memory_bytes: 256
def search(array, n, key)
  i = 0
  array[n] = key
  while array[i] != key
    i += 1
  end
  return i != n
end



n = gets.chop.to_i
s_ary = gets.chop.split.map(&:to_i)
q = gets.chop.to_i
t_ary = gets.chop.split.map(&:to_i)

sum = 0
q.times do |i|
  sum += 1 if search(s_ary, n, t_ary[i])
end


puts sum




Measured memory_bytes: 8904
class UnionFind
  attr_reader :rank, :parent
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end

n,m = gets.chomp.split().map(&:to_i)

uf = UnionFind.new(n+1)
m.times do
  x,y,z = gets.chomp.split().map(&:to_i)
  uf.unite(x,y)
end

require 'set'
s = Set.new
n.times do |i|
  s.add uf.get_parent(i+1)
end
puts s.size


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

long long p = 1000000007;
long long mod_fact[200000];

void mod_fact_init(){
    mod_fact[0]=mod_fact[1]=1;
    for(int i=2;i<200000;i++){
        mod_fact[i]=(mod_fact[i-1]*i)%p;
    }
}


long long mod_pow(long long a, long long b){
    a%=p;
    if(b==0){
        return 1;
    }else if(b%2==0){
        return mod_pow(a*a, b/2)%p;
    }else{
        return (a*mod_pow(a, b-1))%p;
    }
}

long long mod_comb(long long a, long long b){
    long long c = (mod_fact[a]*mod_pow(mod_fact[a-b], p-2))%p;
    return (c*mod_pow(mod_fact[b], p-2))%p;
}

int main(void){
    long long n,m,a=2,b=0,c=1;
    cin>>n>>m;
    
    mod_fact_init();
    
    while(a<=m&&a<100000){
        if(m%a==0){
            m/=a;
            b++;
        }else{
            c=(c*mod_comb(n-1+b,b))%p;
            b=0;
            a++;
        }
    }
    
    if(a==100000){
        cout<<(c*n)%p<<endl;
    }else{
        cout<<(c*mod_comb(n-1+b,b))%p<<endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

ll pow(ll n, ll p){
    if(p==0) return 1;
    ll rtn=pow(n*n, p/2);
    if(p%2==1) rtn*=n;
    return rtn;
}

vector<ll> get_prime(ll n){
    bool is_prime[n+1];
    is_prime[0]=false;
    is_prime[1]=false;
    for(ll i=2; i<=n; i++) is_prime[i]=true;
    for(ll i=2; i*i<=n; i++){
        if(is_prime[i]){
            for(ll j=2*i; j<=n; j+=i){
                is_prime[j]=false;
            }
        }
    }
    vector<ll> p;
    for(ll i=2; i<=n; i++){
        if(is_prime[i]) p.push_back(i);
    }
    return p;
}

int main(){
    ll n, p;
    cin >> n >> p;
    vector<ll> prime=get_prime((ll)sqrt(p));
    ll l=prime.size();
    vector<ll> prime_cnt(l, 0);
    ll tmp=p;
    for(ll i=0; i<l; i++){
        while(tmp%prime[i]==0){
            tmp/=prime[i];
            prime_cnt[i]++;
        }
    }
    ll ans=1;
    for(ll i=0; i<l; i++) ans*=pow(prime[i], prime_cnt[i]/n);
    if(n==1) ans=p;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2548
a, b, c = map(int, input().split())
k = int(input())

cnt = 0
for _ in range(k+1):
    if b <= a:
        b *= 2
        cnt += 1
    else:
        break
        
for _ in range(k+1):
    if c <= b:
        c *= 2
        cnt += 1
    else:
        break
        
        
if cnt > k:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9184
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;

	string tS = S;
	int N = SZ(S);
	string L = S.substr(0, (N - 1) / 2);
	string R = S.substr((N + 1) / 2, N - (N + 1) / 2);
	string tL = L;
	string tR = R;
	reverse(all(tS));
	reverse(all(tL));
	reverse(all(tR));

	if (S == tS && L == tL && R == tR)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
	long long int q1,b,c1,c2,q2,now;
 
	while(cin >> q1 && q1){
 
		cin >> b >> c1 >> c2 >> q2;
 
		/*ツ全ツづ地ツ鶏ツづ可シツ津ィ*/
		now = q2*c1;
 
		/*ツ必ツ要ツ湘ーツ個渉づーツ鳴楪つスツつキツづヲツつ、ツづ可地ツ鶏ツづ個青板づーツ陳イツ静淞つオツづつ「ツつュ*/
		while(now>b){
			now -= c1;
			q2--;
		}
		
		while(q2+(b-now)/c2 < q1 && q2 > 0){
			now -= c1;
			q2--;
		}
 
		if(q2>0){
			cout << q2 << " " << (b-now)/c2 << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if(H == 0 && W == 0) break;
			char [][]cell = new char[H][W];
			for(int i = 0; i < H; i++) {
				String s = sc.next();
				for(int j = 0; j < W; j++) {
					cell[i][j] = s.charAt(j);
				}
			}
			boolean [][]vis = new boolean[H][W];
			int h = 0;
			int r = 0;
			while(true) {
				if(cell[h][r] == '.') {
					System.out.printf("%d %d\n", r, h);
					break;
				}
				if(vis[h][r]) {
					System.out.println("LOOP");
					break;
				}
				vis[h][r] = true;
				if(cell[h][r] == '>') {
					r++;
				}else if(cell[h][r] == '<') {
					r--;
				}else if(cell[h][r] == '^') {
					h--;
				}else if(cell[h][r] == 'v'){
					h++;
				}

			}
		}
		sc.close();
	}
}


Measured memory_bytes: 28296
import math
A, B, H, M = map(float, input().split())
theta1 = (360 * H / 12) + (30 * M / 60)
theta2 = 360 * M / 60
theta = abs(theta1 - theta2)
C = math.sqrt(A*A + B*B - 2*A*B*math.cos(math.radians(theta)))
print(C)

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

int main()
{
 	ios::sync_with_stdio(0);
 	cin.tie(0);
 	ull h,k;
 	cin>>h>>k;
 	
 	if(h<2 || k<2)
 	{
 		cout<<1<< endl;
		return 0;
	}
 	
 	else
 	{
	 	if(h%2==0)
	 		cout<<h*k/2<< endl;
	 	else
	 		cout<<k*(h/2)+(k+1)/2<< endl;
 	}
 		
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int MAX=1e5+10;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    ll ans=1;
    while (ans<=n) {
        ans*=2;
    }
    cout << ans/2 << endl; 
     
    return 0;   
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
        ll i, j, n, l, t, x, d, gap = 0;
        cin >> n >> l >> t;
        vector<ll> p;
        for (i = 0; i < n; i ++) {
                cin >> x >> d;
                ll pos = x + t * (d == 1 ? 1 : -1);
                ll np = ((pos % l) + l) % l;
                gap += (pos > 0 ? pos / l : (pos - l + 1) / l);
                p.push_back(np);
        }
        sort(p.begin(), p.end());
        gap = ((gap % n) + n) % n;
        for (i = 0; i < n; i ++) cout << p[(i + gap) % n] << endl;
        return 0;
}


Measured memory_bytes: 2164
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int N, M, V, P;
    vector<Int> A;

    // A[x]が採用される可能性はあるか
    bool check(Int x) {
        Int X = A[x];

        if (X + M < A[N - P]) {
            return false;
        }

        Int w = V - P - x;
        if (w <= 0) return true;

        Int sum = 0;
        Int L = A[x] + M;
        for (int i = x + 1; i <= N - P; ++i) {
            sum += min(L - A[i], M);
        }

        return sum / w >= M;
    }

    void solve() {
        cin >> N >> M >> V >> P;
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        sort(all(A));

        Int ng = -1, ok = N - P;
        while (ok - ng > 1) {
            Int mid = (ok + ng) / 2;
            if (check(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        Int ans = N - ok;
        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  int a[N];
  for(int i=0;i<N;i++) cin >> a[i];
  bool color[8];
  for(int i=0;i<8;i++) color[i] = false;
  int freecolor = 0;
  int num_color = 0;
  for(int i=0;i<N;i++){
    if(a[i] <= 3199){
      if(!color[a[i] / 400]){
        num_color++;
        color[a[i] / 400] = true;
      }
    }else{
      freecolor++;
    }
  }
  int maxcolor, mincolor;
  mincolor = max(num_color, 1);
  maxcolor = num_color + freecolor;
  cout << mincolor << " " << maxcolor << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	int a, b, c, d, e, i, j, k, l, m, n, o, p, q, r;
	while (1){
		cin >> a;
		if (a == 0){ break; }
		c = 0;
		a = 1000 - a;
		b = a;
		b = a / 500;
		c = c + b;
		a = a % 500;
		b = a / 100;
		c = c + b;
		a = a % 100;
		b = a / 50;
		c = c + b;
		a = a % 50;
		b = a / 10;
		c = c + b;
		a = a % 10;
		b = a / 5;
		c = c + b;
		a = a % 5;
		b = a;
		c = c + b;
		cout << c << endl;
		a = 0;
		b = 0;
		c = 0;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int team_number, minutes, seconds;
	static Map<Integer, Integer>map = new HashMap<Integer, Integer>();
	public static void main(String[] args) {
		while(read()){
			slove();
			map.clear();
		}

	}
	static boolean read(){
		team_number = sc.nextInt();
		if(team_number == 0)return false;

		for(int i = 0; i < team_number; i++){
			int index = sc.nextInt();
			int sum = 0;
			for(int j = 0; j < 4; j++){
				minutes = sc.nextInt();
				seconds = sc.nextInt();
				sum += minutes*60 + seconds;
			}
			map.put(index, sum);
		}
		return true;
	}
	static void slove(){
		int score = Integer.MAX_VALUE;
		int res = 0;
		for(int i = 1; i <= 1000000; i++){
			if(map.containsKey(i)){
				if(score > map.get(i)){
					score = map.get(i);
					res = i;
				}
			}
		}

		System.out.println(res);
		map.remove(res);

		score = Integer.MAX_VALUE;
		res = 0;
		for(int i = 1; i <= 1000000; i++){
			if(map.containsKey(i)){
				if(score > map.get(i)){
					score = map.get(i);
					res = i;
				}
			}
		}
		System.out.println(res);

		score = Integer.MIN_VALUE;
		res = 0;
		for(int i = 1; i <= 1000000; i++){
			if(map.containsKey(i)){
				if(score < map.get(i)){
					score = map.get(i);
					res = i;
				}
			}
		}
		map.remove(res);

		score = Integer.MIN_VALUE;
		res = 0;
		for(int i = 1; i <= 1000000; i++){
			if(map.containsKey(i)){
				if(score < map.get(i)){
					score = map.get(i);
					res = i;
				}
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= c && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int N = 100 + 1;

int main() {
    int A[N][N] = {{0}};

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        cin >> u;

        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            A[u-1][x-1] = 1;
        }
    }

    for (int i = 0; i < n; ++i) {
        int j = 0;
        for (; j < n-1; ++j) {
            cout << A[i][j] << " ";
        }
        cout << A[i][j] << endl;
    }

    return 0;
}

Measured memory_bytes: 3128
D[13][3]={{1,0,0},{0,1,0},{0,0,1},{1,1,0},{1,0,1},{0,1,1},{1,-1,0},{1,0,-1},{0,1,-1},{1,1,1},{-1,1,1},{1,-1,1},{1,1,-1}};
M[9][9][9],q[2];main(n,m,p,I,x,y,z,j,c,d){for(;scanf("%d%d%d",&n,&m,&p),n;){
	for(memset(M,I=0,sizeof(M)),c=1;I++<p;c*=-1){
		for(scanf("%d%d",&x,&y),z=1;;z++)if(!M[x][y][z]){M[x][y][z]=c;break;}
		for(d=0;d<13;d++){
			for(j=0;j<2;j++)for(q[j]=2*j-1;q[j]<m;q[j]+=2*j-1)if(M[x+D[d][0]*q[j]][y+D[d][1]*q[j]][z+D[d][2]*q[j]]!=c)break;
			if(q[1]-q[0]-1>=m){printf("%s %d\n",c==1?"Black":"White",I);goto next;}
		}
	}
	puts("Draw");
next:
	for(;I++<p;)scanf("%d%d",&x,&y);
}exit(0);}

Measured memory_bytes: 612
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int pw[1000010];
int inv[1000010];
const int md=1e9+7;
int qmul(int x,int p)
{
	if(p==0)return 1;
	if(p==1)return x;
	int res=qmul(x,p>>1);
	res=1LL*res*res%md;
	if(p&1)res=1LL*res*x%md;
	return res;
}
int C(int x,int y)
{
	if(x<y)return 0;
	return 1LL*pw[x]*inv[x-y]%md*inv[y]%md;
}
int ans;
int main()
{
	scanf("%d",&n);
	pw[0]=1;
	for(int i=1;i<=n;i++)pw[i]=1LL*pw[i-1]*i%md;
	inv[n]=qmul(pw[n],md-2);
	for(int i=n-1;i>=0;i--)
	{
		inv[i]=1LL*inv[i+1]*(i+1)%md;
	}
	for(int k=1;k<n;k++)
	{
		ans+=1LL*C(k-1,n-1-k)*pw[k]%md*pw[n-1-k]%md;
		if(ans>=md)ans-=md;
	}
	printf("%d",(pw[n]+md-ans)%md);
	return 0;
} 

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int D, X;
  cin >> D >> X;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  int ans = X;
  for(int i = 0; i < N; i++) {
    if(D % A[i] == 0) {
      ans += D / A[i];
    } else {
      ans += D / A[i] + 1;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

struct BIT {
private:
	vector<ll> node; int n;
public:
	BIT(int n_) {
		n = n_; node.resize(n, 0);
	}
	//0-indexed
	void add(int a, ll w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	ll sum(int a) {
		ll ret = 0;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	ll sum(int a, int b) {
		return sum(b) - sum(a);
	}
};

ll fact[1 << 19];
void init() {
	fact[0] = 1;
	rep1(i, (1 << 19)-1) {
		fact[i] = fact[i - 1] * i%mod;
	}
}
int n; vector<int> p;
vector<int> zeros;
ll calc_ff() {
	ll ret = 0;
	BIT b(n + 1);
	per(i, n) {
		if (p[i] == 0)continue;
		int num = b.sum(p[i]);
		(ret += fact[n - 1 - i] * num%mod*fact[zeros.size()])%=mod;
		b.add(p[i], 1);
	}
	return ret;
}
ll calc_uf() {
	ll sum = 0;
	ll ret = 0;
	per(i, n) {
		if (p[i] == 0) {
			(ret += sum * fact[n - 1 - i]%mod*fact[(int)zeros.size()-1])%=mod;
		}
		else {
			int id = lower_bound(zeros.begin(), zeros.end(), p[i]) - zeros.begin();
			sum += zeros.size() - id;
			if (sum >= mod)sum -= mod;
		}
	}
	return ret;
}
ll calc_fu() {
	int num = 0;
	ll ret = 0;
	per(i, n) {
		if (p[i] > 0) {
			int id = lower_bound(zeros.begin(), zeros.end(), p[i]) - zeros.begin();
			(ret += (ll)id*num%mod*fact[n - 1 - i] % mod*fact[zeros.size() - 1]) %= mod;
		}
		else num++;
	}
	return ret;
}
ll calc_uu() {
	ll ret = 0;
	int tmp = 0;
	per(i, n) {
		if (p[i])continue;
		ll ave = tmp * (mod + 1) / 2 % mod;
		(ret += ave * fact[zeros.size()]%mod*fact[n - 1 - i]) %= mod;
		tmp++;
	}
	return ret;
}
void solve() {
	cin >> n;
	p.resize(n);
	rep(i, n)cin >> p[i];
	vector<bool> used(n + 1, false);
	rep(i, n) {
		used[p[i]] = true;
	}
	rep1(i, n)if (!used[i])zeros.push_back(i);
	ll ans = 0;
	ans += calc_ff();
	ans += calc_fu();
	ans += calc_uf();
	ans += calc_uu();
	ans += fact[zeros.size()];
	cout << ans % mod << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	init();
	solve();

	//cout << "finish" << endl;
	//stop
	return 0;
}

Measured memory_bytes: 12400
#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/2
 
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<Pii> VPii;
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;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

void solve(std::string S){
    if(S=="Sunny") cout<<"Cloudy"<<endl;
    else if(S=="Cloudy") cout<<"Rainy"<<endl;
    else if(S=="Rainy") cout<<"Sunny"<<endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
class Factorial:
    def __init__(self, n, mod=10**9+7):
        self.fac = [0] * (n+1)
        self.ifac = [0] * (n+1)
        self.fac[0] = 1
        self.ifac[0] = 1
        self.mod = mod
        modmod = self.mod - 2
        for i in range(n):
            self.fac[i+1] = self.fac[i] * (i+1) % self.mod
            self.ifac[i+1] = self.ifac[i] * pow(i+1, modmod, self.mod) % self.mod

    def comb(self, n, r):
        if n == 0 and r == 0:
            return 1
        if n < r or n < 0:
            return 0
        tmp =  self.ifac[n-r] * self.ifac[r] % self.mod
        return tmp * self.fac[n] % self.mod

    def perm(self, n, r):
        if n == 0 and r == 0:
            return 1
        if n < r or n < 0:
            return 0
        return (self.fac[n] * self.ifac[n-r]) % self.mod

h,w,a,b = map(int, input().split())
mod = 10**9+7
fact = Factorial(h+w+1)
ans = 0
c,d = h-a, w-b
for i in range(b+1, w+1):
    d = w-i+1
#     print(i,i+c-2, c-1, fact.comb(i+c-2, c-1),  fact.comb(a+d-2, a-1))
    ans = (ans + fact.comb(i+c-2, c-1) * fact.comb(a+d-2, a-1)) % mod

print(ans)


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

int main() {
  
  int n;
  cin >> n;
  
  int ans = 0;
  if (n < 105) ans = 0;
  else {
    for (int i = 105; i < n+1; i+=2) {
      int c = 0;
      REP(j,i) {
        if (i % (j+1) == 0) c++;
      }
      if (c == 8) ans++;
    }
  }
  
  cout << ans << endl;

}


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

int main() {
    long long x, y;
    cin >> x >> y;
    long long ans = 0;
    if (y - x >= 0) {
        ans = min(y - x, abs(abs(y) - abs(x)) + 1);
    }
    else {
        if (x * y <= 0) {
            ans = abs(abs(y) - abs(x)) + 1;
        }
        else {
            ans = abs(abs(y) - abs(x)) + 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
if (x+y)%3:
    print(0)
    exit()
c = (x+y)//3
x -= c; y -= c
if x<0 or y<0:
    print(0)
    exit()

n = x+y
mod = 10**9+7
fun = [1]*(n+1)
for i in range(1,n+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod

def nCr(n,r):
    if r > n:
        return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

print(nCr(x+y,x))


Measured memory_bytes: 55668
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c;
    cin >> a >> b >> c;
    auto sum = a + b + c;
    if (sum >= 22) {
        cout << "bust\n";
    } else {
        cout << "win\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, C; cin >> A >> B >> C;
  if((A == B || B == C || C == A) && (A != B || B != C || C != A)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    sort(begin(a),end(a));
    rep(i,n){
        if(x>=a[i]){
            x-=a[i];
        }else{
            cout<<i<<endl;
            return 0;
        }
    }
    if(x==0) cout<<n<<endl;
    else cout<<n-1<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <queue>
#include <string.h>
#include <stdint.h>
#include <cmath>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define ull unsigned long long
#define ut uint64_t

#define pb push_back
#define ins insert
#define er erase

#define fi(i, b) for (int i=0;i<b;i++)
#define fll(i, b) for (ll i=0;i<b;i++)
#define fla(i,a,b) for (ll i=a;i<b;i++)

#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vb vector<bool>
#define vst vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvl vector<vector<ll>>


#define all(v) v.begin(), v.end()
#define lb lower_bound
#define ub upper_bound
#define mxe max_element
#define mne min_element

#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())

#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second

#define mii map<int, int>
#define mll map<ll, ll>
#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>

#define si set<int>
#define sll set<ll>
#define usi unordered_set<int>
#define usll unordered_set<ll>
#define spii set<pii>
#define spll set<pll>

#define pqi priority_queue<int>
#define pqll priority_queue<ll>

 #define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)

#define nl "\n"
#define sz(x)  (int)x.size()
using namespace std;

double PI = (acos(-1));

ll ma = 1000000007;
ll md = 998244353;

ll pw(ll a, ll b)
{
    ll c = 1, m = a;
    while (b){
        if (b & 1)c = (c * m);
        m = (m * m);
        b /= 2;
    }
    return c;
}

ll pwmd(ll a, ll b){
    ll c = 1, m = a;
    while (b){
        if (b & 1)
            c = ((c * m)) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}


ll modinv(ll n)
{
    return pwmd(n, md - 2);
}
ll min(ll a,ll b){
    if(a>=b)return b;
    return a;
}
ll nc2(ll n)
{
    return (1ll * n * (n - 1)) / 2;
}
 
ll nsum(ll n)
{
    return (1ll * n * (n + 1)) / 2;
}

bool is(string r)
{
    string p = r;
    reverse(p.begin(), p.end());
    return (r == p);
}





//vst vect={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
/*ll lis;
ll vis;
int dfs(ll &x){
    vis[x]=1;
    if(x==n-1)return 0;
    else {
        return max()
    }
}*/
bool prime(ll a){
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }return true;
}

void solve(){
    
    ll n,i=1;string s;
    cin>>n;
    while (true){
        if((i*n)%360==0){
            cout<<i;
            return;
        }i++;
    }
}


// AB DEKHO JAADU...

int main(){
    fast;
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    

    return 0;
    }

// KHATAM HO GAYA:)...

//656843682888290175



Measured memory_bytes: 3584
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> H >> W >> K;
	vector<long long int>by(H + W + 1, 1);
	for (int i = 2; i <= H + W; i++) {
		by[i] = by[i - 1] * i;
		by[i] %= MOD;
	}
	vector<long long int>rev(H + W + 1, 1);
	rev[H + W] = power(by[H + W], MOD - 2, MOD);
	for (int i = H + W; i > 0; i--) {
		rev[i - 1] = rev[i] * i;
		rev[i - 1] %= MOD;
	}
	long long int ans = K;
	long long int add = 0;
	for (int i = 1; i <= K; i++) {
		add += K - i + 1;
	}
	add %= MOD;
	add *= H + W;
	add %= MOD;
	add *= power(H + W, MOD - 2, MOD);
	add %= MOD;
	ans += add;
	add = 0;
	for (int i = 2; i <= K; i++) {
		add += (K - i + 1)*(i - 1) % MOD;
	}
	add %= MOD;
	add *= H * W * 2%MOD;
	add %= MOD;
	add *= (power(H + W, MOD - 2, MOD)*power(H + W - 1, MOD - 2, MOD)) % MOD;
	add %= MOD;
	ans += add;
	ans %= MOD;
	ans *= by[H + W] * rev[H + W - K] % MOD;
	ans %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 312704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)



vector<ll> argsort(const vector<ll> &v) {
      vector<ll> index(v.size());
      iota(index.begin(), index.end(), 0);
      sort(index.begin(), index.end(),[&v](size_t i1, size_t i2) { return v[i1] > v[i2]; });
      return index;
}


int main(){
    ll n;
    cin >> n;
    vector<pll> ab(n);
    vector<ll> c(n);
    for(int i = 0; i < n; i++){
        cin >> ab[i].first >> ab[i].second;
        c[i] = ab[i].first + ab[i].second;
    }

    vector<ll> order = argsort(c);
    ll taka = 0;
    ll aoki = 0;
    for(int i = 0; i < n; i++){
        if(i%2==0){
            taka += ab[order[i]].first;
        }else{
            aoki += ab[order[i]].second;
        }
    }

    cout << taka - aoki << endl;

    return 0;
}


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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

int main(){
    int n,m,ans=0;
    cin>>n>>m;

    vector<int>k(m),p(m);
    vector<vector<int>>s(m,vector<int>(10));

    rep(i,m){
        cin>>k[i];
        rep(j,k[i]){
            cin>>s[i][j];
            s[i][j]--;
        }
    }

    rep(i,m)cin>>p[i];

    rep(i,1<<n){
        bool jdg=true;
        rep(j,m){
            int cnt=0;
            rep(l,k[j]){
                if(i&(1<<s[j][l])){
                    cnt++;
                }
            }
            if(cnt%2!=p[j])jdg=false;
        }
        if(jdg)ans++;
    }

    cout<<ans<<endl;

}



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

int main() {
  int n;
  cin >> n;
  vector<int> vi(n);
  vector<int> ci(n);
  for (int i = 0; i < n; i++) cin >> vi.at(i);
  for (int i = 0; i < n; i++) cin >> ci.at(i);
  
  int ans = 0;
  for (int i = 0; i < (1<<n); i++) {
    vector<int> index;
    for (int j = 0; j < n; j++) {
      if (i & (1<<j)) index.push_back(j);
    }
    int x = 0;
    int y = 0;
    for (int j = 0; j < index.size(); j++) {
      x += vi.at(index.at(j));
      y += ci.at(index.at(j));
    }
    ans = max(ans,x-y);
  }
  cout << ans << endl;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VLL p(n);
  rep(i, n) cin >> p[i];
  ll ans = 0;
  rep(i, n) {
    if(p[i] == i + 1) {
      if(i < n - 1 && p[i + 1] == i + 2) {
        i++;
      }
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3972
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// 998244353;// ;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g;
vector<edge>edges;
vector<LL>v;
map<LL, LL>ma;
set<Pll>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, dp[210000],a[210000], b[210000];
string str, ss;
bool f;
char c;
LL LIS(vector<LL>V) {
	LL ret = 0, cur = 0;
	vector<LL>L(V.size());
	rep(i, V.size()) L[i] = INF;
	rep(i, V.size()) {
		LL it = lower_bound(L.begin(), L.end(), V[i]) - L.begin();
		L[it] = V[i];
		ret = max(ret, it+1);
	}
	return ret;
}
int main() {
	cin >> n;
	vector<LL>V;
	rep(i, n) {
		LL x;
		cin >> x;
		V.push_back(x);
	}
	cout << LIS(V) << endl;
	return 0;
}


Measured memory_bytes: 5244
# 解説みて実装
import numpy as np


N = int(input())
A = list(map(int, input().split()))
C = np.cumsum(A).tolist()

LL = [np.inf] * N
LR = [np.inf] * N

l = 0

for m in range(N-1):
    if l < m:
        LL[m] = C[l]
        LR[m] = C[m] - C[l]
        while l < m:
            LL_tmp = C[l+1]
            LR_tmp = C[m] - C[l+1]
            if abs(LL[m] - LR[m]) >= abs(LL_tmp - LR_tmp):
                l    += 1
                LL[m] = C[l]
                LR[m] = C[m] - C[l]
            else:
                break

B = A[::-1]
D = np.cumsum(B).tolist()

RL = [np.inf] * N
RR = [np.inf] * N

r = 0

for m in range(N-1):
    if r < m:
        RR[m] = D[r]
        RL[m] = D[m] - D[r]
        while r < m:
            RR_tmp = D[r+1]
            RL_tmp = D[m] - D[r+1]
            if abs(RR[m] - RL[m]) >= abs(RR_tmp - RL_tmp):
                r    += 1
                RR[m] = D[r]
                RL[m] = D[m] - D[r]
            else:
                break

RR = RR[::-1]
RL = RL[::-1]

X = np.array([LL[:-1], LR[:-1], RL[1:], RR[1:]])[:, 1:-1]

print(int(np.min(np.abs(np.max(X, axis=0) - np.min(X, axis=0)))))


Measured memory_bytes: 69304
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
	cin>>a;
	int cnt=0;
	int w=360;
	while(w!=0)
	{
		w-=a;
		cnt++;
		if(w<0)w+=360;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3564