akhauriyash/Code-Regression huggingface dataset:
input_list = list(map(int, input().split()))
n, q = input_list

LEN = 100005
process_list = [None] * LEN
head = 1
tail = n + 1
elaps = 0

class Process:
    def __init__(self, name, time):
        self.name = name
        self.t = time
        
def enqueue(x):
    global process_list, tail
    process_list[tail] = x
    tail = (tail + 1) % LEN
    
def dequeue():
    global process_list, head
    x = process_list[head]
    head = (head + 1) % LEN
    return x
    
def min(a, b):
    a = int(a)
    b = int(b)
    return a if a <= b else b

for i in range(1, n + 1):
    input_list = list(input().split())
    name, time = input_list
    process_list[i] = Process(name, time)

# start simulationing
while head != tail:
    u = dequeue()
    c = min(q, u.t)
    u.t = int(u.t) - c
    elaps += c
    if int(u.t) > 0:
        enqueue(u);
    else:
        print('{} {}'.format(u.name, elaps))


Measured memory_bytes: 17652
s=input()
mod=10**9+7
dp = [[0]*15 for i in range(100005)]
dp[0][0]=1
for i in range(len(s)):
    keta = len(s)-i-1

    if s[i]=='?':
        nums = range(10)
    else:
        nums = [int(s[i])]
    
    tmp = pow(10,keta,13)
    for num in nums:
        amari = num*tmp%13
        for j in range(13):
            dp[i+1][(j+amari)%13]+=dp[i][j]
            dp[i+1][(j+amari)%13]%=mod

print(dp[len(s)][5])

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

int main(){
  int h,w;
  cin>>h>>w;
  string arr[h];
  for(int i=0;i<h;i++){
  	cin>>arr[i];
  }
  for(int j=0;j<h;j++){
  	cout<<arr[j]<<endl;
    cout<<arr[j]<<endl;
  }
}

Measured memory_bytes: 256
//HappyBirthday.java
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
        int b=sc.nextInt();

        if(a>=9||b>=9){
            System.out.println(":(");
        }
        else{
            System.out.println("Yay!");
        }
        sc.close();
    }
}

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

int main(){
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N), Tk(N);
    for(int i=0; i<N; i++){
        cin >> T[i];
        Tk[i] = T[i] + K;
    }
    sort(T.begin(), T.end());
    int ans = 0;
    int cnt = 0;
    int Tst = -1;
    for(int i=0; i<N; i++){
        cnt++;
        if(Tst == -1){
            Tst = T[i];
        }
        if(i==N-1 || cnt==C || (i<N-1 && T[i+1] > Tst + K)){
            ans++;
            cnt = 0;
            Tst = -1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int x,n;
cin >> x >> n;
vi p(102,0);
rep(i,n) {
    int c;
    cin >> c;
    p[c] = 1;
}

int dist = x;
int ans = 0;
for(int i = 0; i <= 101; i++) {
    if(p[i] == 1) continue;
    if(chmin(dist, abs(x-i))) {
        ans = i;
    }
}

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

Measured memory_bytes: 3616
{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

main :: IO()
main = do
  n <- getInt
  ns <- getIntList
  ms <- getIntVec n
  ls <- getIntVec (n-1)
  print $ solve ms ls ns

solve ms ls ns = f ns
  where
    f [n] = ms VU.! (n-1)
    f (p:q:qs)
      | q - p == 1 = ms VU.! (p-1) + ls VU.! (p-1) + f (q:qs)
      | otherwise = ms VU.! (p-1) + f (q:qs)

-- IO
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getIntVec :: Int -> IO (VU.Vector Int)
getIntVec n = VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine


Measured memory_bytes: 508
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0]*(n+1)
    self.el = [0]*(n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)


n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
xy=[(i,x,y)for i,(x,y) in enumerate(xy)]
xy.sort(key=lambda x:x[1])
g=[set() for _ in range(n)]
bit=BIT(n)
work=[-1]*(n+1)
for i,x,y in xy:
  k=bit.sum(y)
  l,r=1,y+1
  c=y+1
  for j in range(k,0,-1):
    l,r=1,c
    while r-l>1:
      c=(r+l)//2
      if bit.sum(c)>=j:
        l,r=l,c
      else:
        l,r=c,r
    c=l if bit.sum(l)==j else r
    idx=work[c]
    g[idx].add(i)
    g[i].add(idx)
    if j>1:bit.add(c,-1)
  if k==0:bit.add(y,1)
  if k==0:work[y]=i

ans=[0]*n
mi=set(range(n))
while mi:
  s=mi.pop()
  grp={s}
  todo=[s]
  cnt=1
  while todo:
    v=todo.pop()
    for nv in g[v]:
      if nv not in grp:
        todo.append(nv)
        grp.add(nv)
        mi.discard(nv)
        cnt+=1
  for id in grp:
    ans[id]=cnt
print(*ans,sep='\n')
#print(g)
#print(bit.sum(1))


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

int main() {
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;

    h = min (q*2, h);
    s = min (h*2, s);

    long long ans;
    if (s*2 <= d) ans = n*s;
    else ans = n/2*d + n%2*s;
    cout << ans << endl;
}

Measured memory_bytes: 3616
# 整数1個だけ
N = int(input().strip())
A = [int(x) for x in input().strip().split(" ")]

buka = {}
for a in A:
    buka.setdefault(a, 0)
    buka[a] += 1

for n in range(1, N+1):
    print(buka.get(n, 0))


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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#ifdef USE_COUT
#define dump(...) (cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#else
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
#else
#define dump(...) (0)
#endif
/// }}}--- ///

#define int ll

const int N = 702;
int n, m;
int g[N][N];
signed main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a][b] = g[b][a] = 1;
  }

  int used[N] = {};
  vector<ll> cs;
  int cols[N] = {};
  ll ac = 0;
  vector<int> ex(n);
  for(int i = 0; i < n; i++) {
    if(used[i]) continue;
    queue<int> q;q.emplace(i);

    int cnt = 0;
    int num = 0;
    while(q.size()){
      int j = q.front();
      q.pop();
      if(used[j]) continue;
      if(cols[j] == 0) cols[j] = 1;
      if(cols[j] == 1) cnt++;
      num++;
      used[j] = 1;
      for(int k = 0; k < n; k++) if(g[j][k] == 0 && j != k && !used[k]) {
        q.push(k);
        if(cols[k] != 0 && cols[k] != 3 - cols[j]) return(cout << -1 << endl, 0);
        cols[k] = 3 - cols[j];
      }
    }
    assert(num >= cnt);
    ac += min(num - cnt, cnt);
    cs.emplace_back(max(num-cnt, cnt)-min(num-cnt,cnt));
  }
  using B = bitset<710>;
  B dp;
  dp[0] = 1;
  for(int i = 0; i < cs.size(); i++) {
    dp |= dp << cs[i];
  }
  ll ans = 1e18;
  for(int i = 0; i <= n; i++) {
    if(ac+i <= n && dp[i]) {ans = min(ans, (ac+i)*(ac+i-1)/2 + (n-ac-i)*(n-ac-i-1)/2);}
  }
  cout << ans << endl;
}



