akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> a(M);
    for(int i = 0; i < M; i++){
        int b, c;
        cin >> b >> c;
        b--;
        c--;
        a[i] = make_pair(b, c);
    }
    sort(a.begin(), a.end());
    int u = 0;
    long long ans = 0;
    priority_queue<int, vector<int>, greater<int>> pq;
    for(int i = 0; i < N; i++){
        if(!pq.empty() && i == pq.top()){
            ans++;
            priority_queue<int, vector<int>, greater<int>> pq2;
            pq = pq2;
        }
        while(i == a[u].first && u < M){
            pq.push(a[u].second);
            u++;
        }
    }
    cout << ans << endl;
}

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

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n,m;
  while(n = getInt(), m = getInt(), n+m){
    vector<pair<int,int> > d(n);
    REP(i,n){
      d[i].s = getInt();
      d[i].f = getInt();
    }
    sort(d.rbegin(), d.rend());
    REP(i,n){
      if(m > 0){
        if(d[i].s > m){
          d[i].s -= m;
          m = 0;
        }else{
          m -= d[i].s;
          d[i].s = 0;
        }
      }
    }
    long long ans = 0;
    REP(i,n)
      ans += d[i].f * d[i].s;
    printf("%lld\n",ans);
  }
  return 0;
}

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

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

    long max_xy = max(a * c, a * d);
    max_xy = max(max_xy, b * c);
    max_xy = max(max_xy, b * d);

    cout << max_xy << endl;
    return 0;
}

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

ll n, m, i, j, w[109], v[109], dp[109][100009];
int main()
{
    cin >> n >> m;

    for(i = 1; i <= n; i++)
        cin >> w[i] >> v[i];

    for(i = 0; i <= n; i++)
    {
        for(j = 1; j < 100009; j++)
            dp[i][j] = INT_MAX;
    }
    for(i = 0; i <= n; i++)
        dp[i][0] = 0;

    ll ans = 0;
    for(i = 1; i <= n; i++)
    {
        for(j = 0; j < 100009; j++)
        {
            if(j < v[i] || dp[i-1][j-v[i]] + w[i] > m)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);

            if(dp[i][j] != INT_MAX)
                ans = max(ans, j);
        }
    }

    cout << ans;
}


Measured memory_bytes: 80128
n,a,b=map(int,input().split())
mod=10**9+7
ors=[n]
rev=[1]

