akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Convert;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }


        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadInt;
            var b = cin.ReadInt;

            if (a <= 9 && b <= 9)
            {
                WriteLine(a * b);
            }
            else
            {
                WriteLine(-1);
            }
        }


        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13268
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[M + 1];
		
		for (int i = 1; i <= M; i++) {
			A[i] = sc.nextInt();
		}
		
		int nCost = 0;
		for (int i = X + 1; i < N; i++) {
			for (int j = 1;j <= M; j++) {
				if (i == A[j]) {
					nCost++;
					break;
				}
			}
		}
		
		int zeroCost = 0;
		for (int i = X - 1; i > 0; i--) {
			for (int j = 1;j <= M; j++) {
				if (i == A[j]) {
					zeroCost++;
					break;
				}
			}
		}
		
		System.out.println(Math.min(nCost, zeroCost));
	}
}


Measured memory_bytes: 21844
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}


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


	int N = getint();

	ll kotae = (ll(N) * (N + 1) * (2 * N + 1) / 6 + ll(N) * (N + 1) / 2) / 2;

	rep(i, N - 1) {
		int u = getint(), v = getint();
		if (u > v) swap(u, v);

		kotae -= ll(u) * (N - v + 1);
	}

	printf("%lld\n", kotae);



	Would you please return 0;
}

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

int main() {
    ll N, A, B;
    cin >> N >> A >> B;

    if(N%(A+B)==0)
        cout << N / (A + B) * A;
    else
        cout << N / (A + B)*A+(min(N%(A+B),A));

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# Input#
n = int(input())
# n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
max = 0
for i in range(n):
    if i == 0:
        max = a[i]
        continue

    if a[i] < max:
        ans += max - a[i]
    else:
        max = a[i]


print("{}".format(ans))


Measured memory_bytes: 94232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int input[] = new int[n];

		for(int i = 0; i < n; i++){
			input[i] = sc.nextInt();
		}

		long total = Long.MAX_VALUE;
		for(int i = 1; i <= 100; i++){
			long tmpTotal = 0;
			for(int j = 0; j < n; j++){
				tmpTotal += (input[j] - i)*(input[j] - i);
			}

			total = Math.min(total, tmpTotal);
		}

		System.out.println(total);
	}

}


Measured memory_bytes: 23124
#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=1001001001;
int n,x1,x2;
vector<int>to[100010];

vector<int>bfs(int x){
    queue<int>q;
    vector<int>dist(n,INF);
    q.push(x);
    dist[x]=0;
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(int u:to[v]){
            if(dist[u]!=INF)continue;
            dist[u]=dist[v]+1;
            q.push(u);
        }
    }
    return dist;
}

