akhauriyash/Code-Regression huggingface dataset:
N, K, Q = map(int, input().split())
A = []
correct_num = [0 for i in range(N)] 
for i in range(Q):
    A.append(int(input()))
    correct_num[A[i]-1] += 1

for j in range(N):
    if K-Q+correct_num[j] > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 8624
// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 2e5 + 10, N2 = 2e5, delta = 46639, mod = 1e9 + 7, oo = 1e18, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

lli h[N], a[N], dp[N], mx[N << 2];

void add (lli ind, lli val, lli l = 0, lli r = N, lli id = 1) {
	if (r - l <= 1) {
		mx[id] = val;
		return;
	}
	lli mid = (r + l) / 2;
	if (ind < mid)
		add (ind, val, l, mid, 2 * id);
	else
		add (ind, val, mid, r, 2 * id + 1);
	mx[id] = max (mx[2 * id], mx[2 * id + 1]);
}

lli get (lli l, lli r, lli b = 0, lli e = N, lli id = 1) {
	if (l <= b && e <= r)
		return mx[id];
	lli mid = (b + e) / 2, ans = 0;
	if (l < mid)
		ans = max (ans, get (l, r, b, mid, 2 * id));
	if (mid < r)
		ans = max (ans, get (l, r, mid, e, 2 * id + 1));
	return ans;
}

