akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
/* ちゃんと考えてわかって実装 */

ll f(vector<ll> XX, ll b){
    ll res = 0;
    for(ll i=0; i<XX.size(); i++){
        res += abs(XX[i] - b);
    }
    return res;
}

int main(void){
    ll n;
    cin >> n;
    vector<ll> A(n);
    for(ll i=0; i<n; i++){
        cin >> A[i];
        A[i] -= (i+1);
    }
    sort(A.begin(), A.end());

    ll med1, med2, ans;
    if(n % 2 == 0){
        med1 = A[n/2];
        med2 = A[(n/2) - 1];
        ans = min(f(A, med1), f(A, med2));
    }
    else{
        med1 = A[n/2];
        ans = f(A, med1);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    
    vector<ll> a(5,0);
    rep(i,n){
        
        switch (s[i][0]) {
            case 'M':
                a[0]++;
                break;
            case 'A':
                a[1]++;
                break;
            case 'R':
                a[2]++;
                break;
            case 'C':
                a[3]++;
                break;
            case 'H':
                a[4]++;
                break;

            default:
                break;
        }
    }

    ll ans = 0;
    
    for(int i = 2; i < 5; i++){
        for(int j = 1; j < i; j++){
            for(int k = 0; k < j; k++){
                ans += a[i] * a[j] * a[k];
            }
        }
    }
    
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    priority_queue<int> queue;
    rep(i, N) {
        int a;
        cin >> a;
        queue.push(a);
    }

    while (M--) {
        int q = queue.top();
        queue.pop();
        queue.push(q / 2);
    }
    ll ans = 0;
    while (!queue.empty()) {
        int q = queue.top();
        queue.pop();
        ans += q;
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>
#include <tgmath.h>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


int main() {
    int a,b,c;
    cin>>a>>b>>c;

    cout<<((a+b)*c)/2<<endl;

}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n,m,k;
int dsu[100010];
bool used[100010];

int fi(int x) {
    return x==dsu[x] ? x : (dsu[x]=fi(dsu[x]));
}

int main() {
    scanf("%d%d",&n,&m);
    memset(dsu,0,sizeof(dsu));
    memset(used,0,sizeof(used));
    for (int i=0;i<=m;i++) dsu[i]=i;
    for (int i=0;i<n;i++) {
        scanf("%d",&k);
        int first,l;
        scanf("%d",&first);
        used[first]=true;
        for (int j=1;j<k;j++) {
            scanf("%d",&l);
            used[l]=true;
            if (fi(first)!=fi(l)) {
                dsu[fi(first)]=fi(l);
            }
        }
    }
    int idx=1;
    while (idx<=m&&(!used[idx])) idx++;
    int root=fi(idx);
    for (int i=idx+1;i<=m;i++) {
        if (used[i]&&fi(i)!=root) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
}

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

using namespace std;

int main()
{

    int TestCase;
    cin >> TestCase;

    string Answer[100];

    for(int a = 0; a < TestCase; a++)
    {
            float line1;
            float line2;
            float x1,x2,x3,x4;
            float y1,y2,y3,y4;

            cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;

            line1 = (y2-y1)/(x2-x1);
            line2 = (y4-y3)/(x4-x3);

            if (line1 == line2)
            {
                Answer[a] = "YES";
            }
            else
            {
                Answer[a] = "NO";
            }
    }

    for(int b = 0; b < TestCase; b++)
    {
        cout << Answer[b] << endl;
    }



    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dl;
const int iNF = 1e9 + 100;
const ll INF = 1e18 + 100;
typedef pair<int, int> pii;


int main(){
   int n;
   string s;
   cin >> s;
   n = s.length() + 1;
   ll cnt = 1;
   vector<bool> cross(n + 1, 0);
   vector<ll> nums;
   for(int i = 0; i < n - 1; i++){
      if(i < n - 1 and s[i] == s[i + 1]){
         cnt ++;
      }else{
         nums.push_back(cnt);
         cnt = 1;
      }
      if(s[i] == '<' and s[i + 1] == '>'){
         cross[nums.size() - 1] = 1;
      }
   }
   ll total = 0;
   for(int i = 0; i < nums.size(); i++){
      total += ( ( nums[i] * (nums[i] + 1) ) / 2 );
   }
   for(int i = 0; i < nums.size(); i++){
     if(cross[i]){
        total -= min(nums[i], nums[i + 1]);
     }
   }
   cout << total;
   return 0;   
}

Measured memory_bytes: 3068
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

runrun = [None for _ in range(100)]
runrun[1] = (1, 2, 3, 4, 5, 6, 7, 8, 9)


def gen_runrun_keta(k):
    for x in runrun[k - 1]:
        r = x % 10
        if r > 0:
            yield 10 * x + (r - 1)
        yield 10 * x + r
        if r < 9:
            yield 10 * x + (r + 1)


for keta in range(2, 11):
    runrun[keta] = tuple(gen_runrun_keta(keta))


rest = int(read())

answer = 0
for n in range(1, 11):
    if rest <= len(runrun[n]):
        answer = runrun[n][rest - 1]
        break
    rest -= len(runrun[n])
print(answer)


Measured memory_bytes: 12104
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

const int N = 210;
int n;
char s[N];
bitset<N> a[N],now,t,vis;

int main() {
	scanf("%d",&n);
	REP(i,0,n-1) { 
		scanf("%s",s);
		REP(j,0,n-1) a[i][j]=s[j]-'0';
	}
	int ans = -1;
	REP(i,0,n-1) {
		int tot = 1, ret = 0, ok = 1;
		now.reset();
		vis.reset();
		now.set(i);
		vis.set(i);
		while (1) {
			++ret;
			t.reset();
			REP(i,0,n-1) if (now[i]) t |= a[i];
			if ((t&now).any()) {
				ok = 0;
				break;
			}
			if (vis.count()==n) break;
			vis |= t;
			now = t;
		}
		if (ok) { 
			ans = max(ans, ret);
		}
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int W, a, b; cin >> W >> a >> b;
    if (abs(a - b) <= W) printf("%d\n", 0);
    else printf("%d\n", abs(a - b) - W);
}


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

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    // A B a
    // b C c
    // d e f
    //
    // S = A + B + a
    // S = B + C + e
    // S = A + C + f
    //
    //
    int A, B, C;
    cin >> A >> B >> C;
    int RS = 0;
    while(true) {
        REP(d2, 2) {
            int S = (d2 == 0 ? RS : -RS);
            int a = S - A - B;
            int f = S - A - C;
            int e = S - B - C;
            int c = S - a - f;
            int b = S - C - c;
            int d = S - A - b;
            set<int> st;
            st.insert(A + B + a);
            st.insert(b + C + c);
            st.insert(d + e + f);
            st.insert(A + b + d);
            st.insert(B + C + e);
            st.insert(a + c + f);
            st.insert(A + C + f);
            st.insert(a + C + d);
            if(st.size() == 1) {
                cout << A << " " << B << " " << a << endl;
                cout << b << " " << C << " " << c << endl;
                cout << d << " " << e << " " << f << endl;
                return 0;
            }
        }
        RS++;
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int a[100001];

int main() {
	int n,q,k,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	cin>>q;
	while(q--){
		scanf("%d",&k);
		if(*lower_bound(a,a+n,k)==k) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


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

int main () {
  int i = 1;
  int x = 0;
  while (1) {
    cin >> x;
    if (x == 0) break;
    cout << "Case " << i << ": " << x << "\n";
    i = i + 1;
  }
  return 0;
}

Measured memory_bytes: 1160
package main

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

func print(A []int) {
	s := make([]string, len(A))
	for i, o := range A {
		s[i] = strconv.Itoa(o)
	}
	fmt.Println(strings.Join(s, " "))
}

func main() {
	var sc = bufio.NewScanner(os.Stdin)

	sc.Scan()
	N, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	sc.Scan()
	A := make([]int, N)
	for i, v := range strings.Split(sc.Text(), " ") {
		n, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		A[i] = n
	}

	c := 0
	f := true
	for f {
		f = false
		for i := 0; i < N-1; i++ {
			j := i + 1
			if A[i] > A[j] {
				A[i], A[j] = A[j], A[i]
				c++
				f = true
			}
		}
	}
	print(A)
	fmt.Println(c)
}


Measured memory_bytes: 1148
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= N; a++) {
    if (N % a != 0) continue;
    ll ex = 0;
    while (N % a == 0) {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

void solve(ll N) {
  ll cnt = 0;

  auto pf = prime_factorize(N);
  for (auto p : pf) {
    ll a = p.first;
    ll ex = p.second;
    for (int e = 1; e <= ex; e++) {
      ll z = pow(a, e);
      if (N % z == 0) {
        N /= z;
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 4232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int x,y,z,num;
    int mx = INT_MAX;
    for(int i=0; i<s.size()-2; i++)
    {
        x  =s[i] - '0';
        y = s[i+1]- '0';
        z  = s[i+2]- '0';

        num = z+(10*y);
        num += (100*x);

        //cout<<num<<endl;
        mx = min(mx,abs(num - 753));
    }
    cout<<mx<<endl;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, M; cin >> N >> M;
  VL xs(N);
  REP(i,N) cin >> xs[i];

  int lcm = N * M / __gcd(N, M);
  LL ans = 0;
  set<int> q;
  for(int i=0;i<lcm;++i){
	q.insert(xs[i%N]);
	if((i+1)%M == 0){
	  ans += *--end(q) - *begin(q);
	  q.clear();
	}
  }
  cout << ans << endl;

  return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    set<int> A;
    rep(i,n){
        int Ai; cin >> Ai;
        A.insert(Ai);
    }
    int m; cin >> m;
    set<int> B;
    rep(i,m){
        int Bi; cin >> Bi;
        B.insert(Bi);
    }
    // 和集合
    set<int> C;
    for(auto Ai: A){
        if(!B.count(Ai)) C.insert(Ai);
    }
    for(auto Bi: B){
        if(!A.count(Bi)) C.insert(Bi);
    }
    for(auto Ci: C){
        cout << Ci << endl;
    }
}


Measured memory_bytes: 40520
#include<bits/stdc++.h>
      using namespace std;
      #define ll long long
      #define pb push_back
      #define pll  pair <long long,long long>
      #define mp make_pair
      #define ss second
      #define ff first
      #define maa 1000000007
      #define endl '\n'
      #define ld long double
      #define all(x) x.begin(),x.end()
      ll  power(ll  i,ll  j)
      {
        if(j==0)
        return 1 ;
        ll t=power(i,j/2)%maa ;
        if(j%2==0)
        return (t%maa*t%maa)%maa ;
        else
        return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
      }
      bool is(ll  i)
      {
        if(i==1)
            return 0 ;
        ll  f=0 ;
        for(ll  j=2;j<=sqrt(i);j++)
        {
            if(i%j==0)
            {
                f=1 ;
                break ;
            }
        }
        return !f ;
      }
      int main()
      {

        /// 50-4
        /// freopen("input.txt","r",stdin);
        /// freopen("output.txt","w",stdout);
        ll n,wt ;
        cin>>n>>wt ;
        vector<ll>dp(100001) ;
        
        for(ll i=0;i<100001;i++)
        dp[i]=-1 ;
        
        dp[0]=0 ;
        
        for(ll i=0;i<n;i++)
        {
            ll a,b ;
            cin>>a>>b ;
            for(ll v=100000-b;v>=0;v--)
            {
                if(dp[v]!=-1)
                {
                    if(dp[v+b]!=-1)
                    dp[v+b]=min(dp[v+b],dp[v]+a) ;
                    else
                    dp[v+b]=dp[v]+a ;
                }
            }
        }
        ll ans=0 ;
        for(ll i=0;i<100001;i++)
        {
            if(dp[i]!=-1&&dp[i]<=wt)
            ans=max(ans,i) ;
        }
        cout<<ans ;
      
        
        
      }








Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    if(500 * k >= x) cout << "Yes" << endl;
    if(500 * k < x) cout << "No" << endl;

    

    return 0;
    
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{	
	auto N = RD;
	auto A = RDR.ARR;

	long cnt;
	long cnt0;
	foreach (i; 0..N)
	{
		if (A[i] < 0)
			++cnt;
		else if (A[i] == 0)
			++cnt0;
	}
	A.sort!"abs(a) < abs(b)"();
	//debug writeln(A);

	long ans;
	if (cnt % 2 == 1)
		ans -= abs(A[0]);
	else
		ans += abs(A[0]);

	foreach (i; 1..N)
	{
		ans += abs(A[i]);
	}

	//debug writeln(ans);

	writeln(ans);
	stdout.flush();
	//debug readln();
}

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

int main(){
    string S;
    long long K;
    cin>>S>>K;
    for(int i=0;i<min(K,(long long)S.size());i++){
        if(S[i]!='1'){
            cout<<S[i]<<endl;
            return 0;
        }
    } 
    cout<<1<<endl;
    return 0;
}

Measured memory_bytes: 256
N,M,Q=map(int,input().split())
L=[0 for i in range(M)]
R=[0 for i in range(M)]
p=[0 for i in range(Q)]
q=[0 for i in range(Q)]
ans=[0 for i in range(Q)]
B=[[0 for i in range(N+1)] for i in range(N+1)]
C=[[0 for i in range(N+1)] for i in range(N+1)]
D=[[0 for i in range(N+1)] for i in range(N+1)]
for i in range(M):
    L[i],R[i]=map(int,input().split())
    L[i]-=1
    R[i]-=1
for i in range(Q):
    p[i],q[i]=map(int,input().split())
    p[i]-=1
    q[i]-=1
for i in range(M):
    B[R[i]][0]+=1
    B[R[i]][L[i]+1]-=1
    B[N][0]-=1
    B[N][L[i]+1]+=1
for i in range(N+1):
    for j in range(N+1):
        if i==0:
            C[i][j]=B[i][j]
        else:
            C[i][j]=B[i][j]+C[i-1][j]
for i in range(N+1):
    for j in range(N+1):
        if j==0:
            D[i][j]=C[i][j]
        else:
            D[i][j]=C[i][j]+D[i][j-1]
for i in range(Q):
    ans[i]=D[q[i]][p[i]]

for line in ans:
    print(line)


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

long n,a,x[100];
long dp[3000][1000];

int main()
{
	ios::sync_with_stdio(false);
	
	cin>>n>>a;
	
	for(int i=0;i<n;i++)
		cin>>x[i];
	
	dp[0][0]=1;
	
	for(int i=0;i<n;i++)
		for(int j=a*n;j>=x[i];j--)
			for(int k=n;k>0;k--)
				dp[j][k]+=dp[j-x[i]][k-1];
	
	long ans=0;
	
	for(int j=0;j<=a*n;j++)
		for(int k=1;k<=n;k++)
			if(j%k==0&&j/k==a)
				ans+=dp[j][k];
	
	cout<<ans<<endl;
	return 0;
}

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

int main(void)
{
  int n;
  cin >> n;
  char s[n];
  for(int i=0; i<n; i++){cin >> s[i];}

  int warray[n+1]={0}; warray[0] = 0;
  int earray[n+1]={0}; earray[0] = 0;
  for(int i=0; i<n; i++){
    if(s[i] == 'W'){warray[i+1]=warray[i]+1;}
    else{warray[i+1]=warray[i]+0;}
  }
  for(int i=0; i<n; i++){
    if(s[i] == 'E'){earray[i+1]=earray[i]+1;}
    else{earray[i+1]=earray[i]+0;}
  }

  int min=n-1;
  for(int lead=0; lead<n; lead++){
    int wcnt=warray[lead];
    int ecnt=earray[n]-earray[lead+1];
    if(min > wcnt+ecnt){min = wcnt+ecnt;}
  }
  cout << min << endl;
  return 0;

}


Measured memory_bytes: 2944
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.append(100)
B.append(100)
C.insert(0,0)
ans=0
for i in range(1,N+1):
	ans+=B[A[i-1]-1]
	if A[i-1]==A[i]-1:
		ans+=C[A[i-1]]
print(ans)


Measured memory_bytes: 3064
#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;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e5+7;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll dis1[MAX],val[MAX],dis2[MAX];
ll x[MAX],y[MAX];
ll rmqx[20][MAX],rmqy[20][MAX], lg[MAX];
void Sparse_Table_Pre_Process(int n)
{
    for(int i=0; i<n; i++)
    {
        rmqx[0][i]=x[i];
        rmqy[0][i]=y[i];
    }
    for(int i = 2; i <= n; i++)
        lg[i] = lg[i / 2] + 1;
    for(int i = 1; i <= lg[n]; i++)
        for(int j = 0; j < n - (1 << i) + 1; j++)
        {
            rmqx[i][j] = max(rmqx[i - 1][j], rmqx[i - 1][j + (1 << (i - 1))]);
            rmqy[i][j] = max(rmqy[i - 1][j], rmqy[i - 1][j + (1 << (i - 1))]);
        }
}
ll RMQX(int x,int y)
{
    return max(rmqx[lg[y - x + 1]][x], rmqx[lg[y - x + 1]][y - (1 << lg[y - x + 1]) + 1]);
}
ll RMQY(int x,int y)
{
    return max(rmqy[lg[y - x + 1]][x], rmqy[lg[y - x + 1]][y - (1 << lg[y - x + 1]) + 1]);
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,c,sum=0,mx=0;
    cin>>n>>c;
    for(int i=0; i<n; i++)
    {
        cin>>dis1[i];
        cin>>val[i];
        dis2[i]=c-dis1[i];
    }
    for(int i=0; i<n; i++)
    {
        sum+=val[i];
        mx=max(mx,sum-dis1[i]);
        x[i]=sum-dis1[i];
    }

    sum=0;
    for(int i=n-1; i>=0; i--)
    {
        sum+=val[i];
        mx=max(mx,sum-dis2[i]);
        y[i]=sum-dis2[i];
    }
    Sparse_Table_Pre_Process(n);
    sum=0;
    for(int i=0; i<n; i++)
    {
        sum+=val[i];
        ll add=0;
        if(i+1<n)
            add=RMQY(i+1,n-1);
        //cout<<sum+add-(dis1[i]*2ll)<<endl;

        // sum+=add;
        // cout<<i<<" "<<sum<<" "<<add<<endl;
        mx=max(mx,sum+add-(dis1[i]*2ll));
    }
    sum=0;
    for(int i=n-1; i>=0; i--)
    {
        sum+=val[i];
        ll add=0;
        if(i-1>=0)
            add=RMQX(0,i-1);
     //  cout<<sum+add-(dis2[i]*2ll)<<endl;
        mx=max(mx,sum+add-(dis2[i]*2ll));
    }
    cout<<mx<<endl;



    return 0;
}


Measured memory_bytes: 32960
#include<iostream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

const int MAX = 10000;

int main() {
	int N;
	int ans = 0;

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

		if (a & 1)continue;
		while (a % 2 == 0) {
			a /= 2;
			ans++;
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
 

typedef long long ll;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  set<string> s;
  while(n--){
    string ss;
    cin >> ss;
    s.insert(ss);
  }
  cout << s.size();
  return 0;
}

/*
         ,--"""",--.__,---[],-------._         
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________
 
*/

Measured memory_bytes: 19276
n, m = map(int, input().split())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
cd = []
for _ in range(m):
    c, d = map(int, input().split())
    cd.append((c, d))

for a, b in ab:
    mi_len = 10**9
    for ind, (c, d) in enumerate(cd):
        l = abs(a-c)+abs(b-d)
        if l<mi_len:
            mi_len = l
            mi_ind = ind+1
    print(mi_ind)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e17;
// Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int n, m;
    cin >> n >> m;
    vector<Int> c(m);
    for (Int i = 0; i < m; i++) cin >> c[i];
    vector<Int> dp(50010, INF);
    dp[0] = 0;
    sort(c.begin(), c.end());
    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j < m; j++) {
            if (i + c[j] <= n) dp[i + c[j]] = min(dp[i + c[j]], dp[i] + 1);
        }
    }
    dump(dp[n]);
    return 0;  
} 


Measured memory_bytes: 3360
<?php
list($n, $a, $b) = explode(' ', fgets(STDIN));
$ans = 0;
for($i=1;$i<=$n;$i++) {
    $j=$i;
    $sum = 0;
    while($j > 0) {
        $sum += $j%10;
        $j /= 10;
    }
    if ($sum >= $a && $sum <= $b) {
        $ans += $i;
    }
}
echo $ans;


Measured memory_bytes: 4604
using System;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int[] A = cin.ArrayInt(N);
        int ans = 0;
        for (int i = 0; i < N - 2; i++)
        {
            int cnt = 0;
            if (A[i] < A[i + 1]) cnt++;
            if (A[i + 2] < A[i + 1]) cnt++;
            if (cnt == 1) ans++;
        }
        Console.WriteLine(ans);
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
        
    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}





Measured memory_bytes: 11220
n = int(input())
S = [input() for _ in range(n)]
XA = 0
BA = 0
BX = 0
cnt = 0
for s in S:
    cnt+=s.count('AB')
    if s[0]!='B' and s[-1]=='A':
        XA+=1
    elif s[0]=='B' and s[-1]=='A':
        BA+=1
    elif s[0]=='B' and s[-1]!='A':
        BX+=1
if BA==0:
    cnt+=min(XA,BX)
else:
    if XA+BX>0:
        cnt+=min(XA,BX)+BA
    else:
        cnt+=BA-1
print(cnt)

Measured memory_bytes: 3700
def main():
    n = int(input())
    p = [int(x) for x in input().split()]

    count = 0
    array = [x for x in range(1,n+1)]
    for i in range(n):
        if p[i] != array[i]:
            count += 1
    if count <= 2:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;

  for (int r = 0; r <= 3000; ++r) {
    int rcnt = r * R;
    if (rcnt > N) break;

    for (int g = 0; g <= 3000; ++g) {
      int cnt = g * G + rcnt;
      if (cnt > N) break;

      int remain = N - cnt;
      if (remain % B != 0) continue;

      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k, n, i, ans=0;
    cin >> n >> k;
    int price[n];
    for(i=0; i<n; i++){
        cin >> price[i];
    }
    sort(price, price+n);
    for(i=0; i<k; i++){
        ans += price[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define mod 1000000007
#define mx 10005
//#define y 3
using namespace std;
typedef  long long int ll;
#define  f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#include <bitset>

void input(){
int n, m;
cin >> n >>m;
vector<vector<int> > v(m, vector<int>(2));
f(i, m)cin >> v[i][0] >> v[i][1];
int l, r;
l = v[0][0]; r= v[0][1];
if(m == 1){
    cout << r -l + 1<<endl;return;
}
int i =1;
for(i = 1; i < m; ++i){
        int l1 = v[i][0], r1 = v[i][1];
    if(l > r || r1 < l)break;
    if(l1 >=l && r1 <= r)l = l1, r= r1;
    else if(l >= l1 && r <=r1)l = l, r= r;
    else if(l1 >=l && r1 >= r)l = l1;
    else r = r1;
}
if(i != m) cout << 0 <<endl;
else cout << r - l + 1;
}
int main(){
    input();
    return 0;
}



Measured memory_bytes: 5888
from itertools import permutations

lst=[int(input()) for i in range(5)]
ans=float('inf')
tmp=0

for l in list(permutations(lst)):
    for i in range(4):
        tmp+=l[i]
        if tmp%10!=0:
            k=((tmp//10)+1)*10
            tmp+=(k-tmp)
    tmp+=l[4]
    if tmp<=ans:
        ans=tmp
    tmp=0
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, c, k;
int t[100010];

int solve() {
    sort(t, t+n);
    int res = 0, i = 0;
    int s, cnt;
    while (i < n) {
        s = t[i];
        cnt = 0;
        while (i < n && t[i] - s <= k && cnt+1 <= c) {
            i++;
            cnt++;
        }
        res++;
    }
    return res;
}

void input() {
    cin >> n >> c >> k;
    for (int i = 0; i < n; i++) cin >> t[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 640
// 4_abc134_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    rep1(i, n){
        cin >> a[i];
    }

    if(n == 1){
        if(a[1] == 1){
            cout << 1 << endl;
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }

    vector<int> b(n + 1);
    for(int j = n; j > n / 2; j--){
        if(a[j] == 1) b[j] = 1;
        else b[j] = 0;
    }
    for(int i = 2; i <= n; i++){
        for(int j = n / i; j > n / (i + 1); j--){
            int cnt = 0;
            for(int k = 2 * j; k <= n; k += j){
                if(b[k] == 1) cnt++;
            }
            if(a[j] == 0){
                if(cnt % 2 == 0) b[j] = 0;
                else b[j] = 1;
            }else{
                if(cnt % 2 == 0) b[j] = 1;
                else b[j] = 0;
            }
        }
    }
    int m = 0;
    rep1(i, n){
        if(b[i] == 1) m++;
    }

    cout << m << endl;
    rep1(i, n){
        if(b[i] == 1) cout << i << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>

int main()
{
int S, h, m, s;

scanf("%d",  &S);
h = S / 3600;
m = (S % 3600) / 60;
s = (S % 3600) % 60;

printf("%d:%d:%d\n", h,m,s);
return 0;
}



Measured memory_bytes: 2088
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 9 * (long long int)pow(10, 13);

int N,M;
int a[100], b[100], c[100], d[100];
int dis;
int ans[100];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= M; i++) {
		cin >> c[i] >> d[i];
	}
	for (int i = 1; i <= N; i++) {
		dis = abs(a[i] - c[1]) + abs(b[i] - d[1]);
		ans[i] = 1;
		for (int j = 2; j <= M; j++) {
			if (dis > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans[i] = j;
			}
		}
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

B = [0] + A + [0]
ans = 0
for x, y in zip(B[:-1], B[1:]):
    ans += abs(x-y)
for i in range(N):
    print(ans - abs(B[i+1]-B[i]) - abs(B[i+2]-B[i+1]) + abs(B[i+2]-B[i]))

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

bool sortbysec(const P &a, const P &b){
    return (a.second > b.second);
}

void Main() {
    ll n; cin >> n;
    map<int, int> omod, zmod; // one (mod2), zero (mod2)
    rep(i, n){
        ll v; cin >> v;
        if (i % 2 == 0){
            if (zmod.find(v) != zmod.end()){zmod[v] += 1;}else{zmod[v] = 1;}
        } else {
            if (omod.find(v) != omod.end()){omod[v] += 1;}else{omod[v] = 1;}
        }
    }
    vector<P> ovec, zvec;
    for (auto v: omod){ovec.push_back(make_pair(v.first, v.second));}
    for (auto v: zmod){zvec.push_back(make_pair(v.first, v.second));}

    sort(ovec.begin(), ovec.end(), sortbysec);
    sort(zvec.begin(), zvec.end(), sortbysec);

    if (ovec.at(0).first != zvec.at(0).first){
        cout << n - ovec.at(0).second - zvec.at(0).second << endl;
    } else {
        ll ans1 = -INF, ans2 = -INF;
        // if we use second elem in ovec
        if (ovec.size() == 1 && zvec.size() == 1){
            cout << min(ovec.at(0).second, zvec.at(0).second) << endl;
        } else {
            if (ovec.size() > 1){ans1 = n - ovec.at(1).second - zvec.at(0).second;}
            if (zvec.size() > 1){ans2 = n - ovec.at(0).second - zvec.at(1).second;}
            ll ans = (ans1 >= ans2) ? ans2 : ans1;
            cout << ans << endl;
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 7288
N, C = map(int, input().split())
events = []
for i in range(N):
    events.append(list(map(int, input().split())))

def solve():
    L = 250
    dp = [[-10**18]*(L+1) for i in range(C+1)]
    for j in range(C+1):
        dp[j][0] = 0
    for a, b, c in events:
        for j in range(C-c, -1, -1):
            for k in range(L+1):
                if k + (b-a) <= 0:
                    dp[j+c][a-k-b] = max(dp[j+c][a-k-b], dp[j][k]+k+b)
                else:
                    dp[j+c][k+b-a] = max(dp[j+c][k+b-a], dp[j][k]+a)
                if k + (a-b) <= L:
                    dp[j+c][k+a-b] = max(dp[j+c][k+a-b], dp[j][k]+b)
    ans = 0
    for j in range(C+1):
        ans = max(ans, max(dp[j]))
    return ans
print(solve())

Measured memory_bytes: 8720
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid_pleaseAC_fast;

	int a, b;
	cin >> a >> b;
	if (a + b == 15) {
		cout << "+" << rt;
	}
	else if (a * b == 15) {
		cout << "*" << rt;
	}
	else {
		cout << "x" << rt;
	}

	please AC;
}

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

int A[100000];

int main()
{
	int h, n;
	cin >> h >> n;
	for (int i = 0;i < n; ++i)
	{
		cin >> A[i];
	}
	for (int i = 0;i < n; ++i)
	{
		h = h - A[i];
	}
	if (h > 0)
	cout << "No";
	else
	cout << "Yes";
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int n;
ll ans=0;

int ok(ll x){
	bool f[3]={};
	while(x!=0){
		if(x%10==3)f[0]=true;
		if(x%10==5)f[1]=true;
		if(x%10==7)f[2]=true;
		x/=10;
	}
	if(f[0]==f[1]&&f[0]==f[2]&&f[0]==true)return 1;
	else return 0;
}


void dfs(ll sum){
	if(sum>n)return;
	if(ok(sum))ans++;
	dfs(sum*10+3);
	dfs(sum*10+5);
	dfs(sum*10+7);
}

int main(){
	cin>>n;
	dfs(3);
	dfs(5);
	dfs(7);
	print(ans);
}

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

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n = 1) : n(n), f(n + 1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x; }
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
    vector<pair<ll, int>> factor(ll x) {
        vector<pair<ll, int>> res;
        for (int p : primes) {
            int y = 0;
            while (x % p == 0) x /= p, ++y;
            if (y != 0) res.emplace_back(p, y);
        }
        if (x != 1) res.emplace_back(x, 1);
        return res;
    }
};

void solve(int N, std::vector<int> A) {
    Sieve sieve = Sieve(int(1e6) + 5);
    unordered_map<int, int> mp;
    sort(A.begin(), A.end());

    bool isPairewise = true;
    for (int i = 0; i < N; i++) {
        if (!isPairewise) {
            break;
        }
        vector<P> factors = sieve.factor(A[i]);
        for (P p : factors) {
            if (mp.find(p.first) == mp.end()) {
                mp[p.first]++;
            } else {
                isPairewise = false;
                break;
            }
        }
    }
    if (isPairewise) {
        cout << "pairwise coprime" << endl;
        return;
    }

    //setwise coprime を調査

    vector<unordered_map<int, int>> factors(N);
    for (int i = 0; i < N; i++) {
        vector<P> tempfactors = sieve.factor(A[i]);
        for (P p : tempfactors) {
            factors[i][p.first]++;
        }
    }
    bool isSetwise = true;
    for (auto itr = factors[0].begin(); itr != factors[0].end(); itr++) {
        // cerr << "target =" << target << endl;
        int t = itr->first;
        bool found = true;
        for (int i = 1; i < N; i++) {
            if (factors[i].find(t) == factors[i].end()) {
                found = false;
                break;
            }
        }
        if (found) {
            isSetwise = false;
            break;
        }
    }
    if (isSetwise) {
        cout << "setwise coprime" << endl;
        return;
    }
    cout << "not coprime" << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    int N;
    scanf("%d", &N);
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 278136