akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll mod = 1'000'000'007;

ll pow_mod(ll n, ll k) {
  if (k == 0)
    return 1;
  ll res = pow_mod(n, k / 2);
  res *= res, res %= mod;
  if (k % 2 != 0)
    res *= n, res %= mod;
  return res;
}

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

  int z = x + y;
  if (z % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  int xx = x - z / 3;
  int yy = y - z / 3;
  if (xx < 0 || yy < 0) {
    cout << 0 << endl;
    return 0;
  }

  ll a = 1;
  for (int i = 0; i < xx; ++i)
    a *= xx + yy - i, a %= mod;
  ll b = 1;
  for (int i = 0; i < xx; ++i)
    b *= i + 1, b %= mod;

  cout << a * pow_mod(b, mod - 2) % mod << endl;
}

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

int n,r;

int main(){

	while(1){
    cin >> n >> r;
    if ((n == 0)&&(r == 0)){
          break;
		}
	int A[n];
for (int i = 0; i <= n-1; i++){
		A[i] = n-i;
		//cout << A[i] << endl;
	}
	int p,c;


for (int i = r; i >=1; i--){

		cin >> p >> c;

		int M[p-1];
		int N[c];
for (int i = 0; i <= p-2; i++){
			M[i] = A[i];
		}
for (int i = 0; i <= c-1; i++){
			N[i] = A[p-1+i];
		}
		//??????
for (int i = 0; i <= c-1; i++){
			A[i]  = N[i];
		}
for (int i = 0; i <= p-2; i++){
			A[c+i]  = M[i];
		}
		if(i == 1){
			cout << A[0] << endl;
		}

	}
  }
}

Measured memory_bytes: 1160
a,b,c,x,y=map(int,input().split())
ans=a*x+b*y
for HaH in range(0,2*max(x,y)+1,2):
    ans = min(ans, c*HaH+max(0, a*(x-HaH//2))+max(0, b*(y-HaH//2)))
print(ans)

Measured memory_bytes: 3060
#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 long long ll;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int>wadata(n);
    vector<int>acdata(n);
    int acCnt = 0;
    int waCnt = 0;
    rep(i,m){
        int p;
        string s;
        cin >> p >> s;
        if(s == "AC"){
            if(acdata[p-1]==0)
            acCnt++;
            acdata[p-1]=1;
        }
        else {
            if(acdata[p-1]==0)
            wadata[p-1]++;
        }
    }
    rep(i,n){
        if(acdata[i]==1)waCnt += wadata[i];
    }
    cout << acCnt << " " << waCnt << endl;
    return 0;
}

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

bool isPrime(int x){
  if(x < 2) return false;
  if(x == 2) return true;

  if(x%2 == 0) return false;
  for(int i=3;i*i<=x;i+=2){
    if(x % i == 0) return false;
  }
  return true;
}

int main() {
  int X;

  cin >> X;
  while(1){
    if(isPrime(X)) break;
    X += 1;
  }
  cout << X << endl;
  return 0;
}


Measured memory_bytes: 3632
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint n, L; std::cin >> n >> L;
  struct node_type {
    int d;
    node_type * child[2];
    bool punct = false;
  };
  node_type * root = ::new node_type{ 0, {nullptr, nullptr} };

  auto insert = [&] (auto&& f, std::vector<int> & a, node_type * node) -> void {
    if (a.empty()) {
      node->punct = true;
      return;
    }
    int x = a.back(); a.pop_back();
    node_type * & c = node->child[x];
    if (!c) {
      c = ::new node_type{ node->d + 1, {nullptr, nullptr} };
    }
    f(f, a, c);
  };

  std::vector<lint> subtrees;
  auto dfs = [&] (auto&& f, node_type * node) -> void {
    if (node->punct) return;
    assert(node);
    rep(i,0,2) {
      if (node->child[i]) {
        f(f, node->child[i]);
      } else {
        subtrees.emplace_back(L - node->d);
      }
    }
  };

  loop(n) {
    std::string s; std::cin >> s;
    std::vector<int> a(s.size());
    std::transform(all(s), a.rbegin(), [](char c){ return c == '1'; });
    insert(insert, a, root);
  }
  dfs(dfs, root);
  debug(subtrees);

  lint grundy = 0;
  for (lint x : subtrees) {
    lint g = 1ll << __builtin_ctzll(x);
    debug(x,g);
    grundy ^= g;
  }
  bool ans = grundy == 0;
  std::cout << (ans ? "Bob" : "Alice") << std::endl;
  return 0;
}

Measured memory_bytes: 9444
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>
#include <vector>

using namespace std;

int max(int a, int b);
int min(int a, int b);
int is_prime(int n);

int main(int argc, char const* argv[])
{
    int n,p;
    while (cin >> n >> p) 
    {
        if ( n==-1 && p==-1 ) { break; }
        vector<int> arr;

        //素数列を格納
        int count=0;
        int i=n+1;
        while ( count <  p ) 
        {
            if ( is_prime(i) ) 
            {
                //cout << "i = " << i << endl;
                arr.push_back(i);    
                count++;
            }
            i++;
        }

        //
        //for (int i = 0; i < p; i++) 
        //{
        //    cout << arr[i] << endl;
        //}

        //足した素数を格納
        vector<int> sum;
        for (int i = 0; i < p; i++) 
        {
            for (int j = i; j < p; j++) 
            {
                sum.push_back( arr[i] + arr[j] );
            }
        }
        sort(sum.begin(), sum.end());
        cout << sum[p-1] << endl;    
    }
    return 0;
}

int is_prime(int n)
{
    if (n ==1 || n== 0) 
    {
        return 0;
    }
    for (int i = 2; i*i <= n; i++) 
    {
        if (n % i == 0) 
        {
            return 0;
        }
    }
    return 1;

}


int max(int a, int b)
{
    if (a > b) 
    {
        return a;
    }
    else{
        return b;
    }
}
int min(int a, int b)
{
    if (a > b) 
    {
        return b;
    }
    else{
        return a;
    }
}

Measured memory_bytes: 1276
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	int n, a[100001], b[100001], a1 = 0, a2;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
		if (a1 < a[i]) {
			a1 = a[i];
			a2 = b[i];
		}
	}
	printf("%d\n", a1 + a2);
	return 0;
}

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

