akhauriyash/Code-Regression huggingface dataset:
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
# mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file=1





def solve():


    # for _ in range(ii()):
    
        

    n=ii()
    n%=1000
    if(n!=0):
        n=1000-n
    print(n)
 








        
if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):
            sys.stdin=open('input1.txt', 'r')
            sys.stdout=open('output1.txt','w')
        else:
            input=sys.stdin.readline
    solve()


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

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

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

    int left = n - 1;
    int step = k - 1;

    int ans = (left + step - 1)/step;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
ll a[200000];
deque<ll> q;

void init()
{
}

void solve()
{
    int d = 1;
    REP(i, N){
        if(d == 1) q.push_back(a[i]);
        else q.push_front(a[i]);
        d *= -1;
    }
    if(N % 2 != 0){
        for(auto it = q.rbegin(); it != q.rend(); it++){
            cout << (it == q.rbegin() ? "" : " ") << *it;
        }
    }else{
        for(auto it = q.begin(); it != q.end(); it++){
            cout << (it == q.begin() ? "" : " ") << *it;
        }
    }
    cout << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> a[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 5376
# -*- coding: utf-8 -*-
n = gets.chomp.to_i

a = Array.new(100)

str = gets.chomp
a = str.split.map(&:to_i)

flag = 1
count = 0

while flag == 1 do
  flag = 0
  (n-1).downto(1) do |i|
    if a[i] < a[i-1] then
      change = a[i]
      a[i] = a[i-1]
      a[i-1] = change
      flag = 1
      count += 1
    end
  end
end
for i in 0..n-1 do
  print a[i]
  print " " if i != n-1
end

print "\n", count, "\n"

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

using namespace std;

template<class T>
inline T min(vector<T> v) { return *min_element(v.begin(), v.end()); }
template<class T>
inline T max(vector<T> v) { return *max_element(v.begin(), v.end()); }

vector<int> topo_sort(vector<vector<int>> g) 
{ 
  int n = g.size();
  
  vector<int> in_degree(n); 
  
  for (int u=0; u<n; u++) 
  { 
    for (auto itr = g[u].begin(); itr != g[u].end(); itr++) 
      in_degree[*itr]++; 
  } 

  queue<int> q; 
  for (int i = 0; i < n; i++) 
      if (in_degree[i] == 0) 
          q.push(i); 
  
  int cnt = 0; 
  vector <int> top_order; 
  
  while (!q.empty()) 
  { 
    int u = q.front(); 
    q.pop(); 
    top_order.push_back(u); 
  
    for (auto itr = g[u].begin(); itr != g[u].end(); itr++) 
      if (--in_degree[*itr] == 0) 
        q.push(*itr); 
  
    cnt++; 
  } 
  
  if (cnt != n) 
  { 
    cout << "There exists a cycle in the graph\n"; 
    exit(0);
  } 
  
  return top_order;
} 

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);

  int N, M;
  cin >> N >> M;
  vector<vector<int>> graph(N);

  int x, y;
  for (int i = 0; i < M; ++i) {
    cin >> x >> y;
    graph[x-1].push_back(y-1);
  }

  vector<int> dp(N);
  vector<int> ts = topo_sort(graph);

  // for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (auto s: graph[ts[j]]) {
        dp[s] = max(dp[s], dp[ts[j]]+1);
      }
    }
  // }

  int ans = max(dp);
  cout << ans << endl;

  return 0;
}


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

#define READ freopen("alu.txt", "r", stdin);
#define WRITE freopen("vorta.txt", "w", stdout);
typedef long long int LL;

LL arr[100000];

int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
    sort(arr, arr + n, greater<LL>());


    int x, y;
    LL a, b;
    bool a_paisi = false, b_paisi = false;

    for(x = 0, y = 1; y < n && x < n - 1; y++, x++){
        if(arr[x] == arr[y]){
            a_paisi = true;
            a = arr[x];
            break;
        }
    }

    if(a_paisi){
        for(x = y + 1, y = y + 2; y < n && x < n - 1; x++, y++){
            if(arr[x] == arr[y]){
                b_paisi = true;
                b = arr[x];
                break;
            }
        }
    }

    if(a_paisi && b_paisi) printf("%lld", a*b);
    else printf("0");

    return 0;
}


Measured memory_bytes: 1024
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll mod=998244353;

int n;

