akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main(){
    int  n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
    }
    int i = 0;
    while(i < n){
        while(a[i] == a[i+1])i++;
        i++;
        if(i >= n ) ans ++;
        if(a[i] >= a[i-1] && i < n){
            ans++;
            while(a[i] >= a[i-1] && i < n) i++;
        }
        else if(a[i] <= a[i-1] && i < n){
            ans ++;
            while(a[i] <= a[i-1] && i < n)i++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define PB push_back
#define MP make_pair
#define S second
#define F first
//#define D cout<<"*\n";
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define mod 1000000007 
#define inf 1e10;
const double pi = 3.14159265358979323846; 

int visited[100005];

int dfs(vector<int> graph[],int s)
{
	if(graph[s].size()==0)
	return 0;
	
	int &ans=visited[s];
	if(ans!=-1)
	return ans;
	for(int i=0;i<graph[s].size();i++)
	{
		int t=graph[s][i];
		 ans=max(dfs(graph,t),ans);
	}
	ans=ans+1;
	return ans;
}
signed main()
{
    fast
    int t=1;
   // cin>>t;
    
    while(t--)
    {
      int H,W;
      cin>>H>>W;
      int grid[H+1][W+1];
      for(int i=1;i<=H;i++)
      {
      	for(int j=1;j<=W;j++)
      	{
      		char c;
      		cin>>c;
      		if(c=='.')
      		grid[i][j]=-1;
      		else
      		grid[i][j]=0;
		  }
	  }
	  if(grid[1][1]==-1)
	  grid[1][1]=1;
	  
	  for(int i=2;i<=W;i++)
	  {
	  	if(grid[1][i]==-1)
	  	grid[1][i]=grid[1][i-1];
	  }
	  for(int i=2;i<=H;i++)
	  {
	  	if(grid[i][1]==-1)
	  	grid[i][1]=grid[i-1][1];
	  }
	  for(int i=2;i<=H;i++)
	  {
	  	for(int j=2;j<=W;j++)
	  	{
	  		if(grid[i][j]==-1)
	  		{
	  			grid[i][j]=(grid[i][j-1]+grid[i-1][j])%mod;
			  }
		  }
	  }
	  cout<<grid[H][W];
      
      
    }
	return 0;
}

	

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

int main() {
    int s;  cin >> s;
    set<int> cnt;

    while (cnt.count(s) == 0) {
        cnt.insert(s);
        if (s % 2 == 0) s = s / 2;
        else s = 3 * s + 1;
    }
    cout << cnt.size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 1046527
using namespace std;
int hs(string);
int matoi(char);
int h1(int k){return k%M;}
int h2(int k){return 1+(k%(M-1));}
int main(){
  vector<string> a(M,"");
  int n;
  cin >> n;
  for(int j=0;j<n;j++){
    string fu;
    string st;
    cin >> fu >> st;
    int ke=hs(st);
    if(fu=="insert"){
      for(int i=0;;i++){
	int h=(h1(ke)+i*h2(ke))%M;
	if(a[h]==st)break;
	else if(a[h]==""){
	  a[h]=st;
	  break;
	}
	
      }
    }
    else{
      int f=0;
      for(int i=0;;i++){
	int h=(h1(ke)+i*h2(ke))%M;
	if(a[h]==st){
	  cout << "yes" << endl;
	  f=1;
	  break;
	}
	else if(a[h]=="")break;
      }
      if(!f)cout << "no" << endl;
    }
  }
  return 0;
}
int hs(string st){
  int re=0;
  for(int i=st.size()-1;i>=0;i--){
    re*=4;
    int a=matoi(st[i]);
    re+=a;
  }
  return re;
}
int matoi(char ch){
  if(ch=='A')return 1;
  if(ch=='C')return 2;
  if(ch=='G')return 3;
  return 4;
}

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

int main() {
	/****input****/
  ll a,b;
  cin >> a >>b;

  /****calc****/
  ll ans = a*b;

  /* 自然数 a > b を確認・入替 */
  if(a<b){
	int tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッドの互除法 */
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  ans = ans / (ll)b;
  /****output****/
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
	int	n;
	int	n_array[37] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2,
	   					1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5,
					   	4, 1, 4, 1, 51};
	scanf("%d", &n);
	printf("%d", n_array[n - 1]);
	return (0);
}


Measured memory_bytes: 128
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		cs: Chars,
	}

	let a = (cs[0] as u8) as isize - 48;
	let b = (cs[1] as u8) as isize - 48;
	let c = (cs[2] as u8) as isize - 48;
	let d = (cs[3] as u8) as isize - 48;

	//println!("{},{},{},{}", a, b, c, d);

	//+++
	if a+b+c+d == 7 {
		println!("{}+{}+{}+{}=7", a, b, c, d);
		return;
	}
	//++-
	if a+b+c-d == 7 {
		println!("{}+{}+{}-{}=7", a, b, c, d);
		return;
	}
	//+-+
	if a+b-c+d == 7 {
		println!("{}+{}-{}+{}=7", a, b, c, d);
		return;
	}
	//+--
	if a+b-c-d == 7 {
		println!("{}+{}-{}-{}=7", a, b, c, d);
		return;
	}
	//-++
	if a-b+c+d == 7 {
		println!("{}-{}+{}+{}=7", a, b, c, d);
		return;
	}
	//-+-
	if a-b+c-d == 7 {
		println!("{}-{}+{}-{}=7", a, b, c, d);
		return;
	}
	//--+
	if a-b-c+d == 7 {
		println!("{}-{}-{}+{}=7", a, b, c, d);
		return;
	}
	//---
	if a-b-c-d == 7 {
		println!("{}-{}-{}-{}=7", a, b, c, d);
		return;
	}
}



Measured memory_bytes: 2180
#include <stdio.h>
#include <math.h>
#include <string.h>
#define LEN 4
#define SPACE 3

int main()
{
	int operands[LEN];
	char spaces[SPACE];
	char left[100];
	int index, sum;
	const char *operators[2] = {"+", "-"};
	scanf("%1d%1d%1d%1d", &operands[0], &operands[1], &operands[2], &operands[3]);

	for (int i = 0; i < pow(2, SPACE); i++) {
		sprintf(left, "%d", operands[0]);
		index = 0;
		sum = operands[0];
		for (int j = 0; j < SPACE; j++) {
			if ((i >> j) & 1) {
				sprintf(left, "%s%s%d", left, "+", operands[index+1]);
				sum += operands[index+1];
			} else {
				sprintf(left, "%s%s%d", left, "-", operands[index+1]);
				sum -= operands[index+1];
			}
			index++;
		}
		if (sum == 7) goto FINAL;
	}
	FINAL: printf("%s=7\n", left);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

long long ncr[2048][2048];

int main(int argc, char **argv)
{
    int n, k;

    std::cin >> n >> k;
    const int m = 1000000000 + 7;

    for (int i = 0; i < 2001; i++) {
        ncr[i][0] = 1;
        ncr[i][i] = 1;
    }
    for (int i = 2; i < 2001; i++) {
        for (int j = 1; j < i; j++) {
            ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % m;
        }
    }
    for (int i = 1; i <= k; i++) {
        std::cout << (ncr[n - k + 1][i] * ncr[k - 1][i - 1]) % m << std::endl;
    }

    return 0;
}


Measured memory_bytes: 31488
# E - Crested Ibis vs Monster
def main():
    INF = 1 << 30
    
    H, N, *AB = map(int, open(0).read().split())
    dp = [INF] * (H + 1)  # dp[i] := min magic points to decrease monster's health by i
    dp[0] = 0
    for i in range(H):
        if dp[i] == INF:
            continue
        for a, b in zip(*[iter(AB)] * 2):
            if i + a < H:
                dp[i + a] = min(dp[i + a], dp[i] + b)
            else:
                dp[H] = min(dp[H], dp[i] + b)
    print(dp[H])


if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
int n, k, c, tot;
char s[maxn];
int f[maxn], a[maxn];
int main()
{
	scanf("%d%d%d", &n, &k, &c);
	scanf("%s", s + 1);
	for(int i = n; i; --i)
		if(s[i] == 'x')
			f[i] = f[i + 1];
		else
			f[i] = max(f[i + 1], f[i + c + 1] + 1);
	for(int i = 1; i <= n; ++i)
	{
		if(s[i] == 'o')
		{
			a[++tot] = i;
			i += c;
		}
	}
	for(int i = 1; i <= n; ++i)
	{
		int x = lower_bound(a + 1, a + tot + 1, i) - a - 1;
		int ret = x;
		if(x == 0) ret += f[i + 1];
		else ret += f[max(a[x] + c + 1, i + 1)];
		if(ret < k) printf("%d\n", i);
	}
		

	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int n,m;
	cin >> n >> m;
	vi a(n);
	rep(i,n) cin >> a[i];
	vector<P> v;
	rep(i,m){
		int b,c;
		cin >> b >> c;
		v.emplace_back(c,b);
	}

	sort(all(a));
	sort(all(v)); reverse(all(v));

	int j = 0;
	for(int i = 0; i < m; i++){
		while(j < n && v[i].second > 0 && a[j] < v[i].first){
			a[j] = v[i].first;
			v[i].second--;
			j++;
		}
	}

	ll sum = 0;
	for(int i = 0; i < n; i++){
		sum += a[i];
	}

	cout << sum << endl;

	return 0;
}


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

int main() {
  int N ; 
  cin >> N ; 
  vector<int> p(N+1) ; 
  int cnt = 0 ; 
  
  for(int i = 1 ; i <= N ; i++ ){
    cin >> p.at(i) ; 
  }
  
  for(int i = 1 ; i <= N ; i++){
    if( i != p.at(i)){
      cnt++ ; 
    }
  }
  
  if(cnt > 2){
    cout << "NO" << endl ; 
  }
  else{
    cout << "YES" << endl;
  }
  return 0 ; 
}

Measured memory_bytes: 3612
q = int(input())
M = {}

for i in range(q):
    query, *inp = input().split()
    key = inp[0]

    # insert
    if query == "0":
        x = int(inp[1])
        M[key] = x

    # get
    elif query == "1":
        if key in M:
            print(M[key])
        else:
            print(0)

    # delete
    else:
        if key in M:
            del M[key]


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

int main()
{
	int n;
	vector<int> change;

	while (cin >> n, n != -1){
		while (1){
			change.push_back(n % 4);
			if (n / 4 == 0){
				break;
			}
			n /= 4;
		}

		for (int i = change.size() - 1; i >= 0; i--){
			cout << change[i];
		}
		cout << endl;

		change.clear();
	}

	return (0);
}

Measured memory_bytes: 1212
x,y = (int(x) for x in input().split())

if x>3 and y>3:
    print(0)
elif x<=3 and y<=3:
    if x+y == 2:
        print(1000000)
    elif x+y == 3:
        print(500000)
    elif x+y == 4:
        print(400000)
    elif x+y == 5:
        print(300000)
    else:
        print(200000)
else:
    z = min(x,y)
    if z == 1:
        print(300000)
    elif z == 2:
        print(200000)
    else:
        print(100000)

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

using namespace std;

const int N = 3 * 2005;
const int C = 2005;

int n, a[N];

int mx_ind[N];
int mx_color[C];
int mx_ic[N][C];

// get max val(index, anything)
// get max val(index, color)
// get max val(color, color)
// lazy increment

int lz;

int get_ind(int i) {
	return mx_ind[i] + lz;
}

int get_ind_col(int i, int c) {
	return mx_ic[i][c] + lz;
}

int get_col_col(int c) {
	return mx_color[c] + lz;
}

void add(int i, int j, int val) {
	val -= lz;
	mx_ind[i] = max(mx_ind[i], val);
	mx_ind[j] = max(mx_ind[j], val);
	if(a[i] == a[j]) {
		mx_color[ a[i] ] = max(mx_color[ a[i] ], val);
	}
	mx_ic[i][ a[j] ] = max(mx_ic[i][ a[j] ], val);
	mx_ic[j][ a[i] ] = max(mx_ic[j][ a[i] ], val);
}
void lazy_inc() {
	lz++;
}

int dp[N][3];
int dp2[3][3];

int main() {
	memset(mx_ind, -7, sizeof mx_ind);
	memset(mx_color, -7, sizeof mx_color);
	memset(mx_ic, -7, sizeof mx_ic);
	scanf("%d", &n);

	n *= 3;

	for(int i = 0; i < n; i++) scanf("%d", a + i);

	add(0, 1, 0);

	for(int i = 2; i + 2 < n; i += 3) {
		for(int pos = 0; pos < 3; pos++) {
			int b = 0, c = 0;
			while(b == pos) b++;
			while(c == pos or c == b) c++;
			b += i, c += i;
			for(int j = 0; j < i; j++) {
				int &ans = dp[j][pos];
				ans = 0;
				if(a[b] == a[c]) {
					ans = max(ans, get_ind_col(j, a[b]) + 1);
				}
				ans = max(ans, get_ind(j));
			}
		}
		int tmp = 0;
		for(int j = 0; j < i; j++) {
			tmp = max(tmp, get_ind(j));
		}
		for(int p1 = 0; p1 < 3; p1++) for(int p2 = p1 + 1; p2 < 3; p2++) {
			int p3 = 0;
			while(p3 == p1 or p3 == p2) p3++;
			int &ans = dp2[p1][p2];
			ans = 0;
			ans = max(ans, get_col_col(a[i + p3]) + 1);
			ans = max(ans, tmp);
		}

		if(a[i] == a[i + 1] and a[i + 1] == a[i + 2]) lazy_inc();

		for(int pos = 0; pos < 3; pos++) {
			for(int j = 0; j < i; j++) {
				add(j, i + pos, dp[j][pos]);
			}
		}
		for(int p1 = 0; p1 < 3; p1++) for(int p2 = p1 + 1; p2 < 3; p2++) {
			add(i + p1, i + p2, dp2[p1][p2]);
		}
	}

	int ans = 0;

	ans = max(ans, get_col_col(a[n - 1]) + 1);
	for(int i = 0; i < n - 1; i++) {
		ans = max(ans, get_ind(i));
	}

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


Measured memory_bytes: 50984
program main
implicit none
integer N,A,B,sum,i,k,M
 
read(*,*) N,A,B
 
sum=0
do i = A, N
	k=0
    M=i
	do while(M/=0)
		k = k + mod(M,10)
        M = M/10
    enddo
	if(k>=A.and.k<=B)then
    	sum = sum + i
	endif
enddo
 
write(*,*) sum
end program

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

checker = [k]
x = k
while x > 1 :
    x /= 2
    checker.append(x)

percentage = []
for i in range(len(checker)):
    percentage.append(1/(n*2**i))

answer = 0
for i in range(1,n+1):
    for j in range(len(checker)):
        if i >= checker[j]:
            answer += percentage[j]
            break

print(answer)


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 1001001001
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;
 



int main (){
    int s; cin >> s;
       int first = s/100, latter = s%100;
       
    if(1<=first && first<=12){
        if(1<=latter && latter<=12){
            cout << "AMBIGUOUS" << endl;
            return 0;
        }else{
            cout << "MMYY"<< endl;
            return 0;
        }
    }
    else{
        if(1<=latter && latter<=12){
            cout << "YYMM" << endl;
            return 0;
        }else{
            cout << "NA" << endl;
            return 0;
            
        }
    }


}


Measured memory_bytes: 256
#include <stdio.h>


main(){

  int n,o,p,q,i;

  scanf("%d",&n);

  p=0;
  q=1;

  for(i=0; i<=n; i++){
    o=p+q;
    p=q;
    q=o;
  }
  printf("%d\n",p);

  return 0;
}

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

class unionfind{ // 0-indexed
public:
	vector<int> parent;
	vector<int> size;
	int num_of_disjointsets;
	unionfind(int n){
		parent.resize(n, -1);
		size.resize(n, 1);
		num_of_disjointsets = n;
	}

	int find(int x){
		if(parent[x] == -1) return x;
		return parent[x] = find(parent[x]);
	}

	int unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return -1;
		if(size[x] < size[y]){
			parent[x] = y;
			size[y] += size[x];
			--num_of_disjointsets;
			return y;
		}else{
			parent[y] = x;
			size[x] += size[y];
			return x;
			--num_of_disjointsets;
		}
	}

	bool united(int x, int y){
		return find(x) == find(y);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	unionfind uf(n);
	while(q--){
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) uf.unite(x, y);
		else cout << (uf.united(x, y) ? 1 : 0) << "\n";
	}
}


Measured memory_bytes: 3256
#include<iostream>

using namespace std;

int main(void)
{

	int N,K,i,ans=0;

	int h[100010];

	cin >> N >> K;

	for(i=0;i<N;i++)
	{

		cin >> h[i];

	}

	for(i=0;i<N;i++)
	{

		if(h[i]>=K)
			ans++;
	}

	cout << ans << endl;

}




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
template<class T>inline bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

int dp[30][(1<<21)+10];

int main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n,vector<int>(n));
    for range(i,n) for range(j,n) cin >> a[i][j];
    dp[0][0] = 1;
    for range(i,n){
        for range(s,1<<n){
            if (dp[i][s] != 0) for range(j,n){
                if (!(s&(1<<j)) && a[i][j]){
                    dp[i+1][s|(1<<j)] += dp[i][s];
                    dp[i+1][s|(1<<j)] %= mod;
                }
            }
        }
    }
    cout << dp[n][(1<<n)-1] << endl;
}

