akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
int n[5],i=1;
int main()
{
    for(;i<=4;i++)
    	scanf("%1d",&n[i]);
    (n[1]==n[2]&&n[2]==n[3])||(n[2]==n[3]&&n[3]==n[4])?printf("Yes\n"):printf("No\n");
}

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

int main()
{
  int N,K,i,j,count=0;
  int *A,*B;

  scanf("%d",&N);
  A=(int *)malloc(sizeof(int)*N+1);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  scanf("%d",&K);
  B=(int *)malloc(sizeof(int)*K);
  for(i=0;i<K;i++) scanf("%d",&B[i]);

      

  
  for(i=0;i<K;i++)
    {
      j=0;
      A[N]=B[i];
      while(A[j]!=B[i])
	{
	  j++;
	}
      if(j!=N) count=count+1;
      
    }

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


  return 0;
}




Measured memory_bytes: 2108
n = input()

d = {3: 0b001, 5: 0b010, 7: 0b100}

dp = [[[0] * 2 for _ in range(1 << 3)] for _ in range(len(n) + 1)]
dp[0][0][1] = 1

for i, e in enumerate(n):
    e = int(e)
    for num in [0, 3, 5, 7]:
        if num == 0:
            dp[i+1][0b000][0] += sum(dp[i][0b000])
            continue
        for j in range(1 << 3):
            if num == e:
                dp[i+1][j|d[num]][1] += dp[i][j][1]

            elif num < e:
                dp[i+1][j|d[num]][0] += dp[i][j][1]

            dp[i+1][j|d[num]][0] += dp[i][j][0]

ans = sum(dp[len(n)][0b111])
print(ans)


Measured memory_bytes: 9256
#include <stdio.h>

