akhauriyash/Code-Regression huggingface dataset:
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
S, T = gets.split

i = 0
ans = ''
while i < N * 2
  if i % 2 == 0
    ans += S[i/2]
  else
    ans += T[i/2]
  end
  i += 1
end

puts ans


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

int main(){
	int n, t;
	cin >> n >> t;
	int sum = t;
	int pre;
	cin >> pre;
	for (int i=1; i<n; i++){
		int tmp;
		cin >> tmp;
		if (tmp >= pre + t) sum += t;
		else sum += tmp - pre;
		pre = tmp;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int n, m;
    cin >> n >> m;

    vs32 cnt(n, 0);
    int a, b;
    rep (i, m)
    {
        cin >> a >> b;
        --a; --b;
        ++cnt[a];
        ++cnt[b];
    }

    bool ans = true;
    rep (i, n)
    {
        if (cnt[i] & 1) ans = false;
    }

    cout << (ans ? "YES\n" : "NO\n");
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,ans = 2;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    rep(i, n){
        if (n < ans) {
            cout << ans/2 << endl;
            return 0;
        }
        ans = ans * 2;
    }
    return 0;
}


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

int main(){
  double a,b,x; cin>>a>>b>>x;

  if(x<=a*a*b/2.0){
  cout<<setprecision(15)<<atan(a*b*b/x/2.0)*180.0/3.1415926535<<endl;
  }else{
    cout<<setprecision(15)<<atan(2.0*(a*a*b-x)/a/a/a)*180.0/3.1415926535<<endl;
  }

}

Measured memory_bytes: 256
// 
#include <bits/stdc++.h>
using namespace std;
#define ll 		long long int
#define pii 	pair<int,int>
#define vi 		vector<int>
#define mii 	map<int,int>
#define pb 		push_back
#define mp 		make_pair
#define ff 		first
#define ss 		second
#define MOD 	1000000007
 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n,k;
	cin>>n>>k;
	int a[n],i,j;
	for(i=0;i<n;i++)
		cin>>a[i];

	if(n==1)
		return 0;
	int dp[n]={0};
	
	for(i=1;i<k && i<n;i++)
		dp[i]=abs(a[i]-a[0]);

	for(i=k;i<n;i++)
	{
		int ans=INT_MAX;
		for(j=i-1;i-j<=k;j--)
			ans=min(ans,abs(a[j]-a[i])+dp[j]);

		dp[i]=ans;
	}

	cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double t1 = 360 * (H + M / 60) / 12, t2 = 360 * M / 60;
    if(t1 < t2) swap(t1, t2);
    double theta = (t1 - t2) * M_PI / 180.0;
    double ans = A * A + B * B - 2.0 * A * B * cos(theta);
    ans = sqrt(ans);
    cout << fixed << setprecision(18) << ans << endl;
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

int main(){
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    int y=max(c,d);
    
    for(int i = a-1; i < y-2; i++){
        if(s[i]=='#' && s[i+1]=='#'){
            cout << "No" << endl;
            return 0;
        }
    }
    
    if(c < d){
        cout << "Yes" << endl;
        return 0;
    }else{
        for(int i = b-2; i < d - 1; i++){
            if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
}


Measured memory_bytes: 640
import sys

# input処理を高速化する
input = sys.stdin.readline

# 入力
N, W = map(int, input().split())
# sum_vの取りうる上限値
MAX_V = (10**3) * N +1
# 最小値を求めるので無限大の値
f_inf = float('inf')

def knapsack(n, w):
    # dpの初期化　dp[sum_v]は重さの総和の最小値
    dp = [f_inf] * MAX_V
    # 初期条件
    dp[0] = 0
    sum_v = 0
    # forは全て関数の中で回す。
    # 入力
    for i in range(N):
        w, v = map(int, input().split())
        for j in range(MAX_V, v-1, -1):
            new_weight = dp[j - v] + w
            if new_weight > W:
                continue
            if dp[j] > new_weight:
                dp[j] = new_weight

    ans = 0
    for sum_v in range(MAX_V):
        if dp[sum_v] <= W:
            ans = sum_v
    print(ans)

knapsack(N, W)

Measured memory_bytes: 10976
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

void dijkstra(int n, int m[MAX][MAX]) {
    int minv;
    int d[MAX], color[MAX];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;

    while (true) {
        minv = INFTY;
        int u = -1;
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && m[u][v] != INFTY) {
                if (d[v] > d[u] + m[u][v]) {
                    d[v] = d[u] + m[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main() {
    int n, m[MAX][MAX];
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            m[i][j] = INFTY;
        }
    }

    int k, c, u, v;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            m[u][v] = c;
        }
    }

    dijkstra(n, m);
}



Measured memory_bytes: 3116
#include<stdio.h>
int main(){
int H,W;
int h,w;
while(1){
scanf("%d%d",&H,&W);
if(H == 0 && W == 0)break;
   for(h = 0; h < H; h++){ 
   for(w = 0; w < W; w++)putchar('#');
    putchar('\n');}
putchar('\n');}
return 0;
}  



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

long long C[51][51]; // C[n][k] -> nCk
 
void comb_table(int N){ 
	for(int i=0;i<=N;++i){
		for(int j=0;j<=i;++j){
			if(j==0 or j==i){
				C[i][j]=1LL;
			}else{
				C[i][j]=(C[i-1][j-1]+C[i-1][j]);
			}
		}
	}
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    double v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    double mean;
    long long ans=0;
    sort(v,v+n,greater<double>());
    double sum=0;
    for(int i=0;i<a;i++){
        sum+=v[i];
    }
    mean=sum/(double)a;
    printf("%07f",mean);
    cout<<endl;
    int cntl=0,cnt=0;
    for(int i=0;i<n;i++){
        if(v[a-1]<v[i]) cntl++;
        if(v[a-1]==v[i]) cnt++;
    }

    comb_table(50);

    ans=C[cnt][a-cntl];
    if(mean==v[a-1]){
        for(int i=a+1;i<=min(b,cnt);i++){
            ans+=C[cnt][i];
        }
    }

    cout<<ans<<endl;

    
}


Measured memory_bytes: 256
def main():
    n = int(input())
    A = list(map(int, input().split()))

    tallest = A[0]
    cnt = 0

    for height in A:
        if tallest > height:
            cnt += tallest - height
        else:
            tallest = height

    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 32068
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

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

    int n;
    cin >> n;
    auto sd = [&](int x) {
        auto s = to_string(x);
        int ans = 0;
        for (auto t : s) {
            ans += (t - '0');
        }
        return ans;
    };
    int ans = 1e9 + 239;
    for (int i = 1; i < n; i++) {
        ans = min(ans, sd(i) + sd(n - i));
    }
    cout << ans << endl;
}   


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		while (str != null) {
			double vl = Double.parseDouble(str);
			int floor = (int) Math.floor(Math.pow(vl, 2) / (2 * 9.8)) / 5 + 2;
			System.out.println(floor);
			str = br.readLine();
		}
	}
}

