akhauriyash/Code-Regression huggingface dataset:
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int a,b;
    cin>>a>>b;
    vector<int> vec(b,0);
    rep(i,a){
        int c;
        cin>>c;
        for(int j=0;j<c;j++){
            int d;
            cin>>d;
            d--;
            vec.at(d)++;
    }
    }

    int count =0;
    rep(i,b){
        if(vec.at(i)==a){
            count++;
        }
    }
    cout<<count<<endl;
}



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

const int N = 5e5+5, M = 27;
int prv[M],nxt[N][M],ans[N][2],dp[N];
int main(){
	string s; cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++) dp[i] = 1e9;
	for (int i = 0; i < 26; i++) prv[i] = n+2;
	dp[n] = 1;
	ans[n][0] = 'a';
	ans[n][1] = n + 2;
	for (int i = s.size() -1 ; i >= 0; i--){
		prv[s[i]-'a'] = i;
		for (int j = 0; j < 26; j++) nxt[i][j] = prv[j];
	}
	for (int i = n -1; i >= 0; i--){
		for (int j = 0; j < 26; j++) {
			if (dp[i] > dp[nxt[i][j] + 1] + 1) {
				dp[i] = dp[nxt[i][j] + 1] + 1;
				ans[i][0] = j;
				ans[i][1] = nxt[i][j] + 1;
			}
		}
	}
	int id = 0;
	while (id < n + 1){
		cout << char('a'+ans[id][0]);
		id = ans[id][1];
	}
	puts("");
	
}

Measured memory_bytes: 28036
S = list(input())
Q = int(input())
reverse=0
head=[]
tail=[]
for i in range(Q):
    q=input().split()
    if int(q[0])==1:
        reverse=(reverse+1)%2
    else :      
        if (reverse+(int(q[1])-1))%2:
            tail.append(q[2])
        else:
            head.append(q[2])

            
head.reverse()
if reverse:
    tmp=head
    head=tail
    tail=tmp
    S.reverse()
    head.reverse()
    tail.reverse()
    
    
print("".join(head+S+tail))
        
    



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

int l[6];

struct dice {

    void in() {
        for(int i = 0; i < 6; i++) cin >> l[i];
    }
    
    void roll(char c) {
        if(c == 'N') {
            char tmp;
            tmp = l[0];
            l[0] = l[1];
            l[1] = l[5];
            l[5] = l[4];
            l[4] = tmp;
        }
        else if(c == 'E') {
            char tmp;
            tmp = l[0];
            l[0] = l[3];
            l[3] = l[5];
            l[5] = l[2];
            l[2] = tmp;
        }
        else if(c == 'W') {
            char tmp;
            tmp = l[0];
            l[0] = l[2];
            l[2] = l[5];
            l[5] = l[3];
            l[3] = tmp;
        }
        else if(c == 'S') {
            char tmp;
            tmp = l[0];
            l[0] = l[4];
            l[4] = l[5];
            l[5] = l[1];
            l[1] = tmp;
        }
    }
};

int main() {
    dice d;
    d.in();

    string s;   cin >>s;

    for(int i = 0; i < s.size(); i++) {
        d.roll(s[i]);
    }

    cout << l[0] << endl;
}


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