Measured memory_bytes: 4224
#include<cstdio>
#include<vector>

int main()
{
	int n;
	long long input;
	int i;
	bool odd = false;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%lld", &input);

		if (!odd&&input%2)
		{
			odd = true;
		}
	}

	if (odd)
	{
		printf("first\n");
	}

	else
	{
		printf("second\n");
	}

	return 0;
}

Measured memory_bytes: 128
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
a,b = gets.chomp.split.map(&:to_i)

1.upto(100000) do |i|
  if (i * 0.08).to_i == a && (i * 0.1).to_i == b
    puts i
    exit
  end
end

puts -1


Measured memory_bytes: 4220
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;

  vector<ll> a(n);
  vector<ll> b(n);

  for(int i = 0;i < n;i++)cin >> a[i] >> b[i];
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
  ll sum = 0;
  for(int i = 0;i < n;i++){
    a[i] += sum;
    ll now = (b[i] - a[i] % b[i]) % b[i];
    sum += now;
  }

  cout << sum << endl;
}

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

template <typename Value, typename Time, typename Compare = less<Value>>
class slidemin {
private:
    deque<pair<Value, Time>> deq;
    const Compare compare;

public:
    slidemin(Compare cmp = Compare()): compare(cmp) {}

    void push(Value val, Time t) {
        while(!deq.empty() && !compare(deq.back().first, val)) deq.pop_back();
        deq.emplace_back(val, t);
    }

    void pop(Time t) {
        while(!deq.empty() && deq.front().second < t) deq.pop_front();
    }

    pair<Value, Time> getmin() {
        return deq.front();
    }
};

int main() {
    int N, M; string S;
    cin >> N >> M >> S;

    int cnt = 0;
    for(int i=0; i<=N; ++i) {
        if(S[i] == '1') ++cnt;
        else cnt = 0;
        if(cnt == M) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<int> dp(N + 1, 1001001001);
    dp[N] = 0;
    slidemin<int, int> mi;
    mi.push(0, 0);
    for(int i=1; i<=N; ++i) {
        if(S[N - i] != '1') {
            dp[N - i] = mi.getmin().first + 1;
            mi.push(dp[N - i], i);
        }
        mi.pop(i - M + 1);
    }

    int turn = dp[0];
    int pos = 0;
    for(int i=1; i<=N; ++i) {
        if(dp[i] == turn - 1) {
            cout << i - pos << (i==N ? '\n' : ' ');
            pos = i;
            --turn;
        }
    }
}

Measured memory_bytes: 1024
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }.toLongArray()

    val sum = a.reduce { acc, l -> acc xor l }
    if (sum == 0L) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 53872
