akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const ll oo = 0x3f3f3f3f3f3f3f3f;
class Point{
public:
	ll x;
	int v;
};
Point p[maxn];
int n;
ll C;
ll ans = 0;
bool cmp(Point p1 , Point p2){
	return p1.x < p2.x;
}

ll sum[maxn];
void solve(){
	sort(p + 1 , p + n + 1 , cmp);
	sum[0] = 0;
	ll cur = 0 , mx = 0;
	for(int i = 1 ; i <= n ; ++ i){
		cur += p[i].v - (p[i].x - p[i - 1].x);
		if(cur > mx) mx = cur;
		sum[i] = mx;
	}
	ans = max(ans , sum[n]);
	ll now = 0;
	for(int i = n ; i >= 1 ; -- i){
		now += p[i].v;
		ans = max(ans , sum[i - 1] - 2 * (C - p[i].x) + now);
	} 
}
int main(){
	ios::sync_with_stdio(0);
	cin >> n >> C;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> p[i].x >> p[i].v;
	solve();
	for(int i = 1 ; i <= n ; ++ i)
		p[i].x = C - p[i].x;
	solve();
	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 2808
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  sort(all(A));
  map<ll, set<int> > mp;
  rep(i, N) {
    if(!mp.count(A[i])) mp[A[i]] = set<int>();
    mp[A[i]].insert(i);
  }
  vector<bool> paired(N, false);
  int ans = 0;
  for(int i=N-1; i>=0; i--) {
    if(paired[i]) continue;
    int digit = ceil(log2(A[i]));
    ll pair = (ll)pow(2, digit) - A[i];
    if(pair == 0) pair = A[i];
    if(mp.count(pair)) {
      if(mp[pair].size() == 0) {
        mp.erase(pair);
      } else {
        for(auto pairIdx: mp[pair]) {
          if(pairIdx == i) continue;
          if(paired[pairIdx]) {
            mp[pair].erase(pairIdx);
            if(mp[pair].size() == 0) mp.erase(pair);
          } else {
            paired[i] = true;
            paired[pairIdx] = true;
            // cout << A[i] << ' ' << A[pairIdx] << endl;
            mp[pair].erase(pairIdx);
            if(mp[pair].size() == 0) mp.erase(pair);
            ans++;
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 29952
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define read cin >>
#define echo cout <<
#define fin << '\n'
#define _ << ' ' <<
#define in :
#define var auto&&
#define let const auto

signed main ( ) {

    int h, a;
    read h >> a;
    echo (( h + a - 1 ) / a) fin;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

using P = pair<int, int>;


vector<int> to[100005];
int cost[100005];
signed main(){
    int n;
    cin >> n;
    int k;
    cin >> k;
    int ans = 0;
    rep(i, n) {
        int x;
        cin >> x;
        if(x>=k) ans++;
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 2560
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def is_prime(x):
    if x <= 1:
        return False
    for i in range(2,int(x**1/2)):
        if x%i == 0:
            return False
    return True

def main():
    x = int(input())
    n = x
    while not is_prime(n):
        n += 1
    print(n)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<iostream>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
using namespace std;
#define REP(i,x) for (int i=0;i<x;i++)
#define REPP(i,x,y) for (int i=x;i<=y;i++)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define MX3(x,y,z) max({x,y,z})
#define MX4(x,y,z,p) max({x,y,z,p})
#define MX5(x,y,z,p,q) max({x,y,z,p,q})
#define MN3(x,y,z) min({x,y,z})
#define MN4(x,y,z,p) min({x,y,z,p})
#define MN5(x,y,z,p,q) min({x,y,z,p,q})
#define amax(x,y) x=max(x,y)
#define amin(x,y) x=min(x,y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
// #####################################################################

void solve() {

    ll n, a, b;
    SL(n);
    SL(a);
    SL(b);
    if(a > b) swap(a, b);
    ll ans = 2147483647 * 2147483647LL;
    if((b-a) % 2 == 0) {
        amin(ans, (b-a) / 2);
    } else {
        amin(ans, a+(b-a-1)/2);
        amin(ans, (n-b+1)+(n-(a+(n-b+1)))/2);
    }
    printf("%lld\n", ans);
}

void init() {
    


}

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


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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for (int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    int sum=0;
    for (int i=0;i<k;i++)
        sum+=arr[i];
    cout<<sum;

    return 0;
}


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

int main(void){
    string s;
    cin >> s;
    vector<bool> a(26, false);
    auto itr = s.begin();
    while(itr != s.end()){
        a.at(*itr - 'a') = true;
        itr++;
    }
    for(int i=0; i<a.size(); i++){
        if(!a.at(i)){
            cout << (char)(i+'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
use std::collections::*;
use std::io::*;
use std::*;
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    // iterator(splitted input-string) => iterator(output-type)
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:ty),+) => {
        ($(_get!($it; $t)),*)
    };
}

fn main() {
    let n = get!(i32);
    let s = get!(String; n as usize);
    let mut count = [0; 4];
    for i in s {
        if i == "AC" {
            count[0] += 1;
        } else if i == "WA" {
            count[1] += 1;
        } else if i == "TLE" {
            count[2] += 1;
        } else if i == "RE" {
            count[3] += 1;
        }
    }
    println!("AC x {}", count[0]);
    println!("WA x {}", count[1]);
    println!("TLE x {}", count[2]);
    println!("RE x {}", count[3]);
}


Measured memory_bytes: 7532
#include <stdio.h>
#define MAX(a,b) ((a)>(b)?(a):(b))

int main(void){
    // DP[x][i]: x = a,b,cのどれか i = i日目まで見た　このときの最大
    int N;
    scanf("%d", &N);
    int H[100000 + 10][3];
    for (int i = 0; i < N; i++) {
        scanf("%d %d %d", &H[i][0], &H[i][1], &H[i][2]);
    }
    int DP[3][100000 + 10] = {0};
    for (int i = 1; i <= N; i++) {
        for (int today = 0; today < 3; today++) 
            for (int yesterday = 0; yesterday < 3; yesterday++) 
                if (today != yesterday) {
                    
                    DP[today][i] = MAX(DP[today][i], DP[yesterday][i-1]+H[i-1][today]);
                }

    }
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        ans = MAX(ans, DP[i][N]);
    }
    printf("%d\n",ans);

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define f(i, a, b) for (int i = a; i < (b); ++i)
#define f1(i, a, b) for (int i = a; i <= (b); ++i)
#define rep(i, n) f(i, 0, n)
using namespace std;
using ll = long long;

int main(void) {
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  vector<int> a(n);
  rep(i, n) a[i] = i + 1;

  map<vector<int>, int> np;
  do {
    np[a] = np.size();
  } while (next_permutation(a.begin(), a.end()));

  int ans = abs(np[p] - np[q]);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 8556
use std::collections::HashMap;
use std::collections::BinaryHeap;

fn main(){
    let mut reward:HashMap<usize, Vec<usize>>  = HashMap::new();
    let inp: Vec<usize> = read_vec();
    // 面倒になった...
    for e in 0..inp[1] {
        reward.insert(e, Vec::new());
    }
    for i in 0..inp[0] {
        let edge: Vec<usize> = read_vec();
        let a = edge[0]-1;
        let b = edge[1];
        let num = reward.entry(a).or_insert(Vec::new());
        num.push(b);
    };


    // let mut heap = Heap{
    //     tree: Vec::new(),
    //     n: 0
    // };

    let mut works = BinaryHeap::new();
    let mut ans = 0;
    for i in 0..inp[1] {
        if let Some(x_ls) = reward.get(&i) {
            for fee in x_ls {
                works.push(*fee);
            };
        }
        // if heap.n > 0 {
        if let Some(earn) = works.pop() {
            ans += earn;
        }
        // let val = heap.take();
        // ans += val;
        // }
    };

    println!("{}", ans);


}


struct Heap {
    tree: Vec<usize>,
    n: usize,
}

impl Heap {
    fn insert(&mut self, m: usize){
        self.n += 1;
        self.tree.push(m);
        let mut index = self.n-1;
        let mut done = false;
        if index == 0 {
            done = true;
        }
        while !done {
            let next_index = (index-1) / 2;
            if self.tree[next_index as usize] > self.tree[index as usize]{
                done = true;
            } else {
                let next_val = self.tree[next_index as usize];
                self.tree[next_index as usize] = self.tree[index as usize];
                self.tree[index as usize] = next_val;
                index = next_index;
                if index == 0 {
                    done = true;
                }
            }
        }
    }


    fn take(&mut self) -> usize {
        let res = self.tree[0];
        self.tree[0] = self.tree[self.n-1];
        self.tree.pop();
        self.n -= 1;
        let mut index = 0;
        let mut done = false;
        while !done {
            if self.n < 2 * index + 2 {
                done = true;
            } else if self.n == 2 * index + 2{
                done = true;
                if self.tree[2*index+1] > self.tree[index] {
                    let next_val = self.tree[2*index+1];
                    self.tree[2*index+1] = self.tree[index];
                    self.tree[index] = next_val;
                }
            } else {
                let next_index = if self.tree[2*index + 1] > self.tree[2*index+2] {2 * index + 1} else {2* index + 2};
                let next_val = self.tree[next_index];
                self.tree[next_index] = self.tree[index];
                self.tree[index] = next_val;
                index = next_index;
            } 
        };
        res
    }

}


fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

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

int main() {
    int64_t H, W, M;
    cin >> H >> W >> M;

    vector<int64_t> h(M), w(M);
    for (int64_t i = 0; i < M; i++) {
        cin >> h[i] >> w[i];
        h[i]--; w[i]--;
    }

    vector<int64_t> h_num(H, 0), w_num(W, 0);

    for (int64_t i = 0; i < M; i++) {
        h_num[h[i]]++;
        w_num[w[i]]++;
    }

    int64_t h_num_max = *max_element(h_num.begin(), h_num.end());
    int64_t w_num_max = *max_element(w_num.begin(), w_num.end());

    //座標圧縮
    map<int64_t, int64_t> h_mp;
    for (int64_t i = 0; i < H; i++) {
        h_mp[i] = -1;
    }
    int64_t h_index = 0;
    for (int64_t i = 0; i < H; i++) {
        if (h_num[i] == h_num_max) {
            h_mp[i] = h_index++;
        }
    }
    H = h_index;

    map<int64_t, int64_t> w_mp;
    for (int64_t i = 0; i < W; i++) {
        w_mp[i] = -1;
    }
    int64_t w_index = 0;
    for (int64_t i = 0; i < W; i++) {
        if (w_num[i] == w_num_max) {
            w_mp[i] = w_index++;
        }
    }
    W = w_index;

    if (H * W > M) {
        cout << h_num_max + w_num_max << endl;
        return 0;
    }

    vector<vector<bool>> is_there(H, vector<bool>(W, false));
    for (int64_t i = 0; i < M; i++) {
        int64_t hh = h_mp[h[i]];
        int64_t ww = w_mp[w[i]];
        if (hh == -1 || ww == -1) {
            continue;
        }
        is_there[hh][ww] = true;
    }

    bool filled = true;
    for (int64_t i = 0; i < H; i++) {
        for (int64_t j = 0; j < W; j++) {
            if (!is_there[i][j]) {
                filled = false;
                break;
            }
        }
    }

    cout << h_num_max + w_num_max - filled << endl;
}

Measured memory_bytes: 71336
//09, 02, 2019, 10:09:21 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int N = 4;
int deg[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    for(int i = 0 ; i < 3 ; i++){
        int u, v;

        scanf("%d %d", &u, &v);
        u--, v--;

        deg[u]++;
        deg[v]++;
    }

    sort(deg, deg + N);

    if(deg[0] == 1 && deg[1] == 1 && deg[2] == 2 && deg[3] == 2){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

N = int(input())
IN = set([int(input()) for _ in range(N)])

cnt = 0

for x in IN:
    if is_prime(x):
        cnt += 1

print(cnt)




Measured memory_bytes: 6616
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7

int main(){
    int n;
    cin >> n;
    vector<int> count(n + 1,0);

    for(int i = 0; i < n - 1; ++i){
        int a;
        cin >> a;
        count[a]++;
    }

    for(int i = 1; i <= n; ++i){
        cout << count[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 4052
#include <math.h>
#include <stdio.h>
int n, sqrtN;
long long ans, d;
char buf[8],out[20];
k;
i;
s;
X;
int main() {
    s = read(0, buf, 8);
    for(;;) {
        k = buf[i++];
        if(k < '0') break;
        n = n * 10 + k - '0';
    }
    if(n == 1) {
        putchar(49);
    } else {
        const int sqrtN = sqrt(n);
        ans = -(long long)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
        for(int i = 1; i <= sqrtN; ++i) {
            const int a = n / i;
            ans += ((long long)i * (i + a) * (a + 1 - i));
        }
        printf("%lld",ans);
    }
}

Measured memory_bytes: 2024
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
//#define MOD 1000000007
#define MOD 998244353
#define P pair<ll, ll>

ll powmod(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}
ll f[11100000];
void cominit() {
	f[0] = 1;
	REP(i, 11000000)f[i + 1] = f[i] * (i + 1) % MOD;
}

ll com(ll n, ll r) {
	if (n < r)return 0;
	if (n < 0 or r < 0)return 0;
	return f[n] * powmod(f[r] * f[n - r], MOD - 2) % MOD;
}

ll perm(ll n, ll r) {
	if (n < r)return 0;
	if (n < 0 or r < 0)return 0;
	return f[n] * powmod(f[n - r], MOD - 2) % MOD;
}
int main() {
	cominit();
	ll n, k;
	cin >> n;
	ll ans = powmod(3, n);
	FOR(i, n / 2 + 1, n + 1) {
		ll now = com(n, i) * powmod(2, n - i) % MOD * 2 % MOD;
		ans = (ans - now + MOD) % MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 86272
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int xMinusA = x - a;
    int countOfDonuts = xMinusA / b;
    
    System.out.println(xMinusA - countOfDonuts * b);
  }
}

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

int main() {
	int n,cnt=1; string s; cin>>n>>s;
	for(int i=0;i<n-1;i++) {
		if(s[i]==s[i+1]) {
			continue;
		}
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define F(i, l, r) for(long long i =l; i<=r; ++i)
#define REP(i, r) for(int i = 0; i<(int)r; ++i)
#define Fr(i, l, r) for(long long i= l; i>=r; --i)
#define RP (i, u) for(i = u-1; i>=0; --i)
#define pb push_back
#define X first
#define Y second
#define mk make_pair
#define sz size()
#define DEBUG(x) {cerr << #x << " = " << x << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
#define Nmax 100009
#define BASE 1000009
#define name "  "
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x >> (pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1 << (pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1 << (pos-1));}
template<class T> T sqr(T a) {return a*a;}
ll n, x, a[Nmax];
bool avail[Nmax];
int main()
{
  //  freopen(name".INP", "r", stdin);
  //  freopen(name".OUT", "w", stdout);
cin >> n;
 F(i, 1, n) {
     cin >> a[i];
     }
 ll i =1, r = 0;
memset(avail, false, sizeof(avail));
while(!avail[i]&& i!= 2)
{
    avail[i] = true;
    i = a[i];
    ++r;
}
if(i==2) cout<<r; else cout<<-1;
    return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<math.h>
int main(){
    double str[1001]={0,};
    int n,i;
    double a,m,h;
    while(1){
        scanf("%d",&n);
        if(n==0){
            break;
        }
        for(i=0,m=0;i<n;i++){
            scanf("%lf",&str[i]);
            m += str[i];
        }
        m /= n;
        for(i=0,a=0;i<n;i++){
            a += (str[i]-m)*(str[i]-m);
        }
        h=sqrt(a/n);
        printf("%lf\n",h);
    }
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    string str;
    cin>>str;
    ll k;
    cin>>k;
    fr(i,0,SZ(str))
    {
        ll x=26-(str[i]-'a');
        if(str[i]=='a')
            continue;
        if(x<=k)
        {
            k-=x;
            str[i]='a';
        }
    }
    k=k%26;
    frr(i,SZ(str),0)
    {
        if(k!=0)
        {
            ll x=25-(str[i]-'a');
            x=min(x,k); 
            k-=x;
            str[i]=(str[i]+x);
        }
    }
    cout<<str<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3752
n = int(input())
vi = list(map(int,input().split()))
odd = [vi[k] for k in range(0,n,2)]
even = [vi[k+1] for k in range(0,n,2)]
odd.sort()
even.sort()

odd.append(-1)
even.append(-1)

oddset = []
oddcounter = []
pos = 0
while pos<n/2:
    oddset.append(odd[pos])
    counter = 1
    now = odd[pos]
    pos += 1
    while now == odd[pos]:
        counter +=1
        pos += 1
    oddcounter.append([counter,now])

evenset = []
evencounter = []
pos = 0
while pos<n/2:
    evenset.append(even[pos])
    counter = 1
    now = even[pos]
    pos += 1
    while now == even[pos]:
        counter +=1
        pos += 1
    evencounter.append([counter,now])

oddcounter.sort(key=lambda x:x[0],reverse=True)
evencounter.sort(key=lambda x:x[0],reverse=True)

oc = oddcounter
ec = evencounter

if len(oc)==1 and len(ec)==1:
    if oc[0][1]!=ec[0][1]:
        print(0)
    else:
        print(int(n/2))
elif len(oc)==1 and len(ec)>1:
    if oc[0][1]!=ec[0][1]:
        print(int(n/2)-ec[0][0])
    else:
        print((int(n/2)-ec[1][0]))
elif len(oc)>1 and len(ec)==1:
    oc,ec=ec,oc
    if oc[0][1]!=ec[0][1]:
        print(int(n/2)-ec[0][0])
    else:
        print((int(n/2)-ec[1][0]))
else:
    if oc[0][0]==oc[1][0]:
        print(n-oc[0][0]-ec[0][0])
    elif ec[0][0]==ec[1][0]:
        print(n-oc[0][0]-ec[0][0])
    elif oc[0][1]!=ec[0][1]:
        print(n-oc[0][0]-ec[0][0])
    else:
        print(n-max(oc[0][0]+ec[1][0],oc[1][0]+ec[0][0]))

Measured memory_bytes: 19428
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    s+='B';
    int ans=0;
    int cnt=0;
    rep(i,s.length()){
        switch(s[i]){
            case 'A':
            case 'T':
            case 'G':
            case 'C':cnt++;break;
            default:ans=max(ans,cnt),cnt=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt(); int w= sc.nextInt();
        long [][] dp = new long[h][w];
        int [][] a = new int[h][w];
        for (int i = 0; i < h; i++) {
            String s = sc.next();
            for (int j = 0; j < w; j++) a[i][j] = (s.charAt(j) == '.' ? 0 : 1);
        }
        long mod = (long) 1e9 + 7; dp[0][0] = 1;
        for (int i = 1; i < h; i++) {
            if (a[i][0] == 0) {
                dp[i][0] = dp[i-1][0];
            } else {
                dp[i][0] = 0;
            }
        }
        for (int i = 1; i < w; i++) {
            if (a[0][i] == 0) {
                dp[0][i] = dp[0][i-1];
            } else {
                dp[0][i] = 0;
            }
        }
        for (int i = 1; i < h; i++) {
            for (int j = 1; j < w; j++) {
                if (a[i][j] == 1) continue;
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
            }
        }
        System.out.println(dp[h-1][w-1]);
    }


}

Measured memory_bytes: 65888
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  // init();
  ll N;
  cin >> N;
  string S;
  cin >> S;

  vector<vll> alpha(26);
  rep(i, S.size()) {
    ll index = S[i] - 'a';
    alpha[index].pb(i);
  }

  ll Q;
  cin >> Q;

  rep(i, Q) {
    int type;
    // cin >> type;
    scanf("%d", &type);
    if (type == 1) {
      ll a;
      char bb[10];
      scanf("%lld", &a);
      --a;
      scanf("%s", bb);
      char b = bb[0];

      if (b == S[a]) {
        continue;
      }

      // --
      ll index = S[a] - 'a';
      alpha[index].erase(find(ALL(alpha[index]), a));

      S[a] = b;

      // ++
      auto lb = lower_bound(ALL(alpha[b - 'a']), a);
      alpha[b - 'a'].insert(lb, a);
    } else {
      int a, b;
      scanf("%d %d", &a, &b);
      --a;
      --b;
      ll ans = 0;
      rep(i, alpha.size()) {
        if (alpha[i].size() == 0) continue;
        ll lb = lower_bound(ALL(alpha[i]), a) - alpha[i].begin();
        ll ub = upper_bound(ALL(alpha[i]), b) - alpha[i].begin();
        if (lb <= (ll)alpha[i].size() - 1 && lb != ub) {
          ans++;
        }
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}

Measured memory_bytes: 10064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		if (N==1)
			System.out.println("Hello World");
		
		else
			System.out.println(sc.nextInt()+sc.nextInt());
		
		sc.close();

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> Pairs;

const int N = 4040404;

inline char get(void) {
	static char buf[100000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 100000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
template<typename T>
inline void read(T &x) {
	static char c; x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}

bitset<N> f;
int s, x, n;

int main(void) {
	read(n); f[0] = 1;
	while (n--) {
		read(x); s += x;
		f |= f << x;
	}
	for (int i = s - s / 2; ; i++)
		if (f[i]) {
			printf("%d\n", i);
			break;
		}
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int a,b,c[100001],i,count=1,sum=0;
	scanf("%d %d",&a,&b);
	
	for(i=0;i<a;i++){
		scanf("%d",&c[i]);
		sum=sum+c[i];
		if(sum<=b)count++;
	}
	
	printf("%d\n",count);
	
	return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
//#define int __int128
//#define ll __int128
//typedef __int128 long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}



void smain() {

    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    fori (i, n) {
        cnt += s[i] == 'R';
    }
    if (cnt > n - cnt) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
class RPN:
    def __init__(self, l):
        self.l = l.split()
        self.rpn = {'+': lambda x, y: x + y,
                    '-': lambda x, y: y - x,
                    '*': lambda x, y: x * y,}
        self.calc()
        
    def calc(self):
        stack = []
        
        for i in self.l:
            if not self.rpn.get(i):
                stack.append(int(i))
            else:
                stack.append(self.rpn[i](stack.pop(), stack.pop()))
        print(stack.pop())
l = input()
rpg = RPN(l)


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

using namespace std;

typedef long long ll;
typedef  pair<int,int> pa;

int mod=1e9+7;
const int N=2e5+100;

int gcd(int x,int y)
{
    return !y?x:gcd(y,x%y);
}
int main()
{

   int k;cin>>k;
   ll sum=0;
   for(int i=1;i<=k;i++)
    for(int j=1;j<=k;j++)
    for(int r=1;r<=k;r++)
     sum+=gcd(i,gcd(j,r));
     cout<<sum;
   return 0;
}


Measured memory_bytes: 3632
import sys
from itertools import accumulate
N,*L = map(int, open(0).read().split())
ls = []
ml = -1
nr = -1
li = -1
mr = 10**9
nl = -1
ri = -1
for i,(a,b) in enumerate(zip(*[iter(L)]*2)):
  ls.append((a,b))
  if ml<a:
    ml = a
    nr = b
    li = i
  if b<mr:
    mr = b
    nl = a
    ri = i

if ri!=li:
  a,b = min(li,ri),max(li,ri)
  ls.pop(b)
  ls.pop(a)
  N -= 2
else:
  ls.pop(li)
  N -= 1
if N==0:
  ans = max(mr-nl+1,0)+max(nr-ml+1,0)
  print(ans)
  sys.exit()
ls.sort()
length = max(c[1]-c[0]+1 for c in ls)
ans = max(mr-ml+1,0)+length
r = list(accumulate((c[1] for c in ls[::-1]), min))[::-1]
l = list(c[0] for c in ls)
ans = max(ans, max(mr-nl+1,0)+max(r[0]-ml+1,0))
for i in range(N-1):
  xl = max(nl,l[i])
  xr = min(nr,r[i+1])
  ans = max(ans, max(mr-xl+1,0)+max(xr-ml+1,0))
xl = max(nl,l[N-1])
ans = max(ans, max(mr-xl+1,0)+nr-ml+1)
print(ans)

Measured memory_bytes: 25204
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

#define MAX_N 90
#define MAX_M 90

int m, n;
int field[MAX_N][MAX_M];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int count_ice(int y, int x) {
	if (field[y][x] == 0) return 0;
	field[y][x] = 0;
	int break_ice = 1;
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx < 0 || m <= nx || ny < 0 || n <= ny) continue;
		break_ice = max(break_ice, count_ice(ny, nx)+1);
	}
	field[y][x] = 1;
	return break_ice;
}

int main() {
	while (cin >> m >> n, m || n) {
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> field[i][j];

		int break_max = 0;
		for (int i = 0; i < n; i++) 
			for (int j = 0; j < m; j++) 
				break_max = max(break_max, count_ice(i, j));

		cout << break_max << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
from collections import defaultdict

S = input()
T = input()

s_counter = defaultdict(int)
t_counter = defaultdict(int)

for s in S:
    s_counter[s] += 1
for t in T:
    t_counter[t] += 1

s_counter = sorted(list(s_counter.items()), key=lambda x: x[1])
t_counter = sorted(list(t_counter.items()), key=lambda x: x[1])

if len(s_counter) != len(t_counter):
    print("No")
else:
    flag = True
    for s_tup, t_tup in zip(s_counter, t_counter):
        if s_tup[1] != t_tup[1]:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4144
#include<stdio.h>
int main(void){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++){
				if(H-i>0&&W-j>0&&i!=1&&j!=1){
					printf(".");
				}
				else{
					printf("#");
				}
			}
			printf("\n");
			if(i==H){
				printf("\n");
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 572
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nc = Input.ar;
        var stc = Input.ar2D(nc[0]);var NU = (int)1e5 + 2;
        var ct = new int[NU];
        for(var i = 1; i <= nc[1]; i++)
        {
            var imos = new int[NU];
            for(var j=0;j<nc[0];j++)
                if (stc[j][2] == i)
                {
                    imos[stc[j][0]]++;
                    imos[stc[j][1] + 1]--;
                }
            for (var j = 1; j < NU; j++)
            {
                imos[j] += imos[j - 1];
                if (imos[j] > 0) ct[j]++;
            }
        }
        WriteLine(ct.Max());
    }
    
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 35764
#include<bits/stdc++.h>
using namespace std;
int x,y,a[15],b[15],c[15];
int main(){
    scanf("%d%d",&x,&y);
    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
        if(y==1||y==3||y==5||y==7||y==8||y==10||y==12)printf("Yes\n");
        else printf("No");
    }
    if(x==4||x==6||x==9||x==11){
        if(y==4||y==6||y==9||y==11)printf("Yes\n");
        else printf("No");
    }
    if(x==2){
        if(y==2) printf("Yes\n");
        else printf("No");
    }
    return 0;
}

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

static const int MAX = 200000;

int main(void)
{
	ios::sync_with_stdio(false);

	int n,i, minv, maxv;
	static int R[MAX];

	cin >> n;
	for (i = 0; i < n; i++)
		cin >> R[i];

	minv = R[0];
	maxv = R[1] - R[0];
	for (i = 2; i < n; i++){
		if (R[i - 1] < minv)
			minv = R[i - 1];
		if (R[i] - minv > maxv){
			maxv = R[i] - minv;
		}
	}
	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 1976
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e6+10;
int a[N];
void solve()
{
	int n;
	cin>>n;
	if(n%1000==0)
		cout<<0<<endl;
	else
	{
		int ans=n%1000;
		ans=1000-ans;
		cout<<ans<<endl;
	}
}
signed main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,k,a[111111],minn=2147483647;
int main(){
    cin>>n>>k;
    for (int i=1;i<=n;++i) cin>>a[i];
    sort(a+1,a+n+1);
    int i=1,j=k;
    while(j<=n){
        minn=min(minn,a[j]-a[i]);
        ++i;++j;
    }
    cout<<minn<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=2509;
	int n;
	queue<int> q;
	struct tree{
		int fa[N],deg[N],head[N],nex[N<<1],to[N<<1],cnt;
		inline void add(int u,int v){
			nex[++cnt]=head[u];
			head[u]=cnt,to[cnt]=v,deg[v]++;
		}
		inline void getfa(int u,int _f){
			fa[u]=_f;
			for(int i=head[u];i;i=nex[i])
				if(to[i]^_f) getfa(to[i],u);
		}
		inline bool topsort(){
			while(!q.empty()) q.pop();
			for(int i=1;i<=n;i++) if(!deg[i]) q.push(i);
			int tot=0;
			while(!q.empty()){
				int u=q.front();q.pop();
				tot++;
				for(int i=head[u];i;i=nex[i])
					if(!--deg[to[i]]) q.push(to[i]);
			}
			return tot==n;
		}
	}A,B,G;
	inline int solve(){
		for(int i=1;i<=n;i++)
			if(A.fa[i]==B.fa[i] && A.fa[A.fa[i]]!=B.fa[A.fa[i]]) return n+1;
		for(int i=1;i<=n;i++) G.head[i]=G.deg[i]=0;G.cnt=0;
		int ret=0;
		for(int i=1;i<=n;i++){
			if(A.fa[i]!=B.fa[i]) G.add(i,A.fa[i]),ret++;
			if(A.fa[B.fa[i]]!=B.fa[B.fa[i]]) G.add(B.fa[i],i);
		}
		if(G.topsort()) return ret;
		else return n+1;
	}
	int main(){
		int T=read<int>();
		while(T--){
			n=read<int>();
			A.cnt=B.cnt=0;
			for(int i=1;i<=n;i++) A.head[i]=B.head[i]=A.deg[i]=B.deg[i]=0;
			for(int i=1;i<n;i++){
				int u=read<int>(),v=read<int>();
				A.add(u,v),A.add(v,u);
			}
			for(int i=1;i<n;i++){
				int u=read<int>(),v=read<int>();
				B.add(u,v),B.add(v,u);
			}
			int ans=n+1;
			for(int i=1;i<=n;i++){
				A.getfa(i,0),B.getfa(i,0),ans=min(ans,solve());
				if(A.deg[i]==1)
					for(int j=1;j<=n;j++) if(j^i){
						A.getfa(j,0),A.fa[j]=i,A.fa[i]=0;
						ans=min(ans,solve()+1);
					}
			}
			if(ans<=n) printf("%d\n",ans);
			else puts("-1");
		}
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 3664
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N,K;
  get(N,K);
  priority_queue<Pi,vector<Pi>,less<Pi>> list;
  FOR(i,N){
    int t,d;
    get(t,d);
    list.push(Pi(d,t-1));
  }
  vector<bool> used(N);
  int kinds=0;
  priority_queue<ll,vector<ll>,greater<ll>> yobun;
  ll sum=0;
  ll ans=0;
  FOR(i,K){
    Pi next=list.top();
    list.pop();
    if(!used[next.second]){
      used[next.second]=1;
      kinds++;
    }else{
      yobun.push(next.first);
    }
    sum+=next.first;
  }
  ans=sum+(ll)kinds*kinds;
  while(!list.empty()&&!yobun.empty()){
    ll jogai=yobun.top();
    yobun.pop();
    sum-=jogai;
    Pi next=list.top();
    list.pop();
    while(!list.empty()&&used[next.second]){
      next=list.top();
      list.pop();
    }
    if(!used[next.second]){
      used[next.second]=1;
      kinds++;
    }
    sum+=next.first;
    ans=max(ans,sum+(ll)kinds*kinds);
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 1908
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    if (n < 1000)
        cout << "ABC";
    else cout << "ABD";
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define int long long

int N,K;
int a[300];
bool dp[100001];

signed main() {
  cin >> N >> K;
  for(int i=0; i<N; i++) cin >> a[i];

  dp[0]=false;
  for(int i=0; i<=K; i++) 
    for(int j=0; j<N && i-a[j]>=0; j++)
      dp[i] |= !dp[i-a[j]];

  if(dp[K]) puts("First");
  else puts("Second");
}


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

using namespace std;

long long INF = 1e18;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long ans = 0;
    if (a[0] > 0) {
        ans = 1;
        for (auto v: a) {
            if (ans >= 2*INF/v) {
                ans = -1;
                break;
            } else {
                ans *= v;
            }
        }
        if (ans > INF) {
            ans = -1;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3964