int main()
{
    int arrA[20], arrB[20], arrC[20];
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int p;
        cin>>p;
        arrA[i] = p;
    }
    for(int i=0; i<n; i++)
    {
        int p;
        cin>>p;
        arrB[i] = p;
    }
    for(int i=0; i<n-1; i++)
    {
        int p;
        cin>>p;
        arrC[i] = p;
    }
    //cout<<arrC[1]<<endl;
    int ans = 0;
    
    for(int i=0; i<n; i++)
    {
        ans += arrB[arrA[i]-1];
        if(arrA[i] == arrA[i+1] - 1 && i <n-1)
        {
            ans += arrC[arrA[i]-1];

        }
    }
    cout<<ans;
    return 0;
}

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

typedef long long ll;

int main(){

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

    int n;
    cin>>n;
    ll a,b,dsr=0;
    cin>>a>>b;
    for(int i=3;i<=n;i++){
        ll tmp;
        cin>>tmp;
        dsr^=tmp;
    }
    ll same=a+b-dsr>>1;
    if(a+b-dsr&1||same<0||same>a||same&dsr){
        cout<<"-1\n";
        return 0;
    }
    ll na=same;
    for(int i=60;i>=0;i--){
        if(dsr>>i&1&&same>>i&1^1&&(na|1ll<<i)<=a){
            na|=1ll<<i;
        }
    }
    if(na==0){
        cout<<"-1\n";
        return 0;
    }
    cout<<a-na<<endl;

    return 0;
}

Measured memory_bytes: 3656
# -*- coding: utf-8 -*-

def main(N, T, t):
    ttl = T
    tmp = T
    for i in range(1, N):
        if(tmp<t[i]):
            ttl += T
        else:
            ttl += t[i] - t[i-1]
        tmp = t[i] + T
    print(ttl)
          
if __name__ == '__main__':
    N, T = map(int, input().split())
    t = [int(i) for i in input().split()]
    
    main(N, T, t)

Measured memory_bytes: 25196
using System;