int main(void)
{
	int x;
	int y;
	
	for (x = 1; x < 10; x++){
		for (y = 1; y < 10; y++){
			printf("%dx%d=%d\n", x, y, x * y);
		}
	}
	
	return (0);
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int asd[200005];
int asd1[200005];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>asd[i];
		asd1[i]=asd[i];
	}
	sort(asd1,asd1+n);
	int t=(n+1)/2-1;
	for(int i=0;i<n;i++)
	{
		int a=lower_bound(asd1,asd1+n,asd[i])-asd1;
		if(a<=t)
		{
			cout<<asd1[t+1]<<endl;
		}
		else
		{
			cout<<asd1[t]<<endl;
		}
		
	}
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int s[m][2];
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            cin >> s[i][j];
        }
    }

    int minimum = INT_MAX;
    int maximum = 1;
    for(int i = 0; i < m; i++){
        minimum = min(s[i][1], minimum);
        maximum = max(s[i][0], maximum);
    }

    int ans = minimum - maximum + 1;
    if(ans < 0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

ll digitcal(ll x){
  ll n=0;
  while(x>0){
    x/=10;
    n++;
  }
  return n;
}

int main() {
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(char i='0';i<='9';i=(char)(((int)(i-'0')+1)+'0')){
    for(char j='0';j<='9';j=(char)(((int)(j-'0')+1)+'0')){
      for(char k='0';k<='9';k=(char)(((int)(k-'0')+1)+'0')){
        string temp="";
        temp+=i;temp+=j;temp+=k;
        //cout<<temp<<endl;
        int now=0;
        for(int l=0;l<n;l++){
          if(s[l]==temp[now]){
            now++;
          }
          //cout<<now<<endl;
          if(now==3) break;
        }
        //cout<<now<<endl;
        if(now==3) ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3688
s = input()
length = len(s)
cnt = 0
if length % 2 == 0:
    f = s[:length // 2]
    l = s[length // 2:]
    lr = l[::-1]

    for i in range(len(f)):
        if f[i] != lr[i]:
            cnt += 1
else:
    f = s[:length // 2]
    l = s[length // 2 + 1:]
    lr = l[::-1]
    # print(f, l)
    for i in range(len(f)):
        if f[i] != lr[i]:
            cnt += 1

print(cnt)

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

int b;

vector<int> divisor(int n){
    vector<int> res;
    for (int i=1;i*i<=n;++i) if (n%i==0){
        res.emplace_back(i);
        if (i!=n/i) res.emplace_back(n/i);
    }
    return res;
}

void solve(){
    vector<int> cand=divisor(2*b);
    int M=0,ans0,ans1;
    for (int c:cand){
        int a=2*b/c+1-c;
        if (a<=0||a&1) continue;
        if (M<c) ans0=a/2,ans1=c;
    }
    cout << ans0 << ' ' << ans1 << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> b,b) solve();
}


Measured memory_bytes: 3200
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String N = in.next();
		String[] Array = N.split("");
		int a = 0;
		
		for(int i=0; i<Array.length; i++) {
			a += Integer.parseInt(Array[i]);
		}
		
		if(a % 9 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 65148
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    a: i64,
    }

     println!("{}", a+ a*a + a*a*a);
}


Measured memory_bytes: 2112
h,w = map(int,input().split())
x = [''.join(["#"]*(w+2))]
s = x+["#"+input()+"#" for _ in range(h)]+x
ans = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":
            continue
        checked = [[False]*(w+2) for _ in range(h+2)]
        checked[i][j]=True
        stack=[[i,j]]
        stack_=[]
        count = 1
        while stack:
            pair=stack.pop()
            for x,y in [[1,0],[-1,0],[0,1],[0,-1]]:
                if s[pair[0]+x][pair[1]+y]=="." and checked[pair[0]+x][pair[1]+y] == False:
                    stack_.append([pair[0]+x,pair[1]+y])
                    checked[pair[0]+x][pair[1]+y] = True
            if stack==[]:
                stack = stack_.copy()
                stack_ = []
                count += 1

        ans = max(ans,count)
        
print(ans-2)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
const int INF=1001001001;
int main() {
	int n,k;

	cin>>n>>k;
	vector<int> a(n);
	rep(i,n) cin >>a[i];
	sort(a.begin(),a.end());
	int ans=0;
	rep(i,k){
		ans+=a[i];
	}
	cout << ans<<endl;
	return 0;
}


Measured memory_bytes: 3628
n, m = map(int, input().split())
a = list(map(int, input().split()))
cb = [list(map(int, input().split()[::-1])) for _ in range(m)]
a.sort()
cb.sort()
summation = 0
a_tmp = a.pop()
cb_tmp = cb.pop()
for i in range(n):
  if a_tmp >= cb_tmp[0]:
    summation += a_tmp
    if a:
      a_tmp = a.pop()
  else:
    summation += cb_tmp[0]
    cb_tmp[1] -= 1
    if cb_tmp[1] == 0:
      if cb:
        cb_tmp = cb.pop()
      else:
        cb_tmp = [0, n]
print(summation)

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

int minCost(int n,int cost[],int dp[])
{
    if(n==1)
    {
        return 0;
    }
    if(n==2)
    {
        return abs(cost[1]-cost[0]);
    }
    if(dp[n]!=-1)
    {
        return dp[n];
    }
    int cost1 = abs(cost[n-1]-cost[n-2]) + minCost(n-1,cost,dp);
    int cost2 = abs(cost[n-1]-cost[n-3]) + minCost(n-2,cost,dp);
    dp[n] = min(cost1,cost2);
    return dp[n];
}



int main()
{
    int n;
    cin>>n;
    int cost[n];
    for(int i=0;i<n;i++)
    {
        cin>>cost[i];
    }
    int dp[n+1];
    for(int i=0;i<=n;i++)
    {
        dp[i] = -1;
    }
    cout<<minCost(n,cost,dp);

}


Measured memory_bytes: 12184
n, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
    print(n)
elif sum(a) < x:
    print(n-1)
else:
    a = sorted(a)
    total = 0
    for i in range(n):
        total += a[i]
        if total == x:
            print(i+1)
            exit()
        elif total > x:
            print(i)
            exit()


Measured memory_bytes: 3060
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
  int H,W;
  cin >> H >> W;
  char S[H+2][W+2];
  REP(i,H) REP(j,W) cin >> S[i][j];

  int dx[]={1,-1,0,0}, dy[]={0,0,1,-1};
  bool ans = true;
  REP(i,H) {
    REP(j,W) {
      if (S[i][j]=='#') {
        bool found=false;
        REP(k,4)
        {
          int i2 = i + dx[k];
          int j2 = j + dy[k];
          if (i2>=0 && i2<H && j2>=0 && j2<W && S[i2][j2]=='#')
            found=true;
        }
        if (!found) ans = false;
      }
    }
  }

  cout << (ans?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    plglg P[N];
    REP(i, 0, N) {
        ll p;
        cin >> p;
        P[i] = plglg(p, i);
    }
    sort(P, P + N);
    ll ans = 1;
    ll tmp = 1;
    REP(i, 0, N - 1) {
        if (P[i].second < P[i + 1].second) {
            tmp++;
        } else {
            ans = max(ans, tmp);
            tmp = 1;
        }
    }
    ans = max(ans, tmp);
    cout << N - ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int i;
    int pos=-1,ans=0;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='A')
        {
            pos=i;
            break;
        }
    }
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='Z')
        {
            ans=max(ans,i-pos+1);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from collections import deque
def resolve():
    k=int(input())
    E=[[] for _ in range(k)]
    for i in range(k):
        E[i].append(((i+1)%k,1))
        E[i].append(((10*i)%k,0))

    # 0-1 BFS
    dist=[INF]*k
    dist[1]=0
    Q=deque([1])
    while(Q):
        v=Q.popleft()
        for nv,w in E[v]:
            if(dist[nv]<=dist[v]+w): continue
            dist[nv]=dist[v]+w
            if(w==0): Q.appendleft(nv)
            else: Q.append(nv)
    print(dist[0]+1)
resolve()

Measured memory_bytes: 62004
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    long long A, B, N; cin >> A >> B >> N;
    long long x = min(B-1, N);
    long long ans, l, r;
    l = A * x / B;
    r = x / B;
    ans = l - A * r;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
n, a, b = map(int, input().split())
x = list(map(int, input().split()))

ans = 0
for i in range(1, n):
    if a * (x[i]-x[i-1]) < b:
        ans += a * (x[i]-x[i-1])
    else:
        ans += b
print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define int long long
#define rep(i,m,n) for(int i=m;i<n;i++)
#define repr(i,n,m) for(int i=n;i>=m ;i--)
#define MOD 1000000007
#define float long double
#define pb push_back
#define mp make_pair
#define pp pop_back
#define pi 3.141592653589793238
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
bool sortbysec(const pair<int,int> &a,
             const pair<int,int> &b)
{
   return (a.second < b.second);
}
int lcm(int a, int b)  
 {  
    return (a*b)/__gcd(a, b);  
 }  
bool sortinrev(const pair<int,int> &a,  
              const pair<int,int> &b)
{
      return (a.first > b.first);
}
void solve()
{
	int a,b,n;
	cin>>a>>b>>n;
	int x=min(b-1,n);
	cout<<(a*x)/b-a*(x/b);
}    
signed main()
{
                    // #ifndef ONLINE_JUDGE
                    // freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
                    // #endif 
  int t=1;
 //cin>>t;
  while(t--){
  solve();
}
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
 return 0;
}  

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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
//int a[N+2];

int32_t  main(){
	IOS;
  char ch;cin>>ch;
  if(ch=='A')cout<<"T"<<endl;
  if(ch=='T')cout<<"A"<<endl;
  if(ch=='C')cout<<"G"<<endl;
  if(ch=='G')cout<<"C"<<endl;


  return 0;
}



Measured memory_bytes: 256
import sys

cin = sys.stdin
N, = map(int, cin.readline().split())
if N==1:
    print(1)
    exit(0)

x = [None] * N
for i in range(N):
    x[i] = tuple(map(int, cin.readline().split()))
x.sort()

from collections import Counter
c = Counter()
for i in range(N):
    for j in range(i):
        x0d, x1d = x[i][0] - x[j][0], x[i][1] - x[j][1]
        c[(x0d, x1d)] += 1
cMax = max(c.values())
print(N - cMax)



Measured memory_bytes: 3552
#組み合わせ個数
def choose(n, r, mod)
  return 0 if not (0 <= r and r <= n)
  return 1 if r == 0 or r == n
  fact(n, mod) * inverse(fact(r, mod) * fact(n-r, mod) % mod, mod) % mod
end
#階乗(MODあり)
@fact = [1]
def fact(n, mod)
  if n > @fact.size then
    f = @fact[-1]
    (@fact.size+1..n).each{|i|
      f = (f * i) % mod
      @fact << f
    }
  end
  @fact[n-1]
end
#逆元(MODあり)
def inverse(x, mod)
  pow(x, mod-2, mod)
end
#べき乗(MODあり)(繰り返し２乗法)
def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

N, K = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)
MOD = 10 ** 9 + 7

A.sort!
ans = 0
(0..(N - K)).each{|i|
  ans = (ans + (A[N - 1 - i] - A[i]) * choose(N - 1 - i, K - 1, MOD)) % MOD
}

puts ans


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

void solve(long long A, long long B){
    if (A <= 8 && B <= 8) cout << "Yay!" << '\n';
    else cout << ":(" << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

bool n, e, w, s;

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

    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'N') n = true;
        if (S[i] == 'E') e = true;
        if (S[i] == 'W') w = true;
        if (S[i] == 'S') s = true;
    }

    cout << (n ^ s || e ^ w ? "No" : "Yes") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0) break;
		vi x(n+1),y(n+1),prime(n+1);
		fill(prime.begin(),prime.end(),1);
		prime[0]=prime[1]=0;
		for(int i=2;i<=n;i++) if(prime[i]) for(int j=2*i;j<=n;j+=i) prime[j]=0;
		int I=3,d=1,id=2;
		for(int i=0;id<=n;i++){
			for(int j=0;id<=n&&j<=i/2;j++){
				x[id]=x[id-1]+dx[I];
				y[id]=y[id-1]+dy[I];
				id++;
			}
			(I+=1)%=4;
		}
		int mnx=inf,mxx=-inf,mny=inf,mxy=-inf;
		for(int i=1;i<=n;i++){
			mnx=min(mnx,x[i]);
			mxx=max(mxx,x[i]);
			mny=min(mny,y[i]);
			mxy=max(mxy,y[i]);
		}
		int h=mxx-mnx+1,w=mxy-mny+1;
		vvi a(h,vi(w)),dp(h,vi(w,-inf));
		for(int i=1;i<=n;i++) a[x[i]-mnx][y[i]-mny]=i;
//		for(int i=0;i<h;i++){
//			for(int j=0;j<w;j++) cout<<prime[a[i][j]]<<' ';cout<<endl;
//		}
		for(int i=0;i<w;i++) if(a[h-1][i]) dp[h-1][i]=prime[a[h-1][i]];
//		cout<<'A'<<endl;
//		cout<<h<<' '<<w<<endl;
		for(int i=h-2;i>=0;i--){
			for(int j=0;j<w;j++) if(a[i][j]){
			dp[i][j]=0;
			if(a[i+1][j]) dp[i][j]=max(dp[i][j],dp[i+1][j]);
			if(j&&a[i+1][j-1]) dp[i][j]=max(dp[i][j],dp[i+1][j-1]);
			if(j<w-1&&a[i+1][j+1]) dp[i][j]=max(dp[i][j],dp[i+1][j+1]);
			if(prime[a[i][j]]) dp[i][j]++;
		}
		}
//		for(int i=0;i<h;i++){
//			for(int j=0;j<w;j++) cout<<(dp[i][j]<0?-1:dp[i][j])<<' ';cout<<endl;
//		}
		int X=x[m]-mnx,Y=y[m]-mny;
//		cout<<X<<' '<<Y<<endl;
//		cout<<dp[X][Y]<<endl;
		if(dp[X][Y]==0) cout<<0<<' '<<0<<endl;
		else{
			cout<<dp[X][Y]<<' ';
			queue<P> q;
			q.push({X,Y});
			int res=0;
			vvi b(h,vi(w));
			b[X][Y]=1;
			while(!q.empty()){
				P p=q.front();
				q.pop();
				X=p.first,Y=p.second;
				if(X+1<h&&a[X][Y]&&!b[X+1][Y]&&dp[X][Y]==dp[X+1][Y]+prime[a[X][Y]]){
					b[X+1][Y]=1;
					q.push({X+1,Y});
				}
				if(X+1<h&&Y+1<w&&a[X][Y+1]&&!b[X+1][Y+1]&&dp[X][Y]==dp[X+1][Y+1]+prime[a[X][Y]]){
					b[X+1][Y+1]=1;
					q.push({X+1,Y+1});
				}
				if(X+1<h&&Y-1>=0&&a[X][Y-1]&&!b[X+1][Y-1]&&dp[X][Y]==dp[X+1][Y-1]+prime[a[X][Y]]){
					b[X+1][Y-1]=1;
					q.push({X+1,Y-1});
				}
				if(dp[X][Y]==1&&prime[a[X][Y]]) res=max(res,a[X][Y]);
			}
			cout<<res<<endl;
		}
	}
}


Measured memory_bytes: 26612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int m = sc.NextInt();

        bool even = n % 2 == 0;


        int step = (m - 1) * 2 + 1;
        for (int i = 0; i < m; i++)
        {
            int l = i;
            if (even && i * 2 >= m)
            {
                l++;
            }
            int r = n - i - 1;
            Console.WriteLine((l + 1) + " " + (r + 1));
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 37676
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;
 
#define LL long long
const int mod = 1e9 + 7;
LL dp[66][2][2],L, R; 
 
LL dfs(int x, bool Left, bool Right, bool zero) {
    if(x < 0) return 1; 
    if(dp[x][Left][Right] >= 0 && !zero) 
        return dp[x][Left][Right]; 
    LL ans = 0;
    int l = 0, r = 1; 
    if(Left) l = L >> x & 1; 
    if(Right) r = R >> x & 1; 
    for(int i = l ; i <= 1 ; i++) {
        for (int j = i ; j <= r ; j++) {
            if (j == 1 && zero) {
                if(i == 1) ans += dfs(x-1, Left && i == l, Right && j == r, zero && j == 0); 
            }
            else ans += dfs(x-1, Left && i == l, Right && j == r, zero && j == 0); 
        }
    }
    ans %= mod; 
    if(!zero) dp[x][Left][Right] = ans; 
    return ans; 
}
int main() {
    scanf("%lld%lld",  & L,  & R); 
    memset(dp, -1, sizeof(dp)); 
    printf("%lld \n", dfs(60, 1, 1, 1)); 
    //system("pause");
    return 0; 
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    long long n,m;cin>>n>>m;
    vector<long long> num(n,1),r(n,0);
    r[0] = 1;
    for(int j=0;j<m;++j){
        int x,y;cin>>x>>y;
        x--;
        y--;
        num[x]--;
        num[y]++;
        if(r[x]==1)r[y]=1;
        if(num[x]==0)r[x]=0;
    }
    long long res = 0;
    for(int i=0;i<n;++i){
        res+=r[i];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()

const ll inf=0x3f3f3f3f3f3f3f3f;
const ll N = 3e3 + 3;

vector<vector<pair<ll, pii>>> dp(N, vector<pair<ll, pii>>(N, {0, {0, 0}}));

int main() {
    SPEED;
    string s, t;
    cin>>s>>t;
    ll n1 = s.size(), n2 = t.size();
    s = '?' + s;
    t = '?' + t;
    for(ll i = 1; i <= n1; i++) {
    	for(ll j = 1; j <= n2; j++) {
    		if(s[i] == t[j]) {
    			dp[i][j] = {dp[i - 1][j - 1].fi + 1, {i - 1, j - 1}};
    		}
    		else {
    			if(dp[i - 1][j].fi > dp[i][j - 1].fi) {
    				dp[i][j] = {dp[i - 1][j].fi, {i - 1, j}};
    			}
    			else {
    				dp[i][j] = {dp[i][j - 1].fi, {i, j - 1}};
    			}
    		}
    	}
    }
    pii crr = {n1, n2};
    string ans;
    while(crr.fi != 0 && crr.se != 0) {
    	if(dp[crr.fi][crr.se].se.fi == crr.fi - 1 && dp[crr.fi][crr.se].se.se == crr.se - 1) {
    		ans.pb(s[crr.fi]);
    	}
    	crr = dp[crr.fi][crr.se].se;
    }
    reverse(all(ans));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 215128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  //最大値がr以下で作れる
  int l = 0, r = N;
  while(r-l>1){
    ll m = (l+r)/2;
    if(m*(m+1)/2 >= N)r = m;
    else l = m;
  }
  perr(x,1,r+1){
    if(x>N)continue;
    cout << x << endl;
    N-=x;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <math.h>
#include <algorithm>
#include<queue>
#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)

main(){
    long a, b, tall = 0;
    cin >> a >> b;
    FOR(i, 0, b - a - 1){
        tall += i + 1;
    }
    cout << tall - a << endl;
}

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

class Dice{
  
public:
  int TOP = 2, FRONT = 0, LEFT = 4, RIGHT = 1, BACK = 5, BOTTOM = 3;
  vector<int> val;
  Dice():val(6){for(int i=0;i<6;i++) val[i] = i;}
  Dice(int val[6]){for(int i=0;i<6;i++) this->val[i] = val[i];}
  Dice(vector<int> val):val(val){assert(val.size()==6);}
  int& operator [](int a){return val[a];}
  
  void rotN(){
    swap(val[TOP],val[FRONT]);
    swap(val[FRONT],val[BOTTOM]);
    swap(val[BOTTOM],val[BACK]);
  }
  
  void rotS(){
    swap(val[TOP],val[BACK]);
    swap(val[BACK],val[BOTTOM]);
    swap(val[BOTTOM],val[FRONT]);
  }
  
  void rotE(){
    swap(val[TOP],val[LEFT]);
    swap(val[LEFT],val[BOTTOM]);
    swap(val[BOTTOM],val[RIGHT]);
  }
  
  void rotW(){
    swap(val[TOP],val[RIGHT]);
    swap(val[RIGHT],val[BOTTOM]);
    swap(val[BOTTOM],val[LEFT]);
  }
  
  void rotCW(){
    swap(val[FRONT],val[RIGHT]);
    swap(val[RIGHT],val[BACK]);
    swap(val[BACK],val[LEFT]);
  }
  
  void rotCCW(){
    swap(val[FRONT],val[LEFT]);
    swap(val[LEFT],val[BACK]);
    swap(val[BACK],val[RIGHT]);
  }
  
};

Dice dice[4][30];
int N, ans;
int ID[4];

void cal(){
  
  int cnt = 0;
  
  for(int i=0;i<6;i++){
    
    unordered_map<int,int> A;
    
    for(int j=0;j<N;j++) A[dice[j][ID[j]][i]]++;
    
    int maxc = 0;
    
    for(auto p : A ) maxc = max( maxc, p.second );
    
    cnt += N - maxc;
    
  }
  
  ans = min( ans, cnt );
  
}

void dfs(int x){
  
  if( x == N ){
    cal();
    return;
  }
  
  for(int i=0;i<24;i++){
    ID[x] = i;
    dfs( x + 1 );
  }
  
}

int main(){
  
  while(1){
    
    cin>>N;
    if( N == 0 ) break;
    
    vector<string> d[4];
    map<string,int> memo;
    int idx = 0;
    
    for(int i=0;i<N;i++){
      
      for(int j=0;j<6;j++){
	string s;
	cin>>s;
	d[i].push_back(s);
	if( memo.count(s) == 0 ) memo[s] = idx++;
      }
                  
    }
    
    Dice di[4];
    
    for(int i=0;i<N;i++){
      
      vector<int> A;
      
      for(int j=0;j<6;j++){
	
	A.push_back( memo[d[i][j]] );
	
      }
      
      di[i] = Dice(A);
      
    }
        
    for(int I=0;I<N;I++){
      
      int idx = 0;
      
      for(int i=0;i<4;i++){
    
	for(int j=0;j<4;j++){
	  
	  dice[I][idx++] = di[I];
      
	  di[I].rotCW();
      
	}
    
	di[I].rotN();
	
      }

      for(int i=0;i<4;i++){
      
	if(i%2){
      
	  for(int j=0;j<4;j++){
      
	    dice[I][idx++] = di[I];
      
	    di[I].rotCW();
      
	  }
      
	}
	
	di[I].rotE();
	
      }
      
      
    }
    
    for(int i=0;i<N;i++){
      
      vector<int> A;
      
      for(int j=0;j<6;j++){
	
	A.push_back( memo[d[i][j]] );
	
      }
      
      di[i] = Dice(A);
      
    }
    
    ans = 100;
    
    dfs( 1 );
    
    cout<<ans<<endl;
    
  }
  
  return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MOD 1000000007
#define MAX 55
#define PMAX 55
#define PRECISION 0.00000000001
#define INF 2000000000
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int main()
{
    int x;
    scanf("%d",&x);
    int kyu=(2000-x)/200+((2000-x)%200>0);
    printf("%d",kyu);
    return 0;
}


Measured memory_bytes: 3824
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse=True)

ok = A[-1] * F[0]
ng = 0

while ok-ng>1:
    mid = ng + (ok-ng)//2
    trainings = 0
    for i in range(N):
        t = A[i]-mid//F[i]
        if t > 0:
            trainings += t
    if trainings <= K:
        ok = mid
    else:
        ng = mid
trainings = 0
for i in range(N):
    t = A[i]-ng//F[i]
    if t>0:
        trainings += t
if trainings<=K:
    print(ng)
else:
    print(ok)

Measured memory_bytes: 113768
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long n,a[100005],f[100005];
int main()
{
	scanf("%lld",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	f[n-1]=0;
	f[n-2]=abs(a[n-2]-a[n-1]);
	for(int i=n-3;i>=0;i--)
	{
		f[i]=min(abs(a[i]-a[i+1])+f[i+1],abs(a[i]-a[i+2])+f[i+2]);
	}
	printf("%lld",f[0]);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
	int a[6];
	int b[6];
int main()
{
	
	for(int i=0;i<6;i++)
	{
		cin>>a[i];
		b[a[i]]++;
		if(b[a[i]]==3)
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	
	return 0;
}

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

ans = [0 for i in range(len(h))]

for i in range(len(ans)-2, -1, -1):
  if h[i] >= h[i + 1]:
    ans[i] = ans[i + 1] + 1
print(max(ans))



Measured memory_bytes: 14252
//
// Created by Akifumi Ohata on 2017/09/30.
//


#include<iostream>
#include <vector>
#include <numeric>
#include <math.h>
#include <cmath>

using namespace std;

using ll =  long long int;

int main() {

    int N;


    cin >> N ;


    vector<int> arrayA;

    for(int g=0;g<N;g++){
        int tmp;
        cin >> tmp;
    arrayA.push_back(tmp);
    }


    std::vector<int> arrayB;

    int start=0;
    if(N%2==0){
        arrayB.push_back(arrayA[1]);
        arrayB.push_back(arrayA[0]);
        start=2;
    } else{
        arrayB.push_back(arrayA[0]);
        start=1;
    }


    for(int i=start; i < N;i+=2){

        arrayB.push_back(arrayA[i]);
        arrayB.insert(arrayB.begin(),arrayA[i+1]);
    }


    for(const int &p : arrayB){

        cout << p << " ";
    }

}

Measured memory_bytes: 4076
from math import isinf

V, E = map(int, input().split())
d = [[float('inf') for i in range(V)] for j in range(V)]

for i in range(V):
    d[i][i] = 0
    
for i in range(E):
    s, t, w = map(int,input().split())
    d[s][t] = w
    
for k in range(V):
    for i in range(V):
        for j in range(V):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
            
for i in range(V):
    if d[i][i] < 0:
        print('NEGATIVE CYCLE')
        exit()

for di in d:
    print(' '.join( ('INF' if isinf(dij) else str(dij) for dij in di)))

Measured memory_bytes: 8476
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  int N, M; cin >> N >> M;

  vector <int> G1[N], G2[N];
  vector < pair<ll, int> > graph[N];

  for (int i = 0; i < M; i++){
    int A, B; ll C; cin >> A >> B >> C;
    A--; B--; C = -1 * C;
    G1[A].push_back(B);
    G2[B].push_back(A);
    graph[A].push_back(make_pair(C, B));
  }
  
  vector <bool> C1(N), C2(N);
  queue <int> que1, que2;

  que1.push(0); C1[0] = true;
  while (!que1.empty()){
    int Q = que1.front(); que1.pop();
    for (int i = 0; i < G1[Q].size(); i++){
      int next = G1[Q][i];
      if (C1[next] == false){
        C1[next] = true;
        que1.push(next);
      }
    }
  }

  que2.push(N - 1); C2[N - 1] = true;
  while (!que2.empty()){
    int Q = que2.front(); que2.pop();
    for (int i = 0; i < G2[Q].size(); i++){
      int next = G2[Q][i];
      if (C2[next] == false){
        C2[next] = true;
        que2.push(next);
      }
    }
  }

  bool flag = false;
  vector <ll> dist(N);
  fill(dist.begin() + 1, dist.end(), 1e16);

  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      for (int k = 0; k < graph[j].size(); k++){
        ll cost = graph[j][k].first;
        int next = graph[j][k].second;

        if (dist[j] != 1e16 && dist[next] > dist[j] + cost){
          dist[next] = dist[j] + cost;
          if (i == N - 1 && C1[j] == true && C2[next] == true){
            flag = true;
          }
        }
      } 
    }
  }
  
  if (flag == true){
    cout << "inf" << endl;
  }else{
    cout << -1 * dist[N - 1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>

using namespace std;

int main() {
  int N;
  cin >> N;
  map<string, int> m;
  int count = 0;
  for (int i = 0; i < N; ++i) {
    string s;
    cin >> s;
    if (m.count(s)) {
      ++(m[s]);
    } else {
      m.insert(make_pair(s, 1));
    }
    if (count < m[s]) {
      count = m[s];
    }
  }
  for (auto item : m) {
    if (item.second == count) {
      cout << item.first << '\n';
    }
  }
  cout << flush;
  return 0;
}


Measured memory_bytes: 25216
n=int(input())

def keta(x):
    k = 0
    while(x>0):
        k+=1
        x = int(x/10)
    return k

s=[]
for i in range(1,int(n**0.5)+1):
    if n%i != 0:
        continue
    b=n/i
    f_ab=max(keta(i),keta(b))
    s.append(f_ab)
print(min(s))


Measured memory_bytes: 40432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sca = new Scanner(System.in);
		int a = sca.nextInt();
		int b = sca.nextInt();
		int c = sca.nextInt();
		int temp = 0;
		temp = a;
		a = b;
		b = temp;

		temp = a;
		a = c;
		c = temp;
		System.out.print(a);
		System.out.print(" ");
		System.out.print(b);
		System.out.print(" ");
		System.out.print(c);
		System.out.println("");

		// 後始末
		sca.close();
	}
}

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

int main(){
  string a,b;
  cin >> a >> b;
  int c = stoi(a+b);
  for(int i=0; i<c; i++){
    if(i*i == c){
       cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
while(1){
int H,W;
cin>>H>>W;
if(H == 0 && W == 0) break;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){

cout<<"#";
}
cout<<endl;
}
cout<<endl;
} 
return 0;
}


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    ll a,b,x;
    cin >> a >> b >> x;

    if(a > 0){
        cout << b / x - (a - 1) / x << endl;
    }else{
        cout << b / x + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
inline int D()
{
    int t;
    scanf("%d",&t);
    return t;
}
inline ll llD()
{
    ll t;
    scanf("%lld",&t);
    return t;
}

const int Max=1e6+9;
const int OO=-1e6;
int st[4]= {1,0,0,-1};
int nt[4]= {0,1,-1,0};
int n,m;
bool valid(int x,int y)
{
    return x>-1 && y>-1 && x<n && y<m;
}
ll mem[Max];
void init()
{
    memset(mem,-1,sizeof mem);
}
//////////////////////////////////////////////////////////

ll a[Max];

ll solve (int i )
{
    if(i==n-1)return 0;
    if(i>=n)
        return Max;

    ll &ret=mem[i];
    if(~ret)return ret;

    ll take1 =solve(i+1)+abs(a[i]-a[i+1]);
    ll take2 =solve(i+2)+abs(a[i]-a[i+2]);

     return mem[i]=min(take2,take1);
}

void Fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
}
int main()
{
   init();
   n =D();
   for(int i=0; i<n;i++)
   {
       a[i]=llD();
   }
   printf("%lld",solve(0));

}


Measured memory_bytes: 18608
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
 
public class Main {
	
	public static final long MOD = 1000000007;
	
	public static long[][] mat_mut(final int N, long[][] mat1, long[][] mat2){
		long[][] ret = new long[N][N];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				for(int k = 0; k < N; k++) {
					ret[i][j] += mat1[i][k] * mat2[k][j];
					ret[i][j] %= MOD;
				}
			}
		}
		
		return ret;
	}
	
	public static long[][] mat_fact(final int N, long[][] mat, final long K){
		if(K == 1) {
			return mat;
		}else if(K % 2 == 1) {
			return mat_mut(N, mat, mat_fact(N, mat, K - 1));
		}else {
			final long[][] ret = mat_fact(N, mat, K / 2);
			return mat_mut(N, ret, ret);
		}
	}
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int A = sc.nextInt();
			final int B = sc.nextInt();
			
			int fst = 0, snd = 0, thd = 0;
			for(int i = 0; i < N; i++) {
				final int P = sc.nextInt();
				
				if(P <= A) {
					fst++;
				}else if(A < P && P <= B) {
					snd++;
				}else {
					thd++;
				}
			}
			
			System.out.println(Math.min(Math.min(fst, snd), thd));
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21460
N,M = map(int,input().split())
AB_list = []
ans = 0
for i in range(N):
    AB_list.append(list(map(int,input().split())))
AB_list.sort(key = lambda x:x[0])
for i in range(N):
    if(M>=AB_list[i][1]):
        ans += AB_list[i][0]*AB_list[i][1]
        M -= AB_list[i][1]
        if(M==0):
            break
    else:
        ans += AB_list[i][0]*M
        
        break
print(ans)



Measured memory_bytes: 28428
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int N = sc.nextInt();
		int ac  = 0;
		int wa  = 0;
		int tle = 0;
		int re  = 0;

		for(int i = 0; i < N; i++) {
			String S = sc.next();
			if(S.equals("AC")) {
				ac++;
			}else if(S.equals("WA")) {
				wa++;
			}else if(S.equals("TLE")) {
				tle++;
			}else if(S.equals("RE")) {
				re++;
			}
		}

		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);
	}

}


Measured memory_bytes: 49200
class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;

  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n:number):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n:number):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
  f(roop:number, callback:any){
    for(let i=0;i<roop;i++){
      callback(i);
    }
  };
  Yes(){
    console.log('Yes');
  }
  No(){
    console.log('No');
  }
  YES(){
    console.log('YES');
  }
  NO(){
    console.log('NO');
  }
}
const m = () => {
  const o = new AtCoder()
  let [a,b,c,d] = o.nn(4);
  let f=1
  while(a>0&&c>0){
    if(f){
      c-=b
      f=0
    }else {
      a-=d
      f=1
    }
  }
  if(a<=0){
    o.No()
  }else{
    o.Yes()
  }
}
m();

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