char wcz[nax];
int tab[nax];

priority_queue <int> kol[4];

int zgar1[nax];
int zgar2[nax];
int wrzuc1[nax];
int wrzuc2[nax];

ll wyn=1;

int ile[nax];

int main()
{
	scanf("%d", &n);
	scanf("%s", wcz+1);
	for (int i=1; i<=3*n; i++)
	{
		if (wcz[i]=='R')
			tab[i]=1;
		if (wcz[i]=='G')
			tab[i]=2;
		if (wcz[i]=='B')
			tab[i]=3;
	}
	for (int i=1; i<=3*n; i++)
	{
		kol[tab[i]].push(-i);
		if (!kol[1].empty() && !kol[2].empty() && !kol[3].empty())
		{
			vector <pii> wek;
			for (int j=1; j<=3; j++)
			{
				wek.push_back({-kol[j].top(), j});
				kol[j].pop();
			}
			sort(wek.begin(), wek.end());
			int a=wek[0].second;
			int b=wek[1].second;
			int c=wek[2].second;
			int x=wek[0].first;
			int y=wek[1].first;
			int z=wek[2].first;
			wrzuc1[x]=a*1000;
			zgar1[y]=a*1000;
			zgar2[y]=c*100;
			wrzuc2[z]=c*100;
		}
	}
	for (int i=1; i<=3*n; i++)
	{
		if (wrzuc1[i]>=500)
		{
			debug() << "w " << i;
			ile[wrzuc1[i]]++;
		}
		
		if (zgar1[i]>=500)
		{
			debug() << "z " << i;
			if (zgar1[i])
			{
				wyn=(wyn*ile[zgar1[i]])%mod;
				ile[zgar1[i]]--;
			}
		}
	}
	debug() << imie(wyn);
	for (int i=3*n; i; i--)
	{
		if (wrzuc2[i]<=500)
		{
			ile[wrzuc2[i]]++;
		}
		
		if (zgar2[i]<=500)
		{
			if (zgar2[i])
			{
				wyn=(wyn*ile[zgar2[i]])%mod;
				ile[zgar2[i]]--;
			}
		}
	}
	debug() << imie(wyn);
	for (int i=1; i<=n; i++)
		wyn=(wyn*i)%mod;
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 22784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, x;
    cin >> n >> x;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    vll smin(n, INF);
    ll ans = INF;
    rep(i, n){
        rep(j, n){
            chmin(smin[j], a[(j-i+n)%n]);
        }
        chmin(ans, accumulate(ALL(smin), 0ll)+x*i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define int long long 
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MAX(x) *max_element(ALL(x)) //最小値を求める
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PB push_back //vectorヘの挿入
#define PI 3.14159265358979323846

signed main(){
    int S,W;
    cin >> S >>W ;

    if(W>=S) cout << "unsafe" ;
    else cout << "safe" ;

    return 0;
}

Measured memory_bytes: 3596
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception {
        InputStreamReader r = new InputStreamReader(System.in);
        long N = nextLong(r);
        long A = nextLong(r);
        long B = nextLong(r);

        long AB = A > B ? A - B : B - A;
        long ans = 0;
        if (AB % 2 == 0) {
            ans = AB / 2;
        } else {
            long NA = N > A ? N - A : A - N;
            long A1 = A - 1;
            long NB = N > B ? N - B : B - N;
            long B1 = B - 1;

            long DA = NA > A1 ? A1 : NA;
            long DB = NB > B1 ? B1 : NB;
            if (DA > DB) {
                ans = DB + (AB+1)/2;
            } else {
                ans = DA + (AB+1)/2;
            }
        }

        System.out.println(ans);
    }

    public static long nextLong(InputStreamReader r) throws Exception {
        String str = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10 || c == -1) {
                break;
            }
            str += (char)c;
        }
        return Long.parseLong(str);
    }
}


Measured memory_bytes: 21332
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec() -> Vec<i32> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn read_int_tuple() -> (i32, i32) {
    let v = read_vec();
    (v[0], v[1])
}