Measured memory_bytes: 24304
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



struct BFSS
{
    int depth, parent;
};

struct BFSS2
{
    int depth;
    bool is_child_of_x;
};

int bfs(const vvi &tree, vector<BFSS> &dist, int N, int start)
{
    dist.resize(N);
    for (size_t i = 0; i < dist.size(); i++)
    {
        dist[i].depth = -1;
    }
    
    
    queue<int> next;
    dist[start].depth = 0;
    dist[start].parent = -1;
    next.push(start);

    int longest;
    while (!next.empty())
    {
        int cp = next.front(); next.pop();
        for (int node: tree[cp])
        {
            if (dist[node].depth < 0)
            {
                dist[node].depth = dist[cp].depth + 1;
                dist[node].parent = cp;
                next.push(node);
                longest = node;
            }
        }
    }
    return longest;
}

int bfs_depth_x(const vvi &tree, vector<BFSS2> &dist, int N, int root, int x)
{
    dist.resize(N);
    for (size_t i = 0; i < dist.size(); i++)
    {
        dist[i].depth = -1;
    }

    queue<int> next;
    dist[root].depth = 0;
    dist[root].is_child_of_x = false;
    next.push(root);

    int longest;
    while (!next.empty())
    {
        int cp = next.front(); next.pop();
        for (int node: tree[cp])
        {
            if (dist[node].depth < 0)
            {
                dist[node].depth = dist[cp].depth + 1;
                if (node == x)
                    dist[node].is_child_of_x = true;
                else
                    dist[node].is_child_of_x = dist[cp].is_child_of_x;
                
                next.push(node);
                if (dist[node].is_child_of_x)
                {
                    longest = node;
                }                
            }
        }
    }
    return longest;
}

