akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  vector<int> target{a, b, c};
  for(int i = 0; i < n; ++i)
  {
    cin >> l[i];
  }

  do
  {
    do
    {
      // cout << "come\n";
    } while(next_permutation(l.begin(), l.end()));
  } while(next_permutation(target.begin(), target.end()));

  int ans = 1 << 30;
  do
  {
    do
    {
      int ti = 0;
      int cost = 0;
      int now_len = 0;
      for(int li = 0; li < n; ++li)
      {
        if(ti >= 3) continue;
        now_len += l[li];
        int guchoku_cost = abs(now_len - target[ti]);
        int gattai_cost = (li + 1 < n) ? abs(now_len + l[li + 1] - target[ti]) + 10 : 1000000;

        if (guchoku_cost < gattai_cost)
        {
          cost += guchoku_cost;
          now_len = 0;
          ti++;
        }
        else
        {
          cost += 10;
        }
      }
      if (ti >= 3)
      {
        ans = min(ans, cost);
      }
    } while(next_permutation(l.begin(), l.end()));
  } while(next_permutation(target.begin(), target.end()));
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int N, M, X;
int C[14] = {0};
int A[14][14] = {0};

int sumC(int b){
	int ret = 0;
	for(int i=1, p=1; p<=b; p=p*2, i++){
		if((b&p)/p){
			ret+=C[i];
		}
	}
	return ret;
}

int sumA(int b, int j){
	int ret = 0;
	for(int i=1, p=1; p<=b; p=p*2, i++){
		if((b&p)/p){
			ret+=A[i][j];
		}
	}
	return ret;
}