int32_t main() {
	fast;
	lli n, ans = 0;
	cin >> n;
	for (lli i = 0; i < n; i++)
		cin >> h[i];
	for (lli i = 0; i < n; i++)
		cin >> a[i];
	dp[0] = a[0];
	ans = a[0];
	add (h[0] - 1, a[0]);
	for (lli i = 1; i < n; i++) {
		dp[i] = get (0, h[i] - 1) + a[i];
		add (h[i] - 1, dp[i]);
		//cout << dp[i] << '\n';
		ans = max (ans, dp[i]);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sct(tc) scanf("%lld",&tc)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define scs(ch) scanf("%s", ch)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
int main()
{
   ll n,m,x,temp=0,i,sum=0;
   scll(n,m);
   vector<ll>v;
   vector<ll>::iterator it; 
   for(i=0;i<m;i++)
   {
   	 scanf("%lld",&x);
   	 v.pb(x-temp);
   	 temp=x;
   }
   v.pb(n-temp+v[0]);
   it = v.begin(); 
   v.erase(it); 
   sort(v.begin(),v.end());
   for(i=0;i<v.size()-1;i++)
   sum=sum+v[i];
   printf("%lld\n",sum);
}

Measured memory_bytes: 2420
use proconio::{fastout, input};
use std::cmp::min;

#[fastout]
fn main() {
    input! {in_n: usize, in_a: [u64; in_n + 1]};
    let mut leaves = vec![0 as u64; in_n + 1];
    let depth = in_n + 1;

    for i in (1..depth).rev() {
        leaves[i - 1] = leaves[i] + in_a[i];
    }

    let mut node = 1;
    let mut total = 1;

    for i in 0..depth {
        if in_a[i] > node {
            println!("-1");
            return;
        }

        node = min((node - in_a[i]) * 2, leaves[i]);
        total += node
    }

    println!("{}", total);
}


Measured memory_bytes: 4384
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
sumAlice = 0
sumBob = 0
for i in range(N):
    if i % 2 == 0:
        sumAlice += a[i]
    else:
        sumBob += a[i]
print(sumAlice - sumBob)

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()

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

    int64_t N; cin >> N;
    int64_t ans = 0;
    FOR(v, 1, N+1) {
        ans += v * (N - v + 1);
    }
    REP(i, N-1) {
        int v, w; cin >> v >> w;
        if (v > w) swap(v, w);
        ans -= v * (N - w + 1);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 1e5 + 5;
typedef int arr[Maxn];
//ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int k, n;
string s;
int main()
{
	cin >> k >> s;
	if (s.size() <= k)
		cout << s << '\n';
	else
	{
		for (rg int i = 0; i < k; i++)
			putchar(s[i]);
		puts("...");
	}
	return 0;
}
//B

Measured memory_bytes: 3620
#include <iostream>
#include <queue>
#include <string>
#include <cstring>
using namespace std;

#define MAXSTACK 300000
#define MAXSIZE 5010
#define MAXN 12

struct obj {
   short int p, m;
} tmpobj, s[MAXSTACK];

bool starts[MAXSIZE][MAXN], ins[MAXSIZE][1<<MAXN];

int main() {

int N, M, i, j, k, l[MAXN], RES, FULL, E;
string n[MAXN], input, tmp;

cin >> N; FULL = (1<<N)-1;
cin >> M;

do {

for (i=0; i<N; i++) {cin >> n[i]; l[i] = n[i].size();}

input = "";
for (i=0; i<M; i++) {cin >> tmp; input += tmp;}

memset(starts, false, sizeof(starts));
for (i=0; i<input.size(); i++) {
   for (j=1; j<=20; j++) {
		tmp = input.substr(i, j);
		for (k=0; k<N; k++) {
			if (tmp == n[k]) starts[i][k] = true;
		}
	}
}

memset(ins, false, sizeof(ins)); E = 0;
for (i=0; i<input.size(); i++) {
	tmpobj.p = i;
	tmpobj.m = 0;
	s[E++] = tmpobj;
	ins[i][0] = true;
}

RES = 0;
while (E > 0) {
	tmpobj = s[--E];
	if (tmpobj.m == FULL) RES++;
	else {
      for (i=0; i<N; i++) if (starts[tmpobj.p][i] == true && ((tmpobj.m>>i)&1) == 0 && ins[tmpobj.p+l[i]][tmpobj.m^(1<<i)] == false) {
   		s[E].p = tmpobj.p+l[i];
   		s[E].m = tmpobj.m^(1<<i);
	   	ins[s[E].p][s[E].m] = true;
			E++;
			if (E == MAXSTACK) E = 0;
   	}
	}
}

cout << RES << endl;

cin >> N; FULL = (1<<N)-1;
cin >> M;

} while (N!=0 || M!=0);

return 0;
}

Measured memory_bytes: 21712
#include<iostream>
#include<vector>
#define N 100
#define W 10000
using namespace std;

int n,w;
int ans[N+1][W+1];  //ans[i][j]表示前i个货物在j重量限制下的最优解

class item{
public:
    int v;
    int w;
    item(int v,int w){
        this->v=v;
        this->w=w;
    }
    item(){}
};

void deal(int ans[][W+1],item items[]){
    for(int i=0;i<=n;i++) ans[i][0]=0;
    for(int i=0;i<=w;i++) ans[0][i]=0;
    //ans[i][j]=max(ans[i-1][j],ans[i-1][j-items[i].w]+items[i].v);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            ans[i][j]=ans[i-1][j];
            if(items[i].w>j) continue;
            if(ans[i-1][j-items[i].w]+items[i].v>ans[i][j]){
                ans[i][j]=ans[i-1][j-items[i].w]+items[i].v;
            }
        }
    }
}

int main(){
    item items[N+1];
    cin>>n>>w;
    for(int i=1;i<=n;i++){
        cin>>items[i].v>>items[i].w;
    }
    deal(ans,items);
    cout<<ans[n][w]<<endl;
    return 0;
}



Measured memory_bytes: 7000
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x, y;
	cin >> x >> y;
	int tmp;
	while(!(x==0&&y==0)){
		if(x>y){
			tmp = y;
			y = x;
			x = tmp;
		}
		cout << x <<" "<< y << endl;
		cin >> x >> y;
	}
	
	return 0;
}


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

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

    int n; cin >> n;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++)
        v[i] = i;

    vector<bool> ok(n + 1);
    ok[1] = ok[2] = true;
    int pos = 1;

    int q; cin >> q;
    while (q--) {
        int x, y; cin >> x >> y;
        if (v[x] == 1) pos = y;
        if (v[y] == 1) pos = x;
        swap(v[x], v[y]);
        if (1 < pos) ok[v[pos - 1]] = true;
        if (pos < n) ok[v[pos + 1]] = true;
    }

    int cnt = 0;
    for (int i = 1; i <= n; i++)
        cnt += ok[i];
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<map> 
using namespace std;
int a[100005];
map<int,int>mp;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<=0&&b>=0)
	{
		printf("Zero\n");
		return 0;
	}
	if(a>0&&b>0)
	{
		printf("Positive\n");
		return 0;
	}
	if((b-a)%2==0)
	{
		printf("Negative\n");
	}
	else
	{
		printf("Positive\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    vll vec;
    REP(i, 3) {
        ll a;
        cin >> a;
        vec.push_back(a);
    }
    sort(ALL(vec));
    cout << vec.at(0) + vec.at(1) << endl;
    return 0;

}

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

const ll INF = 1e17;
const ll MOD = 1e9+7;
int N;

bool isHonest(int xbool[15][15], ll bit, int person)
{
    for(int i = 0; i < N; i++)
    {
        if (xbool[person][i] != 2 && xbool[person][i] != ((bit & (1<<i)) >> i)) return false;
    }
    return true;
}
 
int getBitSum(ll bit)
{
    int sum=0;
    for (int i=0; i<N; i++)
    {
        if (bit & (1<<i)) sum++;
    }
    return sum;
}

int main() {
    // input, ready
    cin >> N;
    int xbool[15][15];
    for (int i=0; i < N; i++)
    {
        for (int j=0; j< N; j++)
        {
            xbool[i][j] = 2;
        }
    }    

    for (int i=0; i < N; i++)
    {
        int A;
        cin >> A;
        for (int j=0; j< A; j++)
        {
            int x,y;
            cin >> x >> y;
            xbool[i][x-1] = y;
        }
    } 

    //resolve
    // bit探索
    int ans=0;
    for (ll bit=0; bit < (1<<N); bit++)
    {
        bool pool = true;
        int bitsum = getBitSum(bit);
        for (int j =0; j<N; j++)
        {
            if ((bit & (1 << j)) && !isHonest(xbool, bit, j))
            {
                pool = false;
                break;
            }
        }
        if (pool) ans = max(ans, bitsum);
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  n <- getInt
  aList <- concat . transpose <$> replicateM 3 getInts
  let a = listArray (1,3*n) aList
  let part = all (\(i,j)->even (i-j) && ((i`mod`3==2) == (j`mod`3==2))) $ zip aList [1..3*n]
  let sigAll = sig [1..3*n] a
  let sig2x = sig [2,8..3*n] a
  let sig2y = sig [5,11..3*n] a
  let sig13x = even $ length $ filter (\ i -> (a!i)`mod`3==0) [4,10..3*n]
  let sig13y = even $ length $ filter (\ i -> (a!i)`mod`3==0) [1,7..3*n]
  putStrLn . yesNo $ part && sigAll && sig2x == sig13x && sig2y == sig13y

sig ix a = even $ length ix - length (cycles ix a)

cycles :: (Ix a) => [a] -> Array a a -> [[a]]
cycles ix a = let
  -- ix = indices a
  go x = do
    s <- get
    if S.member x s
    then return []
    else do
      put $ S.insert x s
      (x:) <$> go (a!x)
  in
  filter (not . null) $ flip evalState S.empty $ mapM go ix

type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "Yes"
yesNo False = "No"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 97660
#include<iostream>
#include<vector>

using namespace std;

const long long INF=10000000000005;

struct Node
{
	vector<int> to;
	vector<long long> cost;
};

int main()
{
	int n,m;
	cin >> n >> m;
	vector<Node> nodes(n);
	vector<long long> dist(n,INF);
	dist[0]=0;

	for(int i=0;i<m;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		nodes[a-1].to.push_back(b-1);
		nodes[a-1].cost.push_back(c*(-1));
	}


	for(int i=0;i<n-1;i++)
		for(int v=0;v<n;v++)
			for(int k=0;k<nodes[v].to.size();k++)
			{
				if(dist[v]!=INF and dist[nodes[v].to[k]]>dist[v]+nodes[v].cost[k])
				{
					dist[nodes[v].to[k]]=dist[v]+nodes[v].cost[k];
				}
			}

	vector<bool> flag(n,false);

	for(int i=0;i<n;i++)
		for(int v=0;v<n;v++)
			for(int k=0;k<nodes[v].to.size();k++)
			{
				if(dist[v]!=INF and dist[nodes[v].to[k]]>dist[v]+nodes[v].cost[k])
				{
					dist[nodes[v].to[k]]=dist[v]+nodes[v].cost[k];
					flag[nodes[v].to[k]]=true;
				}
			}


	if(flag[n-1])
		cout << "inf" << endl;
	else
		cout << dist[n-1]*(-1) << endl;

}

Measured memory_bytes: 384
using System;

public class AtCoderC
{
    static void Main()
    {
        int n;
        int m;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            m = int.Parse(words[1]);
        }

        bool[] solve = new bool[n + 1];
        int[] was = new int[n + 1];

        int ac = 0;
        int wa = 0;

        for (int i = 0; i < m; i++)
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            int p = int.Parse(words[0]);
            string s = words[1];

            if ("AC".Equals(s))
            {
                if (!solve[p])
                {
                    solve[p] = true;
                    ac++;
                    wa += was[p];
                }
            }
            else
            {
                if (!solve[p])
                {
                    was[p]++;
                }
            }
        }

        Console.WriteLine(ac + " " + wa);
    }
}

Measured memory_bytes: 15456
#include <bits/stdc++.h>
#define int long long 
#define pb push_back
#define fr first
#define sc second
#define sz(v) ((int)(v).size())
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repd(i,a,p) for(int i=a-1;i>=p;i--) 
#define M 1000000007
#define vi vector<int>
#define vp vector<pair<int,int> >
#define ml map<int,int>
#define MPI 3.1415926536
using namespace std;
int temp=0,r,l,w,k=0,m1,e,p,q,ans=0,k1=0,k2=0,d=0,a=0,b=0,s=0,x,y,min1=1000000010,max1=0,m,c=0,t=0,i,n,c1=0,tot=0,t1,k4=0,c2=0,j=0,k3=0;char ch,ch1,ch2;string s1,s2,s3;
signed main()
{
cin>>n>>k;
int k1=100000;
int dp[100010];
dp[0]=0;
vi v1(n),v2(n);
rep(i,0,n)cin>>v1[i]>>v2[i];
rep(i,1,k1+1)dp[i]=M;
rep(i,1,n+1)
{
	for(j=k1;j>=0;j--)
	{
		if(v2[i-1]<=j)
	dp[j]=min(dp[j],dp[j-v2[i-1]]+v1[i-1]);}
}
rep(i,0,k1+1)
{
if(dp[i]<=k)
ans=max(ans,i);	
}
cout<<ans;
}

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

// Circle in a Rectangle
// center of circle, -100 , <= x, y, <= 100, radius 0 <= r <= 100;
// rectangle Width, Height, 0 <= W, H <= 100;


int main(){
	int x, y, W, H, r;
	cin >> W >> H >> x >> y >> r;

	if(x - r < 0 || x + r > W || y - r < 0 || y + r > H){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {

            String sentence = sc.nextLine();

            if (sentence.equals(".")) {
                break;
            }

            char[] str = new char[100];
            str = sentence.toCharArray();

            char[] cutStr = new char[100];
            int count = 0;
            for (int i = 0; i < sentence.length(); i++) {
                if (str[i] == '[' || str[i] == ']' || str[i] == '(' || str[i] == ')') {
                    cutStr[count] = str[i];
                    count++;
                }
            }

            String answer = new String(cutStr);
            answer = answer.trim();
            for (int i = 0; i < 50; i++) {
                answer = answer.replace("()", "");
                answer = answer.replace("[]", "");
            }

            if (answer.equals("")) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }

        }

        sc.close();
    }

}


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

