akhauriyash/Code-Regression huggingface dataset:
class MaxPQ:
    def __init__(self):
        self.q = []

    def insert(self, x):
        self.q.append(x)
        self.swim(len(self.q)-1)

    def get_max(self):
        if len(self.q) > 0:
            return self.q[0]
        else:
            return None

    def delete_max(self):
        if len(self.q) == 0:
            return

        val = self.q.pop()
        if len(self.q) > 0:
            self.q[0] = val
            self.sink(0)

    def sink(self, i):
        c1 = (i + 1) * 2 - 1
        c2 = (i + 1) * 2
        size = len(self.q)
        if c1 >= size:
            pass
        elif c1 < size and c2 >= size:
            if self.q[c1] > self.q[i]:
                self.q[c1], self.q[i] = self.q[i], self.q[c1]
                self.sink(c1)
        elif self.q[c1] > self.q[c2]:
            if self.q[c1] > self.q[i]:
                self.q[c1], self.q[i] = self.q[i], self.q[c1]
                self.sink(c1)
        else:
            if self.q[c2] > self.q[i]:
                self.q[c2], self.q[i] = self.q[i], self.q[c2]
                self.sink(c2)

    def swim(self, i):
        p = (i+1) // 2 - 1
        if p >= 0:
            if self.q[p] < self.q[i]:
                self.q[p], self.q[i] = self.q[i], self.q[p]
                self.swim(p)


def run():
    n, q = [int(x) for x in input().split()]
    pqs = [MaxPQ() for _ in range(n)]

    for _ in range(q):
        com = [int(x) for x in input().split()]
        c = com[0]
        if c == 0:
            t, v = com[1:]
            pqs[t].insert(v)
        elif c == 1:
            t = com[1]
            val = pqs[t].get_max()
            if val is not None:
                print(val)
        elif c == 2:
            t = com[1]
            pqs[t].delete_max()
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



Measured memory_bytes: 13352
n, = (int(x) for x in input().split())
vi_arr = [int(x) for x in input().split()]
odd_dict = {"a":0}
even_dict = {"a":0}
for i, vi in enumerate(vi_arr):
    if i%2 == 0:
        idict = odd_dict
    else:
        idict = even_dict
    idict.setdefault(vi, 0)
    idict[vi] += 1

odd_hist = sorted(odd_dict.items(), key=lambda x:x[1], reverse=True)
even_hist = sorted(even_dict.items(), key=lambda x:x[1], reverse=True)

max_odd = odd_hist[0][1]
max_even = even_hist[0][1]
if odd_hist[0][0] == even_hist[0][0]:
    if odd_hist[0][1]+even_hist[1][1] > even_hist[0][1]+odd_hist[1][1]:
        max_even = even_hist[1][1]
    else:
        max_odd = odd_hist[1][1]

print(len(vi_arr)-max_odd-max_even)


Measured memory_bytes: 20764
a, b, c = map(int, input().split())

if a % 2 == 0 or b % 2 == 0 or c % 2 == 0:
    print(0)
else:
    k1 = a*b
    k2 = b*c
    k3 = c*a
    print(min(k1, k2, k3))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d1=0,d2=0,d3=0,d4=0;
  	string s;
  	cin >> n;
    for(int i=1;i<=n;i++)
    {
    	cin >> s;
      if(s=="AC") d1++;
      if(s=="WA") d2++;
      if(s=="TLE") d3++;
      if(s=="RE") d4++;
    }
  	cout << "AC x " << d1 <<  endl;
  cout << "WA x " << d2 << endl;
  cout << "TLE x " << d3 << endl;
  cout << "RE x " << d4 << endl;
 
}

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

using namespace std;

vector<int> get_divisors (int n) {
  vector<int> v;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      int I = n / i;

      v.push_back(i);
      if (i != I) v.push_back(I);
    }
  }
  return v;
}

int main () {
  int x, y, K;
  cin >> x >> y >> K;

  int A = min(x, y);
  int B = max(x, y);
  vector<int> divisors = get_divisors(A);
  vector<int> common_divisors;

  copy_if(divisors.begin(), divisors.end(), back_inserter(common_divisors), [&](int x) {
    return B % x == 0;
  });
  sort(common_divisors.begin(), common_divisors.end(), greater<int>());

  cout << common_divisors.at(K - 1) << "\n";
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
	
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream outputStream = System.out;
    	PrintWriter out = new PrintWriter(outputStream);

        int i, n, m, c, k;

		int t = Integer.parseInt(br.readLine());    
        StringTokenizer st = new StringTokenizer(br.readLine());
    
      	double sum=0;
		for(i=0;i<t;i++){
          double ar=Double.parseDouble(st.nextToken());
          sum+=1/ar;
          
        }
      	
      	//sum=power(sum,mod-2)%mod;
      out.print(1/sum);
	out.flush();
	out.close();
	
	}
}

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

