akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

struct Edge {
    int a, b, color;
    Edge(int a=-1, int b=-1, int c=-1): a(a), b(b), color(c) {}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, a, b;
    cin >> n;
    vector<Pii> graph[n];   // 行き先と，エッジのインデックス
    vector<Edge> edges(n-1);
    for(int i=0;i<n-1;++i){
        cin >> a >> b;
        --a; --b;
        graph[a].emplace_back(b, i);
        graph[b].emplace_back(a, i);
        edges[i].a = a;
        edges[i].b = b;
    }

    int k = 0;
    for(int i=0;i<n;++i) k = max(k, int(graph[i].size()));

    for(int i=0;i<n;++i) {
        int color = 1, j, idx;
        vector<bool> used(k+1, false);
        for(Pii p: graph[i]) {
            tie(j, idx) = p;
            if(edges[idx].color == -1) continue;
            used[edges[idx].color] = true;
        }
        for(Pii p: graph[i]) {
            tie(j, idx) = p;
            if(i > j) continue;
            while(color < k && used[color]) color++;
            edges[idx].color = color++;
        }
    }

    cout << k << endl;
    for(int i=0;i<n-1;++i) {
        cout << edges[i].color << endl;
    }
}


Measured memory_bytes: 7680
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int n;
    cin >> n;
    VI H(n);
    REP(i,n){
        cin >> H[i];
    }

    int tans = 0; //継続数を記録する変数
    int ans = 0; //答え
    for(int i = n-1; i > 0; i--){
        if(H[i-1] >= H[i]){
            tans++;
        }else{
            if(tans >= ans){
                ans = tans;
                tans = 0;
            }else{
                tans = 0;
            }
        }
    }
    if(tans >= ans) ans = tans;

    cout << ans << endl;
}


Measured memory_bytes: 640
# coding: utf-8
import queue

class Dinic:
    """Implementation of Dinic's Alogorithm"""

    def __init__(self, v, inf = 1000000007):
        self.V = v
        self.inf = inf
        self.G = [[] for _ in range(v)]
        self.level = [0 for _ in range(v)]
        self.iter = [0 for _ in range(v)]

    def add_edge(self, from_, to, cap):
        # to: 行き先, cap: 容量, rev: 反対側の辺
        self.G[from_].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
        self.G[to].append({'to':from_, 'cap':0, 'rev':len(self.G[from_])-1})

    # sからの最短距離をbfsで計算
    def bfs(self, s):
        self.level = [-1 for _ in range(self.V)]
        self.level[s] = 0;
        que = queue.Queue()
        que.put(s)
        while not que.empty():
            v = que.get()
            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if e['cap'] > 0 and self.level[e['to']] < 0:
                    self.level[e['to']] = self.level[v] + 1
                    que.put(e['to'])

    # 増加バスをdfsで探す
    def dfs(self, v, t, f):
        if v == t: return f
        for i in range(self.iter[v], len(self.G[v])):
            self.iter[v] = i
            e = self.G[v][i]
            if e['cap'] > 0 and self.level[v] < self.level[e['to']]:
                d = self.dfs(e['to'], t, min(f, e['cap']))
                if d > 0:
                    e['cap'] -= d
                    self.G[e['to']][e['rev']]['cap'] += d
                    return d

        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            # bfsで到達不可
            if self.level[t] < 0 : return flow
            self.iter = [0 for _ in range(self.V)]
            f = self.dfs(s, t, self.inf)
            while f > 0:
                flow += f
                f = self.dfs(s,t, self.inf)

if __name__ =="__main__":
    H,W=map(int,input().split())
    a=[list(input()) for i in range(H)]
    Dn=Dinic(2+H+W)
    INF=10**15
    #0,1~H,H+1~H+1+W.H+W+1
    #0 1+range(H),H+1+range(W),H+W+1
    s=(-1,-1)
    t=(-1,-1)
    for i in range(H):
        for j in range(W):
            if a[i][j]!=".":
                Dn.add_edge(i+1,H+1+j,1)
                Dn.add_edge(H+1+j,i+1,1)
            if a[i][j]=="S":
                Dn.add_edge(0,i+1,INF)
                Dn.add_edge(0,H+1+j,INF)
                s=(i,j)
            if a[i][j]=="T":
                Dn.add_edge(i+1,H+W+1,INF)
                Dn.add_edge(H+1+j,H+W+1,INF)
                t=(i,j)
    if s[0]==t[0] or s[1]==t[1]:
        print(-1)
    else:
        ans=Dn.max_flow(0,1+H+W)
        print(ans)