int farest(const vector<BFSS> &du, const vector<BFSS> &dv, int N)
{
    int max_dist = 0, max_virt = -1;
    for (int i = 0; i < N; i++)
    {
        if (dv[i].depth > max_dist && du[i].depth < dv[i].depth)
        {
            max_dist = dv[i].depth;
            max_virt = i;
        }
    }
    return max_virt;
}

int main()
{
    int N, u, v;
    cin >> N >> u >> v;
    
    vvi tree(N);
    
    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        tree[a-1].push_back(b-1);
        tree[b-1].push_back(a-1);
    }
    --u;
    --v;

    vector<BFSS> dist_from_v, dist_from_u;
    bfs(tree, dist_from_v, N, v);
    bfs(tree, dist_from_u, N, u);

    int kouji_virt = farest(dist_from_u, dist_from_v, N);
    int du = dist_from_u[kouji_virt].depth;
    int dv = dist_from_v[kouji_virt].depth;
    int ans = dv - 1;

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

Measured memory_bytes: 7424
import java.util.*;
import java.io.*;
 
public class Main {
    static long ans = 0;
    static int[] c;
    static int[][] dc;
    static int[] last;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int d = sc.nextInt();
        c = sc.nextIntArray(26);
        dc = new int[d][26];
        last = new int[26];
        for(int i = 0; i < d; i++){
            for(int j = 0; j < 26; j++){
                dc[i][j] = sc.nextInt();
            }
        }
        for(int i = 1; i <= d; i++){
            int hold = sc.nextInt()-1;
            last[hold] = i;
            ans += dc[i-1][hold];
            calc(i);
            System.out.println(ans);
        }
    }
    
    public static void calc(int d){
        for(int i = 0; i < 26; i++){
            ans -= c[i] * (d-last[i]);
        }
        return;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 28548
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;

int MOD = 1e9+7;

LL fac(LL n,LL m){
    if(m==0) return 1;
    LL res = 1;
    auto tm = 1;
    auto tmm = m;
    while(tmm--){
        res = (res*n/tm)%MOD;
        tm++;
        n--;
    }
    return res;
}
long long solve(){
    int n;
    cin>>n;
    vector<int> cost(n,0);
    for(int i = 0;i<n;i++){
        cin>>cost[i];
    }
    sort(cost.begin(),cost.end(),greater<int>());
    
    LL res = 0;
    vector<int> dp(n+1,1);
    for(int i=1;i<=n;i++){
        dp[i] = (dp[i-1]*2)%MOD;
    }
    LL y = dp[n-1];
    y = (y*y)%MOD;
    for(int i=0;i<n;i++){
        LL temp = (i+2)*y%MOD;
        // cout<<temp<<endl;
        temp = temp * cost[i]%MOD;
        // cout<<temp<<endl;
        res = (res+temp)%MOD;
    }
    // res = (res+res)%MOD;
    cout<<res<<endl;
    return 0;
}

int main(){
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto ab = aryread!string();
    // writeln(ab);
    string ab_str = ab.join();
    // writeln(ab_str);
    long tmp;
    foreach (i; 0 .. ab_str.length)
    {
        // writeln(10 ^^ (((ab_str.length) - 1) - i));
        tmp += (ab_str[i] - '0') * 10 ^^ (((ab_str.length) - 1) - i);
    }
    // writeln(tmp);
    foreach (i; 1 .. 10 ^^ 4)
    {
        if (i * i == tmp)
        {
            writeln("Yes");
            return;
        }
    }
    writeln("No");

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3712
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
	int n;
	cin>>n;
	int p[n];
	for(auto &x:p)
		cin>>x;
	int max_val=3000000;
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(p[i]<max_val)
		{
			max_val=p[i];
			cnt++;
		}
	}
	cout<<cnt;
}
int main()
{
//code
	
fastio	
int t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 4372
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] list = new int[10];
            for (int i = 0; i < 10; i++)
                list[i] = int.Parse(Console.ReadLine());
            foreach (var item in list.OrderByDescending(i => i).Take(3))
                Console.WriteLine(item);
        }
    }
}