def ie(n,r,mod):
  if r==1:
    return n
  elif r%2==0:
    return (ie(n,r//2,mod)**2)%mod
  else:
    return n*((ie(n,(r-1)//2,mod))**2)%mod
    
  
for i in range(1,b):
  ors.append(ors[-1]*(n-i)%mod)
  rev.append(rev[-1]*(i+1)%mod)  
N=ie(2,n,mod)
A=ors[a-1]*ie(rev[a-1],mod-2,mod)
B=ors[b-1]*ie(rev[b-1],mod-2,mod)
print((N-A-B-1)%mod)

Measured memory_bytes: 18892
a=[int(i) for i in input().split()]
a.sort()
ans=0
while a[1]!=a[2]:
    a[1]+=1
    a[0]+=1
    ans+=1
if a[1]%2==a[0]%2:
    ans+=(a[1]-a[0])//2
else:
    ans+=1
    a[1]+=1
    ans+=(a[1]-a[0])//2
print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,sum;
    cin>>a>>b>>c>>d;
    if(a+b>c+d)
        cout<<"Left "<<endl;
    if(a+b<c+d)
        cout<<"Right "<<endl;
        if(a+b==c+d)
        cout<<"Balanced "<<endl;

    return 0;

}

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

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}

// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  ll ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N, Z, W;
  cin >> N >> Z >> W;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int ans = 0;
  if (N > 1) {
    ans = abs(A.at(N - 1) - A.at(N - 2));
  }
  cout << max(abs(W - A.at(N - 1)), ans) << endl;
}

Measured memory_bytes: 3592
/// input macro from https://qiita.com/tanakh/items/1ba42c7ca36cd29d0ac8
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn solve() {
    let big_prime: u64 = 1_000_000_000 + 7;
    input!(s: u64);

    let mut comb = vec![0; (s + 1) as usize];

    for i in 3..=s {
        comb[i as usize] = 1;
        for j in 1..=(i - 3) {
            comb[i as usize] = (comb[i as usize] + comb[j as usize]) % big_prime;
        }
    }

    println!("{}", comb[s as usize]);
}
fn main() {
    std::thread::Builder::new()
        .name("solve".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2276
using System;

public class Program
{
    private int[] ABC;

    public void Solve()
    {
        var sc = new Scanner();
        ABC = sc.IntArray();
        Array.Sort(ABC);
        // A <= B <= C

        int difCB = ABC[2] - ABC[1];
        int difCA = ABC[2] - ABC[0];
        int ans = 0;
        if ((difCA + difCB) % 2 == 1)
        {
            ans += 2;
        }

        ans += (difCA + difCB) / 2;
        Console.WriteLine(ans);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

typedef long long ll;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(15);
    cout << fixed;
    ll d = 0ll, n = 0ll, m = 0ll;
    cin >> n >> m >> d;
    --m;
    if (d==0ll) {
        cout << (long double)(m)/n;
    } else {
        cout << (long double)(2ll*m*(n-d))/(1ll*n*n);
    }
    cout << endl;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,ma,mb;cin>>n>>ma>>mb;
    int suma=0,sumb=0;
    vin a(n),b(n),c(n);
    rep(i,n){
        cin>>a[i]>>b[i]>>c[i];
        suma+=a[i];
        sumb+=b[i];
    }
    vvin m(4001,vin(4001,inf));
    int k=min(n/2,16);
    int materiala,materialb,money;
    rep(i,1<<(n-k)){
        bitset<25> tmp(i);
        materiala=0;materialb=0;money=0;
        rep(j,n-k){
            if(tmp[j]){
                materiala+=a[k+j];
                materialb+=b[k+j];
                money+=c[k+j];
            }
        }
        m[materiala][materialb]=min(m[materiala][materialb],money);
    }
    int ans=inf;
    rep(i,1<<k){
        bitset<17> tmp(i);
        materiala=0;materialb=0;money=0;
        rep(j,k){
            if(tmp[j]){
                materiala+=a[j];
                materialb+=b[j];
                money+=c[j];
            }
        }
        for(int i=1;i*ma<=suma&&i*mb<=sumb;i++){
            if(i*ma<materiala||i*mb<materialb)continue;
            ans=min(ans,m[i*ma-materiala][i*mb-materialb]+money);
        }
    }
    if(ans==inf)ans=-1;
    cout<<ans<<endl;
}

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

int main() {
  int n;
  int m;
  cin >> n;
  cin >> m;
  int a[m];
  for (int i = 0; i < m; i++) {
      cin >> a[i];
  }
  int j = 0;
  int b = 0;
  while (j < m) {
      b = b + a[j];
      j = j + 1;
  }
  if (n - b < 0){
      cout << -1 << endl;
  }
  else {
      cout << n - b << endl;
  }
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll n, T;
    cin >> n >> T;
    ll t = 1000000000/T;
    
    string s;
    cin >> s;
    ll sum = 0;
    int pos = 0;
    bool overflow = false;
    while(pos < s.length()){
        pos+=2;
        ll now = 1;
        int beki = s[pos++]-'0';
        while(beki-- > 0){
            now *= n;
            if(now+sum > t){
                overflow = true;
                break;
            }
        }
        sum += now;
        pos++;  // +
    }
    if(!overflow && sum <= t)   cout << sum*T << endl;
    else                        cout << "TLE" << endl;
    return 0;
}


Measured memory_bytes: 3208
#include <stdio.h>
#include <iostream>
using namespace std;

typedef unsigned long long ull;

ull Sum(ull N, ull NumOfDivide)
{
    ull index = N / NumOfDivide;
    return index * NumOfDivide * (1 + index) / 2;
}


int main()
{
    ull result, USUM, ASUM, BSUM, CSUM;
    ull N;
    cin >> N;

    ASUM = Sum(N, 3);
    BSUM = Sum(N, 5);
    CSUM = Sum(N, 15);
    USUM = N * (N + 1) / 2;
    cout << USUM - (ASUM + BSUM - CSUM) << endl;
    return 0;
}

Measured memory_bytes: 3584
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;

    SegTree(int n, const Func f, const Monoid& unity) : F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }

    /* set, a is 0-indexed */
    void set(int a, const Monoid& v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k * 2], dat[k * 2 + 1]);
    }

    /* update a, a is 0-indexed */
    void update(int a, const Monoid& v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k * 2], dat[k * 2 + 1]);
    }

    /* get [a, b), a and b are 0-indexed */
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }

    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R - 1) cout << ",";
        }
        cout << endl;
    }
};


