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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

  int H, W;
  int h, w;
  cin >> H >> W;
  cin >> h >> w;

  int masu = H * W;
  int nuri = h * W + w * H - h * w;


  cout << masu - nuri << endl;



  
}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        string s;
        cin>>s;
        if(s[2]==s[3]&&s[4]==s[5])
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = [int(each) for each in input().split()]
q = int(input())
rep = [tuple(int(each) for each in input().split()) for i in range(q)]

s = [sum(a)]

c = collections.Counter(a)
for i in range(q):
    diff = (rep[i][1]-rep[i][0])
    num = c.get(rep[i][0])
    if not num:
        num = 0
    # print('i:', i)
    # print(c)
    # print('差分:', diff, '個数:', num)
    s.append(s[-1]+num*diff)

    # 存在しないときにエラーになる
    if c.get(rep[i][0]):
        c[rep[i][1]] += c.pop(rep[i][0])

print('\n'.join([str(each) for each in s[1:]]))

Measured memory_bytes: 43876
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  string s;
  cin >> n >> s >> q;
  vector<set<int> >moji(26);
  int i;
  for(i=0;i<n;i++){
    int tmp = (int)(s[i]-'a');
    moji[tmp].insert(i);
  }
  for(int que=0;que<q;que++){
    int a;
    cin >> a;
    if(a==1){
      int iq;
      char cq;
      cin >> iq >> cq;
      iq--;
      moji[(int)(s[iq]-'a')].erase(iq);
      moji[(int)(cq-'a')].insert(iq);
      s[iq]=cq;
    }else{
      int lq,rq;
      cin >> lq >> rq;
      lq--;
      rq--;
      int ans = 0;
      for(i=0;i<26;i++){
        auto it = moji[i].lower_bound(lq);
        if(it!=moji[i].end() && *it <= rq)ans++;
      }
      cout<<ans<<endl;

    }
  }
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

#define x(p) real(p)
#define y(p) imag(p)

const double eps=1e-10;
const double inf=1e12;
typedef complex<double> P;

namespace std{
  bool operator<(const P& a,const P& b){
    return x(a)==x(b)?y(a)<y(b):x(a)<x(b);
  }
}
double cross(const P& a,const P& b){
  return y(conj(a)*b);
}
double dot(const P& a,const P& b){
  return x(conj(a)*b);
}
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

P projection(const L& l,const P& p){
  P b=l[1]-l[0],c=p-l[0];
  return l[0]+b*x(c/b);
}
P reflection(const L& l,const P& p){
  return p+2.0*(projection(l,p)-p);
}
//// counter-clockwise
int ccw(P a,P b,P c) {
  b=b-a;c=c-a;
  if(cross(b,c)>0) return +1;       // counter clockwise
  if(cross(b,c)<0) return -1;       // clockwise
  if(dot(b,c)<0)   return +2;       // c--a--b on line
  if(norm(b)<norm(c)) return -2;       // a--b--c on line
  return 0;
}

string s[]={"ONLINE_FRONT","CLOCKWISE","ON_SEGMENT","COUNTER_CLOCKWISE","ONLINE_BACK"};

int main(){
	cin.sync_with_stdio(false);
  int q;
  double x1,x2,x3,y1,y2,y3;
  cin>>x1>>y1>>x2>>y2;
  cin>>q;
  rep(i,q){
    cin>>x3>>y3;
    int res=ccw(P(x1,y1),P(x2,y2),P(x3,y3));
    cout<<s[res+2]<<endl;
  }
	return 0;
}

Measured memory_bytes: 3336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
using namespace std;
typedef pair<const int, int> pr;
typedef map<int, int> mp;