//CONSTRAINTS
const int MN = 1e5 + 100;
const int MS = 4e6;

int N, Q;
struct node
{
public:
	int l, r;
	int c, d;
};
node seg[MS];
int X = MN;
void upd(int n, int l, int r, int ql, int qr, int xd)
{
	if(ql <= l&&r <= qr)
		++seg[n].c, seg[n].d += xd;
	else
	{
		int m=l+(r-l)/2;
		if(ql<m) upd(seg[n].l?seg[n].l:seg[n].l=X++, l, m, ql, qr, xd);
		if(m<qr) upd(seg[n].r?seg[n].r:seg[n].r=X++, m, r, ql, qr, xd);
	}
}
int C, D;
void qry(int n, int l, int r, int q)
{
	if(!n)return;
	C+=seg[n].c, D+=seg[n].d;
	if(r-l>1)
	{
		int m=l+(r-l)/2;
		if(q<m) qry(seg[n].l, l, m, q);
		else qry(seg[n].r, m, r, q);
	}
}

struct edg
{
public:
	int n, c, d;
};
std::vector<edg> a[MN];
int p[MN][20], d[MN], l[MN], pre[MN], post[MN], t;
void dfs(int n=1)
{
	pre[n] = t++;
	for(int i=0;p[n][i]&&p[p[n][i]][i];++i)
		p[n][i+1]=p[p[n][i]][i];
	for(auto x:a[n])
		if(x.n!=p[n][0])
		{
			d[x.n]=d[n]+1;
			l[x.n] = l[n]+x.d;
			p[x.n][0]=n;
			dfs(x.n);
			upd(x.c, 0, N, pre[x.n], post[x.n], x.d);
		}
	post[n] = t;
}
int lca(int a, int b)
{
	if(a==b)return a;
	if(d[b]<d[a])std::swap(a,b);
	for(int i=0,j=d[b]-d[a];(1<<i)<=j;++i)
		if(j>>i&1)
			b=p[b][i];
	if(a==b)return a;
	for(int i=31-__builtin_clz(d[a]);i>=0;--i)
		if(p[a][i]&&p[a][i]!=p[b][i])
			a=p[a][i],b=p[b][i];
	return p[a][0];
}
int main(void)
{
	scanf("%d%d", &N, &Q);
	for(int i = 0;i+1 < N;++i)
	{
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		::a[a].push_back({b, c, d});
		::a[b].push_back({a, c, d});
	}
	dfs();
	for(int i=0,x,y,u,v,c,d;i<Q;++i)
	{
		scanf("%d%d%d%d", &x,&y,&u,&v);
		int z = lca(u, v);

		C=D=0;
		qry(x, 0, N, pre[u]);
		qry(x, 0, N, pre[v]);
		c=C,d=D;
		C=D=0;
		qry(x, 0, N, pre[z]);
		c-=2*C,d-=2*D;
		printf("%d\n", c*y+(l[u]+l[v]-2*l[z])-d);
	}
	return 0;
}


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