Measured memory_bytes: 164096
N = int(input())
B = list(map(int, input().split()))
A=[]

for i in range(0,N):
    if i == 0:
        A.append(B[0])
    elif i == N-1:
        A.append(B[N-2])
    else:
        A.append(min(B[i],B[i-1]))

print(sum(A))

Measured memory_bytes: 3060
#include <iostream> 
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
	int x,m,r=90;
	double ansX=0,ansY=0;
	char com;
	while(1){
		cin>>m>>com>>x;
		if(m==0&&x==0)break;
		ansX+=m*cos(3.1415*r/180);
		ansY+=m*sin(3.1415*r/180);
		r-=x;
	}
	cout<<(int)ansX<<endl<<(int)ansY<<endl;
    return 0;
}

Measured memory_bytes: 1164
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt=0

for i in range(n):
    for j in range(i+1,n):
        distance=0
        for k in range(d):
            distance += (x[i][k]-x[j][k])**2
        if (distance**0.5).is_integer():
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
import itertools
n,k = map(int,input().split())
ans = 0
l = []
for i in range(k) :
    d = int(input())
    l.append(input().split())

l = list(itertools.chain.from_iterable(l))
l = [int(i) for i in l]

for i in range(1,n+1) :
    if not i in l :
        ans += 1
print(ans)

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 450555;
const int L = 21;
const int M = 2155;

