akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int S[100000000];
int T[100000000];
int s,t;
int serch(int);
int main(){
  int i=0,count=0;
  scanf("%d",&s);
  while(i<s){
    scanf("%d",&S[i]);
    i++;
  }
  i=0;
  scanf("%d",&t);
  while(i<t){
    scanf("%d",&T[i]);
    i++;
  }
  for(i=0;i<t;i++) count+=search(T[i]);
  printf("%d\n",count);
  return 0;
}

int search(int x){
  int i;
  for(i=0;i<s;i++){
    if(S[i]==x)return 1;
    }
  return 0;

}

Measured memory_bytes: 2652
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e5+50;
int arr[MAX];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	bool flag=true;
	for(int i=n-1;i>=1;i--){
		if(arr[i]<=arr[i+1]){
			continue;
		}
		else if(arr[i]-1<=arr[i+1]){
			arr[i]--;
		}
		else{
			flag=false;
			break;
		}
	}
	if(flag){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

pub 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")
}

use std::collections::VecDeque;

fn main() {
    let x: i64 = read();
    let a: i64 = read();
    let b: i64 = read();
    if b <= a {
        println!("delicious");
        return;
    }

    if b - a <= x {
        println!("safe");
    } else {
        println!("dangerous");
    }
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(){
const int MAX_V=999999;
int prime[MAX_V+1];
	int i,k,n;
	for(i=2;i<=MAX_V;i++){
		prime[i]=1;
	}
	for(i=2;i*i<=MAX_V;i++){
		if(prime[i]){
			for(k=2*i;k<=MAX_V;k+=i){
				prime[k]=0;
			}
		}
	}
	prime[0]=0;
	prime[1]=0;
	int count=0;
	while(scanf("%d",&n)!=EOF){
		count++;
		int cnt=0;
		for(i=n;i>0;i--){
			if(prime[i]==1){
				cnt++;
			}
		}
		printf("%d\n",cnt);
		if(count==30)break;
	}
	return 0;
}

Measured memory_bytes: 4500
K,N = map(int,input().split())
ls_A = list(map(int,input().split()))
d_ls_A = []
for i in range(len(ls_A)-1):
    d_ls_A.append(ls_A[i+1]-ls_A[i])
d_ls_A.append(K-ls_A[N-1]+ls_A[0])
print(K-max(d_ls_A))

Measured memory_bytes: 25836
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn is_ACGT(c: char) -> bool {
    c=='A' || c=='C' || c=='G' || c=='T'
}

fn main() {
    let s = read::<String>();
    let mut max_count = 0;
    let mut count = 0;
    for c in s.chars() {
        if is_ACGT(c) {
            count += 1;
        } else {
            max_count = std::cmp::max(max_count, count);
            count = 0;
        }
    }
    max_count = std::cmp::max(max_count, count);
    println!("{}", max_count);
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    val foods = (1..5).map { readLine()!!.toInt() }.toIntArray()

    // 要素に9を足したものを10で割った余りが最小の要素を探す
    var min = Int.MAX_VALUE
    var lastfood = 0
    foods.forEach {
        val r = (it + 9) % 10
        if(min > r){
            min = r
            lastfood = it
        }
    }

    foods.set(foods.indexOfFirst { it == lastfood }, 0)

    println(foods.map { (it + 9)/10*10 }.sum() + lastfood)
}



Measured memory_bytes: 36288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  vector<int> cnt(n + 1);
  for (int x = 1; x * x <= n; ++x) for (int y = 1; x * x + y * y + x * y <= n; ++y) for (int z = 1; x * x + y * y + z * z + x * y + y * z + z * x <= n; ++z) {
    int w = x * x + y * y + z * z + x * y + y * z + z * x;
    cnt[w]++;
  }
  rep3(i, 1, n + 1) cout << cnt[i] << endl;
}


Measured memory_bytes: 3652
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort()
q.sort()
r.sort()
l = p[a-x:a] + q[b-y:b]
l.sort()

j = 0
for i in range(min(c,x+y)):
    if l[j] < r[c-i-1]:
        l[j] = r[c-i-1]
        j += 1
print(sum(l))

Measured memory_bytes: 23328
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	r.Scan(false)
	s := r.nextString()

	fmt.Fprintln(stdout, len(strings.Split(s, "ABC"))-1)

}


Measured memory_bytes: 640
#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;
    }

    return 0;
}


Measured memory_bytes: 256
# union-find木
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



N, K, L = map(int, input().split())