int main(){
    int N, K, R, S, P;

    scanf("%d%d%d%d%d", &N, &K, &R, &S, &P);

    char *T = (char *) malloc(sizeof(char) * (N + 1));

    scanf("%s", T);

    int score = 0;

    for(int i = 0; i < K; i ++){
        int flg = 0;

        for(int j = i; j < N; j += K){
            if(j < K){
                if(T[j] == 'r'){
                    score += P;
                }else if(T[j] == 's'){
                    score += R;
                }else{
                    score += S;
                }
            }else if(flg == 0){
                if(T[j - K] == T[j]){
                    flg = 1;
                }else{
                    if(T[j] == 'r'){
                    score += P;
                }else if(T[j] == 's'){
                    score += R;
                }else{
                    score += S;
                }
                }
            }else{
                if(T[j] == 'r'){
                    score += P;
                }else if(T[j] == 's'){
                    score += R;
                }else{
                    score += S;
                }
                flg = 0;
            }
        }
    }
    printf("%d\n", score);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	public void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n+1];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 1; i <= n ;i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		reader.close();
		
		for (int i = n / 2 + 1; i >= 1; i--) {
			maxHeapify(i, n, a);
		}
		
		for (int i = 1; i <= n; i++) {
			System.out.print(" " + a[i]);
		}
		System.out.println();
	}

	private void maxHeapify(int cur, int n, int[] a) {
		
		int l = cur * 2;
		int r = l + 1;
		int max = cur;
		if (l <= n && a[max] < a[l]) {
			max = l;
		}
		if (r <= n && a[max] < a[r]) {
			max = r;
		}
		if (max != cur) {
			int tmp = a[max];
			a[max] = a[cur];
			a[cur] = tmp;
			maxHeapify(max, n , a);
		}
	}
}


Measured memory_bytes: 84544
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ve vector
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())
//using namespace __gnu_pbds;
using namespace std;

// // // functions: find_by_order  & order_of_key
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

const int inf=(int)2e9;
const long long mod=1000000007; //1E9+7
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll mdinv(ll a){return powmod(a,mod-2); }

int DP[10004][102][2];
string s; //reverse
int d;
int sol(int i,int r,int less){
	if(i<0) return r==0;
	if(DP[i][r][less]!=-1) return DP[i][r][less];
	int h=s[i]-'0';
	int ans=0;
	forn(x,10){
		if(less==0 && x>h) break;
		int nr=r+x;nr%=d;
		ans+=sol(i-1,nr,less|(x<h));
		if(ans>=mod) ans-=mod;
	}
	return DP[i][r][less]=ans;
}

signed main(){
	IOS
	cin>>s;reverse(all(s));
	cin>>d;
	memset(DP,-1,sizeof(DP));
	cout<<(((sol(sz(s)-1,0,0)-1)%mod+mod)%mod);
}


Measured memory_bytes: 17024
from collections import Counter
N = int(input())
S = list(input())
dic = Counter(S)
dic2 = {"R":0,"G":0,"B":0}
ans = 0
for i in range(N-2):
    RGB = {"R","G","B"} - {S[i]}
    dic2[S[i]]+=1
    dic3 = {"R":0,"G":0,"B":0}
    for j in range(i+1,N-1):
        dic3[S[j]]+=1
        if len(RGB - {S[j]})!=1:
            continue
        else:
            target = list(RGB - {S[j]})[0]
            ans+=dic[target]-dic2[target]-dic3[target]
            if((j - i)+ j <= N -1):
                if(S[(j - i)+ j] == target):
                    ans-=1
print(ans)