ll a[N], b[N], c[N];
void solve(){
    int x,y,n,m,k;
    cin >> x >> y >> n >> m >> k;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++){
        cin >> b[i];
    }
    for (int i = 1; i <= k; i++){
        cin >> c[i];
    }

    sort(a+1, a+n+1);
    sort(b+1, b+m+1);
    sort(c+1, c+k+1);

    ll sum = 0;
    VLL v;
    for (int i = n-x+1; i <= n; i++){
        sum += a[i];
        v.PB(a[i]);
    }
    for (int i = m-y+1; i <= m; i++){
        sum += b[i];
        v.PB(b[i]);
    }

    sort(v.begin(), v.end());
    int z = 0;
    for (int i = k; i >= 1; i--){
        if (c[i] > v[z]){
            sum -= v[z];
            sum += c[i];
            z++;
        }
    }

    cout << sum;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

int h[2], s[2];

int main()
{
    for (int i = 0; i < 2; i++)
        cin >> h[i] >> s[i];
    for (int i = 0; ; i++)
    {
        h[(i & 1) ^ 1] -= s[i & 1];
        if (h[(i & 1) ^ 1] <= 0)
        {
            if (i & 1)
                cout << "No";
            else
                cout << "Yes";
            return 0;
        }
    }
	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

class UFTree {
private:
	static const int	UFTREE_NODE_NUM = 100001;
	int mNode[UFTREE_NODE_NUM];
	int mRank[UFTREE_NODE_NUM];
	int mNodeNum[UFTREE_NODE_NUM];

public:
	void init(int n)
	{
		for (int i = 0; i < n; i++) {
			mNode[i] = i;
			mRank[i] = 0;
			mNodeNum[i] = 1;
		}
	}

	int find(int x)
	{
		if (mNode[x] == x) {
			return x;
		}
		else {
			mNode[x] = find(mNode[x]);
			return mNode[x];
		}
	}

	void unite(int x, int y)
	{
		int idxX = find(x);
		int idxY = find(y);

		if (idxX == idxY) {
			return;
		}

		if (mRank[idxX] > mRank[idxY]) {
			mNode[idxY] = idxX;
			mNodeNum[idxX] += mNodeNum[idxY];
		}
		else {
			mNode[idxX] = idxY;
			mNodeNum[idxY] += mNodeNum[idxX];
			if (mRank[idxX] == mRank[idxY]) {
				mRank[idxY]++;
			}
		}
	}

	bool isSameSet(int x, int y)
	{
		return find(x) == find(y);
	}

	int getNodeNum(int x)
	{
		auto node = find(x);
		return mNodeNum[node];
	}
};

UFTree tree;

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

	for (auto i = 0; i < M; ++i)
	{
		cin >> A[i] >> B[i];
	}

	vector<long long> result(M);

	auto num = ((long long)N) * (N - 1) / 2;
	result[M - 1] = num;
	tree.init(N);

	for (int i = M - 1; i >= 1; --i)
	{
		if (tree.isSameSet(A[i], B[i]))
		{
			result[i - 1] = result[i];
			continue;
		}

		long long numA = tree.getNodeNum(A[i]);
		long long numB = tree.getNodeNum(B[i]);

		num -= numA * (N - numA);
		num -= numB * (N - numA - numB);

		tree.unite(A[i], B[i]);
		num += (numA + numB) * (N - numA - numB);
		result[i - 1] = num;
	}

	for (auto i = 0; i < M; ++i)
	{
		cout << result[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 4096
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = list(input())
n = len(s)
ans = 0
while s:
    s.pop()
    ans +=1
    if len(s) % 2 == 0:
        m = len(s) // 2
        if s[0: m] == s[m:]:
            print(n-ans)
            exit()




Measured memory_bytes: 5176
use std::io::stdin;

fn main() {
    let mut h = String::new();
    let _ = stdin().read_line(&mut h).unwrap();
    let price = h.trim().split(' ').next().unwrap().parse::<u32>().unwrap();
    let mut b = String::new();
    let _ = stdin().read_line(&mut b).unwrap();
    let dislike_nums = b.trim().split(' ').map(|x| x.parse::<u32>().unwrap()).collect::<Vec<_>>();

    let mut payment = price;
    let mut digit = 1;
    while payment >= digit {
        if dislike_nums.iter().any(|&x| x == payment / digit % 10) {
            payment += digit;
        } else {
            digit *= 10;
        }
    };
    digit /= 10;
    let mut flag = false;
    let like_nums = (0..10).filter(|x| dislike_nums.iter().all(|y| y != x)).collect::<Vec<_>>();
    while digit != 0 {
        if flag {
            payment = payment - payment % (digit * 10) + like_nums.iter().min().unwrap() * digit;
        } else if price / digit % 10 < payment / digit % 10 {
            flag = true;
        }
        digit /= 10;
    }
    println!("{}", payment);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int x, y;
	cin >> x >> y;
	print(x + y / 2);
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])

ans = 0
mod = pow(10, 9)+7
for i in range(100):
  c = np.sum((a>>i)&1)
  ans += (c*(n-c)%mod)*pow(2, i, mod)%mod
  ans %= mod

print(ans)

Measured memory_bytes: 68672
#include <bits/stdc++.h>
#define fi first
#define se second
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for(int i = (a); i > (b); --i)
#define REPD(i, a, b) for(int i = (a); i >=(b); --i)
#define TR(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define endl '\n'
#define mp make_pair
#define pb push_back
#define pf push_front
#define ins insert
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define unmap unordered_map
#define pq priority_queue
#define lb lower_bound //first pos >= val
#define ub upper_bound // first pos > val
#define bp __builtin_popcount
#define debug(a) cout << a << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef pair <ll, ld> pld;
typedef pair <ll, pll> pllp;
typedef pair <pll, ll> ppll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pll> vpll;
typedef vector <pii> vpii;
typedef string BigNum;

const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const ld PI = acos(-1);

//Remember limit for IT, etc..., and +1 in limit of any array
const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;
const ll limit2 = 1e3 + 5;
//If TLE let's use int instead of ll because it's as slow as your WPM :)))

/*----IMPORTANT THINGS----*/
pll dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
/*------------------------*/

ll n;
ll a[limit];
ll f[limit];

void solveProblem() {
    f[2] = abs(a[2] - a[1]);
    f[3] = min(f[2] + abs(a[3] - a[2]), abs(a[3] - a[1]));

    REP(i, 4, n) {
        f[i] = min(f[i - 1] + abs(a[i] - a[i - 1]), f[i - 2] + abs(a[i] - a[i - 2]));
    }

    cout << f[n] << endl;
}

void fastInput() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void readInput() {
    cin >> n;
    REP(i, 1, n) cin >> a[i];
}

int main() {
    fastInput();
    readInput();
    solveProblem();
}



Measured memory_bytes: 5116
#include <iostream>
#include <iomanip>
using namespace std;
int calq(int a, char op, int b)
{
	if (op == '+')
		return a + b;
	else if (op == '-')
		return a - b;
	else if (op == '*')
		return a * b;

	return a / b;
}
int main()
{
	//下20桁まで出す処理。たまに精度求められるため記述。
	//cout << fixed << setprecision(20);

	int a, b;
	char op;
	while (cin >> a >> op >> b && op != '?')
	{
		cout << calq(a, op, b) << endl;
	}
	return 0;
}


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

int main() {
    char c;
    cin >> c;
    if (c == 'a' | c == 'i' | c == 'u' | c == 'e' | c == 'o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
using namespace std;
#define ForInt(i, n) for (int i = 0; i < (n); ++i)
#define ForIntInit(i, begin, n) for (int i = (begin); i < (n); ++i)
#define ForItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;



int main()
{
    int n;
    cin >> n;
    map<int, int> a;
    int count;
    ForInt(i, n)
    {
        cin >> count;
        a.emplace(count, i);
    }

    auto itEnd = a.end();
    ForItr(it, a.begin(), itEnd)
    {
        cout << (it == a.begin() ? "" : " ") << (it->second + 1);
    }
    cout << endl;

    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

int main() {

    ll n, m;
    cin >> n >> m;

    if (n > m) swap(n, m);

    if (n == 1 && m == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (n == 1) {
        cout << m - 2 << endl;
        return 0;
    }

    ll center = (m - 2) * (n - 2);

    cout << center << endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.function.DoubleToIntFunction;

public class Main {
    public static void main(String[] args) {

        // Listに標準入力の値を取得
        LinkedList<String> scList = new LinkedList<>();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            while (br.ready()) {
                String[] lineArray = br.readLine().split(" ");
                Arrays.<String>stream(lineArray).forEach(s -> scList.add(s.trim()));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        double r = Double.parseDouble(scList.pop());
        System.out.println(r*Math.PI*2);
    }
}

Measured memory_bytes: 34152
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main()
{
	long long n;
	long long a,b,c,d;
	cin>>a>>b>>c>>d>>n;
	long long best=min(a*4,min(b*2,c));
	if(2*best>d)
	{
		cout<<(n/2)*d+(n%2)*best;
	}
	else
	{
		cout<<best*n;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import os, sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
 
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7

def N(): return int(sys.stdin.readline())
def li(): return list(map(int, sys.stdin.readline().split()))
def bulk_li(): return list(map(lambda s: list(map(int, s.split())), sys.stdin.readlines()))

a, b, c = li()

print(max(0, c - (a - b)))


Measured memory_bytes: 21272
using System;using static System.Console;class P{static void Main(){int t=0,h=0;var s=new int[]{0,1,3};for(int i=0,n=int.Parse(ReadLine());i<n;i++){var a=ReadLine().Split();t+=s[-~a[0].CompareTo(a[1])];h+=s[-~a[1].CompareTo(a[0])];}WriteLine($"{t} {h}");}}


Measured memory_bytes: 18728
n, k = list(map(int ,input().split()))
a = list(map(int ,input().split()))

a.insert(0, 0)
s = [0] * (n+1)
c = [0] * (n+1)

for i in range(1, n+1):
    s[i] = s[i-1] + a[i]
    c[i] = c[i-1] + max(a[i], 0)

res = 0
for i in range(1, n-k+2):
    res = max(res, c[i-1] + max(0, s[i+k-1]-s[i-1]) + c[n] - c[i+k-1])

print(res)

Measured memory_bytes: 16832
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

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

    let mut ans = 0;
    for i in 0..a + 1 {
        for j in 0..b + 1 {
            for k in 0..c + 1 {
                if 500 * i + 100 * j + 50 * k == x {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <fstream>
using namespace std;
typedef long long ll;

int main(){
  int k,n;cin>>k>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
      cin>>v[i];
  }
  int ans=0;
  sort(v.begin(),v.end());
  for(int i=1;i<n;i++)ans=max(ans,v[i+1]-v[i]);
  if(v[n-1]>k/2)ans=max(ans,v[0]+k-v[n-1]);
  cout<<k-ans;
}

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

int main(){
	int n, x_min, x_max, y_min, y_max;
	cin >> x_max >> y_max >> n;
	x_min = 0;
	y_min = 0;
	for(int i= 0; i<n; i++){
		int x, y, a;
		cin >> x >> y >> a;
		switch(a){
		case 1:
			if (x > x_min) x_min = x;
			break;
		case 2:
			if (x < x_max) x_max = x;
			break;
		case 3:
			if (y > y_min) y_min = y;
			break;
		case 4:
			if (y < y_max) y_max = y;
			break;
		}
	}
	if(x_max > x_min && y_max > y_min) {
		cout << (x_max - x_min) * (y_max - y_min);
	} else {
		cout << 0;
	}
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,d;scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  printf("%lld\n",max({a*c,a*d,b*c,b*d}));
}

Measured memory_bytes: 3840
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    
    for i in range(H):
        #for j in range(W):
        if i % 2 == 0:
            for k in range(W):
                if k % 2 == 0:
                    print("#", end = '')
                else:
                    print(".", end = '')
            print("")
        else:
            for k in range(W):
                if k % 2 == 0:
                    print(".", end = '')
                else:
                    print("#", end = '')
            print("")
    print("")


Measured memory_bytes: 7012
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <complex>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#define INF 1<<30
#define EPS 1e-15
#define PB push_back
#define fi first
#define se second
#define rep(i,j) for(int  i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
class edge{
	public:
	int to;
	int cost;
	int state;
	edge(){}
	edge(int _to,int _cost,int _state){
		to = _to;
		cost = _cost;
		state = _state;
	}
	bool operator<(const edge &a)const{
		return cost>=a.cost;
	}
};
int dijkstra(int s,int g,vector<edge> G[128]){
	priority_queue<edge> Q;
	int d[128][5];
	rep(i,128){
		rep(j,5){
			d[i][j] = INF;
		}
	}
	Q.push(edge(0,0,0));
	while(!Q.empty()){
		edge e = Q.top();Q.pop();
		if(d[e.to][e.state]!=INF)continue;
		d[e.to][e.state] = e.cost;
		rep(i,G[e.to].size()){
			if(e.state == 0){
				Q.push(edge(G[e.to][i].to,e.cost+G[e.to][i].cost,0));
				Q.push(edge(G[e.to][i].to,e.cost,1));
			}
			else if(e.state == 1){
				Q.push(edge(G[e.to][i].to,e.cost,2));
			}
			else{
				Q.push(edge(G[e.to][i].to,e.cost+G[e.to][i].cost,e.state));
			}
		}
	}
	int ans = INF;
	ans = min(ans,min(d[g][0],d[g][2]));
	return ans;
}
int main(){
	int n,m;
	while(scanf("%d%d",&n,&m),n){
		vector < edge > G[128];
		rep(i,m){
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			a--;b--;
			G[a].PB(edge(b,c,0));
			G[b].PB(edge(a,c,0));
		}
		printf("%d\n",dijkstra(0,n-1,G));
	}	
	return 0;
}

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

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

int f(int x){
	int ans = 0;
	while(x%2 == 0){
		x /= 2;
		ans++;
	}
	return ans;
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) {
        int a;
        cin >> a;
        A[i] = a / 2;
    }

		int t = f(A[0]);
		rep(i,N){
			if(f(A[i]) != t){
				cout << 0 << endl;
				return 0;
			}
		}

		ll l = 1;
		rep(i,N){
			l = lcm(l,A[i]);
			if(l>M){
				cout << 0 << endl;
				return 0;
			}
		}
		cout << M/l - M/(2*l) << endl;
}

Measured memory_bytes: 1024
import sys
# gcd
# from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
V = lmi()
C = lmi()
good = [V[i] - C[i] for i in range(N)]
good.sort()

cnt = 0
for i in range(N):
    if good[i] >= 0:
        cnt += good[i]

print(cnt)

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

using namespace std;

int main() {
    int n, temp, a, b;
    cin >> n;
    vector<int> v(n+1, 0), dp(n+1, 0);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &v[i]);
    }
    dp[1] = 0;
    for(int i = 2; i <= n; i++) {
        temp = i > 2 ? dp[i-2] + abs(v[i] - v[i-2]) : INT_MAX;
        dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]), temp);
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
w0 = str(input())
list = [w0]
count = 0
for i in range(n-1):
  w = str(input())
  list.append(w)
  if len(list) != len(set(list)) or w0[-1:] != w[:1]:
    print("No")
    count = 1
    break
  w0 = w
if count == 0:
  print("Yes")

Measured memory_bytes: 3060
n = gets.chomp.to_i

class Restaurant
  attr_accessor :s, :p, :i

  def initialize(s, p, i)
    @s = s
    @p = p
    @i = i
  end

  def <=>(other)
    cmp = self.s <=> other.s
    if cmp.zero?
      other.p <=> self.p
    else
      cmp
    end
  end

  def to_s
    "s: #{s}, p: #{p}, i: #{i}"
  end
end

restaurants = []

n.times do |i|
  token = gets.chomp.split(" ")

  restaurants << Restaurant.new(token[0], token[1].to_i, i + 1)
end

puts restaurants.sort.map(&:i)


Measured memory_bytes: 1788
N = int(input())

if N % 2 == 0:
    edge = []
    for s in range(1, N + 1):
        ng = N - s + 1
        for t in range(1, N + 1):
            if s >= t or t == ng:
                continue
            edge.append((s, t))
else:
    edge = []
    for s in range(1, N + 1):
        ng = N - s
        for t in range(1, N + 1):
            if s >= t or t == ng:
                continue
            edge.append((s, t))

print(len(edge))
for s, t in edge:
    print(s, t)

Measured memory_bytes: 3956
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main implements Runnable{

	public static void main(String[] args) {
		new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
	}
	
	public void run() {
		FastScanner sc=new FastScanner();
		int H=sc.nextInt();
		int W=sc.nextInt();
		int N=sc.nextInt();
		int ans=9999999;
		for(int h=0;h<=H;++h) {
			for(int w=0;w<=W;++w) {
				if(H*W-(H-h)*(W-w)>=N)ans=Math.min(ans,h+w);
			}
		}
		System.out.println(ans);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}

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

int main() {
    int N;
    cin >> N;
    int ans = (int)1e5 + 1;
    for (int i = 0; i <= N; ++i) {
        int j = i, count = 0;
        while (j > 0) {
            count += j % 6;
            j /= 6;
        }
        j = N - i;
        while (j > 0) {
            count += j % 9;
            j /= 9;
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
}

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

struct team{ int num, dep; };
#define MAX_N 5000
#define MAX_M 100000
int n, m;
vector<int> beat[MAX_N + 1];
team dat[MAX_N + 1];
team win[MAX_N + 1];
bool used[MAX_N + 1];
bool point[MAX_N + 1];
bool exi[MAX_N + 1] = { false };
bool check[MAX_N + 1];

bool comp(const team& t1, const team& t2){
	return t1.dep < t2.dep;
}
bool comp2(const team& t1, const team& t2){
	return t1.dep > t2.dep;
}

int dfs(int x){
	if(used[x]) return dat[x].dep;
	for(int i = 0; i < beat[x].size(); i++){
		dat[x].dep = max(dat[x].dep, dfs(beat[x][i]) + 1);
		used[beat[x][i]] = true;
	}
	return dat[x].dep + 1;
}

int main(){
	int w, l;
	
	for(int i = 1; i <= MAX_N; i++){
		win[i].num = i;
		dat[i].num = i;
	}
	
	scanf("%d", &n);
	scanf("%d", &m);
	
	for(int i = 0; i < m; i++){
		scanf("%d%d", &w, &l);
		beat[w].push_back(l);
		win[w].dep++;
		exi[w] = true; exi[l] = true;
	}
	
	for(int i = 1; i <= n; i++){
		if(!used[i] && !beat[i].empty()){
			dat[i].dep = dfs(i) + 1;
			used[i] = true;
		}
	}
	
	sort(dat + 1, dat + n + 1, comp);
	
	for(int i = 1; i <= n; i++){
		int id = dat[i].num;
		for(int j = 0; j < beat[id].size(); j++){
			win[id].dep = max(win[id].dep, win[beat[id][j]].dep + 1);
		}
		point[win[id].dep] = true;
	}
	
	sort(win + 1, win + n + 1, comp2);
	
	//順位の出力
	int pt1 = 1, pt2 = 1;
	for(int i = n - 1; i >= 0; i--){
		if(point[i]){
			while(win[pt1].dep == i && pt1 <= n){
				printf("%d\n", win[pt1].num);
				pt1++;
			}
		}
		else{
			while(exi[pt2] && pt2 <= n){ pt2++;}
			if(pt2 <= n) printf("%d\n", pt2);
			pt2++;
		}
	}
	for(int i = 1; i <= n; i++){
		if(!check[win[i].dep]) check[win[i].dep] = true;
		else{
			printf("1\n");
			return 0;
		}
	}
	
	printf("0\n");
	
	return 0;
}

Measured memory_bytes: 1980
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef long long ll;
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"         here"
#define out(value) cout<<value<<en



int main()
{
  int n, m;
  cin >> n >> m;
  
  vector<vector<long long> > x(n, vector<long long>(3));
  for(int i=0; i<n; ++i){
    for(int j=0; j<3; ++j){
      cin >> x[i][j];
    }
  }
  
  long long ans = 0;
  for(int i=0; i<8; ++i){
    bitset<3> bs(i);
    vector<long long> v(n);
    for(int j=0; j<n; ++j){
      for(int k=0; k<3; ++k){
        if(bs[k])
          v[j] += x[j][k];
        else
          v[j] -= x[j][k];
      }
    }
    sort(v.rbegin(), v.rend());
    long long tmp = accumulate(v.begin(), v.begin()+m, 0LL);
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  
  return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string S; cin >> S;
    int count = 0;
    REP(i, S.length())
    {
        if(S[i] == 'o') count++;
    }
    cout << 700 + count * 100 << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
numbers = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [None] * (N + 10)
dp[0] = ""
for i in range(N):
    if dp[i] == None:
        continue
    for k in numbers:
        idx = i + cost[k - 1]
        s1 = dp[i] + str(k)
        s2 = dp[idx]

        if s2 == None or len(s1) > len(s2):
            dp[idx] = s1
        elif len(s1) == len(s2) and s1 > s2:
            dp[idx] = s1
print(dp[N])

Measured memory_bytes: 29044