Measured memory_bytes: 6340
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string.h>
#include <math.h>



int main(){
        long long Yen = 0;
        scanf("%lld",&Yen);
        int a = int(Yen/500);
        Yen -= a*500;
        int b = int(Yen/5);
        printf("%d\n", a*1000 + b * 5);
        return 0;
}

Measured memory_bytes: 128
n, yen = map(int, input().split())

sen = 1000
gosen = 5000
man = 10000
flag = 0
for i in range(n+1):
  if flag == 1:
    break
  for j in range(n+1-i):
    sum = man*i + gosen*j + sen*(n-i-j)
    if sum == yen:
      print(str(i) + ' ' + str(j) + ' ' + str(n-i-j))
      flag = 1
      break

if flag == 0:
  print('-1 -1 -1')

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <climits>
#include <map>
#include <math.h>
using namespace std;

int main(void)
{
    int N, A, B;

    cin >> N >> A >> B;

    if (N * A > B)
    {
        cout << B << endl;
    }
    else
    {
        cout << N * A << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)



main :: IO ()
main = do
    i <- r'
    putStrLn $ if length (nub i) == 2 then "Yes" else "No"



Measured memory_bytes: 380
# https://atcoder.jp/contests/dp/tasks/dp_d

N, W = map(int, input().split())

weights, profits = [], []

for i in range(N):
    w, p = map(int, input().split())
    weights.append(w)
    profits.append(p)

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1, N+1):
    for w in range(1, W+1):
        if w - weights[i-1] >= 0:
            dp[i][w] = max(dp[i-1][w], dp[i-1][w-weights[i-1]] + profits[i-1])
        else:
            dp[i][w] = dp[i-1][w]

print(dp[-1][-1])


Measured memory_bytes: 173448
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

affine a b c
  | isAsciiLower c = chr $ mod (a * (ord c - ord 'a') + b) 26 + ord 'a'
  | otherwise = c

unaffine a b c
  | isAsciiLower c = head [x | x <- ['a'..'z'], affine a b x == c]
  | otherwise = c

  
findAffine s = fromJust $ find (\t -> isInfixOf "that" t || isInfixOf "this" t)  [flip map s $ affine a b | a <- [1..25], b <- [0..25], mod a 2 /= 0, mod a 13 /= 0]

main = do
    getInt >>= flip replicateM getLine >>= mapM_ (putStrLn . findAffine)

Measured memory_bytes: 4124
from sys import stdin
# import numpy as np
# import math
# import fractions
# import sys
# sys.setrecursionlimit(100000)
# N = int(stdin.readline().rstrip().split()[0])
# A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]
# S = stdin.readline().rstrip().split()[0]

R,G,B,N = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
for r in range(N+1):
  for g in range(N+1):
    bB = N-r*R-g*G
    if bB<0:
      break
    if bB%B==0:
      # print(r,g,bB//B)
      ans += 1
print(ans)

Measured memory_bytes: 3060
use std::cmp;

fn main(){
  let nk: Vec<usize> = read_vec();
  let n: usize = nk[0];
  let k: usize = nk[1];
  let h: Vec<i32> =read_vec();
  let mut cst: Vec<i32> = vec![std::i32::MAX; n];

  cst[0] = 0;

  for i in 1 .. n {
    let ik = if i < k {0} else {i - k};
    for j in ik .. i {
      cst[i] = cmp::min(cst[i], cst[j] + (h[i] - h[j]).abs());
    }
  }
  
  println!("{}", cst[n-1]);
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}


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


int main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
  
    rep(i, N) cin >> H[i];
    sort(H.begin(), H.end(), std::greater<long long>());
  
  	long long ret = 0;
 	for(int i = K; i<N; i++) {
		ret += H[i];
    }
  
  	cout << ret << endl;
}

Measured memory_bytes: 1024
P = [1 for _ in range(10**6)]
P[0]=0
P[1]=0
for i in range(2,10**3):
    for j in range(i*i,10**6,i):
        P[j]=0
Q = []
for j in range(2,10**6):
    if P[j]==1:
        Q.append(j)
N = int(input())
E = []
for p in Q:
    if N%p==0:
        k = 0
        while N%p==0:
            N = N//p
            k += 1
        E.append(k)