int main() {

    int N;
    cin >> N;
    vll A(N), H(N);
    REP(i, N) cin >> H[i];
    REP(i, N) cin >> A[i];

    SegTree<ll> st(N + 1, [](ll a, ll b) {return max(a, b); }, 0);

    ll ans = 0;
    REP(i, N) {
        ll a = st.get(0, H[i]);
        if (st.get(H[i], H[i] + 1) < a + A[i]) {
            st.update(H[i], a + A[i]);
        }
        chmax(ans, a + A[i]);
    }

    cout << ans << endl;

#ifdef _MSC_VER
    system("PAUSE");
#endif

    return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int n, k, v[1005], sum;
int main() {
    DAU
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> v[i];
    sort(v + 1, v + n + 1);
    for (int i = 1; i <= k; ++i)
        sum += v[i];
    cout << sum;
    PLEC
}


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

bool linearSearch(int ary[], int size,  int key) {
  ary[size] = key;

  int i = 0;
  while (ary[i] != key) {
    i ++;
  }

  return i != size;
}

bool binarySearch(int ary[], int size, int key) {
  int left = 0;
  int right = size;
  int mid;

  while (left < right) {
    mid = (left + right) / 2;
    if (ary[mid] == key) return true;
    else if (key < ary[mid]) right = mid;
    else if (ary[mid] < key) left = mid + 1;
  }

  return false;
}

int main() {
  int n;cin>>n;
  int S[n+1];
  for(int i = 0; i < n; i ++) {
    cin >> S[i];
  }

  int q; cin>>q;
  int ans = 0;
  for (int i = 0; i < q; i ++) {
    int key;
    cin >> key;

    // if (linearSearch(S, n, key)) ans++;
    if (binarySearch(S, n, key)) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3464
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
	int w,h,n,i,j;
	cin >> w >> h >> n;
	int x,y,a,x_1,y_1,x_2,y_2;
	x_1 = y_1 = 0;
	x_2 = w;	y_2 = h;

	for(i=0; i<n; i++){
		cin >> x >> y >> a;
		if(a == 1)
			x_1 = max(x,x_1);
		else if(a == 2)
			x_2 = min(x,x_2);
		else if(a == 3)
			y_1 = max(y,y_1);
		else if(a == 4)
			y_2 = min(y,y_2);	
	}
	if(x_2 <= x_1 || y_2 <= y_1){
		cout << 0 << endl;
		return 0;
	}
	cout << (x_2 - x_1) * (y_2 - y_1) << endl;


}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#include <map>
#define ll long long 
#define PI 3.14159265358979323846
#define INF 10000000000
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

int main() {
	ll N;
	cin >> N;
	if (N <= 599)cout << "8" << endl;
	else if (N <= 799) cout << "7" << endl;
	else if (N <= 999) cout << "6" << endl;
	else if (N <= 1199) cout << "5" << endl;
	else if (N <= 1399) cout << "4" << endl;
	else if (N <= 1599) cout << "3" << endl;
	else if (N <= 1799) cout << "2" << endl;
	else cout << "1" << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}

signed main() {
	int n, m;
	cin >> n >> m;
	cout << n - m + 1 << endl;
	endre;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;
typedef long long signed int ll;

constexpr int inf = INT32_MAX / 2;
constexpr int mod = 1000000007;
constexpr int maxn = 100000;

class djikstra {
private:
	ll* d = nullptr;
	map<int, map<int, ll>> p;
	int sz = 0;
public:
	void add_path(int from, int to, ll cost) {
		p[from][to] = cost;
	}
	void compute(int from,int nodes) {
		sz = nodes;
		if (d != nullptr) delete d;
		d = new ll[nodes];
		auto cmp = [this](int a, int b) {return d[a] > d[b]; };
		priority_queue <ll, vector<ll>, decltype(cmp)> q(cmp);
		for (int i = 0; i < nodes; i++) d[i] = INT64_MAX / 2;
		d[from] = 0;
		q.push(from);
		while (!q.empty()) {
			for (auto& e : p[q.top()]) {
				if (d[e.first] > d[q.top()] + e.second) {
					d[e.first] = d[q.top()] + e.second;
					q.push(e.first);
				}
			}
			q.pop();
		}
	}
	ll operator[](int node) {
		if (node >= sz) return INT64_MAX/2;
		return d[node];
	}
};

string s;
ll abc[maxn + 1], bc[maxn + 1], c[maxn + 1], q[maxn + 1];

ll dpow3[maxn + 1];
ll mpow3(ll power) {
	if (power == 0) return 1;
	if (dpow3[power] == 0) dpow3[power] = (3 * mpow3(power - 1)) % mod;
	return dpow3[power];
}

int main() {
	cin >> s;
	for (int i = s.length() - 1; i >= 0; i--) q[i] = q[i + 1] + (s[i] == '?' ? 1 : 0);
	for (int i = s.length() - 1; i >= 0; i--) c[i] = ((c[i + 1] * (s[i] == '?' ? 3 : 1)) + (s[i] == '?' || s[i] == 'C' ? mpow3(q[i + 1]) : 0)) % mod;
	for (int i = s.length() - 2; i >= 0; i--) bc[i] = ((bc[i + 1] * (s[i] == '?' ? 3 : 1)) + (s[i] == '?' || s[i] == 'B' ? c[i + 1] : 0)) % mod;
	for (int i = s.length() - 3; i >= 0; i--) abc[i] = ((abc[i + 1] * (s[i] == '?' ? 3 : 1)) + (s[i] == '?' || s[i] == 'A' ? bc[i + 1] : 0)) % mod;
	std::cout << abc[0] << endl;
}


Measured memory_bytes: 4352
#include<cstdio>
#include<vector>

#define	mp	make_pair
#define	pb	push_back

using namespace std;

typedef	pair<int,int>	pii;
typedef	vector<pii>	vpii;

vector<vpii> rect;
int w,h,n,land[10][10],test[10][10],ans[10][10];

bool search(int i0,int j0){
	for(int i=i0;i<h;i++){
		for(int j=(i==i0?j0:0);j<w;j++){
			int id=land[i][j];
			if(id==0)	continue;

			int cnt=0;
			for(int k=0;k<rect[id].size();k++){
				int rh=rect[id][k].first,rw=rect[id][k].second;
				for(int y=i-rh+1;y<=i;y++)for(int x=j-rw+1;x<=j;x++){
					if(!(0<=y && y+rh<=h && 0<=x && x+rw<=w))	continue;
					bool canput=true;
					for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++){
						if(test[yy][xx]!=0
						||(land[yy][xx]!=0 && land[yy][xx]!=id))	canput=false;
					}
					if(!canput)	continue;
					for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++)	test[yy][xx]=id;
					cnt+=search(i,j+1);
					for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++)	test[yy][xx]=0;
					if(cnt>=2)	return false;
				}
			}

			return cnt==1;
		}
	}

	bool suc=true;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++){
		if(test[i][j]==0)	suc=false;
	}
	if(suc){
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	ans[i][j]=test[i][j];
		return true;
	}
	return false;
}