uf_road = UnionFind(N)
uf_train = UnionFind(N)

for _ in range(K):
    a, b = map(int, input().split())
    uf_road.union(a-1, b-1)
    
for _ in range(L):
    a, b = map(int, input().split())
    uf_train.union(a-1, b-1)

from collections import defaultdict

d = defaultdict(int)
for i in range(N):
    d[(uf_road.find(i), uf_train.find(i))]+=1
    
ans = []
for i in range(N):
    ans.append(d[(uf_road.find(i), uf_train.find(i))])

print(' '.join(map(str, ans)))


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

#define ll long long
#define mod 1000000007
#define inf 1000000000000000000
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,a,n) for(ll i=n-1;i>=a;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define umap unordered_map<ll,ll>
#define lpq priority_queue<ll,vector<ll>,greater<ll>>
ll globe=0;
ll powe(ll n,ll r){if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);}

ll solve(vector<vll> &dp,vll &w,vll& v,ll i,ll c){
	if(i<0||c<=0)
		return 0;
	if(dp[i][c]!=-1)
		return dp[i][c];
	if(c>=w[i])
		dp[i][c]=v[i]+solve(dp,w,v,i-1,c-w[i]);
	dp[i][c]=max(dp[i][c],solve(dp,w,v,i-1,c));
	return dp[i][c];
}

int main(){

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll t=1;
	//cin>>t;
	while(t--){
		ll n,cap;
		cin>>n>>cap;
		vll w(n);//weight
		vll v(n);//value
		for(ll i=0;i<n;i++)
			cin>>w[i]>>v[i];
		globe=n;
		vll sdp(cap+1,-1);
		vector<vll> dp(n,sdp);
		ll ans=solve(dp,w,v,n-1,cap);
		cout<<dp[n-1][cap]<<endl;
	}

	return 0;

}

Measured memory_bytes: 79488
N = int(input())
A = list(map(int,input().split()))
A.sort()
A = A[::-1]
ans = 0
if N%2==0:
    for i in range(N//2):
        if i==0:
            ans += A[i]
        else:
            ans += 2*A[i]
else:
    for i in range(N//2):
        if i==0:
            ans += A[i]
        else:
            ans += 2*A[i]
    ans += A[N//2]
print(ans)

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

int main() {
  
  vector<int> vec(5);
  
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2) >> vec.at(3) >> vec.at(4);
  
  for(int i=0; i<5; i++) {
    
    if(vec.at(i)==0) {
      
      cout << i+1 << endl;
      
    }
    
  }
  
}

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

int main(){
  int n;
  cin>>n;
  vector<vector<int>> a(n,vector<int>(3,0));
  for(int i = 0; i < n; i ++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  
  vector<vector<int>> dp(n,vector<int>(3,0));
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];
                
  for(int i  = 1; i < n; i ++){
    dp[i][0] = a[i][0] + max(dp[i-1][1] , dp[i-1][2]);
    dp[i][1] = a[i][1] + max(dp[i-1][0] , dp[i-1][2]);
    dp[i][2] = a[i][2] + max(dp[i-1][0] , dp[i-1][1]);
  } 
  cout<<max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]));
}


Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    
    int n,m;
    long long int x[1111][4],judge[1111]={0},all=0,ans=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>x[i][0]>>x[i][1]>>x[i][2];
    for(int Bit=0;Bit<(1<<3);Bit++){
        for(int i=0;i<3;i++){
            if(Bit&(1<<i)){
                for(int j=0;j<n;j++){
                    judge[j]-=x[j][i];
                }
            }
            else{
                for(int j=0;j<n;j++)judge[j]+=x[j][i];
            }
        }
        sort(judge,judge+n,greater<long long int>());
        for(int i=0;i<m;i++)all+=judge[i];
        //cout<<all<<endl;
        ans=max(all,ans);
        all=0;
        
        for(int i=0;i<n;i++)judge[i]=0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int a,b,c;
    cin >> a >> b >> c;
    cout << ((c - (a - b) >= 0) ? c - (a - b) : 0) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++){
            s[i] = sc.next();
        }

        Set<String> set = new HashSet<>();
        for (int i = 0; i < n; i++){
            set.add(s[i]);
        }

        System.out.println(set.size());
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    int n = s.size();
    int p = 2019;
    vector<int> sum(n + 1);
    reverse(s.begin(), s.end());
    ll x = 1;
    FOR (i, 1, n + 1) {
        ll t = s[i - 1] - '0';
        t *= x;
        sum[i] = t;
        x *= 10;
        x %= p;
    }
    FOR (i, 1, n + 1) {
        sum[i] += sum[i - 1];
        sum[i] %= p;
    }
    ll res = 0;
    map<int, int> mp;
    rep (i, n + 1) {
        res += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << res << endl;
    
    return 0;
}



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