s = input()
t = input()

"""
dp[i][j] = 長さ
i : sのi文字目まで見た状態
j : tのj文字目まで見た状態

遷移
dp[i+1][j+1] = max(dp[i-1][j-1],dp[i][j])
if s[i] == t[j]:
    dp[i+1][j+1] = max(dp[i-1][j-1]+1,dp[i][j])
dp[i][j+1] = max(dp[i][j+1],dp[i][j])
dp[i+1][j] = max(dp[i+1][j],dp[i][j])
"""

dp = [[0]*3001 for i in range(3001)]
res = ""
for i in range(len(s)):
    for j in range(len(t)):
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1])
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j])
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1)
#復元
i = len(s)
j = len(t)
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        res = s[i-1] + res
        i -= 1
        j -= 1

print(res)


Measured memory_bytes: 114268
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string x;

	cin >> x;
	int n = x.size();

	string t;

	for (int i = 0; i < n; i++) {
		t += x[i];
		while (t.size() > 1) {
			if (t.substr(t.size() - 2) == "ST") {
				t = t.substr(0, t.size() - 2);
			} else {
				break;
			}
		}
	}
	cout << t.size() << endl;
	return 0;
}


Measured memory_bytes: 1056
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
int32_t main(){
    SPEED;
    int h, w;
    cin >> h >> w;
    if(h == 1 || w == 1){
        cout << 1 ;
        return 0;
    }
    if(h & 1 && w & 1) cout << (h * w)/2 + 1;
    else cout << (h * w) / 2;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define in insert
#define mk make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(a) a.begin(), a.end()
#define INF (1<<28)
typedef long long int ll; typedef long int l; typedef pair<int, int> pii;
const double PI = acos(-1);
ll dp[100005];

void initialize(){
    for(int i=0;i<100005;i++)dp[i] = 999999999999;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,k;cin>>n>>k;
    int arr[100005];
    for(int i=0;i<n;i++)cin>>arr[i];

    initialize();
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j < n)dp[i+j] = min(dp[i+j], dp[i]+ abs(arr[i+j]-arr[i]));
        }
    }
    // for(int i=0;i<n;i++){
    //     cout<<dp[i]<<endl;
    // }
    cout<<dp[n-1]<<endl;
return 0;
}

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

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int N, X, T; cin >> N >> X >> T;
	int ans = 0;
	int n = 0;

	for (int n = 0; n < N; n += X) {
		ans += T;
	}

	cout << ans << endl;

	return 0;
}

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

string str;
 