if N>1:
    E.append(1)
cnt = 0
for e in E:
    n=1
    while (n*(n+1))//2<=e:
        n += 1
    cnt += n-1
print(cnt)

Measured memory_bytes: 142484
package main

import "fmt"

func main() {
	var n, a, b int
	var s string
	passer := 0
	foreign_rank := 1
	fmt.Scan(&n, &a, &b)
	fmt.Scan(&s)
	for i:=0; i<len(s); i++{
		if s[i] == 'a' {
			if passer<a+b{
				fmt.Println("Yes")
				passer++
			}else{
				fmt.Println("No")
			}
		}else if s[i] == 'b'{
			if passer<a+b && foreign_rank <= b{
				fmt.Println("Yes")
				passer++
				foreign_rank++
			}else{
				fmt.Println("No")
			}
		}else if s[i] == 'c'{
			fmt.Println("No")
		}
	}

}

Measured memory_bytes: 3328
n, k = map(int, input().split())
a = list(map(int , input().split()))
b = [0] * (n-k+1)
b0 = 1
for i in range(k):
    b0 = b0 + a[i]
b[0] = b0
for i in range(k, n):
    b[i-k+1] = b[i-k] - a[i-k] + a[i]
    if b[i-k+1] > b[i-k]:
        print('Yes')
    else:
        print('No')
#print(a, b, b0)

Measured memory_bytes: 94176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
const int MAX_N = 2e5;

int d, c[365], s[365][26], t[365], last[26], u;

void input(){
  cin >> d;
  rep(i, 26) cin >> c[i];
  rep(i, d){
    rep(j, 26){
      cin >> s[i][j];
    }
  }
  rep(i, d){
    int k;
    cin >> k;
    k--;
    t[i] = k;
  }
  fill(last, last+26, 0);
}

int test(int k, int i){
  ll res = 0;
  rep(j, 26){
    if(j == k) continue;
    res -= c[j] * last[j];
  }
  
  return res + s[i][k];
}

void greedy(){
  rep(i, d){
    rep(i, 26) last[i]++;
    int res = -INF;
    rep(k, 26){
      if(res < test(k, i)){
        u = k;
        res = test(k, i);
      }
    }
    last[u] = 0;
    t[i] = u;
  }
}

int p_calc(){
  ll res = 0;
  int last[26];
  fill(last, last+26, 0);
  rep(i, d){
    res += s[i][t[i]];
    rep(i, 26) last[i]++;
    last[t[i]] = 0;
    rep(j, 26){
      res -= c[j]*last[j];
    }
  }
    
  return res;
}
  
  
int main(){
  input();
  greedy();
  ll ans = p_calc();
  
  rep(i, d){
    int p = i, q, tmp = t[p];
    
    q = s[i][i%26]%26;
      
      
    t[p] = q;
    if(ans > p_calc()){
      t[p] = tmp;
    }
  }
  
  rep(i, d) cout << t[i]+1 <<endl;
}

  

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

