akhauriyash/Code-Regression huggingface dataset:
round = int(input())
points =[0, 0]
for r in range(round):
    taro, hanako = input().split(" ")
    if taro == hanako:
        points[0] += 1
        points[1] += 1
    elif taro > hanako:
        points[0] += 3
    elif taro < hanako:
        points[1] += 3

print(*points)

Measured memory_bytes: 7660
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    
    string s;
    std::cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        std::cout << "Yes";
    }
    else{
        cout<< "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int h, w, d;
  cin >> h >> w >> d;
  int a[h][w];
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }

  vector<pair<int, int>> g(h * w);
  rep(i, h) {
    rep(j, w) {
      g[a[i][j] - 1] = {i, j};
    }
  }
  vector<int> c(h * w, 0);
  rep(i, h * w - d) {
    c[i + d] = abs(g[i].first - g[i + d].first) + abs(g[i].second - g[i + d].second);
    c[i + d] += c[i];
  }

  int q;
  cin >> q;
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    cout << c[r - 1] - c[l - 1] << endl;
  }



  
  return 0;
}

Measured memory_bytes: 2560
const main = (input) => {
	const lines = input.split('\n')
    const n = Number(lines[0])
    let startIndex = 1
    const arr = []
    for (let i = 0; i < n; i++) {
       arr.push([])
    }
    for (let i = 0; i < n; i++) {
      const a = Number(lines[startIndex])
      
      for (let j = 0; j < a; j++) {
        const xy = lines[startIndex + j + 1].split(' ').map(n => Number(n))
        arr[i].push(xy)
      
      }
      startIndex += 1+a
    }
 
  const pad = (num, length) => {
    return ('000000000000000' + num).slice(-length)
  }
  let result = 0
  for (let i = 0; i < 2**n; i++) {
    let bit = i.toString(2)
    bit = pad(bit, n)
    let isOk = true
    for (let j = 0; j < n; j++) {
      if (bit[j] === '0') continue
      const testifies = arr[j]

      for (let k = 0; k < testifies.length; k++) {
        const [x, y] = testifies[k]

        if (Number(bit[x-1]) !== y) {
          isOk = false
          break
        }
      }
      
      if (!isOk) break
    }

    if (isOk) {
      let num = 0
      for (let l = 0; l < n; l++) {
        if (bit[l] === '1') num++
      }
      result = result < num ? num : result
    }
    
  }
  console.log(result)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  string fr = s.substr(0, n), re = s.substr(n);
  reverse(ALL(re));
  map<pair<string, string>, int> mp;
  rep(bit, 1 << n){
    string rd, bl;
    rep(i, n){
      if((bit & (1 << i)) == 0) rd.push_back(fr.at(i));
      else bl.push_back(fr.at(i));
    }
    mp[{rd, bl}]++;
  }

  // for(auto p : mp){
  //   cerr << p.first.first << " " << p.first.second << " " << p.second << endl;
  // }

  ll ans = 0;
  rep(bit, 1 << n){
    string rd, bl;
    rep(i, n){
      if((bit & (1 << i)) == 0) rd.push_back(re.at(i));
      else bl.push_back(re.at(i));
    }
    ans += mp[{rd, bl}];
  }
  cout << ans << endl;
  
  return 0;
}

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

int N;
double D[501];
double xs[501];
int main(){

  cin>>N;
  for(int i=0;i<N;i++){
    cin>>D[i];
  }

  xs[0] = D[0];
  
  // ????????????????????????????????????
  for(int i = 1; i < N; i++){
    double max_x = -1;
    for(int j = 0; j < i; j++){
      double nxt_x = 0;
      nxt_x = xs[j] + sqrt(pow(1.0*D[i] + D[j], 2) - pow(abs(D[i] - D[j]), 2));
      max_x = max(max_x, nxt_x);
    }
    xs[i] = max_x;
  }

  double max_x = -1;
  double min_x = 100000000;
  for(int i=0;i<N;i++){
    max_x=max(max_x, xs[i] + D[i]);
    min_x=min(min_x, xs[i] - D[i]);
  }
  double ans = abs(min_x-max_x);
  printf("%.10f\n", ans);
  
  return 0;
}

Measured memory_bytes: 3296
N = int(input())
name = ""
for i in range(20):
    N -= 1
    N_mod = N % 26
    N_div = N // 26
    Nmod_to_alp = chr(N_mod+ord("a"))
    name = Nmod_to_alp + name
    if N_div == 0:
        break
    else:
        N = N_div
print(name)

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

