akhauriyash/Code-Regression huggingface dataset:
import math

N,H = map(int,input().split())
a = []
b = []

for i in range(N):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)

b.sort()
m = max(a)
ind = -1
for i in range(N):
    if b[i] > m:
        ind = i
        break

if ind == -1:
    print(math.ceil(H/m))
else:
    count = 0
    for i in reversed(range(ind,N)):
        if H > 0:
            H -= b[i]
            count += 1
        else:
            break
    if H > 0:
        count += math.ceil(H/m)
    print(count)

Measured memory_bytes: 11264
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 60;
const ll INF = numeric_limits<ll>::max();

int sum[Maxn][Maxn];

int n, k;

map<ll, int> compress(vector<ll> v, int &size) {
    map<ll, int> res;
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    size = 0;
    for (auto &e : v) res[e] = size++;
    //for (auto &m : res) v[m.second] = m.first;

    return res;
}

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
     */
    cin >> n >> k;
    vector<ll> x(n), y(n), xs(n), ys(n), xv(n), yv(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        xs[i] = x[i], ys[i] = y[i];
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());

    int h, w;
    auto xmp = compress(x, h);
    auto ymp = compress(y, w);
    for (auto &m : xmp) xv[m.second] = m.first;
    for (auto &m : ymp) yv[m.second] = m.first;

    for (int i = 0; i < n; ++i) {
        int tx = xmp[x[i]], ty = ymp[y[i]];
        sum[tx + 1][ty + 1]++;
    }

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

            sum[i + 1][j + 1] += sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
        }
    }

    ll ans = INF;
    for (int x1 = 0; x1 < n; ++x1) {
        for (int x2 = x1; x2 < n; ++x2) {
            for (int y1 = 0; y1 < n; ++y1) {
                for (int y2 = y1; y2 < n; ++y2) {
                    int lx = xmp[xs[x1]], rx = xmp[xs[x2]];
                    int ly = ymp[ys[y1]], ry = ymp[ys[y2]];
                    int cnt = sum[rx + 1][ry + 1] - sum[rx + 1][ly] - sum[lx][ry + 1] + sum[lx][ly];
                    if (cnt >= k) {
                        ans = min(ans, (xs[x2] - xs[x1]) * (ys[y2] - ys[y1]));
                    }
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
    int n;
    int d[50];
    int ans=0;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(i==j)continue;
            ans+=d[i]*d[j];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>
 
using namespace std;

typedef double db;

db solve(db n,db d1,db x)
{
	if (!n)
		return 0;
	db p = (2 * d1 + (2 * n - 1) * x) * n;
	db d2 = ((2 * n + 2) * d1 + 5 * x) / (2 * n);
	return p / (2 * n) + solve(n - 1,d2,(2 * (p - (4 * d1 + (4 * n - 2) * x) / (2 * n)) / (2 * n - 2) - 2 * d2) / (2 * n - 3));
}

int main()
{
	db n,d1,x;
	cin >> n >> d1 >> x;
	cout << fixed << setprecision(10) << solve(n,d1,x) << endl;
	return 0;
}

Measured memory_bytes: 6528
function Main(input) {
   var tmp = input.split("\n");
   var num = parseInt(tmp[0]);
   var ary = [];
   var pst = 0;
   var numAC = 0;
   var numWA = 0;
   var numTLE = 0;
   var numRE = 0;
   
   
   for(pst=1; pst<=num; pst++){
       ary.push(tmp[pst]);
   }
   for(pst=0; pst<ary.length; pst++){
       if(ary[pst]==="AC"){
           numAC+=1;
       }else if(ary[pst]==="WA"){
           numWA+=1;
       }else if(ary[pst]==="TLE"){
           numTLE+=1;
       }else if(ary[pst]==="RE"){
           numRE+=1;
       }
   }
   
   console.log("AC x "+numAC);
   console.log("WA x "+numWA);
   console.log("TLE x "+numTLE);
   console.log("RE x "+numRE);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 40060
N = int(input());
salto = [int(i) for i in input().split()];
 
Costo = [0, abs(salto[1] - salto[0])]+ [float('inf')]*(N - 2)  ;
 
for i in range(2, N):
    Costo[i] = min(Costo[i - 2] + abs(salto[i] - salto[i - 2]), Costo[i - 1] + abs(salto[i] - salto[i - 1]));
 
print(Costo[N - 1]);

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_DIGIT = (int)(4e1 + 5);
const int MAX_N = (int)(1e5 + 5);

int n;
ll k;
ll a[MAX_N];

int bit_cnt[MAX_DIGIT];
ll choice[MAX_DIGIT];

vector<ll> ansvec;
ll ans = -1;

/////////////////////////////////////////////////////////////
ll mypow_core(ll x, int n, ll result) {
  if (n == 0) {
    return result;
  }

  if (n % 2 == 0) {
    return mypow_core(x * x, n / 2, result);
  }
  else {
    return mypow_core(x, n - 1, x * result);
  }
}

ll mypow(ll x, int n) {
  return mypow_core(x, n, 1);
}
/////////////////////////////////////////////////////////////

ll calc(ll x) {
  ll ret = 0;
  for (int i = 0; i < n; ++i) {
    ret += x ^ a[i];
  }
  // printf("%lld\n", ret);
  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &k);

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(a[i]));
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < MAX_DIGIT; ++j) {
      if ((a[i] >> j) & 1LL) bit_cnt[j] += 1;
    }
  }

  for (int i = 0; i < MAX_DIGIT; ++i) {
    if (bit_cnt[i] > (n - bit_cnt[i])) {
      choice[i] = 0;
    }
    else {
      choice[i] = 1;
    }
  }

  ll acc = 0;
  ll minusacc = 0;

  ll kplus1 = k + 1;

  if ((kplus1 >> 0) & 1LL) {
    minusacc += (1LL << 0);
    ansvec.push_back(kplus1 - minusacc);
  }

  acc += (1LL << 0) * choice[0];

  for (int i = 1; i < MAX_DIGIT; ++i) {
    if ((kplus1 >> i) & 1LL) {
      minusacc += (1LL << i);
      ansvec.push_back(kplus1 - minusacc + acc);
    }
    acc += (1LL << i) * choice[i];
  }

  for (auto e: ansvec) {
    ans = max(ans, calc(e));
  }

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

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
    string s;
    cin >>s;

    char f0 = '0';
    char f1 = '1';
    int ans0 = 0;
    int ans1 = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != f0){
            ans0++;
        }
        if(s[i] != f1){
            ans1++;
        }
        swap(f0, f1);
    }
    printf("%d\n", min(ans0, ans1));
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int i,j,result;

	for(i=1; i<10; ++i)
	{
		for(j=1; j<10; j++)
		{
			result = i*j;
			
			printf("%dx%d=%d\n",i,j,result);
		}
	}

	return 0;
}

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

