akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};

int main(){
    int h,w,m;cin>>h>>w>>m;
    vector<int> hs(h,0),ws(w,0);
    set<P> s;
    rep(i,m){
        int c,r;cin>>c>>r;
        --c;--r;
        hs[c]++;ws[r]++;
        s.emplace(c,r);
    }
    vector<int>is,js;
    int mi=0,mj=0;
    rep(i,h)mi = max(mi,hs[i]);
    rep(j,w)mj = max(mj,ws[j]);
    rep(i,h)if(mi == hs[i])is.emplace_back(i);
    rep(j,w)if(mj == ws[j])js.emplace_back(j);

    int ans = mi + mj;
    for(int i : is)for(int j : js){
        if(s.count(P(i,j)))continue;
        cout<<ans<<endl;
        return 0;
    }
    ans--;
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 23852
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    ll n, k;
    while(cin>>n>>k){
        ll ans=0;
        ll tmp1=0, tmp2=0;
        ll mod=1e9+7;
        for(int i=0; i<k; ++i){
        	tmp1+=i;
        	tmp2+=n-i;
        }
        for(int i=k; i<=n+1; ++i){
        	ans+=tmp2-tmp1+1;
        	ans%=mod;
        	tmp1+=i;
        	tmp2+=n-i;
        }
        printf("%lld\n",ans);
    }
  return 0;
}




Measured memory_bytes: 3760
#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() {
    string s;
    cin >> s;
    int K;
    cin >> K;

    vector<string> ans;
    int N = s.size();
    int cnt = 0;
    rep(i, N) {
        for (int j = i; j < N; ++j) {
            string sub = s.substr(i, j - i + 1);

            bool ok = true;
            rep(k, cnt) if (ans[k] == sub) ok = false;
            if (!ok) continue;

            if (cnt < 5) {
                ans.push_back(sub);
                sort(ans.begin(), ans.end(), greater<>());
                ++cnt;
            } else {
                if (sub < ans[0]) {
                    ans[0] = sub;
                    sort(ans.begin(), ans.end(), greater<>());
                } else
                    j = N;
            }
        }
    }

    cout << ans[ans.size() - K] << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  vector<int> v(9, -1);
  rep(i, 0, 9){
    cin >> v[i];
  }
  int n;
  cin >> n;
  int a[n];
  rep(i, 0, n){
    cin >> a[i];
    rep(j, 0, 9){
      if(a[i] == v[j]){
        v[j] = -1;
        break;
      }
    }
  }
  
  if(v[4] == -1){
    if(v[0] == -1 && v[8] == -1){
      cout << "Yes\n";
      return 0;
    }
    if(v[1] == -1 && v[7] == -1){
      cout << "Yes\n";
      return 0;
    }
    if(v[2] == -1 && v[6] == -1){
      cout << "Yes\n";
      return 0;
    }
    if(v[3] == -1 && v[5] == -1){
      cout << "Yes\n";
      return 0;
    }
  }
  
  if(v[0] == -1){
    if(v[1] == -1 && v[2] == -1){
      cout << "Yes\n";
      return 0;
    }
    if(v[3] == -1 && v[6] == -1){
      cout << "Yes\n";
      return 0;
    }
  }
  if(v[8] == -1){
    if(v[2] == -1 && v[5] == -1){
      cout << "Yes\n";
      return 0;
    }
    if(v[6] == -1 && v[7] == -1){
      cout << "Yes\n";
      return 0;
    }
  }
  
  cout << "No\n";
}
    
    

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

int main() {
  int n, i;
  cin >> n;
  vector<int> h(n);
  for (i = 0;i < n; i++) cin >> h[i];
  int l = 0, ans = 0;
  while (l < n) {
    if (h[l] == 0) {
      l++;
      continue;
    } //0になったら残りを飛ばす
    int r = l;
    while (r < n && h[r] != 0) r++; //ループの終わりを決める(h[r]が0になるrを探す)
    for (i = l; i < r; i++) h[i]--; //0****0における全ての*から1を引く
    ans++;
  }
  cout << ans << endl;
}


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

int powmod[200000];
int dp[200001];
int cnt[2019] = {0};
int main() {
	string s;
	cin >> s;
	int curr = 1;
	int n = s.size();
	powmod[0] = 1;
	for(int i=0;i<n;i++){
		powmod[i+1] = (powmod[i]*10)%2019;
	}
	dp[n] = 0;
	for(int i=0;i<n;i++){
		dp[n-i-1] = (dp[n-i] + (s[n-i-1]-'0')*powmod[i])%2019;
		cnt[dp[n-i-1]]++;
	}
	int sum = 0;
	cnt[0]++;
	for(int i=0;i<2019;i++){
		sum += cnt[i]*(cnt[i]-1)/2;
	}
	cout << sum;
}

Measured memory_bytes: 5304
import random
import time

t1=time.time()
d=int(input())
c=input()
cl=[int(n) for n in c.split()]
sl=list()
for i in range(d):
    s=input()
    sl=sl+[int(n) for n in s.split()]
tl=[1]*d
sat=0
for i in range(d):
    sat+=sl[i*26+tl[i]-1]