typedef long long ll;

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

    string n; cin >> n;
    int sum = 0;
    for(int i=0;i<n.size();i++){
        sum += n[i] - '0';
    }
    if(stoi(n)%sum==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

int main(){
int A, B;
cin >> A >> B;
if(A + B >= A - B && A + B >= A * B) print(A + B);
else if (A - B >= A + B && A - B >= A * B) print(A - B);
else if (A * B >= A + B && A * B >= A - B) print(A * B);
}

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

const int N = 10000;

int main() {
  int n = 0;
  std::vector<int> S;

  S.reserve(N);

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    int x = 0;

    std::cin >> x;

    S.push_back(x);
  }

  int q = 0;
  std::vector<int> T;

  T.reserve(N);

  std::cin >> q;

  for (int i = 0; i < q; i++) {
    int x = 0;

    std::cin >> x;

    T.push_back(x);
  }

  int count = 0;
  
  for (std::vector<int>::iterator i = S.begin(); i != S.end(); ++i) {

    
    for (std::vector<int>::iterator j = T.begin(); j != T.end(); ++j) {
      if (*i == *j) {
	count++;

	T.erase(j);	

	break;
      }
    }
  }

  std::cout << count << std::endl;
  
  return 0;
}

Measured memory_bytes: 1256
def main():
    _ = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    c = dict()

    for i in a:
        for j in range(i - 1, i + 2):
            c[j] = c.get(j, 0) + 1
    
    return max(c.values())

main()


Measured memory_bytes: 20600
#include <iostream>
using namespace std;
 
int main(){
  char c;
  cin >> c;
  bool flg = false;
  char check[5] = {'a','i','u','e','o'};
  for(int i = 0; i < 5; ++i){
    if(c == check[i]){
      flg = true;
      break;
    }
  }
  cout << ((flg) ? "vowel" : "consonant") << endl; 
}


Measured memory_bytes: 256
/*
全員でn人の人間がいる.
自分の左右に並んでいる人数の差の絶対値がAiである
= 中央値から何人分ずれているか(左右に)
数列Aには同じ値は２回までしか登場できない.
(0の場合はnが奇数なら1回のみ,
nが偶数なら１回も存在できない.0は真ん中を表すから)
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);

ll mpow(ll a, ll n, ll mod) {
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    sc(n)
    int A[n], cnt[n];
    fill(cnt, cnt + n, 0);
    REP(i, n) sc(A[i])
    REP(i, n) cnt[A[i]] += 1;
    if ((n % 2 == 0 && cnt[0] > 0)\
     || (n % 2 == 1 && cnt[0] > 1)){
        cout << 0 << endl;
    }else{
        bool check = true;
        for (int i = 1; i < n; i++){
            if (i == 0 && cnt[i] > 2) check = false;
            else if (cnt[i] != 2 && cnt[i] != 0) check = false;
        }
        if (check) cout << mpow(2, n / 2, 1e9 + 7) << endl;
        else cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;

pair < ll, ll> p[100001];
ll c[100001];

int main() {
	int n, m;

	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &p[i].second,&p[i].first);
	}
	for (int i = 0; i < m; i++) {
		scanf("%lld",&c[i]);
	}

	sort(c, c + m);
	sort(p, p + n);

	ll ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (ans >= m) break;
		if (c[m - ans - 1] >= p[i].second) {
			ans++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5148
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	vi a(n);
	unordered_map<int, int> m;
	rep(i, n) cin >> a[i], m[a[i]]++;
	int t = m.size();
	int ans = 0;
	vi sz;
	vi pos;
	for(pi x : m) pos.pb(x.se);
	sort(all(pos));
	rep(i, (t - k)) ans += pos[i];
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 11080
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <functional>
#include <cstdio>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
int dic[16000000];
ull pow(ull x,ull n) {
  ull res = 1;
  while(n > 0) {
    if(n&1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14],int& key)
{
  int j;
  int f = 1;
  int g = 0;
  for(j = 0;j<10;j++) {
    if(str[j] == 'A')
      g += f * 1;
    else if(str[j] == 'C')
      g += f * 2;
    else if(str[j] == 'G')
      g += f * 3;
    else if(str[j] == 'T')
      g += f * 4;
    else break;
    f *= 5;
  }
  key = 0;
  if(j == 10) {
    f = 1;
    for(;j<10;j++) {
      if(str[j] == 'A')
        key += f * 1;
      else if(str[j] == 'C')
        key += f * 2;
      else if(str[j] == 'G')
        key += f * 3;
      else if(str[j] == 'T')
        key += f * 4;
      else break;
        f *= 5;
    }
  }
  return g;
}
int main()
{
  int i,j,k,l;
  long n;
  long ans = 0;
  char opstr[7];
  char str[13];
  int key;
  int a = 1;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s",opstr,str);
    if(opstr[0] == 'i') {
      int tmp = dic_op(str,key);
      if( (dic[tmp] >> key) % 2 == 0) {
        dic[tmp] += 1 << key;
      }
    }
    else if(opstr[0] == 'f') {
      int tmp = dic_op(str,key);
      /*
      printf("tmp = %d\n",tmp);
      printf("key = %d\n",key);
      printf("dic[tmp] = %d\n",dic[tmp]);
      */
      if( (dic[tmp] >> key) % 2 == 1) {
        puts("yes");
      }
      else {
        puts("no");
      }
    }
  }
  return 0;
}

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