int main(){
  string t, s;
  cin >> s >> t;
  int u = t.size();
  int v = s.size();
  int count = 0;
  int m = 0;
  for (int i = 0; i < v - u + 1; i++){
    for (int j = 0; j < u; j++){
      if (s.at(j + i) == t.at(j)){
        count++;
      }
    }
    m = max(m, count);
    count = 0;
  }
  cout << u - m << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include<iomanip>
using namespace std;
int main(void){
    // Your code here!
double w,h,x,y;
cin>>w>>h>>x>>y;

cout<<fixed<<setprecision(6)<<(w*h)/2;
if(x==w/2 && y==h/2)
    cout<<" "<<1;
else
cout<<" "<<0;
}


Measured memory_bytes: 3256
#include<iostream>
#include<iomanip>

using namespace std;

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  int n,m;
  cin>>n>>m;
  n==m ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    t = str(readline().rstrip().decode('utf-8'))
    print("Yes" if s == t[:len(s)] else "No")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 80016
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 13:56:40 2020

@author: shinba
"""
import sys
from collections import deque

s = input()
q = int(input())

dq = deque(s)
rev = False

for i in range(q):
    t = sys.stdin.readline().rstrip().split()
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            if rev:
                dq.append(t[2])
            else:
                dq.appendleft(t[2])
        else:
            if rev:
                dq.appendleft(t[2])
            else:
                dq.append(t[2])

s = "".join(list(dq))

if rev:
    print(s[::-1])
else:
    print(s)
        
        


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

using namespace std;

typedef long long ll;

#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORd(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
#define II pair<ll,ll>

const int N=8e3+10;
const int maxN=1e5;

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE
    string s,s1,x;
    cin >> s;
    cin >> s1;
    x=s1.substr(0,s1.length()-1);
    if (x==s) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3628
n,q = map(int, input().split())
if n == 1:
  for _ in range(q):
    print(min(map(int, input().split())))
else:
  for _ in range(q):
    v,w = map(int, input().split())
    while v != w:
      if v > w:
        v,w = w,v
      w = (w+n-2)//n
    print(v)

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

int main(){
    int n;
    while(cin >> n, n){
        vector<int> v(n);
        for(int i = 0; i < n; i++)  cin >> v[i];
        sort(v.begin(), v.end());
        for(int i = 0; i < n; i++){
            if(i)   cout << " ";
            int j = i;
            while(j+1 < n && v[j+1]-v[j] == 1)  j++;
            if(i != j)  cout << v[i] << "-" << v[j];
            else        cout << v[i];
            i = j;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3036
#include <stdio.h>

int main(void)
{
	int n, x, max;
	int a, b, c;
	int ans;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		ans = 0;
		max = x; if (max > n) max = n;
		for (a = 1; a <= max; a++) {
			for (b = a + 1; b <= max; b++) {
				c = x - a - b;
				if (c > b && c <= n) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}



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

int main() {
    int N,L;
    cin >> N>>L;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
    vec.at(i)=i+L;
    }
  
  int answer=0;
  
    for (int i = 0; i < N; i++) {
      answer+=vec.at(i);
    }
  
  int ab=1000;
  int h;
  
    for (int i = 0; i < N; i++) {
      if(abs(0-vec.at(i))<ab){
        h=i;
        ab=abs(0-vec.at(i));
      }
    }
  
  cout<<answer-vec.at(h)<<endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a;string s;cin>>a>>s;
  if(a>=3200){
    cout(s);
  }else{
    cout("red");
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);

	//0埋め
	static String zeroLine(String a) {
		String zero = "";
		if(a.length() < 32) {

			for(int i=0; i<32-a.length(); i++) {
				zero += "0";
			}
		}
		return zero + a;
	}

	//文字列の出力
	static void printStr(String a) {

		for(int i=a.length()-32; i<a.length(); i++) {
			System.out.print(a.charAt(i));
		}
		System.out.println();
	}


	public static void main(String args[]) {

		Long num1 = scan.nextLong();
		Long num2 = scan.nextLong();

		//2進数
		printStr(zeroLine(Long.toBinaryString(num1 & num2)));
		//
		printStr(zeroLine(Long.toBinaryString(num1 | num2)));
		//
		printStr(zeroLine(Long.toBinaryString(num1 ^ num2)));
	}
}	


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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> v) {
  if (v.size() > n) {
    int now = 0;
    rep(i, q) {
      if (v[b[i]] - v[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  v.push_back(v.back());
  while (v.back() <= m) {
    dfs(v);
    v.back()++;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(vector<int>(1, 1));
  cout << ans << endl;
}

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

int main(){
	int n;
	cin>>n;
	string st,last; 
	vector<string> s(n);
	cin>>st;
	last=st;
	s[0]=st;
	bool f=true;
	for(int i=1;i<n;i++){
		cin>>st;
		if(st[0]!=last[last.size()-1]){
			f=false;
		}
		for(int j=0;j<i;j++){
			if(st==s[j]){
				f=false;
			}
		}
		s[i]=st;
		last=st;
	}
	if(f) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
def merge(arr, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = []
  for i in 0...n1
    l << arr[left + i]
  end
  r = []
  for i in 0...n2
    r << arr[mid + i]
  end
  l << Float::INFINITY
  r << Float::INFINITY
  i = 0
  j = 0
  for k in left...right
    if l[i] <= r[j]
      arr[k] = l[i]
      i += 1
    else
      arr[k] = r[j]
      j += 1
    end
    $cnt += 1
  end
end

def merge_sort(arr, left, right)
  if left + 1 < right
    mid = (left + right) / 2
    merge_sort(arr, left, mid)
    merge_sort(arr, mid, right)
    merge(arr, left, mid, right)
  end
end

n = gets.to_i
s = gets.split.map(&:to_i)
$cnt = 0
merge_sort(s, 0, n)
puts s.join(' ')
puts $cnt


Measured memory_bytes: 62404
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int length = scanner.nextInt();
        final int[] array = new int[length];

        for (int i = 0; i < length; i++) {
            array[i] = scanner.nextInt();
        }

        int res = 0;
        for (int i = 1; i < length - 1; i++) {
            if (array[i] > array[i - 1] && array[i + 1] > array[i] || array[i] < array[i - 1] && array[i + 1] < array[i]) {
                res++;
            }
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 23252
#include<stdio.h>
#define N 10000
#define Q 500

int search(int);
int S[N];
int n;

int main(){
  int q,T[N],i,j,x,count=0;
  scanf("%d",&n);
  for(i = 0; i< n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
  }
  for(i = 0; i < q; i++){
    x = search(T[i]);
    if(x >= 0 && x < n ){
      count++;
    }
  }

  printf("%d\n",count);
  return 0;
}

int search(int key){
  int i = 0;
  S[n] = key;
  while(S[i] != key){
    i++;
    if(i ==n){
      return n;
    }
  }
  return i;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> idx(N);
    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(), [&](int l, int r) { return A[l] > A[r]; });

    vv<ll> dp = vvec(N + 1, N + 1, 0LL);
    rep(i, N) {
        rep(j, i + 1) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + (ll)A[idx[i]] * abs(N - (i - j) - 1 - idx[i]));
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (ll)A[idx[i]] * abs(j - idx[i]));
        }
    }
    write(*max_element(all(dp[N])));
}

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

using namespace std;

#define int long long

const int N=3e5;

int n;
int color[N];
int f[N];
int sum[N];
vector<int> adj[N];
int cnt;

void dfs(int u,int pr){
	int tmp=f[color[u]]+cnt;
	cnt++;
	for(auto v:adj[u]){
		if(v!=pr){
			f[color[u]]=-cnt;
			dfs(v,u);
			int s=f[color[u]]+cnt;
			sum[color[u]]+=(s*(s+1))/2;
		}
	}
	f[color[u]]=tmp-cnt;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>color[i];
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1,-1);
	for(int i=1;i<=n;i++){
		int s=f[i]+cnt;
		sum[i]+=(s*(s+1))/2;
		cout<<(n*(n+1))/2-sum[i]<<"\n";
	}
}

Measured memory_bytes: 37152
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

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

  std::cin >> NN;

  int hyaku = 100;
  int ps[hyaku];
  int pcas[hyaku];

  for (size_t i = 0; i < hyaku; i++) {
    ps[i] = 0;
    pcas[i] = 0;
  }

  ps[0] = 2;
  ps[1] = 3;
  ps[2] = 5;
  ps[3] = 7;
  ps[4] = 11;
  ps[5] = 13;
  ps[6] = 17;
  ps[7] = 19;
  ps[8] = 23;
  ps[9] = 29;
  ps[10] = 31;
  ps[11] = 37;
  ps[12] = 41;
  ps[13] = 43;
  ps[14] = 47;

  for (int i = 1; i < NN+1; i++) {
    int nuu = i+0 ;
    for (size_t j = 0; j < 15; j++) {
      while (nuu % ps[j] == 0) {
        nuu = nuu / ps[j];
        pcas[j]++;
        // std::cout << "here_" << '\n';
      }
    }
  }

  // for (size_t j = 0; j < 15; j++) {
  //   std::cout << "prime"<<ps[j] << "::: "<< pcas[j]<<'\n';
  // }

  int ans = 0;

  if (pcas[0] >= 74) {
    ans += 1;
  }

  // if (pcas[0] > 24) {
    for (size_t j = 0; j < 15; j++) {
      if (pcas[j] >= 24) {
        // int count_sub = 0;
        for (size_t j2 = 0; j2 < 15; j2++) {
          if (j2 != j) {
            if (pcas[j2] >= 2) {
              // count_sub ++;
              ans ++;
            }
          }
        }
      }
    }
  // }

  for (size_t j = 0; j < 15; j++) {
    if (pcas[j] >= 14) {
      // int count_sub = 0;
      for (size_t j2 = 0; j2 < 15; j2++) {
        if (j2 != j) {
          if (pcas[j2] >= 4) {
            // count_sub ++;
            ans ++;
          }
        }
      }
    }
  }

  for (size_t j1 = 0; j1 < 15; j1++) {
    if (pcas[j1] >= 2) {
      for (size_t j2 = 0; j2 < 15; j2++) {
        if (j2 != j1 && pcas[j2] >= 4) {
          for (size_t j3 = j2 + 1; j3 < 15; j3++) {
            if (j3 != j1 && pcas[j3] >= 4) {
              ans++;
            }
          }
        }
      }
    }
  }


  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define what_is(x) cerr << #x << " is " << x << endl;
int mp[1000009];
bool check (int n)
{
    bool bo=1;
    for (int i=2; i*i<=n; ++i)
    {
        if (n%i==0)
        {
            if (mp[i]>0)
                return 0;
            if (n%(n/i)==0 )
            {
                if (mp[n/i]>0)
                    return 0;
            }
        }
    }
    return 1;
}
int main()
{
    fastIO;
    int n;
    cin>>n;

    vector<int>v(n);
    for (int i=0; i<n; ++i)
    {
        cin>>v[i];
        mp[v[i]]++;
    }

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

    int ans=0;
    for (int i=0; i <n; ++i)
    {
        --mp[v[i]];
        if (mp[1] || mp[v[i]])
        {
            ++mp[v[i]];
            continue;
        }

        if (check(v[i]))
            ++ans;
        ++mp[v[i]];
    }
    cout<<ans;




}


Measured memory_bytes: 7944
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 10000000000
#define PI 3.141592653589793

int main() {
	long long h, w, ans;
	cin >> h >> w;

	ans = (h*w+1) / 2;
	if (h == 1 || w == 1) ans = 1;

	cout << ans;
	return 0;
}

Measured memory_bytes: 3624
n = [int(input()) for _ in range(5)]
nplus = [[0,10-n[i] % 10][n[i] % 10 != 0] for i in range(5)]
nm = max(nplus)
ans, mc = 0, 0
for i in range(5):
    if nplus[i] != nm:
        ans += nplus[i] + n[i]
    else:
        mc += 1

while mc:
    for i in range(5):
        if nplus[i] == nm:
            if mc != 1:
                ans += nplus[i] + n[i]
            else:
                ans += n[i]
            mc -= 1
print(ans)

Measured memory_bytes: 3064
#include<cstdio>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n,i;
  while(true){
    int num[500],max=0,min=100000000,sum=0;
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&num[i]);
      if(num[i]<min)
	min=num[i];
      if(num[i]>max)
	max=num[i];
    }
    for(i=0;i<n;i++)
      sum+=num[i];
    sum=sum-max-min;
    printf("%d\n",sum/(n-2));
  }
  return 0;
}



Measured memory_bytes: 2552
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <utility>

typedef long long ll;
typedef std::pair<int, int> pii;

#define mp std::make_pair

int n, k, ans[100005];
bool vis[100005];
int head[100005], next[100005 << 1], to[100005 << 1], ed = 0;
int deg[100005];

void AddEdge(int u, int v) {
	next[++ed] = head[u]; head[u] = ed; to[ed] = v;
}

pii dp[100005];

pii DP(int now, int fa, bool odd, int L, int R) {
	if (vis[now]) {
		if (ans[now] < L || ans[now] > R || (ans[now] & 1) != odd) {
			puts("No"); exit(0);
		}
		L = R = ans[now];
	}
	pii tmp;
	for (int i = head[now]; i; i = next[i]) {
		if (to[i] == fa) continue;
		tmp = DP(to[i], now, odd ^ 1, L - 1, R + 1);
		L = std::max(L, tmp.first - 1);
		R = std::min(R, tmp.second + 1);
		if (L > R) {
			puts("No"); exit(0);
		}
	}
	return dp[now] = mp(L, R);
}

void DFS(int now, int fa, int L, int R) {
	dp[now].first = std::max(dp[now].first, L);
	dp[now].second = std::min(dp[now].second, R);
	ans[now] = dp[now].first;
	for (int i = head[now]; i; i = next[i]) {
		if (to[i] == fa) continue;
		DFS(to[i], now, dp[now].first - 1, dp[now].second + 1);
	}
}

int main() {
	scanf("%d", &n);
	for (int u, v, i = 1; i < n; ++i) {
		scanf("%d%d", &u, &v);
		AddEdge(u, v);
		AddEdge(v, u);
		++deg[u]; ++deg[v];
	}
	scanf("%d", &k);
	int v, p;
	for (int i = 1; i <= k; ++i) {
		scanf("%d%d", &v, &p);
		ans[v] = p;
		vis[v] = 1;
	}

	DP(v, 0, p & 1, p, p);
	DFS(v, 0, p, p);

	puts("Yes");
	for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);

	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int N;
  cin >> N;
  long A[N];
  long ans=0;
  long b;
  rep(i,N) {
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A,A+N);
  rep(i,N) {
    int num=1;
    for(int j=i+1; j<N; j++){
      if(A[j]==A[i]) num++;
      else break;
    }
    if(i+num>=N-i-num){
      b = A[i];
      break;
    }
  }
  rep(i,N) ans += abs(A[i]-b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
n=int(input())
count=0
for i in range(n):
    a=int(input())
    flag=0
    if a==2:
        count+=1
        continue
    elif a<2 or a%2==0:
        continue
    for i in range(2,int(a**0.5)+1):
        if a%i==0:
            flag=1
            break
    if flag==0:
        count+=1
print(count)


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

template <typename monoid>
class segmentTree {
public:
  using M = monoid;
  using T = typename M::value_type;

  int sz;
  vector<T> x;

  segmentTree(int n = 1e5) {
    sz = 1; while(sz < n) sz *= 2;
    init();
  }
  void init() { x.assign(sz*2, M::id()); }

  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return M::id();
    if(a <= l && r <= b) return x[k];
    return M::f(query(a, b, 2*k+1, l, (l+r)/2),
                query(a, b, 2*k+2, (l+r)/2, r));
  }
  T query(int a, int b) {return query(a, b, 0, 0, sz);}
  // 点更新
  void update(int i, const T &val) {
    i += sz-1;
    x[i] = M::g(x[i], val);
    while(i > 0) {
      i = (i-1) / 2;
      x[i] = M::f(x[i*2+1], x[i*2+2]);
    }
  }
};

template <typename T>
struct min_monoid {
  using value_type = T;
  static constexpr T id() { return std::numeric_limits<T>::max(); }
  static T f(const T &a, const T &b) { return min(a, b); }
  static T g(const T &a, const T &b) { return a; }
};
template <typename T>
struct max_monoid {
  using value_type = T;
  static constexpr T id() { return std::numeric_limits<T>::min; }
  static T f(const T &a, const T &b) { return max(a, b); }
  static T g(const T &a, const T &b) { return a; }
};
template <typename T>
struct sum_monoid {
  using value_type = T;
  static constexpr T id() {return 0;}
  static T f(const T &a, const T &b) { return a+b; }
  static T g(const T &a, const T &b) { return a+b; }
};

template <typename T>
using rmq = segmentTree<min_monoid<T>>;
template <typename T>
using rsq = segmentTree<sum_monoid<T>>;

signed main() {
  int n, q;
  cin >> n >> q;
  rsq<int> seg(n);
  for(int i=0; i<q; ++i) {
    int c, x, y;
    cin >> c >> x >> y;
	  x--;
    if(c == 0) {
      seg.update(x, y);
    } else {
      cout << seg.query(x, y) << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3900
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, i = 0, c = 0;
    string s;
    scanf("%d", &n);
    for (; i < n; i++) {
        cin >> s;
        c += (s == "A") ? 1 : -1;
        
        if (c < 0) {
            printf("NO\n");
            return 0;
        }
    }
    if (c)
        printf("NO\n");
    else
        printf("YES\n");
    
    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm> 
#include <cmath> //pow

#define rep(i,n)  for(int (i) = 0; (i) < (n); (i)++)
#define rep1(i,n) for(int (i) = 1; (i) <= (n); (i)++)

using namespace std;

const int inf = 1 << 29;

int main(void) {
	int n, c;
	cin >> n >> c;

	vector<vector<int>> d(c,vector<int>(c,0));
	rep(i, c) rep(j,c) {
		cin >> d[i][j];
	}

	vector<vector<int>> field(n,vector<int>(n,0));
	rep(i, n) rep(j,n) {
		cin >> field[i][j];
		field[i][j]--;
	}

	vector<long long int> mod0(3,inf); 
	vector<int> mod0c(3,31);
	vector<long long int> mod1(3,inf);
	vector<int> mod1c(3,31);
	vector<long long int> mod2(3,inf);
	vector<int> mod2c(3,31);

	rep (col, c) {
		int cost0 = 0, cost1 = 0, cost2 = 0;

	  rep(i, n) rep(j, n) {
			switch ((i + j) % 3) {
			case 0: cost0 += d[field[i][j]][col]; break;
			case 1: cost1 += d[field[i][j]][col]; break;
			case 2: cost2 += d[field[i][j]][col]; break;
			}
		}
		
		rep(i, 3) if (cost0 < mod0[i]) { 
			for (int j = 1; j >= i; j--) {
				mod0[j + 1] = mod0[j];
				mod0c[j + 1] = mod0c[j];
			}
			mod0[i] = cost0;
			mod0c[i] = col;
			break;
		}

		rep(i, 3) if (cost1 < mod1[i]) {
			for (int j = 1; j >= i; j--) {
				mod1[j + 1] = mod1[j];
				mod1c[j + 1] = mod1c[j];
			}
			mod1[i] = cost1;
			mod1c[i] = col;
			break;
		}

		rep(i, 3) if (cost2 < mod2[i]) {
			for (int j = 1; j >= i; j--) {
				mod2[j + 1] = mod2[j];
				mod2c[j + 1] = mod2c[j];
			}
			mod2[i] = cost2;
			mod2c[i] = col;
			break;
		}
  }

	long long int ans = inf;
	rep(i0, 3) rep(i1, 3) rep(i2, 3) {
		if (mod0c[i0] == mod1c[i1] || mod1c[i1] == mod2c[i2] || mod0c[i0] == mod2c[i2]) continue;

		ans = min(ans, mod0[i0] + mod1[i1] + mod2[i2]);
	}

  cout << ans << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin >> p[i];

    int count = 1;
    int min = p[0];
    for(int i=1; i<n; i++) {
        if(p[i] < min) {
            count++;
            min = p[i];
        }
    }
    
    cout << count << endl;
    

    return 0;
}


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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define REP(i,n) for(ll i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vi p(a), q(b), r(c);
  rep(i,a) cin >> p[i];
  rep(i,b) cin >> q[i];
  rep(i,c) cin >> r[i];
  sort(rall(p));
  sort(rall(q));
  sort(rall(r));
  vi v(x+y+c);
  rep(i,x) v.push_back(p[i]); 
  rep(i,y) v.push_back(q[i]); 
  rep(i,c) v.push_back(r[i]); 
  sort(rall(v));
  ll ans = 0;
  rep(i, x+y){
    ans += v[i];
  }
  cout << ans << endl;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] num = new int[n];
        Arrays.fill(num, -1);
        for (int i = 0; i < m; i++) {
            int s = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());
            if (s == 1 && c == 0 && n != 1) {
                System.out.println(-1);
                return;
            }
            if (num[s - 1] != -1 && num[s - 1] != c) {
                System.out.println(-1);
                return;
            }
            num[s - 1] = c;
        }
        for (int i = 0; i < n; i++) {
            if (i == 0 && num[i] == -1) {
                if (n > 1) {
                    num[i] = 1;
                } else {
                    num[i] = 0;
                }
            } else if (num[i] == -1) {
                num[i] = 0;
            }
        }
        for (int ans : num) {
            System.out.print(ans);
        }
        System.out.println();
    }
}

Measured memory_bytes: 23636
#!/usr/bin/env python3

import sys

def main():
    sys.setrecursionlimit(10 ** 6)
    n = int(input())
    adjs = [[] for i in range(n)]
    for i in range(n - 1):
        u, v, w = map(int, input().split())
        adjs[u - 1].append((v - 1, w))
        adjs[v - 1].append((u - 1, w))
    colors = [None for i in range(n)]
    colors[0] = 0
    dfs(0, adjs, -1, colors)
    for i in range(n):
        print(colors[i])

def dfs(i, adjs, p, colors):
    for v, w in adjs[i]:
        if v == p:
            continue
        colors[v] = (colors[i] + w) % 2
        dfs(v, adjs, i, colors)

if __name__ == "__main__":
    main()


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll a,b;
	cin >> a >> b;
	cout << a*b << " " << 2*a+2*b << endl;
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
using namespace std;
int main()
{
  long long n,a,b;
  cin >> n >> a >> b;
 
  long long x[n + 1];
 
  for (int i = 1; i <= n; i++)
    cin >> x[i];
  
  long long sum = 0;
 
  for (int i = 1; i < n; i++) {
    int dis = x[i + 1] - x[i];
    if (dis * a < b)
      sum += dis * a;
    else
      sum += b;
  }
 
  cout << sum << endl;
 
  return 0;
}

Measured memory_bytes: 1024
k = gets.to_i

k_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

puts k_list[k-1]

Measured memory_bytes: 1788
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a == b && b == c || a != b && b != c && a!= c) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}

	return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


int n, k;
int p[5000];
int c[5000];



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

	cin >> n >> k;
	rep(i, n)cin >> p[i], p[i]--;
	rep(i, n)cin >> c[i];

	long long ans = *max_element(c, c + n);

	rep(i, n) {
		unordered_map<int, pair<int, long long>> vis;
		vis.reserve(n);
		int cur = i;
		long long s = 0;
			
		rep(j, min(2 * n, k)) {
			s += c[cur];
			cur = p[cur];

			ans = max(ans, s);

			auto it = vis.find(cur);
			if (it != vis.end()) {
				int cyc = j - it->second.first;
				long long cycs = s - it->second.second;

				ans = max(ans, s + (k - j - 1) / cyc * cycs);
			}
			vis[cur] = make_pair(j, s);
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 3952
#include<stdio.h>
int main(){
  int m,f,r;
  while(1){
    scanf("%d %d %d", &m, &f, &r);
    if(m == -1 && f == -1 && r == -1)
      break;
    if(m == -1 | f == -1)
      puts("F");
    else if(m+f >= 80)
      puts("A");
    else if(m+f >= 65)
      puts("B");
    else if(m+f >= 50)
      puts("C");
    else if(m+f >= 30 && r >= 50)
      puts("C");
    else if(m+f >= 30)
      puts("D");
    else if(m+f < 30)
      puts("F");
  }
  return 0;
}


Measured memory_bytes: 2028
s=list(input())
n=len(s)
n_cnt,w_cnt,s_cnt,e_cnt=0,0,0,0
for i in range(n):
    if s[i]=="N":
        n_cnt=1
    elif s[i]=="W":
        w_cnt=1
    elif s[i]=="S":
        s_cnt=1
    elif s[i]=="E":
        e_cnt=1
if n_cnt+w_cnt+s_cnt+e_cnt==4:
    print("Yes")
elif n_cnt+s_cnt==2 and w_cnt+e_cnt==0:
    print("Yes")
elif e_cnt+w_cnt==2 and n_cnt+s_cnt==0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
/*
{
######################
#       Author       #
#        Gary        #
#        2020        #
######################
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MAXN=100000+20;
int fa[MAXN];
int n;
int root(int x){
	return fa[x]=(fa[x]==x? x:root(fa[x]));
}
int main(){
	fastio;
	R(n);
	rb(i,1,n) fa[i]=i;
	int m;
	R(m);
	rb(i,1,m){
		int u,v;
		R2(u,v);
		fa[root(u)]=root(v); 
	}
	int rest=-1;
	rb(i,1,n){
		if(root(i)==i) rest++;
	}
	cout<<rest<<endl;
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/


Measured memory_bytes: 3956