int main(int argc, char* argv[]){
	cin >> N >> M >> X;

	for(int i=1; i<=N; i++){
		cin >> C[i];
		for(int j=1; j<=M; j++){
			cin >> A[i][j];
		}
	}

	int ans = -1;

	for(int b=0; b<(1<<N); ++b){
		int tmpans = 0;
		int x = 0;
		int ng = 0;
		for(int j=1; j<=M; j++){
			x = sumA(b, j);
			if(x<X){
				ng = 1;
				break;
			}
		}
		if(ng==1){
			continue;
		}
		else{
			tmpans = sumC(b);
			if(ans==-1 || ans>tmpans){ ans = tmpans; }
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if ((a+b)%2 == 0){
    cout << (a+b)/2 << endl;
  }
  else {
    cout << (a+b)/2+1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

class DistUnionFind{
public:
    vector<int> par;
    vector<int> dist;
    DistUnionFind(int n){
        init(n);
    }
    void init(int n){
        par.resize(n);
        for(int i=0;i<n;i++){
            par[i] = i;
        }
        dist.assign(n, 0);
    }
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            int prev_par = par[x];
            par[x] = find(par[x]);
            dist[x] += dist[prev_par];
            return par[x];
        }
    }
    void unite(int x, int y, int diff){
        // w_y - w_x = diff
        if(diff < 0){
            swap(x, y);
            diff = -diff;
        }
        if(find(y) != y){
            unite(x, par[y], diff - dist[y]);
            return;
        }
        par[y] = x;
        dist[y] = diff;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

int main(){
    while(true){
        int N, M;
        cin >> N >> M;
        if(N == 0) break;

        DistUnionFind uf(N);
        for(int i=0;i<M;i++){
            char c;
            int a, b;
            cin >> c >> a >> b;
            a--; b--;
            if(c == '!'){
                int w;
                cin >> w;
                if(uf.same(a, b)){
                    assert(uf.dist[b] - uf.dist[a] == w);
                }else{
                    uf.unite(a, b, w);
                }
            }else{
                if(!uf.same(a, b)){
                    cout << "UNKNOWN" << endl;
                }else{
                    cout << uf.dist[b] - uf.dist[a] << endl;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 5312
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n,m;
	int i,j;
	cin >> n >> m;
	int coins[m];
	for(int i=0;i<m;i++)
	{
		cin >> coins[i];	
	}
	sort(coins, coins+m);
	int dp[n+1][m+1];
	for(i=0;i<=n;i++)
		for(j=0;j<=m;j++)
			dp[i][j]=0;

	for(i=0;i<=n;i++)
	{
		dp[i][1]=i;
	}


	for(i=2;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(j-coins[i-1] >= 0)
				dp[j][i] = min(dp[j][i-1], dp[j-coins[i-1]][i]+1);
			else
				dp[j][i] = dp[j][i-1];
		}
	}
	/*for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	cout << dp[n][m] << endl;
	return 0;
}

Measured memory_bytes: 5276
# -*- coding: utf-8 -*-
h, w = map(int,input().split())
s = []
for i in range(h):
    s.append(list(str(input())))

dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
ans = [['' for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            ans[i][j] = '#'
        else:
            tmp = 0
            for k in range(8):
                if 0 <= i + dy[k] < h and 0 <= j + dx[k] < w:
                    if s[i + dy[k]][j + dx[k]] == '#':
                        tmp += 1
            ans[i][j] = str(tmp)
for i in range(h):
    print(''.join(ans[i]))


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 200001

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int par[2][MAX_N];
int myrank[2][MAX_N];

void init(int n)
{
  for (int i = 0; i < n; i++) {
    par[0][i] = i;
    par[1][i] = i;
    myrank[0][i] = 0;
    myrank[1][i] = 0;
  }
}

int find(int x, int i)
{
  if (par[i][x] == x) return x;
  return par[i][x] = find(par[i][x], i);
}

void unite(int x, int y, int i)
{
  x = find(x, i);
  y = find(y, i);
  if (x == y) return;
  if (myrank[i][x] < myrank[i][y]) {
    par[i][x] = y;
  } else {
    par[i][y] = x;
    if(myrank[i][x] == myrank[i][y]) myrank[i][x]++;
  }
}

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

int main()
{
  int N, K, L;
  cin >> N >> K >> L;
  init(N);
  int p, q;
  for (int i = 0; i < K; i++) {
    cin >> p >> q;
    p--; q--;
    unite(p, q, 0);
  }
  int r, s;
  for (int i = 0; i < L; i++) {
    cin >> r >> s;
    r--; s--;
    unite(r, s, 1);
  }

  P idx[MAX_N];
  for (int i = 0; i < N; i++) {
    idx[i] = P(find(i, 0), find(i, 1));
  }

  map<P, int> num;
  for (int i = 0; i < N; i++) {
    num[idx[i]]++;
  }

  for (int i = 0; i < N; i++) {
    cout << num[idx[i]] << endl;
  }

  return 0;
}


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

int main()
{
	string a, b;
	int x;
	int zh(string a);
	
	cin >> a >> b;
	
	x = zh(a+b);
	
	if(int(sqrt(x))==(sqrt(x)))
	  cout << "Yes" << endl;
	else
	  cout << "No" << endl;
	
	return 0;
}

int zh(string s)
{
	int tmp=0;
	for(int i=0; i<s.size(); i++)
   	   tmp = tmp * 10 + s[i] - '0';
   	return tmp;
}

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int[] arr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => int.Parse(hogehoge)).ToArray<int>();

			int min = int.MaxValue;

			int cnt = 0;

			for (int i = 0; i < n; i++)
			{
				if (arr[i] < min)
				{
					cnt++;
					min = arr[i];
				}
			}

			Console.Write(cnt);

		}


	}


}


Measured memory_bytes: 34012
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

type Task struct {
	name string
	time int
}

const MAX = 100000

type Queue struct {
	container [MAX]Task
	head      int
	tail      int
}

func generateQueue() Queue {
	return Queue{head: 0, tail: 0}
}

func (q *Queue) isEmpty() bool {
	return q.head == q.tail
}

func (q *Queue) enqueue(name string, time int) {
	q.container[q.tail] = Task{name: name, time: time}
	q.tail = (q.tail + 1) % MAX
}

func (q *Queue) dequeue() Task {
	task := q.container[q.head]
	q.head = (q.head + 1) % MAX
	return task
}

func main() {
	n := scanInt()
	q := scanInt()

	que := generateQueue()
	for i := 0; i < n; i++ {
		que.enqueue(scanString(), scanInt())
	}

	total := 0
	for !que.isEmpty() {
		task := que.dequeue()

		if task.time > q {
			total += q
			que.enqueue(task.name, task.time-q)
		} else {
			total += task.time
			fmt.Printf("%s %d\n", task.name, total)
		}
	}
}


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

int main() {
	ll h, w, n;
	cin >> h >> w >> n;
	set<pair<ll, ll>> st;
	vector<pair<ll, ll>> p(n);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		p[i] = {a, b};
		st.insert({a, b});
	}
	vector<vector<vector<bool>>> adj(n, vector<vector<bool>>(5, vector<bool>(5, false)));
	rep(i, n) {
		ll a = p[i].first;
		ll b = p[i].second;
		for (int r = -2; r <= 2; r++){
			for (int c = -2; c <= 2; c++){
				if ((a + r < 0) || (a + r >= h) || (b + c < 0) || (b + c >= w)) continue;
				if (st.count({a+r, b+c})) {
					adj[i][r+2][c+2] = true;
				}
			}
		}
	}
	vector<ll> ans(10);
	rep(i, n) {
		ll a = p[i].first;
		ll b = p[i].second;
		for (int r = -2; r <= 0; r++){
			for (int c = -2; c <= 0; c++){
				if ((a + r < 0) || (a + r + 2 >= h) || (b + c < 0) || (b + c + 2 >= w)) continue;
				int cnt = 0;
				for (int x = 0; x < 3; x++){
					for (int y = 0; y < 3; y++){
						if (adj[i][r+x+2][c+y+2]) cnt++;
					}
				}
				ans[cnt]++;
			}
		}
	}
	ll sum = 0;
	rep(i, 10) {
		if (i == 0) continue;
		ans[i] /= i;
		sum += ans[i];
	}
	ans[0] = (h-2) * (w-2) - sum;
	rep(i, 10) cout << ans[i] << endl;
	// rep(i, n) {
	// 	for (int r = 0; r < 5; r++){
	// 		for (int c = 0; c < 5; c++){
	// 			cout << adj[i][r][c] << " ";
	// 		}
	// 		cout << endl;
	// 	}
	// 	cout << endl;
	// }
	return 0;
}

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

vector<int> Eratosthenes(const int N)
{
    std::vector<bool> is_prime(N + 1);
    for (int i = 0; i <= N; i++)
    {
        is_prime[i] = true;
    }
    std::vector<int> P;
    for (int i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (int j = 2 * i; j <= N; j += i)
            {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto &x: A){
        cin >> x;
    }
    
    int v;
    v = A[0];
    for (auto x:A) {
        v = gcd(v, x);
    }
    if (v != 1) {
        cout << "not coprime" << endl;
    }
    else {
        int cnt = 0;
        set<int> st;
        
        for (auto &x:Eratosthenes(1000)) {
            cnt = 0;
            for (auto &y: A) {
                if (y%x == 0) {
                    y /= x;
                    cnt += 1;
                }
            }
            if (cnt >= 2) {
                cout << "setwise coprime" << endl;
                exit(0);
            }
        }

        for (auto &x : A)
        {
            if (x != 1)
            {
                if (st.count(x) != 0)
                {
                    cout << "setwise coprime" << endl;
                    exit(0);
                }
                else
                {
                    st.insert(x);
                }
            }
        }
        
        cout << "pairwise coprime" << endl;
    }
    return 0;
}


Measured memory_bytes: 7568
#include <stdio.h>
#include <string.h>

int main()
{
  int a,b;
  char line[256];
  int out=0;
  int i;

  scanf("%d %d\n%s",&a,&b,line);


  for(i=0; i<a; i++)
  {
    if(line[i] < 48 || line[i] > 57) out++;
    // printf("1:%d\n",out);
  }
  if(line[i] != '-') out++;
  for(i=i+1; i<a+b+1; i++)
  {
    if(line[i] < 48 || line[i] > 57) out++;
    // printf("3:%d\n",out);
  }

  if(out == 0)
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

int main(){
	int num;
	std::string str;
	const std::string wrong_word("Hoshino");
	const std::string right_word("Hoshina");
	std::cin >> num;
	std::cin.ignore();
	
	while(num != 0){
		std::getline(std::cin, str);
		std::string::size_type pos = str.find(wrong_word);
		
		while(pos != std::string::npos){
			str.replace(pos, wrong_word.length(), right_word);
			pos = str.find(wrong_word);
		}
		
		std::cout << str << std::endl;
		--num;
	}
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
	int n,s=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		for(int i=x;i<=y;i++)
		a[i]=1;
	}
	for(int i=1;i<=100000;i++)
	if(a[i]==1)++s;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 640
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break

    cnt = 0

    for a in range(1, x // 3):
        for b in range(a + 1, x // 2):
            c = x - a - b
            if b < c <= n:
                cnt += 1

    print(cnt)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define pq priority_queue
#define rep(i,n) for (int i=1;i<=n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
int n; 
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    if (n%10==9||n/10==9) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String s = sc.next();
			if(s.compareTo("0000")==0)break;
			
			String[] f = new String[4];
			int count=0;
			int L, S;
			while(true){
				if(s.compareTo("6174")==0){
					System.out.println(count);
					break;
				}
				for(int i=0;i<4;i++){
					f[i] = s.substring(i,i+1);
				}
				if(f[0].compareTo(f[1])==0 && f[1].compareTo(f[2])==0 && f[2].compareTo(f[3])==0){
					System.out.println("NA");
					break;	
				}
				Arrays.sort(f);
				L = Integer.valueOf(f[3])*1000 + Integer.valueOf(f[2])*100 + Integer.valueOf(f[1])*10 + Integer.valueOf(f[0]);
				S = Integer.valueOf(f[0])*1000 + Integer.valueOf(f[1])*100 + Integer.valueOf(f[2])*10 + Integer.valueOf(f[3]);
				s = Integer.toString(L-S);
				count++;
				if(s.length()==1){
					s = "000" + s;
				}else if(s.length()==2){
					s = "00" + s;
				}else if(s.length()==3){
					s = "0" + s;
				}
			}
		}
		
	}	
}

Measured memory_bytes: 46488
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
    int N;
    SCD(N);
    vector<ll> a(N);
    vector<PII> ans;
    int Min,min;
    ll M,m;

    REP(i,N){
        SCLLD(a[i]);
    }

    M = a[0]; Min = 0;
    m = a[0]; min = 0;

    REP(i,N){
        if (chmax(M,a[i])) Min = i;
        if (chmin(m,a[i])) min = i;
    }

    int mode = 0;
    if (m >= 0) mode = 1;
    if (M <= 0) mode = -1;
    //cout << M << " " << m << " " << Min << " " << min << " " << mode << "\n";
    if (mode == 0){
        if (M >= -m){
            REP(i,N){
                if (i == Min) continue;
                a[i] += a[Min];
                ans.PB(MP(Min+1,i+1));
                mode = 1;
            }
        }else{
            REP(i,N){
                if (i == min) continue;
                a[i] += a[min];
                ans.PB(MP(min+1,i+1));
                mode = -1;
            }
        }
    }

    if (mode == 1){
        REP(i,N-1){
            a[i+1] += a[i];
            ans.PB(MP(i+1,i+2));
        }
    }else{
        REPr(i,N-1){
            a[i] += a[i+1];
            ans.PB(MP(i+2,i+1));
        }
    }

    int outm = ans.size();
    PRINTD(outm);

    REP(i,outm){
        printf("%d %d\n",ans[i].fst,ans[i].snd);
    }

}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;
 
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=1e6+5;

int n,w;
int a[N][3];
int dp[105][N];

int go(int pos,int wei)
{
    if(wei>w) return -1e15;
    if(pos==n+1)
        return 0;
    int &ans=dp[pos][wei];
    if(ans!=-1)
        return ans;
    ans=max(go(pos+1,wei),a[pos][2]+go(pos+1,wei+a[pos][1]));
    return ans;

}

int32_t main()
{
    IOS;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
    {
        for(int j : {1,2})
            cin>>a[i][j];
    }
    memset(dp,-1,sizeof(dp));
    cout<<go(1,0)<<endl;
    
}

Measured memory_bytes: 821504
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,k=gsmi
a=gsmi

n.times do |i|
  h[a[i]]+=1
end

ar = h.to_a.map{|i|i[1]}.sort
size=ar.size
putsend 0 if size<=k

size-=k
puts sum(ar[0,size])

Measured memory_bytes: 43776
#include <stdio.h>

int main(void) {
  int n, i, j, k, l, count;

  while (scanf("%d", &n) != EOF) {
    count = 0;
    for (i = 0; i < 10; i++)
      for (j = 0; j < 10; j++)
	for (k = 0; k < 10; k++)
	  for (l = 0; l < 10; l++)
	    if (i + j + k + l == n)
	      count++;

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

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string s;
    cin>>s;
    if(s=="RRS" or s=="SRR")cout<<2;
    else if(s=="RRR")cout<<3;
    else if(s=="SSR" or s=="SRS" or s=="RSS" or s=="RSR")cout<<1;
    else cout<<0;
    
    return 0;
}

Measured memory_bytes: 3588
n = int(input())
data = [int(s) for s in input().split()]

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)


x = gcd(data[0], data[1])
for i in range(2,n-1):
    x = gcd(x,data[i])
print(x)


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

using namespace std;

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	int64_t n, k;
	cin >> n >> k;

	// we take the smaller of these two values:

	// n % k is what we'd be left over with if we stopped before negatives
	// k - (n % k) is what we'd be left over with (positive) if we did one more
	cout << min(n % k, abs((n % k) - k));
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
while(true){
String A=scan.next();
String B=scan.next();
int a=Integer.parseInt(A);
int b=Integer.parseInt(B);
if(a==0&&b==0)
	break;
int okiba;
if(a>b){
okiba=a;
a=b;
b=okiba;
}
System.out.println(a+" "+b);
}
}
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, a, b, c, d, o, l, h;

int main() {
	cin >> n >> a >> b >> c >> d;
	o = b-a;
	// C〜Dをi回だけ足すことに決めると-D〜-Cをn-i-1回足すことになる
	rep(i,n) {
		l = -d*(n-i-1) + c*i;
		h = -c*(n-i-1) + d*i;
		if (l<=o && o<=h) {
			cout << "YES" << ln;
			return 0;
		}
	}
	cout << "NO" << ln;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    x,y,z,n = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    a.sort(reverse=1)
    b.sort(reverse=1)
    c.sort(reverse=1)
    res = []
    hq = [[-(a[0]+b[0]+c[0]), 0, 0, 0]]
    heapq.heapify(hq)
    check = set([(0, 0, 0)])
    for _ in range(n):
        cost, i, j, k = heapq.heappop(hq)
        res.append(-cost)
        if i+1<x and not (i+1, j, k) in check:
            heapq.heappush(hq, [-(a[i+1]+b[j]+c[k]), i+1, j, k])
            check.add((i+1, j, k))
        if j+1<y and not (i, j+1, k) in check:
            heapq.heappush(hq, [-(a[i]+b[j+1]+c[k]), i, j+1, k])
            check.add((i, j+1, k))
        if k+1<z and not (i, j, k+1) in check:
            heapq.heappush(hq, [-(a[i]+b[j]+c[k+1]), i, j, k+1])
            check.add((i, j, k+1))
    for i in res:
        print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 54232
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")


#include <bits/stdc++.h>
using namespace std;

#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


typedef long long int lli;
typedef long long ll;
typedef long double ld;

typedef vector<lli> vi;
typedef pair<lli,lli> pi;
typedef vector<pi> vpi;


#define FOR(i,x,n) for(lli i=x;i<n;i++)
#define RFOR(i,x,n) for(lli i=x;i>=n;i--)
#define pb push_back
#define Resize(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unique_sort(c) (sort(c.begin(),c.end()), Resize(c))
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) (lli)x.size()
#define fs first
#define ss second
#define mp make_pair
#define lb '\n'
#define gc getchar()
#define pc(x) putchar(x)
#define il inline void
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
 
 
const lli mod=1e9+7;

template <typename T>
inline void read(T &r){ static char c; r=0; int f=1; for(c=gc; c<'0'||c>'9'; c=gc) if(c=='-')f=-1; 
	for(; c>='0'&&c<='9'; r=(r<<1)+(r<<3)+(c^48),c=gc); r*=f; } 

template <typename T, typename... Args>
inline void read(T& r, Args&... args) { read(r); read(args...); }


template<class T>il print(T x){ if(x>=10) print(x/10); pc(x%10+'0'); }
template<class T>il printt(T x){ if(x<0) pc('-'),x=-x; print(x); pc(10);}
template <typename T, typename... Args> il print(T x, Args&... args) {print(x); pc(32); print(args...); }
template <typename T, typename... Args> il printt(T x, Args&... args) {print(x); pc(32); print(args...); pc(10); }

template<typename T>inline void rdstr(T& x){static char c;  for(c=gc; c!=10 ; c=gc)x.push_back(c);}
template<typename T>inline void prstr(T x){lli i=0; while(i<x.size()){pc(x[i]); i++;} pc(10);}

template <typename T1, typename T2> inline void chkmin(T1 &a, const T2 & b) {if (a > b) a = b;}
template <typename T1, typename T2> inline void chkmax(T1 &a, const T2 & b) {if (a < b) a = b;}


int main()
{
    fast()
    lli t; read(t);
    lli sum = 0;
    FOR(i,1,t+1)
    {
        if(i%3!=0 && i%5!=0)sum+=i;
    }
    print(sum);
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll ans=0,tmp=INF;
    rep(i,n){
        if(abs(n*a[i]-sum)<tmp){
            ans=i;
            tmp=abs(n*a[i]-sum);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;


void solve_old(long long A, long long B, long long C, long long D){
    ll ret =0;
    if (B <= C || D <= A)
    {
        ret = 0;
    } else if (A <= C && C < B && B <= D)
    {
        ret = B - C;
    } else if (C <= A && A < D && D <= B)
    {
        ret = D - A;
    } else if (A <= C && D <= B)
    {
        ret = D - C;
    } else if (C <= A && B <= D)
    {
        ret = B -A;
    }
    cout << ret << "\n";
}

void solve(long long A, long long B, long long C, long long D){
    cout << max((ll)0, min(B,D)-max(A,C)) << "\n";
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
using vint = std::vector<int>;
using vvint = std::vector<std::vector<int>>;
using namespace std;
ll mod = 1e9 + 7;

/*int <= 10^9*/
/*10^5までは全探索できる*/

int main() {


  int N; cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
	string tmp = to_string(i);
	if (tmp.size() % 2 == 1)ans++;
  }
  cout << ans;


  return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
sort_P = sorted(P)
cnt = 0

for i in range(len(P)):
    if (P[i] != sort_P[i]):
        cnt += 1

if (cnt <= 2):
    ans = 'YES'
else:
    ans = 'NO'

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while(left < right) {
		mid = (left + right) / 2;
		if(A[mid] == key) return 1;
		if(key < A[mid]) right = mid;
		else if(key > A[mid]) left = mid+1; 
	}
	return 0;	
}

int main() {
	int i, q, key, sum = 0;
	
	scanf("%d", &n);
    for(int i = 0; i < n; i++) { 
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    for(int i = 0; i < q; i++) {
	    scanf("%d", &key);
		if( binarySearch(key)) sum++; 
	}
	printf("%d\n", sum);
	
	return 0;    
}
  

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		cout << max(0, n - 2*m) << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

void createPrim(){
	int index=0;
	for(int x=11;x<=55555;x+=30){
		int z=0;
		for(int y=2;y!=x;++y){
			if(x%y==0)++z;
        }
		if(z==0)prime.push_back(x);
	}
}

int main(){
	ios::sync_with_stdio(false);
	int a;
	vector<int>select;
	createPrim();
	cin>>a;
	for(int i=0;i<prime.size();++i){
		if(prime[i]%5==1)select.push_back(prime[i]);
		if (select.size()==a)break;
	}
	for(int i=0;i<select.size();++i){
		cout<<select[i];
		if(i==select.size()-1)cout<<"\n";
		else cout<<" ";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int D = sc.nextInt();

        System.out.println(solve(D));

        sc.close();
    }

    static String solve(int D) {
        if (D == 25) {
            return "Christmas";
        } else if (D == 24) {
            return "Christmas Eve";
        } else if (D == 23) {
            return "Christmas Eve Eve";
        } else {
            return "Christmas Eve Eve Eve";
        }
    }
}

Measured memory_bytes: 35460
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n)cin >> l[i];

    sort(all(l));
    int ans = 0;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < i; j++) {
            for(int k = 0; k < j; k++) {
                if(l[i] != l[j] && l[j] != l[k] && l[k]+l[j] > l[i]) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3548
#include "bits/stdc++.h"
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
	ios_base::sync_with_stdio(0);
	int a,b,n,x,T,cas=0;
	cin>>n>>x;
	if(n*500>=x) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc127/tasks/abc127_c>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,M; cin >> N >> M;
    ll l = 1,r = N;
    for(int i = 0; i < M;i++){
        ll L,R; cin >> L >> R;
        l = max(l,L);
        r = min(r,R);
    }
    res = max(r-l+1,0LL);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <unistd.h>
#include <stdio.h>

int main(void)
{
  char s[4];
  scanf("%s", s);
  if ((s[0] == 'A' && s[1] == 'A' && s[2] == 'A') || (s[0] == 'B' && s[1] == 'B' && s[2] == 'B'))
  {
    write(1, "No", 2);
    return 0;
  }
  write(1, "Yes", 3);
  return 0;
}

Measured memory_bytes: 128
# https://atcoder.jp/contests/abc043/tasks/abc043_b

"""
双方向キューをつかって実装する

このどれかの操作ができる
* 0 をキューに入れる
* 1 をキューに入れる
* キューの最後のものを出す

注意: キューが空の場合にバックスペースをしても何も起きないようにする
"""

from collections import deque

q = deque()

s = input()
for operation in s:
    if operation == "0":
        # 右端に0を追加
        q.append("0")

    elif operation == "1":
        # 右端に1を追加
        q.append("1")

    elif operation == "B":
        # バックスペース
        # 右端を一つ削除
        # q の中身が空でもエラーにならないように例外処理
        try:
            q.pop()
        except IndexError:
            pass # 何もしない

# キューの中身を順番に取り出して文字列に変換
answer = ""
for i in q:
    answer = answer + i

print(answer)


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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);
#define inf INT_MAX
char arr[100][101];
int cnt[100][100];

int main(){
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;++i)
		cin>>arr[i];
	for(int i=0;i<h;++i)
		for(int j=0;j<w;++j){
			if(!i&&!j)continue;
			int left=j?cnt[i][j-1]+(arr[i][j]!=arr[i][j-1]):inf;
			int top=i?cnt[i-1][j]+(arr[i][j]!=arr[i-1][j]):inf;
			cnt[i][j]=min(left,top);
		}
//	for(int i=0;i<h;++i,cout<<endl)
//		for(int j=0;j<w;++j)
//			cout<<cnt[i][j]<<" ";
	int res=cnt[h-1][w-1];
	res=res/2+res%2+(!(res%2)*arr[0][0]=='#');
	cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a < b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return a / gcd(a, b)*b;

}
//最小公倍数

ll ncr(ll n, ll r) {

	ll ret = 1;
	for (ll i = 0; i < r; i++) {
		ret *= n - i;
		ret /= i + 1;
	}
	return ret;

}

int main() {
	
	int N, P, even = 0, odd = 0;
	ll ans = 0;
	cin >> N >> P;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a % 2 == 0)even++;
		else odd++;
	}
	if (P == 0) {
		ans = pow(2, even);
		ll tmp = 0;
		for (int i = 0; i <= odd; i += 2) {
			tmp += ncr(odd, i);
		}
		ans *= tmp;
		cout << ans << endl;
	}
	else {
		ans = pow(2, even);
		ll tmp = 0;
		for (int i = 1; i <= odd; i += 2) {
			tmp += ncr(odd, i);
		}
		ans *= tmp;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()
p2=0
p1=0
if n==1:
  print(0)
  exit()
if s[0]=="L":
  p1+=1
if s[n-1]=="R":
  p1+=1
  
for i in range(1,n):
  if not (s[i]=="L" and s[i-1]=="R"):
    continue
  p2+=1
if k<=p2-1:
  print(n-2*p2-p1+2*k)
elif p2-1<k<p2+p1:
  print(n-p1+(k-p2))
else:
  print(n-1)


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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (i * 500 + j * 100 + k * 50 == x)
                    ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

LL F(LL a, LL b) {
  int one = 0, two = 0;
  while(a > 0) {
    one++;
    a /= 10;
  }
  while(b > 0) {
    two++;
    b /= 10;
  }
  return max(one, two);
}

int main() {
  ios_base::sync_with_stdio(false);
  LL n;
  cin >> n;
  LL res = 1e9;
  for(LL d = 1; d*d <= n; d++) {
    if(n % d == 0) {
      res = min(res, F(d, n/d));
    }
  }
  if(res == 1e9) {
    assert(false);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    while((H != 0) || (W != 0)){
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((i == 0) || (i == H - 1) || (j == 0) || (j == W - 1)){
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
 
//  cout <<  << endl;
//  printf("%f\n",x);
}


Measured memory_bytes: 3068
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i<n; i++) {
			a[i] = sc.nextInt();
    	}
		System.out.println(minsort(a));
		
	}
	public static int myindex(int[] a,int b){
		for (int i=0;i<a.length;i++){
			if (a[i]==b) {
				return i;
			}
		}
		return -1;
	}
	public static int minsort(int[] a){
		int [] sorted=a.clone();
		Arrays.sort(sorted);
		int n=a.length;
		int cost=0;
		for (int i=0;i<n;i++){
			int cnt=0;
			int c1= myindex(a,sorted[i]);
			while (c1!=i){
				cnt++;
				int c2= myindex(a,sorted[c1]);
				cost+=a[c2];
				int work=a[c2];
				a[c2]=a[c1];
				a[c1]=work;
				c1=c2;
			}
			cost+=Math.min(sorted[i]*cnt, sorted[i]*2+sorted[0]*(cnt+2));
		}
		return cost;
	}
}

Measured memory_bytes: 31580
#include <stdio.h>
int main(void)
{
    int n,i,count = 0;
    char s[50];
    scanf("%d %s",&n,s);
    for(i = 0 ; i <= n-3 ; i++)
    {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
            count++;
        }
    }
    
    
    
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 1692
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;

void main() {
  int n = readln.chomp.to!int, ans;
  bool[int] mp;

  foreach(i; 0..n) {
    int d = readln.chomp.to!int;
    // keyが連想配列に登録されているかどうか 
    if ((d in mp) == null) {
      ans++;
      mp[d] = true;
    }
  }

  ans.writeln;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n,x;
  cin>>n>>x;
  vll a(n);
  vll b(n);
  rep(i,n) {
    cin>>a[i];
    b[i]=a[i];
  }
  ll ans=0;
  rep(i,n-1){
    if(a[i]+a[i+1]>x){
      ll k=a[i]+a[i+1]-x;
      if(k>=a[i+1]){
        a[i+1]=0;
        k-=a[i+1];
        a[i]-=k;
        ans+=k;
      }
      else{
        a[i+1]-=k;
        ans+=k;
      }
    }
  }
 
  COUT(ans);
}


Measured memory_bytes: 1792
import array;R=range;L=input;T=[0]*28;N=int(L());S=[[ord(C)-95 for C in L()]for _ in[0]*N];U=N*26**2*array.array('i',[0]);V=N*[0];Q=int(L())
for X in S:
	P=0
	for C in X:
		if T[P+C]==0:T[P+C]=len(T);T+=[0]*28
		T[P]+=1;P=T[P+C]
	T[P]+=1;T[P+1]=1
while N:
	N-=1;P=0
	for C in S[N]:
		for A in R(26):X=T[P+A+2];U[676*N+26*A+C-2]+=T[X]*(X and A!=C-2)
		V[N]+=T[P+1];P=T[P+C]
while Q:K,P=L().split();K=int(K)-1;P=[ord(C)-97 for C in P];X=1+V[K]+sum(U[676*K+26*P[A]+P[B]]for A in R(26)for B in R(A+1,26));print(X);Q-=1

Measured memory_bytes: 405176
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization ("Ofast")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b) {
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if(a<b){a=b;return true;}
	return false;
}
template<class T> inline int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=998244353;
constexpr int inf=3e18;


signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int a,b,c,d;cin>>a>>b>>c>>d;
	rep(i,5000){
		if(i%2==0){
			c-=b;
			if(c<=0){
				cout<<"Yes\n";return 0;
			}
		}else {
			a-=d;
			if(a<=0){
				cout<<"No\n";return 0;
			}
		}
	}
}


Measured memory_bytes: 3652
# coding: utf-8
n = int(input())
data = []
for i in range(n):
    a, b = map(str, input().split())
    data.append([float(a), b])

jpy_sum = 0
btc_sum = 0
for j in range(n):
    if data[j][1] == 'JPY':
        jpy_sum += data[j][0]
    else:
        btc_sum += data[j][0]

print(jpy_sum + 380000.0 * btc_sum)


Measured memory_bytes: 3060