Measured memory_bytes: 70144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
	int N = 0;
	std::string ans;
	std::cin >> N;

	std::vector<int> P(N), S(N);
	for (int i = 0; i < N; i++){
		std::cin >> P[i];
	}

	S = P;
	std::sort(P.begin(), P.end());
	int chk = 0;
	for (int i = 0; i < N; i++){
		chk += (S[i] == P[i]) ? 0 : 1;
	}

	if (chk == 0 || chk == 2){
		ans = "YES";
	}
	else
	{
		ans = "NO";
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MIN(a, b) ((a < b) ? a : b)
#define MAX(a, b) ((a < b) ? b : a)
#define LL long long

LL min1(int h, int w) { // h >= 3の場合のみ有効
    int h1, h2;
    LL min, max, s1, s2, s3, dif_min;
    dif_min = (LL)h*w;
    for(h1 = 1; h1 < h-1; ++h1) {
        h2 = (LL)(h - h1)/2;
        s1 = (LL)h1 * w;
        s2 = (LL)h2*w;
        s3 = (LL)(h - h1 - h2) * w;
        max = MAX(MAX(s1, s2), s3);
        min = MIN(MIN(s1, s2), s3);
        dif_min = MIN(dif_min, max - min);
        
    }
    return dif_min;
}

LL min2(int h, int w) { //h >= 2 かつw >=2の場合のみ有効
    int h1, w1;
    LL min, max, s1, s2, s3, dif_min;
    dif_min = (LL)h * w;
    for(h1 = 1; h1 < h; ++h1) {
        w1 = w / 2;
        s1 = (LL)h1 * w;
        s2 = (LL)(h - h1) * w1;
        s3 = (LL)(h - h1) * (w - w1);
        max = MAX(MAX(s1, s2), s3);
        min = MIN(MIN(s1, s2), s3);
        dif_min = MIN(dif_min, max - min);
    }
    return dif_min;
}

void solve(int h, int w) {
    LL  dif1 = (h >= 3)? min1(h, w) : (LL)h*w,
        dif2 = min2(h, w),
        dif3 = (h >= 3)? min1(w, h) : (LL)h*w,
        dif4 = min2(w, h),
        min;
    //LL test = (LL)h * w; printf("test : %lld\n", test);
    //printf("dif1; %lld dif2: %lld dif3: %lld dif4: %lld\n", dif1, dif2, dif3, dif4);
    min = MIN(dif1, dif2);
    min = MIN(dif3, min);
    min = MIN(dif4, min);
    printf("%lld\n", min);
}

int main(void)
{
    int h, w;
    scanf("%d %d", &h, &w);
    solve(h, w);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

int main(void) {
	int N;
	std::vector <int> L;
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		int l;
		std::cin >> l;
		L.push_back(l);
	}

	long long ans = 0;
	std::sort(L.begin(), L.end());
	for (int i = 0; i <= L.size()-3; i++) {
		for (int j = i+1; j <= L.size()-2; j++) {
			int a = L[i];
			int b = L[j];
			int ab = a+b;

			int cminpos = j+1;
			int cmaxpos = L.size()-1;
			int cmidpos;

			while (cminpos <= cmaxpos) {
				cmidpos = (cminpos+cmaxpos+1)/2;
				if (ab > L[cmidpos]) {
					if (cmidpos>=cmaxpos) break;
					cminpos = cmidpos;
				} else {
					cmaxpos = cmidpos-1;
				}
			}
			ans += std::max(0, cmaxpos-j);
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(a-1); i>=(b); i--)
#define qrep(i, q) for(auto i : q)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 100005;
const int logn = (log(maxn)/log(2))+5;
const int inf = 0x3f3f3f3f;
const ld eps = 1e-9;
ll a[maxn];
int main()
{
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	int n;
	cin >> n;
	rep(i, 1, n+2) cin >> a[i];
	ll ans = 0;
	rep(i, 1, n+1) {
		int x;
		cin >> x;
		if(x >= a[i]) ans += a[i], x -= a[i];
		else ans += x, x = 0;
		if(x >= a[i+1]) ans += a[i+1], a[i+1] = 0;
		else ans += x, a[i+1] -= x;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
s = input()
K = int(input())

l = []

for i in range(len(s)):
    l.append(s[i:])

l.sort()
m={l[0][0]}

for x in l:
    for i in range(len(x)):
        m.add(x[:i+1])
        if len(m)>=5:
            break
    if len(m)>=5:
        break

m=list(m)
m.sort()

print(m[K-1])

Measured memory_bytes: 15604
use proconio::*;

// ナップザック？
// 死ぬ
//
// アイテムはlog N 程度 <= 18
// 半分全列挙？
// 各クエリ2^9 程度で処理できればOKだが
//
// 2^18 = 2.6*10^5
//
// 実装スッキリしない

#[fastout]
fn run() {
    input! {
        n: usize,
        mut item: [(u32, i32); n],
        q: usize,
        ask: [(usize, i32); q],
    }
    item.insert(0, (0, 0));
    let calc = |v: usize| -> (usize, Vec<(u32, i32)>) {
        let mut dp = vec![(0, 0)];
        let mut pos = v;
        while pos >= 1 && dp.len() < (1 << 9) {
            let (v, w) = item[pos];
            pos /= 2;
            let mut a = vec![];
            for &(p, q) in dp.iter() {
                a.push((p + v, q + w));
            }
            let mut next = vec![];
            while a.len() > 0 && dp.len() > 0 {
                let (_, q) = *a.last().unwrap();
                let (_, s) = *dp.last().unwrap();
                if q >= s {
                    next.push(a.pop().unwrap());
                } else {
                    next.push(dp.pop().unwrap());
                }
            }
            while let Some(p) = dp.pop() {
                next.push(p);
            }
            while let Some(p) = a.pop() {
                next.push(p);
            }
            next.reverse();
            dp = next;
        }
        let mut v = 0;
        for i in 0..dp.len()  {
            v = std::cmp::max(v, dp[i].0);
            dp[i].0 = v;
        }
        (pos, dp)
    };
    for (start, width) in ask {
        let (v, dp) = calc(start);
        let ans = if v >= 1 {
            let p = calc(v).1;
            let mut ans = 0;
            let mut i = 0;
            let mut j = p.len();
            while i < dp.len() && j > 0 {
                if dp[i].1 + p[j - 1].1 <= width {
                    ans = std::cmp::max(ans, dp[i].0 + p[j - 1].0);
                    i += 1;
                } else {
                    j -= 1;
                }
            }
            ans
        } else {
            let mut ans = 0;
            for (v, w) in dp {
                if w <=  width {
                    ans = std::cmp::max(v, ans);
                }
            }
            ans
        };
        println!("{}", ans);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 10152
//agc011_a.cpp
//Sat Oct 27 12:01:46 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int busnum = 0;
	int firsttime = 0;
	int guestcount = 0;

	int t[n];
	for (int i=0;i<n;i++){
		cin >> t[i];
	}
	sort(t,t+n);

	for (int i=0;i<n;i++){
		guestcount++;
		int temp = t[i];
		if (guestcount > c){
			busnum++;
			guestcount = 1;
			firsttime = temp;
		}else if (firsttime == 0){
			firsttime = temp;
		}else if (temp-firsttime > k){
			busnum++;
			guestcount = 1;
			firsttime = temp;
		}
	}

	if (guestcount != 0){
		busnum++;
	}

	cout << busnum << endl;
}

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

using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a>0){
		cout<<"Positive";
	}
	else if(a==0){
		cout<<"Zero";
	}
	else if(b==0){
		cout<<"Zero";
	}
	else if(b<0 && a<0){
		if(abs(a-b-1)%2==0){
			cout<<"Positive";
		}
		else {
			cout<<"Negative";
		}
	}
	else if(b>0 && a<0){
		cout<<"Zero";
	}
}

Measured memory_bytes: 256
n, k = map(int, input().split())
hoge = input().split()

def check(num):
    for i in range(k):
        if num.find(hoge[i]) >= 0:
            return False
    return True

result = n
while(True):
    if check(str(result)):
        break
    result += 1
print(result)



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

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a < 10 && b < 10 ? a*b : -1) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=1e5+5;
int n,m,k,sb[N],odr[N],deg[N],co,par[N],ans,s;
bool use[N],euse[20],vuse[N],isans;
vector<int> v,g[N],g2[N];
vector<P> edge;
int ufp[N];
int fi(int x)
{
    if(ufp[x]==x) return x;
    return ufp[x]=fi(ufp[x]);
}
void un(int x,int y)
{
    x=fi(x); y=fi(y);
    if(x!=y) ufp[y]=x;
}
//dfs 트리 만들면서 back edge 저장
void dfs(int x,int p)
{
    odr[x]=++co;
    for(auto &it : g[x]){
        if(it==p) continue;
        if(odr[it]&&odr[it]<odr[x]){
            edge.push_back(P(x,it));
            use[x]=use[it]=true;
            continue;
        }
        if(odr[it]) continue;
        dfs(it,x);
    }
}
// dfs 트리 tree edge들 압축 후 저장
void dfs_dcp(int x,int p)
{
    odr[x]=1;
    vector<int> v;
    sb[x]=use[x];
    for(auto &it : g[x]){
        if(it==p) continue;
        if(odr[it])
            continue;
        dfs_dcp(it,x);
        if(sb[it]) v.push_back(it);
        sb[x]+=sb[it];
    }
    if(v.size()>=2) use[x]=true;
}
void dfs_dcp2(int x,int p,int pp)
{
    odr[x]=1;
    if(use[x]){
        if(pp){
            g2[pp].push_back(x);
            par[x]=pp;
        }
        v.push_back(x);
        pp=x;
    }
    for(auto &it : g[x]){
        if(it==p) continue;
        if(odr[it])
            continue;
        dfs_dcp2(it,x,pp);
    }
}
void dfs_chk(int x)
{
    for(auto &it : g2[x])
        dfs_chk(it);
    if(deg[x]>=3) isans=false;
    if(deg[x]==1){
        if(x==1) isans=false;
        else{
            deg[x]++;
            deg[par[x]]++;
            un(x,par[x]);
            vuse[x]=vuse[par[x]]=true;
        }
    }
}
void backtrack(int curr)
{
    if(curr==k){
        for(auto &it : v) deg[it]=vuse[it]=0;
        for(auto &it : v) ufp[it]=it;
        for(int i=0;i<k;i++) if(euse[i]){
            deg[edge[i].first]++;
            deg[edge[i].second]++;
            vuse[edge[i].first]=vuse[edge[i].second]=true;
            un(edge[i].first,edge[i].second);
        }
        isans=true;
        dfs_chk(1);
        int cv=0;
        for(auto &it : v) if(it==fi(it)&&vuse[it]) cv++;
        if(isans&&cv==1) ans++;
        return;
    }
    euse[curr]=1;
    backtrack(curr+1);
    euse[curr]=0;
    backtrack(curr+1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int u,v,i=1;i<=m;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    if(m==n-1){
        cout<<0<<endl;
        return 0;
    }
    dfs(1,0);
    use[1]=true;
    k=edge.size();/*
    cout<<k<<endl;
    for(auto &it : edge)
        cout<<it.first<<" "<<it.second<<endl;*/
    for(int i=1;i<=n;i++) odr[i]=0;
    dfs_dcp(1,0);
    for(int i=1;i<=n;i++) odr[i]=0;
    dfs_dcp2(1,0,0);
    /*
    for(int i=1;i<=n;i++)
        cout<<i<<" : "<<use[i]<<endl;
    cout<<v.size()<<endl;
    for(auto &it : v)
        cout<<it<<" ";
    cout<<endl;*/
    backtrack(0);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 20056
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAx = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAx, min_index = -1;

typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
    cin >> N;
    vector<pair<string, int>> vec;
    string s;
    rep(i, N){
        cin >> s >> T;
        vec.push_back(make_pair(s, T));
    }
    cin >> s;
    bool flag = true;
    ll sum = 0;
    rep(i, N){
        if(vec[i].first == s){
            flag = false;
            continue;
        }
        if(!flag) sum += vec[i].second;
    }
    cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 2018;
const int SZ = N * N / 2;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n;
    cin >> n;
    bitset<SZ> can;
    can[0] = 1;
    int sum = 0;
    forn(i, 0, n) {
        int x;
        cin >> x;
        sum += x;
        can |= (can << x);
    }
    for (int i = (sum + 1) / 2;; ++i)
        if (can[i]) {
            cout << i << '\n';
            return 0;
        }
}


Measured memory_bytes: 1024
import java.util.Scanner;

//Baby Tree
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m)==0)break;
			double[][] t = new double[n][n];
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)t[i][j]=sc.nextDouble();
			double[][] dp = new double[m][n];
			for(int i=0;i<n;i++)dp[0][i]=1;
			for(int i=1;i<m;i++){
				for(int j=0;j<n;j++){
					for(int k=0;k<n;k++){
						dp[i][j] = Math.max(dp[i][j], dp[i-1][k]*t[k][j]);
					}
				}
			}
			double a = 0;
			for(int i=0;i<n;i++)a=Math.max(a, dp[m-1][i]);
			System.out.printf("%.2f\n", a);
		}
	}
}