int main(){
	int N; cin >> N;
	vector<pair<int, int>> P;
	for(int i=0; i<N; i++){
		int a, b; cin >> a >> b;
		P.push_back({b, a});
	}
	sort(P.begin(), P.end());
	int t = P[N-1].first;
	for(int i=N-1; i>=0; i--){
		t = min(t, P[i].first);
		if(t - P[i].second >= 0){
			t -= P[i].second;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 2420
S = str(input())
ans = 0

for i in range(1 << (len(S) - 1)):
    num = [S[0]]

    for j in range(len(S) - 1):
        if ((i >> j) & 1):
            num.append(S[j + 1])
        else:
            num[-1] += S[j + 1]
    ans += sum([int(n) for n in num])

print(ans)


Measured memory_bytes: 40432
#include <stdio.h>

int main(int argc, char const *argv[]) {

    int a,b,i,j;

    while(1){
        scanf("%d%d",&a,&b);
        if(a == 0 && b == 0){
            break;
        }
        for(i = 0; i < a; i++){
            for(j = 0; j < b; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");

    }
    return 0;
}



Measured memory_bytes: 2100
import math

List = list(map(int, input().split()))

kakuA = - (List[2] * 60 + List[3]) * 0.5 + 90
kakuB = - List[3] * 6 + 90

xA = List[0] * math.cos(math.radians(kakuA))
yA = List[0] * math.sin(math.radians(kakuA))
xB = List[1] * math.cos(math.radians(kakuB))
yB = List[1] * math.sin(math.radians(kakuB))

d = math.sqrt((xA - xB)**2 + (yA - yB)**2)

print(d)

Measured memory_bytes: 9516
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s = sc.next();
		int count = sc.nextInt();
		StringBuffer result = new StringBuffer(s);
		boolean outputflg = true;
		Map<Integer, String> map = new HashMap<Integer,String>();
		int start,end;
		start=0;
		end =0;
		map.put(0, s);
		for(int i=0;i<count;i++) {
			int type = sc.nextInt();
			if (type == 1) {
				outputflg = !outputflg;
			} else {
				int f = sc.nextInt();
				String c = sc.next();
				if ((f==1&&outputflg)||((f==2&&!outputflg))) {
					map.put(start-1 , c);
					start--;
				} else {
					map.put(end+1, c);
					end++;
				}
			}
		}
		if (outputflg) {
			for (int i=start;i<=end;i++) {
				System.out.print(map.get(i));
			}
		} else {
			for (int i=end;i>=start;i--) {
				if (i==0) {
					System.out.print(new StringBuffer(map.get(i)).reverse());
				} else {
					System.out.print(map.get(i));
				}
			}
		}

	}
}

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

int main() {
  int N, M, L, R, mx = 0, mi = 1e9;
  cin >> N >> M;
  while (cin >> L >> R) mx = max(mx, L), mi = min(mi, R);
  cout << max(0, mi - mx + 1) << "\n";
}

Measured memory_bytes: 256
def myAnswer(N:int,s:list,M:int,t:list) -> int:
   dic = dict()
   for blueCard in s:
      if(blueCard in dic.keys()):
         dic[blueCard]+=1
      else:
         dic[blueCard]=1
   for redCard in t:
      if(redCard in dic.keys()):
         if(dic[redCard] > 0):
            dic[redCard] -= 1
   return max(dic.values())


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   s = [input() for _ in range(N)]
   M = int(input())
   t = [input() for _ in range(M)]
   print(myAnswer(N,s[:],M,t[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==1||n==2||n==3||n==5||n==6||n==9||n==10) cout<<"No";
	else if(n==13||n==17||n==27||n==39) cout<<"No";
	else cout<<"Yes";
}

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

int main() {
  int N;
  char c;
  bool res = false;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> c;
    if (c == 'Y') {
      res = true;
    }
  }
  
  if (res) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 998244353
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;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n,m;
    cin >> n >> m;
    if (abs(n-m)>1){
        cout << 0 << endl;
        return 0;
    }
    ll ans=1;
    if (n==m)ans=2;
    for (ll i=1;i<=n;i++){
        ans*=i;
        ans%=1000000007;
    }
    for (ll i=1;i<=m;i++){
        ans*=i;
        ans%=1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int N , M;
vector <int> adj[20];
int cc[20];

bool actu[20];
int solut;
void recursion(int indice)
{
	if (indice == N)
	{
		//cout<<endl;
		for (int i  = 0 ; i < M ; i++)
		{
			int nb = 0;
			for (int j = 0 ; j < adj[i].size() ; j++)
			{
				//cout<<actu[adj[i][j]]<<" ";
				nb+=actu[adj[i][j]];
			}
			//cout<<nb<<endl;
			if (nb % 2 != cc[i]) return;
		}
		solut++;
		return;
	}

	recursion(indice + 1);
	actu[indice] = true;

	recursion(indice + 1);
	actu[indice] = false;
}


int main()
{
	solut = 0;
	cin>>N>>M;
	for (int i = 0 ; i < M ; i++)
	{
		int a;
		cin>>a;
		for (int j = 0 ; j < a ; j++)
		{
			int b;
			cin>>b;
			b--;
			adj[i].push_back(b);
		}
	}
	for (int i = 0 ; i < M ; i++)
	{
		cin>>cc[i];
	}
	recursion(0);
	cout<<solut<<endl;
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
T = []
while Q:
    i = deque.popleft(Q)
    T.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

BU = [0] * N # Bottom Up
TD = [1] * N # Top Down
for i in T[::-1]:
    if len(X[i]) == 0:
        BU[i] = 0
        continue
    s = 0
    for j in X[i]:
        s += BU[j]
    BU[i] = s / len(X[i]) + 1

for i in T:
    if i == 0:
        for j in X[i]:
            TD[j] = 2 + ((BU[i]-1) * len(X[i]) - BU[j]) / (len(X[i]) - 1) if len(X[i]) > 1 else 1
    else:
        for j in X[i]:
            TD[j] = BU[i] + (TD[i] - BU[j] - 1) / len(X[i]) + 1

for i in range(N):
    print((len(X[i]) * BU[i] + TD[i]) / (len(X[i]) + 1) if i else BU[i])

Measured memory_bytes: 94084
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
int Dice(char *p, int d[]);

int main() {
	int d[6], i,sum,n;
	char dir[101], *p;
	while (1) {
		sum = 1;
		scanf("%d", &n);
		for (i = 0; i <6; i++)  d[i] = i + 1;
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%s", dir);
			p = dir;
			sum += Dice(p, d);
		}
		printf("%d\n", sum);
	}
	return 0;
}

int Dice(char *p, int d[]) {
	int tmp;
		if (strcmp(p, "South")==0) { tmp = d[0]; d[0] = d[4]; d[4] = d[5]; d[5] = d[1]; d[1] = tmp; }
		if (strcmp(p, "West") == 0) { tmp = d[0]; d[0] = d[2]; d[2] = d[5]; d[5] = d[3]; d[3] = tmp; }
		if (strcmp(p, "East") == 0) { tmp = d[0]; d[0] = d[3]; d[3] = d[5]; d[5] = d[2]; d[2] = tmp; }
		if (strcmp(p, "North") == 0) { tmp = d[0]; d[0] = d[1]; d[1] = d[5]; d[5] = d[4]; d[4] = tmp;}
		if (strcmp(p, "Left") == 0) { tmp = d[1]; d[1] = d[3]; d[3] = d[4]; d[4] = d[2]; d[2] = tmp; }
		if (strcmp(p, "Right") == 0) { tmp = d[1]; d[1] = d[2]; d[2] = d[4]; d[4] = d[3]; d[3] = tmp; }
		return d[0];
}

Measured memory_bytes: 604
n = int(input())
S = {}
ans = 0

for i in range(n):
    s = list(input())
    s.sort()
    s_s = ''.join(s)
    if s_s in S:
        ans += S[s_s]
        S[s_s] += 1
    else:
        S[s_s] = 1

print(ans)

Measured memory_bytes: 99956
N = int(input())
A = list(map(int, input().split()))
mod = int(1e+9 + 7)
L = A[0]
p = mod - 2
X = []
while p != 0:
  X = [p%2] + X[:]
  p //= 2

def inved(x):
  y = 1
  for i in range(len(X)):
    if X[i] == 1:
      y *= x
      y %= mod
    if i != len(X) - 1:
      y *= y
      y %= mod
  return y

for i in range(N-1):
  a, b = L, A[i+1]
  while b != 0:
    a, b = b, a % b
  b = A[i+1] // a
  L = b * L
S = 0
for i in range(N):
  S += (L * inved(A[i])) % mod
  S %= mod
print(S)



Measured memory_bytes: 4084
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC159D
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] A = ReadLong();
            long[] count = new long[N + 1];
            foreach (var a in A)
            {
                count[a]++;
            }

            long[] countKey = count.Where(x => x >= 2).ToArray();

            long sum = 0;
            for (long i = 0; i < countKey.Length; i++)
            {
                long c = countKey[i];
                long add = (c * (c - 1)) / 2;
                sum += add;
            }

            for (long i = 0; i < N; i++)
            {
                Console.WriteLine(sum - count[A[i]] + 1);
            }
            Console.ReadKey();
        }

        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 40008
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int ab = Integer.parseInt(String.valueOf(a) + String.valueOf(b));

		for (int i = 1; i <= ab; i++) {
			if (i * i == ab) {
				System.out.println("Yes");
				return;
			}
		}

		System.out.println("No");

	}
}


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

using namespace std;

#define LL           long long
#define ULL          long long unsigned
#define LD           long double
#define ff              first
#define ss              second
#define FOR(i,n)     for(int i=0;i<n;i++)
#define FLR(i,n)     for(LL i=0;i<n;i++)
#define RFOR(i,n)    for(int i=n-1;i>=0;i--)
#define RFLR(i,n)    for(LL i=n-1;i>=0;i--)
#define rep(i,a,b)   for(int i=a;i<=b;i++)
#define repl(i,a,b)  for(LL i=a;i<=b;i++)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
#define all(a)       a.begin(),a.end()
#define ABS(x)       ((x)<0?-(x):(x))
#define NL           "\n"
#define pb           push_back
#define mk              make_pair
#define pi           acos(-1.0)
#define prec(n)      fixed << setprecision(n)
#define sq(a)          (a)*(a)
#define asi          cout<<"check"<<" ";
#define all_set(arr,val) memset(arr,val,sizeof(arr))

int main()
{
    fast;
    int i,j,k,ans,n,x;
    map<int,int>mp;
    cin>>n;
    FOR(i,n){
        cin>>x;
        mp[x]=i+1;
    }
    for(i=1;i<=n;i++)cout<<mp[i]<<" ";

}


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

using namespace std;

bool cmp(vector<long long> a, vector<long long> b) {
    if (a.at(0) < b.at(0)) return true;
    if (a.at(0) > b.at(0)) return false;
    if (a.at(1) < b.at(1)) return true;
    return false;
}

bool cmp2(pair<int, long long> a, pair<int, long long> b){
    if (a.first < b.first) return true;
    return false;
}

void print_id(long long a) {
    int zero_count = 0;
    if (a < 10000000) zero_count = 5;
    else if (a < 100000000) zero_count = 4;
    else if (a < 1000000000) zero_count = 3;
    else if (a < 10000000000) zero_count = 2;
    else if (a < 100000000000) zero_count = 1;
    for (int i=0; i<zero_count; i++) cout << 0;
    cout << a << endl;
}

int main () {
    int n = 0, m = 0;
    cin >> n >> m;
    vector<vector<long long>> input(m, vector<long long>(3));
    for (int i=0; i<m; i++) {
        cin >> input.at(i).at(0) >> input.at(i).at(1);
        input.at(i).at(2) = i;
    }
    sort(input.begin(), input.end(), cmp);
    vector<pair<int, long long>> id(m);
    int count = 0;
    long long now_pre = 0;
    for (int i=0; i<m; i++) {
        if (now_pre == input.at(i).at(0)) count++;
        else count = 1;
        now_pre = input.at(i).at(0);
        long long buf = now_pre * (long long)pow(10, 6);
        buf += count;
        id.at(i) = make_pair(input.at(i).at(2), buf);
    }
    sort(id.begin(), id.end(), cmp2);
    for (int i=0; i<m; i++) {
        print_id(id.at(i).second);
    }
    return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int M, T, P, R, m, t, p, j;
  while (cin >> M >> T >> P >> R, M) {
    vector< vector<int> > V(T, vector<int>(P, 0)), Result(T, vector<int>(3, 0));
    for (int i = 0; i < T; ++i) Result[i][2] = -i-1;
    for (int i = 0; i < R; ++i) {
      cin >> m >> t >> p >> j;
      if (j) ++V[t-1][p-1];
      else {
	--Result[t-1][0];
	Result[t-1][1] += V[t-1][p-1]*20+m;
      }
    }
    sort(Result.begin(), Result.end());
    cout << -Result[0][2];
    for (int i = 1; i < T; ++i) {
      if (Result[i-1][0] == Result[i][0] && Result[i-1][1] == Result[i][1]) cout << "=";
      else cout << ",";
      cout << -Result[i][2];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3124
/*
    Problem 2
    https://atcoder.jp/contests/abc106/tasks/abc106_b
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
/* global variables */
/* function */
int cntDvisor(int x) {
    if (x <= 1) return 1;
    int cnt = 0;
    for (int i = 1; i*i <= x; i++) {
        if (x % i == 0) {
            cnt++;
            if (i * i != x) cnt++;
        }
    }
    return cnt;
}
/* main */
int main(){
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        if (cntDvisor(i) == 8) ans++;
    }
    cout << ans << '\n';
}


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

const int MAXN = 100055;

int A[MAXN], O[MAXN];

ll Ans[MAXN];
int N;

int main() {
	ios::sync_with_stdio(false);
	
	cin >> N;
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		Ans[1] += A[i];
	}

	iota(O, O+N+1, 0); sort(O+1, O+N+1, [&](int a, int b) {
		return A[a] != A[b] ? A[a] > A[b] : a < b;
	});
	
	for(int s = 1, e, i = N, t; s <= N; s = e) {
		t = O[s]; if(t < i) i = t; if(1 == i) break;
		for(e = s+1; e <= N && A[O[e]] == A[i]; e++);
		Ans[i] += ll(A[i] - A[O[e]]) * (e-1);
		A[i] = A[O[e]];
	}
	for(int i = 2; i <= N; i++) Ans[1] -= Ans[i];
	for(int i = 1; i <= N; i++) printf("%lld\n", Ans[i]);
	return 0;
}

Measured memory_bytes: 2688
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int A = intArray[0];
            int B = intArray[1];

            int C = intArray[2];
            int D = intArray[3];
            while (true)
            {
                C = C - B;
                A = A - D;
                if(C <= 0)
                {
                    Console.WriteLine("Yes");
                    break;
                }
                else if(A <= 0)
                {
                    Console.WriteLine("No");
                    break;
                }
            }
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28244
#include <iostream>
#include <cstdio>

//#define PI 3.141592653589

using namespace std;



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

Measured memory_bytes: 1164
import bisect
import copy

#bisect2回使用する計算はアウト

N = int(input())
L = [int(i) for i in input().split()]
L.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        Max = bisect.bisect_left(L,L[i]+L[j])
        ans += max(Max-(j+1),0)
print(ans)

Measured memory_bytes: 3700
N,A,B=[int(i) for i in input().split()]

def findsum0fdigit(n):
    sum=0
    while n>0:
        sum+=n%10
        n//=10
    return sum

find_list=[]    
for x in range(1,N+1):
    if A<=findsum0fdigit(x)<=B:
        find_list.append(x)
        
print(sum(find_list))

Measured memory_bytes: 9312
N, K = map(int, input().split())
d = []
A = [[] for i in range(K)]

for i in range(K):
    d.append(int(input()))
    A[i] = list(map(int, input().split()))

hold = set()
for i in range(len(A)):
    hold = hold | set(A[i])

print(N - len(hold))

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

int main(void) {
    int64_t X;
    int64_t j,k;
    cin >> X;

    if(X == 2 ) {
        cout << "2\n";
        return 0;
    }
    for(int64_t i=X;;i++){
        if((i % 2) == 0) continue;
        k = 0;
		for(j=3;j<=sqrt(i);j+=2) {
			if(i%j==0) {
				k=1;
				break;
			}
		}

		if(k==0){
            printf("%ld\n",i);
            break;
        }
    }
    
    return 0;
}


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

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

  vector<int> ball(N + 1);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    ball[A]++;
  }

  sort(ball.begin(), ball.end());
  int type = 0, rewrite = 0;
  for (int i = 1; i <= N; i++) {
    if (!type&&ball[i]) rewrite = i;
    if (ball[i]) type++;
  }

  int ans = 0;
  for (int i = type; i > K; i--) {
    ans += ball[rewrite];
    rewrite++;
  }

  cout << ans << endl;

  return 0;
}

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string s; cin >> s;
	if(s == "SUN") cout << 7;
	else if(s == "MON" ) cout << 6;
	else if(s == "TUE") cout << 5;
	else if(s == "WED") cout << 4;
	else if(s == "THU") cout << 3;
	else if(s == "FRI") cout << 2;
	else cout << 1;
} 

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int i=0;
  char str[1200];
 
  gets(str);
 
  while(1)
    {
      if(str[i] == '\0')
        {
          break;
        }
      if('a' <= str[i] && str[i] <= 'z')
        {
          str[i] -= 0x20;
        }
      else if('A' <= str[i] && str[i] <= 'Z')
        {
          str[i] += 0x20;
        }
      i++;
    }
 
  puts(str);
  return 0;
}