int main(){
    cin>>n>>x1>>x2;
    x1--; x2--;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int>s=bfs(x1);
    vector<int>t=bfs(x2);
    int ans=0;
    rep(i,n){
        if(s[i]<t[i])ans=max(ans,t[i]-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9588
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
closed = [0, 0, 0, 0]
sys.setrecursionlimit(10 ** 8)

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    info = [[closed for _ in range(w + 2)]]  # 上左下右
    for _ in range(h):
        info.append([closed] + [[1] * 4 for _ in range(w)] + [closed])
    info.append([closed for _ in range(w + 2)])
    for i in range(1, w + 1):  # 0＝壁, 1=なにもない
        info[0][i][0] = 0
        info[-1][i][2] = 0
    for i in range(1, h + 1):
        info[i][0][1] = 0
        info[i][-1][3] = 0
    for i in range(1, h + 1):
        vertical_wall = list(map(int, input().split()))
        for j in range(1, w):
            if vertical_wall[j-1] == 1:
                info[i][j][3] = 0
                info[i][j + 1][1] = 0
        if i < h:
            horizontally_wall = list(map(int, input().split()))
            for j in range(1, w + 1):
                if horizontally_wall[j-1] == 1:
                    info[i][j][2] = 0
                    info[i + 1][j][0] = 0
    stack = deque([[1, 1, 1]])
    info[1][1] = closed
    while len(stack) > 0:
        y, x, dis = stack.popleft()
        if y == h and x == w:
            print(dis)
            break
        if info[y][x + 1][1] == 1:
            info[y][x + 1] = closed
            stack.append([y, x + 1, dis + 1])
        if info[y][x - 1][3] == 1:
            info[y][x - 1] = closed
            stack.append([y, x - 1, dis + 1])
        if info[y + 1][x][0] == 1:
            info[y + 1][x] = closed
            stack.append([y + 1, x, dis + 1])
        if info[y - 1][x][2] == 1:
            info[y - 1][x] = closed
            stack.append([y - 1, x, dis + 1])
        if len(stack) == 0:
            print(0)
            break



Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
 
using ull = unsigned long long;
using ll = long long;
using ld = long double;
int main(){
  int N,X,T;
  cin>>N>>X>>T;
  int a;
  if(N%X==0) a=N/X;
  else a=N/X+1;
  cout<<a*T<<endl;
  return 0;
}

Measured memory_bytes: 3596
n=int(input())
*a,=map(int,input().split())
a=sorted(a)
from math import gcd

for i in range(n):
    if i==0:
        tmp=a[i]
    else:
        tmp=gcd(tmp, a[i])

b=[x//tmp for x in a]

for i in range(n):
    if i==0:
        tmp=b[i]
    else:
        tmp=gcd(tmp, b[i])
        if tmp==1:
            l=i-1
            r=i
            break
if l>0:
    c=a[:l]+a[l+1:]
else:
    c=a[1:]
if r+1<n:
    d=a[:r]+a[r+1:]
else:
    d=a[:r]

for i in range(len(c)):
    if i==0:
        ctmp=c[i]
        dtmp=d[i]
    else:
        ctmp=gcd(ctmp, c[i])
        dtmp=gcd(dtmp, d[i])

ans=max(ctmp,dtmp)

for i in range(n-1,-1,-1):
    if i==n-1:
        tmp=b[i]
    else:
        tmp=gcd(tmp, b[i])
        if tmp==1:
            l=i
            r=i+1
            break
if l>0:
    c=a[:l]+a[l+1:]
else:
    c=a[1:]
if r+1<n:
    d=a[:r]+a[r+1:]
else:
    d=a[:r]

for i in range(len(c)):
    if i==0:
        ctmp=c[i]
        dtmp=d[i]
    else:
        ctmp=gcd(ctmp, c[i])
        dtmp=gcd(dtmp, d[i])

print(max(ans,ctmp,dtmp))

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

void Main()
{
    string s;
    cin >> s;
    vector<int> sm(s.size()+1); // sの下i桁の数 % 2019
    vector<int> cm(2019); // i = sの下i桁の数 % 2019 となる数
    sm[0] = 0;
    cm[0] = 1;
    int e = 1;
    for (int i = 1; i <= s.size(); i++)
    {
        sm[i] = (((s[s.size()-i] - '0') * e) % 2019 + sm[i-1]) % 2019;
        cm[sm[i]]++;
        e = (e * 10) % 2019;
    }
    int sum = 0;
    for (int i = 0; i < 2019; i++)
    {
        // if(cm[i] > 0)
        //     cout << i << " " << cm[i] << endl;
        if(cm[i] >= 2)
            sum += cm[i] * (cm[i]-1) / 2;
    }
    cout << sum << endl;

    // s[i..j] % 2019 == 0
    // (s[i..n] - s[j..n]) / 10^(n-j) % 2019 == 0
    // (s[i..n] % 2019) - (s[j..n] % 2019) == 0
    // s[i..n] % 2019 = s[j..n] % 2019
    
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

int n;
vector<double> p;
double dp[3010][3010], ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	p.resize(n+1);
	for(int i=1; i<=n; ++i) cin >> p[i];
	dp[0][0] = 1.0;
	for(int i=1; i<=n; ++i){
		dp[i][0] = dp[i-1][0] * (1 - p[i]);
		for(int j=1; j<=i; ++j)
			dp[i][j] = dp[i-1][j] * (1 - p[i]) + dp[i-1][j-1] * p[i];
	}
	for(int i=(n+1)/2; i<=n; ++i) ans += dp[n][i];
	cout << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 69120
import copy

def cost_val(visit_list, P, C):
    maxval = [-10**10] * (len(P) + 1)
    for start_idx in visit_list:
        cost = 0
        now_id = start_idx
        for i in range(len(visit_list)):
            now_id = P[now_id]
            cost += C[now_id]
            maxval[i + 1] = max(maxval[i + 1], cost)
    return maxval[1:len(visit_list) + 1]

def cycles(P):
    cycle_list = []
    visit_list = [False] * len(P)
    for i in range(len(P)):
        if visit_list[i]:
            continue
        now_id = i
        cycle = []
        for j in range(len(P)):
            if visit_list[now_id]:
                break
            cycle.append(now_id)
            visit_list[now_id] = True
            now_id = P[now_id]
        cycle_list.append(cycle)
    return cycle_list

def main():
    N, K = map(int, input().split())
    P = list(map(lambda x: int(x) - 1, input().split()))
    C = list(map(int, input().split()))
    cycle_list = cycles(P)
    ans = max(C)
    for cycle in cycle_list:
        maxval = cost_val(cycle, P, C)
        if len(cycle) > K:
            ans = max(ans, max(maxval[:K]))
        else:
            if K % len(cycle) == 0:
                ans = max(ans, max(maxval), max(map(lambda x: x + maxval[-1] * (K // len(cycle) - 1), maxval)), maxval[-1] * (K // len(cycle)))
            else:
                ans = max(ans, max(maxval), max(map(lambda x: x + maxval[-1] * (K // len(cycle) - 1), maxval)), maxval[-1] * (K // len(cycle)) + max(maxval[:(K % len(cycle))]))
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 75504
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);

uint64_t a, b, c, d, i, j, k, n;

int main(){
//////////////////////////////////////////////////////

    //string s;
    
    //cin >> s;

    uint64_t x;
    cin >> a >> b >> x;

    for ( int i = 0 ; i < 10 ; i ++)
    {
        
        x = a * x - b;
        cout << x << endl;
    }

    // cout << "n:" << n << endl;

    // vector<long> input(n+1);
    // for (int i = 1 ; i <= n ; i ++ )
    // {
    //     cin >> input[i];
    //     cout << "input[" << i << "]=" << input[i] << endl;
    // }

    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();


    //////////////////////////////////////////////////////
    // DP

//     // 無限大の値
//     const uint64_t INF = (uint64_t)1 << 60;
//     //const int64_t NINF = -1 * ((int64_t)1 << 60 );

//     // DP テーブル
//     uint64_t dp[100010];

//     //DPテーブル初期化（最小化用）
//     for (int i = 0; i < 100010; ++i)
//     {
//         //dp[i] = INF;
//         dp[i] = 0;
//     } 

//     // 初期条件
//     dp[0] = 0;

//     // ループ
//     for (int i = 1; i <= n; ++i) {
//         //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
//         //if (i < 2)continue;
//         //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));



//         // chmax ( dp [i] , dp[i - 1]);
//         // chmax ( dp [i] , dp[i - 1] + input[i]);
//         // cout << "dp[" << i <<"] = " << dp[i] << endl;

//     }



// //////////////////////////////////////////////////////

//     cout << dp[n] << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
template<class T> inline bool chmin(T& a, T b)
{
    if (a > b) 
    {
        a = b;
        return true;
    }
    return false;
}

//最大化関数
template<class T> inline bool chmax(T& a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

using namespace std;

const int maxn = 100100;

struct dsu {
    vector<int> p;
    int n;

     dsu(int _n) : n(_n) {
        p.resize(n);
        int num=0;
        for (int i=0;i<n;i++) p[i]=num++;
     }

    int get(int x) {
        return (x==p[x] ? x : (p[x] = get(p[x])));
    }

    bool unite(int x,int y) {
        //cout<<x<<" "<<y<<" "<<get(x)<<" "<<get(y)<<endl;
        x = get(x);
        y = get(y);
        if (x!=y) {
            p[x]=y;
            return true;
        }
        return false;
    }
};

int a[maxn],n,m;
long long res;
vector<int> all[maxn];
vector<int> min2;

int main() {
 //   freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=0;i<n;i++) cin>>a[i];
    dsu T(n);
    for (int i=1;i<=m;i++) {
        int x,y;
        cin>>x>>y;
        T.unite(x,y);
    }
    for (int i=0;i<n;i++) {
        all[T.get(i)].push_back(a[i]);
       // cout<<i<<" "<<T.get(i)<<endl;
    }
    int cnt=0;
    for (int i=0;i<n;i++) cnt+=(!all[i].empty());
    if (cnt<=1) {
        cout<<0;
        return 0;
    }
   // cout<<cnt;
    for (int i=0;i<n;i++)
        if (!all[i].empty()) {
            sort(all[i].begin(), all[i].end());
            res+=all[i][0];
           // cout<<all[i][0]<<endl;
            for (int j=1;j<all[i].size();j++) min2.push_back(all[i][j]);
        }
    if (min2.size() < cnt-2) {
        cout<<"Impossible";
        return 0;
    }
    sort(min2.begin(),min2.end());
    for (int i=0;i<cnt-2;i++) res+=min2[i];
    cout<<res;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    sort(a.begin(), a.end());
    a.resize(unique(a.begin(), a.end()) - a.begin());
    if (a.size() == 1 && a[0] == 0) {
        cout << "Yes";
        return 0;
    }
    if (n % 3) {
        cout << "No";
        return 0;
    }
    if (a.size() == 2 && cnt.count(0) && cnt[0] == n / 3) {
        cout << "Yes";
        return 0;
    }
    if (a.size() == 3 && (a[0] ^ a[1] ^ a[2]) == 0 && cnt[a[0]] == n / 3 &&
    cnt[a[1]] == n / 3) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

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

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

    string c;
    cin >> c;

    int red = 0;
    int white = 0;

    for (int i = 0; i < N; i++) {
        if (c[i] == 'R') {
            red++;
        } else {
            white++;
        }
    }
    int output = 0;
    for (int i = red; i < N; i++) {
        if (c[i] == 'R') {
            output++;
        }
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3640
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string s[3];
    rep(i, 3) {
        cin >> s[i];
    }
    int cur[3];
    rep(i, 3) cur[i] = 0;
    int nxt = 0;
    while(true) {
        if(cur[nxt] == (int)s[nxt].size()) {
            cout << (char)('A' + nxt) << endl;
            return;
        }
        cur[nxt] ++;
        nxt = s[nxt][cur[nxt] - 1] - 'a';
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3652
from sys import stdin

readline = stdin.readline


def main():
    s = readline().rstrip()
    UD = ('U', 'D')
    res = 'No'
    for i, c in enumerate(s):
        if c in UD:
            continue
        if i % 2 is 0:
            if c is 'L':
                break
        else:
            if c is 'R':
                break
    else:
        res = 'Yes'
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char c = sc.next().charAt(0);
		if (c >= 'a') {
			System.out.println('a');
		} else {
			System.out.println('A');
		}
	}
}

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

int main()
{
    int a,b,c;
    while(scanf("%d%d",&a,&b)!=EOF){

        c= a-b;
        if(c<0){
            printf("%d\n",0);
        }
        else{
            printf("%d\n",c);
        }

    }
    return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;

    int ans = 0;
    for (int i=A; i<=B; i++) {
        string str_i = to_string(i);
        if ((str_i[0] == str_i[4]) && (str_i[1] == str_i[3])) ans++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#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, greater<int>());
  int sum = 0;
  for(int i = 0; i < k; i++) sum += l[i];
  cout << sum << endl;
}


Measured memory_bytes: 256
#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 a, b;
    cin >> a >> b;
    int ans = 0, ac = 1;
    while(1){
        if(ac >= b){
            cout << ans ;
            break;
        }
        ac--;
        ac += a;
        ans++;
    }
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};



int main() {
    bool flag = false;
    int N; cin >> N;
    vector<ll> A(N);
    int minus_num = 0;
    ll ans = 0LL;
    ll mini_num=INF;
    rep(i,N){
        cin >> A[i];
        if(A[i]<0){
            minus_num++;
        }
        if(A[i]==0){
            flag = true;
        }
        ans += abs(A[i]);
        mini_num = min(mini_num, abs(A[i]));
    }

    if(flag){
        cout << ans << endl;
        return 0;
    }

    if(minus_num%2==0){
        cout << ans << endl;
    }else{
        cout << ans - 2*mini_num << endl;
    }


    return 0;
}


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

using namespace std;
using ll = long long;

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

  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  int nb = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
      if (s[i][j] == '#')
        nb++;
    }
  }

  queue<tuple<int, int, int>> q;
  q.push({0, 0, 0});

  vector<vector<bool>> visit(h, vector<bool>(w, false));
  while (!q.empty()) {
    auto [x, y, d] = q.front();
    q.pop();

    if (x == w - 1 && y == h - 1) {
      cout << h * w - nb - (d - 1) - 2 << endl;
      exit(0);
    }

    for (auto [dx, dy] :
         vector<pair<int, int>>({{-1, 0}, {1, 0}, {0, -1}, {0, 1}})) {
      int nx = x + dx;
      int ny = y + dy;

      if (nx < 0 || nx >= w || ny < 0 || ny >= h)
        continue;
      if (s[ny][nx] == '#')
        continue;
      if (visit[ny][nx])
        continue;
      visit[ny][nx] = true;

      q.push({nx, ny, d + 1});
    }
  }

  cout << -1 << endl;

  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int a[n][3], ans[n][3];
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    memset(ans,-1,sizeof(ans));
    for(int i=0;i<3;i++)
        ans[0][i]=a[0][i];
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(k!=j){
                    ans[i][k]=max(ans[i][k],a[i][k]+ans[i-1][j]);
                }
            }
        }
    }
    int ma=-1;
    for(int i=0;i<3;i++)
    {
        if(ma<ans[n-1][i])
        ma=ans[n-1][i];
    }
    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 5928
#include <stdio.h>
int main(void){
    int n, m;
    scanf("%d %d", &n, &m);
    int l, r;
    scanf("%d %d", &l, &r);
    for(int i=1; i<m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(l<a)l=a;
        if(b<r)r=b;
    }
    if(r<l)printf("0\n");
    else printf("%d\n", r-l+1);
    return 0;
}


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

using namespace std;

int n, x, y;

long long ans = 0;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> x >> y;
        ans += (y - x + 1);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000
using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> c;
  rep(i,n)cin>>a.at(i);
  c = a;
  sort(a.begin(),a.end());
  rep(i,n){
    if(c.at(i)==a.at(n-1))cout<<a.at(n-2)<<endl;
    else cout<<a.at(n-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br =
				new BufferedReader( new InputStreamReader(System.in) );

		int n = Integer.parseInt(br.readLine());

		int[] A = new int[n];
		String[] array = br.readLine().split(" ");
		for (int i=0; i < n; i++) {
			A[i] = Integer.parseInt(array[i]);
		}

		int x = A[n-1];
		int i = -1;
		int temp;
		for (int j=0; j <= n-2; j++) {
			if (A[j] <= x) {
				i++;
				temp = A[i];
				A[i] = A[j];
				A[j] = temp;
			}
		}
		temp = A[i+1];
		A[i+1] = A[n-1];
		A[n-1] = temp;

		StringBuilder sb = new StringBuilder();
		sb.append(A[0]);
		for (int j=1; j < i+1; j++) {
			sb.append(" " + A[j]);
		}

		sb.append(" [" + A[i+1] + "]");

		for (int j=i+2; j < n; j++) {
			sb.append(" " + A[j]);
		}
		System.out.println(sb);
	}

}

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

class Dice {
public:
	int u, f, r, l, b, d;

	Dice(int uu, int ff, int rr, int ll, int bb, int dd) {
		u = uu;
		f = ff;
		r = rr;
		l = ll;
		b = bb;
		d = dd;
	}

	void move(char dir) {
		int tmp;

		if (dir == 'N') {
			tmp = u;
			u = f;
			f = d;
			d = b;
			b = tmp;
		}
		else if (dir == 'W') {
			tmp = u;
			u = r;
			r = d;
			d = l;
			l = tmp;
		}
		else if (dir == 'R') {
			tmp = r;
			r = f;
			f = l;
			l = b;
			b = tmp;
		}
	}
};

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

	Dice dice(a, b, c, d, e, f);
	int q;
	cin >> q;

	for (int i = 0;i < q;i++) {
		cin >> a >> b;
		for (int j = 0;j < 6;j++) {
			if (dice.u == a) {
				for (int k = 0;k < 4;k++) {
					if (dice.u == a && dice.f == b) {
						cout << dice.r << endl;
					}
					dice.move('R');
				}
			}
			if (j % 2 == 0) {
				dice.move('W');
			}
			else {
				dice.move('N');
			}
		}
	}
    return 0;
}



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

int main(){
  string s;
  cin >> s;
  int count = 0;
  if (s[0] == '1') ++count;
  if (s[1] == '1') ++count;
  if (s[2] == '1') ++count;
  cout << count <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>

#define REP(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
typedef long double ld;
using namespace std;

const double pi = 3.141592653589793;
double r;

double L(double r) { return 2 * pi * r; };

double S(double r) { return pi * r * r; };

void solver() {
    cin >> r;
    //cout << S(r) << " " << L(r) << endl;
    printf("%lf %lf\n", S(r), L(r));
}

int main() {
    solver();
    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define f(i, n) for (int i = 0; i < n; ++i)

using namespace std;
void solve() {
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No") << nl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3668
#include <stdio.h>
int main(){
  int a,b,c,i;
  while(scanf("%d %d",&a,&b)!=EOF){
    if(a>=0 && b>=0 && a<=1000000 && b<=1000000){
      c=a+b;
      for(i=1;;i++){
        if(c/10==0)break;
        else c=c/10;
      }
      printf("%d\n",i);
    }
  }
  return 0;
}

Measured memory_bytes: 600
# include <bits/stdc++.h>
using namespace std;
long long  n,a[300005],b[300005],le,ri,x,cnt1,le1,ri1,w,x2;
vector <long long> v;
int main()
{
     cin>>n;
     for (int i=1; i<=n; i++)
     {
          cin>>a[i];
     }
     for (int i=1; i<=n; i++)
     {
          cin>>b[i];
     }
     reverse(b+1, b+n+1);
     for (int i=1; i<=n; i++)
     {
          if (a[i]==b[i] && !le)
          {
               le=i;
          }
          if(a[i]==b[i]) ri=i, x=a[i];
     }
     if (le==0)
     {
     	cout<<"Yes"<<endl;
     	for (int i=1; i<=n; i++)
     	{
     		cout<<b[i]<<" ";
		 }
		 cout<<endl;
		 return 0;
	 }
     for (int i=1; i<=n; i++)
     {
          if (b[i]==x) w++;
          if (a[i]==x) w++;
          if (a[i]==b[i]) v.push_back(i);
          if (a[i]==x && !le1) le1=i;
          if (b[i]==x && !le1) le1=i;
          if (a[i]==x) ri1=i;
     }
     //cout<<x<<endl;
     if (!le1)
     {
     	cout<<"Yes"<<endl;
          for (int i=1; i<=n; i++)
          {
               cout<<b[i]<<" ";
          }
          cout<<endl;
     	return 0;
	 }
     if (w>n) 
     {
          cout<<"No"<<endl;
          return 0;
     }
     x=1;
     x2=n;
    for (int i=0; i<v.size(); i++)
    {
    	if (x<le1)
    	{
    		swap(b[x], b[v[i]]);
    		x++;
		}
		else
		{
			swap(b[x2], b[v[i]]);
			x2--;
		}
	}
     cout<<"Yes"<<endl;
     for (int i=1; i<=n; i++)
     {
          cout<<b[i]<<" ";
     }
     cout<<endl;
     
}

Measured memory_bytes: 8368
from collections import defaultdict as dd
d = dd(int)
N = int(input())
for i in [int(n) for n in input().split()]:
  d[i] = d[i]+1
times = int(input())
summation = sum([ key*value for key, value in d.items() if value > 0])
for i in range(times):
  a, b = [int(n) for n in input().split()]
  summation = summation + (b-a)*d[a]
  d[b], d[a] = d[b] + d[a], 0
  print(summation)

Measured memory_bytes: 23224
import numpy as np

X = float(input())
posx = 0.0
posy = 0.0
K = 0
theta = 0.0
while True:
    posx += np.cos(theta)
    posy += np.sin(theta)
    theta += X / 180 * np.pi
    K += 1
    if np.abs(posx) < 0.000000001 and np.abs(posy) < 0.000000001:
        break
print(K)

Measured memory_bytes: 27200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793

int main() {
	int n;
	cin >> n;
	vector<int>t(n);
	for (int i = 0; i < n; i++)cin >> t[i];
	int m;
	cin >> m;
	vector<int>p(m), x(m);
	for (int i = 0; i < m; i++)cin >> p[i] >> x[i];
	vector<int>copy(t);
	for (int i = 0; i < m; i++) {
		int res = 0;
		copy = t;
		copy[p[i]-1] = x[i];
		for (int j = 0; j < copy.size(); j++) {
			res += copy[j];
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

struct node{
    int parent;
    int c_left;
    int right;
    int depth;
    int rank;
};

void setDepth(node node1[], int num, int depth){
    node1[num].depth = depth;
    int n = num;
    for (int i = 0; i < node1[num].rank; i++){
        if (i == 0) n = node1[n].c_left;
        else n = node1[n].right;
        setDepth(node1, n, depth+1);
    }
}

int main(){
    int n;
    scanf("%d", &n);
    node node1[100000];
    for (int i = 0; i < n; i++) node1[i].parent = node1[i].c_left = node1[i].right = -1;
    for (int i = 0; i < n; i++){
        int num, rank;
        scanf("%d %d", &num, &rank);
        node1[num].rank = rank;
        int c = num;
        for (int j = 0; j < rank; j++){
            int child;
            scanf("%d", &child);
            if (j == 0) node1[c].c_left = child;
            else node1[c].right = child;
            c = child;
            node1[child].parent = num;
        }
    }
    int root = -1;
    for (int i = 0; i < n; i++){
        if (node1[i].parent == -1) root = i;
    }
    setDepth(node1, root, 0);
    
    for (int i = 0; i < n; i++){
        printf("node %d: parent = %d, depth = %d, ", i, node1[i].parent, node1[i].depth);
        if (node1[i].parent == -1) printf("root, [");
        else if (node1[i].rank > 0) printf("internal node, [");
        else printf("leaf, [");
        int num = i;
        for (int j = 0; j < node1[i].rank; j++){
            if (j == 0) num = node1[num].c_left;
            else num = node1[num].right;
            printf("%d", num);
            if (j != node1[i].rank - 1) printf(", ");
        }
        printf("]\n");
    }
}


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

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

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

int main()
{
    int a,b,c,x,ans = 0;
    cin  >> a >> b >> c >> x;
    rep(i, a + 1){
        rep(j, b + 1){
            rep(k, c + 1){
                if (500 * i + 100 * j + 50 * k == x) {
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include<vector>
#include<algorithm>
#include<utility>
#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 srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;



int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sort(rng(a));
    reverse(rng(a));
    vector<int>b(2*n);
    b[0] = a[0];
    srep(i,1,n){
        b[2*i-1]=a[i];
        b[2*i]=a[i];
    }
    ll ans = 0;
    rep(i,n-1) ans +=b[i];
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 5628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;
#define REP(i, n) for (ll i = 0; i < n; i++)

ll n, L, a[100005];
vector<int> ans;

int main() {
    cin >> n >> L;
    REP(i, n) {
        cin >> a[i];
    }
    REP(i,n-1){
        if(a[i]+a[i+1]>=L){
            for(int j=i+1;j>0;j--){
                ans.push_back(j);
            }
            for(int j=i+2;j<n;j++){
                ans.push_back(j);
            }
            reverse(ans.begin(),ans.end());
            cout << "Possible" << endl;
            REP(i,n-1){
                cout << ans[i] << endl;
            }
            return 0;
        }
    }
    cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;
public class Main {
  	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next();
		String b = scanner.next();
		int ans = Integer.parseInt(a+b);
		int i=(int)Math.sqrt(ans);
		if(i*i==ans){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
    }
}

Measured memory_bytes: 23380
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        W: usize,
        WV: [(usize,usize); N],
    }
    let mut dp = vec![vec![0;W+1];N+1];
    for i in 0..N{
        let (w,v) = WV[i];
        for j in 0..W+1{
            if j>=w{
                dp[i+1][j] = max(dp[i+1][j], dp[i][j-w]+v);
            }
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    println!("{}", dp[N][W]);
}

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

int main(){
    long long N;
    cin >> N;
    long long P[5];
    long long T[5];

    for(int i = 0; i < 5; i++){
        cin >> P[i];
        if(N % P[i] == 0){
            T[i] = N / P[i];
        }
        else{
            T[i] = (N / P[i]) + 1; 
        }
    }

    long long count = T[0];

    for(int i = 1; i < 5; i++){
        if(T[i] <= T[i-1]){
            T[i] = T[i-1];
        }
        count += T[i] - T[i-1] + 1;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod1e7(ll a){
  return (a % 1000000007);
}

ll mod1e9(ll a){
  return (a % 1000000009);
}

ll mod998(ll a){
  return (a % 998244353);
}

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

vector<ll> fac(200001);
void factorial(){
  fac[0] = 1; 
  for(ll i=1; i < 200001; i++){
    fac[i] = mod998(fac[i-1]*i);
  }
}
    
ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return mod998(fac[n]/fac[r]/fac[n-r]);
}

int main(){
  ll n,m; cin >> n >> m; ll ans = 0;
  vl liker(m);
  
  rep(i,n){
    ll x; cin >> x;
   
    rep(j,x){
      ll food; cin >> food;
      liker[food-1]++;
    }
  }
  
  rep(i,m){
    if(liker[i] == n){
      ans++;
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 4664
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    vector<mp> c(n);
    for(int i=0;i<n;i++)c[i] = mp(a[i],-b[i]);
    sort(c.begin(),c.end());
    priority_queue<ll> q;
    ll res = 0;
    ll index = 0;
    for(int i=1;i<=m;i++){
	while(index<n&&c[index].first <= i){
	    q.push(-c[index].second);
	    index++;
	}
	if(!q.empty()){
	    res += q.top();
	    q.pop();
	}
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 4472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  a--;
  b--;
  c--;
  d--;
  bool f = 1;
  if (c < b) {
    rep(i, c-a) {
      if (s.substr(a+i, 2) == "##") {
        f = 0;
      }
    }
    rep(i, d-b) {
      if (s.substr(b+i, 2) == "##") {
        f = 0;
      }
    }
  } else if (c < d) {
    rep(i, d-b) {
      if (s.substr(b+i, 2) == "##") {
        f = 0;
      }
    }
    rep(i, c-a) {
      if (s.substr(a+i, 2) == "##") {
        f = 0;
      }
    }
  } else {
    bool ok = 0;
    for (ll i = b; i <= d; i++) {
      if (s.substr(i-1, 3) == "...") {
        ok = 1;
        break;
      }
    }
    f = ok;
  }

  if (f) {
    puts("Yes");
  } else {
    puts("No");
  }
}



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

int main()
{
    int s, w;
    long ans;
    // scanf("%d", &x);
    cin >> s >> w;
    // printf("%d\n", x * x * x);
    if (s > w)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "unsafe" << endl;
    }
}


Measured memory_bytes: 3632
from collections import Counter


def main():
  n, *lst = map(int, open(0).read().split())
  c1, c2 = sorted(Counter(lst[::2]).items(), key=lambda x: x[1], reverse=1), sorted(Counter(lst[1::2]).items(), key=lambda x: x[1], reverse=1)
  c1.append((0, 0)), c2.append((0, 0))
  if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
  else:
    print(n - max(c1[1][1] + c2[0][1], c1[0][1] + c2[1][1]))


if __name__ == '__main__':
  main()

Measured memory_bytes: 20572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  
  if (A+B+C >= 22){
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
}
  

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

int main() {
  int H,W,A,B,i,j;
  cin >> H >> W >> A >> B;
  vector<vector<char>> s(H, vector<char>(W, '0'));

  for(i=0; i<H; i++)
    for(j=0; j<W; j++)
      if((i<B && j>=A) || (i>=B && j<A))
        s.at(i).at(j) = '1';
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++)
      cout << s.at(i).at(j);
    cout << endl;
  }
}

Measured memory_bytes: 2176
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var PriorityQueue=(function(){
  function f(){return new PriorityQueue();}
  function PriorityQueue(){
    this.heap=[];
  }
  PriorityQueue.prototype.push=function(x){
    var h=this.heap,i=h.length++,j;
    while(i){
      j=i-1>>1;
      if(h[j][0]<=x[0])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
  };
  PriorityQueue.prototype.pop=function(){
    var h=this.heap,r=h[0],x=h.pop(),l=h.length,i=0,j;
    if(l===0)return r;
    var k=l>>1;l--;
    while(i<k){
      j=(i<<1)+1;
      if(j<l&&h[j+1][0]<h[j][0])j++;
      if(x[0]<=h[j][0])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
    return r;
  };
  return f;
})();

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var b = o.l();
  var pq = PriorityQueue();
  for(var i = 0; i < n; i++){
    if(a[i] === b[i])continue;
    if(a[i] > b[i])return -1;
    pq.push([-b[i],i]);
  }
  var ans = 0;
  while(pq.heap.length){
    var t = pq.pop();
    var j = t[1];
    var y = b[j?j-1:n-1] + b[j+1===n?0:j+1];
    var z = (b[j]-a[j])/y|0;
    if(z === 0)return -1;
    ans += z;
    b[j] -= y*z;
    if(a[j] === b[j])continue;
    pq.push([-b[j],j]);
  }
  return ans;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) {
        cout << "bust" << endl;
    }
    else cout << "win" << endl;
}

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

typedef long long ll;

int N;
vector<int> A[3];

ll dp[4][100010], psum[4][100010];

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

    for(int i = 0; i < 3; i++) {
        A[i].resize(N);
        for(int j = 0; j < N; j++) {
            scanf("%d", &A[i][j]);
        }
        sort(A[i].begin(), A[i].end());
    }

    for(int i = 0; i < 100010; i++) {
        dp[3][i] = 1;
        psum[3][i] = dp[3][i];
        if(i) psum[3][i] += psum[3][i - 1];
    }
    for(int i = 2; i >= 1; i--) {
        for(int j = 0; j < N; j++) {
            int prev = A[i - 1][j];

            int s = 0, e = N - 1;
            int p = -1;
            while(s <= e) {
                int m = (s + e)>>1;

                if(prev < A[i][m]) {
                    p = m;
                    e = m - 1;
                }
                else s = m + 1;
            }

            if(p != -1) dp[i][j] = psum[i + 1][N - 1] - (p == 0? 0 : psum[i + 1][p - 1]);
            else dp[i][j] = 0;
            psum[i][j] = dp[i][j];
            if(j) psum[i][j] += psum[i][j - 1];
        }
    }
    ll ans = 0;
    for(int i = 0; i < N; i++) ans += dp[1][i];
    cout << ans;
}


Measured memory_bytes: 6912