void solve(long long N, std::vector<long long> A){
vector<int> ans(N);
for(int i=0; i<N-1; i++){
    int s=(A.at(i))-1;
    ans.at(s)=ans.at(s)+1;
}
for(int i=0; i<N; i++){
    cout<<ans.at(i)<<endl;
}
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 5656
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int A = sc.nextInt();
		int B = sc.nextInt();
        if (B%A == 0){
            out.println(A+B);
        }else{
          out.println(B-A);
        }
     out.flush();
    }
}

Measured memory_bytes: 23124
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"


int main(int argc, char const *argv[]) {

  int NN, MM;
  std::cin >> NN >> MM;

  int b = 1;



  // if (MM / NN < 1e6) {
  //   for (size_t i = 2; i <= MM / NN; i++) {
  //     if (MM % i == 0) {
  //       if (MM/i >= NN) {
  //         b = i;
  //       }
  //     }
  //   }
  // }

  // for (size_t i = 2; i <= MM / NN; i++) {
  //   if (MM % i == 0) {
  //     if (MM/i >= NN) {
  //       b = i;
  //     }
  //   }
  // }

  int mn = MM / NN;
  int p =mn;

  for (size_t i = p; i >0; i--) {
    if (MM % i == 0) {
      b=i;
      break;
    }
  }


  std::cout << b << '\n';


  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    //          int N =  int.Parse(Console.ReadLine());
    //CompLib.Collections.PriorityQueue<?>
    public static void Main()
    {
        long output = 0;
        Console.ReadLine();
        int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Array.Sort(sp);
        Array.Reverse(sp);
        for (int i = 0; i < sp.Length - 2; i++)
        {
            for (int j = i + 1; j < sp.Length - 1; j++)
            {
                int limit = sp[i] - sp[j];
                for (int k = j + 1; k < sp.Length; k++)
                {
                    if (limit >= sp[k]) break;
                    output++;
                }
            }
        }
        Console.WriteLine(output);
    }


}



Measured memory_bytes: 13396
#include <stdio.h>

int main(void) {
    int i;
    int count = 0;
    char S[4] = {};

    for(i = 0; i < 4; i++) {
        scanf("%c",&S[i]);
    }
     
    for(i = 0; i < 3; i++) {
        if(S[i] == S[i+1] || S[i] == S[i+1] || S[i] == S[i+2] || S[i] == S[i+3]) {
        count += 1;
        }
    }

    if(count == 2) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}

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


int main(void){
  int N;
  string S;
  cin >> N >> S;
  for(int i = 0; i < S.size(); i++){
   	int ch = S.at(i);
    //cout << ch << endl;
    if(ch + N > 90){
      S.at(i) = char(64 + ch + N - 90);
    }
    else
	    S.at(i) = char(ch + N);
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int N;
    scanf("%d",&N);
    vector<string> B;
    string t;
    for(int i=0;i<N;i++){
        cin>>t;
        B.push_back(t);
    }
    int M;
    scanf("%d",&M);
    vector<string> R;
    for(int i=0;i<M;i++){
        cin>>t;
        R.push_back(t);
    }
    int ans=0,cnt=0;
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            if(B[i]==B[j]){cnt+=1;}
        }
        for(int j=0;j<M;j++){
            if(B[i]==R[j]){cnt-=1;}
        }
        if(ans<cnt){ans=cnt;}
        cnt=0;
    }
    
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
a = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]

def yu(n,a)
    b = 0
    i = 1
    while n / (a ** i) > 0
        b += n / a ** i
        i += 1
    end
    b
end