def decr(tl,cl):
    dec=0
    for i in range(26):
        last=[a for a, x in enumerate(tl) if x==i+1]
        if last==list():
            dec+=(d*(d+1)/2)*cl[i]
        else:
            for v in range(len(last)):
                if v!=len(last)-1:    
                    dec+=cl[i]*(last[v+1]-last[v]-1)*(last[v+1]-last[v])/2
                else:
                    dec+=cl[i]*(d-last[v]-1)*(d-last[v])/2
            dec+=cl[i]*(last[0])*(last[0]+1)/2
    return(int(dec))

oldscore=sat
oldans=oldscore-decr(tl,cl)
oldtl=[int(x) for x in tl]
t2=time.time()
while t2-t1<1.85:
    if round(t2*100)/2==0:
        d1=random.randint(1,d)
        d2=random.randint(1,d)
        q1=tl[d2-1]
        q2=tl[d1-1]
        cha=sl[(d1-1)*26+q1-1]-sl[(d1-1)*26+tl[d1-1]-1]+sl[(d2-1)*26+q2-1]-sl[(d2-1)*26+tl[d2-1]-1]
        tl[d2-1]=q1
        tl[d1-1]=q2
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
        if newans<oldans:
            tl=[int(x) for x in oldtl]
        else:
            oldans=newans
            oldtl=[int(x) for x in tl]
            oldscore=newscore
    else:
        da=random.randint(1,d)
        q=random.randint(1,26)
        cha=sl[(da-1)*26+q-1]-sl[(da-1)*26+tl[da-1]-1]
        tl[da-1]=q
        newscore=oldscore+cha
        newans=newscore-decr(tl,cl)
        if newans<oldans:
            tl=[int(x) for x in oldtl]
        else:
            oldans=newans
            oldtl=[int(x) for x in tl]
            oldscore=newscore
    t2=time.time()
for i in range(d):
    print(tl[i])
        

Measured memory_bytes: 91312
N = int(input())
A = list(map(int, input().split()))

import numpy as np
sumA = np.cumsum(A)

ans = float('inf')
for i in range(0, N-1):
    x = sumA[i]
    y = sumA[-1] - x
    ans = min(abs(x-y), ans)
print(ans)