int main() {
    int n, ans = 0;
    cin >> n >> str;
    for (int i = 0; i < 1000; i++) {
        int pat[3] = {i / 100, (i / 10) % 10, i % 10};
        int ii = 0;
        for (int j = 0; j < n; j++) {
            if (str[j] == ('0' + pat[ii])) ii++;
            if (ii == 3) break;
        }
        if (ii == 3) ans++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define S size()
#define E end()
#define B begin()
#define L length()
 
#define endl "\n"
#define cnt count
#define in insert
#define er erase
#define fi first
#define se second
#define fl float
#define ld long double
#define ll long long

#define gcd __gcd
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define all(v) v.B,v.E
#define acc(v) accumulate(all(v), 0)
#define psum partial_sum
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define np next_permutation
#define maxe *max_element
#define mine *min_element
 
#define forl(i,n) for(ll i = 0; i < n; i++)
#define fore(i, m, n) for (ll i = m; i <= n; i++)
#define rforl(i,n) for (ll i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (ll i = n; i >= m; i--)    
#define iter(s) for(auto it:s)
 

#define prec(n) fixed<<setprecision(n)
#define popcnt(n) __builtin_popcountll(n)
#define parity(n) __builtin_parityll(n)
#define clz(n) __builtin_clzll(n)
#define ctz(n) __builtin_ctzll(n)

#define sll set<ll>
#define sc set<char>
#define mll map<ll,ll>
#define vll vector<ll>
#define vc vector<char>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define msll multiset<ll>
#define msc multiset<char>
#define vvll vector<vector<ll>>
#define rev reverse

#define pat ll n;cin>>n;
#define pat1 vll a(n);forl(i,n)cin>>a[i];
#define pat2 ll n,k;cin>>n>>k;vll a;forl(i,n) cin>>a[i];
#define tc ll q;cin>>q;while(q--)
#define pats string s;cin>>s;
#define put forl(i,n)
#define yesno if(flag)cout<<"Yes\n";else cout<<"No\n";

#define p0(a) cout << a << " ";
#define p1(a) cout << a << endl;
#define p2(a,b) cout << a << " " << b << endl;
#define p3(a,b,c) cout << a << " " << b << " " << c << endl;
#define p4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl
 
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define mod1 1000000007
#define mod2 998244353
#define PI 3.1415926535897932384626433832

//**********************************
 
int main(){
    
  ll x,y;
  cin>>x>>y;
  bool flag=false;
  if(y-2*x>=0 && (y-2*x)%2==0 && 4*x-y>=0 && (4*x-y)%2==0){
      flag=true;
  }
  yesno
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef struct _dot{
    int a;
    int b;
}Dot;

int Distance(Dot a,Dot b){
    
    return abs(a.a-b.a) + abs(a.b - b.b);
}
int main(void){
    
   int N,M;
   cin >> N >> M;
   
   Dot student[N];
   Dot CheckPoint[M];
   
   for(int i=0;i<N;i++){
       cin >> student[i].a;
       cin >> student[i].b;
   }
   
   for(int i=0;i<M;i++){
       cin >> CheckPoint[i].a;
       cin >> CheckPoint[i].b;
   }
   
   for(int i=0;i<N;i++){
       int max,index=1;
       for(int j=0;j<M;j++){
           if(j==0){max = Distance(student[i],CheckPoint[j]);}
           else{if(max > Distance(student[i],CheckPoint[j])){ max = Distance(student[i],CheckPoint[j]); index = j+1;}}
       }
       cout << index << endl;
   }
}

Measured memory_bytes: 3620
// ABC140B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>

#include<vector> // 配列を使おう
using namespace std;

int main()
{
	int N; //料理の種類
	cin >> N;
	vector<int> A(N+1);
	for (int i = 1; i <= N; i++)
	{
		cin >> A.at(i); // 食べた順番
	}
	vector<int>B(N+1);
	for (int i = 1; i <= N; i++)
	{
		cin >> B.at(i); // 食べた時の満足度
	}
	vector<int>C(N);
	for (int i = 1; i < N; i++)
	{
		cin >> C.at(i); // 続けて食べた時の追加の満足度
	}

	int ans = 0;
	for (int i = 1; i <= N; i++)
	{
		ans = ans + B.at(A.at(i));
		if (i>1 && A.at(i-1)==A.at(i)-1)
		{
			ans = ans + C.at(A.at(i)-1); // もしも連番で食べたら追加の満足度を追加する
		}
	}
	cout << ans << endl; // 答えを出力する

}


Measured memory_bytes: 256
local mmi, mma = math.min, math.max
local n, t = io.read("*n", "*n")
local prv = 0
local ret = 0
for i = 1, n do
  local a = io.read("*n")
  ret = ret + mmi(t, a - prv)
  prv = a
end
print(ret + t)


Measured memory_bytes: 760
H, W = map(int, input().split())
C = []
for _ in range(10):
    c = [int(s) for s in input().split()]
    C.append(c)
A = []
for _ in range(H):
    a = [int(s) for s in input().split()]
    for ai in a:
        if ai != -1:
            A.append(ai)
for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])
ans = sum([C[ai][1] for ai in A])
print(ans)


Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int n=0;bool b=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')b=1;c=getchar();}
	while(c>='0'&&c<='9')n=(n<<3)+(n<<1)+(c^48),c=getchar();
	return b?-n:n;
}
int n,ans;
string s;
main()
{
	n=read();
	cin>>s;
	for(int i=0;i+2<n;++i)
	{
		if(s[i]=='A')
		if(s[i+1]=='B')
		if(s[i+2]=='C')ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,t;
	cin >> n >> t;
	int sum = 0;
	vector<int> vec(n);
	rep(i,n){
		cin >> vec[i];
	}
	rep(i,n){
		if(i != n-1){
			sum += min(t,vec[i+1] - vec[i]);
		}
		else sum += t;
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
		}
		long ans = 0;
		
		for(int i = 1; i < n; i++) {
			if(a[i-1] > a[i]) {
				ans += a[i-1] - a[i];
				a[i] = a[i-1];
			}
		}
		
		System.out.println(ans);
		

	}

}


Measured memory_bytes: 61568
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
	int n = 0;
	cin >> n;
	cout << ((n % 1000 == 0) ? 0 : (1000 - (n % 1000)));

}



Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    int n;cin>>n;
    vector<int >a(n+1,0);
    for(int i=1;i<=n;i++)cin>>a[i];
    int count=1;
    int start=1;
    int next;
    while(count<n){
        next = a[start];
        if(next==2)break;
        start=next;
        count+=1;
    }
    if(count==n)cout<<-1;
    else cout<<count;
    
}