int main()
{
    int n;
    cin >> n;
    mp cnt;
    int idxCnt = 0;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (cnt.find(a) == cnt.end())
        {
            cnt[a] = 1;
            idxCnt++;
        }
        else
        {
            cnt[a]++;
        }
    }

    string ans = "No";
    if (idxCnt == 3)
    {
        vector<pr> elm;
        for (auto c : cnt)
        {
            elm.push_back(pr(c.first, c.second));
        }
        if ((elm[0].first ^ elm[1].first) == elm[2].first &&
            elm[0].second == elm[1].second &&
            elm[0].second == elm[2].second)
        {
            ans = "Yes";
        }
    }
    else if (idxCnt == 2)
    {
        vector<pr> elm;
        for (auto c : cnt)
        {
            elm.push_back(pr(c.first, c.second));
        }
        if ((elm[0].first ^ elm[1].first) == elm[1].first &&
            elm[0].second * 2 == elm[1].second)
        {
            ans = "Yes";
        }
        if ((elm[0].first ^ elm[1].first) == elm[0].first &&
            elm[0].second == elm[1].second * 2)
        {
            ans = "Yes";
        }
    }
    else if (idxCnt == 1)
    {
        for (auto c : cnt)
        {
            if (c.first == 0)
            {
                ans = "Yes";
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3840
def main(l):
    counts = {}
    answer = 0
    for nb in l:
        counts[nb] = counts.get(nb, 0) + 1
    for a in sorted(counts.keys(), reverse=True):
        b = (1 << a.bit_length()) - a
        c_a = counts[a]
        c_b = counts.get(b)
        if c_b:
            if a == b:
                answer += c_a // 2
            else:
                increment = c_a if c_a < c_b else c_b
                counts[a] -= increment
                counts[b] -= increment
                answer += increment

    return answer


if __name__ == '__main__':
    input()
    print(main(map(int, input().split())))

Measured memory_bytes: 44560
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

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

ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}
  
int main()
{
	int t;
	scanf("%d", &t);
	for(int i=0; i<t; i++){
		ll a, b, c, d;
		scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
      if(a<b){
        printf("No\n");
			continue;
		}
		if(b>d){
			printf("No\n");
			continue;
		}
		if(c>=b){
			printf("Yes\n");
			continue;
		}
		a%=b, d%=b;
		ll g=gcd(b, d);
		ll k=(b-a+g-1)/g;
		if(a+(k-1)*g<=c && (a+(b/g-1)*g)%b<=c){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MAX:usize = 100006;

fn main(){
    let x:i32 = read();

    let mut dp:[bool; MAX] = [false; MAX];
    dp[0] = true;
    for i in 100..x+1 {
        let i = i as usize;
        for j in 100..106 {
            let j = j as usize;
            if dp[i-j] { dp[i] = true }
            if i-j == 0 {break}
        }
        //if dp[i] {println!("{}: {}", i, dp[i]);}
    }

    println!("{}", if dp[x as usize] {"1"} else {"0"});
}

Measured memory_bytes: 4352
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int d = sc.nextInt();
		int n = sc.nextInt();

		int base = 1;
		for (int i = 0; i < d; i++) {
			base *= 100;
		}

		int ans = base * n;
		if (n % 100 == 0) {
			ans += base;
		}

		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define lg2 std::__lg
#define EB emplace_back

typedef long long ll;
typedef std::vector <int> vector;
const int N = 200054, M = N * 2, LN = 19, mod = 1000000007, iv2 = (mod + 1) / 2;

int n;
int p[N], fc[N], nc[N];
vector deps[N];
int dep[N], id[N], stack[N];
int cnt, st[LN][M], *o = *st;
int cnt_vir, vir[N], virp[N], virfc[N], virnc[N];
int f[N];
bool tag[N];

inline void link(int x, int px) {p[x] = px, nc[x] = fc[px], fc[px] = x;}
inline int dmin(const int x, const int y) {return dep[x] < dep[y] ? x : y;}
inline bool idcmp(const int x, const int y) {return id[x] < id[y];}

ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

void dfs(int x) {
	int y; o[cnt] = x, id[x] = cnt++;
	for (y = fc[x]; y; y = nc[y]) dep[y] = dep[x] + 1, dfs(y), o[cnt++] = x;
}

void build_sparse_table() {
	int *f, *g = o, i, j, k = cnt;
	for (j = 0; 1 << (j + 1) <= cnt; ++j) {
		f = g, g = st[j + 1], k -= 1 << j;
		for (i = 0; i < k; ++i)
			g[i] = dmin(f[i], f[i + (1 << j)]);
	}
}

inline int LCA(int x, int y) {
	int L, R, c; std::tie(L, R) = std::minmax(id[x], id[y]), c = lg2(++R - L);
	return dmin(st[c][L], st[c][R - (1 << c)]);
}

void DSA(int n, int *v) {
	#define ins(x) (virp[x] = stack[top], stack[++top] = vir[cnt_vir++] = x)
	int i, x, y, top = 0; cnt_vir = 0;
	for (i = 0; i < n; ++i)
		if (x = v[i], !top) {
			for (; top; --top) stack[top] = 0; ins(x);
		} else {
			stack[top + 1] = 0;
			for (y = LCA(x, stack[top]); dep[ stack[top] ] > dep[y]; --top);
			virp[ stack[top + 1] ] = y;
			if (stack[top] != y) ins(y); ins(x);
		}
	for (; top; --top) stack[top] = 0;
	std::sort(vir, vir + cnt_vir, idcmp);
}

inline void virlink(int x, int px) {virnc[x] = virfc[px], virfc[px] = x;}

int solve(vector &ps) {
	int i, x, y, _0, _1;
	std::sort(ps.begin(), ps.end(), idcmp), DSA(ps.size(), ps.data());
	for (i = 0; i < cnt_vir; ++i) virfc[vir[i]] = 0;
	for (i = 1; i < cnt_vir; ++i) virlink(vir[i], virp[vir[i]]);
	for (int x : ps) f[x] = iv2, tag[x] = true;
	for (i = cnt_vir - 1; i >= 0; --i) {
		if (tag[x = vir[i]]) continue;
		_0 = 1, _1 = 0;
		for (y = virfc[x]; y; y = virnc[y])
			_1 = (_1 * ll(mod + 1 - f[y]) + _0 * (ll)f[y]) % mod,
			_0 = _0 * ll(mod + 1 - f[y]) % mod;
		f[x] = _1;
	}
	for (int x : ps) tag[x] = false;
	return f[*vir];
}

int main() {
	int i, x; ll ans = iv2;
	scanf("%d", &n), ++n;
	for (i = 2; i <= n; ++i) scanf("%d", &x), link(i, ++x);
	dfs(1), build_sparse_table();
	for (i = 2; i <= n; ++i) deps[ dep[i] ].EB(i);
	for (i = 1; !deps[i].empty(); ++i) ans += solve(deps[i]);
	printf("%d\n", (int)PowerMod(2, n, ans % mod));
	return 0;
}

Measured memory_bytes: 55168
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

template<typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}

int main()
{
  ll n, k;
  cin >> n >> k;
  if (n < k) {
    cout << min(n, k - n) << endl;
    return 0;
  }

  ll t = n / k;
  n -= t * k;
  ll result = n;
  for (int i = 0; i < 3; ++i) {
    n = abs(n - k);
    result = min(result, n);
  }
  cout << result << endl;

  return 0;
}


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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    string s;
    scan(s);
    int x, y;
    scan(x, y);

    auto t = s.dup;
    int xs;
    while (!t.empty && t.front == 'F') {
        xs++;
        t.popFront();
    }

    debug {
        writeln("xs:", xs);
        writeln("t:", t);
    }

    auto xa = new int[][](2, 0);
    int mode;

    foreach (i ; 0 .. t.length) {
        if (t[i] == 'T') {
            mode ^= 1;
            xa[mode] ~= 0;
        }
        else {
            xa[mode].back += 1;
        }
    }

    debug {
        writeln(xa[0]);
        writeln(xa[1]);
    }

    xa[0] = xa[0].filter!"a > 0".array;
    xa[1] = xa[1].filter!"a > 0".array;

    auto ans = solve(xa[0], x, xs) && solve(xa[1], y, 0);

    writeln(ans ? "Yes" : "No");
}


bool solve(int[] a, int x, int s) {
    auto m = a.length.to!int;
    int zero = 8000;
    auto dp = new bool[][](m + 1, 2*zero + 1);
    dp[0][zero + s] = true;

    foreach (i ; 0 .. m) {
        foreach (j ; 0 .. 2*zero + 1) {
            if (j - a[i] >= 0) {
                dp[i + 1][j - a[i]] |= dp[i][j];
            }
            if (j + a[i] <= 2*zero) {
                dp[i + 1][j + a[i]] |= dp[i][j];
            }
        }

        debug {
            writefln("%(%b%)", dp[i + 1][zero .. zero + 20]);
        }
    }

    return dp[m][zero + x];
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 65788
#include <iostream>
#include <vector>

using namespace std;
int main()
{
  using ll = long long;
  using vll = vector<ll>;
  ll N;
  cin >> N;
  vll height(N), dp(N);
  for (auto &i : height) { cin >> i; }
  dp[0] = 0;
  dp[1] = abs(height[0] - height[1]);
  for (auto i = 2; i < N; i++) {
    dp[i] = min(dp[i-2] + abs(height[i-2] - height[i]),
		dp[i-1] + abs(height[i-1] - height[i]));
  }
  cout << dp[N-1];
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
int main(void){
    // Your code here!
 int d,t,s;
 cin >> d >> t >> s;
 cout << (d<=(t*s) ? "Yes" : "No");
 return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

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

        int train = Math.min(a, b);
        int bus = Math.min(c, d);

        System.out.println(train + bus);
    }
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int taro=0;
        int hanako=0;
        for(int i=0; i<n ;i++){
            String a=scanner.next();
            String b=scanner.next();
            switch(isWin(a,b)) {
                case 0:
                    taro++;
                    hanako++;
                    break;
                case 1:
                    taro += 3;
                    break;
                case 2:
                    hanako += 3;
                    break;
            }
        }
        System.out.println(taro+" "+hanako);
    }
    public static int isWin(String a,String b){
        int len=Math.min(a.length(),b.length());
        String alphabet="abcdefghijklmnopqrstuvwxyz";
        for(int i=0;i<len;i++){
            if(alphabet.indexOf(a.charAt(i))<alphabet.indexOf(b.charAt(i))){
                return 2;
            }else if(alphabet.indexOf(a.charAt(i))>alphabet.indexOf(b.charAt(i))){
                return 1;
            }
        }
        if(a.length()==b.length()){
            return 0;
        }else if(a.length()>b.length()){
            return 1;
        }else{
            return 2;
        }
    }
}



Measured memory_bytes: 29408
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,m,i,ta,tb,tc,mi,ma,b[2010101],d[2010101];
vector<pair<ll,ll> > v[2010101];
ll rmt(ll aa,ll bb)
{
//	cout<<aa<<" "<<bb<<"\n";
	ma=max(ma,bb);
	mi=min(mi,bb);
	if(b[aa]==0)
	{
		b[aa]=1;
		d[aa]=bb;
		ll ii;
		for(ii=0;ii<v[aa].size();ii++)
		{
			rmt(v[aa][ii].fi,bb+v[aa][ii].se);
		}
	}
	else
	if(d[aa]!=bb)
	{
		cout<<"No\n";
		exit(0);
	}
}
int main()
{
//	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>ta>>tb>>tc;
		v[ta].pb(mp(tb,tc));
		v[tb].pb(mp(ta,-tc));
	}
	for(i=1;i<=n;i++)
	{
		if(b[i]==0)
		{
			mi=10e17;
			ma=-mi;
			rmt(i,0);
		}
		if(ma-mi>1000000000)
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
}

Measured memory_bytes: 66560
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define int long long
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

signed main(){
	int n,a;
	cin>>n;
	map<int,int> mp;
	rep(i,n){
		cin>>a;
		mp[a]++;
	}
	int sum=0;
	for(map<int,int>::iterator ite=mp.begin();ite!=mp.end();ite++){
		if(ite->second%2)sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 6528
/************************************************
 * Au: Hany01
 * Date: Jan 14th, 2019
 * Prob: dp_w
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 WoXiHuanNiA

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template <typename T> inline T read() {
	register T _, __; register char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int MAXN = 2e5 + 5;

int n, m;
vector<PII> op[MAXN];

#define lc (t << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
LL mx[MAXN << 2], tg[MAXN << 2];
void maintain(int t) { mx[t] = max(mx[lc], mx[rc]); }
void pushdown(int t) {
	if (tg[t]) {
		mx[lc] += tg[t], mx[rc] += tg[t];
		tg[lc] += tg[t], tg[rc] += tg[t];
		tg[t] = 0;
	}
}
void update(int t, int l, int r, int x, int y, LL dt) {
	if (x <= l && r <= y) {
		mx[t] += dt, tg[t] += dt;
		return;
	}
	pushdown(t);
	if (x <= mid) update(lc, l, mid, x, y, dt);
	if (y >  mid) update(rc, mid + 1, r, x, y, dt);
	maintain(t);
}

int main() {
#ifdef hany01
	freopen("dp_w.in", "r", stdin);
	freopen("dp_w.out", "w", stdout);
#endif

	n = read<int>(), m = read<int>();
	For(i, 1, m) {
		int l = read<int>(), r = read<int>(), val = read<int>();
		op[r].PB(MP(l, val));
	}

	For(i, 1, n) {
		update(1, 1, n, i, i, mx[1]);
		for (PII t: op[i])
			update(1, 1, n, t.X, i, t.Y);
	}
	printf("%lld\n", max(0ll, mx[1]));

	return 0;
}

Measured memory_bytes: 22656
def solve():
    N,M,X=map(int,input().split())
    A=list(map(int,input().split()))
    c1 = len(list(filter(lambda e:e<X, A)))
    c2 = len(list(filter(lambda e:e>X, A)))
    return min(c1,c2)

print(solve())


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
priority_queue<int>q1,q2;
ll p[maxn],q[maxn],r[maxn],ans;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	rep(i,1,a) cin>>p[i];
	rep(i,1,b) cin>>q[i];
	rep(i,1,c) cin>>r[i];
	sort(p+1,p+1+a);
	sort(q+1,q+1+b);
	sort(r+1,r+1+c);
	per(i,a,1) {
		if(q1.size()>=x) break;
		q1.push(-p[i]);
		ans+=p[i];
	}
	per(i,b,1) {
		if(q2.size()>=y) break;
		q2.push(-q[i]);
		ans+=q[i];
	}
	per(i,c,1) {
		if(q1.size()<x) {
			q1.push(-r[i]);
			ans+=r[i];
		}
		if(q2.size()<y) {
			q1.push(-r[i]);
			ans+=r[i];
		}
		int now1=-q1.top(),now2=-q2.top();
		if(now1>now2) {
			if(now2<r[i]) {
				ans+=r[i];
				ans-=now2;
				q2.pop();
				q2.push(-r[i]);
			}
			else break;
		}
		else {
			if(now1<r[i]) {
				ans+=r[i];
				ans-=now1;
				q1.pop();
				q1.push(-r[i]);
			}
			else break;
		}
	}
	cout<<ans<<'\n';
	return 0;
}



Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=1e5+5;
lli dp[N];
vector<lli> v[N];
lli value(lli x)
{
    if(dp[x]==0)
    {
        for(auto j : v[x])
        dp[x]=max(dp[x],value(j));
        
        dp[x]++;
    }
    return dp[x];
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli n,m;
    cin>>n>>m;
    lli i,x,y,ans=0;
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
    }
    
    for(i=1;i<=n;i++)
    {
        ans=max(ans,value(i));
    }
    cout<<ans-1;
    return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define fi first
#define se second
using namespace std;

const int N = 1e5+7;
const int inf = 1e18;
int n, m;
vector <pair <int, int> > adj[N];
vector <int> dist;

void dijistra(int s){
    dist[s] = 0;
    priority_queue <pair <int, int>, vector <pair <int, int> >, greater<pair <int, int> > > pq;
    pq.push({0, s});
    while (!pq.empty()){
        pair <int, int> t = pq.top();
        pq.pop();
        int d = t.fi, u = t.se;
        if (d == dist[u]){
            for (int j=0; j<adj[u].size(); j++){
                pair <int, int> v = adj[u][j];
                if (dist[u] + v.se < dist[v.fi]){
                    dist[v.fi] = dist[u] + v.se;
                    pq.push({dist[v.fi], v.fi});
                }
            }
        }
    }
}

signed main(){
	cin >> n >> m;
	dist.assign(n, inf);
	for (int i=1; i<n; i++){
	    adj[i].pb({i-1, 0});
	}
	for (int i=1; i<=m; i++){
	    int l, r, w;
	    cin >> l >> r >> w; l--, r--;
	    adj[l].pb({r, w});
	    adj[r].pb({l, w});
	}
	dijistra(0);
	if (dist[n-1] == inf) cout << -1;
	else cout << dist[n-1];
} 

Measured memory_bytes: 13304
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<signal.h>
#include<unistd.h>
#define FR first
#define SC second
#define MP make_pair
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
#define ws wss
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
void read(int &x)
{
	char ch;int fu=1;
	while ((ch=getchar())<=32);
	x=0;
	if (ch=='-') fu=-1;else x=ch-48;
	while ((ch=getchar())>32) x=x*10+ch-48;
	x*=fu;
}
template<class T> void upmax(T &a,T b) { if (a<b) a=b;}
template<class T> void upmin(T &a,T b) { if (a>b) a=b;}

//---------template--------------
const int N=1000100,p=998244353;
int c[7123],bit[7777];
LL f[7777];
int n,a,b;
void C(int i) { for (;i<=n;i+=i&-i) bit[i]++;}
int  Q(int i) { int res=0;for (;i;i-=i&-i) res+=bit[i];return res;}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for (int i=1;i<=n;i++) scanf("%d",&c[i]);
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++) bit[j]=0;
		f[i]=1LL<<60;
		for (int j=i-1,k=0;j>=0;j--)
		{
		//	printf("%d %d\n",i,j);
			int l=Q(c[j]);
			if (c[j]<c[i]&&l+k==i-j-1) { f[i]=min(f[i],f[j]+1LL*l*b+1LL*k*a);}
			if (j>0) C(c[j]);
			if (c[j]>c[i]) k++;
		}
	}
	LL ans=1LL<<60;
	for (int i=1;i<=n;i++)
	{
		int flag=0;
//		printf("%lld ",f[i]);
		for (int j=i+1;j<=n;j++)
			if (c[j]>c[i]) { flag=1;break;}
		if (flag) continue;
		ans=min(ans,f[i]+1LL*(n-i)*b);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define N 5005
#define ll long long
using namespace std;
int n,a,b;
int s[N];
ll f[N][N];
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++) scanf("%d",&s[i]);
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
			f[i][j]=1e15;
	f[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(j<s[i]) f[i][s[i]]=min(f[i][s[i]],f[i-1][j]);
			if(j<s[i]) f[i][j]=min(f[i][j],f[i-1][j]+a);
			if(j>s[i]) f[i][j]=min(f[i][j],f[i-1][j]+b);
		}
	}
	ll ans=1e15;
	for(int i=1;i<=n;i++) ans=min(ans,f[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 195840
n = int(input())
lst_b = list(map(int, input().split()))
lst_a = list(map(int, input().split()))
sum = 0
for i in range(n):
  if lst_a[i] > lst_b[i]:
    tmp = lst_b[i]+lst_b[i+1]
    if lst_a[i]>tmp:
      sum += tmp
      lst_b[i+1] = 0
    else:
      sum += lst_a[i]
      lst_b[i+1] -= lst_a[i] - lst_b[i]    
  else:
    sum += lst_a[i]

print(sum)

Measured memory_bytes: 81892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  1<=A<=B<=20;
  1<=C<=20;
  cin>>A>>B>>C;
  if(C-(A-B)<=0){
    cout<<"0"<<endl;
  }else{
    cout<<C-(A-B)<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int h,w,i,k;
    while(1){
        scanf("%d %d\n",&h,&w);//h,w scan
        if(h==0 && w==0){
            break;
        }else{
            for(i=0;i<h;i++){    
                if((i+2)%2 == 1){
                    for(k=0;k < w;k++){
                        if((k+2)%2==1){
                            printf("#");
                        }else{
                            printf(".");
                        }
                    }
                    printf("\n");
                }else if((i+2)%2 == 0){
                    for(k=0;k < w;k++){
                        if((k+2)%2==1){
                            printf(".");
                        }else{
                            printf("#");
                        }
                    }
                    printf("\n");
                }
            }
        }
        printf("\n");
    }
    return 0; /*0?????????*/
}

Measured memory_bytes: 576
n = int(input())
arfa = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
str = ''
while n > 26:
  amari = n % 26
  n = n // 26 
  if amari == 0:
    n -= 1
  str += arfa[amari-1]
str += arfa[n-1]
print(str[::-1])



Measured memory_bytes: 9208
#include <stdio.h>
int main(){
  long long n,k,a=0,b=0;
  scanf("%lld%lld",&n,&k);
  a=n/k;
  if(k%2==0)b=((n+k/2)/k);
  printf("%lld",a*a*a+b*b*b);
}

Measured memory_bytes: 128
#C 
S =input()
s0=0
s1=0
for i in range(len(S)):
    if i%2==0 and S[i]=="0":
        s1+=1
    elif i%2==0:
        s0+=1
    elif i%2!=0 and S[i]=="0":
        s0+=1
    elif i%2!=0:
        s1+=1
print(min(s0,s1))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

int cnt[100005];

int main() {
	int n, q; cin >> n >> q;
	string s; cin >> s;
	s = "@" + s;
	for (int i = 2; i < (int)s.size(); i++) {
		cnt[i] = cnt[i - 1] + (s[i - 1] == 'A' && s[i] == 'C');
	}
	while (q--) {
		int l, r; cin >> l >> r;
		cout << cnt[r] - cnt[l] << endl;
	}
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0, x, y; cin >> x >> y; i++) {
    G.at(--x).push_back(--y);
    G.at(y).push_back(x);
  }
  vector<int> depth(N, -1), ans(N);
  queue<int> Q;
  Q.push(0);
  depth.at(0) = 0;
  ans.at(0) = -1;
  while (Q.size()) {
    int now = Q.front();
    Q.pop();
    for (auto next : G.at(now)) {
      if (depth.at(next) == -1) {
        depth.at(next) = depth.at(now) + 1;
        ans.at(next) = now;
        Q.push(next);
      }
    }
  }
  cout << "Yes" << "\n";
  for (int i = 1; i < N; i++) {
    cout << ans.at(i) + 1 << "\n";
  }
}

Measured memory_bytes: 10616
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct State{
  vector<int> v;
  State(vector<int> v) : v(v.begin(), v.end()) {}
  int head() const {
    return v.back();
  }
  bool operator < (const State& s) const {
    if(v.size() != s.v.size()) return v.size() > s.v.size();
    return head() > s.head();
  }
};

int main(){
  vector<int> s;
  s.push_back(1);
  priority_queue<State> que;
  que.push(State(s));
  int ans[2001];
  int cnt[2001] = {};
  REP(i, 2001) ans[i] = INF;
  const int B = 30;
  while(!que.empty()){
    State s = que.top(); que.pop();
    if(cnt[s.head()] >= B) continue;
    cnt[s.head()]++;
    ans[s.head()] = min(ans[s.head()], (int)s.v.size());
    for(int i = 0; i < s.v.size(); i++){
      int x = s.head() + s.v[i];
      if(1 < x && x <= 2000 && cnt[x] < B) {
        State next = s;
        next.v.push_back(x);
        que.push(next);
      }
      x = s.head() - s.v[i];
      if(1 < x && x <= 2000 && cnt[x] < B) {
        State next = s;
        next.v.push_back(x);
        que.push(next);
      }
    }
  }
  int N;
  while(cin >> N && N) cout << ans[N] - 1 << endl;
  return 0;
}

Measured memory_bytes: 26480
n = gets.chomp.to_i
s = gets.chomp.split(" ")
q = gets.chomp.to_i
t = gets.chomp.split(" ")

count = 0
q.times do |i|
  s.each do |ss|
    if t[i] == ss
      count += 1
      break
      # include? true or false can be the solution
    end
  end
end

puts count


Measured memory_bytes: 7100
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main(){

  int N, a, b, c, d, e;
  int f, g, h, i;
  bool tmp = true;
  while(cin >> N && N > 0){
    cin >> a >> b >> c >> d;
    if(tmp){
      tmp = false;
    }else{
      cout << endl;
    }
    e = 10*a + 50*b + 100*c + 500*d - N;
    i = e/500;
    h = (e-500*i)/100;
    g = (e-500*i-100*h)/50;
    f = (e-500*i-100*h-50*g)/10;

    if(a > f) cout << 10 << " " << a-f << endl;
    if(b > g) cout << 50 << " " << b-g << endl;
    if(c > h) cout << 100 << " " << c-h << endl;
    if(d > i) cout << 500 << " " << d-i << endl;



  }

}


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

std::vector<long long> l;
long long A;
long long B;
long long C;
long long answer = 1000000000LL;

void dfs(long long N, long long al, long long bl, long long cl, long long ac, long long bc, long long cc) {
    if (N == 0) {
        if (ac > 0 && bc > 0 && cc > 0) {
            answer = min(abs(A-al) + abs(B-bl) + abs(C-cl) + (ac - 1) * 10 + (bc - 1) * 10 + (cc - 1) * 10, answer);
        }
        return;
    }
    dfs(N-1, al+l[N-1], bl, cl, ac+1, bc, cc);
    dfs(N-1, al, bl+l[N-1], cl, ac, bc+1, cc);
    dfs(N-1, al, bl, cl+l[N-1], ac, bc, cc+1);
    dfs(N-1, al, bl, cl, ac, bc, cc);
}

void solve(long long N)
{
    dfs(N, 0,0,0, 0, 0, 0);
    printf("%lld\n", answer);
}

int main(){
    long long N;
    scanf("%lld",&N);
    scanf("%lld",&A);
    scanf("%lld",&B);
    scanf("%lld",&C);
    l.resize(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&l[i]);
    }
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n,h,w;
    cin>>n>>h>>w;
    int a,b,s=0;
    while(n--){
        cin>>a>>b;
        if(a>=h && b>=w) s++;
    }
    cout<<s<<endl;
    return 0;
}

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
//int choose2(ll x){
	//	return x*(x-1)/2;}
int main() {
	ll X, ans;
	cin >> X;
	ans = 0;
	ans += (X / 500)*1000;
	X = X % 500;
	ans +=( X / 5)*5;

	cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int count = 0;
	int i;
	
	scanf("%d%d%d", &a, &b, &c);
	
	for(i = 0; i < c; i++) {
		if(b - a >= 0) {
			b = b - a;
			count++;
		}
	}
	
	printf("%d", count);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;


int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(min(a + c, a + d), min(b + c, b + d));
	return 0;
}

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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    long long int n, w;
    cin >> n >> w;

    vector<pair<long long int, long long int>> weights;

    long long int x, y;
    for(long long int i=1; i<=n; i++){
        cin >> x >> y;
        weights.push_back({x,y});
    }

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

    // long long int dp[n+1][w+1];
    // for(long long int i=0; i<n; i++) dp[i][0]=0;
    // for(long long int j=1; j<=w; j++){
    //     if(weights[0].first<=j) dp[0][j]=weights[0].second;
    //     else dp[0][j]=0;
    // }
    
    // for(long long int i=1; i<n; i++){
    //     for(long long int capacity=1; capacity<=w; capacity++){
    //         if(capacity<weights[i].first) dp[i][capacity] = dp[i-1][capacity];
    //         else{
    //             dp[i][capacity] = max((weights[i].second + dp[i-1][capacity-weights[i].first]), dp[i-1][capacity]);
    //         }
    //     }
    // }

    // for(int i=0; i<=n; i++){
    //     for(int j=0; j<=w; j++) cout<<dp[i][j]<<' ';    
    //     cout<<'\n';
    // }

    // cout<<dp[n-1][w]<<'\n';

    // below is the space efficient approach-

    vector<ll> dp(w+1);
    for(int i=0; i<=w; i++){
        if(weights[0].first<=i) dp[i]=weights[0].second;
        else dp[i]=0;
    }

    for(int i=1; i<n; i++){
        vector<ll> new_dp(w+1);
        for(int capacity=0; capacity<=w; capacity++){
            if(weights[i].first>capacity) new_dp[capacity]=dp[capacity];
            else new_dp[capacity]=max(weights[i].second+dp[capacity-weights[i].first],dp[capacity]);
        }
        dp=new_dp;
    }
    cout<<dp[w]<<'\n';

    return 0;
}


Measured memory_bytes: 4764
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

  ll n, p;
  cin >> n >> p;
  string s;
  cin >> s;

  ll ans = 0;
  if (10 % p == 0) {
    rep(i, n) {
      ll d = s[i] - '0';
      if (d % p == 0) ans += i + 1;
    }
    cout << ans << endl;
    return 0;
  }

  vll csum(n + 1, 0);
  ll ten = 1;
  vll cnt(p, 0);
  cnt[0] = 1;
  rep(i, n) {
    ll d = s[n - 1 - i] - '0';
    csum[i + 1] = (csum[i] + ten * d) % p;
    ten = (ten * 10) % p;
    ans += cnt[csum[i + 1]];
    cnt[csum[i + 1]]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2196
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CManagement solver = new CManagement();
        solver.solve(1, in, out);
        out.close();
    }

    static class CManagement {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[n + 1];
            for (int i = 1; i < n; i++) {
                a[in.nextInt()]++;
            }
            for (int i = 1; i <= n; i++) {
                out.println(a[i]);
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    ll N, A, B;
    cin >> N >> A >> B;
    PRINT(N / (A + B) * A + min(A, N % (A + B)));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#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>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e9;


int main(){
  int Nmax;
  cin>>Nmax;
  rep1(n,Nmax){
    int f=0;
    if(n<6){
      cout<<0<<endl;
      continue;
    }
    int zmax=int(sqrt(double(n)-2.0)-1);
    int zmin=int(sqrt(double(n)/6.0));
    for(int z=zmin-1;z<=zmax+1;z++){
      for(int y=1;y<=z;y++){
        for(int x=1;x<=y;x++){
          if(x*x+y*y+z*z+x*y+y*z+z*x==n){
            if(x==y && y==z){
              f+=1;
            }else if(x==y || y==z || z==x){
              f+=3;
            }else{
              f+=6;
            }
          }
        }
      }

    }
    cout<<f<<endl;
  }
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>
#include <random>

using namespace std;

int main() {
    string S, result;
    int num = 0;
    cin >> S;
    num = S.size();
    for (int i = 0; i < num; i++) {
        result += "x";
    }
    cout << result;
}   


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

const int MAXN = 100100;

int n;
int A[MAXN], B[MAXN], C[MAXN];
ll sum[MAXN];

void load() {
	scanf("%d", &n);
	FOR(i, n) scanf("%d", A + i);
	FOR(i, n) scanf("%d", B + i);
	FOR(i, n) scanf("%d", C + i);
}

void solve() {
	sort(A, A + n);
	sort(B, B + n);
	sort(C, C + n);
	FOR(i, n) {
		int x = upper_bound(C, C + n, B[i]) - C;
		sum[i] = n - x;
	}
	for (int i = n - 1; i >= 0; i--) {
		sum[i] += sum[i + 1];
	}
	ll ret = 0;
	FOR(i, n) {
		int x = upper_bound(B, B + n, A[i]) - B;
		ret += sum[x];
	}
	printf("%lld\n", ret);
}

int main() {
	load();
	solve();
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, y;
  cin >> x >> y;
  set<int> a = {1, 3, 5, 7, 8, 10, 12};
  set<int> b = {4, 6, 9, 11};
  if(a.count(x) && a.count(y)) {
    cout << "Yes" << endl;
  } else if(b.count(x) && b.count(y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll dp[444][444];
ll pw(ll a, ll e) {
    ll res = 1;
    for(; e; e/=2) {
        if(e&1) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
    }
    return res;
}
ll sum(ll a, ll b, ll ex) {
    return dp[ex][b] - dp[ex][a-1];
}
ll dp2[444];
ll a[444];
ll b[444];
int main() {
    ll n, c;
    cin>>n>>c;
    for(int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    for(int i = 0; i < n; ++i) {
        cin>>b[i];
    }
    for(int i = 0; i < 444; ++i) {
        for(int j = 1; j < 444; ++j) {
            dp[i][j] = (dp[i][j-1] + pw(j, i))%MOD;
        }
    }
    dp2[0] = 1;
    for(int i = 0; i < n; ++i) {
        for(int j = c; j >= 0; --j) {
            dp2[j] = dp2[j] * sum(a[i], b[i], 0) % MOD;
            for(int k = 0; k < j; ++k) {
                dp2[j] += dp2[k] * sum(a[i], b[i], j-k);
                dp2[j] %= MOD;
            }
        }
    }
    dp2[c] += MOD;
    dp2[c] %= MOD;
    cout<<dp2[c]<<endl;
}


Measured memory_bytes: 1792
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
c=sorted(list(map(int,input().split())))
ans=0
for b_i in b:
  s_a=bisect.bisect_left(a,b_i)
  s_c=n-bisect.bisect_right(c,b_i)
  ans+=s_a*s_c
print(ans)

Measured memory_bytes: 23156