Measured memory_bytes: 58600
def srch_all(ptn, str):
    index = []
    i = -1
    while True:
        i = str.find(ptn, i + 1)
        if i > -1:
            index.append(i)
        else:
            break
    return index

def judge(i, jlist, len):
    for l in jlist:
        k = 1
        while k < M:
            try:
                if n[i + 1][l:l + len] == m[k]:
                    pass
                else:
                    return 'No'
            except:
                return 'No'
            i += 1
            k += 1
        else:
            return 'Yes'

N, M = map(int, input().split())
i = 0
n = []
while i < N:
    n.append(input())
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

i = 0
r = 'No'
while i < N:
    result = srch_all(m[0], n[i])
    if len(result) > 0:
        r = judge(i, result, len(m[0]))
        if r == 'Yes':
            break
    i += 1
print(r)

Measured memory_bytes: 3064
n = int(input())

#約数取得
def make_divisors(n):
    divisors_keta = []
    i = 1
    while i*i <= n:
        if n % i == 0:
            divisors_keta.append(max(len(str(i)), len(str(n//i))))
            #print(i, n/i, len(str(i)), len(str(n//i)))
        i += 1
    return divisors_keta

keta_min_sort = sorted(make_divisors(n))

#print(keta_min_sort)
print(keta_min_sort[0])

Measured memory_bytes: 9176
# -*- coding: utf-8 -*-
import numpy as np

H, W = map(int, input().split())
S = [input() for x in range(H)]

L = np.zeros([H, W], dtype=int)
R = np.zeros([H, W], dtype=int)
U = np.zeros([H, W], dtype=int)
D = np.zeros([H, W], dtype=int)

S_ = np.zeros([H, W], dtype=int)
for h in range(H):
    for w in range(W):
        if S[h][w] == '#': S_[h, w] = 0
        else: S_[h, w] = 1
L[:, 0] = S_[:, 0]
for w in range(1, W):
    L[:, w] = (L[:, w-1] + 1) * S_[:, w]
R[:, W-1] = S_[:, W-1]
for w in range(W-2, -1, -1):
    R[:, w] = (R[:, w+1] + 1) * S_[:, w]
U[0] = S_[0]
for h in range(1, H):
    U[h] = (U[h-1] + 1) * S_[h]
D[H-1] = S_[H-1]
for h in range(H-2, -1, -1):
    D[h] = (D[h+1] + 1) * S_[h]

L = np.array(L)
R = np.array(R)
U = np.array(U)
D = np.array(D)
print(np.max(L+R+U+D)-3)

Measured memory_bytes: 235520
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n;
	string s;
	cin>>n>>s;
	int a[202020]={};
	FOR(i,0,n){
		if(s[i]=='#')a[i+1]=1;
		a[i+1]+=a[i];
	}
	int ans=mod;
	FORQ(i,0,n){
		int r=n-i-(a[n]-a[i]);
		int l=a[i];
		ans=min(ans,r+l);
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1412
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        
        if(a + b <= 23) {
        System.out.println(a + b);
        }  else if (a + b >= 24) {
        System.out.println(a + b - 24);
        }
    }
}

Measured memory_bytes: 23764
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
#define AC io()
const int mod = 1000000007;
//endregion


pls give {
    AC;
    int a, b, c;
    cin >> a >> b >> c;
    if (a+b+c >= 22) cout << "bust";
    else cout << "win";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Y = scanner.nextInt();
		scanner.close();
		
		if (Y % 1000 != 0 || N * 10000 < Y || N * 1000 > Y) {
			System.out.println("-1 -1 -1");
			return;
		}
		if (Y / 1000 == N) {
			System.out.println("0 0 " + N);
			return;
		}
		if (Y / 5000 == N) {
			System.out.println("0 " + N + " 0");
			return;
		}
		if (Y / 10000 == N) {
			System.out.println(N + " 0 0");
			return;
		}
		
		for (int i = 0; i < N; i++) {
			for (int i2 = 0; i2 < N; i2++) {
				for (int i3 = 0; i3 < N; i3++) {
					if (1000*i + 5000*i2 + 10000*i3 == Y && i + i2 + i3 == N) {
						System.out.println(i3 + " " + i2 + " " + i);
						return;
					}
					if (i + i2 + i3 > N) {
						break;
					}
				}
				if (i + i2 > N) {
					break;
				}
			}
		}
		System.out.println("-1 -1 -1");
		
	}
	
}

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

int main(){
  long long n;
  cin >> n;
  string res = "";
  if(n == 0) res += '0';
  long long i = 1;
  while(n){
    if(n % (2 * abs(i))){
      res += '1';
      n -= i;
    }else{
      res += '0';
    }
    i *= -2;
  }
  reverse(res.begin(), res.end());
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int s[11] = { 0 }, i, a=0;
	for (i = 1; i <= 10; i++) {
		scanf("%d", &s[i]);
		a = a + s[i];
	}
	printf("%d\n", a);
	return 0;
}


Measured memory_bytes: 2100
import bisect

def main():
  n, k, *lst = map(int, open(0).read().split())
  z = bisect.bisect_left(lst, 0)
  if not z:
    print(lst[k - 1])
  elif z >= n - 1:
    print(-lst[-k])
  else:
    res = float('inf')
    for i in range(max(z - k + 1, 0), min(z, n - k) + 1):
      tmp = lst[i + k - 1] - lst[i] + min(abs(lst[i]), lst[i + k - 1])
      if tmp < res:
        res = tmp
    print(res)

if __name__ == '__main__':
  main()

Measured memory_bytes: 14052
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define len(s) s.length()
#define forp(i,a,b) for( i=a;i<=b;i++)
#define rep(i,n)    for( i=0;i<n;i++)
#define ren(i,n)    for( i=n-1;i>=0;i--)
#define forn(i,a,b) for( i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define b(v) v.begin()
#define e(v) v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vii vector<int>
#define vll vector<long long>
#define gl(cin,s)  getline(cin,s);
#define bitc(n) __builtin_popcountll(n)
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
 
#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define SIZE 100001
#define SZ 101
 
typedef long long  ll;
typedef unsigned long long ull;
typedef long double  ldo;
typedef double  db ;
using namespace std;
long long dp[SZ][SIZE];
int N,W;
int We[SZ];
int Va[SZ];
long long func(int which,int rem)
{
    if(which > N)
    return 0LL;
    if(dp[which][rem] != -1)
    return dp[which][rem];
    long long fans = 0;
    fans = max(fans,func(which+1,rem));
    if(rem >= We[which])
    fans = max(fans,Va[which] + func(which+1,rem-We[which]));
    dp[which][rem] = fans;
    return fans;
}
int main()
{  	
	/* #ifndef ONLINE_JUDGE
	freopen(fi, "r", stdin);
	#endif */
	//freopen("route.in","r",stdin);
	//freopen("route.out","w",stdout);
	//cin.ignore();
	//cin.clear();
	boost;
	//cin.tie(0);
	//cout<<"Case "<<tt<<": ";
	cin>>N>>W;
	for(int i=1;i<=N;i++){
	    cin>>We[i]>>Va[i];
	}
	mem(dp,-1);
	cout<<func(1,W)<<endl;
	return 0;
}

Measured memory_bytes: 79232
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s == "SUN"){
cout << 7 << endl;
  } else if (s == "MON"){
cout << 6 << endl;
  } else if (s == "TUE"){
  cout << 5 << endl;
  } else if( s == "WED"){
 cout << 4 << endl;
  } else if (s == "THU"){
 cout << 3 << endl;
  }else if ( s == "FRI"){
 cout << 2 << endl;
    } else cout << 1 << endl;
  }


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(10**6)