int main(){
    string S,T;
    cin >> S;
    cin >> T;
    int ans = 0;
    for(int i = 0; i < 3; ++i){
        if(S[i] == T[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    let mut s=String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v:Vec<i32>=s.trim().split_whitespace()
                    .map(|e|e.parse().unwrap()).collect();
    println!("{} {} {} {}",v[2]-v[3]+v[1],v[3]-v[0]+v[2],v[0]-v[3]+v[1],v[1]-v[0]+v[2] );
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const  int mod = 1000000007;
void add(ll& a, ll b)
{
    a+=b;
    while(a>=mod)
        a-=mod;
    while(a<0)
        a+=mod;
    
}
set<ll> s;

ll dfs(ll n,int lim)
{
	
	if(s.size()==lim)
		return 0;
	int x = n%10;
	s.insert(n*10 + max(0,x-1));
	s.insert(n*10 + x);
	s.insert(n*10 + min(9,x+1));

}

int main()
{
	
	ll n; cin>>n;
	if(n<10)
	{
		cout<<n<<endl;
		return 0;
	}
	for(int i = 1 ;i < 10; i ++)
	{
		s.insert(i);
	}
	while(s.size()<n)
	{
		for(auto& it: s)
		{
			if(s.size()>=n)
				break;
			dfs(it,n);
		}
	}
	vector<ll> lister;
	for(ll k : s)
	{
		if(lister.size()==n)
			break;
		else
		{
		//	cout<<k<<endl;
			lister.push_back(k);
		}
	}
	cout<<lister.back()<<endl;
  	return 0;
}

Measured memory_bytes: 6136
class Segtree():
    def __init__(self, n):
        self.num = 1 << (n - 1).bit_length()
        self.tree = [0] * 2 * self.num
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = max(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = max(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = 0
        l, r = l + self.num, r + self.num
        while l < r:
            if l & 1:
                res = max(res, self.tree[l])
                l += 1
            if r & 1:
                res = max(res, self.tree[r - 1])
            l, r = l >> 1, r >> 1
        return res


n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]

# 解説AC
a_max = max(a) + 1
seg_dp = Segtree(a_max)
for ai in a:
    tmp = seg_dp.query(max(ai - k, 0), min(ai + k + 1, a_max))
    seg_dp.update(ai, tmp + 1)
print(max(seg_dp.tree))


Measured memory_bytes: 139828
import sys, math, collections, heapq, itertools
from bisect import bisect_left
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    Q = int(single_input())
    n, a, b = map(int, line_input())
    left, right = [-a], [a]
    heapq.heapify(left)
    heapq.heapify(right)
    minans =  b
    for i in range(1, Q):
        queri = [int(i) for i in line_input()]
        if queri[0] == 1:
            a, b = queri[1:]
            minans += b
            if -1 * left[0] <= a <= right[0]:
                heapq.heappush(left, -a)
                heapq.heappush(right, a)
            elif a < -1 * left[0]:
                minans += (-1 * left[0]) - a
                heapq.heappush(left, -a)
                heapq.heappush(left, -a)
                heapq.heappush(right, -1 * heapq.heappop(left))
            else:
                minans += a - right[0]
                heapq.heappush(left, -1 * heapq.heappop(right))
                heapq.heappush(right, a)
                heapq.heappush(right, a)
        else: print(-1 * left[0], minans)

    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 19304
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
 ll h,w ;cin>> h>> w ;
 char  d[h][w] ;
 int dist[h][w] ;
 int res=0 ;

 
 vector<P> A ;
 rep(i,h){
   rep(j,w){
      cin>> d[i][j] ;
     if(d[i][j]=='.') {
       A.pb(mpa(i,j)) ;  
        res++ ;
   }
   }
 }
 res-- ;
 int aans = 0 ;

 for(auto main :A){
 queue<P> q ;
 bool seen[h][w] ;
 rep(i,h){
   rep(j,w) {
     seen[i][j]=0 ;
     dist[i][j]=0 ;
     }

 }
 
 q.push(main) ;



while(!q.empty()){
   auto x= q.front() ;
   q.pop() ;
   seen[x.fi][x.se]= 1 ;
   int a= x.fi ; int b=x.se ;
   if(a-1>=0&& seen[a-1][b]==0&&d[a-1][b]=='.'){
   dist[a-1][b]= dist[a][b]+1 ;
   seen[a-1][b]=1 ;
   q.push(mpa(a-1,b)) ;
   res-- ;
   }
   if(res==0) break ;
   if(a+1<=h-1&& seen[a+1][b]==0&&d[a+1][b]=='.'){
   dist[a+1][b]= dist[a][b]+1 ;
   seen[a+1][b]=1 ;
   q.push(mpa(a+1,b)) ;
   res-- ;
   }
   if(res==0) break ;
   if(b-1>=0&& seen[a][b-1]==0&&d[a][b-1]=='.'){
   dist[a][b-1]= dist[a][b]+1 ;
   seen[a][b-1]=1 ;
   q.push(mpa(a,b-1)) ;
   res--;
   }
  if(res==0) break ;
  if(b+1<=w-1 && seen[a][b+1]==0&&d[a][b+1]=='.'){
    dist[a][b+1]=dist[a][b]+1 ;
    seen[a][b+1]=1 ;
    q.push(mpa(a,b+1)) ;
    res-- ;
  }
 if(res==0) break ;
 }
 
 
 int ans= 0;
 rep(i,h){
   rep(j,w) ans= max(ans,dist[i][j]) ;
 }
   aans = max(aans,ans) ;
   }  
   cout<<aans<<endl ;
  return 0;
  }

Measured memory_bytes: 3600
n = int(input())
a = list(map(int, input().split()))

snk = a[0]
ari = sum(a)-snk
ans = abs(snk-ari)
for i in range(n-2):
    snk += a[i+1]
    ari -= a[i+1]
    ans = min(ans, abs(snk-ari))
print(ans)

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

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

	string	str;
	cin >> str;
	bool	n;
	bool	s;
	bool	w;
	bool	e;
	n = false;
	s = false;
	w = false;
	e = false;
	rep(i, str.size())
	{
		if (str.at(i) == 'N') n = true;
		if (str.at(i) == 'S') s = true;
		if (str.at(i) == 'W') w = true;
		if (str.at(i) == 'E') e = true;
	}
	if (n == s && w == e)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

// https://atcoder.jp/contests/abc122/tasks/abc122_c
namespace CGeTAC
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputs[0];
            var q = inputs[1];
            var str = Console.ReadLine().ToCharArray();

            // str 内の AC 累積数一覧を作成
            var acCount = 0;
            var acSummary = new int[n];
            acSummary[0] = 0;
            for (var i = 1; i < n; i++)
            {
                if (str[i - 1] == 'A' && str[i] == 'C') acCount++;
                acSummary[i] = acCount;
            }

            var answers = new int[q];
            for (var i = 0; i < q; i++)
            {
                var range = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var left = range[0] - 1;
                var right = range[1] - 1;
                answers[i] = acSummary[right] - acSummary[left];
            }

            // 解答の出力
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
            Console.Out.Flush();
        }
    }
}


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

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

    cout << (500*k >= x ? "Yes" : "No") << endl;
    return 0;
}

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