int main() {
    string s; cin >> s;
    const int n = s.size();

    deque<char> d;
    for(int i = 0; i < n; ++i) {
        if(d.empty() || d.back() == s[i]) {
            d.push_back(s[i]);
        } else {
            d.pop_back();
        }
    }
    cout << n - d.size() << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  cin >> N;
  ;
}
bool is_prime[1111111];
vector<int> P;
void Eratosthenes(const int N) {
  for (int i = 2; i <= N; i++) {
    is_prime[i] = true;  // initialize.
  }
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
}
map<int, int> fac;
void factorize(int x) {
  for (int i = 2; i * i <= x; i++) {
    while (x % i == 0) {
      x /= i;
      fac[i]++;
    }
  }
  if (x != 1) fac[x]++;
}
void solve() {
  // N<1000
  //
  // n* n-1 * n-2 * n-3 * ... ... * 3 * 2 * 1
  // n までの素数列挙？
  //素因数分解
  rep(i, 1, N) { factorize(i); }
  int ans = 1;
  rep(i, 2, N) {
    ans *= (fac[i] + 1);
    ans %= MOD;
  }
  cout << ans << endl;

  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    s = input()
    S.append(s)
for i in range(N):
    S[i] = ''.join(sorted(S[i]))

count = 0
t = dict()
for i in range(N):
    if S[i] in t:
        t[S[i]] += 1
    else:
        t[S[i]] = 1
ans = 0
for key in t:
    ans += (t[key]*(t[key]-1)) // 2


print(ans)

Measured memory_bytes: 19472
#include<iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long int llint;
using namespace std;
 
 
int main() {
	int a,b,k;
    cin >> k;
    cin >> a >> b;
  	if(b-a>=k){
		cout << "OK"; 
    } else{
      	int i,fa=0;
     	for(i=a;i<=b;i++){
         	if(i%k==0){
              	cout << "OK";
                fa=1;
                break;
            }
        }
        //cout << i;
        if(fa==0){
         	cout << "NG"; 
        }
    }
	return 0;
}

Measured memory_bytes: 3620
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let k: i32 = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();

    let sum: i32 = a.iter().sum();

    let mut v = vec![];
    for i in 1..sum {
        if i * i > sum {
            break;
        }
        if sum % i == 0 {
            v.push(i);
            v.push(sum / i);
        }
    }
    v.sort_by_key(|v| -v);

    let mut ans = 1;
    for v in v {
        let mut b: Vec<i32> = a.iter().map(|a| a % v).collect();
        let mut s: i32 = b.iter().sum();
        b.sort_by_key(|b| -b);

        let mut ok = true;
        let mut t = 0;
        for b in b {
            t += i32::abs(b - v);
            s -= v;
            if t > k {
                ok = false;
                break;
            }
            if s == 0 {
                break;
            }
        }

        if ok {
            ans = v;
            break;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
n, m = map(int, input().split())
s = [list(map(int, input().split()[1:])) for _ in range(m)]
p = list(map(int, input().split()))
ret = 0
for b in range(1 << n):
    if all(sum((b >> (i - 1)) & 1 for i in s[j]) % 2 == p[j] for j in range(m)):
        ret += 1
print(ret)

Measured memory_bytes: 42352
N, K, Q = list(map(int,input().split()))
A = [int(input()) for i in range(Q)]
score = [0] * N
for i in range(Q):
  score[A[i] - 1] += 1
for i in range(N):
  result = K - Q + score[i]
  if result > 0:
    print("Yes")
  else:
    print("No")

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

int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    if (h >= k) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vec;
typedef vector<vec> mat;

int N, M;

mat mul(mat &A, mat &B){
	mat C(A.size(), vec(B[0].size()));
	for(int i = 0; i < A.size(); i++){
		for(int k = 0; k < B.size(); k++){
			for(int j = 0; j < B[0].size(); j++){
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
			}
		}
	}
	return C;
}
mat pow(mat A, ll n){
	mat B(A.size(), vec(A.size()));
	for(int i = 0; i < A.size(); i++){
		B[i][i] = 1;
	}
	while(n > 0){
		if(n & 1) B = mul(B, A);
		A = mul(A, A);
		n >>= 1;
	}
	return B;
}

int main(){
	int A, B, C, T;
	for(;;){
		scanf("%d %d %d %d %d %d", &N, &M, &A, &B, &C, &T);
		if(N == 0 && M == 0 && A == 0 && B == 0 && C == 0 && T == 0) break;
		mat D(N, vec(N));
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if(i == j) D[i][j] = B;
				else if(i == j + 1) D[i][j] = C;
				else if(i == j - 1) D[i][j] = A;
				else D[i][j] = 0;
			}
		}
		mat x(1, vec(N));
		for(int i = 0; i < N; i++) scanf("%d", &x[0][i]);
		mat Dn = pow(D, T);
		mat res = mul(x, Dn);
		for(int i = 0; i < N; i++) printf("%d%c", res[0][i], (i == N - 1 ? '\n' : ' '));
	}
	return 0;
}


Measured memory_bytes: 2744
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                ans+=1
print(ans)


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

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

    string N;
    cin >> N;

    vector<string> v = {
        "AKIHABARA",
        "KIHABARA",
        "AKIHBARA",
        "AKIHABRA",
        "AKIHABAR",
        "KIHBARA",
        "KIHABRA",
        "KIHABAR",
        "AKIHBRA",
        "AKIHBAR",
        "AKIHABR",
        "KIHBRA",
        "KIHABR",
        "KIHBAR",
        "AKIHBR",
        "KIHBR",
    };

    string ans = "NO";
    for (int i = 0; i < v.size(); ++i) {
        if(N == v[i]) ans = "YES";
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;

int main(){
    ll a,b,n;cin>>a>>b>>n;
    cout<<a*min(n,b-1)/b<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace::std;
int main(int argc, const char * argv[]) {
    int H, W;
    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for (int i = 0; i<H; i++) {
            for (int j = 0; j<W; j++) {
                if ((i+j)%2 == 0) {
                    cout << "#";
                }
                else{
                    cout <<".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    // insert code here...
   // std::cout << "Hello, World!\n";
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define LL long long
#define INF 1e9
#define eps 1e-9
#define PI acos(-1.0)
#define  Exp 2.7182818284
using namespace std;
const int maxn=123456*2;
char ch[maxn];



void init(){

}

void play(){



}

void Pri(){


}



int main() {



    while(scanf("%s",ch+1)!=EOF){
        int len=strlen(ch+1);
        LL sum=0;
        int now=0;
        for(int i=len;i>=1;i--){
            if(ch[i]=='B'){
                sum+=now;
            }
            else {
                now++;
            }
        }
        printf("%lld\n",sum);



    }




    return 0;

}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define Sort(x) sort(x.begin(),x.end()); 
#define ll long long
int mod=1e9+7;
const int INF = 1e9;

using namespace std;

int main(void) {
	int w, h;
	cin >> h >> w;
	vector<vector<int>> vv(h, vector<int>(w)),v(10,vector<int>(10,INF));
	vector<vector<int>> dis(9, vector<int>(9, INF));
	rep(i, 0, 10) {
		rep(j, 0, 10)scanf("%d", &v[i][j]);
	}
	rep(i, 0, h) {
		rep(j, 0, w) {
			scanf("%d", &vv[i][j]);
		}
	}
	rep(i, 0, 10) {
		v[i][i] = 0;
	}

	rep(i, 0, 10) {
		rep(j, 0, 10) {
			rep(k, 0, 10) {
				v[j][k] = min(v[j][k], v[j][i] + v[i][k]);
			}
		}
	}

	int sum = 0;
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (vv[i][j] != -1) {
				sum += v[vv[i][j]][1];
			}
		}
	}
	cout << sum << endl;





	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    vector<PL> a(4);
    ll n;
    REP(i,4) cin >> a[i].first;
    cin >> n;
    n *= 4;
    a[0].second = 1;
    a[1].second = 2;
    a[2].second = 4;
    a[3].second = 8;
    REP(i,4) a[i].first *= 8 / a[i].second;
    sort(ALL(a));
    REP(i,4) a[i].first /= 8 / a[i].second;

    ll ans = 0;
    REP(i,n){
        ll x = n / a[i].second;
        n -= x * a[i].second;
        ans += x * a[i].first;
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  if(a+a-1>b+b-1&&a+a-1>a+b)
    cout<<a+a-1<<endl;
  else if(b+b-1>a+a-1&&b+b-1>a+b)
    cout<<b+b-1<<endl;
  else
    cout<<a+b<<endl;
}

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

using namespace std;

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

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())

ll MOD(ll x, ll m) {
    ll r = x % m;
    if (r < 0) {
        r += m;
    }
    return r;
}

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 9e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    ll res = 0;
    while (res < n) {
        res += 1000;
    }

    // cout << fixed << setprecision(6);
    cout << res - n << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
    //cin.rdbuf()->in_avail()
    return 0;
}

Measured memory_bytes: 3632
l,r = map(int,input().split())

r_min = min(l+2019,r)
inf = float('inf')
ans = inf

for i in range(l,r_min+1):
    for j in range(i+1,r_min+1):
        modu = i*j
        if modu%2019 <= ans:
            ans = modu%2019

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef pair<int,int> pii;
// tree <pii,null_type,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
// cin.tie(0);
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 5005;
const int M = 205;
const int V = 207;
const int E = 60007;
const int INF = 0x3f3f3f3f;
const double inf = 2e9;
const double Pi = acos(-1);
const int MOD = 1e9+7;
const double eps = 1e-8;
int n,m;
char t[] = "AKIHABARA";
char s[N];
bool vis[N];
int main()
{
    while (~scanf("%s",s))
    {
        memset(vis,0,sizeof vis);
        int l = strlen(s);
        int len = strlen(t);
        int p = 0;
        int f = 0;
        for (int i=0;i<l;i++)
        {
            while (s[i]!=t[p] && p<len)
                p++;
            if (p>=len)
            {
                f=1;
                break;
            }
            vis[p] = 1;
            p++;
        }
        for (int i=0;i<len;i++)
            if (vis[i]==0 && t[i]!='A')
                f=1;
        if (f)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}
/*

AKIHABARA

AKIHABAR

AKIHABARAA

AKIHABAA

KIHBR

AKIBAHARA

AAKIAHBAARA

*/

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

int main() {
  	locale l = locale::classic();
  
	string s1,s2,s3;
	cin >> s1 >> s2 >> s3;
  	cout << toupper(s1.at(0),l) << toupper(s2.at(0),l) << toupper(s3.at(0),l) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define m 1000000007
ll solve(ll r,ll c,ll h,ll w,vector<vector<char> > &v,vector<vector<ll> > &dp)
{
    //if(r>=h || c>=w)
       // return 0;
    if(dp[r][c]!=(-2))
        return(dp[r][c]);
    if(v[r][c]=='#')
        return(0);
    dp[r][c]=((solve(r,c+1,h,w,v,dp)%m)+(solve(r+1,c,h,w,v,dp)%m))%m;
    //cout<<"r="<<r<<" c="<<c<<" dp="<<dp[r][c]<<"\n";
    return(dp[r][c]);
}
int main()
{
    ll h,w;cin>>h>>w;
    vector<vector<char> > v(h,vector<char> (w));
    vector<vector<ll> > dp(h,vector<ll> (w,-2));
    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
        {
            cin>>v[i][j];
        }
    }
    for(ll i=(h-1);i>=0;i--)
    {
        if(v[i][w-1]=='#')
        {
            for(ll j=0;j<=i;j++)
                dp[j][w-1]=0;
            break;
        }
        else
        {
            dp[i][w-1]=1;
        }
    }
    for(ll i=(w-1);i>=0;i--)
    {
        if(v[h-1][i]=='#')
        {
            for(ll j=0;j<=i;j++)
            {
                dp[h-1][j]=0;
            }
            break;
        }
        else
            dp[h-1][i]=1;
    }
   // dp[0][0]=-2;
    cout<<solve(0,0,h,w,v,dp);
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5+10;
const int M = 1e6+10;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}
inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}
//==================================================================================================================================================================//

int n, k, h[N], dp[N];

int main() {
   scanf("%d %d", &n, &k);
   for1(i, n) scanf("%d", h+i);
   ms(dp, inf); dp[n] = 0;
   for(int i = n; i; --i)
      for1(j, k) {
         if(i - j < 1) break;
         dp[i-j] = min(dp[i-j], dp[i] + abs(h[i] - h[i-j]));
      }
   printf("%d\n", dp[1]);
   return 0;
}

Measured memory_bytes: 4616
a = list(int(input()) for _ in range(5))

min_rem = 10
ans = 0
for i in range(5):
    ans += (a[i] + 10 - 1) // 10 * 10
    if min_rem > a[i] % 10 > 0:
        min_rem = a[i] % 10

if min_rem != 10:
    ans -= (10 - min_rem)
print(ans)

Measured memory_bytes: 61772
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int A[1000005];
int main(){
  int N,M;cin>>N>>M;
  int i,j,k,l;
  vector<pair<int, int> > pairs(M);
  rep(i,N) cin>>A[i];
  rep(i,M) cin>>pairs[i].second>>pairs[i].first;
  long long ans=0;
  sort(A,A+N);
  sort(pairs.begin(), pairs.end(),greater<P>());
  //大きい方かから入れていく
  int cnt=0,tmp=0;
  bool tu=false,la=false;
  rep(i,N){
    if(pairs[cnt].first<=A[i]) break;
    if(tmp>=pairs[cnt].second){
      cnt++;
      tmp=0;
      tu=true;
      //cout<<i<<endl;
    }
    if(tu) {tu=false;i--;continue;}
    tmp++;
    if(A[i]<pairs[cnt].first) A[i]=pairs[cnt].first;
  }
  rep(i,N){
    ans+=A[i];
    //cout<<A[i]<<" ";
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1408