Measured memory_bytes: 920
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
l = na()

l = sorted(l)
 
print(sum(l[n-k:]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int32_t main() {

    fast
    
    int d,t,s;
    cin>>d>>t>>s;

    if(d<=s*t){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }



    return 0;
}



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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);
    const vector<char> v={'a','e','i','o','u'};
    char c;
    cin >> c;
    cout << (find(ALL(v),c)!=v.end()?"vowel":"consonant") << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:isize,
    b:isize,
    }
    println!("{}",2*b-a)
}

Measured memory_bytes: 2164
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main()
{
    ll n;
    ll s = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
        s = s ^ a[i];
    }
    rep(i, n)
    {
        ll r = s ^ a[i];
        cout << r << " ";
    }
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
int n,c[N],sz[N],all,now[N],u,v;
vector<int>e[N];
ll ans[N];
void dfs(int u,int fa){
	sz[u]=1;
	int tmp=now[c[u]];//进入u的子树前now[c[u]]的值 
	for(auto &v:e[u]){
		if(v==fa)continue;
		int pre=all-now[c[u]];
		dfs(v,u);
		sz[u]+=sz[v];
		int nex=all-now[c[u]];
		ans[c[u]]-=1ll*(nex-pre)*(nex-pre-1)/2;
	}
	all++;
	now[c[u]]=tmp+sz[u];//离开u的子树后now[c[u]]的值 
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&c[i]);
		ans[i]=1ll*n*(n-1)/2;
	} 
	for(int i=1;i<n;++i){
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,-1);
	for(int i=1;i<=n;++i){
		int pre=0,nex=all-now[i];
		ans[i]-=1ll*(nex-pre)*(nex-pre-1)/2;
	}
	for(int i=1;i<=n;++i){
		ans[c[i]]++;
	}
	for(int i=1;i<=n;++i){
		printf("%lld\n",ans[i]);
	}
	return 0;
} 

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