N = gets.to_i
if a.select.with_index{|x,i| 4 <= yu(N,a[i])  && yu(N,a[i+1]) < 4}.size > 0
b = a.index(a.select.with_index{|x,i| 4 <= yu(N,a[i])  && yu(N,a[i+1]) < 4}[0])
h = a.index(a.select.with_index{|x,i| 2 <= yu(N,a[i])  && yu(N,a[i+1]) < 2}[0])
c = ((b * (b-1)) / 2) * (b+1) +  (((b+1) * b) / 2)  * (h-b)

else
    c = 0
end


if a.select.with_index{|x,i| 14 <= yu(N,a[i])  && yu(N,a[i+1]) < 14}.size > 0


d = a.index(a.select.with_index{|x,i| 14 <= yu(N,a[i])  && yu(N,a[i+1]) < 14}[0])
j = a.index(a.select.with_index{|x,i| 4 <= yu(N,a[i])  && yu(N,a[i+1]) < 4}[0])
e = d * (d+1) + (d+1) * (j-d)



else
    e = 0
end

if a.select.with_index{|x,i| 24 <= yu(N,a[i])  && yu(N,a[i+1]) < 24}.size > 0


f= a.index(a.select.with_index{|x,i| 24 <= yu(N,a[i])  && yu(N,a[i+1]) < 24}[0])
k = a.index(a.select.with_index{|x,i| 2 <= yu(N,a[i])  && yu(N,a[i+1]) < 2}[0])
g = f * (f+1) + (f+1) * (k-f)


else
    g = 0
end

if yu(N,2) >= 74
    puts (c+e+g+1)
else
    puts (c+e+g)
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], * di = dn, dt;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

const int K = 21;
const int KM = 1 << (K - 1);
int laz[1 << K];
int zero = 2e9;
void update(int L, int R, int X, int A, int l, int r) {
	if (r <= L || R <= l) return;
	if (L <= l && r <= R) {
		laz[A] = min(laz[A], X);
		return;
	}
	update(L, R, X, A * 2, l, (l + r) / 2);
	update(L, R, X, A * 2 + 1, (l + r) / 2, r);
}

void pakuripair_sort(int N, int A[], int B[]) {
	const int b = 8;
	int tmp[600001], tmp2[600001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) {
			tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
			tmp2[kazu[A[i] >> k * b & ((1 << b) - 1)]] = B[i];
		}
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) {
			A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
			B[kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp2[i];
		}
	}
}

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


	int N = getint(), Q = getint();
	int X[200000];
	int all[600001], k[600001];
	rep(i, N) {
		int s = getint(), t = getint();
		X[i] = getint();
		all[i + i] = s - X[i] + 1e9;
		all[i + i + 1] = t - X[i] + 1e9;
	}
	rep(i, Q) all[N + N + i] = getint() + 1e9;
	rep(i, N + N + Q) k[i] = i;
	pakuripair_sort(N + N + Q, all, k);
	rep(i, N + N + Q) {
		all[k[i]] = i;
	}

	rep(i, 1 << K) laz[i] = zero;

	rep(i, N) {
		int L = all[i + i];
		int R = all[i + i + 1];
		cesp(L); ce(R);
		update(L, R, X[i], 1, 0, KM);
	}
	rep1(i, KM - 1) {
		laz[i * 2] = min(laz[i * 2], laz[i]);
		laz[i * 2 + 1] = min(laz[i * 2 + 1], laz[i]);
	}
	rep(i, Q) {
		if (laz[KM + all[N + N + i]] == zero) {
			*di++ = '-';
			*di++ = '1';
			*di++ = '\n';
		}
		else putint(laz[KM + all[N + N + i]]);
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve()
{
  int N, M, P;
  cin >> N >> M >> P;
  vector<vector<int>> to(N), ot(N);
  vector<tuple<int, int, int>> eg;
  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    c = -(c - P);
    to[a].push_back(b);
    ot[b].push_back(a);
    eg.emplace_back(a, b, c);
  }
  vector<int> from1(N);
  function<void(int)> dfs1 = [&](int u) {
    if (from1[u]) return;
    from1[u] = 1;
    for (auto& v : to[u]) dfs1(v);
  };
  dfs1(0);
  vector<int> fromN(N);
  function<void(int)> dfsN = [&](int u) {
    if (fromN[u]) return;
    fromN[u] = 1;
    for (auto& v : ot[u]) dfsN(v);
  };
  dfsN(N - 1);
  dump(from1, fromN);
  vector<int> dist(N, INF);
  dist[0] = 0;
  int updated = 1;
  int step = 0;
  while (updated) {
    dump(dist);
    updated = 0;
    rep(i, M) {
      int a, b, c;
      tie(a, b, c) = eg[i];
      if (!from1[a] || !fromN[a]) continue;
      if (!from1[b] || !fromN[b]) continue;
      if (dist[a] + c < dist[b]) {
        updated = 1;
        dist[b] = dist[a] + c;
      }
    }
    step++;
    if (N < step) {
      cout << -1 << endl;
      return;
    }
  }
  cout << max(0, -dist[N - 1]) << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
int main()
{
	int n,i;
	scanf("%d",&n);
	int p[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&p[i]);
	}
	int count = 0;
	for(i=1;i<n;i++)
	{
		if(i == n-1)
			break;

		if((p[i] > p[i-1] && p[i] <p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])){
			count++;
//			printf("%d\n",p[i]);
		}
		else
			continue;
	}
	printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld dp[3005][3005];