using namespace std;

int main(void){
	long long int N,K;
	long long int p;
	long long int count = 0;
	cin >> N >> K;
	if(K%2 == 1){
		p = N/K;
		count = p*p*p;
	}else if(K%2 == 0){
		p = N/K;
		count = p*p*p;
		p = 1+(long long int)((N-(K/2))/K);
      	if(N<K/2) p = 0;
		count += p*p*p;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var graph = Enumerable.Repeat(0, (int)N).Select(_ => new long[N]).ToArray();
            var edges = new List<(int from, int to, long cost)>();
            for (var i = 0; i < N; ++i)
                graph[i] = Sarray();
            for (var k = 0; k < N; ++k)
                for (var i = 0; i < N; ++i)
                    for (var j = 0; j < N; ++j)
                        if (graph[i][k] + graph[k][j] < graph[i][j])
                        {
                            WriteLine(-1);
                            return;
                        }
            var sum = 0L;
            for (var i = 0; i < N; ++i)
                for (var j = i + 1; j < N; ++j)
                {
                    var flg = true;
                    for (var k = 0; k < N; ++k)//i→jへの移動に直通路は必要か確認
                    {
                        if (k == i || k == j) continue;
                        if (graph[i][k] + graph[k][j] == graph[i][j])
                        {
                            flg = false;
                            break;
                        }
                    }
                    if (flg)
                        sum += graph[i][j];
                }
            WriteLine(sum);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 37484
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  
  string S;
  cin >> S;
  
  int year = stoi(S.substr(0,4));
  int mon  = stoi(S.substr(5,2));
  int day  = stoi(S.substr(8,2));
  
  if (year == 2019){
    if (mon < 5){
      cout << "Heisei" << endl;
    }
    else{
      cout << "TBD" << endl;
    }
  }
  else if (year < 2019){
    cout << "Heisei" << endl;
  }
  else{
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1 << 30;
// const ll INF = 1LL << 62;
// --------------------------------------------------------


double dist(int x1, int y1, int x2, int y2) {
    double dx = x1 - x2;
    double dy = y1 - y2;
    return pow(dx * dx + dy * dy, 0.5);
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    VI X(N), Y(N); REP(i,N) cin >> X[i] >> Y[i];

    double ans = 0.0;
    int num = 0;
    VI P(N); iota(ALL(P), 0);
    do {
        FOR(i, 0, N - 1) {
            int p1 = P[i], p2 = P[i + 1];
            ans += dist(X[p1], Y[p1], X[p2], Y[p2]);
        }
        num++;
    } while (next_permutation(ALL(P)));

    ans /= num;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FASTIO ios::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main() {
	FASTIO;
	string s, t;
	cin >> s >> t;
	int ans = SZ(t);
	for(int i = 0; i <= SZ(s) - SZ(t); ++i){
	    int diff = 0;
	    for(int j = 0; j < SZ(t); ++j){
	        if(t[j] != s[i+j]){
	            diff++;
	        }
	    }
	    ans = min(ans, diff);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[81];
ll dp[81];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	dp[0]=1000;
	for(int i=1;i<=n;i++){
		dp[i]=max(dp[i],dp[i-1]);
		for(int j=0;j<i;j++){
			ll num=dp[j]/a[j];
			dp[i]=max(dp[i],num*a[i-1]+dp[j]%a[j]);
		}
	}
	printf("%lld\n",dp[n]);
	return 0;
}


Measured memory_bytes: 3864
n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
ma=max(a)
if a.count(ma)>1:
  for i in range(n):
    print(ma)

else:
  for i in range(n):
    if a[i]==ma:
      a[i]=0
      print(max(a))
    else:
      print(ma)

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

int main() {
  int N,C,K;
  cin>>N>>C>>K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  int A=p[0],B=1,Z=1;
  for(int i=1;i<N;i++){
    if(B==C||p[i]-A>K){
      Z++;
      A=p[i];
      B=1;
    }
    else{
      B++;
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3756
# AOJ 0052: Factorial II
# Python3 2018.6.15 bal4u

pow5 = [1, 5, 25, 125, 625, 3125, 15625, 78125]

while True:
	n = int(input())
	if n == 0: break
	ans, i = 0, 1
	while n >= pow5[i]:
		ans += n // pow5[i]
		i += 1
	print(ans)


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

using namespace std;

int main(){
    int x;
    cin >> x;

    vector<int> vec;
    int cnt = 0;
    for(int i = 0; i < x; i++){
        int lover;
        cin >> lover; lover--;
        vec.push_back(lover);
        if(lover < i){
            if(i == vec.at(lover)){
                cnt++;
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

int main(void){
    int N,K,a;
    vector<ll> P;
    cin >> N >> K;
    REP(i,N){
        cin >> a;
        P.push_back(a);
    }
    sort(P.begin(),P.end());
    
    ll Ans=0;
    REP(i,K){
        Ans+=P[i];
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
using namespace std;
#define LL long long
const LL maxn = 3e5+55;
const LL mod = 998244353;
LL jie[maxn];

LL qkm(LL base,LL mi)
{
	LL ans=1;
	while(mi){
		if(mi&1)
			ans=ans*base%mod;
		base=base*base%mod;
		mi>>=1;
	}
	return ans;
}

LL C(LL a,LL b)
{
	//printf("%lld %lld %lld\n",jie[b],qkm(jie[b-a],mod-2),qkm(jie[a],mod-2));
	return jie[b]*qkm(jie[b-a],mod-2)%mod*qkm(jie[a],mod-2)%mod;
}


int main()
{



	jie[0]=1;
	for(LL i=1;i<maxn;i++)
		jie[i]=jie[i-1]*i%mod;


	LL n,a,b,k;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
	LL ans=0;
	for(LL i=0;i<=n;i++){
		if(k-i*a<0) break;
		if((k-i*a)%b==0){
			LL y=(k-i*a)/b;
			if(y<=n){
				ans+=C(i,n)*C(y,n)%mod;
				ans%=mod;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2560
# Template 1.0
import sys, re
from decimal import *
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor, trunc, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

x = INT()

print(x^1)

Measured memory_bytes: 70980
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque

n = int(input())

max_v = 0

s = {}
list = [[] for _ in range(n+1)]
for _ in range(n):
    str = input()
    if str in s:
        v = s[str] + 1
    else:
        v = 1
    s[str] = v
    max_v = max(max_v, v)
    list[v].append(str)

list[max_v].sort()

for str in list[max_v]:
    print(str)


Measured memory_bytes: 47660
import java.util.Scanner;

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

        int n = Integer.parseInt(sc.nextLine());
        int[] array = new int[n];
        String[] input = sc.nextLine().split(" ");

        for (int i=0; i<n; i++) {
            array[i] = Integer.parseInt(input[i]);
        }

        int count = 1;
        int nearbyHighest = array[0];
        
        for (int i=1; i<array.length; i++) {
            if (nearbyHighest <= array[i]) {
                nearbyHighest = array[i];
                count++;
            } else {
                continue;
            }
        }
        System.out.println(count);
    }
}

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

namespace ConsoleApplication1
{
    class ReverseSequence
    {
        static void Main(string[] args)
        {
            char[] charArray = System.Console.ReadLine().ToCharArray();
            for (int i = charArray.Length - 1; i >= 0; i--)
            {
                System.Console.Write(charArray[i]);
            }
        System.Console.Write("\n");
        }
    }
}

Measured memory_bytes: 5248
#if 0
2019.08.07

#endif
#include <cstdio>
#include <cstring>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 10001, mod = 998244353;
int f[maxn];
char s[maxn], t[maxn];
int jie[maxn];

inline lolong power(lolong x, int k) {
	if(k < 0) k += mod - 1;
	lolong res = 1;
	while(k) {
		if(k & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return res;
}

inline lolong C(int n, int m) {
	return jie[n] * power(jie[n - m], -1) % mod * power(jie[m], -1) % mod;
}

int main() {
	scanf("%s", s);
	scanf("%s", t);
	int n = strlen(s), a = 0, b = 0;
	for(int i = 0; i < n; i ++)
		if(s[i] == '1' and t[i] == '1')
			a ++;
		else if(s[i] == '1')
			b ++;
	jie[0] = 1;
	for(int j = 1; j <= n; j ++)
		jie[j] = 1ll * jie[j - 1] * j % mod;
	for(int j = 0; j <= b; j ++)
		f[j] = 1ll * jie[j] * jie[j] % mod;
	int ans = 1ll * f[b] * jie[a] % mod * jie[a] % mod *
			C(a, a) % mod * C(a + b, a) % mod;
	for(int i = 1; i <= a; i ++) {
		// f[0] = (1ll * f[0] * i * i) % mod;
		f[0] = 0;
		for(int j = 1; j <= b; j ++)
			f[j] = (1ll * f[j - 1] * j * j + 1ll * f[j] * i * j) % mod;
		ans = (1ll * f[b] * jie[a - i] % mod * jie[a - i] % mod *
				C(a, a - i) % mod * C(a + b, a - i) + ans) % mod;
	}
	printf("%d\n", ans);
}


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

int main() {
  int n, k, h, ans=0;
  cin >> n >> k;
  vector<int> height(n);
  
	for (int i=0; i<n; i++){
  	  cin >> height.at(i);
      if(height.at(i)>=k){
        ans += 1;
      }
    }

  cout << ans << endl;
}

Measured memory_bytes: 640
N = int(input())
S = input()
count = 0
for i in range(10):
    #print(S.find(str(i)),i)
    if S.find(str(i)) == -1:
        #print(S.find(str(i)),i)
        continue
    for j in range(10):
        if S.find(str(j),S.find(str(i))+1) == -1:
            #print(S.find(str(j)),j)
            continue
        for k in range(10):
            if S.find(str(k),S.find(str(j),S.find(str(i))+1)+1) != -1:
                #print(S.find(str(k)),k)
                count += 1
print(count)


Measured memory_bytes: 9280
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	if (N == 3) {
		cout << "2 5 63" << endl; return 0;
	}
	else if (N == 4) {
		cout << "2 5 20 63" << endl;
		return 0;
	}
	int a, b;
	if (N % 2) {
		a = min((N / 4 - 1) * 4 + 3, 9999LL);
		b = N - a;
	}
	else {
		a = min((N - 1) / 4 * 4, 10000LL);
		b = N - a;
	}
	FOR(i, 1, a + 1)cout << 3 * i << " ";
	int cnt = 0, x = 2;
	while (1) {
		if (x % 3 == 0) {
			x += 2;
			continue;
		}
		else {
			cout << x << (cnt != b - 1 ? " " : "\n");
			if (cnt == b - 1)break;
			else cnt++;
			x += 2;
		}
	}




	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if(s[i]=='1')
          ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// <------------- Template -----------------------> //

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

#pragma optimization_level 3   									//Comment optimisations for an interatcive problem - use endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll t=1;
ll n,x,m,a,y,b,k,c;
string s;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	ll ans = n/500*1000;
	n%=500;
	ans+=(n/5)*5;
	cout<<ans;newl;
}

int main() {
	fastio;randomINT;
	//cin>>t;
	while(t--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 235008
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(i):
    print(i,flush=True)
    s = ins()
    a[i] = h[s]
    if h[s]==1:
        exit()

h = {'Vacant':1, 'Male':2, 'Female':3}
n = inn()
a = [0]*(n+1)
foo(0)
a[n] = a[0]
p = 0
q = n
while True:
    r = (p+q)//2
    foo(r)
    if a[r]==a[p] and (r-p)%2==1 or a[r]!=a[p] and (r-p)%2==0:
        q = r
    else:
        p = r
        #ddprint(a)
    #ddprint(f"p {p} q {q}")




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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d)
    {
        cout << "Left" << endl;
    }
    else if(a + b == c + d)
    {
        cout << "Balanced" << endl;
    }else
    {
        cout << "Right" << endl;
    }
    
}

Measured memory_bytes: 3564
'''
1~9の文字列で構成されたSの中で
i文字目からj文字目までが2019の倍数になっているものの個数を求めよ

terms:
    1<=|S|<=2*10**5

input:
    1817181712114

output:
    3
'''
from collections import defaultdict
import sys
input = sys.stdin.readline
s = input()[:-1]
n=len(s)
arr = [int(s[i]) for i in range(n)]
ans = 0
dic = defaultdict(int)
dic[0] = 1
now = 0
for i in range(n - 1, -1, -1):
    now += arr[i] * pow(10, n - i - 1, 2019)
    now %= 2019
    ans += dic[now]
    dic[now] += 1
print(ans)

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

int n, a, b;
int ta = 0;

int main() {
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		if (i / 10000 + i / 1000 % 10 + i / 100 % 10 + i / 10 % 10 + i % 10 >= a && i / 10000 + i / 1000 % 10 + i / 100 % 10 + i / 10 % 10 + i % 10 <= b) {
			ta += i;
		}
	}
	cout << ta << endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

char table[501][501];
int main() {
	int H,W;
	cin >> H >> W;
	for(int i=0;i<H;i++){
		cin >> table[i];
	}
	for(int i=0;i<H;i++){
		cout << "#";
		for(int j=1;j<W-1;j++){
			if(i%2==0||table[i][j]=='#'){
				cout << "#";
			}
			else{
				cout << ".";
			}
		}
		cout << "." << endl;
	}
	cout << endl;
	for(int i=0;i<H;i++){
		cout << ".";
		for(int j=1;j<W-1;j++){
			if(i%2==1||table[i][j]=='#'){
				cout << "#";
			}
			else{
				cout << ".";
			}
		}
		cout << "#" << endl;
	}

	return 0;
}



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

int main(){
  int r = 0;
  string s;
  cin >> s;
  for(int i=0;i<4;++i){
    if(s[i]=='+'){
      ++r;
    } else{
      --r;
    }
  }
  cout<<r<<endl;
}

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

int main()
{
	int n, i, j;
    int h[1000000];
    int dp[1000000];

    scanf("%d", &n);

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

    dp[1] = abs(h[1] - h[0]);

    for (i = 2; i <= n; i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }

    printf("%d\n", dp[n-1]);
}

Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner in = new Scanner(System.in);
    	int n = in.nextInt();
    	int[] monsters = new int[n];
    	
    	for (int i = 0; i < n; i++) {
    		monsters[i] = in.nextInt();
    	}
    	
    	int ansGcd = 0;
    	for (int i = 0; i < n; i++) {
    		ansGcd = gcd(ansGcd,monsters[i]);
    	}
    	
    	System.out.println(ansGcd);
    }
    
    private static int gcd(int a,int b) {
     	if (a == 0) return b;
    	else return gcd(b%a, a);
    }
}



Measured memory_bytes: 50152
N = int(input())
cards = {"a" * 10: 0}
for _ in range(N):
    s = input()
    cards[s] = cards.get(s, 0) + 1
M = int(input())
for _ in range(M):
    s = input()
    cards[s] = cards.get(s, 0) - 1
print(max(cards.values()))

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int ans = 0;
  for(int i=2; i<n; i++){
    if(p[i-1]!=max({p[i-2],p[i-1],p[i]}) && p[i-1]!=min({p[i-2],p[i-1],p[i]}))
        ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> mp;
  rep(i, n) mp[a[i]]++;
  ll def = 0;
  for (auto e : mp)
    def += e.second*(e.second-1)/2;
  rep(i, n) {
    ll res = def;
    res -= mp[a[i]]*(mp[a[i]]-1)/2;
    res += (mp[a[i]]-1)*(mp[a[i]]-2)/2;
    cout << res << '\n';
  }
  return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<long long> a(n);
    vector<bool> h(n-k);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n-k;i++){
        if(a[i] < a[i+k]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <stdio.h>

int main(void){
  int x,out=0;
  std::cin >> x;
  while(x>=500){
    x=x-500;
    out=out+1000;
  }
  while(x>=5){
    x=x-5;
    out=out+5;
  }
  std::cout << out;
  return 0;
}

Measured memory_bytes: 3640
i = list(map(int, input().split()))
A = i[0]
B = i[1]

total = 0

if(A == B):
  print(A + A)
elif(A > B):
  total = total + A
  A = A - 1
  if(A >= B):
    total = total + A
    print(total)
  elif(B > A):
    total = total + B
    print(total)
elif(A < B):
  total = total + B
  B = B - 1
  if(A <= B):
    total = total + B
    print(total)
  elif(B < A):
    total = total + A
    print(total)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;
int main(void){
    string S,T;
    cin>>S>>T;
    cout<<T<<S<<endl;
}


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

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

const lli INF = (1LL<<49);

int main(){
  int n;
  while(cin >> n && n){
    int a;
    lli b,cnt;
    char c;
    vector<P> v;
    v.push_back(P(-1,INF));
    for(int i=0;i<n;i++){
      cin >> c;
      if(c == 'W'){
	cin >> a >> b;
	for(int j=0;j<v.size();j++){
	  if(v[j].first == -1){
	    if(b >= v[j].second){
	      v[j].first = a;
	      b -= v[j].second;
	      if(b == 0) break;
	    } else {
	      v.insert(v.begin()+j,P(a,b));
	      v[j+1].second -= b;
	      break;
	    }
	  }
	}
      } else if(c == 'D'){
	cin >> a;
	for(int j=0;j<v.size();j++) if(v[j].first == a) v[j].first = -1;
      } else if(c == 'R'){
	//for(int j=0;j<v.size();j++) cout << v[j].first << ' ' << v[j].second << endl;
	cin >> b;
	cnt = 0;
	for(int j=0;j<v.size();j++){
	  cnt += v[j].second;
	  if(cnt > b){
	    cout << v[j].first << endl;
	    break;
	  }
	}
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1336
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;


int gcd(int x,int y){
    int r;
if(x<y)swap(x,y);
while(y>0){
    r=x%y;
    x=y;
    y=r;
}
    return x;
}

int main(){
    
int N;
cin >> N;
vector<int>A;
int a;
for(int i=0;i<N;i++){
    cin >>a;
    A.push_back(a);
}

int m=gcd(A[0],A[1]);
for(int i=1;i<N-1;i++){
    a=gcd(A[i],A[i+1]);
    m=gcd(m,a);
}


cout << m <<endl;
 return 0;
}

Measured memory_bytes: 892
mod=10**9+7
n,m=map(int,raw_input().split())
mul1=mul2=1
if abs(n-m)>1:
    print 0
else:
    for i in range(1,n+1):
        mul1*=i
        mul1%=mod
    for i in range(1,m+1):
        mul2*=i
        mul2%=mod
    if n==m:
        print (2*mul1*mul2)%mod
    else:
        print (mul1*mul2)%mod

Measured memory_bytes: 5764
N,M,X=map(int,input().split())
C=[]
As=[]
for _ in range(N):
  c,*a=map(int,input().split())
  C+=[c]
  As+=[a]
r=1e9
for i in range(2**N):
  cost=0
  perf=[0]*M
  for j in range(N):
    if (i>>j)&1:
      cost+=C[j]
      perf=[perf[k]+As[j][k] for k in range(M)]
  if all(p>=X for p in perf):
    r=min(r,cost)
if r==1e9:r=-1
print(r)

Measured memory_bytes: 9192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
int digit(int a){
    int count = 0;
    for (int i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }     
    }
    return count;
}
//pow(x,n) == x^n

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

string s;
cin >> s;
int n = s.size();
rep(i,n){
    for(int j = i+1;j < n;j++){
        if(s.at(i) == s.at(j)){
            cout << "no" << endl;
            return 0;
        }
    }
}
cout << "yes" << endl;

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  int ans=0;
  int now=100;
  while(now<x){
    now+=(now/100);
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <limits.h>

#define WHITE 1
#define GRAY 2
#define BLACK -1

int Adj[101][101], d[101], time, n;
int head, tail;
int Q[100];

enque(int x){
  Q[tail] = x;
  if(tail + 1 == 100){
    tail = 0;
  }else{
    tail++;
  }
}

int deque(){
  int x = Q[head];
  if(head + 1 == 100){
    head = 0;
  }else{
    head++;
  }

  return x;

}  

int isEmpty(){
  if(tail == head){
    return 1;
  }else{
    return 0;
  }
}

bfs(){
  int s = 1, u, v;
  int color[101];

  for(u=2; u<=n; u++){
    color[u] = WHITE;
    d[u] = -1;
  }

  color[s] = GRAY;
  d[s] = 0;

  enque(s);

  while(!isEmpty(Q)){
    u = deque();
    for(v=1; v<=n; v++){
      if(Adj[u][v] && color[v] == WHITE){
	color[v] = GRAY;
	d[v] = d[u] + 1;
	enque(v);
      }
    }
    color[u] = BLACK;
  }

}


int main(){
  int i, j, u, k, temp;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    for(j=0; j<k; j++){
      scanf("%d",&temp);
      Adj[u][temp] = 1;
    }
  }

  bfs();

  for(i=1; i<=n; i++){
    printf("%d %d\n", i, d[i]);
  }

  return 0;

}

Measured memory_bytes: 636
#include <stdio.h>

int judge(int num)
{
	int i;
	
	if (num < 2){
		return (0);
	}
	if (num == 2){
		return (1);
	}
	if (num % 2 == 0){
		return (0);
	}
	for (i = 3; i * i <= num; i += 2){
		if (num % i == 0){
			return (0);
		}
	}
	return (1);
}

int main(void)
{
	int n, num;
	int ct = 0, i;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d", &num);
		if (judge(num)){
			ct++;
		}
	}
	
	printf("%d\n", ct);
	return (0);
}

Measured memory_bytes: 596
#include<stdio.h>
#include<string.h>
int main(void){
  long long int n,k,q,i;
  scanf("%lld%lld%lld",&n,&k,&q);
  long long int a[n],t;
  for(i=0;i<n;i++){
    a[i]=k;
  }
  for(i=0;i<q;i++){
    scanf("%lld",&t);
    a[t-1]++;
  }
  for(i=0;i<n;i++){
    a[i]=a[i]-q;
  }
  for(i=0;i<n;i++){
    if(a[i]<=0) printf("No\n");
    else printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int n, m;
    cin >> n >> m;
    vector< string > board(m);
    i_i all = i_i(0, 0);
    i_i sum = all;

    rep(i, m) {
        cin >> board[i];
    }

    vector< i_i > cnt(n, i_i(0, 0));
    rep(i, n) {
        rep(j, m) {
            if (board[j][i] == 'W') {
                cnt[i].first++;
                all.first++;
            } else {
                cnt[i].second++;
                all.second++;
            }
        }
    }
//    cout << all.first << " " << all.second << endl;

    int min = all.first, ans = -1;
    rep(i, n) {
        sum.first += cnt[i].first;
        sum.second += cnt[i].second;
        all.first -= cnt[i].first;
        all.second -= cnt[i].second;
        //cout << sum.first << sum.second << endl;
        //cout << all.first << all.second << endl;
        int tmp = sum.second + all.first;
        //cout << tmp << endl;
        if (min > tmp) {
            min = tmp;
            ans = i;
        }
    }

    cout << ans+1 << " " << ans+2 << endl;

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll K,A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>A>>B;
	if(A>=K) {
		cout<<1<<endl;
	}
	else if(A<=B) {
		cout<<-1<<endl;
	}
	else {
		cout<<((K-A)+A-B-1)/(A-B)*2+1<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n,k;
    cin>>n>>k;
    vi a(n),b(n+1,0);
    rep(i,n){
        cin>>a[i];
        b[a[i]]++;
    }
    b.erase(remove(b.begin(),b.end(),0),b.end());
    sort(all(b));
    int x=b.size();
    if(x<k){cout<<0<<endl;return 0;}
    else{
        int ans=0;
        for(int i=0;i<x-k;++i){
            ans+=b[i];
        }
        cout<<ans<<endl;
    }
}

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

#define int long long
#define INF 1e18

int n;
vector<int> v;
vector<int> pref;

int memo[409][409];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    v.resize(n+1);
    pref.resize(n+1);
    fill(pref.begin(), pref.end(), 0);
    for(int i = 1; i <= n; i++){
        cin >> v[i];
        pref[i] += pref[i-1];
        pref[i] += v[i];
    }
    for(int l = n; l >= 0; l--){
        for(int r = l+1; r <= n; r++){
            memo[l][r] = INF;
            for(int i = l; i <= r; i++){
                memo[l][r] = min(memo[l][r], pref[r]-pref[l-1]+memo[l][i]+memo[i+1][r]);
            }
        }
    }
    cout << memo[1][n] << endl;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        Map<Integer, List<Integer>> d = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int k = Integer.parseInt(sc.next());
            for (int j = 0; j < k; j++) {
                int s = Integer.parseInt(sc.next()) - 1;
                List<Integer> l = d.getOrDefault(s, new ArrayList<>());
                l.add(i);
                d.put(s, l);
            }
        }

        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = Integer.parseInt(sc.next());
        }

        int res = 0;

        for (int i = 0; i < (1 << n); i++) {
            int[] ii = new int[m];
            for (int j = 0; j < n; j++) {
                if((1 & i >> j) == 1) {
                    List<Integer> l = d.getOrDefault(j, new ArrayList<>());
                    for (int iii : l) {
                        ii[iii] += 1;
                    }
                }
            }

            boolean b = true;
            for (int j = 0; j < m; j++) {
                if(ii[j] % 2 != p[j]) {
                    b = false;
                    break;
                }
            }
            if(b) {
                res++;
            }
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 21844
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n, h, w;
    scan(n, h, w);
    long[] len = new long[n];
    long[] side = new long[n];
    long[] ans = new long[n];
    foreach (e; 0 .. n)
    {
        scan(len[e], side[e]);
    }
    foreach (ref e; len)
    {
        if (e < h)
        {
            e = 0;
        }
    }
    foreach (ref e; side)
    {
        if (e < w)
        {
            e = 0;
        }
    }
    foreach (i, ref e; ans)
    {
        e = len[i] && side[i];
    }
    ans.sum.writeln();
}

Measured memory_bytes: 380
#include <iostream>

const int ms = 10100;

int a[ms], b[ms];

std::string qry(int i) {
	std::string str;
	std::cout << i << std::endl;
	std::cin >> str;
	return str;
}

int main() {
	int n;
	std::cin >> n;
	std::string base = qry(0);
	if(base[0] == 'V') return 0;
	int l = 1, r = n - 1;
	while(l != r) {
		int mid = (l + r) / 2;
		std::string str = qry(mid);
		if(str[0] == 'V') return 0;
		if(mid % 2 == 0) {
			if(str == base) {
				l = mid + 1;
			} else {
				r = mid;
			}
		} else {
			if(str != base) {
				l = mid + 1;
			} else {
				r = mid;
			}
		}
	}
	qry(l);
}

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

int main() {
  int taste[200];
  int N, L;
  cin >> N >> L;

  for (int i{}; i < N; ++i)
    taste[i] = L + i;

  sort(taste, taste+N, [](int l, int r) {
    return abs(l) < abs(r);
  });

  int ans{};
  for (int i{1}; i < N; ++i)
    ans += taste[i];

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,m,a[100000],s,ms;
	while(cin >> n >> m,n){
		ms = s = 0;
		for(int i = 0;i < n;++i){
			cin >> a[i];
			if(i < m){
				ms += a[i];
				s += a[i];
			}
			else{
				s = s + a[i] - a[i - m];
				if(ms < s) ms = s;
			}
		}
		cout << ms << endl;
	}
	return 0;
}

Measured memory_bytes: 1548