vector<long long>vec;
long long a[1001],b[1001],c[1001];
	
int main(){
	long long x,y,z,k;
	cin>>x>>y>>z>>k;

	

	for(int i=0;i<x;++i)
		cin>>a[i];
	for(int i=0;i<y;++i)
		cin>>b[i];
	for(int i=0;i<z;++i)
		cin>>c[i];
		
	sort(a,a+x,greater<long long>());
	sort(b,b+y,greater<long long>());
	sort(c,c+z,greater<long long>());
	
	for(long long i=0;i<x;++i)
		for(long long j=0;j<y;++j)
			for(long long l=0;l<z;++l){
				if((i+1)*(j+1)*(l+1)<=k){
					vec.push_back(a[i]+b[j]+c[l]);
					continue;}
				else break;
			}
	sort(vec.begin(), vec.end(), greater<long long>());
	for(long long i=0;i<k;++i)
		cout<<vec[i]<<endl;
	return 0;
}

Measured memory_bytes: 1400
N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得
#print(s) #出力：['s_1', 's_2', 's_3', 's_N']
set = set(s)
#print(set)
print(len(set))

Measured memory_bytes: 35528
#include <iostream>
 
using namespace std;
 
int main() {
  int N;
  long long int sum = 0;
  cin >> N;
  
  for (int i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  
  cout << sum;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define forabr(i, a, b) for(int i = int(b)-1; i >= int(a); i--)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 4e5;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    vi a(n);
    forn(i, n) a[i] = s[i] - '0';
    if (p == 2 || p == 5) {
        ll ans = 0;
        forn(i, n) if (a[i] % p == 0) ans += i + 1;
        cout << ans << "\n";
        return 0;
    }
    map<int, int> cnt;
    ll ans = 0, pw = 1;
    int cur = 0;
    cnt[0] = 1;
    fornr(i, n) {
        cur = (cur + a[i] * pw) % p;
        ans += cnt[cur];
        cnt[cur]++;
        pw = (pw * 10) % p;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1684
#include <stdio.h>
#include <string.h>
 
int main()
{
    int i, n, h, len;
    char str[201], temp[201];

    for(;;) {
        scanf("%s", str);
        if (strcmp(str, "-") == 0) {
            break;
        }
        len = strlen(str);
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
            scanf("%d", &h);
            strcpy(temp, str);
            strcpy(str, &temp[h]);
            strncpy(&str[len - h], temp, h);
            str[len] = '\0';
        }
        printf("%s\n", str);
    }
    return 0;
}

Measured memory_bytes: 596
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define maxn 101000

LL mymin(LL x,LL y){return (x<y)?x:y;}
LL mymax(LL x,LL y){return (x>y)?x:y;}
int main()
{
	int n,i;LL x,mx,mn;
	scanf("%d",&n);
	mx=mn=-1;
	for (i=1;i<=n;i++) 
	{
		scanf("%lld",&x);
		if (mn==-1) mn=x;
		if (mx==-1) mx=x;
		mn=mymin(mn,x);
		mx=mymax(mx,x);
	}
	printf("%lld",mx-mn);
	return 0;
}


Measured memory_bytes: 256