ld pb[3005];
int main(){
	ll n;
	ld ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>pb[i];
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<i+1;j++){
			dp[i+1][j]+=dp[i][j]*(1-pb[i]);
			dp[i+1][j+1]+=dp[i][j]*pb[i];
		}
	}
	for(int i=n/2+1;i<n+1;i++){
		ans+=dp[n][i];
	}
	cout<<fixed<<setprecision(10)<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 139392
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    char xs[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> xs[i][j];
        }
    }
    cout << xs[0][0] << xs[1][1] << xs[2][2] << endl;
    return 0;
}


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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1000003;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

// 繰り返し二乗法
ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
// 階乗, 逆元テーブル(mod)
const int nMax = 1000005;
ll fact[nMax], fact_inv[nMax], inv[nMax];
ll calcFact() {
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < nMax; i++) {
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}

signed main() {
    int Q;
    cin >> Q;

    int x[Q], d[Q], n[Q];
    REP(i, Q) cin >> x[i] >> d[i] >> n[i];

    calcFact();

    REP(i, Q) {
        if (d[i] == 0) {
            ll ans = modpow(x[i], n[i]);
            cout << ans << endl;
            continue;
        }
        int xd = x[i] * inv[d[i]] % MOD;
        if (xd <= MOD && MOD <= xd + n[i] - 1) {
            cout << 0 << endl;
            continue;
        }
        int prod = fact[xd + n[i] - 1] * fact_inv[xd - 1] % MOD;
        ll ans = modpow(d[i], n[i]) * prod % MOD;
        cout << ans << endl;
    }

    return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n, 0);
  vector<int> b(n, 0);
  vector<int> c(n, 0);

  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 < n; i++) {
    cin >> c[i];
  }
  sort(all(a));
  sort(all(b));
  sort(all(c));

  // print(a);
  // print(b);
  // print(c);
  //
  ll res = 0;

  for (int i = 0; i < n; i++)
  {
    auto au = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    auto cu = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
    // cout << au << " " << cu << endl;
    res += au * cu;
  }

  cout << res << endl;

}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<int,pair<int,int> >PII;



int main()
{
	int n;
	fflush(stdout);
	cin>>n;
	fflush(stdout);
	cout<<0<<endl;
	fflush(stdout);
	string a;
	cin>>a;
	if(a[0]=='V')return 0;
	char lochar=a[0];
	int lo=0;
	cout<<n-1<<endl;
	fflush(stdout);
	cin>>a;
	if(a[0]=='V')return 0;
	char hichar=a[0];
	int hi=n-1;
	int k=18;
	while(k--)
	{
		int mid=lo+(hi-lo)/2;
		if(hi-lo<2)break;
		//cout<<hi<<" "<<lo<<" "<<mid<<endl;
		cout<<mid<<endl;
		fflush(stdout);
		cin>>a;
		if(a[0]=='V')return 0;
		else 
		{
			int dif=(mid-lo);
			if(dif%2==0)
			{
				if(a[0]==lochar)
				{
					lo=mid;
				}
				else
				{
					hi=mid;
				}
			}
			else
			{
				if(a[0]!=lochar)
				{
					lo=mid;
					lochar=a[0];
				}
				else
				{
					hi=mid;
				}
			}
			//cout<<hi<<" "<<lo<<" "<<mid<<endl;			
		}
	}
	for(int i=lo;i<=hi;i++)
	{
		cout<<i<<endl;
		fflush(stdout);
		cin>>a;
		if(a[0]=='V')return 0;
	}
	assert(1==2);
	return 0;
}


Measured memory_bytes: 852
use std::io::*;