class Program
{
    static void Main(string[] args)
    {
        int poitTarou = 0;
        int pointhanako = 0;

        int count = int.Parse(Console.ReadLine());

        for (int i = 0; i < count; i++)
        {
            String[] card = Console.ReadLine().Split(' ');

            if (String.Compare(card[0], card[1], true) == 0)
            {
                poitTarou++;
                pointhanako++;
            }
            else if (String.Compare(card[0], card[1], true) > 0)
            {
                poitTarou += 3;
            }
            else if (String.Compare(card[0], card[1], true) < 0)
            {
                pointhanako += 3;
            }

        }

        Console.WriteLine("{0} {1}", poitTarou, pointhanako);

    }
}

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

 int main() {
   int n, ans;
   cin >> n;
   vector<int> v(n + 1);
   vector<pair<int, int>> oddsum(100001), evensum(100001);

   rep(i, n) cin >> v.at(i + 1);
   rep(i, 100001) {
     oddsum.at(i).second = i;
     evensum.at(i).second = i;
   }

   for (int i = 1; i <= n; i += 2) {
     oddsum.at(v.at(i)).first++;
   }
   for (int i = 2; i <= n; i += 2) {
     evensum.at(v.at(i)).first++;
   }

   sort(oddsum.begin(), oddsum.end());
   reverse(oddsum.begin(), oddsum.end());
   sort(evensum.begin(), evensum.end());
   reverse(evensum.begin(), evensum.end());

   if (oddsum.at(0).second != evensum.at(0).second) ans = n - oddsum.at(0).first - evensum.at(0).first;
   else ans = min(n - oddsum.at(0).first - evensum.at(1).first, n - oddsum.at(1).first - evensum.at(0).first);

   cout << ans << endl;
 }


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T>
T extgcd(T a,T b,T &x,T &y){
  if(!b){x=1;y=0;return a;}
  T d=extgcd(b,a%b,y,x); 
  y-=(a/b)*x;
  return d;
}
//ax+by=gcd(a,b)を満たすx,y 返り値はgcd

template<typename T>
pair<T,T> ChineseRem(const vector<T> &b,const vector<T> &m){
  T r=0,M=1;
  for(int i=0;i<(int)m.size();++i){
    T p,q;
    T g=extgcd(M,m[i],p,q);
    if((b[i]-r)%g)return {0,-1};
    r+=M*(((b[i]-r)/g*p)%(m[i]/g));
    M*=m[i]/g;
  }
  return {(r%M+M)%M,M};
}
//x=a[i](modm[i]) を満たすx(0<=x<Π(m[i])) を求める
//法が互いに素でない場合、解が存在しない場合がある

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,m;cin>>n>>m;
  V<ll> b(n),mo(n);
  rep(i,0,n){
    cin>>mo[i];
    b[i]=mo[i]/2;
  }

  PL ans=ChineseRem(b,mo);

  if(ans.sc<0){
    cout<<0<<ENDL;
    return 0;
  }
  ll cnt=m/ans.sc;
  if(ans.fs!=0 && ans.fs<=m%ans.sc)cnt++;
  cout<<cnt<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

int main() {
	ll h,n;
	cin>>h>>n;
	ll arr[n],sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		sum=sum+arr[i];
	}
	if(sum>=h)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 1024
S = list(input())
kisu = ['R','U','D']
gusu = ['L','U','D']
ans = 'Yes'
for i in range(len(S)):
    if i%2==0:
        if S[i] in kisu:
            continue
        else:
            ans = 'No'
            break
    else:
        if S[i] in gusu:
            continue
        else:
            ans = 'No'
            break
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int MAX_V = 10;

int d[MAX_V][MAX_V];
int V = MAX_V;

void warshall_floyd() {
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int H, W;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      cin >> d[i][j];
    }
  }
  warshall_floyd();

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int a;
      cin >> a;
      if (a == -1 || a == 1) {
        continue;
      }
      ans += d[a][1];
    }
  }
  cout << ans << endl;
  return 0;
}

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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    ll x1,x2,x3,x4,y1,y2,y3,y4,a,b,ansx,ansy; cin >> x1 >> y1 >> x2 >> y2;
   a=x1-x2;b=y1-y2;
   ansx=b+x2;
   ansy=-a+y2;
   cout << ansx << " "<< ansy<<" ";
   a=x2-ansx;b=y2-ansy;
   ansx=b+ansx;
   ansy=-a+ansy;
   cout << ansx << " "<< ansy << endl;
  }


Measured memory_bytes: 256
[A, B, C] = list(map(int, input().split()))
K = int(input())
N = 0
Answer = 'No'

while B <= A:
    B = 2*B
    N += 1

while C <= B:
    C = 2*C
    N += 1

if N <= K:
    Answer = 'Yes'
print(Answer)


Measured memory_bytes: 9168
#include<iostream>

using namespace std;