def solve(a,b,c,counter=0):
    if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
        return counter
    elif a == b == c: 
        return -1
    else:
        return solve((b+c)//2,(c+a)//2,(a+b)//2,counter+1)


def main():
    A, B, C = map(int,input().split())
    print(solve(A,B,C))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000
#define vll vector<ll>
using namespace std;
const int N=100008;

void solve()
{
	ll n,m,x,y,ans=0,cnt,i,j;
	vll a[N];
	vll v;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
	}
	priority_queue<ll>pq;
	for(i=1;i<=m;i++)
	{
		for(auto j:a[i])
			pq.push(j);
		if(pq.size())
		{
			ans+=pq.top();
			pq.pop();
		}
	}
	cout<<ans;
	
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

Measured memory_bytes: 5632
/*
            _           __                _      _____ _____ _____ 
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / / 
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /  
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/   

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<int> vl;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ; 
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()                                                              
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) {cout<<n<<"\n" ; return ;}
#define po(n) cout << n <<"\n " 
#define pff(n) cout << n << " " ; 
#define ar array
#define endl "\n" 
#define PI acos(-1) 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
//#ifndef ONLINE_JUDGE
//#ifndef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
//#else
//#define debug(x...)
//#endif
//#define int ll 
long const M=1e9+7;
const long mxN =1e5+2 ;
const ll INF =1e18;
void solve(){ 
  int x,y ;
  cin >> x >>  y;
  if(4*x-y>=0 && (4*x-y)%2==0 && (y-2*x)>=0 && (y-2*x)%2==0){
    pf("Yes")
  }
  pf("No") ;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //cout << setprecision(20) << fixed ;
  solve() ;
  // ll t ; cin >> t ; while(t--)solve() ;
	return 0;
}


Measured memory_bytes: 3696
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	ans := 0
	for b := K + 1; b <= N; b++ {
		q := N / b
		r := N % b

		ans += q * (b - K)
		if r-K+1 >= 0 {
			ans += r - K + 1
		}
	}
	if K == 0 {
		ans -= N - K
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, k;
    cin >> n >> k;

    vector<int64_t> h(n);
    for (auto&& hh : h) {
        cin >> hh;
    }

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

    int64_t ans = 0;
    for (auto i : irange(0L, max(n - k, 0L))) {
        ans += h[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    string S;
    cin >> S;
    int n=0, s=0, e=0, w=0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'N') n=1;
        if (S[i] == 'S') s=1;
        if (S[i] == 'E') e=1;
        if (S[i] == 'W') w=1;
    }

    if (n == s && e == w) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 23:20:46
*/

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


int main(){
    char c;
    cin >> c;
    if(c>='a' && c<='z') cout << 'a' << endl;
    else if(c>='A' && c<='Z') cout << 'A' << endl;
    return 0;
}


Measured memory_bytes: 3628
#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, A;
    cin >> N;
    multiset<int> st;
    rep(i, N) {
        cin >> A;
        auto j = st.upper_bound(-A);
        if (j != st.end()) st.erase(j);
        st.insert(-A);
    }
    cout << st.size() << "\n";
}