fn main() {
    let (N, M) = read_int_tuple();
    let M = M as usize;
    let mut s = vec![vec![]; M];
    for i in 0..M {
        s[i] = read_vec()[1..].to_vec();
    }
    let p = read_vec();
    let mut ans = 0;
    for bits in 0..(1 << N) {
        let mut ok = true;
        for i in 0..M {
            let mut count = 0;
            for sij in &s[i] {
                if bits & (1 << (sij - 1)) != 0 {
                    count += 1;
                }
            }
            if count % 2 != p[i] {
                ok = false;
                break;
            }
        }
        if ok {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
x = int(input())
res = []
a=list("zabcdefghijklmnopqrstuvwxy")
while x > 0:
  if x % 26 == 0:
    res.append("z")
    x = x // 26 - 1
  else:
    res.append(a[x % 26])
    x = x // 26 

print("".join(res)[::-1])

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

int main(){
    int N,K;
    cin >> N >> K;
    int h[100000];
    for(int i=0;i<N;i++) cin >> h[i];
    int dp[100100];
    for(int i=0;i<100100;i++)dp[i] = INT_MAX;
    dp[0] = 0;
    for(int i=0;i<N;i++){
        for(int k=1;k<=K;k++){
            if(i+k == N) break;
            dp[i+k] = min(dp[i]+abs(h[i+k]-h[i]), dp[i+k]);
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,x;
    cin>>n;
    vector<pair<int,int> >vi;
    for(i =1 ;i<=n;i++)
    {
        cin>>x;
        vi.push_back(make_pair(x,i));
    }
    sort(vi.begin(),vi.end());
    for(i = 0;i<n;i++)
    {
        cout<<vi[i].second<<" ";
    }
    cout<<endl;
}


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

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

    int count=0;
    for(int j = 0; j<N; j++){
        if(vec.at(j) != j+1){
            count += 1;
        }
    }

    if(count <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

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

int main() {
    int A, B, C, X, res, i_d, j_d, k_d;
    res = 0;

    cin >> A >> B >> C >> X;

    for (int i = 0; i <= A; i++){
        for (int j = 0; j <= B; j++){
            for (int k = 0; k <= C; k++){
                if (500 * i + 100 * j + 50 * k == X){
                    res += 1;
                }
            }
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
 
/* Coding Space*/
int main(){
  string s; cin >> s;
  rep(i,s.size()-1){
    if(s[i] == 'A' && s[i+1] == 'C'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl; 
  return 0;
}

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

using namespace std;

#define endl '\n'

const int nax = 2*1e5 + 5;
int to[nax];
bool vis[nax];
int order[nax];
long long cycleSize;
int beginCycle;
long long n, k;


void solve(int u, int o){
  while(to[u]){
    if(order[u]){
      cycleSize = o-order[u];
      beginCycle = u;
      break;
    }
    order[u] = o++;
    u = to[u];
  }

  u = 1;
  long long cnt = 0;

  if(beginCycle){
     while(u != beginCycle && k){
       u = to[u];
       k--;
     }
     k = k%cycleSize;
  }
  
  while(cnt < k){
      u = to[u];
      cnt++;
  }

  cout << u << endl;
}

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  
  cin >> n >> k;

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

  solve(1,1);


 
  
  return 0;
}

Measured memory_bytes: 5220
#include<iostream>
#include<cstdio>
#define pq priority_queue
using namespace std;
int n;
int l(int x)
{
    if(x==1)
        return 2*n-1;
    else
        return x-1;
}
int r(int x)
{
    if(x==2*n-1)
        return 1;
    else
        return x+1;
}
int main()
{
    int now,k,gg=1;
    cin>>n>>k;
    now=n;
    if(k==1 || k==2*n-1)
        printf("No\n");
    else
    {
        printf("Yes\n");
        while(now<k)
        {
            now++;
            gg=r(gg);
        }
        while(now>k)
        {
            now--;
            gg=l(gg);
        }
        for(int i=1;i<2*n;i++)
        {
            printf("%d\n",gg);
            gg=r(gg);
        }
    }
    return 0;
}


Measured memory_bytes: 1664
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;
    l(i,0,n)
    {
        cin>>a;
        v.pb(a);
        //d=d+a;
    }
    hi(v);
    l(i,m,n)
    {
        d=d+v[i];
    }
    cout<<d<<endl;

}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,k;

int main()
{
	cin>>n>>k;
	if(n<=k) cout<<min(n,k-n)<<endl;
	else
	{
		n%=k;
		cout<<min(n,k-n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;

    cin >> n;

    for (int i = n; i < 1000; i++)
    {
        if (i % 111 == 0)
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define inf 10000000
#define mod 30000000
#define omarshagar                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;
bool same(int arr1[],int arr2[],int n)
{
    for(int i=0;i<n;i++)
    {
        if(arr1[i]!=arr2[i])return 0;
    }
    return 1;
}
ll counnt(int arr[],int res[],int n)
{
    int ress=1;
    if(same(arr,res,n))return 1;
    while(next_permutation(arr,arr+n))
    {
        ress++;
        if(same(arr,res,n))return ress;
    }
    return ress;
}

int main()
{
   int n;
   cin>>n;
   int arr[n];
   int arr1[n];
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   for(int i=0;i<n;i++)
   {
       cin>>arr1[i];
   }
   ll a=0,b=0;
   int tmp[n];
   for(int i=0;i<n;i++)
   {
       tmp[i]=arr[i];
   }
   sort(tmp,tmp+n);
   a=counnt(tmp,arr,n);
    for(int i=0;i<n;i++)
    {
        tmp[i]=arr1[i];
    }
    sort(tmp,tmp+n);
   b=counnt(tmp,arr1,n);
    cout<<abs(a-b)<<endl;
    return 0;
}
/*












 */

Measured memory_bytes: 256
N=int(input())
A=input()
B=input()
C=input()
ans=0
for i in range(N):
  if A[i]==B[i]==C[i]:
    ans+=0
  elif A[i]==B[i] or B[i]==C[i] or C[i]==A[i]:
    ans+=1
  else:
    ans+=2
print(ans)
   

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int a[n][n-1];
    for(int i=0;i<n;++i){
        for(int j=0;j<n-1;++j){
            cin>>a[i][j];
            --a[i][j];
        }
    }
    set<int> st[2];
    int pos[n]={};
    for(int i=0;i<n;++i){
        st[1].insert(i);
    }
    int ans=0;
    while(++ans&&st[ans&1].size()){
        for(int p:st[ans&1]){
            if(pos[p]==n-1)continue;
            int q=a[p][pos[p]];
            if(st[(ans+1)&1].find(p)!=st[(ans+1)&1].end())continue;
            if(st[(ans+1)&1].find(q)!=st[(ans+1)&1].end())continue;
            if(a[q][pos[q]]==p){
                ++pos[p];
                ++pos[q];
                if(pos[p]!=n-1)st[(ans+1)&1].insert(p);
                if(pos[q]!=n-1)st[(ans+1)&1].insert(q);
            }
        }
        st[ans&1].clear();
    }
    --ans;
    for(int i=0;i<n;++i){
        if(pos[i]!=n-1)ans=-1;
    }
    cout<<ans<<endl;
}


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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    set<string> st;
    int n;
    cin >> n;
    while(n--){
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << "\n";
}


Measured memory_bytes: 19216
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define vii vector<pair<int,int> >
#define vi vector<ll>
#define ll long long
#define rep(i,a,b) for(i=a;i<=b;i++)
#define inf 100000000000000000

using namespace std;

int n,k;
ll v[100001][3];
ll dp[100001][3]; 

ll f(int i, int j)
{
    if(i==n) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    dp[i][j]=v[i][j]+max(f(i+1,(j+1)%3),f(i+1,(j+2)%3));
    return dp[i][j];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>v[i][0]>>v[i][1]>>v[i][2];
    }
    for(int i=0;i<n;i++)
    {
        dp[i][0]=dp[i][1]=dp[i][2]=-1;
    }
    dp[0][0]=v[0][0]+max(f(1,1),f(1,2));
    dp[0][1]=v[0][1]+max(f(1,2),f(1,0));
    dp[0][2]=v[0][2]+max(f(1,0),f(1,1));
    //cout<<dp[0][0]<<endl;
    //cout<<dp[0][1]<<endl;
    //cout<<dp[0][2]<<endl;
    ll ans=max(dp[0][0],max(dp[0][1],dp[0][2]));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11264
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

l = [0]*5

for i in range(5):
	l[i] = int(input())

t = [0]*5

for i in range(5):
	t[i] = l[i]%10
	if t[i] == 0:
		t[i] = 10

#print(l)		
#print(t)

k = -1

k = t.index(min(t))

#print(k)

for i in range(5):
	if i != k and l[i]%10 != 0:
		l[i] = l[i] + (10-l[i]%10)

#print(l)

print(sum(l))



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s=to_string(n);
  int c=s.size()-1;
  if(s[c]=='3') cout<<"bon";
  else if(s[c]=='0'||s[c]=='1'||s[c]=='6'||s[c]=='8') cout<<"pon";
  else cout<<"hon";
}


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

int main(void){
    double L; cin >> L;
    double a=L/3,b=L/3,c=L/3;
    double ans = a*b*c;
    //cout << ans << endl;
     //小数点以下の長さを指定
    cout << fixed << setprecision(14) << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
int a[4];
int main(){
	for(int i=1;i<=3;i++)scanf("%d",&a[i]);
	sort(a+1,a+4);
	if(a[1]==a[2]&&a[1]==a[3]){
		printf("No\n");
	}else if(a[1]==a[2]||a[2]==a[3]){
		printf("Yes\n");
	}else printf("No\n");
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int lim = 1000000001;
int calc(vector<int> v1, vector<int> v2, bool flag_eq = false) {
	if(v1 < v2) return -calc(v2, v1, true) + 1;
	if((v1[1] - v2[1]) % v1[0] != 0) return (v1[1] - v2[1]) / v1[0] + 1;
	int ex = (v1[1] - v2[1]) / v1[0];
	int lp = v1.size();
	for(int i = 0; i < ex; i++) {
		int clp = lp;
		for(int j = 1; j < lp; j++) {
			v2[j] += v2[j - 1];
			if(v2[j] >= lim) {
				v2[j] = lim;
				if(clp == lp) clp = j;
			}
		}
		lp = clp;
		if(lp == 2) {
			v2[1] += ex - i - 1;
			break;
		}
	}
	if((!flag_eq && v1 < v2) || (flag_eq && v1 <= v2)) return ex;
	return ex + 1;
}
int N, M;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N >> M;
	vector<vector<int> > v(N, vector<int>(M));
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < M; j++) {
			cin >> v[i][j];
		}
	}
	if(M == 1) {
		bool f = true;
		for(int i = 1; i < N; i++) {
			if(v[i - 1][0] >= v[i][0]) f = false;
		}
		cout << (f ? 0 : -1) << endl;
	}
	else {
		bool f = true;
		for(int i = 1; i < N; i++) {
			if(v[i - 1][0] > v[i][0]) f = false;
		}
		if(!f) cout << -1 << endl;
		else {
			long long cur = 0, ret = 0;
			for(int i = 1; i < N; i++) {
				if(v[i - 1][0] != v[i][0]) {
					cur = 0;
					continue;
				}
				long long res = calc(v[i - 1], v[i]);
				cur = max(cur + res, 0LL);
				ret += cur;
			}
			cout << ret << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 6272
n=int(input())
a=[[] for i in range(n)]
for i in range(n):
    b=int(input())
    for j in range(b):
        c,d= map(int, input().split())
        a[i].append((c-1,d))

ans=0
for i in range(2**n):
    flag=True
    count=0
    for j in range(n):
        if (i>>j)&1:
            # １がたったら正直者
            count+=1
            for k in range(len(a[j])):
                if a[j][k][1]==1:
                    if (i>>(a[j][k][0]))&1==1:
                        continue
                    else:
                        flag=False
                        break

                if a[j][k][1]==0:
                    if (i>>(a[j][k][0]))&1!=1:
                        continue
                    else:
                        flag=False
                        break
    if flag:
        ans=max(ans,count)
print(ans)


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, m, e;
    cin >> b >> m >> e;
    rotate(v.begin() + b, v.begin() + m, v.begin() + e);
  }

  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      cout << v.at(i) << endl;
    } else {
      cout << v.at(i) << " ";
    }
  }
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL)
#define REP(i,a,b) for(int i=a,_b=b;i<=_b;i++)
#define rep(i,n) REP(i,0,n-1)
#define FORD(i,b,a) for(int i=b,_a=a;i>=_a;i--)
#define ford(i,n) FORD(i,n-1,0)
#define sqr(x) ((x)*(x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define add push_back
#define len(arr) arr.size()
#define print(x) cout<<(x)<<'\n'
using namespace std;

const int N = 4e5 + 1;

int main() {
	SPEED;
	//freopen("in.txt", "r", stdin);
	string s; cin >> s;
	int k; cin >> k;
	for(int i = 0; i < len(s); i += k) cout << s[i];
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n,i;
  i=0;
  scanf("%d", &n);
  double p,q;
  p=n/1.08;
  while(i<p){
    i++;
  }
  
  double r;
  r=i*1.08;
  if(r-n>=0 && r-n<1){
    printf("%d\n",i);
  }else{
    printf(":(");
  }
 
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define N 1050
int lcs(string X,string Y){
  int c[N+1][N+1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for(int i=0;i<=m;i++) c[i][0]=0;
  for(int j=1;j<=n;j++) c[0][j]=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(X[i]==Y[j]) c[i][j]=c[i-1][j-1]+1;
      else c[i][j]=max(c[i-1][j],c[i][j-1]);
      maxl=max(maxl,c[i][j]);
    }
  }
  return maxl;
}
int main(){
  string s,t,b;cin>>s>>t;
  int i;bool f=0;
  for(i=0;i<s.size();i++) if(i%2==1) b+=s[i];
  f|=(lcs(b,t)==b.size());b="";
  for(i=0;i<s.size();i++) if(i%2==0) b+=s[i];
  f|=(lcs(b,t)==b.size());b="";
  cout << (f?"Yes":"No") << endl;
  return 0;
}

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

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

int main(void){
  string S;
  cin >> S;

  long long N;
  N = S.size();

  long long ans = 0;
  for (int i = 0; i < N - 1; ++i){
    if (S.at(i) != S.at(i + 1)) {;}
    if (S.at(i) == S.at(i + 1) && S.at(i) == '0'){
      S.at(i + 1) = '1';
//  cout << S << endl;
      ans++;
    }
    if (S.at(i) == S.at(i + 1) && S.at(i) == '1'){
      S.at(i + 1) = '0';
//  cout << S << endl;
      ans++;
    }
  }

  cout << ans << endl;




  return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
map<int,int>ma;
bool f(int a){
	while(a){
		if(ma[a%10])return true;
		a/=10;
	}
	return false;
}
int main(){
	int a,n;
	cin>>a>>n;
	rep(i,n){
		int b;
		cin>>b;
		ma[b]=true;
	}
	while(f(a))a++;
	cout<<a<<endl;
}








Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;

    // n = qk^x + a
    // n/k = qk^x-1 + b
    int count = 0;
    while(n>0)
    {
        n /= k;
        count++;
    }

    cout << count++ << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000

void check(map<string,int> &mp,int goal,int now,string now_s){
	if(now==goal)mp[now_s]=-1;
	
	for(int i=0;i<10;i++){
		if(now+i+1>goal)break;
	
		check(mp,goal,now+i+1,now_s+(char)('0'+i));
	}
	
}

int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

int main(){
	int N;
	cin>>N;
	int X,Y,Z;
	cin>>X>>Y>>Z;
	
	map<string,int> str1,str2,str3;
	
	check(str1,X,0,"");
	check(str2,Y,0,"");
	check(str3,Z,0,"");
	
	map<string,int> S;
	
	for(auto &a:str1){
		for(auto &b:str2){
			for(auto &c:str3){
				S[a.first+b.first+c.first]=-1;
			}
		}
	}
	
	map<string,int> pre_S;
	for(auto &a:S){
		for(int i=0;i<=a.first.size();i++){
			pre_S[a.first.substr(0,i)]=-1;
		}
	}
	int cnt = 0;
	for(auto &a:pre_S){
		a.second = cnt;
		cnt++;
	}
	
	vector<vector<int>> E(pre_S.size(),vector<int>(10,0));

	for(auto &a:pre_S){
		for(int i=0;i<10;i++){
			string s = a.first + (char)('0'+i);
			for(int j=0;j<=s.size();j++){
				if(S.count(s.substr(j))){
					E[a.second][i] = pre_S[s.substr(j)];
					goto L;
				}
			}
			
			for(int j=0;j<s.size();j++){
				if(pre_S.count(s.substr(j))!=0){
					E[a.second][i] = pre_S[s.substr(j)];
					goto L;
				}
			}
			
			L:;
		}
	}
	
	vector<bool> B(pre_S.size(),false);
	for(auto &a:pre_S){
		if(S.count(a.first))B[a.second]=true;
	}
	
	vector<vector<int>> dp(N+1,vector<int>(pre_S.size(),0));
	dp[0][0] = 1;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<pre_S.size();j++){
			for(int k=0;k<10;k++){
				dp[i+1][E[j][k]] = mod(dp[i+1][E[j][k]]+dp[i][j]);
				if(B[E[j][k]])dp[i+1][E[j][k]]=0;
			}
		}
	}
	
	int ho = 0;
	for(int i=0;i<pre_S.size();i++){
		ho = mod(ho + dp[N][i]);
	}
	
	int ans = beki(10,N);
	ans = mod(ans - ho);
	
	cout<<ans<<endl;
	
	
			
			
	
	
	return 0;
}


Measured memory_bytes: 13952
open System

let INF = 1000000000
let N =stdin.ReadLine()|>int
let h =stdin.ReadLine().Split()|>Array.map int
[<EntryPoint>]
let main argv =
    let dp = [|for i in [0..N-1] do yield INF|]
    dp.[0] <- 0
    dp.[1] <- abs (h.[0] - h.[1])
    for i in [2..N-1] do
        dp.[i] <- min (dp.[i-2] + abs (h.[i-2]-h.[i])) (dp.[i-1] + abs (h.[i-1] - h.[i]))
    printfn "%d" dp.[N-1]
    0

Measured memory_bytes: 33492
#include<iostream>                                                     
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
    int a, b; cin >> a >> b;
    a -= b * 2;
    a >=0 ? cout << a : cout << 0;
}


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

#define ndl "\n"
#define f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll M = 1e9+7;
const int N = 2*1e5+5;
const ll INF = 1e18;
const double EPS = 1e-6;

string s;
ll ans = 1,n;
map <char,int> m;

int main () {
	faster;
	cin>>n>>s;
	for (int i = 0; i<s.size(); i++) {
		m[s[i]]++;
	}
	for (int i = 0; i<s.size(); i++) {
		ans*= (m[s[i]]+1);
		ans+=M;
		ans%=M;
		m[s[i]] = 0;
	}
	cout<<ans - 1;

    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Console.WriteLine(nab[0] * nab[1] <= nab[2] ? nab[0] * nab[1] : nab[2]);
        }
    }
}

Measured memory_bytes: 11092
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! printvec {
    ( $item:expr ) => {
        for &i in &$item {
            print!("{} ", i);
        }
        println!("");
    }
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
#[derive(PartialEq, PartialOrd, Clone, Debug)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;


fn main() {
    input!{
        X: usize, Y: usize,
    }
    let x = match X {
        1 => 300000,
        2 => 200000,
        3 => 100000,
        _ => 0,
    };
    let y = match Y {
        1 => 300000,
        2 => 200000,
        3 => 100000,
        _ => 0,
    };
    if X == 1 && Y == 1 {
        println!("{}",x+y+400000);
    } else {
        println!("{}",x+y);
    };
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    map<int, int> cnt1_, cnt2_, cnt3_;
    int c1 = 0, c2 = 0;
    for (int i = 0; i < N; i+=2) {
        cnt1_[A[i]]++;
        cnt3_[A[i]]++;
        c1++;
    }
    for (int i = 1; i < N; i+=2) {
        cnt2_[A[i]]++;
        cnt3_[A[i]]++;
        c2++;
    }
    if (cnt3_.size() == 1) {
        cout << N / 2 << endl;
        return;
    }
    vector<pair<int,int>> cnt1, cnt2;
    for(auto x : cnt1_) {
        cnt1.push_back({x.first, x.second});
    }
    for(auto x : cnt2_) {
        cnt2.push_back({x.first, x.second});
    }
    sort(all(cnt1), [] (pii a, pii b){
        return a.second < b.second;
    });
    sort(all(cnt2), [] (pii a, pii b){
        return a.second < b.second;
    });

    int k1 = (*cnt1.rbegin()).second;
    int k2 = (*cnt2.rbegin()).second;

    if ((*cnt1.rbegin()).first == (*cnt2.rbegin()).first) {
        int kk1 = (*(cnt1.rbegin() + 1)).second;
        int kk2 = (*(cnt2.rbegin() + 1)).second;

        if (kk1 < kk2) {
            cout << N / 2 - k1 + N / 2 - kk2 << endl;
        } else {
            cout << N / 2 - k2 + N / 2 - kk1 << endl;
        }
    } else {
        cout << c1 - k1 + c2 - k2 << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 11256
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: usize = itr.next().unwrap().parse().unwrap();
    let b: usize = itr.next().unwrap().parse().unwrap();
    let x: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    // 各区間を選ぶかbにするか
    let mut area = vec![0; n + 1];
    area[0] = 0;
    for i in 1..n {
        area[i] = x[i] - x[i - 1];
    }

    let mut ans = 0;
    for i in 0..n {
        if area[i] * a > b {
            ans += b;
        } else {
            ans += area[i] * a;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c,ans;
	cin>>a>>b>>c;
	vector<ll> vi;
	vi.pb(a);
	vi.pb(b);
	vi.pb(c);
	sort(vi.begin(),vi.end());
	a=vi[2]*10+vi[1];
	a=a+vi[0];
	cout<<a;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define fcout cout << fixed << setprecision(10)
int main(){
    int x,y;
    cin>>x>>y;
    cout<<(x%y?x:-1);
}


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

bool A(int z) {
    set<int> a{1, 3, 5, 7, 8, 10, 12};
    return a.count(z);
}

bool B(int z) {
    set<int> b{4, 6, 9, 11};
    return b.count(z);
}

bool C(int z) {
    set<int> c{2};
    return c.count(z);
}

int main() {
    int x, y;
    cin >> x >> y;
    bool P = A(x) and A(y), Q = B(x) and B(y), R = C(x) and C(y);
    if (P or Q or R) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3580
#include "bits/stdc++.h"
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int n,m;
    cin >> n >> m;
    COMinit();
    long long ans = 1;
    for(int i = 2; i*i <= m; i++){
        int t = 0;
        while(m%i == 0){
            t++;
            m /= i;
        }
        (ans *= COM(t+n-1, t)) %= MOD;
    }
    if(m != 1) (ans *= n) %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 12160
n=int(input())
d=[]
e=[]
for i in range(n):
    p=[0,0]
    s=input()
    for j in s:
        if j==")":
            if p[0]!=0:
                p[0]-=1
            else:
                p[1]+=1
        else:
            p[0]+=1
    if p[0]-p[1]>=0:
        d.append(p)
    else:
        e.append(p)
d=sorted(d,key=lambda x:x[1])
e=sorted(e,key=lambda x:-x[0])
s=d+e
q=0
for i,j in s:
    if q<j:
        print("No")
        exit()
    else:
        q=q-j+i
if q==0:
    print("Yes")
else:
    print("No")


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

int main(){
	ll n,k;
  cin >> n >>k;
  vector<pair<ll,ll>> p(n);
  ll a[n],b[n];
  for(int i=0;i<n;i++){
    cin >>a[i] >> b[i];
    p[i]=make_pair(a[i],b[i]);
  }
  sort(p.begin(),p.end());
  for(int i=0;i<n;i++){
    if(k<=p[i].second){
      cout <<p[i].first;
      break;
    }
    else{
      k-=p[i].second;
    }
  }
}

Measured memory_bytes: 3328
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   set<int>s;
   int x=(n-1);
   if(x > 1)
   s.insert(x);
   for(int i=2;i*i<=x;i++)
   {
       if(x % i == 0)
       {
           if(i != (x/i))
           {
               s.insert(i);
               s.insert(x/i);
           }
           else
           {
               s.insert(i);
           }
       }
   }
   if(n > 1)
   s.insert(n);
   x=n;
   for(int i=2;i*i<=x;i++)
   {
       if(x % i == 0)
       {   int temp=x;
           while(temp % i == 0)
           {
               temp/=i;
           }
           if(temp%i == 1)s.insert(i);
           temp=x;
           int t=(x/i);
           while(temp % t == 0)
           {
               temp/=t;
           }
           if(temp%t == 1)s.insert(t);
       }
   }
   cout<<s.size()<<endl;

}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  for(int i=0;i<n;i++){
    cin >> A.at(i) ;
  }
  for(int i=0;i<n;i++){
    cin >> B.at(i) ;
  }
  int ans = A.at(0) + accumulate(B.begin(),B.end(),0);
  vector<int> ans_list(n);
  ans_list.at(0) = ans;
  for(int i=1;i<n;i++){
    ans = ans+A.at(i)-B.at(i-1);
    ans_list.at(i) = ans;
  }
  cout << *max_element(ans_list.begin(),ans_list.end()) <<endl;
}
    




Measured memory_bytes: 256