using namespace std;

typedef long long ll;


void solve()
{
	ll n;
	cin>>n;
	vector<ll> arr(n);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	ll ans=INT_MAX;
	for(int i=1;i<=100;i++)
	{
		ll sta=0;
		for(int j=0;j<n;j++)
		{
			sta+=(arr[j]-i)*(arr[j]-i);
		}
		ans=min(ans,sta);
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;
ll dp[110][100100];
 
int main(){
   int n,m;
   cin >> n >> m;
   int ans = 0;
   vector<bool>ok(n,false);
   vector<int>pena(n,0);
   rep(i,m){
        int p;
        string  s;
        cin >> p >> s;
        p--;
        if(ok[p])continue;
        if(!ok[p]){
           if(s=="AC"){
              ans++;
              ok[p]=true;
           }
           if(s=="WA")pena[p]++;
        }
        
   }
   int cnt = 0;
   rep(i,n){
      if(ok[i])cnt+=pena[i];
   }
   cout << ans << ' ' <<cnt <<endl;
}

Measured memory_bytes: 3780
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        long W = int.Parse(str[1]);
        long[] DP = new long[10001];
        for(int i=1;i<10001;i++){
            DP[i] = W+1;
        }
        for(int j=0;j<N;j++){
            str = Console.ReadLine().Split(' ');
            int v = int.Parse(str[0]);
            long w = int.Parse(str[1]);
            for(int i=10000;i>=v;i--){
                DP[i] = Math.Min(DP[i],DP[i-v]+w);
            }
        }
        for(int i=10000;i>=0;i--){
            if(DP[i] <= W){
                sb.Append(i+"\n");
                break;
            }
        }
    }
}