int main(){
	for(;scanf("%d%d%d",&w,&h,&n),w;){
		rect=vector<vpii>(n+1);

		for(int i=0;i<n;i++){
			int id,area;	scanf("%d%d",&id,&area);
			for(int j=1;j<=area;j++){
				if(area%j==0)	rect[id].pb(mp(j,area/j));
			}
		}
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	scanf("%d",&land[i][j]);

		if(search(0,0)){
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++)	printf("%s%d",(j?" ":""),ans[i][j]);
				putchar('\n');
			}
		}
		else	puts("NA");
	}

	return 0;
}

Measured memory_bytes: 832
cnt = 0
n = gets.chomp.split("/").map(&:to_i)
if n[0] <= 2019
  if n[1] <= 4
    if n[2] <= 30
      puts "Heisei"
      cnt += 1
    end
  end
end
if cnt == 0
  puts "TBD"
end

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

int main()
{
  int N;
  int a[33] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin>>N;
  cout<<a[N-1];
}


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

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

int n, m;

int x[maxn], y[maxn];
int c[maxn];

void add(int &a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
}

void Add(int p, int val){
    for(int i = p;i < maxn;i += i & -i){
        add(c[i], val);
    }
}

int Sum(int p){
    int ret = 0;
    for(int i = p;i > 0;i -= i & -i){
        add(ret, c[i]);
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 1;i <= n;i++){
        cin >> x[i];
    }
    for(int j = 1;j <= m;j++){
        cin >> y[j];
    }
    vector<pair<int, int> > v;
    for(int i = 1;i <= n;i++){
        int j = lower_bound(y + 1, y + m + 1, x[i]) - y;
        j--;
        if(j >= 1 and j < m){
            v.emplace_back(x[i] - y[j], x[i] - y[j + 1]); 
        }
    }
    sort(v.begin(), v.end());
    auto it = unique(v.begin(), v.end());
    v.erase(it, v.end());
    n = v.size();
    for(int i = 0;i < n;i++){
        y[i] = -v[i].second;
    }
    sort(y, y + n);
    m = unique(y, y + n) - y;
    for(int i = 0;i < n;i++){
        int val = lower_bound(y, y + m, -v[i].second) - y + 1;
        int dp = 1;
        add(dp, Sum(val - 1));
        Add(val, dp);
    }
    int ans = 1;
    add(ans, Sum(maxn - 1));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2292
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void){
  int i,j,n,min,max,get,*rate;
  //?????????
  scanf("%d",&n);
  rate=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    scanf("%d",&rate[i]);
  min=rate[n-1];
  max=rate[n-1];
  get=-2000000000;//????°?????????±

  //??????:??????????????????
  for(i=n-2;0<=i;i--){
    if(min>rate[i+1])
      min=rate[i+1];
    if(max<rate[i+1])
      max=rate[i+1];
    if(get<max-rate[i])
      get=max-rate[i];
  }
  printf("%d\n",get);
  
  //??????
  free(rate);
  return(0);
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/arc093/tasks/arc093_b

# 条件を満たすものを出力しろ
# 連結成分が指定されている
# 100*100のマスに限定して考えれば簡単。
# 50*100のマスの中で499個の島を作ることはできるよね？(2行あたり25個作れるはず, 40行もあれば十分作れる)

A, B = read_ints()
A -= 1
B -= 1
print(100, 100)

# 黒の中に白の個島を作る
for _ in range(25):
    for _ in range(50):
        if A > 0:
            print('#.', end='')
            A -= 1
        else:
            print('##', end='')
    print()
    print('#' * 100)  # 隔離

# 白の中に黒の個島を作る
for _ in range(25):
    print('.' * 100)  # 隔離
    for _ in range(50):
        if B > 0:
            print('#.', end='')
            B -= 1
        else:
            print('..', end='')
    print()


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

const int INF = 1e9+7;
int dp[40 + 1][40 * 10 + 2][40 * 10 + 2]; // dp[id][ca][cb]

int main() {

    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);

    rep(i, N) {
        cin >> a[i] >> b[i] >> c[i];
    }
    rep(i,N+1) rep(ca, 40*10+1) rep(cb, 40*10+1) dp[i][ca][cb] = INF;

    dp[0][0][0] = 0;    // 使わないから
    for (int i = 0; i < N; ++i) {
        for (int ca = 0; ca <= 40*10; ++ca) {
            for (int cb = 0; cb <= 40*10; ++cb) {
                if (dp[i][ca][cb] == INF) continue;
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb] + c[i]);
            }
        }
    }

    int ans = INF;
    for (int ca = 1; ca <= 40*10; ++ca) {
        for (int cb = 1; cb <= 40*10; ++cb) {
            if (ca*Mb == cb*Ma) {
                ans = min(ans, dp[N][ca][cb]);
            }
        }
    }

    cout << (ans == INF ? -1 : ans) << endl;
}


