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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;



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

	ll l,r;cin>>l>>r;

	int n = l%2019;

	if((2019-n)+l <= r){
		writeln(0);
	}else {
		int ans =100000;
		for(ll i=l; i <=r-1; i++){
			for(ll j=i+1; j<=r; j++){
			int tmp = (i*j)%2019;
			ans = min(ans,tmp);
			if(!ans){
				writeln(0);
				return 0;
			}
			}
		}
		writeln(ans);
	}




}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll w[100], v[100], dp[105][10005];
int main() {
    init();
    ll N, W;
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i];

    rep(i,N){
        rep(j,W+1){
            dp[i + 1][j] = dp[i][j];
            if (j >= w[i]) chmax(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 10992
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 14:42:59 2020

@author: liang
"""

from collections import deque
S = deque(input())
Q = int(input())

reverse = False

for i in range(Q):
    t = input().split()
    if int(t[0]) == 1:
        if reverse == False:
            reverse = True
        else:
            reverse = False
    else:
        F = int(t[1])
        C = t[2]
        if F == 1:
            if reverse == False:
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if reverse == False:
                S.append(C)
            else:
                S.appendleft(C)

                
if reverse == False:
    print(''.join(S))
else:
    print(''.join(reversed(S)))
        

Measured memory_bytes: 14184
#include<cstdio>
int main()
{
	long long a,b;
	char c[3];
	scanf("%lld %s %lld",&a,c,&b);
	if(c[0]=='+')
		printf("%lld\n",a+b);
	else
		printf("%lld\n",a-b);
	return 0;
}

Measured memory_bytes: 128
def main():
    a, b, k = [int(a) for a in input().split()]

    for i in range(100):
        i = 100 - i
        if a % i == 0 and b % i == 0:
            if k == 1:
                print(i)
                return
            k -= 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n,k = (int(i) for i in input().split())

belongs = [0] * n

for i in range(k):
	if 0 in belongs:
		d = int(input())
		a = [int(j) for j in input().split()]
		for j in range(d):
			belongs[a[j]-1] = 1

print(belongs.count(0))

Measured memory_bytes: 66052
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  ll mul = 1;
  bool f = false;
  rep(i, n){
    ll a;
    cin >> a;
    if(f == false){
      if(mul < LLONG_MAX / a){
        mul *= a;
      }else{
        mul = -1;
        f = true;
      }
    }
    if(a == 0){
      mul = 0;
      break;
    }
    if(f == false && mul > 1'000'000'000'000'000'000){
      mul = -1;
      f = true;
    }
  }
  cout << mul << endl;
  return 0;
}

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

using namespace std;

void solve(int N) {
  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) {
        cnt += 1;
      }
    }
    if (cnt == 8) {
      ans += 1;
    }
  }
  printf("%d\n", ans);
}

int main() {
  int N;
  cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int H, W, i, j;
	while (1)
	{
		scanf("%d%d", &H, &W);
		if (H==0&&W==0)
		{
			break;
		}
		for (i = 1; i <= H; i++)
		{
			for (j = 1; j <= W; j++)
			{
				if (i == 1 || i == H)
				{
					printf("#");
				}
				else
				{
					if (j == 1 || j == W)
					{
						printf("#");
					}
					else
					{
						printf(".");
					}
				}

			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

int main() {
	int h, w;
	
	while (cin >> h >> w) {

		if (h == 0 and w == 0) break;

		for (int i = 0; i < h; i++) {

			for (int j = 0; j < w; j++) {
				if (i == 0 or j == 0 or i + 1 == h or j + 1 == w) {
					cout << '#';
				} else {
					cout << '.';
				}
			}

			cout << '\n';

		}
		
		cout << '\n';

	}
	
	return 0;
}


Measured memory_bytes: 3024
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;

int H,W;
char s;
int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    char table[H][W];
    bool h[H];
    bool w[W];

    REP(i,H){
        h[i] = true;
        REP(j,W){
            cin >> s;
            table[i][j] = s;
            if(s == '#' && h[i]) h[i] = false; 
        }
    }
    REP(i,W){
        w[i] = true;
        REP(j,H){
            if(table[j][i] == '#' && w[i]) w[i] = false; 
        }
    }
    REP(i,H){
        REP(j,W){
            if(h[i]) table[i][j] = 'n';
        }
    }
    REP(i,W){
        REP(j,H){
            if(w[i]) table[j][i] = 'n';
        }
    }

     REP(i,H){
        REP(j,W){
            if(table[i][j] != 'n') cout << table[i][j];
        }
        if(!h[i]) cout << endl;
    }



    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    string ans="",s[n+5];
    map<int,int>mp[n+5];
    for(int i=0; i<n; i++)
        cin>>s[i];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<s[i].length(); j++)
        {
            mp[i][s[i][j]]++;
        }
    }
    for(int i='a'; i<='z'; i++)
    {
        int mn=INT_MAX;
        for(int j=0; j<n; j++)
            mn=min(mn,mp[j][i]);
        for(int j=0; j<mn; j++)
            ans+=i;

    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3704
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double m = 0;
		if(n%2==0) {
			System.out.println(0.5000000);
		}
		else {
			m = ((n/2)+1);
			m = m/n;
			System.out.println(m);
		}

	}

}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	char c = s[0];
	for (int i = 1; i < s.length(); i++) {
		if (s[i] != c) {
			c = s[i];
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using VI = vector<int>;

int main()
{
    
    string s, t;
    cin >> s >> t;
    int ans = 0;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3816
from operator import itemgetter

N, M = map(int,input().split())
shops = []
for i in range(N):
  shops.append(list(map(int,input().split())))
shops.sort(key=itemgetter(0))
daikin = 0
can = 0
j = 0
while can < M:
  daikin += (shops[j][0]*shops[j][1])
  can += shops[j][1]
  j += 1
if can > M:
  daikin -= (can - M)*shops[j-1][0]
print(daikin)

Measured memory_bytes: 28972
N,M = map(int, input().split())
a_list = [int(input()) for _ in range(M)]

MOD = 10**9+7

dp = [0] * (10**5 + 3)
dp[1] = 0
dp[2] = 1
dp[3] = 2
for i in range(3, len(dp)):
    dp[i] = dp[i-1] + dp[i-2] 

res = 1
bef = -1
if M > 0:
    for a in a_list:
        res *= dp[a-bef]
        res %= MOD
        bef = a
res *= dp[N-bef+1]
res %= MOD

print(res)

Measured memory_bytes: 464040
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
  int minv;
  int d[MAX], color[MAX];

  for(int i=0; i<n; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    int u = -1;
    for(int i=0; i<n; i++){
      if(minv > d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(int v=0; v<n; v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(int i=0; i<n; i++){
    cout << i << " " << (d[i] == INFTY ? -1 : d[i] ) << endl;
  }
}

int main(){
  cin >> n;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      M[i][j] = INFTY;
    }
  }

  int k,c,u,v;
  for(int i=0; i<n; i++){
    cin >> u >> k;
    for(int j=0; j<k; j++){
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <map>
#include <vector>
#include <utility>

using namespace std;

struct union_find {
    vector<int> par, sz;
    union_find(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            sz[i] = 0;
        }
    }

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

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

        if (x == y) return ;
        else {
            if (sz[x] < sz[y])
                par[x] = y;
            else {
                par[y] = x;
                if (sz[x] == sz[y])
                    sz[x]++;
            }
        }
    }   

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

int main() {
    int n, k, l;    cin >> n >> k >> l;
    union_find road(n), rail(n);

    for (int i = 0; i < k; i++) {
        int a, b;   cin >> a >> b;
        a--, b--;
        road.unite(a, b);
    }
    for (int i = 0; i < l; i++) {
        int a, b;   cin >> a >> b;
        a--; b--;
        rail.unite(a, b);
    }

    vector<pair<int,int> > com(n);
    map<pair<int,int>, int> s;
    for (int i = 0; i < n; i++) {
        com[i].first = road.find(i);
        com[i].second = rail.find(i);
        s[com[i]]++;
    }

    for (int i = 0; i < n; i++)
        cout << s[com[i]] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 13696
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb(x) push_back(x)

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

void solve(){
    int k; cin >> k;
    string str; cin >> str;
    int temp = k;
    for(int i = 0; i < str.length() && k; i++){
        cout << str[i];
        --k;
    }
    if(temp < str.length()) cout << "...";
}

int main(){

    // #ifndef ONLINE_JUDGE
    // freopen("/ATOMCODES/input.txt", "r", stdin);
    // freopen("/ATOMCODES/output.txt", "w", stdout);
    // #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();

}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;

template <class T>
T fexp(T x, long long e) {
	T ans(1);
	for(; e > 0; e /= 2) {
		if(e & 1) ans = ans * x;
		x = x * x;
	}
	return ans;
}

template <int mod = MOD>
struct modBase {
	modBase(int v = 0) : val((v % mod + mod) % mod) {}
	int val;
 
	void operator += (modBase<mod> o) { *this = *this + o; }
	void operator -= (modBase<mod> o) { *this = *this - o; }
	void operator *= (modBase<mod> o) { *this = *this * o; }
	modBase<mod> operator * (modBase<mod> o) { return (int)((long long) val * o.val % mod); }
	//modBase<mod> operator / (modBase<mod> o) { return *this * fexp(o, mod - 2); }
	modBase<mod> operator + (modBase<mod> o) { return val + o.val >= mod ? val + o.val - mod : val + o.val; }
	modBase<mod> operator - (modBase<mod> o) { return val - o.val < 0 ? val - o.val + mod : val - o.val; }
};

const int ms = 2001000;
modBase<> fat[ms], ifat[ms];
void initComb() {
	fat[0] = 1;
	for(int i = 1; i < ms; i++) {
		fat[i] = fat[i-1] * i;
	}
	ifat[ms-1] = fexp(fat[ms-1], MOD - 2);
	for(int i = ms-1; i > 0; i--) {
		ifat[i-1] = ifat[i] * i;
	}
}
modBase<> comb(int n, int a) { return a < 0 || a > n ? modBase<>(0) : fat[n] * ifat[a] * ifat[n-a]; }

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	initComb();
	int k;
	std::cin >> k;
	std::string str;
	std::cin >> str;
	int n = (int) str.size();
	modBase<> cur = fexp(modBase<>(26), k);
	modBase<> ratio = fexp(modBase<>(26), MOD - 2) * 25;
	modBase<> ans(0);
	for(int i = 0; i <= k; i++) {
		ans = ans + cur * comb(i + n - 1, n - 1);
		cur = cur * ratio;
	}
	std::cout << ans.val << '\n';
}

Measured memory_bytes: 19928
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;

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

	ll n, x;
	cin >> n >> x;
	vi v(n);
	rep(i, n) {
		cin >> v[i];
		x -= v[i];
	}
	sort(all(v));
	ll ans = n;
	ans += (x / v[0]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <regex>
#include <initializer_list>
#define DBL_MIN 0.000000000000001

#define A_P(n,a,d) (n/2)*(2*a + (n-1)*d)
using namespace std;

//ちゃんとlong型でやってる？

int main(void){
    int L,R,d;
    cin >> L >> R >> d;
    int cnt = 0;
    for(int i = L; i <= R; i++){
        if(i % d == 0){
            cnt ++;
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  int n;
  while(cin >> n, n!=0){
    int	t=0;
    for(int i=1;i<n;i++){
      int sum =	i;
      for(int j=i+1; j<n;j++){
        sum+=j;
        if(sum == n){
          t++;
          break;
        }else if(sum > n) break;
      }
    }
    cout<< t<<endl;
  }
}

Measured memory_bytes: 1160
#!/usr/bin/env python3

D = int(input())
# S = input()
# N, K = map(int, input().split())
# A = list(map(int, input().split()))

def main():
    if D == 25:
        print("Christmas")
    if D == 24:
        print("Christmas Eve")
    if D == 23:
        print("Christmas Eve Eve")
    if D == 22:
        print("Christmas Eve Eve Eve")


if __name__ == "__main__":
    main()



Measured memory_bytes: 2940
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;

  

int main(){
  double kakeru = 0.333333333333333333;
  double l; cin >> l;
  double ans = l*kakeru*l*kakeru*l*kakeru;
  printf("%.12lf\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	map<ll,ll> m;
	REP(i,n) {
		ll a;
		cin>>a;
		m[a]++;
	}
	vector<ll> p;
	auto ite=m.begin();
	while(ite!=m.end()) {
		if((*ite).second>=2&&(*ite).second<4) p.pb((*ite).first);
		if((*ite).second>=4) {
			p.pb((*ite).first);
			p.pb((*ite).first);
		}
		ite++;
	}
	sort(ALL(p));
	if(p.size()<2) cout<<0<<endl;
	else {
		cout<<p[p.size()-1]*p[p.size()-2]<<endl;
	}
}


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

int main()
{
    bool used[30];
    bool used2[30];
    memset(used,0,sizeof used);
    memset(used2,0,sizeof used2);
    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++)
        used[s[i]-'a']=1;
    string temp=s;
    bool f=0;
    vector<string>v;
    int j=0;
    if(s.length()<26)
    {
        for(int i=0; i<26; i++)
        {
            if(!used[i])
            {
                temp+='a'+i;
                v.push_back(temp);
                f=1;
                break;
            }
        }
    }
    if(!f)
    {
        string tt;
        for(int i=0; i<s.length(); i++)
        {
            int j=s[i]-'a'+1;
            for(; j<26; j++)
            {
                if(!used2[j])
                {
                    f=1;
                    v.push_back(tt+char(j+'a'));
                }
            }
            tt+=s[i];
            used2[s[i]-'a']=1;
        }
    }
    sort(v.begin(),v.end());
    //for(int i=0;i<v.size();i++)
    //    cout<<v[i]<<endl;
    if(f)
        cout<<v[0]<<endl;
    else
        cout<<-1<<endl;
}


Measured memory_bytes: 256
ache = None                                                         
                                                                     
def make_cache(string):                                              
    global cache                                                     
                                                                     
    n = len(string)                                                  
    cache = [-2] * n                                                 
                                                                     
    prev = None                                                      
    count = 0                                                        
                                                                     
    for i, c in enumerate(string):                                   
        if c == 'C' and prev == 'A':                                 
            count += 1                                               
                                                                     
        cache[i] = count                                             
        prev = c                                                     
                                                                     
                                                                     
if __name__ == "__main__":                                           
    N, Q = map(int, input().split())                                 
    string = input()                                                 
    make_cache(string)                                               
                                                                     
    for _ in range(Q):                                               
        l, r = map(int, input().split())                             
        print(cache[r-1] - cache[l-1]) 

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
typedef long long ll;
int k, A, B, L, R, T;
bool chk(int p){
	int a = A - p / (k+1) * k - p % (k+1);
	int b = B - p / (k+1); return b <= 1ll * a * k;
}
void Main(){
	scanf("%d%d%d%d",&A,&B,&L,&R);
	k = max((A-1)/(B+1)+1, (B-1)/(A+1)+1);
	int l=0, r=A+B+1;
	while(l<r){
		int mid=(l+r)>>1;
		if(chk(mid)) l=mid+1; else r=mid;
	} int a = A - l / (k+1) * k - l % (k+1);
	int b = B - l / (k+1);
	r = l + 1 + b - a * k;
	for(int i=L; i<=R; i++){
		if(i<=l){
			if(i % (k+1) == 0) putchar('B');
			else putchar('A');
		}
		else{
			if((i-r) % (k+1)) putchar('B');
			else putchar('A');
		}
	} puts("");
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&T);
	while(T--) Main(); return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
//key = 按头数字first和尾数字last构成的键值（ 如果first<last，则键值=first*10+last，存入A，否则键值=last*10+first,存入B） 
//value=key值相同的计数 
map<int,int> A,B;
void saveNumber( int number )
{
	int last = number%10;
	if( last == 0 ) return;
	int first = number;
	while(first>=10)
		first/=10;
	
	int value = first<last?first*10+last:last*10+first;
	if( first <= last ) 
	{
		if( A.find(value) == A.end() )
			A[value] = 1;
		else
			A[value] += 1;
	}
	else
	{
		if( B.find(value) == B.end() )
		{
			B[value] = 1;
		}
		else
			B[value] += 1;
	}
}
int main()
{
	int N;
	cin>>N;
	for( int i=1; i<=N; i++ )
		saveNumber(i); 
	map<int,int>::iterator iter;//定义一个迭代指针iter
	int sum = 0;
	for(iter=A.begin(); iter!=A.end(); iter++)
	{
		int key = iter->first;
		int count = iter->second; 
		
		if( key%11 == 0 )
		{
			sum += count*count;
		}
		else
		{
			if( B.find(key) != B.end() )
				sum += count*B[key]*2;
		}
	}
		
	cout << sum << endl;
	
	return 0;
}

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

signed main(){
    
    int n; cin>>n;
    vector<string> name(n);
    vector<int> march(5,0);
    string s="MARCH";
    rep(i,n){
        cin>>name.at(i);
        rep(j,5){
            if(name.at(i).at(0)==s.at(j)){
                march.at(j)++;
            }
        }
    }
    int ans=0;
    for(int i=0; i<=2; i++){
        for(int j=1; i+j<=3; j++){
            for(int k=1; i+j+k<=4; k++){
                ans+=march.at(i)*march.at(i+j)*march.at(i+j+k);
            }
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<long long> b(n+1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i+1] = b[i] + a[i];
  }
  int mod = 1000000007;
  long long ans = 0;
  for (int i = 0; i < n-1; i++) {
    long long sum = (b[n] - b[i+1])%mod;
    ans += a[i]*sum;
    ans %= mod;
  }
  cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) {

		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] p = new int[n];
		int ans=0;

		for(int i=0; i<n; i++) {
			p[i] = sc.nextInt();
		}

		Arrays.sort(p);

		for(int i=0; i<k; i++) {
			ans += p[i];
		}

		System.out.println(ans);

		sc.close();

	}

}


Measured memory_bytes: 38824
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,int_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,int_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define M1 100000000000000000ll
#define PRECISE cout.precision(18);
#define BS(v,n) binary_search(v.begin(),v.end(),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater <int>())
#define F first
#define S second
#define GET(i,p) get<p>(i)


int main(){

    FAST
//	PRECISE


ll n;
cin>>n;
ve <ll> v(n,0);
ll sum=0;
FOR(i,0,n)
cin>>v[i],sum+=v[i];
ll x=(n*(n+1))/2;
ve <ll> d(n,0);
FOR(i,0,n){
	d[i]=(v[(i+1)%n]-v[i]);
}
if(sum%x==0){

ll k=sum/x;
for(auto i:d)
	if((k-i)<0||((k-i)%n!=0)){
		cout<<"NO";
		return 0;
	}
cout<<"YES";


}
else{
	cout<<"NO";
}









//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
return 0;
 }

Measured memory_bytes: 4780
inlst = list(map(int, input().split()))
ans1 = 0
ans2 = 0
cnt1 = inlst[0] * inlst[4]
if cnt1 + (inlst[0] * 100) > inlst[-1]:
    cnt1 = inlst[-1] - (inlst[0] * 100)
wcnt1 = (cnt1 // inlst[2] + 1)
fcnt = wcnt1
roopcnt = inlst[-1] // (cnt1 + 100 * inlst[0])
def ansloop(wcnt1, fcnt, n):
    wcnt1 *= n
    fcnt *= n
    tans = 0
    while wcnt1 >= 0:
        tmpans = wcnt1 * inlst[2]
        if tmpans <= cnt1 * n:
            tmp = tmpans
            for i in range(fcnt):
                tmp += inlst[3]
                if tmp <= cnt1 * n:
                    tmpans = tmp
                else:
                    break
            tans = max(tans, tmpans)
        wcnt1 -= 1
    return tans
index = 1
for i in range(1, roopcnt + 1):
    tmp = ansloop(wcnt1, fcnt, i)
    if (100 * ans1) / (index * 100 * inlst[0] + ans1) < (100 * tmp) / (i * 100 * inlst[0] + tmp):
        ans1 = tmp
        index = i
print(100 * inlst[0] * index + ans1, ans1)

Measured memory_bytes: 3188
// Amsal Shoma Ro Gaedan Ye Amal Pasandidas !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 55;
const ll Inf = 2242545357980376863LL;
const ll Log = 18;
const int K = (2<<18) + 10;

int n, s, k, t, a[N], A[N], mark[N];
vector<int> V, V2;
int C = 0;
ll ans = 0;
int cnt[K];
ll Z[N];

void Solve(){
	int al = (1 << C);
	for(auto &x : V2) cnt[x] ++;
	for(int i = 0; i < C; i++){
		for(int j = 0; j < al; j++){
			if(j >> i & 1) cnt[j] += cnt[j ^ (1 << i)];
		}
	}

	for(int j = 0; j < al; j++){
		ans += Z[cnt[j]] * (__builtin_popcount(j ^ (al - 1)) & 1 ? -1 : 1);
		cnt[j] = 0;
	}
}

ll ch[N][N];
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for(int i = 0; i < N; i++)
		for(int j = 0; j <= i; j++)
			ch[i][j] = (j == 0 ? 1 : ch[i - 1][j] + ch[i - 1][j - 1]);
	
	cin >> n >> k >> s >> t;
	
	for(int i = 0; i <= n; i++) for(int j = 1; j <= k; j++) Z[i] += ch[i][j - 1];

	for(int i = 1; i <= n; i++) cin >> a[i];
	int sb, tb;
	for(int i = 0; i < 18; i++){
		sb = s>>i & 1;
		tb = t>>i & 1;
		if(sb == tb){
			for(int j = 1; j <= n; j++){
				if((a[j] >> i & 1) != sb) mark[j] = 1;
			}
			continue;
		}
		if(sb == 1) return cout << "0\n", 0;
		for(int j = 1; j <= n; j++){
			A[j] = A[j] * 2 + (a[j] >> i & 1);
		}
		C ++;
	}
	for(int j = 1; j <= n; j++) if(!mark[j]) V.pb(A[j]);

	n = V.size();
	for(int i = 0; i < n; i++){
		V2.clear();
		for(int j = i + 1; j < n; j++) V2.pb(V[i] ^ V[j]);
		Solve();
	}
	cout << ans << '\n';
	return 0;
}


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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, k;
	cin >> n >> k;

	int res = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;

		res += min(2 * a, 2 * (int)abs(k - a));
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
A=[]
for _ in range(n):
    cost,time=map(int,input().split())
    A.append([cost,time])
mincost=float('inf')
for i in range(n):
    if A[i][1]<=t:
        mincost=min(mincost,A[i][0])
if mincost==float('inf'):
    print('TLE')
else:
    print(mincost)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int A, B, K; std::cin >> A >> B >> K;

  std::set<ll> L;
  for(int i=A;    i<std::min(A+K,B+1); i++) L.insert(i);
  for(int i=std::max(A,B-K+1); i<=B; i++) L.insert(i);

  for(auto&& l : L) std::cout << l << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>

typedef long long ll;
ll a, b, n;

int main() {
	scanf("%lld%lld%lld", &a, &b, &n);
	
	ll x = std::min(b - 1, n);
	printf("%lld", a * x / b);
}

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

int gcd(int x, int y, int z){
  int a = __gcd(x, y);
  int b = __gcd(a, z);
  return b;
}

int main() {
	int k = 0;
	cin >> k;
	int a = 0;
	for(int i = 1; i <= k; i++ )
		for(int j = 1; j <= k; j++)
			for (int n = 1; n <= k; n++) {
				a += gcd(i, j, n);
			}
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;

vector<ll> p,c;//p点灯時の偶奇、実際の偶奇
map<ll,set<ll>> mp;//電球につながるスイッチの配列

signed main(){
    ll n,m,ans=0;
    cin>>n>>m;

    p.resize(m);

    for(ll i=0;i < m;i++)
    {
        ll k;
        cin>>k;
        for(ll j=0;j < k;j++)
        {
            ll x;
            cin>>x;
            mp[i].emplace(x-1);
        }
    }

    for(ll i=0;i < m;i++)
    {
        cin>>p.at(i);
    }

    for(int i=0;i < (1<<n);i++)
    {
        ll x=i,cnt=0;
        vector<ll> c(m,0);
        while(x>0){
            if(x%2==1){
                for(int j=0;j < m;j++)//電球j
                {
                    if(mp[j].count(cnt)){
                        c.at(j)++;
                    }
                }
            }
            cnt++;
            x/=2;
        }
        bool flag=true;
        for(int i=0;i < m;i++)
        {
            if(p.at(i)%2 != c.at(i)%2){
                flag=false;
                break;
            }
        }
        if(flag){
            ans++;
        }
    }
    cout<<ans<<endl;
}
/*2^x通りの全探索→底が２なのでDFSでなくbit全探索*/

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	s := make([]string, n)
	for i := range s {
		fmt.Scan(&s[i])
	}

	sort.Sort(sort.StringSlice(s))

	var ans string
	for _, si := range s {
		ans += si
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1280
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] NW = br.readLine().split(" ");
        int N = Integer.parseInt(NW[0]);
        int W = Integer.parseInt(NW[1]);
        
        long[][] dp = new long[N+1][W+1];
        dp[0][0] = 0;
        int[] ws = new int[N+1];
        int[] vs = new int[N+1];
        
        for (int i = 0; i < N; i++) {
            String[] line = br.readLine().split(" ");
            ws[i+1] = Integer.parseInt(line[0]);
            vs[i+1] = Integer.parseInt(line[1]);
        }
        
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= W; j++) {
                if (j-ws[i] >= 0) dp[i][j] = Math.max(dp[i-1][j-ws[i]] + vs[i], dp[i-1][j]);
                else dp[i][j] = dp[i-1][j];
            }
        }
        
        System.out.println(dp[N][W]);
    }
}



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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	VI as(n);
	rep (i, n) {
		cin >> as[i];
	}
	LL ans = 0;
	rep (i, as.size()) {
		ans += as[i] / 2;
		as[i] %= 2;
		if (i != 0 && as[i - 1] > 0) {
			ans += min(as[i], as[i - 1]);
			as[i - 1] -= min(as[i], as[i - 1]);
			as[i] -= min(as[i], as[i - 1]);
		}
		if (i != as.size() - 1 && as[i + 1] > 0) {
			ans += min(as[i], as[i + 1]);
			as[i + 1] -= min(as[i], as[i + 1]);
			as[i] -= min(as[i], as[i + 1]);
		}
	}
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    long long N, K, A, B, i, sum = 1;
    cin >> N >> K;
    for(i = 1; i <= N; i++)
    {
        A = sum *2;
        B = sum + K;
        if(A < B) sum = A;
        else sum = B;
    }
    cout <<sum << endl;
    return 0;
}


Measured memory_bytes: 256
//////////////////////////////
//////////////////////////////
////                      ////
////  Please give me AC!  ////
////  Please give me AC!  ////
////                      ////
//////////////////////////////
//////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
using  UM=unordered_map<char,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N,M;
  cin>>N>>M;
  vector<P> vec(N);
  map<ll,vector<ll>> mp;//価値と日数
  priority_queue<ll> q;
  ll maxb=0;
  for(ll i=0;i<N;i++){
    ll a,b;//aは何日かかるか、bは価値
    cin>>a>>b;
    vec.at(i)=make_pair(a,b);
    mp[a].push_back(b);
    if(b>maxb){maxb=b;}
    if(a==1){q.push(b);}
  }
  ll ans=0;
  vector<ll> work(M);
  for(ll i=1;i<=M;i++){//i日前
    if(q.empty()){work.at(M-i)=0;}
    else{work.at(M-i)=q.top();q.pop();}
    if(i<M){
      for(ll j=0;j<(ll)mp[i+1].size();j++){
        q.push(mp[i+1].at(j));
      }
    }
    ans+=work.at(M-i);
  }
  cout<<ans<<endl;
}

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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, k, h;
	cin>>n>>k;
	int ans=0;
	REP(i, n){
		cin>>h;
		if(h>=k){
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

// 線形探索
int search(int A[], int n, int key) {
	int i = 0;
	A[n] = key;
	while (A[i] != key) i++;
	return i != n;
}

int main() {
	int i, n, A[10000 + 1], q, key, sum = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &key);
		if (search(A, n, key)) sum++;
	}
	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 2748
p = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
q = [ 6, 7, 8, 9, 5, 4, 3, 2, 1, 0 ]
r = [ 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8 ]

ans' x [a,b] = 
  let t0 = dropWhile (/= a) x
      tr = dropWhile (/= b) t0
      t  = takeWhile (/= b) t0
  in
    if tr == []
    then Nothing
    else Just (t++[b])

ans i =
  let ap = ans' p i
      aq = ans' q i
  in
    case (ap,aq) of
      (Nothing, Just x) -> x
      (Just x, Nothing) -> x
      (Just x,  Just y) -> if (length x) <= (length y) then x else y
      (Nothing,Nothing) -> let Just z = ans' r i
                           in
                             z
main = do
  l <- getLine
  c <- getContents
  let n = read l :: Int
      i = map (map read) $ map words $ take n $ lines c :: [[Int]]
      o = map ans i
  mapM_ putStrLn $ map (\e -> unwords $ map show e ) o



Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e9)
using namespace std;
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll ans = (x + 11 - 1)/11;
    if(x % 11 == 0){
        ans *= 2;
    }else if(x % 11 <= 6){
        ans *= 2;
        ans--;
    }else{
        ans *= 2;
    }
    print(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;
template <class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
ll mod_pow(ll a, ll n, T mod) {
    mod = (ll)mod;
    ll res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    ll ansx = 0;
    rep(k, n) {
        k = (ll)k;
        ansx = (ansx + ((2 * k - n + 1) * x[k])) % MOD;
    }
    ll ansy = 0;
    rep(k, m) {
        k = (ll)k;
        ansy = (ansy + ((2 * k - m + 1) * y[k])) % MOD;
    }
    cout << ansx * ansy % MOD << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define uint unsigned int


#if 0
const int MOD = (int) ;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}
#endif


#if 0
int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}
#endif

using namespace std;




int main() {
#ifdef HOME
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, n, m, v, p;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> m >> v >> p;

    vector <int> a(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    vector <ll> x(n + 1);
    vector <bool> vis(n + 1);

    auto check = [&](int pos) -> bool {
        int cur = a[pos] + m;

        int big = 0;
        for(i = 1; i <= n; i++) {
            if(a[i] > cur) {
                big++;
            }
        }

        if(big >= p) {
            return 0;
        }

        fill(vis.begin(), vis.end(), 0);
        int sz = n;

        for(i = n; i >= 1; i--) {
            if(i == pos) continue;

            if(a[i] > cur) {
                x[sz--] = 1e18;
                vis[i] = 1;
            }
            else {
                if(big < p - 1) {
                    x[sz--] = 1e18;
                    big++;
                    vis[i] = 1;
                }
            }
        }

        for(i = 1; i <= n; i++) {
            if(i == pos || vis[i]) continue;

            x[sz--] = cur - a[i];
        }

        x[1] = 0;

        pos = 0;
        ll sum = 0;

        for(int j = 1; j <= n; j++) {
            if(x[j] == 0) continue;

            ll k = min(x[j] - 1, 1LL * m);
            while(pos <= n && x[pos] <= k) {
                sum += x[pos];
                pos++;
            }
            if(sum + 1LL * k * (n - pos + 1) < 1LL * k * (v - 1)) {
                return 0;
            }
        }
        return 1;
    };

    int res = 0;
    for(int step = 1 << 18; step; step >>= 1) {
        if(res + step <= n && check(res + step) == 0) {
            res += step;
        }
    }

    cout << n - res;

    return 0;
}


Measured memory_bytes: 1408