Measured memory_bytes: 23792
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
const int mod = 1e9 + 7;
#define putchar putchar_unlocked
#define getchar getchar_unlocked

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    f(n) {
        int x;
        cin >> x;
        ans += (x >= k);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N, A, B, C = map(int, input().split())

MOD = 10 ** 9 + 7

fact = [0] * (2 * N)
fact[0] = 1

for i in range(1, 2 * N) :
    fact[i] = (fact[i-1] * i) % MOD

def inv(x) :
    return pow(x, MOD - 2, MOD)

def comb(n, r) :
    if n < r or n < 0 or r < 0 :
        return 0
        
    return (fact[n] * inv(fact[n-r]) * inv(fact[r])) % MOD

A_ = A * inv(A+B) % MOD
B_ = B * inv(A+B) % MOD

ret = 0
for M in range(N, 2 * N) :
    ret += (M * comb(M-1, N-1) * pow(A_, N, MOD) * pow(B_, M-N, MOD)) % MOD
    ret += (M * comb(M-1, N-1) * pow(B_, N, MOD) * pow(A_, M-N, MOD)) % MOD
    ret %= MOD
    
ret *= 100 * inv(100 - C) % MOD

print(ret % MOD)

Measured memory_bytes: 45304
a = [[0 for i in range(14)] for j in range(14)]
drop = [0 for i in range(3)]
drop[0] = [
	[0,0,0,0,0],
	[0,0,1,0,0],
	[0,1,1,1,0],
	[0,0,1,0,0],
	[0,0,0,0,0]
]
drop[1] = [
	[0,0,0,0,0],
	[0,1,1,1,0],
	[0,1,1,1,0],
	[0,1,1,1,0],
	[0,0,0,0,0]
]
drop[2] = [
	[0,0,1,0,0],
	[0,1,1,1,0],
	[1,1,1,1,1],
	[0,1,1,1,0],
	[0,0,1,0,0]
]

while(1):
	try:
		x,y,n = [int(i) for i in input().split(",")]
		for i in range(5):
			for j in range(5):
				a[x+i][y+j] = a[x+i][y+j] + drop[n-1][i][j]
	except EOFError:
		b = [[0 for i in range(10)] for j in range(10)]
		for i in range(10):
			for j in range(10):
				b[i][j] = a[i+2][j+2]
		zero = [sum([1 if b[i][j] == 0 else 0 for j in range(10)]) for i in range(10)]
		print(sum(zero))
		print(int(max([max(i) for i in b])))
		break


Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
long long int nChoosek( long long int n, long long int k )
{
if (k > n) return 0;
if (k * 2 > n) k = n-k;
if (k == 0) return 1;
    int result = n;
for( int i = 2; i <= k; ++i )
{
        result *= (n-i+1);
        result /= i;
}
    return result;
}

long long int lcm(long long int a,long long int b)
{
    long long int m,n;
    m=a;
    n=b;
    while(m!=n)
    {
        if(m < n)
        {
            m=m+a;
        }
        else
        {
            n=n+b;
        }
    }
    return m;
}

long long int gcd(long long int a,long long int b)
{ 
if (a == 0) 
return b; 
return gcd(b % a, a);
}
vector<int> initializeDiffArray(vector<int>& A) 
{ 
    int n = A.size(); 
  
    // We use one extra space because 
    // update(l, r, x) updates D[r+1] 
    vector<int> D(n + 1); 
  
    D[0] = A[0], D[n] = 0; 
    for (int i = 1; i < n; i++) 
        D[i] = A[i] - A[i - 1]; 
    return D; 
} 
  
// Does range update 
void update(vector<int>& D, int l, int r, int x) 
{ 
    D[l] += x; 
    D[r + 1] -= x; 
} 
// Prints updated Array 
int printArray(vector<int>& A, vector<int>& D) 
{ 
    for (int i = 0; i < A.size(); i++) { 
        if (i == 0) 
            A[i] = D[i]; 
        else
            A[i] = D[i] + A[i - 1];   
        cout << A[i] << " "; 
    } 
    cout << endl; 
    return 0;
} 
int main()
{
    fastio
    
    ll a,b;
    cin>>a>>b;
    if((a<1 || a>9) || (b<1||b>9))
    {
        cout<<-1<<'\n';
    }
    else
    {
        cout<<a*b<<'\n';
    }
    
    return 0;
}


Measured memory_bytes: 256
n, k = [int(_) for _ in input().split(' ')]
a = [int(_) for _ in input().split(' ')]

M = 1000000007

answer = 0
for i in range(n):
    p = 0
    q = 0
    for j in range(n):
        if a[j] < a[i]:
            p += 1
            if j > i:
                q += 1
    answer += q * k + p * k * (k - 1) // 2
    answer %= M

print(answer)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int a[5010];
int main(void)
{
    int K,S;
    cin>>K>>S;
    for(int i=0;i<=2*K;i++)
    {
        a[i]=i;
    }
    int cnt=0;
    for(int i=0;i<=K;i++)
    {
        int key=S-i;
        if(binary_search(a,a+2*K+1,key))
        {
            if(S-i>=0&&S-i<=K)
            {
                cnt+=(S-i+1);
            }
            else
            {
                cnt+=(2*K+1-(S-i));
            }
        }
    }
    cout<<cnt <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int mn = 99999;
    int mx = -99999; 
    for (int i = 0; i < N; ++i) {
        int a_i;
        cin >> a_i;
        mn = min(mn, a_i);
        mx = max(mx, a_i);
    }
    cout << mx - mn << '\n';
}


Measured memory_bytes: 888
package main

import (
    "fmt"
)

func main() {
    // in   int [N A B]
    // A: blueBall, B: redBall
    // out  [N個 青いボールの個数]
    
    var n, a, b int
    fmt.Scan(&n, &a, &b)
    
    // N個中 A+B を何ターンできるか
    var turnCount int = n / (a + b)
    
    // ターン数の余り
    var remainder int = n % (a + b)
    
    
    // ターン数分の青ボールの個数
    var blueBall int = a * turnCount
    
    // ターン数の余りの中での青ボールの個数
    if a < remainder {
        blueBall += a
    } else {
        blueBall += remainder
    }
    
    
    // 出力
    fmt.Println(blueBall)
}





Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
    int n, m;
    scanf("%d %d", &n, &m);
    
    int a[m], b[m];
    int i;
    for(i=0;i<m;i++)
        scanf("%d %d", &a[i], &b[i]);
    
    int c[n];
    for(i=0;i<n;i++)
        c[i]=0;
        
    int j;
    for(i=0;i<m;i++){
        for(j=1;j<=n;j++){
            if(j==a[i])
                c[j-1]++;
            if(j==b[i])
                c[j-1]++;
        }
    }

    for(i=0;i<n;i++)
        printf("%d\n", c[i]);
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<int>v[100009];
bool visited[100009];
void f(int x)
{
    visited[x]=1;
    for (auto child:v[x])
    {
        if (visited[child])
            continue;
        f(child);
    }
}
int main()
{
    FASTINOUT;
    int x,m;
    cin>>x>>m;
    int l,r;
    for (int i=0; i<m; i++)
    {
        cin>>l>>r;
        v[l].push_back(r);
        v[r].push_back(l);
    }
    int cnt=0;
    for (int i=1; i<=x; i++)
    {
        if (!visited[i])
        {
            cnt++;
            f(i);
        }
    }
    cout<<cnt-1;
    return 0;
}


Measured memory_bytes: 9720
import heapq
N,M=map(int,input().split())
AB=[0]*N
for i in range(N):
    a,b=map(int,input().split())
    b*=-1
    AB[i]=[a,b]

AB.sort()
h=[]
heapq.heapify(h)
count=0
i=0
for day in range(AB[0][0],M+1):
    while i<N-1:
        if AB[i][0]==day:
            heapq.heappush(h,AB[i][1])
            i+=1
        elif AB[i][0]!=day:
            if len(h)!=0:
                count+=-heapq.heappop(h)
            break
    if i==N-1:
        if AB[i][0]==day:
            heapq.heappush(h,AB[i][1])
            count+=-heapq.heappop(h)
        elif AB[i][0]!=day:
            if len(h)!=0:
                count+=-heapq.heappop(h)
print(count)

Measured memory_bytes: 20776
//
//  main.cpp
//  ABC162B
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    ll ans=0;
    for (int i=1; i<=n; i++) {
        if(i%3==0)continue;
        if(i%5==0)continue;
        ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	while(b<=a) b*=2,k--;
	while(c<=b) c*=2,k--;
	cout<<(k>=0?"Yes":"No");
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

ll mod = 1000000007;

int main() {
	IOS;

	ll n;
	cin >> n;
	ll ans = 3, cnt = 1, x; 
	ll c1 = 1, c2 = 0, c3 = 0;
	cin >> x;
	if(x != 0) {
		cout << 0;
		return 0;
	}
	for(int i = 1; i < n; ++i) {
		cin >> x;
		if(x == 0) {
			++cnt;
			if(cnt == 2) {
				c2 = 1;
				ans = (ans * 2) % mod;
			}
			else if(cnt == 3) {
				c3 = 1;
			}
			else {
				cout << 0;
				return 0;
			}
		}
		else {
			if(x == c1 && x == c2 && x == c3) {
				++c1;
				ans = (ans * 3) % mod;
			}
			else if(x == c1 && x == c2) {
				++c1;
				ans = (ans * 2) % mod;
			}
			else if(x == c1 && x == c3) {
				++c1;
				ans = (ans * 2) % mod;
			}
			else if(x == c2 && x == c3) {
				++c2;
				ans = (ans * 2) % mod;
			}
			else if(x == c1) {
				++c1;
			}
			else if(x == c2) {
				++c2;
			}
			else if(x == c3) {
				++c3;
			}
			else {
				cout << 0;
				return 0;
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll A,B,C,D,E,F,G,H,I;
ll ans=0;
ll cnt=0;
string S,T;
map<char,ll> m;
vector<ll> v[100000];
int main()
{
	cin>>S;
	for(ll i=0;i<4;i++) m[S[i]]++;
	for(ll i='A';i<='Z';i++){
		if(m[i]==2) cnt++;
	}
	if(cnt==2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    bool f=true;
    cin>>s;
    s.pop_back();
    while(s.length()!=0){
        f=true;
        if(s.length()%2==0){
            for(int i=0;i<s.length()/2;i++){
                if(s[i]!=s[(s.length()/2)+i]) f=false;
                if(!f)break;
            }
            if(f){
                cout<<s.length()<<endl;
                break;
            }
        }
        s.pop_back();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
int main(){
  int n,m;cin>>n>>m;
  vi a(n),b(m);
  rep(i,n)cin>>a[i];
  rep(i,m)cin>>b[i];
  vvi dp(n+1,vi(m+1,1));
  rep(i,n){
    rep(j,m){
      if(a[i]!=b[j])dp[i+1][j+1]=(mod+dp[i][j+1]+dp[i+1][j]-dp[i][j])%mod;
      else dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1])%mod;
      }
    }
  cout<<dp[n][m]%mod<<endl;
}


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

using namespace std;

long long n,k,a,b,c,q[200005],nr,rs;
string s,x;

int main() 
{
    cin>>n;
    for (int i=1; i<=n; i++){
        cin>>q[i];
        if (q[i]<q[i-1]) rs+=abs(q[i]-q[i-1]), q[i] = q[i-1];
    }
    cout<<rs;
}

Measured memory_bytes: 5192
import numpy as np

N, W = map(int, input().split())

INF = 10**15
dp = np.full(10**5+1,INF,np.int64)
dp[0] = 0

for _ in range(N):
    w, v = map(int, input().split())
    dp[v:] = np.minimum(dp[v:], dp[:-v] + w)

print(np.where(dp<=W)[0][-1])

Measured memory_bytes: 20960
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int d[100010];
    for(int i=0;i<N;i++){
        cin >> d[i];
    }

    sort(d,d+N);

    cout << d[N/2]-d[N/2-1];

    return 0;
}


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

int memo[10][10];

int main() {
        ios_base:: sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++) {
                int t = i;
                int fst = -1, lst = -1;
                while(t > 0) {
                        int z = t % 10;
                        if(lst == -1)
                                lst = z;
                        fst = z;
                        t = t / 10;
                }
                memo[fst][lst]++;
        }
        int ans = 0;
        for(int i = 1; i < 10; i++) {
                for(int j = 1; j < 10; j++) {
                        if(i == j) {
                                ans = ans + memo[i][j] * memo[i][j]; 
                        } else 
                                ans = ans + memo[i][j] * memo[j][i];
                }
        }
        cout << ans;
        return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    d = defaultdict(int)

    maxi = 0
    for _ in range(N):
        S = input()
        d[S] += 1
        maxi = max(maxi, d[S])

    ans = []
    for k, v in d.items():
        if v == maxi:
            ans.append(k)
    for a in sorted(ans):
        print(a)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 36328
import java.util.Scanner;

class Main {

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

		while(true) {
			int n = sc.nextInt();
			int r = sc.nextInt();
			if (n == 0 && r == 0) return;
			a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = n-i;
			}
			//System.out.println(Arrays.toString(a));
			for (int i = 0; i < r; i++) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				int count = x-1;
				int b[] = new int[y];
				for (int j = 0; j < y; j++) {
					b[j] = a[count++];
				}

				for (int j = x-2; j >= 0; j--) {
					a[j+y] = a[j];
				}
				for (int j = 0; j < y; j++) {
					a[j] = b[j];
				}
				//System.out.println(Arrays.toString(a));
			}
			System.out.println(a[0]);
		}
	}
}


Measured memory_bytes: 36152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
const ll MOD=998244353;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

int main()
{
        io;
        //////////////////////////////////
        ll n,i,j,k,s=0,p=0,q=0;
        cin>>n;
        vll v(n,0),vl(100005,0);
        for(i=0;i<n;i++) {cin>>v[i];
			vl[v[i]]++;
			s=s+v[i];
			}
			
			cin>>q;
			while(q--)
			{ll b,c;
				cin>>b>>c;
				ll no=vl[b];
				s=s+(c-b)*no;
				cout<<s nl;
				vl[c]=vl[c]+vl[b];
				vl[b]=0;
				}
        //////////////////////////////////
        cer;
}


Measured memory_bytes: 4668
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100000
#define MAXH 400
using namespace std;
int N,H;
int setfa[MAXH+5],cd[MAXH+5],rd[MAXH+5];
int A[MAXN+5],B[MAXN+5],C[MAXN+5],D[MAXN+5];
int ok[MAXH+5];
void Init()
{
	for(int i=1;i<=MAXH;i++)
		setfa[i]=i;
}
int Findfa(int x)
{
	if(x==setfa[x])
		return x;
	return setfa[x]=Findfa(setfa[x]);
}
void Union(int x,int y)
{
	int fx=Findfa(x),fy=Findfa(y);
	if(fx==fy)
		return;
	setfa[fx]=fy;
}
int main()
{
	Init();
	scanf("%d %d",&N,&H);
	for(int i=1;i<=N;i++)
	{
		scanf("%d %d %d %d",&A[i],&B[i],&C[i],&D[i]);
		int x,y;
		if(C[i]==0)	x=A[i];
		else		x=C[i]+H;
		if(D[i]==0)	y=B[i]+H;
		else		y=D[i];
		cd[x]++,rd[y]++;
		Union(x,y);
	}
	bool legal=true;
	for(int i=1;i<=MAXH;i++)
	{
		int fi=Findfa(i);
		if(cd[fi]==0&&rd[fi]==0)
			continue;
		if(cd[i]!=rd[i])
		{
			if(cd[i]>rd[i]&&i>H)
				legal=false;
			else if(cd[i]<rd[i]&&i<=H)
				legal=false;
			ok[fi]=1;
		}
	}
	for(int i=1;i<=MAXH;i++)
	{
		int fi=Findfa(i);
		if(cd[fi]!=0||rd[fi]!=0)
			if(ok[fi]==false)
			{
				legal=false;
				break;
			}
	}
	if(legal==true)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N, a;
	cin >> N;
	ll ans = 0;
	REP(i, N) {
		cin >> a;
		ans += (a - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2])
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}

Measured memory_bytes: 256
private val scanner = java.util.Scanner(System.`in`)

private fun readInts(n: Int) = Array(n) { scanner.nextInt() }
private fun readLongs(n: Int) = Array(n) { scanner.nextLong() }
private fun readLineInts() = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()
private fun readLineLongs() = readLine()!!.split(" ").map { it.toLong() }.toTypedArray()

fun main(args: Array<String>) {
    val (N, A, B) = readInts(3)

    println("${Math.min(A, B)} ${Math.max(A + B - N, 0)}")
}

Measured memory_bytes: 31012
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	char c[2][3],x[2][3],y;
	for(int i=0;i<2;i++){
		for(int j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	for(int i=0;i<3;i++){
		x[0][i]=c[1][2-i];
		x[1][i]=c[0][2-i];
	}

	for(int i=0;i<2;i++){
		for(int j=0;j<3;j++){
			if(c[i][j]!=x[i][j]){
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}
	cout<<"YES"<<endl;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    int count = 0;
    for (int i = a; i <= b; ++i) {
        if (c % i == 0) count++;
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        string S = Console.ReadLine();
        string previous = "";
        string now = "";
        int K = 0;
        for (int i = 0; i < S.Length; i++)
        {
            now += S[i];
            if (now != previous)
            {
                K++;
                previous = now;
                now = "";
            }
            else
            {
                if (i == S.Length - 1)
                {
                    break;
                }
            }
        }
        Console.WriteLine(K);
    }




}

Measured memory_bytes: 15712
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0; i < s.length() / 2; i++){
    if(s[i] != s[s.length() - 1 - i]){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       String a=sc.nextLine();
       String b=a+a;
       String c=sc.nextLine();
       if(b.contains(c)) {
    	   System.out.println("Yes");
       }else {
    	   System.out.println("No");
       }
    }

}


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

const int N = 1054, W = 5054, INF = 0x3f3f3f3f;

int n;
int p[N], fc[N], nc[N];
int s[N], f[N];
int dp[2][W], *cur = *dp, *nxt = dp[1];

inline void link(int x, int px) {p[x] = px, nc[x] = fc[px], fc[px] = x;}
inline void down(int &x, const int y) {x > y ? x = y : 0;}

void dfs(int x) {
	int i, y;
	for (y = fc[x]; y; y = nc[y]) dfs(y);
	memset(nxt, 63, sizeof *dp), *nxt = 0;
	for (y = fc[x]; y; y = nc[y]) {
		std::swap(cur, nxt), memset(nxt, 63, sizeof *dp);
		for (i = s[y]; i <= s[x]; ++i) down(nxt[i], cur[i - s[y]] + f[y]);
		for (i = f[y]; i <= s[x]; ++i) down(nxt[i], cur[i - f[y]] + s[y]);
	}
	f[x] = *std::min_element(nxt, nxt + (s[x] + 1));
}

int main() {
	int i, x;
	scanf("%d", &n);
	for (i = 2; i <= n; ++i) scanf("%d", &x), link(i, x);
	for (i = 1; i <= n; ++i) scanf("%d", s + i);
	dfs(1), puts(f[1] >= INF ? "IMPOSSIBLE" : "POSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n;
    cin>>n;
    set<int> se;
    REP(i,n){
        int t;
        cin>>t;
        se.insert(t);
    }
    cout<<n-(n-se.size()+1)/2*2<<endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int N;
  cin >> N;
  map <string, int> vote;
  int MAX = 0;
  rep(i,N){
    string S;
    cin >> S;
    if(vote.count(S)){
      vote[S] += 1;
    }
    else{
      vote[S] += 1;
    }
    MAX = max(vote[S],MAX);
  }
  for(auto p : vote){
    auto k = p.first;
    auto v = p.second;
    if(v == MAX){
      cout << k << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 19236
n = int(input())
a = list(map(int, input().split()))
b = []

for i in range(n):
  if a[i] % 2 == 0:
    b.append(a[i])

for j in b:
  if j % 3 != 0 and j % 5 != 0:
    print('DENIED')
    exit()
    
print('APPROVED')

Measured memory_bytes: 9164
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
for i in range(len(s)):
    if s[i] == "A":
        l = i
        break
for i in range(len(s))[::-1]:
    if s[i] == "Z":
        r = i
        break
print(r - l + 1)







Measured memory_bytes: 4268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int dp[n+1]={0};
    dp[1]=0;
    dp[2]=abs(a[2]-a[2-1]);
    for(int i=3;i<=n;i++)
    {
        ll x1=abs(a[i-2]-a[i]);
        ll x2=abs(a[i-1]-a[i]);
        dp[i]=min(dp[i-2]+x1,dp[i-1]+x2);
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;

const int V_MAX = 10000;
const int INF = 100000000;

struct Edge {
	bool operator< (const Edge& e)const {
		return w > e.w;
	}
	int to;
	int w;
};

int main() {
	int v;
	int e;
	priority_queue<Edge> edge[V_MAX];
	vector<int> tree;
	bool check[V_MAX] = { false };
	int ans = 0;

	scanf("%d%d", &v, &e);

	for (int i = 0; i < e; i++) {
		int s, t, w;
		Edge e1, e2;

		scanf("%d%d%d", &s, &t, &w);

		e1.to = t;
		e1.w = w;
		e2.to = s;
		e2.w = w;

		edge[s].push(e1);
		edge[t].push(e2);
	}

	tree.push_back(0);
	check[0] = true;

	for (int i = 1; i < v; i++) {

		int minW = INF;
		int minV = 0;
		int k = 0;

		for (int j = 0; j < tree.size(); j++) {
			int t = tree[j];
			while (!edge[t].empty() && check[edge[t].top().to]) {
				edge[t].pop();
			}

			if (edge[t].empty())continue;

			if (minW > edge[t].top().w) {
				minV = edge[t].top().to;
				minW = edge[t].top().w;
				k = t;
			}
		}

		edge[k].pop();

		check[minV] = true;
		tree.push_back(minV);
		ans += minW;
	}

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

	return 0;
}

Measured memory_bytes: 5756
import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Ix
import Data.Vector.Generic ((!))
import qualified Data.Vector as V
import qualified Data.Vector.Algorithms.Intro as A

main = sol <$> get >>= print

get = V.fromList . fmap (V.unfoldr (C.readInteger . C.dropWhile (<'-'))) . C.lines <$> C.getContents 

sol :: V.Vector (V.Vector Integer) -> Integer
sol v = minimum [g l r d u | 
  l <- [0..n-2], r <- [l+1..n-1], d <- [0..n-2], u <- [d+1..n-1], k <= f l r d u]
  where
  [n,k] = fmap fromIntegral $ V.toList (v!0) :: [Int]
  ps = V.tail v
  xs = V.modify A.sort $ V.map V.head ps
  ys = V.modify A.sort $ V.map V.last ps
  f l r d u = V.length $ V.filter (\p -> inRange (xs!l,xs!r) (p!0) && inRange (ys!d,ys!u) (p!1)) ps
  g l r d u = (xs!r - xs!l)*(ys!u - ys!d)

Measured memory_bytes: 7380
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

def getlist():
	return list(map(int, input().split()))


def main():
	H, W, N = getlist()
	D = defaultdict(int)
	D[0] += (H - 2) * (W - 2)
	L = []
	for i in range(N):
		a, b = getlist()
		for j in range(3):
			for k in range(3):
				if H - 2 >= a - j and a - j >= 1 and W - 2 >= b - k and b - k >= 1:
					L.append((a - j, b - k))

	L = sorted(L)
	n = len(L)
	if n != 0:
		v = L[0]
	c = 0
	for i in range(n):
		if v == L[i]:
			c += 1
		else:
			D[c] += 1
			c = 1
		v = L[i]

	if n != 0:
		D[c] += 1
	for i in range(1, 10):
		D[0] -= D[i]

	for i in range(10):
		print(D[i])	


if __name__ == '__main__':
	main()




Measured memory_bytes: 135888
n = int(input())
p = list(map(int, input().split()))
diff = []
for i in range(n):
    if p[i] != i + 1:
        diff.append((i+1, p[i]))
if len(diff) == 0:
    print('YES')
elif len(diff) == 2:
    if diff[0][0] == diff[1][1] and diff[0][1] == diff[1][0]:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<cassert>
#include<stack>
#include<deque>
#include<list>
#include<sstream>
#include<unordered_map>
#include<time.h>
#include<functional>
#pragma comment(linker, "/STACK:8809999999")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<ld, ld> pld;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
typedef vector<vector<vector<ll>>> vvv;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const ll settled = 400007;



int main()
{
	ios_base::sync_with_stdio(false); cout.tie(NULL);
#ifndef overlord
	/*freopen("capitals.in", "r", stdin);
	freopen("capitals.out", "w", stdout);*/
#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	vl a(5, 0);
	forn(i, 0, 3)
	{
		ll f, s;
		cin >> f >> s;
		a[f]++;
		a[s]++;
	}
	forn(i, 1, 5)
		if (a[i] == 3)
		{
			cout << "NO";
			return 0;
		}
	cout << "YES";
	return 0;
}

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int n;
bool calc (int c,int cnt,vector<int> a) {
    rel(i,n,0) {
        if(a[i] < c) return true;
        cnt -= (a[i]+c-1) / c - 1;
        if(cnt < 0) return false;
    }
    return true;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int k;cin >> n >> k;
    vector<int> a;
    ll l = 0,r = 1e9+1;
    rep(i,0,n){
        int tmp; cin >> tmp;
        a.push_back(tmp);
    }
    sort(all(a));
    while(l < r-1) {
        ll c = (r+l)/2;
        if(calc(c,k,a)) {
            r = c;
        }else {
            l = c;
        }
        //cout << l << " " << r << endl;
    }
    cout << r << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    int M = 0, ans = 0;
    for(int i = 0; i < N; i++) {
        int H;
        cin >> H;
        if(M <= H) ans++;
        M = max(M, H);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		int result = 0;
		result = 800*n - 200*(n/15);
		
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		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());}
	}
}



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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, x[114], y[114], h[114];
	cin>>n;
	REP(i, n){
		cin>>x[i]>>y[i]>>h[i];
	}
	REP(c1, 101){
		REP(c2, 101){
			bool f=false, ok=true;
			int H=1<<30;
			REP(i, n){
				if(f){
					if(h[i]==0){
						if(H>abs(x[i]-c1)+abs(y[i]-c2)){
							ok=false;
							i=n;
						}
					}
					else if(H!=h[i]+abs(x[i]-c1)+abs(y[i]-c2)){
						ok=false;
						i=n;
					}
				}
				else{
					if(h[i]==0){
						H=min(H, abs(x[i]-c1)+abs(y[i]-c2));
					}
					else if(H<h[i]+abs(x[i]-c1)+abs(y[i]-c2)){
						ok=false;
						i=n;
					}
					else{
						H=h[i]+abs(x[i]-c1)+abs(y[i]-c2);
						f=true;
					}
				}
			}
			if(ok && H>=1){
				cout<<c1<<' '<<c2<<' '<<H<<'\n';
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
A, B, K = list(map(int, input().split()))
flag = 0
def f(a, b):
    return a // 2, b + a //2
flag = 0
for i in range(K):
    if flag == 0:
        A, B = f(A, B)
        flag = 1
    else:
        B, A = f(B, A)
        flag = 0
print(A, B)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,m,u=0,q,ans=0;
    cin >> n >> m;
    vector<vector<int>> a(m, vector<int>(0));
    vector<int> b(m),c(n);
    for (int i=0;i<m;i++){
        cin >> u;
        for (int j=0;j<u;j++){
            cin >> q;
            a.at(i).push_back(q);
        }
    }
    u=0;
    for (int i=0;i<m;i++){
        cin >> q;
        b.at(i)=q;
    }
    for (int i=0;i<pow(2,n);i++){
        u=i;
        for(int j=0;j<n;j++){
            if (u%2==0) c.at(j)=0;
            else c.at(j)=1;
            u=u>>1;
            }
        for (int j=0;j<m;j++){
            q=0;
            for (int k=0;k<a.at(j).size();k++){
                if (c.at(a.at(j).at(k)-1)==1) q++;
            }
            if (q%2!=b.at(j)) break;
            if (j==m-1) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,t,a,b,n,c,y,d,m,prev,sum,ans;
    t=1;
    // cin>>t;
    while(t--)
    {
       string s;
       cin>>s;
       string s1=s;
       reverse(s.begin(),s.end());
       if(s==s1)cout<<"Yes";
       else cout<<"No";
    }
}

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

int main(){
    long long d, n;
    cin>>d>>n;
    for(int i=0; i<n; i++){
        int temp;
        cin>>temp;
        d-=temp;
    }
    if(d<0)
        cout<<-1<<"\n";
    else
        cout<<d<<"\n";
}


Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
int N;
int main() {
    scanf("%d", &N);
    int res = N;
    for (int i = 0; i <= N; i++) {
        int cc = 0;
        int t = i;
        while (t > 0) cc += t % 6, t /= 6;
        t = N - i;
        while (t > 0) cc += t % 9, t /= 9;
        if (res > cc) res = cc;
    }
    printf("%d\n", res);
}


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

using namespace std;

int a[18], b[18];
int dp[(1 << 18)][18][2];
int inf = 1e9;

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    for (int mask = 0; mask < (1 <<  n); ++mask) for (int i = 0; i < n; ++i) dp[mask][i][0] = inf, dp[mask][i][1] = inf;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) dp[(1 << i)][i][0] = i;
        else dp[(1 << i)][i][1] = i;
    }
    for (int mask = 1; mask < (1 << n); ++mask) {
        int cnt_bit = 0;
        for (int i = 0; i < n; ++i) if ((mask&(1 << i)) > 0) cnt_bit++;
        for (int i = 0; i < n; ++i) {
            if ((mask&(1 << i)) > 0) {
                int where = (mask^(1 << i)), cnt = 0, add = 0, cur = 0;
                for (int j = 0; j < n; ++j) {
                    if ((where&(1 << j)) > 0) {
                        if (j > i) cnt++, cur++;
                    }
                    else if (j < i) cnt++;
                }
                add = i + 1 + cur - cnt_bit;
                int go = a[i + 1];
                if (cnt % 2 == 1) go = b[i + 1];
                for (int lst = 0; lst < n; ++lst) {
                    if ((where&(1 << lst)) > 0) {
                        if (go >= a[lst + 1]) {
                            dp[mask][i][cnt % 2] = min(dp[mask][i][cnt % 2], dp[where][lst][0] + add);
                        }
                        if (go >= b[lst + 1]) dp[mask][i][cnt % 2] = min(dp[mask][i][cnt % 2], dp[where][lst][1] + add);
                    }
                }
            }
        }
    }
    int ans = inf;
    for (int i = 0; i < n; ++i) ans = min({ans, dp[(1 << n) - 1][i][0], dp[(1 << n) - 1][i][1]});
    if (ans > inf / 2) cout << -1;
    else cout << ans;
    return 0;
}



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

#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define N 1003

using namespace std;

struct Edge {
    int to, nxt;
} e[N * N * 3];

int n, cnt;
int ins[N * N], mp[N][N], fir[N * N], t[N * N];

queue<int> Q;

int id(int, int);
void add(int, int);

int main() {
    scanf("%d", &n);
    int ans = 0;
    rep (i, 1, n)
        rep (j, 1, n - 1)
            scanf("%d", mp[i] + j);
    rep (i, 1, n)
        rep (j, 2, n - 1)
            add(id(i, mp[i][j - 1]), id(i, mp[i][j]));
    rep (i, 1, n * n) {
        if (!ins[i])
            Q.push(i);
        t[i] = 1;
    }
    while (!Q.empty()) {
        int u = Q.front();
        Q.pop();
        ans = max(ans, t[u]);
        for (int i = fir[u]; i; i = e[i].nxt) {
            int v = e[i].to;
            --ins[v];
            if (!ins[v])
                Q.push(v), t[v] = t[u] + 1;
        }
    }
    rep (i, 1, n) 
        if (ins[i])
            ans = -1;
    cout << ans << endl;
    return 0;
}

int id(int x, int y) {
    if (x > y)
        swap(x, y);
    return (x - 1) * n + y;
}

void add(int u, int v) {
    e[++cnt] = (Edge){v, fir[u]};
    fir[u] = cnt;
    ++ins[v];
    return;
}


Measured memory_bytes: 26880
import java.util.Scanner;

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

    int x = b/k*k;
    System.out.println(x>=a?"OK":"NG");
  }
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int ret = 0;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        if (i % 2 == 1 && a % 2 == 1)ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3620
(defun main ()
  (let ((x (read))
        (y (read))
        (a)
        (b)
        (ans "No"))
    (setf a (- x (/ (- y (* 2 x)) 2)))
    (setf b (/ (- y (* 2 x)) 2))
    (if (and (<= 0 a) (<= 0 b) (integerp a) (integerp b))
        (setf ans "Yes"))
    (format t "~a~%" ans)))

(main)


Measured memory_bytes: 23596