akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().split())
a = [list(map(int,input().split())) for A in range(n)]
c = [list(map(int,input().split())) for C in range(m)]
for i in range(n):
    ans = []
    for j in range(m):
        ans.append((abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])))
    print(ans.index(min(ans))+1)

Measured memory_bytes: 9108
n = int(input())
arr = list(map(int, input().split()))
MOD = 10**9 + 7

ans = 0
for i in range(60):
    mask = 1 << i
    cnt = sum([1 for x in arr if x & mask == mask])
    ans += mask * cnt * (n - cnt) % MOD

print(ans % MOD)

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

int main() {
  string s;
  cin >> s;

  long int n = 0, m = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'B') {
      n++;
    } else if (s.at(i) == 'W') {
      m += n;
    }
  }
  cout << m << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch;
    int num, i;
    int counter[26] = {0};
    
    while(scanf("%c", &ch)!=EOF){
        if(isupper(ch)) ch = tolower(ch);
        num = ch - 'a';
        counter[num]++;
    }
    
    for(i=0; i<26; i++){
        printf("%c : %d\n", i+'a', counter[i]);
    }
    return 0;
}

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

bool G[100][100],f[100][100],f2;
int h,w,ans,c;

void dfs(int y, int x, bool dfs_f){
  int dx[] = {-1,0,-1,1,-1,0};
  if(y % 2 == 0){
    dx[0] = dx[4] = 0;
    dx[1] = dx[5] = 1;
  }
  int dy[] = {-1,-1,0,0,1,1};

  f[y][x] = false;

  if(!dfs_f){
    if(y == 0 || y == h - 1) ans += 2;
    if(y % 2 == 0 && x == w - 1 || y % 2 == 1 && x == 0){
      if(y == 0 || y == h - 1) ans += 2;
      else ans += 3;
    }
    if(y % 2 == 1 && x == w - 1 || y % 2 == 0 && x == 0) ans += 1;
    
    for(int i=0;i<6;i++){
      if(x + dx[i] >= 0 && x + dx[i] < w && y + dy[i] >= 0 && y + dy[i] < h){
	if(!G[y+dy[i]][x+dx[i]]) ans++;
	else if(f[y+dy[i]][x+dx[i]]) dfs(y+dy[i],x+dx[i],dfs_f);
      }
    }
  }

  else{
    for(int i=0;i<6;i++){
      if(x + dx[i] < 0 || x + dx[i] >= w || y + dy[i] < 0 || y + dy[i] >= h) f2 = false;
      else if(G[y+dy[i]][x+dx[i]]) c++;
      else if(f[y+dy[i]][x+dx[i]]) dfs(y+dy[i],x+dx[i],dfs_f);
    }
  }
}

int main(){
  while(cin >> w >> h){
    ans = 0;

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> G[i][j];
	f[i][j] = G[i][j];
      }
    }

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(f[i][j]){
	  dfs(i,j,false);
	}
      }
    }

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(!G[i][j]) f[i][j] = true;
	else f[i][j] = false;
      }
    }

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(f[i][j]){
	  f2 = true;
	  c = 0;
	  dfs(i,j,true);
	  if(f2) ans -= c;
	}
      }
    }

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

Measured memory_bytes: 0
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

f [y,m,d] = era y m d
era y m d
  | compare y 1989 <> compare m 1 <> compare d 8 /= LT = "heisei " ++ unwords (map show [y-1988,m,d])
  | compare y 1926 <> compare m 12 <> compare d 25 /= LT = "showa " ++ unwords (map show [y-1925,m,d])
  | compare y 1912 <> compare m 7 <> compare d 30 /= LT = "taisho " ++ unwords (map show [y-1911,m,d])
  | compare y 1868 <> compare m 9 <> compare d 8 /= LT = "meiji " ++ unwords (map show [y-1867,m,d])
  | otherwise = "pre-meiji"


main = map (f . map readInt . words) . lines <$> getContents >>= mapM_ putStrLn

Measured memory_bytes: 3780
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;



public class Main {


	static List<Integer> ansset;

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	String S=sc.next();

    	String[] input=S.split("");

    	Deque<String> result=new ArrayDeque<String>();