fn read_line_char(s: &mut StdinLock) -> Vec<char> {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .collect()
}
fn main(){
    let s = stdin();
    let mut s = s.lock();
    let all_s = read_line_char(&mut s);

    let mut d: Vec<usize> = vec![0; all_s.len()+1];
    let mut ten: usize = 1;
    for i in (0..all_s.len()).rev() {
        let a = ((all_s[i] as u8 - b'0') as usize) * ten % 2019;
        d[i] = (d[i+1]+a) % 2019;
        ten *= 10;
        ten %= 2019
    }
    let mut cnt: Vec<usize> = vec![0; 2019];
    let mut ans = 0;
    for i in (0..all_s.len()+1).rev() {
        ans += cnt[d[i]];
        cnt[d[i]] += 1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4196
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M; cin >> M;
    cout << 48 - M << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
    char search[21], word[21];
    int count=0;
    int i;
    
    scanf("%s", search);
    while(1){
        scanf(" %s", word);
        if(strcmp(word, "END_OF_TEXT")==0)break;
        for(i=0;word[i]!='\0';i++){
            word[i]=tolower(word[i]);
        }
        if(strcmp(word, search)==0){
            count++;
        }
    }
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr if(true)cerr
void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p=LLONG_MAX)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------

int main(){
    
    int n,m;
    cin>>n>>m;
    vector<int> h(n+1);
    vector<int> g(n + 1,1);
    fori(n) cin>>h[i+1];
    int x,y;
    fori(m){
        cin>>x>>y;
        if(h[x]<h[y]){
            g[x]=0;
        }
        else if(h[x]>h[y]) g[y]=0;
        else{
            g[x]=0;
            g[y]=0;
        }
    }
    int ans=0;
    //printvec(g);
    for(int i=1;i<=n;i++) ans+=g[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    int n,m;
    cin>>n>>m;
    if(n>=2 && m>=2) cout<<(n-1)*(m-1)<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

ll get(ll t, ll s){
    if(t == -1)return 0;
    else return t / s + 1;
}

int main(){

    ll a, b, x;
    cin >> a >> b >> x;

    cout << get(b, x) - get(a - 1, x) << endl;
    
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v = read_vec::<u64>();
    let n = v[0] as usize;
    let m = v[1];
    let mut oks = vec![true; n + 1];

    for _ in 0..m {
        let ai = read::<usize>();
        oks[ai] = false;
    }

    let mut dp = vec![0; n + 1];
    dp[0] = 1;
    for now in 0..n {
        for next in now + 1..std::cmp::min(n, now + 2) + 1 {
            if oks[next] {
                dp[next] += dp[now];
                dp[next] %= 1000000007;
            }
        }
    }

    println!("{}", dp[n]);
}


Measured memory_bytes: 4352
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N, X = l_inpl()

a, p = [1], [1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(N, X):
    if N == 0: # 一番下の層のみ
        if X > 0:
            return 1
        else:
            return 0
    elif X <= 1 + a[N-1]: # 一番下の層 + その上のN-1バーガーの下からX-1層
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

Measured memory_bytes: 3700
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    l = [0]*(n+1)
    l[n] = (A[n], A[n])
    for i in reversed(range(1, n+1)):
        l[i-1] = (max(math.ceil(l[i][0]/2)+A[i-1], 1), l[i][1]+A[i-1])

    if 1 not in range(l[0][0], l[0][1]+1):
        print(-1)
    else:
        ans = [0]*(n+1)
        ans[0] = 1
        cnt = 1
        for i in range(n):
            ans[i+1] = min((ans[i]-A[i])*2, l[i+1][1])
        print(sum(ans))


resolve()

Measured memory_bytes: 94428
def f(a):
	s=0;q=a[:n];s=sum(q);heapify(q);yield s
	for e in a[n:2*n]:s+=e-heappushpop(q,e);yield s
from heapq import*;r=reversed;n,*a=map(int,open(0).read().split());print(max(map(sum,zip(f(a),r(list(f([-e for e in r(a)])))))))

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

using namespace std;

/*
    5 2 4
    bbrrr
    6 2 4
    bbrrrr
    7 2 4
    bbrrrrb
    8 4 0

*/



int main()
{
    long long int N,A,B;
    cin >> N >> A >> B;
    long long int counter = 0;
    if(A==0 && B==0)
    {
        cout << counter << endl;
    }
    else
    {
        counter += (N/(A+B))*A;
        long long int n = N-(N/(A+B))*(A+B);
        counter += min(A,n);
        cout << counter << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  int N;
  cin >> N;
  char prev = '\0';
  set<string> s;
  bool ans = true;
  rep(i, 0, N) {
    string w;
    cin >> w;

    if (s.find(w) != s.end()) ans = false;
    s.insert(w);

    if (prev != '\0' && prev != w[0]) ans = false;
    prev = w[w.size() - 1];
  }

  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
const int mod = 1000000007;
signed main() {
	string l; cin >> l;
	int ans = 1;
	int k = 0, p = 1, p1 = 1;
	for (int i = 0; i < l.size(); i++) {
		ans *= 3;
		ans %= mod;
		p1 *= 3;
		p1 %= mod;
	}
	for (int i = 0; i < l.size(); i++) {
		while (p1 % 3 != 0)p1 += mod; p1 /= 3;
		if (l[i] == '1') { p *= 2; p %= mod; }
		else k += p * p1 * 2; k %= mod;
	}
	cout << (ans - k + mod) % mod << endl;
  
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[110];
int main()
{
	int n;
	int x;
	double ans = 0.0;
	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
		ans += (1.0 * 1 / a[i]);
	}
	
	cout << 1 / ans << endl;

	return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define int int64_t
#define watch(x) cout << (#x) << " is " << (x) << endl

const int32_t MAX=1e9+7;
typedef vector<int> vi;
typedef vector<int64_t> vll;

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

    //Problem code start

    int n;
    cin >> n;
    int ways{0};
    for(int a=1;a<n;a++){
        int ans = (n-1)/a;
        ways+=ans;
    }
    cout << ways;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

const ll MAX_N = 1LL << 19;
vec bit(MAX_N, 0);//1-indexed
ll sum(ll i){
    ll s = 0;
    while(i > 0){
        s += bit[i];
        i -= i & -i;
    }
    return s;
}
void add(ll i, ll x){
    while(i < MAX_N){
        bit[i] += x;
        i += i & -i;
    }
}


int main() {
  cin>>S;
  N = S.size();
  mat memo(26,vec(0));
  rep(i,N){
    memo[(S[i] - 'a')].push_back(i);
  }
  bool first = true;
  vec abcnum(26);
  rep(i,26){
    abcnum[i] = memo[i].size();
    if(abcnum[i]%2 == 1){
      if(first) {
	first = false;
      }else{
	cout<<-1<<endl;
	return 0;
      }
    }
  }
  vector<bool> used(N,false);
  ll ans = 0, id = 0;
  rep(i,N){
    while((id < N) && (used[id])) ++id;
    if(id == N) break;
    ll alpha = S[id] - 'a';
    if(abcnum[alpha] == 1){
      ans += (N - 1 - sum(MAX_N - 1))/2;
    }else{
      ll right = memo[alpha][(memo[alpha].size() + abcnum[alpha])/2 - 1];
      //cout<<id<<' '<<right<<' '<<sum(MAX_N - 1)<<' '<<sum(right + 1)<<endl;
      ans += N - 1 - right - (sum(MAX_N - 1) - sum(right + 1));
      used[right] = true;
      add(right + 1, 1);
      --abcnum[alpha];
    }
    used[id] = true;
    add(id + 1, 1);
    --abcnum[alpha];
    //cout<<i<<' '<<id<<' '<<ans<<endl;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 7288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)


int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int E = min(B,D) - max(A,C);
    if (E >= 0) {
        cout << E << endl;
    }
    else {
        cout << 0 << endl;
    }
}



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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=2e5 +10, M=(ll)1e9+1 ;
const int mod =(ll)998244353 ,sz=5, MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";
	
void work(){
	ll n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	ll dif=b-a;
	for(ll i=0;i<n;i++){
		if(c*(n-1-i)-d*i <= dif && dif <= d*(n-1-i)-c*i){
			cout << "YES\n";
			return;
		}
	}
	cout << "NO\n";
  	return;

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

	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll a,b;
 
int main()
{
    scanf("%lld%lld",&a,&b);
    ll ans=0;
    for(ll i=59;i>=0;i--)
    {
        if((a&(1ll<<i))==(b&(1ll<<i)))
        {
            if(a&(1ll<<i)) a-=(1ll<<i),b-=(1ll<<i);
        }
        else
        {
            ll tmp=(1ll<<i);
            ll r=tmp*2-1; ll l=tmp+a;
            ll L=tmp; ll R=tmp;
            for(ll j=i-1;j>=0;j--)
            {
            	if(b&(1ll<<j)) 
            	{
            		R+=(1ll<<(j+1))-1;
            		break;
            	}
            }
            if(l<=R) ans+=(r-L+1);
            else ans+=(r-l+1)+(R-L+1);
            ans+=L-a;
            printf("%lld\n",ans);
            return 0;
        }
    }
    puts("1");
    return 0;
}

Measured memory_bytes: 3812
S = str(input())

words = ['dream', 'dreamer', 'erase', 'eraser']

S = S[::-1]
for i in range(len(words)):
    words[i] = words[i][::-1]

fin = True
com1 = False
cont = 0

for i in range(len(S)):
    if cont > 0:
        cont -= 1
        continue
    for j in range(len(words)):
        if words[j] == S[i:i+len(words[j])]:
            com1 = True
            cont = len(words[j]) - 1
            break
    if com1 == False:
        fin = False
        break
    com1 = False

if fin == True:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int search(int A[],int n,int key){
    int i=0;
    A[n]=key;
    while(A[i]!=key)i++;
    return i!=n;
}
int main(){
    int i,n,A[10001],q,key,sum=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>A[i];
    }
    cin>>q;
    for(i=0;i<q;i++){
        cin>>key;if(search(A,n,key))sum++;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3116
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

const ll mod = 1e9+7;

ll raise(ll a, ll b) { return b ? raise(a*a%mod,b/2)*(b%2?a:1)%mod : 1; }

ll ncr(ll n, ll r) {
	ll x = 1, y = 1;
	forl(i, 1, r+1) {
		x = x*(n-i+1)%mod;
		y = y*i%mod;
	}
	return x*raise(y, mod-2)%mod;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n, a, b; cin >> n >> a >> b;
	ll ans = raise(2, n);
	ans -= ncr(n, a); ans -= ncr(n, b);
	ans = (ans+2*mod)%mod;
	println(ans-1);
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n+1);
  for(int i=1;i<n+1;i++) {
    cin >> h.at(i);
  }
  h.at(0)=h.at(1);
  vector<int> dp(n+1,0);
  for(int i=0;i<n-1;i++) {
    dp.at(i+2)=min(dp.at(i+1)+abs(h.at(i+2)-h.at(i+1)),
                   dp.at(i)+abs(h.at(i+2)-h.at(i)));
  }
  cout << dp.at(n) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

int main() {
    string s;
    ll K;
    int ans1 = 0;
    int ans2 = 0;
    cin >> s;
    cin >> K;

    int n = s.size();
    if (s == string(n, s[0])) {
        cout << n * K / 2 << endl;
        return 0;
    }

    for (int i = 0; i < n-1; i++) {
        if (s[i] == s[i+1]) {
            ans1++;
            i++;
        }
    }
    for (int i = 0; i+1<2*n;i++) {
        if (s[i%n]==s[(i+1)%n]) {
            ans2++, i++;
        }
    }
    cout << ans1 + (ans2-ans1)*(K-1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>

using namespace std;
//debug

#define rep(i, N) for (int i = 0; i < N; i++)

#define pb push_back

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;



#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()



int main() {
	ll n,m,d;
	cin >> n >> m >> d;
	printf("%.8f", double(m - 1) / n / n*(n*double(d == 0) + 2*(n - d)*double(d != 0)));


}



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int ans;
int n;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
cin>>n;
  for (int i=0; i<n; i++) {
    int x; cin>>x;
    while (x%2==0) {
      ans++;
      x=x/2;
    }
  }
  
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
/* JOI 2014 Yosen 2 */

#include <stdio.h>

int main(void)
{
	int n, m;					/* n = ??????????????°, m = ?????????????????° */
	int i, j, k;				/* ??????????????° */
	int a[100], b[100][100];	/* a[i] = i????????????????????????
									b[i][j] = j?????????i????????????????????§??????????????????????????? */
	int point[100] = {0};		/* point[i] = i??????????????° */
	
	/* ??\??? */
	scanf("%d", &n);
	scanf("%d", &m);
	for (i = 0; i < m; i++){
		scanf("%d", &a[i]);
	}
	for (i = 0; i < m; i++){
		for (j = 0; j < n; j++){
			scanf("%d", &b[i][j]);
		}
	}
	
	/* ?¨???? */
	for (i = 0; i < m; i++){		/* i?????????????????? */
		for (j = 0; j < n; j++){	/* j??????????????? */
			if (b[i][j] == a[i]){	/* i??????????????????????????????j????????£??? */
				point[j]++;			/* ??????????????? */
			}
			else {					/* ????????§???????????° */
				point[a[i] - 1]++;		/* ??????????????????????????????????????? */
				/* ???????????????1???????§??????£???????????§????????¨??????-1?????? */
			}
		}
	}
	
	/* ?????? */
	for (i = 0; i < n; i++){
		printf("%d\n", point[i]);
	}
	
	return (0);
}

Measured memory_bytes: 632