int main(){
	int h,m,s;
	cin>> s;
	h=s/3600;
	s=s%3600;
	m=s/60;
	s=s%60;
	cout<< h<< ":"<< m<< ":"<< s<<endl;
	return 0;
}

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

using namespace std;

int main(void){
    long long Q;
    cin >> Q;
    set<long long> left, right;
    long long bsum = 0;
    long long msum = 0;
    long long geta = 1E+10;
    for(long long q = 0; q < Q; q++){
        int type;
        cin >> type;
        if(type == 1){
            long long a, b;
            cin >> a >> b;
            bsum += b;
            long long m = 0;
            if(left.size() > 0) m = *(left.rbegin()) / Q - geta;
            else{
                goto hoge;
            }
            if((a + geta) * Q + q < *(left.rbegin())){
                msum += m - a;
                hoge:;
                left.insert(Q * (a + geta) + q);
            }else{
                right.insert(Q * (a + geta) + q);
                msum += a - m;
            }
            if(left.size() < right.size()){
                long long rmin = *(right.begin());
                right.erase(rmin);
                rmin /= Q;
                rmin -= geta;
                long long lmax = *(left.rbegin());
                left.insert((rmin + geta) * Q + q);
                lmax /= Q;
                lmax -= geta;
                 msum -= rmin - lmax;
            }else if(left.size() > right.size() + 1){
                long long lmax = *(left.rbegin());
                left.erase(lmax);
                lmax /= Q;
                lmax -= geta;
                long long rmin = *(right.begin());
                right.insert((lmax + geta) * Q + q);
                rmin /= Q;
                rmin -= geta;
                // msum += rmin - lmax;
            }
            // cout << "L: " << left.size() << " R: " << right.size() << endl;
        }else{
            cout << *(left.rbegin()) / Q - geta << " " << msum + bsum << endl;
        }
    }
    return 0;
}

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

int n;
int a[20][20], a_tmp[20][20];

void op0(){
  int r, c, size, angle;
  cin >> r >> c >> size >> angle;
  r--;
  c--;

  for(int q = 0; q < angle / 90; q++){
    memcpy(a_tmp, a, sizeof(a));

    for(int i = r; i < r + size; i++){
      for(int j = c; j < c + size; j++){
        int i0 = i - r;
        int j0 = j - c;
        a[r + j0][c + (size - i0 - 1)] = a_tmp[r + i0][c + j0];
      }
    }
  }
}

void op1(){
  int r, c, size;
  cin >> r >> c >> size;
  r--;
  c--;

  for(int i = r; i < r + size; i++){
    for(int j = c; j < c + size; j++){
      a[i][j] = !a[i][j];
    }
  }
}

void op2(){
  int r;
  cin >> r;
  r--;

  int left_val = a[r][0];
  for(int i = 0; i < n - 1; i++){
    a[r][i] = a[r][i + 1];
  }
  a[r][n - 1] = left_val;
}

void op3(){
  int r;
  cin >> r;
  r--;

  int right_val = a[r][n - 1];

  for(int i = n - 1; i > 0; i--){
    a[r][i] = a[r][i - 1];
  }
  a[r][0] = right_val;
}

int dr[] = {1, -1, 0, 0};
int dc[] = {0, 0, 1, -1};

void dfs(int r, int c, int val){
  a[r][c] = !a[r][c];

  for(int i = 0; i < 4; i++){
    int nr = r + dr[i];
    int nc = c + dc[i];

    if(nr < 0 || n <= nr || nc < 0 || n <= nc) continue;
    if(a[nr][nc] != val) continue;

    dfs(nr, nc, val);
  }
}

void op4(){
  int r, c;
  cin >> r >> c;
  r--;
  c--;
  dfs(r, c, a[r][c]);
}