Measured memory_bytes: 640
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    N = int(input())

    ans = 0
    for i in range(1, N+1):
        j = N // i
        ans +=  i * j * (1+ j) // 2
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 62892
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    vector< pair<int, int> > pairs;
    int A, B;
    for(int i = 0; i < N; i++){
        scanf("%d %d", &A, &B);
        pairs.push_back(make_pair(A, B));
    }

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

    long long int ans = 0;
    int count;
    for(int i = 0; i < N; i++){
        count = min(M, pairs[i].second);
        ans += (long long int)pairs[i].first * count;
        M -= count;
        if(M == 0){
            break;
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(void){
    int n, d, ans = 0;
    scanf("%d %d", &n, &d);
    ans = n / (2 * d + 1);
    if(n % (2 * d + 1) != 0){
        ans++;
    }
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int ans = 0;
  int a;
  int A = 1;
  rep(i, N){
    cin >> a;
    if(a == A){
      A++;
    } else {
      ans++;
    }
  }
  if(ans == N){
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if((H==0)&&(W==0))break;
        for(int i = 1;i<=H;i++){
            for(int j = 1;j<=W;j++){
                if((i>1)&&(j>1)&&(j<W)&&(i<H)){
                    cout << ".";
                }else{
                    cout << "#";
                }
            }
            cout << endl;
        }
        cout<< endl;
    }
    return 0;
}


Measured memory_bytes: 3076
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int[] a = new int[n];
		Map<Integer, Integer> map = new HashMap<>();
        for(int i=0; i<n; i++) {
            a[i] = Integer.parseInt(sc.next());
            if(map.containsKey(a[i])) map.put(a[i], map.get(a[i])+1);
            else map.put(a[i], 1);
        }
        int[] value = new int[map.size()];
        int x=0;
        for(int key : map.keySet()) {
            value[x] = map.get(key);
            x++;
        }
    
        Arrays.sort(value);
        int kijun = map.size()-k;
        int count = 0;
        
        for(int i=0; i<kijun; i++) {
            count += value[i];
            
        }
        
        System.out.println(count);
	}
}