    	for(int i=0;i<input.length;i++) {

    		if(!input[i].equals("B")) {
    			result.push(input[i]);
    		}else {

    			if(!result.isEmpty()) {
    				result.pop();
    			}
    		}
    	}

    	int Size=result.size();
    	String buf="";
    	for(int i=0;i<Size;i++) {

    		if(!result.isEmpty()) {
    			buf=result.pollLast();
    		}

    		System.out.print(buf);
    	}

    	System.out.println();
    }
}



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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    int n, a;
    cin >> n >> a;
    cout << (n % 500 <= a ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
# abc132_c.py
# https://atcoder.jp/contests/abc132/tasks/abc132_c

# C - Divide the Problems /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 高橋君は、 N個の競技プログラミング用の問題をつくりました。 
# それぞれの問題には 1 から N の番号がついており、問題 i の難易度は整数 diで表されます(大きいほど難しいです)。
# 高橋君はある整数 Kを決めることで、

#     難易度が K以上ならば「 ARC用の問題」
#     難易度が K未満ならば「 ABC用の問題」

# という風に、これらの問題を二種類に分類しようとしています。

# 「ARC用の問題」と「ABC 用の問題」が同じ数になるような整数 Kの選び方は何通りあるでしょうか。

# 制約
#     2≦N≦105
#     Nは偶数である。
#     1≦di≦105
#     入力は全て整数である。

# 入力
# 入力は以下の形式で標準入力から与えられます。
# N
# d1 d2 ... dN

# 出力

# 「ARC用の問題」と「ABC 用の問題」が同じ数になるような整数 Kの選び方の数を出力してください。

# 入力例 1
# 6
# 9 1 4 4 6 7

# 出力例 1
# 2

# K=5,6としたとき、問題 1,5,6 が「ARC 用の問題」、問題 2,3,4 が「ABC 用の問題」となり、
# 条件を満たします。 よって、答えは 2通りです。

# 入力例 2
# 8
# 9 1 14 5 5 4 4 14

# 出力例 2
# 0

# 「ARC用の問題」と「ABC 用の問題」が同じ数になるような整数 Kの選び方が存在しない場合もあります。

# 入力例 3
# 14
# 99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1

# 出力例 3
# 42685


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # X, A = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    values.sort()
    n = int(N/2)

    log(f'values=[{values}]')
    result = values[n] - values[n-1]

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['6', '9 1 4 4 6 7']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['8', '9 1 14 5 5 4 4 14']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['14', '99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1']
        lines_export = [42685]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 21184
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x = sc.nextInt();
    
    long ans = 0;
    int prev = 0;
    for (int i = 1; i <= N; i++) {
      int a = sc.nextInt();
      int diff = Math.max(prev+a - x, 0);
      ans += diff;
      prev = a - diff;
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 48796
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [int(input()) for _ in range(N)] + [0]

# 連結成分ごとに、最大1枚残りでできる

answer = 0
x = 0
for a in A:
    if a == 0:
        answer += x//2
        x = 0
    x += a

print(answer)

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

#define DFS_ITEM 2
int DEPTH;
int N, ans = 0;
vector<int> A(20);
int x[20][20], y[20][20];

void calc(vector<int> v) {
    vector<int> right(N+1, -1);
    for(int i=0; i<N; i++){
    	if(v[i]==0){
	    if(right[i+1]==1)
		return;
	    right[i+1]=0;
	    continue;
	}
    	for(int j=0; j<A[i]; j++){
	    if(right[i+1]==0)
		return;
	    right[i+1]=1;
    	    if(right[x[i][j]]==-1)
    		right[x[i][j]]=y[i][j];
    	    else if(right[x[i][j]]!=y[i][j])
    		return;
    	}
    }
    int sum=0;
    for(int i=0; i<N; i++){
    	sum += v[i];
    }
    ans = max(ans, sum);

}
void DFS(int depth, vector<int> v) {    
    if(depth == DEPTH){
	calc(v);
	return;
    }    
    for(int i=0; i<DFS_ITEM; i++){
	v[depth] = i;
	DFS(depth+1, v);	
    }
}

int main(){
    cin >> N;
    DEPTH=N;
    vector<int> v(N);    
    for(int i=0; i<N; i++){
	cin >> A[i];
	for(int j=0; j<A[i]; j++){
	    cin >> x[i][j]>> y[i][j];
	}
    }
    DFS(0, v);			    
    cout << ans << endl;
}




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

int main() {
    int h, w, eq;
    string s1, s2;
    cin >> s1 >> s2;
    s2 += s2;
    for(int i = 0; i < s1.size(); ++i) {
        eq = 0;
        for(int j = 0; j < s1.size(); ++j) {
            if(s1[j] == s2[i+j]) {
                eq++;
            }
        }
        if(eq == s1.size()) {
            cout << "Yes" << '\n';
            return 0;
        }
    }
    cout << "No" << '\n';
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
a = list(map(int,input().split()))

dp = np.zeros((n+1,2), int)
dp[1],dp[2] = [0,a[0]], [0,max(a[0], a[1])]
for i in range(3,n+1):
  if(i%2 == 0):
    dp[i][0] = max(dp[i-1][0],dp[i-2][0]+a[i-1],dp[i-2][1])
    dp[i][1] = max(dp[i-1][1],dp[i-2][1]+a[i-1])
  else:
    dp[i][0] = max(dp[i-1][1],dp[i-2][1],dp[i-2][0]+a[i-1])
    dp[i][1] = dp[i-2][1]+a[i-1]
print(dp[n][(n+1)%2])

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> a(n);
    REP(i,n)cin >> a[i];
    int32 next = 1;
    int32 ans = 0;
    REP(i,n){
        if(a[i] == next){
            next++;
        }else{
            ans++;
        }
    }
    if(ans == n)ans = -1;
    ANS(ans);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<double,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n;
vector<double> x, y;

double check3(int i, int j, int k){
    double X[] = {x[i],x[j],x[k]};
    double Y[] = {y[i],y[j],y[k]};
    double A[2], B[2], C[2];
    for(int i=0;i<2;i++){
        A[i] = X[i+1]-X[i];
        B[i] = Y[i+1]-Y[i];
        C[i] = X[i]*X[i] - X[i+1]*X[i+1] + Y[i]*Y[i] - Y[i+1]*Y[i+1];
    }
    double CX, CY, R;
    if(abs(B[1])>EPS){
        double D = B[0]/B[1];
        CX = -(C[0]-C[1]*D)/(2*(A[0]-A[1]*D));
        CY = -(C[0]+2*A[0]*CX)/(2*B[0]);
        R = sqrt(pow(X[0]-CX,2)+pow(Y[0]-CY,2));
    }else{
        double D = B[1]/B[0];
        CX = -(C[1]-C[0]*D)/(2*(A[1]-A[0]*D));
        CY = -(C[1]+2*A[1]*CX)/(2*B[1]);
        R = sqrt(pow(X[1]-CX,2)+pow(Y[1]-CY,2));
    }
    bool ok = true;
    for(int id=0;id<n;id++){
        if(sqrt(pow(x[id]-CX,2)+pow(y[id]-CY,2)) > R + EPS){
            ok = false;
        }
    }
    if(ok) return R;
    else return -1;
}

double check2(int i, int j){
    double CX, CY, R;
    CX = (x[i]+x[j])/2;
    CY = (y[i]+y[j])/2;
    R = sqrt(pow(x[i]-CX,2)+pow(y[i]-CY,2));
    for(int k=0;k<n;k++){
        if(i == k || j == k) continue;
        R = max(R, sqrt(pow(x[k]-CX,2)+pow(y[k]-CY,2)));
    }
    if(R < 0) return 1e9;
    return R;
}

double check1(int i){
    double R = 0;
    for(int j=0;j<n;j++){
        if(i == j) continue;
        R = max(R, sqrt(pow(x[j]-x[i],2)+pow(y[j]-y[i],2)));
    }
    return R;
}

int main(){
    cin >> n;
    x.resize(n);
    y.resize(n);
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    double ans = 1e9;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(abs((x[i]-x[j])*(y[k]-y[j])-(x[k]-x[j])*(y[i]-y[j])) > EPS){
                    double r = check3(i,j,k);
                    if(r > EPS){
                        ans = min(ans, r);
                    }
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans = min(ans, check2(i,j));
        }
    }
    for(int i=0;i<n;i++){
        ans = min(ans, check1(i));
    }
    printf("%.9lf\n",ans);
    return 0;
}

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


public class Main {
	Scanner sc=new Scanner(System.in);
	static final int upperlimit=(int) Math.pow(2, 15);
	
	
	private void cal(){
		
		boolean[] values=new boolean[1<<15];
		Arrays.fill(values,true);
		values[0]=false;
		values[1]=false;
		
		for(int i=2;i<1<<15;i++)
		    if(values[i])
			for(int j=2;i*j<1<<15;j++)
			    values[i*j]=false;
				
		
		
		while(true){
			int n=sc.nextInt();
			int count=0;
			
			if(n==0)
				break;
			for(int i=0;i<=n/2;i++)
				if(values[i]&&values[n-i])
					count++;
		
		
		System.out.println(count);
		
		}
		
	}
	
	public static void main(String[] argv){
		new Main().cal();
	}
	
	
	
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){ 
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N-1);
  REP(i, N){
    cin >> A[i];
    A[i]--;
  }
  REP(i, N){
    cin >> B[i];
  }
  REP(i, N-1){
    cin >> C[i];
  }
  int sum = B[A[0]];
  FOR(i, 1, N){
    sum += B[A[i]];
    if(A[i-1] + 1 == A[i]){
      sum += C[A[i-1]];
    }
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
int h[100100],f[100100];
int smallest ;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	f[1]=0;
	f[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++){
		smallest=2147483647;
		for(int j=max(1,i-k);j<i;j++){
			smallest=min(smallest,f[j]+abs(h[j]-h[i]));
		}
		f[i]=smallest;
	}
	cout<<f[n];
}


Measured memory_bytes: 1024
from itertools import product
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]

ans = 10**18
for pattern in product(range(4), repeat=N):
  MP = 0
  take = [0] * 3 # A, B, Cの3本
  for index, length in zip(pattern, l):
    if index == 3:
      continue
    if take[index] != 0: # 最初の1本は合成MP不要
      MP += 10
    take[index] += length
  
  if take[0] != 0 and take[1] != 0 and take[2] != 0:
    MP += abs(A - take[0])
    MP += abs(B - take[1])
    MP += abs(C - take[2])
    ans = min(MP, ans)

print(ans)

Measured memory_bytes: 3064
N = int(input())
S = input()

# print(N)
# print(S)

ss = []
for i in range(N):
    # print(S[i])
    
    # print(len(ss))
    
    if len(ss) == 0:
        ss.append(S[i])
    else:
        # print(ss[len(ss) - 1])
        if S[i] != ss[len(ss) - 1]:
            ss.append(S[i])
    
# print(''.join(ss))
print(len(ss))

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

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

string S,T;
void input()
{
    cin>>S>>T;
}

void solve()
{
    string ans="Yes";
    for(int i=0;i<S.length();++i){
        if(S[i]!=T[i]){
            ans="No"; break;
        }
    }
    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

using ll = long long;
ll n, x;
ll a[123456];

int main(void)
{
	scanf("%lld %lld", &n, &x);
	for (int i = 0; i < n; ++i)
	{
		scanf("%lld", a + i);
	}
	ll ans = 0;
	if (a[0] > x)
	{
		ans += (a[0] - x);
		a[0] = x;
	}
	for (int i = 1; i < n; ++i)
	{
		if (a[i] + a[i - 1] > x)
		{
			ans += (a[i] - x + a[i - 1]);
			a[i] = x - a[i - 1];
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

//const int mod = 998244353;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

    mint ans = 0;
    ll min = 0, max = n;
    ll subans = max-min+1;
    if(k==1) ans += subans;
    for(int i=2;i<=n+1;i++){
        subans += n-i+1;
        subans -= i-1;
        if(i>=k) ans += subans;
        //cout << subans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [1] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1)

    return {2} | {2 * i + 1 for i in range(1, m) if p[i]}


def main():
    primes = prime_numbers(10 ** 5)
    A = [n % 2 and n in primes and (n + 1) // 2 in primes for n in range(10 ** 5 + 1)]
    A = tuple(accumulate(A))

    Q, *LR = map(int, open(0).read().split())
    ans = []
    for l, r in zip(LR[::2], LR[1::2]):
        ans.append(A[r] - A[l - 1])

    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 29000
#include <bits/stdc++.h>
#include <iomanip>      // std::setprecision
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)
#define char2Int(c) (c-'0')
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define REMAX(a,b) (a)=max((a),(b)) // set a to the maximum of a and b
#define REMIN(a,b) (a)=min((a),(b));
#define FENWICK(k) (k&-k)
#define FOREACH(i,t) for (auto i=t.begin(); i!=t.end(); i++) // traverse an STL data structure
#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define PRESENT(c,x) ((c).find(x) != (c).end()) 
#define CPRESENT(c,x) (find(ALL(c),x) != (c).end()) 
#define LL long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef int elem_t;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
// directions
const int fx[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}};
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
const int rogi[4][2] = { {1,1}, {1,-1}};

int n;
int gcd_left[111111];
int gcd_right[111111];
int val[111111];

void dane() {
    cin>>n;
    F(i,1,n+1) cin>>val[i];
    
    gcd_left[1] = val[1];
    F(i,2,n+1) {
        gcd_left[i] = __gcd(gcd_left[i-1], val[i]);
    }

    gcd_right[n] = val[n];
    FFE(i, n-1, 1) {
        gcd_right[i] = __gcd(gcd_right[i+1], val[i]);
    }

    int maxi = max(gcd_right[2], gcd_left[n-1]);
    F(i,2,n) {
        maxi = max(maxi, __gcd(gcd_left[i-1], gcd_right[i+1]));
    }
    cout<<maxi<<endl;
}


int main() {
	IOS
	// int t;
	// cin>>t;
	// F(i,0,t)
	    dane();
    return 0;
}

Measured memory_bytes: 1408
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.nextInt();
            var b = cin.nextInt();

            var ans = 0;
            for (int i = a; i <= b; i++)
            {
                if (i.ToString()[0] == i.ToString()[4] && i.ToString()[1] == i.ToString()[3]) ans++;
            }

            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N+ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }   

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


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

#define ll long long

using namespace std;

ll k;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> k;
    ll now = 0, cnt = 0;
    ll temp = 2*(ll)1e6;
    while (temp--) {
        now = now * 10 + 7;
        ++cnt;
        now = now % k;
        if (now == 0) {
            cout << cnt << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int d0[50],d1[50],m,mm;
long long ans,d,wei,te,ten[18];
//81000 wei+3
void dfs(int x,long long v,long long s){
	//if (abs(v)>d*10000) return;//12
	if (v<-d*15) return;//*105
	if (v>d*15&&v>(ten[m-x]-ten[x-1])*15) return;//*105
	//printf("%d %lld %lld\n",x,v,s);
	if (x>mm){//>m
		if (v==d){
			//printf("%d %lld %lld\n",x,v,s);
			if (m&1) ans+=s*10;else ans+=s;//(m>2)&&
		}
		return;
	}
	if (x==1){
		fo(i,-9,8) dfs(x+1,v+i*(ten[m-x]-ten[x-1]),s*d1[i+20]);//m-i+1 i
		return;
	}
	fo(i,-9,9) dfs(x+1,v+i*(ten[m-x]-ten[x-1]),s*d0[i+20]);
}
inline void sol(int wei){
	if (wei<=1) return;
	m=wei;mm=m/2;
	dfs(1,0,1);
}
int main(){
	scanf("%lld",&d);
	if (d%9!=0){
		printf("0\n");
		return 0;
	}
	if (d==9){
		printf("8\n");
		return 0;
	}
	ten[0]=1;fo(i,1,17) ten[i]=ten[i-1]*10;
	fo(i,0,9) fo(j,0,9) d0[i-j+20]++;
	fo(i,0,9) fo(j,1,9) d1[i-j+20]++;
	te=d;
	while (te){
		wei++;
		te/=10;
	}
	//printf("%lld\n",wei);
	fo(i,-2,9) sol(wei+i);//-8..8
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  int n, i, maxs, mins, score, sum, ave;
  while(scanf("%d", &n) != EOF)
    {
      if(n == 0) break;
      scanf("%d", &score);
      maxs = mins = sum = score;
      for(i = 1; i < n; i ++){
	scanf("%d", &score);
	sum += score;
	if(score > maxs) maxs = score;
	if(score < mins) mins = score;
      }
      sum -= maxs + mins;
      ave = sum / (n - 2);
      printf("%d\n", ave);
    }
}

Measured memory_bytes: 600
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
mod = 1000000007

s = input()
t = input()

if len(t) - len(s) == 1 and s == t[:-1]:
    print('Yes')
else:
    print('No')

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

import sys
from math import hypot, sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def heron(a, b, c):
    s=(a+b+c)/2
    return sqrt(s*(s-a)*(s-b)*(s-c))

x1,y1=MAP()
x2,y2=MAP()
x3,y3=MAP()

# 各辺の長さ
a=hypot(x1-x2, y1-y2)
b=hypot(x2-x3, y2-y3)
c=hypot(x3-x1, y3-y1)
# 三角形の面積(ヘロンの公式)
S=heron(a, b, c)
# 内接円の半径
r=2*S/(a+b+c)

# max(a,b,c)*(1-x/r)==2*xをxについて解く
mx=max(a, b, c)
print(mx/(2+mx/r))


Measured memory_bytes: 3188
import scala.io.StdIn.readLine
import scala.collection.mutable.Queue

object Main extends App {
  val l = readLine.split(" ").map(_.toInt)
  val q = new Queue[(String,Int)]
  val b = new StringBuilder

  for(i<-0 until l(0)) {
    val m = readLine.split(" ")
    q += ((m(0), m(1).toInt))
  }

  def rrobin(total:Int):Unit = {
    if(q.isEmpty) return
    else {
      val (p,t) = q.dequeue
      val newTotal =
        if(t>l(1)) {
          q += ((p,t-l(1)))
          total + l(1)
        } else {
          b.append(p + " " + (t+total)+"\n")
          total + t
        }
      rrobin(newTotal)
    }
  }

  rrobin(0)
  print(b.result)
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long N, std::vector<long long> A) {
  double ans = 0;
  rep(i, N) { ans += 1.0 / A[i]; }
  ans = 1 / ans;
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


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

int main() {
	int N, X, Y;
	cin >> N >> X >> Y;
	X--;Y--;
	map<int, int> mii;

	int tmp1, tmp2;
	for (int s = 0; s < N-1; s++) {
		for (int e = s+1; e < N; e++) {
			tmp1 = e - s;
			if (s <= X && Y <= e) tmp2 = (X - s) + 1 + (e - Y);
			else if (e <= X || Y <= s) tmp2 = e - s;
			else if (s <= X && e <= Y) tmp2 = (X - s) + 1 + (Y - e);
			else if (X <= s && Y <= e) tmp2 = (s - X) + 1 + (e - Y);
			else tmp2 = (s - X) + 1 + (Y - e);
			if (tmp1 < tmp2) mii[tmp1]++;
			else mii[tmp2]++;
		}
	}

	for (int i = 1; i < N; i++) {
		cout << mii[i] << "\n";
	}

	return 0;
}


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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

const int mod = 1000000007;

lint f(lint l, lint r) { return (l + r) * (r - l + 1) / 2; }

void resolve()
{
    lint N, K;
    cin >> N >> K;

    lint total = 0;
    RPT(i, K, N + 1)
    {
        lint ma = f(N - i + 1, N);
        lint mi = f(0, i - 1);
        total += ma - mi + 1;
        total %= mod;
    }

    cout << total << endl;
}

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


Measured memory_bytes: 3624
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card
{
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right)
{
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++)
        L[i] = A[left + i];
    for (i = 0; i < n2; i++)
        R[i] = A[mid + i];

    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++)
    {
        if (L[i].value <= R[j].value)
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right)
{
    int mid;
    if (left + 1 < right)
    {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r)
{
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++)
    {
        if (A[j].value <= x.value)
        {
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r)
{
    int q;
    if (p < r)
    {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main()
{
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A,n,0,n);
    quickSort(B,n,0,n-1);

    for (i=0;i<n;i++) {
        if (A[i].suit != B[i].suit) stable = 0;
    }

    if (stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for (i=0;i<n;i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 5044
from collections import Counter
mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans = sum(b)
    for i in range(n-1):
        if a[i] + 1 == a[i+1]:
            ans += c[a[i]-1]

    print(ans)

main()


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


int main() {
    int n; cin >> n;
    if(n%10==3){
        cout << "bon" << endl;
        return 0;
    }
    if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
        cout << "pon" << endl;
        return 0;
    }
    else{
        cout << "hon" << endl;
        return 0;
    }
}

Measured memory_bytes: 3624
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:(input())

"""========main code==============="""
def fast(a,b):
    res=1
    while(b>0):
        if(b&1):
            res*=a
        a*=a    
        b>>=1
    return res
x=ii()
f=0
for i in range(-201,201):
    k=fast(i,5)
    for j in range(i,201):
        p=fast(j,5)
        #print(k,p,i,j,p-k)
        if((p-k)==x):
            print(j,i)
            f=1
            break
        elif(k-p==x):
            print(i,j)
            f=1
            break
    if f:
        break


Measured memory_bytes: 68124
#include <stdio.h>

#define MAX 200000

int max(int a,int b) { return a>b ? a: b;}
int min(int a,int b) { return a<b ? a: b;}

int main(void) {
    int R[MAX], i, n;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    printf("%d\n",maxv);

    return 0;
}


Measured memory_bytes: 2568
#include"bits/stdc++.h"
//#include"../../bits/stdc++.h"

using namespace std;

int main() {
    int N;
    int max = 0;
    map<string, int> mp;
    vector<string> name;
    cin >> N;
    string str;
    for(int i = 0;i < N; i++){
        cin >> str;
        mp[str] += 1;
        name.push_back(str);
        if(mp[str]>max) {
            max = mp[str];
        }
    }

    sort(name.begin(), name.end());
    name.erase(unique(name.begin(), name.end()), name.end());
    for(auto it = name.begin(); it != name.end(); ++it) {
        if (mp[*it]==max){
            cout << *it << endl;
        }
    }
}

Measured memory_bytes: 26736
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;


int main(){
    int X,Y,A,B,C;
    int t;
    cin >> X >> Y >> A >> B >> C;

    vector <int> P,Q,R;
    priority_queue<int,vector<int>,greater<int> > Q_a,Q_b;
    //input
    for (int i=0;i<A;i++){
        cin >>t;
        if (Q_a.empty() or Q_a.size()<X){
            Q_a.push(t);
        }
        else{
            if (Q_a.top()<t){
                Q_a.pop();
                Q_a.push(t);
            }
        }
    }
    for (int i=0;i<B;i++){
        cin >> t;
        if (Q_b.empty() or Q_b.size()<Y){
            Q_b.push(t);
        }
        else{
            if(Q_b.top()<t){
                Q_b.pop();
                Q_b.push(t);
            }
        }
    }
    for (int i=0;i<C;i++){
        cin >> t;
        R.push_back(t);
    }
    //sort
    sort(R.begin(),R.end(),greater<int>());
    for ( int i=0;i<C;i++){
        int a=Q_a.top();
        int b=Q_b.top();
        if(a>b){
            if(b<R[i]){
                Q_b.pop();
                Q_b.push(R[i]);
            }
        }
        else{
            if(a<R[i]){
                Q_a.pop();
                Q_a.push(R[i]);
            }
        }
    }
    long long ans=0;
    while (!Q_a.empty()){
        ans+=Q_a.top();
        Q_a.pop();
    }
    while (!Q_b.empty()){
        ans+=Q_b.top();
        Q_b.pop();
    }
    cout << ans<<endl;
}

int main3(){
    int X,Y,A,B,C;
    int t;
    cin >> X >> Y >> A >> B >> C;

    vector <int> P,Q,R;
    priority_queue<int,vector<int>,greater<int> > Q_a,Q_b;
    //input
    for (int i=0;i<A;i++){
        cin >>t;
        if (Q_a.empty() or Q_a.size()<X){
            Q_a.push(t);
        }
        else{
            if (Q_a.top()<t){
                Q_a.pop();
                Q_a.push(t);
            }
        }
    }
    for (int i=0;i<B;i++){
        cin >> t;
        if (Q_b.empty() or Q_b.size()<Y){
            Q_b.push(t);
        }
        else{
            if(Q_b.top()<t){
                Q_b.pop();
                Q_b.push(t);
            }
        }
    }
    for (int i=0;i<C;i++){
        cin >> t;
        R.push_back(t);
    }
    
    while (!Q_a.empty()){
        R.push_back(Q_a.top());
        Q_a.pop();
    }
    while (!Q_b.empty()){
        R.push_back(Q_b.top());
        Q_b.pop();
    }
    sort(R.begin(),R.end(),greater<int>());
    long long ans=0;
    for (int i=0;i<X+Y;i++){
        ans+=R[i];
    }
    cout << ans<<endl;
}


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

vector<int> vec(5);

int main() {
  for (int i=0;i<vec.size();i++) {
    cin >> vec.at(i);
  }
  for (int k=0;k<vec.size();k++) {
    if (vec.at(k) == 0) {
      cout << k+1 << endl;
    } 
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int n,a[300006],b[300006];
char s[3000006];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	a[0]=b[n+1]=0;
	for(int i=1;i<=n;i++)
	{
		a[i]=a[i-1];
		b[n-i+1]=b[n-i+2];
		if(s[i]=='W')a[i]++;
		if(s[n-i+1]=='E') b[n-i+1]++;
	}
	int ans=INF;
	for(int i=1;i<=n;i++)
		ans=min(ans,a[i-1]+b[i+1]);
	printf("%d\n",ans);
	return 0;
}

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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 88
#define MAXS 13000

int dp[MAXN][MAXN][MAXS];

int main(){
  int h,w;cin>>h>>w;
  vector<vector<int>> scores(h);
  rep(i, h)rep(j, w){
    int a;cin>>a;
    scores[i].push_back(a);
  }
  rep(i, h)rep(j, w){
    int a;cin>>a;
    scores[i][j] -= a;
    if(scores[i][j] < 0)scores[i][j] *= -1;
  }

  dp[0][0][scores[0][0]] = 1;
  rep(i, h)rep(j, w)rep(k, MAXS){
    int s = scores[i][j];
    int mpre = k-s;
    if(mpre<0)mpre *= -1;
    if(i && dp[i-1][j][mpre]==1)dp[i][j][k]=1;
    if(j && dp[i][j-1][mpre]==1)dp[i][j][k]=1;

    int ppre = k+s;
    if(ppre<=7000){
      if(i && dp[i-1][j][ppre]==1)dp[i][j][k]=1;
      if(j && dp[i][j-1][ppre]==1)dp[i][j][k]=1;
    }
  }

  int result = 0;
  rrep(i, MAXS)if(dp[h-1][w-1][i])result = i;

  cout<<result<<endl;

  return 0;

  rep(i, h){
    rep(j, w)cout<<scores[i][j]<<' ';cout<<endl;
  }
cout<<"###"<<endl;

rep(k, 15){
cout<<k<<endl;
  rep(i, h){
    rep(j, w)cout<<dp[i][j][k]<<' ';cout<<endl;
  }
  cout<<"---"<<endl;
}

  return 0;
}


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

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    if (x == accumulate(a.begin(), a.end(), 0ll)) {
        cout << n << endl;
        return 0;
    }
    ll sum = 0;
    sort(a.begin(), a.end());
    int i;
    for (i = 0; i < n; i++) {
        if (sum + a[i] <= x) {
            sum += a[i];
        } else
            break;
    }
    cout << (i != n ? i : n - 1) << endl;
}

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

int main(){
    int n;
    while(cin>>n,n){
        vector<int> V(n);
        for(auto &v:V) cin>>v;
        sort(V.begin(), V.end());
        int ans = 1e9;
        for(int i=1;i<n;i++){
            ans = min(ans, V[i]-V[i-1]);
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

queue<char>q[3];


int main()
{
    fast;
  
 ll h,w;
 cin>>h>>w;
vector<string>v(h+1);

v[0]="\0";
 
 for(ll i=1;i<=h;i++)
 {

 	cin>>v[i];
 	

 }
 
 for(ll i=1;i<=2*h;i++)
 {
 	cout<<v[(i+1)/2]<<"\n";
 }
  	
}

		
	
	
	
	


Measured memory_bytes: 3660
S = gets.chomp
P = lambda{|s|
	(s.size/2).times.all?{|i| s[i]==s[-1-i] }
}
puts(P[S]&&P[S[0,(S.size-1)/2]]&&P[S[(S.size+3)/2-1,S.size]] ? 'Yes' : 'No')


Measured memory_bytes: 3836