int main(){
  int a,b,w;
  int c=0;
  cin>>w>>a>>b;
  if((1,a+w)==(1,b) || (1,b)==(1,a) || (1,a)==(1,b+w) ){
  cout<<"0";
  }
  if((1,b)<(1,a+w) &&(1,b)>(1,a)){
  	
  	cout<<"0";
  }
if((1,a+w)<(1,b)){
  c = b - (a+w);
  cout<<c;
}
  if((1,a)>(1,b+w)){
  c = a - (b+w);
  cout<<c;
}
}

Measured memory_bytes: 256
N = int(input())

lst = []

for i in range(N):
   lst.append(input().split())

X = input()

index = 0

for i in range(N):
   if lst[i][0] == X:
      index = i
      break

ans = 0

for i in range(index + 1, N):
   ans += int(lst[i][1])

print(ans)

Measured memory_bytes: 9092
import sys
from heapq import heappop as hpp, heappush as hp
def dijkstra(N, s, Edge):
    inf = 10**18
    dist = [inf] * N
    Q = [(0, s)]
    decided = set()
    for _ in range(N):
        while True:
            dn, vn = hpp(Q)
            if vn not in decided:
                decided.add(vn)
                dist[vn] = dn
                break
        for vf, df in Edge[vn]:
            if vf not in decided:
                hp(Q, (dn + df, vf))
    return dist


N, M ,K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
J = list(map(int, input().split()))

Edge1 = [[] for _ in range(N)]
L = []
for _ in range(M):
    u, v, t = map(int, sys.stdin.readline().split())
    u -= 1
    v -= 1
    Edge1[u].append((v, t))
    Edge1[v].append((u, t))
    L.append((u, v, t))

dist = dijkstra(N, 0, Edge1)

Edge2 = [[] for _ in range(3*N)]

for u, v, t in L:
    Edge2[u].append((v, t))
    Edge2[v].append((u, t))
    Edge2[N+u].append((N+v, t))
    Edge2[N+v].append((N+u, t))
inf = 10**17
for i in range(N):
    Edge2[i].append((N+i, inf - P[i]))
    Edge2[N+i].append((2*N+i, inf - J[i] + dist[i]))

dist2 = dijkstra(3*N, 0, Edge2)
Ans = [-10**20]*K
for i in range(N):
    Ans[C[i]-1] = max(Ans[C[i]-1], 2*inf - dist2[2*N+i])
for a in Ans:
    print(a)


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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  map<int, int> a;
  int tmp;
  int b = 0;
  REP(i, n) {
    cin >> tmp;
    if(1 <= tmp && tmp < 400) a[0]++;
    else if(400 <= tmp && tmp < 800) a[1]++;
    else if(800 <= tmp && tmp < 1200) a[2]++;
    else if(1200 <= tmp && tmp < 1600) a[3]++;
    else if(1600 <= tmp && tmp < 2000) a[4]++;
    else if(2000 <= tmp && tmp < 2400) a[5]++;
    else if(2400 <= tmp && tmp < 2800) a[6]++;
    else if(2800 <= tmp && tmp < 3200) a[7]++;
    else a[8]++;    
  }
  int ans = a.size();
  if (a[8] > 0 && ans == 1) {
    cout << 1 << " " << a[8] << endl;
  } else {
    if(a[8] > 0) ans--;
    cout << ans << " ";
    ans += a[8];
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
//  [amitdu6ey]
// g++ -std=c++11 -o2 -Wall filename.cpp -o filename
#include <bits/stdc++.h>
#define hell 1000000009
#define bug1(x) cout<<"$ "<<x<<" $"<<endl
#define bug2(x) cout<<"% "<<x<<" %"<<endl
#define bug3(x) cout<<"# "<<x<<" #"<<endl
#define ll long long
#define pb push_back
#define mp make_pair
#define tr(z) for(auto it=z.begin(); it!=z.end(); it++)
#define rloop(i,a,b) for(long long i=a; i>=b;i--)
#define loop(i,a,b) for(long long i=a; i<b; i++)
#define vbool vector< bool >
#define vvbool  vector< vector<bool> >
#define vchar vector<char>
#define vi vector<int>
#define vvi vector< vector<int> >
#define pll pair<long long, long long>
#define vll vector<long long>
#define vvl vector< vector<long long> >
#define ninf numeric_limits<long long>::min()
#define pinf numeric_limits<long long>::max()
#define comp(a,b) (abs(a-b)<1e-9) // to compare doubles
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    loop(i,0,n) cin>>a[i];
    vector<int> dp(n,0);
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    loop(i,2,n){
        dp[i]=min( dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int test_cases=1;
    //cin>>test_cases;
    while(test_cases--){
      solve();
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n - 1];
		
		Arrays.setAll(a, i -> sc.nextInt() - 1);
		Arrays.setAll(b, i -> sc.nextInt());
		Arrays.setAll(c, i -> sc.nextInt());
		
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			sum += b[a[i]];
			if (a[i + 1] == a[i] + 1) sum += c[a[i]];
		}
		sum += b[a[n - 1]];
		
		System.out.println(sum);
		
		sc.close();
	}
	
}