Measured memory_bytes: 65736
/**
*	created: 10.08.2020 01:22:03
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {0, 1, 0, -1, 1, 1,-1, -1};
const int dy2[8] = {1, 0,-1, 0, 1, -1, 1, -1};
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    vector<pair<int,int>> mp;
    rep(i,n) {
        int a; cin >> a;
        mp.push_back(make_pair(a,1));
    }
    rep(i,m) {
        int b, c;
        cin >> b >> c;
        mp.push_back(make_pair(c,b));
    }
    sort(rall(mp));
    int i = 0;
    int sum = 0;
    while(n > 0) {
        int t = min(mp[i].second, n);
        sum += t * mp[i].first;
        n -= t; i++;
    }
    cout << sum << endl;
    return 0;
}

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

typedef long long ll;
ll MOD = 1e9+7;

int main()
{
	ll k,a,b;
	ll ans=0;
	cin>>k>>a>>b;
	k++;
	if(b-a<=2 || a+2>k)
	{
		ans=k;//全部叩く
	}else{
		k-=a;
		ll cnt=k/2;
		ans=cnt*b-(cnt-1)*a+(k%2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>

namespace beet{
  
  template<typename T>
  void swap(T &a,T &b){
    T x=a;
    a=b;
    b=x;
  }
  
  template<typename T>
  struct Vector{
    int sz,cap;
    T *data;
    Vector():sz(0),cap(1){
      data = new T[cap];
    }    
    Vector(int sz):sz(sz),cap(sz<<1){
      data = new T[cap];
    }
    Vector(int sz,T t):sz(sz),cap(sz<<1){
      data = new T[cap];
      for(int i=0;i<sz;i++) data[i]=t;
    }
    ~Vector(){
      delete[] data;
    }
    void resolve(){
      T *tmp = new T[cap];
      for(int i=0;i<sz;i++) tmp[i]=data[i];
      delete[] data;
      data=tmp;
    }
    void resize(int nsz){
      cap=nsz<<1;
      if(sz>cap) sz=cap;
      resolve();      
    }
    void assign(int nsz,T t){
      resize(nsz);
      sz=nsz;
      for(int i=0;i<sz;i++) data[i]=t;
    }    
    void push_back(T x){
      if(sz>=cap){
        cap<<=1;
        assert(sz<cap);
        resolve();
      }      
      data[sz++]=x;
    }
    void pop_back(){
      sz--;
    }
    int size() const{
      return sz;
    }
    const T operator[](int x) const{
      return data[x];
    }
    T& operator[](int x){
      assert(0<=x&&x<sz);
      return data[x];
    }
  };

  template <typename T, typename F>
  struct SegmentTree{
    int n;
    F f;
    T ti;
    Vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,T ti):f(f),ti(ti){}
    void init(int n_){    
      n=1;
      while(n<n_) n<<=1;
      dat.assign(n<<1,ti);
    }
    void build(const Vector<T> &v){
      int n_=v.size();
      init(n_);
      for(int i=0;i<n_;i++) dat[n+i]=v[i];
      for(int i=n-1;i;i--)
        dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void set_val(int k,T x){
      dat[k+=n]=x;
      while(k>>=1)
        dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
    }
    T query(int a,int b){
      T vl=ti,vr=ti;
      for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
        if(l&1) vl=f(vl,dat[l++]);
        if(r&1) vr=f(dat[--r],vr);
      }
      return f(vl,vr);
    }
  };

}
//INSERT ABOVE HERE
using namespace beet;

int main(){
  int n,q;
  scanf("%d %d",&n,&q);
  int ti=(1LL<<31)-1;
  auto f=[](int a,int b){return a<b?a:b;};
  SegmentTree<int, decltype(f)> seg(f,ti);
  seg.build(Vector<int>(n,ti));
  for(int i=0;i<q;i++){
    int c,x,y;
    scanf("%d %d %d",&c,&x,&y);
    if(c==0) seg.set_val(x,y);
    if(c==1) printf("%d\n",seg.query(x,y+1));
  }
  return 0;
}



Measured memory_bytes: 3656
#include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;
int main() {
    double A, B;
    double H, M;
    cin >> A >> B >> H >> M;
    double a;
    a = abs(H * 30 - M * 11 / 2);
    if (a > 180) {
        a = 360 - a;
    }
    double pi;
    pi = acos(-1.0);
    double seta;
    seta = a * pi / 180;
    if (seta == pi) {
        cout << A + B << endl;
    }
    else if (seta == 0) {
        cout << abs(A - B) << endl;
    }
    else {
        double m;
        m = sqrt(A * A + B * B - 2 * A * B * cos(seta));
        cout <<fixed << setprecision(15) << m << endl;
    }
}

Measured memory_bytes: 4236
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        int ans = x + (y / 2);
        
        System.out.println(ans);
        
        sc.close();
        
    }
}


Measured memory_bytes: 22868
#include <iostream>

using namespace std;

long long gcd(long long a, long long b)
{
	return b == 0 ? a : gcd(b, a % b);
}

int main()
{
	long long N, X;
	cin >> N >> X;
	long long d = gcd(N, X);
	N /= d;
	X /= d;
	cout << 3 * (N - 1) * d << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

  for (int i = 0; i < W + 2; i++) {
    printf("#");
  }
  printf("\n");

  for(int i = 0; i < H; i++) {
    printf("#");
    for(int j = 0; j < W; j++) {
      char c;
      cin >> c;
      printf("%c", c);
    }
    printf("#\n");
  }
  for (int i = 0; i < W + 2; i++) {
    printf("#");
  }
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
#define for(in1,in2,in3) for (int in1 = in2; in1 < in3; in1++)
#define inf 1e9
#define mp make_pair
#define pb push_back
#define f first
#define s second
using namespace std;

int mx,x,y,z,t,u,v,ans,n,m,o;
string s1,s2,ans1;

int main() {
	cin >> x >> y;
	ans = (y-x)*2+x;
	cout << ans << "\n";
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

vector<long long> fact, fact_inv, inv;   //fact[i]=i!                       nが10^7より大きいと配列が大きすぎる？
void init_nCk(int SIZE) {                //inv[i]=i^(-1)           
    fact.resize(SIZE + 5);               //fact_inv[i]=inv[i]の累積積
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;                          
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long nPk(int n, int k) {
    return (fact[n] * fact[n-k]) % mod;
}

int main(){
    init_nCk(510000);
    int n,m;
    cin>>n>>m;
    int ans,x;
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    else if(abs(n-m)==1) x=1;
    else x=2;
    cout<<x*nPk(n,n)%mod*nPk(m,m)%mod<<endl;
return 0;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define int long long

int N;
int A[6000];

int dp[4000][6000];

int dfs(int l, int r){
    if(~dp[l][r]) return dp[l][r];

    int res;
    int cnt = r - l - 1;

    if(cnt == N) res = 0;
    else if(cnt & 1){
        if(A[l] > A[r]) res = dfs(l - 1, r);
        else res = dfs(l, r + 1);
    }
    else{
        res = max(dfs(l - 1, r) + A[l], dfs(l, r + 1) + A[r]);
    }

    return dp[l][r] = res;
} 

signed main(){

    cin >> N;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        A[i] = A[N + i] = A[N * 2 + i] = a;
    }

    memset(dp, -1, sizeof(dp));
    int ans = 0;
    for(int i = 0; i < N; i++) chmax(ans, dfs(N + i - 1, N + i + 1) + A[i]);
    cout << ans << endl;

}


Measured memory_bytes: 190704
#include <iostream>
#include <algorithm>
#include <string>
#include <typeinfo>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;


int main(){
	ll a,b,k;
	cin >> a >> b >> k;

	for(ll i=a;i<=b;i++){
		if(i < a+k || b-k < i)cout << i << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,k,i,j,x;
    cin>>n>>k;
    long long int A[n],B[n];
    for(i=0;i<n;i++){
        cin>>A[i];
        B[i]=1;
    }
    for(i=0;i<k;i++){
        //map<long long int,long long int>mt;
        long long int C[n]={0},D[n]={0};
        x=0;
        for(j=0;j<n-1;j++){
            C[j+1]+=1;
            if(j+A[j]+1<n)
            C[j+A[j]+1]-=1;
        }
        for(j=n-1;j>0;j--){
            D[j-1]+=1;
            if(j-A[j]-1>=0)
            D[j-A[j]-1]-=1;
        }
        for(j=1;j<n;j++){
            C[j]+=C[j-1];
        }
        for(j=n-2;j>=0;j--){
            D[j]+=D[j+1];
        }
        for(j=0;j<n;j++){
           // cout<<A[j]<<" "<<B[j]<<" "<<C[j]<<" "<<D[j]<<endl;
            A[j]=B[j]+C[j]+D[j];
            if(A[j]==n)
                x+=1;
        }
        if(x==n)
            break;
    }
    for(i=0;i<n;i++){
        cout<<A[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 9800
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
int n,m;cin>>n>>m;
int ans=0;
ans=n*(n-1)/2+m*(m-1)/2;
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int,int> mp;
int main(){
int n,k;
cin>>n>>k;
vector<int> a(n);
for(int i=0;i<n;i++){
    cin>>a.at(i);
    mp[a.at(i)]++;
}
sort(a.begin(),a.end());
a.erase(unique(a.begin(),a.end()),a.end());
if(k>=a.size())cout<<0<<endl;
else {
    priority_queue<int ,vector<int>,greater<int>> b;
    for(auto p:mp){
        int s=p.second;
         b.push(s);
    }
    int ans=0;
    for(int i=0;i<a.size()-k;i++){
        ans+=b.top();
        b.pop();
    }
    cout<<ans<<endl;
}

}

Measured memory_bytes: 11516
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>

using namespace std;

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

    int s;
    cin >> s;

    int ans = 0;
    for (; s >= 1;) {
        int p = s / 10;
        int r = s - p * 10;
        if (r == 1) {
            ans++;
        }
        s = p;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3596
n, k = map(int, input().split())
x = list(map(int, input().split()))

result = []
for i in range(n - k + 1):
    left = x[i]
    right = x[i + k - 1]
    if left < 0:
        if right < 0:
            result.append(- left)
        else:
            if left + right < 0:
                result.append(- left + 2 * right)
            else:
                result.append(-2 * left + right)
    else:
        result.append(right)
print(min(result))

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};

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

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
    }
  }
  return (ret);
}

int main() {
    ll N;
    cin >> N;
    vector<ll> divs = divisor(N);
    ll a = divs[divs.size() - 1];
    ll b = N / a;
    if (a <= 9 && b <= 9) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
};


Measured memory_bytes: 256
a = 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
K = int(input())-1
print(a[K])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  for(int i = 0; i < n; ++i){
    if(i != k-1) cout << s[i];
    else if(isupper(s[i])) cout << char(s[i]-'A'+'a');
    else cout << s[i];
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(void){
    string n;
    cin>>n;
    bool seven(false);
    for(int i(0);i<3;i++){
        if(n[i] == '7')seven = true;
    }
    if(seven)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3060
"use strict";
 
var main = function main(input) {
  var N = input.split(' ')[0];
  var Y = input.split(' ')[1];
  var flag = false;
 
  for (var i = 0; i <= N; i++) {
    var Yminus1000 = Y - 1000 * i;
 
    for (var j = 0; j <= N - i; j++) {
      var Yminus1000minus5000 = Yminus1000 - 5000 * j;
      var k = Yminus1000minus5000 / 10000;
 
      if (Yminus1000minus5000 % 10000 == 0 && i + j + k == N) {
        console.log("".concat(k, " ").concat(j, " ").concat(i));
        flag = true;
        break;
      }
    }
 
    if (flag) {
      break;
    }
  }
 
  if (!flag) {
    console.log("-1 -1 -1");
  }
};
 
main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 9804
#include <bits/stdc++.h>
using namespace std;
int f_X (int X){
  int sum = 0;
  while (X > 0) {
      sum += X % 10;
      X /= 10;
  }
  return sum;
}


int main() {
  int X;
  cin >> X;
  
  if (X % f_X(X) == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  if(u == NIL) return NIL;
  else if(u->key == k) return u;
  else if(u->key < k) return treeSearch(u->right,k);
  else return treeSearch(u->left,k); 
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
    z->parent = y;

    if(y == NIL) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;

}

void inorder(Node u){
  if(u->left != NIL) inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL) inorder(u->right);
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20496
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
//AtCoderC++.cpp

using namespace std;


inline int ceileing(int a, int b) {return a % b == 0 ? a / b : a / b + 1;}
int main() {
	int A, B; cin >> A >> B;
	cout << (A + B) % 24 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IO cin.tie(0),ios::sync_with_stdio(0);
#define ff first
#define ss second
#define eb emplace_back
#define iter(v) v.begin() ,v.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define print(v) for(auto x: v) cout<<x<<' ';
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vec;
int dp[1001][10002];
int main()
{
    int h,n;
    IO;
    cin>>h>>n;
    vec a(n+1),b(n+1);
    rep1(i,n)cin>>a[i]>>b[i];
    for(int i=0;i<=n;i++)
        for(int j=1;j<=h;j++)
            dp[i][j]=1<<30;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=h;j++)
        {
            if(j<=a[i]) dp[i][j]=min(dp[i-1][j],dp[i][0]+b[i]);
            else    dp[i][j]=min(dp[i-1][j],dp[i][j-a[i]]+b[i]);
        }

    }
    /*for(int i=1;i<=n;i++)
        for(int j=0;j<=h;j++)
            cout<<dp[i][j]<<" \n"[j==h];*/
    cout<<dp[n][h];
    return 0;
}