Measured memory_bytes: 13000
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;
  long long lcm = c * d / gcd(c, d);

  cout << ((b + (long long)(b / lcm) - (long long)(b / c) - (long long)(b / d)) -
             (a+  (long long)(a / lcm) - (long long)(a / c) - (long long)(a / d)))
       << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);

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

  int MAX, MIN;
  MAX = *max_element(A.begin(), A.end());
  MIN = *min_element(A.begin(), A.end());

  cout << MAX-MIN << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 505

struct Info{
	int cost,start_time,span;
};

int N;
Info info[NUM];


int main(){

	scanf("%d",&N);

	for(int i = 0; i < N-1; i++){

		scanf("%d %d %d",&info[i].cost,&info[i].start_time,&info[i].span);
	}

	int current_time,tmp_index;

	for(int index = 0; index < N-1; index++){

		current_time = info[index].start_time+info[index].cost;
		tmp_index = index+1;

		while(tmp_index < N-1){

			if(current_time < info[tmp_index].start_time){

				current_time = info[tmp_index].start_time+info[tmp_index].cost;

			}else{

				//current_timeより大きい、(info[tmp_index].spanの最小の倍数を見つける)

				if(current_time%info[tmp_index].span == 0){ //ちょうど出発

					current_time += info[tmp_index].cost;

				}else{

					current_time = info[tmp_index].span*((current_time/info[tmp_index].span)+1)+info[tmp_index].cost;
				}
			}

			tmp_index++;
		}

		printf("%d\n",current_time);
	}

	printf("0\n");

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e2+7, M = 8;

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	printf("%s\n", (n+1)/2 >= k ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define space ' '

inline void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main(void) {
  int r, g, b;
  cin >> r >> g >> b;
  r = r * 100 + g * 10 + b;
  if (r % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl; 
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    string S; cin >> S;
    int n(S.length());
  /*  VI dp(n+1, 0);
    dp[1] = 1;
    if(n > 1) dp[2] = (S[0]!=S[1]) + 1;
    FORS(i, 3, n){
        if(S[i-2] != S[i-1]) dp[i] = dp[i-1] + 1;
        else dp[i] = dp[i-3] + 2;
    }
    cout << dp[n] << endl;
    */
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    ll a = 0, b = 1, c = 1;
    if(S[0] != S[1]) ++c;
    FOR(i, 2, n){
        int d = ((S[i-1]!=S[i]) ? c+1 : a+2);
    a = b;
    b = c;
    c = d;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 640
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int is(char c){
    char keys[]={'q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'};
    rep(i,15){
        if(c==keys[i])return 0;
    }
    return 1;
    
}


int main(){
    string s;
    while(cin>>s){
        if(s=="#")break;
        int c=0;
        int now=-1;
        rep(i,s.sz){
            if(now==-1){
                now=is(s[i]);
            }
            else{
                if(now!=is(s[i]))c++;
                now=is(s[i]);
            }
        }
        cout<<c<<endl;
        
    }
    
    
    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
using namespace std;
int a[9], b, sum, mx;
int main() {
	for(int i=0; i<5; i++) {
		cin>>a[i];
		b = (a[i]+9) / 10 * 10;
		sum += b;
		mx = max(mx, b - a[i]);
	}
	cout<<sum - mx;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
num_list = list(map(int, input().split()))

flag = 0

for num in num_list:
    if ((num % 2) == 0) and (((num % 3) > 0) and ((num % 5) > 0)):
        flag = 1
        break

if flag == 1:
    print('DENIED')
else:
    print('APPROVED')


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

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> dp(n);
    for (int i = 1; i < n; i++)
    {
        dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
        if (i > 1)
            dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
 
int main(){
 int N,W;
 cin>>N>>W;
 
 int v[N],w[N];
 
 for(int i=0;i<N;i++){
    cin>>v[i]>>w[i];
 }
 
 int DP[N+1][W+1];
 
 for(int j=0;j<=W;j++){
    DP[0][j]=0;
 }
 
 for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
        if(j<w[i-1]){
            DP[i][j]=DP[i-1][j];
        }else{
            if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1]){
                DP[i][j]=DP[i-1][j];
            }else{
                DP[i][j]=DP[i][j-w[i-1]]+v[i-1];
            }
        }
    }
 }
 cout<<DP[N][W]<<endl;
return 0;
}

Measured memory_bytes: 7012
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll a,b,c,d;cin>>a>>b>>c>>d;
  if(a*b<=c*d){
    P(c*d);
  }else{
    P(a*b);
  }
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
p=list(map(int,input().split()))
ps=[]
for i in range(n):
    ps.append((p[i],i))
ps.sort()
s=1
for i in range(n):
    print(s+ps[i][1],end='')
    print(' ',end='')
    s=s+30000
print('')
s=1+30000*(n-1)
for i in range(n):
    print(s,end='')
    print(' ',end='')
    s=s-30000




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

string dp[10001];
int num[10] = {0,2,5,5,4,5,6,3,7,6};

bool cmp(string a, string b)
{
	if(a.length()==b.length())
	{
		return a > b;
	}
	return a.length() > b.length();
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,m,t;
	vector <int> v;

	cin >> n >> m;

	for(int i=0;i<m;i++)
	{
		cin >> t;
		v.push_back(t);
		if(dp[num[t]].length()==0)
		{
			dp[num[t]] += (char)(t+'0');
		}
		else
		{
			string s;
			s+=(char)(t+'0');
			if(cmp(s,dp[num[t]])==1)
			{
				dp[num[t]] = s;
			}
		}
	}

	for(int i=1;i<=n;i++)
	{
		if(dp[i].length()==0)
		{
			continue;
		}
		for(int j=0;j<m;j++)
		{
			int x = num[v[j]];
			if(i+x<=n)
			{
				string s = dp[i] + (char)(v[j]+'0');
				//cout << dp[i] << ' ' << dp[i+x] << ' ' << i << ' ' << i+x << '\n';
				if(cmp(s,dp[i+x])==1)
				{
					dp[i+x] = s;
				}
				//cout << dp[i] << ' ' << dp[i+x] << ' ' << i << ' ' << i+x << '\n';
			}
		}
	}

	/*
	for(int i=0;i<=n;i++)
	{
		cout << dp[i] << '\n';
	}
	*/
	cout << dp[n] << '\n';
	return 0;
}

Measured memory_bytes: 43648
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define x first
#define y second
#define pb(a) push_back(a)

const int N = 2010;

int n, a[N], d[N];
struct edge{ int to, pre; } e[(N * N) << 1]; int u[N], l = 0;
void ins(int a, int b) { e[++l] = (edge){b, u[a]}, u[a] = l; d[b]++; }
#define v e[i].to
#define reg(i,a) for(int i = u[a]; i; i = e[i].pre)

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

typedef pair<int, int> pii;
#define mp(a,b) make_pair(a,b)
priority_queue<pii> q;
void topsort() {
	rep(i,1,n) if (!d[i]) q.push(mp(a[i], i));
	while (!q.empty()) {
		int x = q.top().second; q.pop(); printf("%d ",a[x]);
		reg(i,x) {
			d[v]--;
			if (!d[v]) q.push(mp(a[v], v));
		}
	}
	printf("\n");
}

int c[N][N]; bool vis[N];
void dfs(int x) {
	vis[x] = true;
	vector<pii> ch;
	rep(i,1,n) if (c[x][i] && !vis[i]) ins(x, i), dfs(i);
}

void build() {
	sort(a + 1, a + n + 1);
	rep(i,1,n) rep(j,1,n) c[i][j] = (gcd(a[i], a[j]) > 1);
	rep(i,1,n) if (!vis[i]) dfs(i);
}

int main() {
	scanf("%d",&n);
	rep(i,1,n) scanf("%d", a + i);
	build();
	topsort();
	return 0;
}

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

using namespace std;

int ans = -INT_MAX, n, p[100][11];
bool f[100][10];

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i) for(int j = 0; j < 10; ++j) cin >> f[i][j];
	for(int i = 0; i < n; ++i) for(int j = 0; j <= 10; ++j) cin >> p[i][j];

	for(int b = 1; b < (1<<10); ++b){
		bitset<10> bit = b;
		int benefit = 0;
		for(int i = 0; i < n; ++i){
			int d = 0;
			for(int j = 0; j < 10; ++j) if(bit[9-j]&&f[i][j]) d++;
			benefit += p[i][d];
		}
		ans = max(ans, benefit);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as B
import Data.Bits
import Data.Char

type Open = V.Vector (V.Vector Int)
type Prof = V.Vector (V.Vector Int)
type BitV = V.Vector Int
type OP = (V.Vector Int, V.Vector Int)

toBitV :: Int -> Int -> BitV
toBitV n l
    | l == 0 = V.empty
    | otherwise = V.snoc (toBitV (shiftR n 1) (l - 1)) (n .&. 1)

solve :: Open -> Prof -> BitV -> Int
solve open prof bitv = loop
    where
        zss :: V.Vector OP
        zss = V.zip open prof
        loop :: Int
        loop = V.foldl' step 0 zss
        step :: Int -> OP -> Int
        step acc (op, pf) = acc + (pf V.! l)
            where
                l = V.length $ V.filter (==1) $ V.zipWith (*) op bitv

main = do
    n <- readLn :: IO Int
    fss <- V.replicateM n $ do
        xs <- V.unfoldrN 10 (B.readInt . B.dropWhile isSpace) <$> B.getLine
        return xs
    pss <- V.replicateM n $ do
        xs <- V.unfoldrN 11 (B.readInt . B.dropWhile isSpace) <$> B.getLine
        return xs
    print $ maximum $  [solve fss pss (toBitV i 10) | i <- [1..2^10-1]]

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

int main(){
    int i = 0;
    while(i <= 20010){
        int x,y;
        char op;
        cin >> x >> op >> y;
        if(op == '+') printf("%d\n",x+y);
        if(op == '-') printf("%d\n",x-y);
        if(op == '*') printf("%d\n",x*y);
        if(op == '/') printf("%d\n",x/y);
        if(op == '?') break;
        i++;
    }
    return 0;
}


Measured memory_bytes: 3232
#include<iostream>
using namespace std;
int main(){
	int X;
	cin >> X;
	int A=0;
	int B=0;
	A=X/100;
	B=X%100;
	if(A*5>=B){
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}

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

typedef pair<string, int> P;

bool compare(P s1, P s2){
  if(s1.first.size() < s2.first.size()) return true;
  else if(s1.first.size() > s2.first.size()) return false;
  
  else{
    for(int i = 0 ; i < s1.first.size() ; i++){
      if(s1.first[i] < s2.first[i]) return true;
      else if(s1.first[i] > s2.first[i]) return false;
    }
  }
}

int main(){
  map<string, int> data;
  vector<P> ans;
  
  int n;
  cin >> n;
  string s;
  int t;
  for(int i = 0 ; i < n ; i++){
    cin >> s >> t;
    data[s] += t;
  }
  
  for(map<string, int>::iterator it = data.begin() ; it != data.end() ; it++){
    ans.push_back(*it);
  }
  
  sort(ans.begin(), ans.end(), compare);
  
  for(int i = 0 ; i < ans.size() ; i++){
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
import copy
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)

first_harf = Y[:int(N/2)]
second_harf = Y[int(N/2):]

for i in range(N):
    if X[i] <= first_harf[-1]:
        print(second_harf[0])
    else:
        print(first_harf[-1])


Measured memory_bytes: 32544
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int main(void)
{
	int N, M;
	int A[100010];
	int ans = 0;
	scanf("%d%d", &N, &M);
	if (N > M) {
		printf("0");
		return 0;
	}
	for (int i = 0; i < M; i++) {
		scanf("%d", &A[i]);
	}
	int B[100010];
	sort(A, A + M);
	for (int i = 0; i < M - 1; i++) {
		B[i] = abs(A[i + 1] - A[i]);
		ans += B[i];
		//printf("%d\n", B[i]);
	}
	sort(B, B + M-1, greater<int>());
	for (int i = 0; i < N-1; i++) {
		ans -= B[i];
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<queue>
int dx[2][6] = {{-1,0,-1,1,-1,0},{0,1,-1,1,0,1}};
int dy[6] = {-1,-1,0,0,1,1};	
struct S{int x,y;S(int x,int y):x(x),y(y){}};
int main()
{
	int w,h,a[109][109]={},f[109][109]={},x,y,r=0,i;
	scanf("%d%d",&w,&h);
	for(y=1;y<=h;++y)for(x=1;x<=w;++x)scanf("%d",&a[y][x]);
	std::queue<S>q;
	q.push(S(0,0));
	while(!q.empty())
	{
		S s(q.front());
		q.pop();
		if(s.x<0||s.y<0||s.x>108||s.y>108)continue;
		if(a[s.y][s.x]){++r;continue;}
		if(f[s.y][s.x]++)continue;
		for(i=0;i<6;++i)q.push(S(s.x+dx[s.y&1][i],s.y+dy[i]));
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
 
int main() {
	string S; cin >> S;
	int flag = 0;
	for (int i = 0; i < S.size(); i=i+2) {
		if(S[i] == 'L') flag = 1;
	}
	for (int i = 1; i < S.size(); i=i+2) {
		if(S[i] == 'R') flag = 1;
	}
	if(flag == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
def euclidian(a, b): #ユークリッドの互除法
    
    tmp = max(a,b)
    b = min(a,b)
    a = tmp

    mod = 1
    
    while (mod > 0):
        mod = a % b
        a, b = b, mod
    
    return(a)

low, high, C, D = map(int, input().split())

common = C * D // euclidian(C, D)
right_count = high - (high // C + high // D) + high // common 
l_tmp = low - 1
left_count = l_tmp - (l_tmp // C + l_tmp // D) + l_tmp // common

answer = right_count - left_count
print(int(answer))

Measured memory_bytes: 3064
import sys
A=[[0]*3 for i in range(3)]
for i in range(3):
  A[i]=list(map(int,input().split()))
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k]==b:
        A[j][k]=10**10
for i in range(3):
  if sum(A[i])==3*10**10:
    print("Yes")
    sys.exit()
a=0
for i in range(3):
  a=a+A[i][0]
if a==3*10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][1]
if a==3*10**10:
  print("Yes")
  sys.exit()
a=0
for i in range(3):
  a=a+A[i][2]
if a==3*10**10:
  print("Yes")
  sys.exit()
if A[0][0]+A[1][1]+A[2][2]==3*10**10 or A[0][2]+A[1][1]+A[2][0]==3*10**10:
  print("Yes")
  sys.exit()
print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string s,t;cin>>s>>t;int f=1;
	for(int u=0;u<s.size();u++){
		if(s[u]!=t[u]){f=0;break;}}
	cout<<(f? "Yes":"No");
}


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

int main(){
    int N;
    cin >> N;
    string names[N];
    long m_count = 0;
    long a_count = 0;
    long r_count = 0;
    long c_count = 0;
    long h_count = 0;

    for(int i = 0; i < N; i++){
        cin >> names[i];
        char tmp_char = names[i][0];
        if(tmp_char == 'M') m_count++;
        if(tmp_char == 'A') a_count++;
        if(tmp_char == 'R') r_count++;
        if(tmp_char == 'C') c_count++;
        if(tmp_char == 'H') h_count++;
    }
    long counts[5];
    counts[0] = m_count;
    counts[1] = a_count;
    counts[2] = r_count;
    counts[3] = c_count;
    counts[4] = h_count;
    sort(counts, counts+4);
    if(counts[2] == 0){
        cout << 0 << endl;
        return 0;
    }
    long ans = 0;
    for(int i = 0; i < 5; i++){
        ans += counts[i%5]*counts[(1+i)%5]*counts[(2+i)%5];
        ans += counts[i%5]*counts[(1+i)%5]*counts[(3+i)%5];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6144
#include<vector>
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int n, x;
	cin >> n >> x;
	bool flag = true;
	vector<int> vec(n);
	for (vector<int>::iterator it = vec.begin(); it != vec.end(); it++) {
		cin >> *it;
	}
	sort(vec.begin(), vec.end());
	if (*vec.begin() > x) { //cant even make the 1 that costs minimum
		cout << 0 << endl;
	}
	else {
		int count = 0;
		for (vector<int>::iterator it = vec.begin(); it != vec.end(); it++) {
			if (*it <= x) { count++; x -= *it; }
			else { cout << count << endl; flag = false; break; }
		}
		if (flag) { //can make all of them once, use the rest to make max number of minimum cost
			count += static_cast<int>(x / *vec.begin());
			cout << count << endl;
		}
	}
	return 0;
}

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

int main() {
	int N; cin >> N;
	vector<int>b(N), ans;
	for (auto&& x : b)cin >> x;

	for (int i = 0; i < N; i++) {
		int target = -1;
		for (int j = 0; j < b.size(); j++) {
			if (j + 1 == b[j])target = j + 1;
		}
		if (target == -1) { cout << -1 << endl; return 0; }
		ans.push_back(target);
		b.erase(b.begin() + target - 1);
	}
	for (int i = N - 1; i >= 0;i--)cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
mod=10**9+7
bt=bin(n)[2:]
k=len(bt)
dp=[[0]*2 for i in range(k+1)]
dp[0][0]=1
dp[0][1]=1
for i in range(k):
  j=int(bt[k-i-1])
  a,b,c=[(1,0,0),(1,1,0)][j]
  d,e,f=[(1,1,1),(0,1,2)][j]
  dp[i+1][0]=(a*dp[i][0]+b*dp[i][1]+c*(3**i))%mod
  dp[i+1][1]=(d*dp[i][0]+e*dp[i][1]+f*(3**i))%mod
print(dp[k][0])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define pii pair<int64_t,int64_t>
#define mp make_pair
#define whole(v) begin(v),end(v)
#define print(c,n) for(int64_t i=0;i<n;i++) cout << c[i] << " ";
#define MOD 1000000007
void solve(){
	int n,k;
	cin >> n >> k;
	int arr[n];
	for(int i=0;i<n;i++) cin >> arr[i];
	int dp[n+1];
	dp[1]=0;
	for(int i=2;i<=n;i++){
		dp[i] = INT_MAX;
		for(int j=i-1;j>=1;j--){
			if(i-j>k) break;
			dp[i] = min(dp[i],dp[j]+abs(arr[i-1]-arr[j-1]));
		}
	}
	cout <<  dp[n] << "\n";
}
int main(){
	
	solve();
}

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,M = MI()

if N % 2 == 1:
    for i in range(M):
        print(i+1,N-i)
else:
    if N % 4 == 0:
        for i in range(min(M,N//4)):
            print(i+1,N-i)
        if M > N//4:
            for i in range(M-N//4):
                print(N//4+i+1,(3*N)//4-i-1)
    else:
        for i in range(min(M,N//4)):
            print(i+1,N-i)
        if M > N//4:
            for i in range(M-N//4):
                print(N//4+i+1,N-N//4-i-1)


Measured memory_bytes: 75472
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
a.sort()
#print(bc)
bc.sort(key=lambda x:x[1])
bc = bc[::-1]
ans = 0
now = 0
key = 0
for i in range(n):
    #print(now, a[i])
    if now >= m:
        ans += a[i]
    elif bc[now][1] > a[i]:
        ans += bc[now][1]
        bc[now][0] -= 1
        if bc[now][0] <= 0:
            now += 1
    else:
        ans += a[i]
print(ans)

Measured memory_bytes: 82328
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
        Integer[] l = new Integer[n];
        int sum = 0;
        for (int i=0; i < n; i++) {
        	l[i] = scan.nextInt();
        }
        Arrays.sort(l,Collections.reverseOrder());
        for (int j = 0; j < k; j++) {
        	sum += l[j];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23508
N = int(input())
S = '0' + input()
west = [0 for i in range(N+1)]

for i in range(1,N+1):
    if S[i] == 'W':
        west[i] = west[i-1] + 1
    else:
        west[i] = west[i-1]

change = N

for i in range(1,N+1):
    ans = west[i-1] + N - west[N] - i + west[i]
    change = min(change,ans)

print(change)

Measured memory_bytes: 15480
//quming
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=55;
int a[N],n,res;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	fp(i,1,n)fp(j,i+1,n)res+=a[i]*a[j];
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256