int main(){
  int Q;

  while(cin >> n >> Q){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        cin >> a[i][j];
      }
    }

    while(Q--){
      int o;
      cin >> o;

      switch(o){
        case 0: op0(); break;
        case 1: op1(); break;
        case 2: op2(); break;
        case 3: op3(); break;
        case 4: op4(); break;
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(j != 0) cout << " ";
        cout << a[i][j];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n ; cin >> n;

    vector<ll> a(n+1);
    vector<ll> b(n);
    REP(i,n+1) cin >> a[i];
    REP(i,n) cin >> b[i];

    ll ans = 0;
    ll prev = 0;

    REP(i,n) {
        ans += min(a[i],b[i]+prev);
        prev = max(0LL,b[i] - max(0LL,a[i] - prev));
    }
    ans += min(a[n],prev);

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {
	private static final int MOD = 1_000_000_007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		int C = sc.nextInt();
		int D = sc.nextInt();

		long a = B / C - (A - 1) / C;
		long b = B / D - (A - 1) / D;

		long lcm = lcm(C, D);
		long dup = B / lcm - (A - 1) / lcm;

		System.out.println((B - (A - 1)) - a - b + dup);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	private static long gcd(long m, long n) {
		long temp;
		while (m % n != 0) {
			temp = n;
			n = m % n;
			m = temp;
		}
		return n;
	}

	private static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	private static int add(int a, int b) {
		return (a + b) % MOD;
	}

	private static int sub(int a, int b) {
		return (a - b % MOD) % MOD;
	}

	private static int mul(int a, int b) {
		return ((a % MOD) * (b % MOD)) % MOD;
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public char nextChar() throws IOException {
			return (char) skip();
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

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


#define li          long long int
#define uli         unsigned long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li dp[2020][2020];

li sum[2020][2020];

int main() {
    li s;
    cin >> s;
    li res = 0;
    dp[0][0] = 1;
    sum[0][0] = 1;
    rep(i, s) {
        sum[0][i + 1] = 1;
    }
    rep(i, s / 3 + 1) {
        repp(j, 3, s + 1) {
            dp[i + 1][j] = sum[i][j - 3];
        }
        sum[i + 1][0] = 0;
        rep(j, s) {
            sum[i + 1][j + 1] = (sum[i + 1][j] + dp[i + 1][j + 1]) % MOD;
        }
        res = (res + dp[i + 1][s]) % MOD;

        //rep(j, s + 1)cout << dp[i + 1][j] << " "; cout << endl;
        //p2(res, dp[i + 1][s]);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 24476
#include<cmath>
#include<cstdio>
#include<algorithm>

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

using namespace std;

int main(){
	for(int x1,y1,x2,y2,x3,y3;scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3),x1||y1||x2||y2||x3||y3;){
		double a,b,c;
		a=hypot(x2-x3,y2-y3);
		b=hypot(x3-x1,y3-y1);
		c=hypot(x1-x2,y1-y2);
		double A,B,C;
		A=acos((b*b+c*c-a*a)/(2.*b*c))/2;
		B=acos((c*c+a*a-b*b)/(2.*c*a))/2;
		C=acos((a*a+b*b-c*c)/(2.*a*b))/2;

		double cotA,cotB,cotC;
		cotA=cos(A)/sin(A);
		cotB=cos(B)/sin(B);
		cotC=cos(C)/sin(C);

		double s=(a+b+c)/2;
		double area=sqrt(s*(s-a)*(s-b)*(s-c));

		double r1,r2,r3;
		double r1min=0.05,r1max=2*area/(a+b+c);
		rep(i,50){
			r1=(r1min+r1max)/2;
			r2=(-sqrt(r1)+sqrt(r1+cotB*(c-r1*cotA)))/cotB;	r2=r2*r2;
			r3=(-sqrt(r1)+sqrt(r1+cotC*(b-r1*cotA)))/cotC;	r3=r3*r3;
			if(r2*cotB+2*sqrt(r2*r3)+r3*cotC<a)	r1max=r1;
			else								r1min=r1;
		}
		printf("%f %f %f\n",r1,r2,r3);
	}

	return 0;
}



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

int main(int argc, char const *argv[]) {
  int c, r;
  cin >> c >> r;

  int a[101][101] = {0};

  for (int i = 0; i < c; i++) {
    for (int j = 0; j < r; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < c; i++) {
    for (int j = 0; j < r; j++) {
      // cout << a[i][r] << endl;
      a[i][r] += a[i][j];
      a[c][j] += a[i][j];
    }
    a[c][r] += a[i][r];
  }

  for (int i = 0; i <= c; i++) {
    cout << a[i][0];
    for (int j = 1; j <= r; j++) {
      cout << ' ' << a[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3128
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;

int main()
{
  std::cin >> N;

  ll d = N%10;

  if( d == 3 )
  {
    std::cout << "bon" << std::endl;
  }
  else if( d == 0 || d == 1 || d == 6 || d == 8 )
    std::cout << "pon" << std::endl;
  else
    std::cout << "hon" << std::endl;

  return 0;
}

Measured memory_bytes: 3136
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
H, W=input().split()
H=int(H)
W=int(W)
#C=int(C)
#K=int(K)
i=0
ID_list=[]
ID_sublist=[]
pixel_list=[]
H_dummy=0
W_dummy=0
C_dummy=0
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#for i in range(K):
# ID_list.append(i+1)
#print(ID_list)
#for i in range(H)
#この下の行が二次元リストの読み込
#intを消して記号を読み込めるようにしたしかしこれでは文字列から読み込んでいるのと同じ
pixel_list =  [list(input())for i in range(H)]
#for i in range(H):
#  ppixel_list=list(input())
#  
#print(pixel_list)
i=0
j=0
high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)
#print(pixel_list[0][1])#行　列の順番にかっこが並んでいる
j=0
k=0
for j in range(2*H):
    for k in range(W):
        #print(j, k)
        high_pixel_list[j][k]=pixel_list[j//2][k]
    print(''.join(high_pixel_list[j][:]))
#print(high_pixel_list)

 



#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！

#x=[]
#y=[]
#t, x, y = [0]*(H+1), [0]*(H+1), [0]*(H+1)#H+1個の空のリストを作成(原点を入れて##るから一つ増える)
#delta_t=0
#delta_x=0
#delta_y=0
#l=0
#t[0],x[0],y[0]=[0, 0, 0]
#とりあえず入力までは完成した．
#for i in range(Hyy):
# t[i+1], x[i+1], y[i+1] = map(int, input().split())
#child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
#child_il=sorted(child_i)
#print(child_il)#リストの右端のほうが大きい


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


int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, k; cin >> n >> k;
	vector<ll> l, r(1, 0);
	for(int i = 0; i < n; i++) {
		ll x; cin >> x;
		if(x < 0) {
			x = -x;
			l.push_back(x);
		} else if(x > 0) {
			r.push_back(x);
		} else {
			k--;
		}
	}
	l.push_back(0);
	if(k <= 0) {
		cout << "0\n";
		return 0;
	}
	reverse(all(l));
	ll ans = LLONG_MAX;
	for(int i = 0; i <= k; i++) {
		if(i >= l.size() || k - i >= r.size()) continue;
		ans = min(ans, 2 * l[i] + r[k - i]);
		ans = min(ans, l[i] + 2 * r[k - i]);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1656
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      xys: [(f64, f64); n],
    }

    let mut ans = 0.0;
    for i in 0..n {
        let mut s = 0.0;
        for j in 0..n {
            if i != j {
                let (x1, y1) = xys[i];
                let (x2, y2) = xys[j];

                s += ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)).sqrt();
            }
        }
        ans += s/(n as f64);
    }
    puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/22  Problem: codefestival2017_qual_b C  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	string s;
	cin >> s;
	VI cnt(30, 0);
	int flag = 1;
	FOR(i, 0, SZ(s))cnt[s[i] - 'a']++;
	for (int l = 0,  r = SZ(s) - 1; l < r;) {
		if (s[l] == s[r]) { l++; r--; }
		else if (s[r] == 'x') { ans++; cnt['x' - 'a']++; r--; }
		else if (s[l] == 'x') { ans++; cnt['x' - 'a']++; l++; }
		else { flag = 0; break; }
	}

	if (flag == 0)cout << "-1" << endl;
	else cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <map>
using namespace std;
 
class Point2{
public:
    int tx;
    int ty;
    int kx;
    int ky;
};
 
int mk(Point2 p)        // キーを生成
{
    return (((p.tx-1)*50+(p.ty-1))*50+(p.kx-1))*50+(p.ky-1);
}
 
int main()
{
    while(true){
        int W, H;
        cin >> W >> H;
 
        if(W==0 && H==0)
            break;
 
        Point2 p;
        cin >> p.tx >> p.ty;
        cin >> p.kx >> p.ky;
 
        int d[52][52];
        for(int y=0; y<=H+1; y++){
            for(int x=0; x<=W+1; x++){
                d[y][x] = 1;            // 番兵
            }
        }
 
        for(int y=1; y<=H; y++){
            for(int x=1; x<=W; x++){
                cin >> d[y][x];
            }
        }
 
        queue<Point2> que;        // キュー
        que.push(p);
 
        map<int, int> n;          // マップ（時間）
        n[mk(p)] = 0;
 
        while(true){
            if(que.empty()){            // 出会うことができない場合
                cout << "NA" << endl;
                break;
            }
 
            p = que.front();
            que.pop();
 
            if(n[mk(p)]>=100){       // 100以上の時間を要する場合
                cout << "NA" << endl;
                break;
            }
 
            if(p.tx==p.kx && p.ty==p.ky){       // 2人が出会う
                cout << n[mk(p)] << endl;
                break;
            }
 
            Point2 q;
 
            // 東
            q = p;
            if(d[q.ty][q.tx+1]==0){
                q.tx = q.tx+1;
            }
            if(d[q.ky][q.kx-1]==0){
                q.kx = q.kx-1;
            }
            if(n.find(mk(q))==n.end()){
                que.push(q);
                n[mk(q)] = n[mk(p)]+1;
            }
 
            // 西
            q = p;
            if(d[q.ty][q.tx-1]==0){
                q.tx = q.tx-1;
            }
            if(d[q.ky][q.kx+1]==0){
                q.kx = q.kx+1;
            }
            if(n.find(mk(q))==n.end()){
                que.push(q);
                n[mk(q)] = n[mk(p)]+1;
            }
 
            // 南
            q = p;
            if(d[q.ty+1][q.tx]==0){
                q.ty = q.ty+1;
            }
            if(d[q.ky-1][q.kx]==0){
                q.ky = q.ky-1;
            }
            if(n.find(mk(q))==n.end()){
                que.push(q);
                n[mk(q)] = n[mk(p)]+1;
            }
 
            // 北
            q = p;
            if(d[q.ty-1][q.tx]==0){
                q.ty = q.ty-1;
            }
            if(d[q.ky+1][q.kx]==0){
                q.ky = q.ky+1;
            }
            if(n.find(mk(q))==n.end()){
                que.push(q);
                n[mk(q)] = n[mk(p)]+1;
            }
        }
    }
 
    return 0;
}


Measured memory_bytes: 11452
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 2e5 + 20 ;
int n , m , A[N] , B[N] ;
bool mark[N] ;
string s ;
vector <int> g[N] ;
queue <int> que ;

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

	cin >> n >> m ;
	cin >> s ;
	for (int i = 0 , u , v ; i < m ; i ++) {
		cin >> u >> v ;
		u -- , v -- ;
		g[u].push_back(v) ;
		g[v].push_back(u) ;

		(s[u] == 'A' ? A[v] : B[v]) ++ ;
		(s[v] == 'A' ? A[u] : B[u]) ++ ;
	}

	for (int i = 0 ; i < n ; i ++) {
		if (!A[i] || !B[i]) mark[i] = 1 , que.push(i) ;
	}

	int cnt = 0 ;

	while (_sz(que)) {
		int v = que.front() ;
		que.pop() ;
		cnt ++ ;

		for (int u : g[v]) {
			(s[v] == 'A' ? A[u] : B[u]) -- ;
			if (!mark[u] && (!A[u] || !B[u])) mark[u] = 1 , que.push(u) ;
		}
	}

	cout << (cnt < n ? "Yes" : "No") << '\n' ;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N, M, Q;
    cin >> N >> M >> Q;
    int train[N][N]; //train[i][j]: 町iから出発してjまで到達する電車の本数
    int num_trains[N] = {}; //町iから出発する電車の総数
    rep(i, N) rep(j, N) train[i][j] = 0;
    rep(i, M){
        int l, r; scanf("%d%d", &l, &r);
        l--; r--;
        for(int j = l; j <= r; j++) train[l][j]++;
        num_trains[l]++;
    }
    rep(i, Q){
        int p, q; scanf("%d%d", &p, &q);
        int ans = 0;
        p--; q--;
        for(int j = p; j <= q; j++){
            if(q != N-1) ans += train[j][j] - train[j][q+1];
            else ans += train[j][j];
        }
        printf("%d\n", ans);
    }
    return 0;
}

void solve(){}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
#define min(a, b) ((a) < (b) ? (a) : (b))

vector<pair<long long, long long>> prime_factorize(long long n) {
	vector<pair<long long, long long>> res;
	for (long long p = 2; p * p <= n; ++p) {
		// とりあえず約数を出す。
		if (n % p != 0) continue;
		int num = 0;
		while (n % p == 0) ++num; n /= p;
		res.push_back(make_pair(p, num));
	}
	// 1との約数をまとめて追加する。
	if (n != 1) res.push_back(make_pair(n, 1));
	return res;
}

long long gcd(long long x, long long y) {
	return y ? gcd(y, x % y) : x;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);

	long long N; cin >> N;
	vector<char> S(N);
	long long east = 0, west = 0;
	for (long long i = 0; i < N; ++i) {
		cin >> S.at(i);
		if (S.at(i) == 'E') {
			++east;
		}
		else {
			++west;
		}
	}

	vector<long long> left(N), right(N);
	left.at(0) = 0;
	right.at(0) = (N - 1) - west;
	if (S.at(0) == 'W') {
		right.at(0) += 1;
	}
	for (long long i = 1; i < N; ++i) {

		left.at(i) = left.at(i - 1);
		if (S.at(i - 1) == 'W') {
			left.at(i) +=  1;
		}

		right.at(i) = right.at(i - 1);
		if (S.at(i) == 'E') {
			right.at(i) -= 1;
		}
	}
	long long res = 310000;
	for (long long i = 0; i < N; ++i) {
		chmin(res, left.at(i) + right.at(i));
	}
	cout << res << endl;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
    
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	ll x;cin>>x;
	ll d=100;
	int cnt=0;
	while(1){
		d*=1.01;
		cnt++;
		if(d>=x){
			cout<<cnt<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3632
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>

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

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) (a).begin(), (a).end()

ll sign(ll x) {
	return  x / abs(x);
}

int main() {
	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	ll a = a1 - b1, b = a2 - b2;
	if (a * t1 + b * t2 == 0) {
		cout << "infinity" << endl;
		return 0;
	}
	if (sign(t1*a)*sign(t1*a + t2 * b) > 0) {
		cout << 0 << endl;
	}
	else {
		ll ans = 0;
		if (abs(t1*a) % abs(t1*a + t2 * b)) {
			ans = 1;
		}
		ans += abs(t1*a) / abs(t1*a + t2 * b) * 2;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n),b(n+1),c(n+1);
    for(lint&x:a)std::cin>>x;
    std::partial_sum(a.begin(),a.end(),b.begin()+1,[](lint x,lint y){return std::__gcd(x,y);});
    std::partial_sum(a.rbegin(),a.rend(),c.begin()+1,[](lint x,lint y){return std::__gcd(x,y);});
    lint max=0;
    for(lint i=0;i<n;i++){
        lint x=std::__gcd(b.at(i),c.at(n-i-1));
        if(max<x)max=x;
    }
    std::cout<<max<<'\n';
}


Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
using namespace std;
int d, n, q, a[300009], x;
int main() {
	while (scanf("%d", &d), d) {
		scanf("%d%d", &n, &q);
		for (int i = 1; i < n; i++) scanf("%d", &a[i]);
		sort(a, a + n);
		for (int i = 0; i < n; i++) a[i + n] = a[i] + d; a[n * 2] = a[0] + d * 2;
		long long ret = 0;
		while (q--) {
			scanf("%d", &x);
			int ptr = lower_bound(a, a + n * 2, x) - a;
			ret += min(a[ptr] - x, x - a[ptr + n - 1] + d);
		}
		printf("%lld\n", ret);
	}
	return 0;
}

Measured memory_bytes: 3340
# coding: utf-8
import re
import math
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)

def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 

 
#main

N,blue=map(int,input().split())
fac=fac_list(N,mod)
red=N-blue
for a in range(1,blue+1):
    if red+1<a:
        num=0
    else:
        num=fac[red+1]*pow(fac[red+1-a]*fac[a],mod-2,mod)
        num*=fac[blue-(a-1+1)+a-1]*pow(fac[blue-(a-1+1)]*fac[a-1],mod-2,mod)
    print(num%mod)


Measured memory_bytes: 5744
import sys
import numpy as np
import math

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A,B,H,M = map(int, input().split())

def angle(H, M):
  H_angle = H * 30 + (M/60)*30
  M_angle = M * 6
  if 360 - abs(H_angle - M_angle) > abs(H_angle - M_angle):
    return abs(H_angle - M_angle)
  else:
    return 360 - abs(H_angle - M_angle)

angle = angle(H, M)
ans = math.sqrt(A**2 + B**2 - 2*A*B* math.cos(math.radians(angle)))
print(ans)
  

Measured memory_bytes: 27160
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class BAlgae {
public:
        ll r,d,x;
void solve(std::istream& cin, std::ostream& cout) {
    cin >>r >> d >> x;
    _for(i,10){
        x = r*x-d;
        cout << x << endl;
    }
}
};


#undef int
int main() {
	BAlgae solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256