Measured memory_bytes: 9268
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    int t = 0;
    for (double d = A + 0.5; d < B; d += 1.0) {
      if (C < d && d < D) t++;
    }
    System.out.println(t);
  }
}


Measured memory_bytes: 20820
N = int(input())
happy = [list(map(int, input().split())) for _ in range(N)]

# i日目に選んだ行動別の幸福度の最大値
dp = [[0, 0, 0] for _ in range(N+1)]

act = None
for i in range(N):
    a, b, c = happy[i]
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
    dp[i+1][1] = max(dp[i][2], dp[i][0]) + b
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c

print(max(dp[-1]))

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

using namespace std;
using ll = long long;

int main()
{
    ll n;
    cin >> n;
    ll ans;
    if (n & 1LL) {
        ans = n / 2;
        ans = ans * n;
    } else {
        ans = n * (n - 1) / 2;
    }
    cout << ans;
    return 0;
}


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

using namespace std;

int main(){
    int n ;
    cin >> n;
    string x[n];
    
    double u[n];

    double bit = 380000.0;

    double all = 0;

    for(int i = 0; i < n; i++){
        cin >> u[i];
        cin >> x[i];
        if(x[i] == "JPY"){
            all += u[i];
        }else{
            all += u[i] * bit;
        }

    }

    cout << all << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v;
int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0){
			cout << " " << i;
			continue;
		}
		int x = i;
		while (x != 0) {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	cout << endl;
}