Measured memory_bytes: 26112
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
vector<Q> vec;
int n, p[100010], num;
ll a, b, ans;
bool jud;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a >> b;
		vec.push_back(Q(a, P(i, 1)));
		vec.push_back(Q(b, P(i, 2)));
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < n; i++)
	{
		p[vec[i].second.first]++;
		if (p[vec[i].second.first] == 2)
		{
			jud = true;
		}
		if (vec[i].second.second == 1)
		{
			num++;
		}
		ans += vec[i].first;
	}
	if (jud || num == n || num == 0)
	{
		cout << ans << endl;
	}
	else if (vec[n - 1].second.first != vec[n].second.first)
	{
		cout << ans - vec[n - 1].first + vec[n].first << endl;
	}
	else if ((num == n - 1 && vec[n].second.second == 1) || (num == 1 && vec[n].second.second == 2))
	{
		cout << ans - vec[n - 1].first + vec[n].first << endl;
	}
	else
	{
		cout << ans + min(vec[n].first - vec[n - 2].first, vec[n + 1].first - vec[n - 1].first) << endl;
	}
	cin >> n;
}

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

#define ll long long int
ll mod=1e9+7;

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j;
        // cin >> n;
        // ll arr[n];
        string s;
        cin >> s;
        n = s.size();

        ll sum = 0;
        for(i=0;i<n;i++)
        {
            ll dig = s[i]-'0';
            sum += dig;
        }

        if(sum%9 == 0)
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
        
        
        
    }
    
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <climits>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;
int main() {
	long long N;
	cin >> N;
	long long sum = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 3 == 0 && i % 5 == 0) continue;
		if (i % 3 == 0) continue;
		if (i % 5 == 0) continue;
		sum += i;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int ans = 0;
    rep(i, 5){
        int x;
        cin >> x;
        if (x == 0){
            ans = i+1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		string S = GetString();

		int cnt = 1;
		for(int i = 1; i < N; i++)
		{
			if(S[i] != S[i - 1])
				cnt++;
		}

		Console.WriteLine(cnt);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 13908
#include <stdio.h>

int main(void)
{
	int a,b,c,d;
	int ac,ab,bc;
	
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	
ac = (a > c) ? a-c : c-a;
ab = (a > b) ? a-b : b-a;
bc = (b > c) ? b-c : c-b;
		
	if(ac<=d){
		printf("Yes\n");
	}
	else if(ab<=d && bc<=d){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


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

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

    int h, w;
    cin >> h >> w;

    char A[h][w];
    REP(i, h){
        REP(j, w){
            cin >> A[i][j];
        }
    }

    set<int> y, x;
    REP(i, h){
        REP(j, w){
            if(A[i][j] == '#'){
                y.insert(i);
                x.insert(j);
            }
        }
    }

    for(auto i : y){
        for(auto j : x){
            cout << A[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
public class Main {

  private static void solve() {
    int m = ni();
    int k = ni();

    // a b c k c b a k
    // 001 010 011 100 101 110 111


    int v = 1 << m;
    if (k < v) {
      if (m == 1) {
        if (k == 0) {
          System.out.println("0 0 1 1");
        } else {
          System.out.println(-1);
        }
        return;
      }
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < v; i++) {
        if (i == k)
          continue;
        sb.append(i + " ");
      }
      sb.append(k + " ");
      for (int i = v - 1; i >= 0; i--) {
        if (i == k)
          continue;
        sb.append(i + " ");
      }
      sb.append(k + " ");

      System.out.println(sb);
    } else {
      System.out.println(-1);
    }

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 46084
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
int main(){
    //std::stack<int> stack;
    string s;
    cin >> s;
    int cnt[2019];
    int n = s.size();
    int ten = 1;
    for(int i = 0; i < 2019; i++){
        cnt[i] = 0;
    }
    cnt[s[n-1] - '0'] ++;
    cnt[0]  = 1;
    int tmp = s[n-1] - '0';
    for(int i = 1; i < n; i++){
        ten *= 10;
        ten %= 2019;
        cnt[(tmp + ten * (s[n-i-1] - '0'))%2019] ++;
        //cout << (tmp + ten * (s[n-i-1] - '0'))%2019 << " " ;
        tmp += ten * (s[n-i-1] - '0')%2019;
    }
    int ans = 0;
    for(int i = 0; i < 2019; i++){
        ans += cnt[i] * (cnt[i]-1) / 2;
        
    }
    cout << ans << endl;
    return 0;
}





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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-10;

typedef long long int llu;
const llu MODD[3] = {1000000009, 2000000011, 3000000019};
const llu base[3] = {901502696, 617916109, 103244261};
const llu basi[3] = {938106584, 434659818, 480258097};
llu B = 100000007LLU;
llu BI = 158730160LLU;
int n, m;
string s;
string q[333333];
llu b[3][333333];

int main(int argc, char *argv[])
{
  cin >> n >> m;
  cin >> s;
  rep(i, m) cin >> q[i];
  rep(i, 3) b[i][0] = 1LL;
  rep(i, 3) rep(j, m) b[i][j + 1] = b[i][j] * base[i] % MODD[i];

  llu H[3] = {s[0], s[0], s[0]};
  int l = 0;
  int r = 0;
  vector<vector<llu> > can;
  rep(i, m){
    rep(j, 3){
      if(q[i] == "L++") H[j] += - (b[j][r - l] * s[l]) % MODD[j];
      if(q[i] == "L--") H[j] += b[j][r - l + 1] * s[l - 1];
      if(q[i] == "R++") H[j] = H[j] * base[j] % MODD[j] + s[r + 1];
      if(q[i] == "R--") H[j] = (H[j] - s[r] + MODD[j]) *  basi[j] % MODD[j];
      if(H[j] < 0) H[j] += MODD[j];
      H[j] %= MODD[j];
    }
    if(q[i] == "L++") l += 1;
    if(q[i] == "L--") l -= 1;
    if(q[i] == "R++") r += 1;
    if(q[i] == "R--") r -= 1;
    vector<llu> tmp;
    rep(j, 3) tmp.pb(H[j]);
    can.pb(tmp);
  }

  sort(ALL(can));
  can.erase(unique(ALL(can)), can.end());

  cout << can.size() << endl;
  
  return 0;
}

Measured memory_bytes: 47372
S = input()
N = int(input())

while N > 0:
    command = input().split()

    if command[0] == "print":
        a = int(command[1])
        b = int(command[2])

        print(S[a:b+1])
    elif command[0] == "reverse":
        a = int(command[1])
        b = int(command[2])

        S = S[:a]+S[a:b+1][::-1]+S[b+1:]
    

    else:
        a = int(command[1])
        b = int(command[2])
        p = command[3]

        S = S[:a] + p + S[b+1:]


    N -= 1



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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int x, t;

  scanf("%d %d",&x,&t);

  printf("%d\n",max(x - t, 0));
}


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

int main()
{
	int n; cin>>n;
  	bool flag = false;
    while(n>0){
    	if(n%10 == 7)flag =true;
        n/=10;
    }
  if(flag)cout<<"Yes";
  else cout<<"No";

}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(){
	int n;
	int m;
	cin >> n;
	cin >> m;
	n = n / 2;
	if(n%2==1){
		n++;
	}
	if(n == 0){
		n=1;
	}
	if(n>=m){
		cout << "YES";
	}else{
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

map<int,int> m;

int main()
{
    int n;
    cin>>n;
    int f=0;
    while(n--)
    {
        int x;
        cin>>x;
        if(m[x]==0)m[x]=1;
        else if(m[x]==1)f=1;
    }
    if(!f)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}







Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep (i, n) cin >> a[i];

	if (k == 2) {
		cout << n - 1 << endl;
	}
	else {
		if (n == k) cout << 1 << endl;
		else {
			cout << ((n - 1) + (k - 1) - 1) / (k - 1) << endl;
		}
		
	}

	return 0;
}

Measured memory_bytes: 640
use proconio::input;
use itertools::Itertools;

fn main() {
    input! {
        n: u32,
    }
    input! {
        mut a: [u32; n - 1],
    }
    a.extend_from_slice(&(1..=n).collect::<Vec<u32>>());
    // for n in a.sorted() {
    //     println!("{}", n);
    // }
    for (_, group) in &a.into_iter().sorted().group_by(|a| *a) {
        println!("{}", group.count() - 1); 
    }
}


Measured memory_bytes: 5528