Measured memory_bytes: 39424
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        x: usize,
        n: usize,
        p: [usize; n],
    }

    let mut hs = std::collections::HashSet::new();
    for e in p {
        hs.insert(e);
    }

    for i in 0..100 {
        let target = x - i;
        if let None = hs.get(&target) {
            echo!(target);
            return;
        }

        let target = x + i;
        if let None = hs.get(&target) {
            echo!(target);
            return;
        }
    }
}


Measured memory_bytes: 2204
N = input()
a = list(map(int, input().split()))
a_sorted = sorted(a, reverse=True)
is_alice = True
a_score = 0
b_score = 0
for num in a_sorted:
    if is_alice == True:
        a_score += num
        is_alice = False
    else:
        b_score += num
        is_alice = True
        
print(a_score - b_score)

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

int main() {
	// your code goes here
	int a,b,x;
	cin>>a>>b;
	if(b>a)
	{
		swap(a,b);
	}
	x=a/b;
	//cout<<a<<b<<endl;
	if(x>=2){
		cout<<":("<<endl;
	}
	else cout<<"Yay!"<<endl;
	return 0;
}

Measured memory_bytes: 256
#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=0;i<h;i++){
            for(j=0;j<w;j++){
                if ((i+j)%2==0) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2048
import sys
import socket
from collections import Counter

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    c = [Counter(a[k::2]) for k in range(2)]
    a, b = [c[k].most_common(1)[0] for k in range(2)]

    if a[0] != b[0]:
        return n - a[1] - b[1]
    if a[1] == n // 2 and b[1] == n // 2:
        return n // 2

    res = n
    if a[1] < n // 2:
        p, q = c[0].most_common(2)
        res = min(res, n - q[1] - b[1])
    if b[1] < n // 2:
        p, q = c[1].most_common(2)
        res = min(res, n - a[1] - q[1])

    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18400
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値
int len;
int N;
ll ans;

const vector<int> G={0,3,5,7};

void dfs(vector<int> &A) {
    if (A.size() == len) {
        int cnt0=0;
        int cnt3=0;
        int cnt5=0;
        int cnt7=0;
        int tmp=0;
        for(int i=0;i<len;i++){
            tmp+=A[i]*pow(10,len-i-1);
            if(A[i]==0){
                if(cnt3>0||cnt5>0||cnt7>0){
                    cnt0++;
                }
            }
            if(A[i]==3) cnt3++;
            if(A[i]==5) cnt5++;
            if(A[i]==7) cnt7++;
        }
        if(cnt0>0||N<tmp) return;
        if(cnt3>0&&cnt5>0&&cnt7>0) ans++;
        return;
    }

    for (auto v:G) {
        A.push_back(v);
        dfs(A);
        A.pop_back();
    }
}


int main(){
    cin>>N;
    ans=0;
    int tmp=N;
    while(tmp>0){
        len++;
        tmp/=10;
    }
    vector<int> A;
    dfs(A);
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 4012
import sys

n, k = map(int, sys.stdin.readline().split())

def main():
    res = set()
    for _ in range(k):
        d = int(sys.stdin.readline().rstrip())
        *a, = map(int, sys.stdin.readline().split())
        res |= set(a)
    print(n - len(res))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9152