Measured memory_bytes: 4992
//
// Created by Hideaki Imamura on 2020-03-27.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
const ll mod = 1000000007;

inline ll take_mod(ll a) {
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b) {
    return take_mod(a + b);
}

inline ll sub(ll a, ll b) {
    return take_mod(a - b);
}

inline ll mul(ll a, ll b) {
    return take_mod(a * b);
}

inline ll mod_pow(ll x, ll n) {
    ll res = 1LL;
    while (n > 0) {
        if (n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x) {
    return mod_pow(x, mod - 2);
}

string L;

int main() {
    cin >> L;

    ll num = 0;
    ll res = 0;
    for (int i = 0; i < L.size(); ++i) {
        int len = (int)L.size() - i - 1;
        if (L[i] == '1') {
            res = add(res, mul(mod_pow(2, num), mod_pow(3, len)));
            num++;
        }
    }
    res = add(res, mod_pow(2, num));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int f(int X) {
    int cnt = 0;
    for(int i = X/4*4; i <= X; i++) {
        cnt^=i;
    }
    return cnt;
}
signed main() {
    int A,B;
    cin >> A >> B;
    A--;
    int ans = f(A);
    ans^=f(B);
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <bitset>

int main()
{
	const int N = 10;
	const int B = 1 << N;
	const int SMAX = 330;	// 10*9 + 9*8 + ... + 2*1 + 1*0 = 90+72+56+42+30+20+12+6+2+0 = 330
	int table[N + 1][SMAX + 1] = {0};
	
	int (*bitTable)[SMAX + 1] = new int[B][SMAX + 1];
	
	
	int emax[N + 1] = {0};
	for (int i = 1; i <= N; ++i) {
		emax[i] = emax[i - 1] + 9 * i - i * (i - 1) / 2;
	}
	
	bitTable[0][0] = 1;
	
	for (int i = 0; i < B; ++i) {
		std::bitset<N> bs(i);
		int nbc = bs.count() + 1;
		
		for (int j = 0; j < N; ++j) {
			if (bs.test(j) == false) {
				std::bitset<N> nextBit = bs;
				nextBit.set(j);
				
				int d = j * nbc;
				
				for (int k = 0; k <= emax[nbc]; ++k) {
					bitTable[nextBit.to_ulong()][k + d] += bitTable[i][k];
				}
			}
		}
	}
	
	for (int i = 0; i < B; ++i) {
		std::bitset<N> bs(i);
		int n = bs.count();
		for (int s = 0; s <= emax[n]; ++s) {
			table[n][s] += bitTable[bs.to_ulong()][s];
		}
	}
	
	delete [] bitTable;
	
	int n, s;
	while (std::cin >> n >> s) {
		if (n <= 0 || n > N || s > SMAX || s < 0) {
			std::cout << 0 << std::endl;
			continue;
		}
		std::cout << table[n][s] << std::endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 2352
#include<bits/stdc++.h>
#define ll long long
#define met(a) memset(a,0,sizeof(a))
#define inf 0x3f3f3f3f
//met(dp,0x7F);
using namespace std;
const int mod=1e9+7;
const int N=1e6+10;
int s[300010];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    met(s);
    int i,j,m,n;
    cin>>m>>n;
    int cnt=n,ans;
    if(m%2)
    {
        for(i=1; i<=n; i++)
            s[i]=(m+1)/2;
        for(i=1; i<=n/2; i++)
        {
            if(s[cnt]>1)
            {
                s[cnt]--;
                for(j=cnt+1; j<=n; j++)
                    s[j]=m;
                cnt=n;
            }
            else
                cnt--;
        }
        for(i=1; i<=cnt; i++)
            cout<<s[i]<<' ';
    }
    else
    {
        cout<<m/2;
        for(i=2; i<=n; i++)
            cout<<' '<<m;
        cout<<endl;

    }
    return 0;
}


Measured memory_bytes: 3456
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    n = int(input())
    order = list(map(int, input().split()))
    points = list(map(int, input().split()))
    bonus = list(map(int, input().split()))
    last_one = -10
    ans = 0

    for x in order:
        if last_one + 1 == x - 1:
            ans += bonus[last_one]

        last_one = x - 1
        ans += points[x-1]

    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for(int i=0; i<n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}

	int dp[n][3];
	dp[0][0] = a[0]; 
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for (int i=1; i<n; i++){
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);

		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
	}

	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
	return 0;
}

Measured memory_bytes: 5944
#include <cstdio>
#include <map>
using namespace std;
const int MAXN = 2e5 + 10;
int a[MAXN];
int main() {
    int n;
    scanf("%d", &n);// don't forget &
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);// don't forget &
    }
    map<int, int> mmp;
    for (int i = 2; i <= n; i++) {
        a[i] -= i - 1;
        mmp[a[i]]++;
    }
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        int x = a[i] + i - 1;
        int y = 1 - i - x;
        ans += mmp[y];
        if (i != 1) {
            mmp[a[i]]--;
        }
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 21060
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import combinations as comb
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig

sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    S = input(str)

    ans, last = 0, "*"
    for s in S:
        if not s == last:
            last = s
            ans += 1
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


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

int main() {
  int N =0, M=0;
  cin >> N >> M;
  int A[N];
  int total=0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    total = total + A[i];
  }
  int os=0;
  int pg=0;
  int t=0;
  int w=0;
  pg = 4*M;
  os = total/pg;
  w = total%pg;
  if(w>0){
   os = os +1;
  }
  for(int i=0; i<N; i++){
    if(A[i] < os) t++;
  }
  int y = N-t;
  if(y<M){
    cout << "No" << endl;
  }else if(y>=M) {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define Aint(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
const int mINF = -1001001001;
const int mod = 1000000007;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());


int main() {
  int n,m;
  cin >> n >> m;
  int l,r,lmax=mINF,rmin=INF;
  REP(i,m) {
    cin >> l >> r;
    lmax=max(l,lmax);
    rmin=min(r,rmin);
  }
  int ans = rmin-lmax+1;
  if(ans<0) ans=0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    while(cin>>n){
        vl a(n), b(n);
        forn(i,n) cin>>a[i]>>b[i];
        sort(all(a)); sort(all(b));
        
        if(n&1){
            ll mid = n/2;
            cout<<b[mid] - a[mid] + 1<<endl;
        }else{
            ll m1 = (n-1)/2;
            ll m2 = n/2;
            cout<< (b[m1]+b[m2]) - (a[m1]+a[m2]) + 1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6348
x,y=map(int,input().split())
mod=10**9+7
def nCr_mod(n,r,mod):
  x=1
  y=1
  for i in range(r):
    x=(x*(n-i)) % mod
    y=(y*(i+1)) % mod
  return (x * pow(y, mod - 2, mod)) % mod
if (x+y)%3!=0:
  print(0)
else:
  m=int((2*x-y)/3)
  n=int(x-2*m)
  if m<0 or n<0:
    print(0)
  else:
    print(nCr_mod(m+n,n,mod))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
const int INF=1e7+5;
priority_queue<int,vector<int>,greater<int> > q;
int n,k;
int A[maxn],ans[maxn],ind[maxn];
int tot;
int h[maxn],last[maxn<<1],to[maxn<<1];
int st[maxn<<2];
void build(int x,int l,int r)
{
	st[x]=INF;
	if(l==r) return;
	int mid=(l+r)>>1;
	build(x<<1,l,mid),build(x<<1|1,mid+1,r);
} 
void pushup(int x)
{
	st[x]=min(st[x<<1],st[x<<1|1]);
}
void update(int x,int l,int r,int id,int k)
{
	if(l==r){
		st[x]=k;
		return;
	}
	int mid=(l+r)>>1;
	if(id<=mid) update(x<<1,l,mid,id,k);
	else update(x<<1|1,mid+1,r,id,k);
	pushup(x);
}
int query(int x,int l,int r,int ql,int qr)
{
	if(r<ql||l>qr) return INF;
	if(l>=ql&&r<=qr) return st[x];
	int mid=(l+r)>>1;
	return min(query(x<<1,l,mid,ql,qr),query(x<<1|1,mid+1,r,ql,qr));
}
void add(int x,int y)
{
	to[++tot]=y;last[tot]=h[x];h[x]=tot;++ind[y];
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i){
		int a=0;
		scanf("%d",&a);
		A[a]=i;
	}
	build(1,1,n);
	for(int i=n;i>=1;--i){
		int l=query(1,1,n,A[i],A[i]+k-1),r=query(1,1,n,A[i]-k+1,A[i]);
		if(l!=INF) add(A[i],A[l]);
		if(r!=INF) add(A[i],A[r]);
		update(1,1,n,A[i],i);
	}
	for(int i=1;i<=n;++i) if(!ind[i]) q.push(i);
	int cnt=0;
	while(q.size()){
		int u=q.top();
		q.pop();
		ans[u]=++cnt; 
		for(int i=h[u];i;i=last[i]){
			int v=to[i];
			if(!--ind[v]) q.push(v);
		}
	}
	for(int i=1;i<=n;++i) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 27764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

template <typename T, typename U> T pow_fast(T x, U n) {
    T ret = (T)1;
    while(n) {
        if(n & (U)1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}

template <typename ModType, ModType MOD> struct ModInt {
    ModType val;
    ModInt() : val(0) {}
    ModInt(ModType x) : val(x % MOD) {
        if(val < 0) val += MOD;
    };
    operator ModType() const { return val; }
    ModInt &operator+=(const ModInt &m) {
        val += m.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    ModInt &operator-=(const ModInt &m) {
        val -= m.val;
        if(val < 0) val += MOD;
        return *this;
    }
    ModInt &operator*=(const ModInt &m) {
        (val *= m.val) %= MOD;
        return *this;
    }
    ModInt &operator/=(const ModInt &m) {
        *this *= m.inverse();
        return *this;
    }
    ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; }
    ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; }
    ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; }
    ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; }
    ModInt inverse() const { return pow_fast(*this, MOD - 2); }
    ModInt pow(ModType n) const {return pow_fast(*this, n); }

    friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
        os << rhs.val;
        return os;
    }
    friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
        ModType value;
        is >> value;
        rhs = ModInt(value);
        return is;
    }
};

int main(){
    int n;
    cin >> n;
    using mint = ModInt<ll, MOD>;
    mint x = mint(10).pow(n);
    mint y = mint(8).pow(n);
    mint z = mint(9).pow(n);
    cout << x - y - ((z - y)*mint(2))<< '\n';  
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int countnum = 0;
int T, N;
string bign;
void DFS(int index, int flag1,int flag2,int flag3,string str)
{
	if (index == bign.size())
	{
		if (flag1&&flag2&&flag3&&str <= bign)
			countnum++;
		return;
	}
	else
	{
		if (flag1&&flag2&&flag3)
			countnum++;
	}
	DFS(index + 1, 1, flag2, flag3, str + '3');
	DFS(index + 1, flag1 , 1, flag3, str + '5');
	DFS(index + 1, flag1, flag2, 1, str + '7');
}
int main()
{
	cin >> bign;
	DFS(0, 0, 0, 0, "");
	printf("%d\n", countnum);
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    char a; cin >> a;
    if(a>='a' && a<='z') cout << 'a' << endl;
    else cout << 'A' << endl;
return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, m; cin >> n >> m;
    ll sum = 0, ans = 0;
    unordered_map<ll, ll> cnt;
    cnt[sum]++;
    vi a(n);
    rep(i, n){
        cin >> a[i];
        sum += a[i];
        cnt[sum%m]++;
    }
    for(auto &num: cnt) ans += num.second*(num.second-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 7288
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int W,H,N,x,y,X,Y;
bool e[50][50][4];
int bfs(){
	int d[50][50]={};
	rep(i,W) rep(j,H) d[i][j]=-1;
	d[x][y]=0;
	queue<P> que;
	que.push(P(x,y));
	while(!que.empty()){
		P p=que.front();
		que.pop();
		int x=p.fs,y=p.sc;
		rep(di,4){
			int nx=x+dx[di],ny=y+dy[di];
			if(e[x][y][di]&&d[nx][ny]<0){
				d[nx][ny]=d[x][y]+1;
				que.push(P(nx,ny));
			}
		}
	}
	return d[X][Y];
}
int main(){
	cin>>W>>H>>N;
	rep(i,W) rep(j,H){
		rep(d,4){
			if(0<=i+dx[d]&&i+dx[d]<W&&0<=j+dy[d]&&j+dy[d]<H) e[i][j][d]=1;
		}
	}
	rep(i,N){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		if(a==c){
			if(b>d) swap(b,d);
			for(int j=b;j<d;j++){
				if(a>=1) e[a-1][j][0]=0;
				if(a<W) e[a][j][2]=0;
			}
		}else{
			if(a>c) swap(a,c);
			for(int j=a;j<c;j++){
				if(b>=1) e[j][b-1][1]=0;
				if(b<H) e[j][b][3]=0;
			}
		}
	}
	cin>>x>>y>>X>>Y;
	int D=bfs(),d=D;
	rep(i,W) rep(j,H) rep(k,2){
		if(e[i][j][k]){
			e[i][j][k]=e[i+dx[k]][j+dy[k]][k+2]=0;
			chmax(d,bfs());
			e[i][j][k]=e[i+dx[k]][j+dy[k]][k+2]=1;
		}
	}
	cout<<d-D<<endl;
}

Measured memory_bytes: 1232
#include <iostream>
#include <queue>

using namespace std;

typedef pair<double, int> P;

int main() {
	int n;
	cin >> n;
	int a, b, c;
	cin >> a >> b;
	cin >> c;
	double base = (double)c / (double)a;
	int nedan = a;
	long long int caro = c;
	int d;
	priority_queue<P> pq;
	for (int i = 0; i < n; i++) {
		cin >> d;
		double k = (double)d / (double)b;
		pq.push(P(k, d));
	}
	while (!pq.empty()) {
		P pp = pq.top();
		pq.pop();
		if (pp.first >= base) {
			nedan += b;
			caro += pp.second;
			base = caro/nedan;
		} else {
			break;
		}
	}
	cout << caro/nedan << endl;
	return 0;
}

Measured memory_bytes: 1204
// 12/07/2020  @ 19:54:17
// *****************************************************************
// *****************************************************************
#include <bits/stdc++.h>
// *****************************************************************
// *****************************************************************
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#define fr(i,n) for(llu i=0;i<n;i++)
#define fl(j,a,b) for(llu j=a;j<=b;j++)
#define Pi 3.1415926535897932384626
#define mod 1e9+7
#define MID(a,b) ((a + b) >> 1)
#define MAX(a,b) ((a) > (b) ? (a): (b))
#define MIN(a,b) ((a) < (b) ? (a) :(b))
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define printer(a, n) fr(i,n) cout << a[i] << " ";
// *****************************************************************
// *****************************************************************
typedef long long unsigned int llu;
typedef long long int ll;
// *****************************************************************
// *****************************************************************
using namespace std;
// *****************************************************************
// *****************************************************************

                   // Dream it. Wish it. Do it.

                         // tannatsri //

              // Without tact you can learn nothing.

// *****************************************************************
// *****************************************************************
bool rev(ll a, ll b) {
    return a > b;
}
// *****************************************************************
void solution() {
	ll n;
	cin >> n;
	if(n % 1000)
	cout << 1000 - n % 1000;
	else cout << 0;

}
// *****************************************************************
int main() {
    IOS;
    // #ifndef ONLINE_JUDGE
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/input.txt", "r", stdin);
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/output.txt", "w", stdout);
        // freopen("C:/Users/Mr.Tanishq/Desktop/noc/error.txt", "w", stderr);
    // #endif
    // *****************************************************************
    // *****************************************************************
    int t = 1;
    // cin >> t;
    while(t--) {

       solution();
       cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;


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

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

int main() {
	int n; cin >> n;
	int a[800];
	rep(i,n) cin >> a[i];
	// int m = 1000;
	lint dp[900];
	dp[0] = 1000;
	for (int i=1; i <= n; i++) {
		lint hi = 0;
		rep(j,i) {
			lint buy = dp[j] / a[j];
			lint money = dp[j] % a[j];
			money += a[i] * buy;
			hi = max(hi, money);
			hi = max(hi, dp[j]);
		}
		dp[i] = hi;
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 3640
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n,ans=0;
  	cin >> n;
  	for(ll i=1;i<=n;i++){
    	if(i%3!=0&&i%5!=0){
        	ans+=i;
        }
    }
  	cout << ans << endl;
}



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

int main()
{
    int n;
    cin>>n;
    string  ss;
    cin>>ss;
    ss="#"+ss;
   if(n%2==0)
   {
       bool chk=false;
       int index=1;
       for(int i=n/2+1; i<=n;i++)
       {
          
           if(ss[i]==ss[index++])
                continue;
             else
               {
                   chk=true;
                   break;
               }
       }
       if(chk==true)
        cout<<"No";
       else
        cout<<"Yes";

   }
   else
    cout<<"No";
}


Measured memory_bytes: 256
from math import factorial

def com(n, r):
    return fac_n // factorial(r) // factorial(n - r)


N, P = map(int, input().split())
A = [int(x) for x in input().split()]

odd, even = 0, 0
for i in range(N):
    if A[i] % 2 == 1:
        odd += 1
    else:
        even += 1

fac_n = factorial(odd)

res = 0
for r in range(P, odd+1, 2):
    res += com(odd, r)
ans = res * (2**even)

print(ans)

Measured memory_bytes: 8988