Measured memory_bytes: 3092
use std::io::*;
use std::str::FromStr;
use std::cmp::max;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:i32 = read();
    let b:i32 = read();

    let max = max(max(a+b,a-b),a*b);
    println!("{}",max);
}

Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
const int maxn=1111;
int dis[maxn][maxn],A[maxn][maxn],X[5]={0,-1,1,0,0},Y[5]={0,0,0,-1,1};
char ss[maxn];
bool vis[maxn][maxn];
struct hhh
{
	int x,y;
	hhh(int a=0,int b=0)
	{
		x=a,y=b;
	}
};
queue<hhh> Q;
int main()
{
	int N,M;scanf("%d%d",&N,&M);
	for(int i=1;i<=N;++i)
	{
		scanf("%s",ss+1);
		for(int j=1;j<=M;++j) A[i][j]=(ss[j]=='#');
	}
	for(int i=1;i<=N;++i)for(int j=1;j<=M;++j)if(A[i][j]) Q.push(hhh(i,j)),vis[i][j]=true;
	while(!Q.empty())
	{
		hhh q=Q.front();Q.pop();
		for(int i=1;i<=4;++i)
		{
			int xx=q.x+X[i],yy=q.y+Y[i];
			if(!xx||!yy||xx>N||yy>M||vis[xx][yy]) continue;
			dis[xx][yy]=dis[q.x][q.y]+1;
			Q.push(hhh(xx,yy)),vis[xx][yy]=true;
		}
	}
	int ans=0;
	for(int i=1;i<=N;++i)for(int j=1;j<=M;++j) ans=max(ans,dis[i][j]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 15488