Measured memory_bytes: 32288
#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 std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(T &a){
	cout << a << '\n';
}
ll n,a,b;

int main(){
	g(n); g(a); g(b);
	
	ll x = n/(a+b);
	ll y = n%(a+b);
	x *= a;
	x += min(y,a);
	cout<<x<<endl;
}

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

using namespace std;

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

    sort(b.begin(), b.end());
    for (int i = 0; i < min(N, 5); i++) {
        a.push_back(b[i]);
    }
   
    vector<int> v;
    for (int i = 0; i < (int)a.size(); i++) {
        for (int j = 0; j < (int)a.size(); j++) {
            if (i == j) continue;
            string s = to_string(a[i]) + to_string(a[j]);
            v.push_back(stoi(s));
        }
    }
    sort(v.begin(), v.end());
    cout << v[2] << endl;
    return 0;
}

Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
int main() {
  int h[10];
  for (int i = 0; i < 10; i++) {
    cin >> h[i];
  }
  sort(h, h+10);
  for (int i = 9; i >= 7; i--) {
    cout << h[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define show(...) 42
#endif


#define f first
#define s second
#define endl "\n"
#define pb push_back
#define  oo 0x3f3f3f3f
#define limit 1000000007
#define two pair<int,int>
#define int long long int
#define mod(x,m) ((x%m+m)%m)
#define all(v) v.begin(),v.end()
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define fori(x,n) for(int i = x; i < n; i++)
#define forj(y,m) for(int j = y; j < m; j++)
#define fork(z,p) for(int k = z; k < p; k++)
#define fastio std::ios::sync_with_stdio(false)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define input_from_file  freopen("input.txt", "r", stdin);

int power(int a, int b){
	if(b==0) return 1;
	if(b==1) return a;
	if(b%2 == 1) return (power(a,b-1)*a)%limit;
	int q = power(a,b/2); return (q*q)%limit;
}

int findinv(int n){
  return power(n,limit-2);
}

int fact(int n){
  int ans = 1;
  fori(1,n+1) ans *= i, ans %= limit;
  return ans;
}

signed main(){
  //input_from_file;
  int a,b; cin>>a>>b;
  int x1 = 2*b-a;
  int y1 = 4*a-2*b;
  if(x1%3 != 0 || x1 < 0) cout<<0<<endl, exit(0);
  if(y1%6 != 0 || y1 < 0) cout<<0<<endl, exit(0);
  x1 /= 3;
  y1 /= 6;
  int ans = (fact(x1+y1)*findinv(fact(x1)))%limit;
  ans = (ans*findinv(fact(y1)))%limit;
  cout<<ans<<endl;
}


Measured memory_bytes: 888
N,X = list(map(int, input().split()))
L = list(map(int, input().split()))
D = [0]*(N+2)
for i in range(N):
    D[i+1] = D[i] + L[i]
#print (D)
count = 0
for i in range(len(D)):
    if D[i] <= X:
        count += 1
print (count-1)

Measured memory_bytes: 3064
#include <iostream> 
#include <string> 
using namespace std; 
int ans; string s; 
int main(){ 
  cin >> s; 
  if(s[0]=='1') ans++; 
  if(s[1]=='1') ans++; 
  if(s[2]=='1') ans++; 
  cout << ans << endl; 
}


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

int main() {
    int n, b, f, r, v;
    int resident[4][3][10] = {};
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> b >> f >> r >> v;
        resident[b - 1][f - 1][r - 1] += v;
    }
    
    for (b = 0; b < 4; b++)
    {
        for (f = 0; f < 3; f++)
        {
            for (r = 0; r < 10; r++)
            {
                cout << " " << resident[b][f][r];
            }
            cout << "\n";
        }
        if (b != 3) {
            cout << "####################\n";
        }
    }

    return 0;
}


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

int main() {
        int a, b, c;
        cin >> a >> b >> c;

        bool flag = false;
        for (int i=1; i<=b; ++i) {
                int res = (a*i-c) / b;
                if (a*i-c == res*b) {
                        flag = true;
                        break;
                }
        }

        if (flag) cout << "YES" << endl;
        else cout << "NO" << endl;

        return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
target = a[0]
cnt = 1
hen = []


for i in range(1,n):
    if target == a[i]:
        cnt += 1
        if cnt == 2:
            hen.append(a[i])
            cnt = 0
    else:
        target = a[i]
        cnt = 1
    
    if len(hen) == 2:
        print(hen[0]*hen[1])
        exit()

print(0)


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

using namespace std;

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

    long long sum = 0;
    for (long long i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) sum += i;
    }

    cout << sum << endl;

    return 0;
}


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

int main(){
  int N,L,koko,ans=0;
  cin>>N>>L;
  vector<int> a(N);
  int m = 1e5;
  
  for(int i=0;i<N;i++){
    a.at(i) = L+i;
    if(m>abs(a.at(i))){
      m = abs(a.at(i));
      koko = i;
    }
  }
  for(int i=0;i<N;i++){
    if(i!=koko)
      ans +=a.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
	int i,n,j,p,r,hz,x;
	Scanner scat=new Scanner(System.in);
	n=scat.nextInt();
	int A[]=new int[n];
	for(i=0;i<n;i++){
	    A[i]=scat.nextInt();
	}
	p=0;
	r=n-1;
	x=A[r];
	i=p-1;
	for(j=p;j<r;j++){
	    if(A[j]<=x){
		i++;
		hz=A[i];
		A[i]=A[j];
		A[j]=hz;
	    }
	}
	hz=A[i+1];
	A[i+1]=A[r];
	A[r]=hz;
	for(j=0;j<n;j++){
	    if(j!=0) System.out.print(" ");
	    if(j!=i+1){
		System.out.print(A[j]);
	    }else{
		System.out.print("["+A[j]+"]");
	    }
	}
	System.out.println("");
    }
}



Measured memory_bytes: 68836
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
 
using namespace std;
 
typedef long long LL;
 
struct edge{LL from,to,cost;};
 
template <typename T>
class UF{
public:
    vector<T> par,rank;
 
    UF(T n){
        par.resize(n);
        rank.resize(n);
        for(T i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
 
    T find(T x){
        if(par[x]==x)
            return x;
        else
            return par[x]=find(par[x]);
    }
 
    void unite(T x, T y){
        x=find(x);
        y=find(y);
        if(x==y) return;
 
        if(rank[x]<rank[y])
            par[x]=y;
        else{
            par[y]=x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
 
    bool same(T x, T y){
        return find(x)==find(y);
    }
 
};
int main(){
	int n,q;
	cin>>n>>q;
	
	UF<int> uf(n);
	
	for(int i=0;i<q;i++){
		int c,x,y;
		cin>>c>>x>>y;
		
		if(c) cout<<uf.same(x,y)<<endl;
		else uf.unite(x,y);
	}
	
}

Measured memory_bytes: 3192
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	string b[10] = { "0111111","0000110","1011011","1001111",
	"1100110","1101101","1111101","0100111","1111111","1101111" };
	while (cin >> n&&n != -1) {
		string c = "0000000";
		for (int z = 0; z < n; z++) {
			int a;
			cin >> a;
			string d = "";
			for (int i = 0; i < 7; i++) {
				if (b[a][i] != c[i])
					d += "1";
				else
					d += "0";
			}																																									
			c = b[a];
			cout << d << endl;
		}
	}
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define N 2005
#define int long long
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<'!');
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>'!')x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,x,ans=1ll<<60,a[N],b[N];
main()
{
	re(n),re(x);
	for(int i=1;i<=n;++i)re(a[i]),b[i]=a[i];
	for(int i=0;i<n;++i)
	{
		int now=i*x;
		for(int j=1;j<=n;++j)
			b[j]=min(b[j],a[j>i?j-i:j-i+n]);
		for(int j=1;j<=n;++j)
			now+=b[j];
		ans=min(ans,now);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 998244353 
#define pb push_back
//#define mp make_pair
#define INF 2000000011LL
#define INFLL 1000000000000000011LL
#define eps 1e-9
#define pp pair < pair<ll,ll> , ll> 
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define foll(i,j,k) for(ll i=j;i<=k;i++)
#define clr(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vll vector<ll>
#define sz(a) a.size()
#define len(a) a.length()
#define all(a) a.begin(),a.end()
#define io_file freopen("input_file.in", "r", stdin); freopen("output_file.in", "w", stdout)

const int MAXN = 2e5+5;
using namespace std;
ll power(ll x, ll y)
{
  ll res = 1;
  while(y>0)
  {
    if(y&1)
       {
         res = (res*x)%mod;
        }
     x = (x*x)%mod;
     y = y>>1;
  }
    return res;
}
// std::vector<ll> divi[100004];
// void divisor(int n)
// {
//    for(ll i=1;i<=n;i++)
//    {
//      for(ll j=i;j<=n;j+=i)
//      {
//        divi[j].pb(i);
//      }
//    }
// }

ll a[100004];
ll k;

// bool check(ll val)
// {
// 	for(int i=1;i<=k;i++)
// 	{

// 	}
// }


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // io_file;
    cin>>k;
    for(int i=1;i<=k;i++)
    {
    	cin>>a[i];
    }
    
    pair<ll,ll>range;
    range = {2LL,2LL};

    for(int i=k;i>=1;i--)
    {
    	ll x = (range.first + a[i] - 1LL)/a[i];
    	ll y = (range.second)/a[i];
    	if(x>y)
    	{
    		cout<<-1<<endl;
    		return 0;
    	}
    	range = {x*a[i],y*a[i] + a[i]-1LL};
    }

    cout<<range.first<<" "<<range.second<<endl;
    return 0;
    

}
	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
  	int max = 1;
  	int min = 1000000000;
  	cin >> n;
  	vector<int> a(n);
  for(int i = 0; i < n; i++){
      cin >> a.at(i);
  }
  for(int i = 0;i < n; i++){
    if(max < a.at(i)) max = a.at(i);
    if(min > a.at(i)) min = a.at(i);
  }
  cout << max - min <<endl;
}

Measured memory_bytes: 3600
def main():
    n, a, b = map(int, input().split())
    s = input()
    
    p, pa = 0, 0
    for i in s:
        if i == "a" and p < a + b:
            print("Yes")
            p += 1
        elif i == "b" and p < a + b and pa < b:
            print("Yes")
            p += 1
            pa += 1
        else:
            print("No")
            
            
if __name__ == "__main__":
    main()

Measured memory_bytes: 4040
/*
Author : Hocky Yudhiono
Min 26 Jan 2020 06:59:57  WIB

1. You can sort the query if offline!
2. Don't bring the dp remaining state when dfsing on DP on Tree.
3. Try to reverse (Think from the back) if you stuck.
4. Be careful when submitting Div. 2 D-F, dont waste it on stupid WAs.
5. Try to reduce a problem
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
//If the time limit is strict, try not to use long double

#define popf pop_front
#define pf push_front
#define popb pop_back
#define mp make_pair
#define pb push_back
#define remove erase
#define fi first
#define se second

//Remember to undefine if the problem is interactive
#define endl '\n'
#define DEBUG(X) cout << ">>> DEBUG(" << __LINE__ << ") " << #X << " = " << (X) << endl

const double eps = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const LL LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const LL MOD = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1};
const int dy[8] = {0,1,0,-1,1,-1,1,-1};
const double PI = 3.141592653589793;

inline void open(string a){
    freopen((a+".in").c_str(),"r",stdin);
    freopen((a+".out").c_str(),"w",stdout);
}

inline void fasterios(){
    //Do not use if interactive
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

LL n,m; 

int main(){
    cin >> n >> m;
    cout << (LL)(ceil((LD)(n)/(LD)(m))) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A, B = list(map(int, input().split()))
P = list(map(int, input().split()))

P.sort()

ans = 0

fir, sec = [], []

for i in range(len(P) - 1):
    if P[i] > A:
        fir = P[:i]
        P = P[i:]
        break


for i in range(len(P)):
    if P[i] > B:
        sec = P[:i]
        P = P[i:]
        break



print(min(len(fir), len(sec), len(P)))



Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



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

	
	cin >> a >> b;
	int i = b - a - 1;

	cout << i * (i + 1) / 2 - a << endl;
	
	

		
	

	
	
}
	

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

int main()
{
  
  LL n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  a=min(a,b);
  a=min(a,c);
  a=min(a,d);
  a=min(a,e);
  cout<<(n+a-1)/a+4<<'\n';
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int digitsum(int x){
    int s = 0;
    while(x > 0){
        s += x % 10;
        x /= 10;
    }
    return s;
}

signed main(){

    int N;
    cin >> N;
    int ans = 10000000000;

    FOR(i, 1, N){
        ans = min(ans, digitsum(i) + digitsum(N - i));
    }
    
    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;
 
int main()
{
    int n, l;

    cin >> n >> l;

    int aji[n];
    int i, osum = 0;
    for(i=0; i<n; i++) {
        aji[i] = l + i;
        osum += aji[i];
    }

    int j, sum = 0, min = 1000000000, dif, res;
    for(i=0; i<n; i++) {
        sum = 0;
        for(j=0; j<n; j++) {
            if(j != i)
              sum += aji[j];
        }
        dif = abs(osum - sum);
        if(dif < min) {
            min = dif;
            res = sum;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[100010], invf[100010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
ll p2[100010];
int main()
{
	int n; cin>>n;
  p2[0]=1;
  for(int i=1; i<=n; i++) p2[i]=p2[i-1]*2%MOD;
  //vector<int> g[100010];
  int deg[100010]={};
  int a[100010];
  for(int i=0; i<n; i++){
    cin>>a[i];
    a[i]--;
    //g[i].push_back(a);
    deg[a[i]]++;
  }
  for(int i=0; i<n; i++){
    if(deg[i]>=3){
      cout<<0<<endl;
      return 0;
    }
  }
  int myon[100010]={};
  int nuo[100010]={};
  bool used[100010]={};
  for(int i=0; i<n; i++){
    if(deg[i]==0){
      int x=i, cnt=0;
      while(deg[x]<2){
        used[x]=1;
        cnt++;
        x=a[x];
      }
      myon[x]=cnt;
    }
  }
  for(int i=0; i<n; i++){
    if(deg[i]==2){
      int x=i, cnt=0;
      do{
        used[x]=1;
        cnt++;
        x=a[x];
      }while(deg[x]<2);
      nuo[x]=cnt;
    }
  }
  map<int, int> mp;
  for(int i=0; i<n; i++){
    if(!used[i]){
      int x=i, cnt=0;
      while(!used[x]){
        used[x]=1;
        cnt++;
        x=a[x];
      }
      mp[cnt]++;
    }
  }
  ll ans=1;
  for(int i=0; i<n; i++){
    if(myon[i]){
      //cout<<nuo[i]<<" "<<myon[i]<<endl;
      if(nuo[i]<myon[i]){
        cout<<0<<endl;
        return 0;
      }
      if(nuo[i]>=myon[i]+1) (ans*=2)%=MOD;
    }
  }
  //cout<<"myon"<<endl;
  fac(n);
  for(auto p:mp){
    int d=p.first, m=p.second;
    //cout<<d<<" "<<m<<endl;
    ll pp=1, q=1, s=0;
    for(int i=0; i<=m/2; i++){
      if((d&1) && d>1) (s+=pp*q%MOD*comb(m, 2*i)%MOD*p2[m-2*i])%=MOD;
      else (s+=pp*q%MOD*comb(m, 2*i))%=MOD;
      (pp*=d)%=MOD;
      (q*=(2*i+1))%=MOD;
    }
    (ans*=s)%=MOD;
  }
  cout<<ans<<endl;
 	return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;

    int l[N];
    for (int i = 0; i < N; i++)
    {
        cin >> l[i];
    }
    sort(l, l + N);
    reverse(l, l + N);

    int ans = 0;
    for (int i = 0; i < K; i++)
    {
        ans += l[i];
    }
    cout << ans << endl;
}


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

int main(){
    int S;
    cin >> S;
   
    int h = S / 3600;
    int m = (S - (h * 3600)) / 60;
    int s = S - (h * 3600) - (m * 60);
    
    cout << h << ":";
    cout << m << ":";
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n,m;
    cin>>n;
    ll a[200005],b[200005];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=0;i<n;i++)
    {
      
      cin>>a[i];
     
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
      
      cin>>b[i];
      
      
    }
    sort(a,a+n);sort(b,b+m);
    if(m>n)
    {
      NO
    }
    else
    {
      ll j=0,c=0;
      for(int i=0;i<n;i++)
      {
        if(j<m&&a[i]==b[j])
        {
                c++;
                j++;
        }

      }
      if(c==m)
      {
        YES
      }
      else
      {
        NO
      }
    }

}
return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<map>
int main()
{
	int n;
	char s[8];
	while(scanf("%d",&n),n)
	{
		std::map<char,char>m;
		fgets(s,8,stdin);
		while(n--) fgets(s,8,stdin),m[s[0]]=s[2];
		scanf("%d",&n);
		while(n--) scanf("%s",s),putchar(m.find(s[0])==m.end()?s[0]:m[s[0]]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include <iostream>
using namespace std;
long long C;
int A[200001];
int main() {
    int N,K; cin >> N >> K;
	for(int i=0; ++i<=N;) cin >> A[i];
	sort(A+1, A+N+1);
	for(int i=1; i<=N-K; ++i) C += A[i];
    cout << C << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int S, T;
string s, t;
int memo[3001][3001];
pair<int, int> nextNode[3001][3001];

int LCS(int i, int j){
    int temp = memo[i][j];
    if(temp != -1){
        return temp;
    }

    if(i == 0 || j == 0){
        memo[i][j] = 0;
        return 0;
    }

    if(s[i - 1] == t[j - 1]){
        memo[i][j] = LCS(i - 1, j - 1) + 1;
        nextNode[i][j] = make_pair(i - 1, j - 1);
        return memo[i][j];
    }

    int temp1 = LCS(i - 1, j);
    int temp2 = LCS(i, j - 1);
    if(temp1 > temp2){
        memo[i][j] = temp1;
        nextNode[i][j] = make_pair(i - 1, j);
        return temp1;
    }
    else{
        memo[i][j] = temp2;
        nextNode[i][j] = make_pair(i, j - 1);
        return temp2;
    }
}

int main(){

    cin >> s;
    cin >> t;

    S = (int)s.size();
    T = (int)t.size();

    memset(memo, -1, sizeof(memo));

    LCS(S, T);

    int i = S;
    int j = T;

    string ans = "";
    while(i != 0 && j != 0){
        if(s[i - 1] == t[j - 1]){
            ans = s[i - 1] + ans;
        }
        auto n = nextNode[i][j];
        i = n.first;
        j = n.second;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 106240
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    ll n, ans = 0;
    scanf("%lld", &n);
    vector<ll> a(3 * n);
    for (ll i = 0; i < 3 * n; ++i) scanf("%lld", a.begin() + i);
    sort(a.begin(), a.end(), greater<ll>());
    for (ll i = 0; i < n; ++i) ans += a.at(i * 2 + 1);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstdlib>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e6 + 10;
const int EPS = 1e-9;
const ll MOD = 1e9 + 7;

void solve() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (a > b) swap(a, b);
	ll ans = 0;
	if (abs(a - b) % 2) {
		ll d1 = max(a, b) - 1;
		ll d2 = n - min(a, b);
		if (d1 < d2) {
			d1 = min(a, b) - 1;
			ans += d1;
			a -= d1, b -= d1;
			b--, ans++;
		}
		else {
			d2 = n - max(a, b);
			ans += d2;
			a += d2, b += d2;
			a++, ans++;
		}
	}
	cout << (abs(a - b) + 1) / 2 + ans;
}

int main() {
//	auto trash = freopen("a.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}

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

int main() {
  ll N;
  cin >> N;
  ll power = 1;
  ll w = pow(10, 9) + 7;
  for (ll i = 2; i <= N; ++i) {
    power *= i;
    power %= w;
  }
  ll result = power % w;
  cout << result << endl;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    vector<vector<int> > c(3, vector<int>(3));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }

    bool flag = false;
    for(int i = 0; i <= 100; i++){
        int b1 = c[0][0] - i;
        int b2 = c[0][1] - i;
        int b3 = c[0][2] - i;
        if(b1 < 0 || b2 < 0 || b3 < 0) continue;
        int a2b1 = c[1][0] - b1;
        int a2b2 = c[1][1] - b2;
        int a2b3 = c[1][2] - b3;
        if(a2b1 < 0 || a2b2 < 0 || a2b3 < 0) continue;
        if(a2b1 != a2b2 || a2b2 != a2b3 || a2b1 != a2b3) continue;
        int a3b1 = c[2][0] - b1;
        int a3b2 = c[2][1] - b2;
        int a3b3 = c[2][2] - b3;
        if(a3b1 < 0 || a3b2 < 0 || a3b3 < 0) continue;
        if(a3b1 != a3b2 || a3b2 != a3b3 || a3b1 != a3b3) continue;
        flag = true;
        break;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    if(a >= k){
        a -= k;
    }
    else{
        b = max(0LL, b-(k-a));
        a = 0;
    }

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,c,d,z=0;
    cin>>n>>k;
    int a[k];
    for(int i=0;i<k;++i)
        cin>>a[i];
    sort(a,a+k);
    for(int i=0; ; ++i)
    {
        c=n;
        while(c!=0)
        {
            d=c%10;
            c=c/10;
            if(binary_search(a,a+k,d))
            {
                z=1;
                break;
            }
        }
        if(z==0)
        {
            cout<<n<<endl;
            return 0;
        }
        z=0;
        ++n;
    }
}


Measured memory_bytes: 3608
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int m, d;
    cin >> m >> d;
    LL ans = 0;
    for (int i = 1; i <= m; i++) {

            for (int j = 1; j <= d; j++) {
                int d1 = j % 10;
                int d2 = j / 10;
                if (d1 >= 2 and d2 >= 2 and d1 * d2 == i) ans++;
            }

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


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

int main() {
   int a , b;
   cin >> a >> b;
   if ( (a + b) % 2 == 0 ) {
      cout << (a + b) / 2 << endl;
   }
   else {
      cout << (a + b) / 2 + 1 << endl;
   }
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
string S;
int main() {
	cin>>S;

	S[3]='8';
	cout<<S<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
t,x,y = 0,0,0
cou = 0
t1,t2,x1,x2,y1,y2= 0,0,0,0,0,0

for i in range(N):
    t,x,y = map (int,input().split())
    if t>=(x+y) and (t+x+y)%2 == 0:
        t1,x1,y1 = t,x,y
        if abs(t1-t2) >= abs((x1-x2)+(y1-y2)):
            cou += 1
        else:
            print("No")
            break
        t2,x2,y2 = t1,x1,y1
    else:
        print("No")
        break

if cou == N:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1000000000;
const int MOD = 1000000007;

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 main() {
  int s, w;
  cin >> s >> w;
  if(s > w){
    cout << "safe" << endl;
  }
  else{
    cout << "unsafe" << endl;
  }
  return 0;
}


Measured memory_bytes: 3680