akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
int main(){
  string s; cin >>s;
  deque<char>dq;
  for(int i=0; i<s.size(); i++) dq.push_back(s[i]);
  int q; cin >>q; bool shit=0;
  for(int i=0; i<q; i++){
    int t; cin >>t;
    if(t==1) shit=1-shit;
    else{
      int f; char c; cin >>f >>c;
      if(f==1){
        if(shit) dq.push_back(c);
        else dq.push_front(c);
      }
      else{
        if(shit) dq.push_front(c);
        else dq.push_back(c);
      }
    }
  }
  if(shit) while(!dq.empty()){cout <<dq.back(); dq.pop_back();}
  else while(!dq.empty()){cout <<dq.front(); dq.pop_front();}
return 0;}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main()
{
   int a,b ;
   cin >> a >> b;
 if (a>b)
   cout <<"a > b"<<endl;
   else if (a<b)
   cout <<"a < b"<<endl;
   else
   cout <<"a == b"<<endl;
    return 0;
}



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

using namespace std;

#define N 600000

int n,x,y,s,t,sg[N],head[N],tot,d[N],q[N];
struct edge{int v,nxt;}e[N];

void add(int x,int y){
	e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;
}

int bfs(int s){
	memset(d,-1,sizeof d);
	int tt=0,ww=1; q[1]=s; d[s]=1;
	while (tt<ww){
		int u=q[++tt];
		for (int i=head[u],v;i;i=e[i].nxt)
			if (d[v=e[i].v]==-1){
				d[v]=d[u]+1;
				q[++ww]=v;
			}
	}
	return q[ww];
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<n;++i){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	sg[0]=0; sg[1]=1; sg[2]=0;
	for (int i=3;i<=n;++i){
		if (sg[i-1]==0||sg[i-2]==0){
			sg[i]=1;
			if (sg[i-1]==1||sg[i-2]==1) sg[i]=2;
		}
	}
	s=bfs(1); t=bfs(s);
	puts(sg[d[t]]?"First":"Second");
	
	return 0;
}
			


Measured memory_bytes: 12800
def dist(x, y):
    return abs(x[0] - y[0]) + abs(x[1] - y[1])


N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(M)]
for i in range(N):
    ans = -1
    min_dist = float("inf")
    for j in range(M):
        if (d := dist(AB[i], CD[j])) < min_dist:
            ans = j
            min_dist = d
    print(ans + 1)


Measured memory_bytes: 9212
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        long[] arr=findDivisors(n);
        for(int i=1;i<arr.length;i++){
            sum+=arr[i]*(i);
            
        }
        System.out.println(sum);
    }
    
    static long[] findDivisors(int n)  
    {  
        long[] div = new long[n + 1];  
        for (int i = 1; i <= n; i++)  
        {   
            for (int j = 1; j * i <= n; j++)  
                div[i * j]++;  
        }  
        return div;
    }  
}

Measured memory_bytes: 116172
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (H, W) = Slice2<long>();
            var (h, w) = Slice2<long>();
            WriteLine((W - w) * (H - h));
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 27544
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  long long int A[N],H[N+1]={0},C[N+1];
  for(int i=0;i<N;i++)
  {
    cin>>A[i];
    H[A[i]]++;
  }
  //cout<<H[1];
  long long int sum=0;
  for(int i=0;i<N+1;i++)
  {
    C[i]=H[i]*(H[i]-1)/2;
    sum+=C[i];
  }
  //cout<<C[1];
  for(int i=0;i<N;i++)
  {
    long long int ans;
    ans=sum-(H[A[i]]-1);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 8832
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main()
{
        string S;
        cin >> S;

        int even = 0;
        int odd = 0;
        for (int i = 0; i < S.length(); i++)
        {
                if (i % 2 == 0)
                {
                        if (S[i] != '1')
                        {
                                even++;
                        }
                }
                else
                {
                        {
                                if (S[i] != '0')
                                {
                                        even++;
                                }
                        }
                }
        }

        for (int i = 0; i < S.length(); i++)
        {
                if (i % 2 == 0)
                {
                        if (S[i] != '0')
                        {
                                odd++;
                        }
                }
                else
                {
                        {
                                if (S[i] != '1')
                                {
                                        odd++;
                                }
                        }
                }
        }

        cout << min(odd, even) << endl;

        return 0;
}

Measured memory_bytes: 512
#[allow(dead_code)]
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()
}
#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let _n = read::<usize>();
    let mut ls = read_vec::<u32>();
    ls.sort();
    let lmax = ls.pop().unwrap();
    let lsum = ls.iter().sum::<u32>();
    yn(lmax < lsum);
}


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

#define STRING(str) #str
#define ll long long

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

int main() {
	int N;
	cin >> N;
	int cnt = 0;
	bool flag = false;
	for (int i=0;i<N;i++) {
		int D1, D2;
		cin >> D1 >> D2;
		if (D1 == D2) {
			cnt++;
		} else {
			cnt = 0;
		}
		if (cnt == 3) {
			flag = true;
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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


void solve(long long A, long long B, long long C){
    long long ans = 0;

    if (B >= C) {
        ans = B + C;
    } else {
        ans = 2 * B;
        C -= B;
        ans += min(A + 1, C);
    }

    cout << ans << endl;
    return;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 100005
int N;
vector<pii> G[MXN];
int col[MXN];

void dfs(int u, int p)
{
    for(pii e : G[u])
    {
        int v = e.f, w = e.s;
        if( v==p )continue;
        if( w%2 )
        {
            col[v]=3-col[u];
            dfs( v, u );
        }
        else
        {
            col[v]=col[u];
            dfs( v, u );
        }
    }
}

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

    cin>>N;
    int a,b,c;
    FOR(i,1,N-1)
    {
        cin>>a>>b>>c;
        G[a].pb( mkp(b,c) );
        G[b].pb( mkp(a,c) );
    }
    col[1]=1;
    dfs(1,-1);
    FOR(i,1,N)cout<<col[i]-1<<'\n';

    return 0;
}


Measured memory_bytes: 9216
N = int(input())
D = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
  S = input()
  if S[0] in D:
    D[S[0]] += 1
L1 = [D[i] for i in D]
M = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      M += L1[i]*L1[j]*L1[k]
print(M)

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

int main() {
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int ans=0;
  for(int i=0;i<=a;i++) {
    for(int j=0;j<=b;j++) {
      for(int k=0;k<=c;k++) {
        if(500*i+100*j+50*k==x) {
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  int len = s.length();
  int count = 0;
  bool a = false, maked = true;
  REP(i,len){
    if(!a && s[i] == 'A'){
      a = true;
    }else if(count == 0 && s[i] == 'K' && i + 1 < len && s[i + 1] == 'I' && i + 2 < len && s[i + 2] == 'H'){
      count++;
      a = false;
      i++;
    }else if(count == 1 && s[i] == 'H'){
      count++;
      a = false;
    }else if(count == 2 && s[i] == 'B'){
      count++;
      a = false;
    }else if(count == 3 && s[i] == 'R'){
      count++;
      a = false;
    }else{
      maked = false;
      break;
    }
  }

  if(maked == true && count == 4){
    cout << "YES\n";
  }else{
    cout << "NO\n";
  }
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC101C
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split(' ');
            int N = int.Parse(input1[0]);
            int K = int.Parse(input1[1]);

            string[] input2 = Console.ReadLine().Split(' ');

            int ans = (N - 1) / (K - 1);
            int res = (N - 1) % (K - 1);
            if (res != 0)
            {
                ans += 1;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 18528
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String[] sl = s.split(" ");
            int W = Integer.parseInt(sl[0]);
            int a = Integer.parseInt(sl[1]);
            int b = Integer.parseInt(sl[2]);

            int ans = 0;
            if (a + W < b) ans = b - a - W;
            if (b + W < a) ans = a - b - W;

            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 22484
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;

#define EPSILON 1.0e-12



int main(){
  int a,b,t;cin>>a>>b>>t;
  cout<<t/a*b<<endl;
}

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

using namespace std;

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

	scanf("%d %d %d",&a,&b,&c);

	if((a<c && c<b)||(b<c && c<a)){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
ll a[3], d;
int r[3] = {2, 3, 5};
unordered_map<ll, ll> dp;
ll work(ll n) {
	if (dp[n]) return dp[n];
	if (n == 0) return 0;
	if (n == 1) return d;
	if (n == 2) return min(a[0] + d, 2 * d);
	ll ans = 1e18;
	if (1.0 * d * n < 2e18) 
		chkmin(ans, d * n);
	dp[n] = 1e18;
	for (int j = 0; j < 3; j++) {
		ll dv = n % r[j];
		chkmin(ans, dv * d + a[j] + work(n / r[j]));
		chkmin(ans, (r[j] - dv) * d + a[j] + work(n / r[j] + 1));
	}
	return dp[n] = ans;
} 
int main() {
	int t;
	cin >> t;
	while (t--) {
		dp.clear();
		ll n;
		cin >> n;
		for (int i = 0; i < 3; i++)
			cin >> a[i];
		cin >> d;
		cout << work(n) << endl;
	}
	return 0;
}


Measured memory_bytes: 4168
package main

import (
	"fmt"
	"math"
)

func main() {

	var num int

	for {
		fmt.Scanln(&num)

		if num == 0 {
			break
		}

		scores := make([]float64, num)

		sum := 0.0
		for i := range scores {
			fmt.Scanf("%f", &scores[i])
			sum += scores[i]
		}

		ave := sum / float64(num)

		variance := 0.0
		for i := range scores {
			variance += math.Pow((scores[i] - ave), 2.0)
		}
		variance /= float64(num)

		fmt.Printf("%f\n", math.Sqrt(variance))
	}

}



Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3652
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      if(s.length()==2){
        System.out.println(s);
      }else{
        StringBuffer str = new StringBuffer(s);
        String sb = str.reverse().toString();
        System.out.println(sb);
      }
    }
}

Measured memory_bytes: 35540
main = do
    ls <- getLine
    print $ solve ls

solve :: String -> Int
solve ls = machine (0,0) ls 0

machine :: (Int, Int) -> String -> Int -> Int
machine (r,b) []      ac = ac 
machine (r,b) ('0':ls) ac =
    if b > 0
    then machine (r,b-1) ls (ac+2)
    else machine (r+1,b) ls ac
machine (r,b) ('1':ls) ac =
    if r > 0
    then machine (r-1,b) ls (ac+2)
    else machine (r,b+1) ls ac

Measured memory_bytes: 4988
import java.math.BigDecimal

const val modLong = 1000000007L
val mod = BigDecimal(modLong)

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toLong() }
    val arr = readLine()!!.split(" ").map { it.toInt() }
    val leftCnt = arr.mapIndexed { index, i ->
        arr.subList(index + 1, arr.size).filter { i > it }.count()
    }
    val cnt = arr.map { i ->
        arr.filter { i > it }.count()
    }

    val kk = BigDecimal(k * (k - 1) / 2)
    var ans = BigDecimal(cnt.sum()) * kk
    ans += BigDecimal(leftCnt.sum() * k)
    println(ans % mod)
}

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

int main(){
    int a,p;
    cin >> a >> p;
    int ans;
    ans=(3*a+p)/2;

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,T = map(int,input().split())
CT = [tuple(map(int,input().split())) for _ in range(N)]

INF = float("inf")
ans = INF
for c,t in CT:
    if t <= T and c < ans:
        ans = c

print(ans if ans != INF else "TLE")

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  ll ans = (10000 - N) % 1000;
  cout << ans << endl;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll a,b,c,d;
    scanf ("%lld %lld %lld %lld",&a,&b,&c,&d);
    if (a > b) swap (a,b);
    ll lcm = c*d/__gcd(c,d);
    ll cfmult = (c > a ? (c > b ? 0 : 1) : (ll)ceil(a*1.0/c)), dfmult = (d > a ? (d > b ? 0 : 1) : (ll)ceil(a*1.0/d)), clmult = (c > b ? -1 : b/c), dlmult = (d > b ? -1 : b/d),lcmfmult = (lcm > a ? (lcm > b ? 0 : 1) : (ll)ceil(a*1.0/lcm)),lcmlmult=(lcm > b ? -1 : b/lcm);
    printf ("%lld\n",max((b-a+1)-(clmult-cfmult+1)-(dlmult-dfmult+1)+(lcmlmult-lcmfmult+1),0LL));
    return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 1000100;

int N;
ll arr[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> arr[i];

    ll ans = 0;
    while (true)
    {
        bool found = false;
        for (int i = 0; i < N; i++)
        {
            if (arr[i] >= N)
            {
                found = true;
                ll nv = arr[i] / N;
                arr[i] -= nv * N;
                for (int j = 0; j < N; j++)
                    if (j != i)
                        arr[j] += nv;
                ans += nv;
            }
        }
        if (!found) break;
    }
    cout << ans << "\n";
}

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


int main() {
  int a;
  cin >> a;
  string ans = "ABC";
  if(a > 999) ans = "ABD";
  cout << ans << endl;
  return 0;
  
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n, m;
int from[300], to[300], cnt[300];
map<vector<int>, int> ma, nma;
int pc[8];

inline void add(int &x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

int main() {
    if (0) {
        mt19937 mt(123);
        n = m = 300;
        forn(i, m) {
            from[i] = mt() % n;
            to[i] = mt() % n;
            if (from[i] > to[i]) {
                swap(from[i], to[i]);
            }
            cnt[i] = 1;
        }
    } else {
        scanf("%d%d", &n, &m);
        forn(i, m) {
            scanf("%d%d%d", from + i, to + i, cnt + i);
            --from[i], --to[i];
        }
    }
    vector<int> t(m, 0);
    ma[t] = 1;
    forn(i, 8) pc[i] = __builtin_popcount(i);
    forn(i, n) {
        for (auto vv : ma) forn(col, 3) {
            auto &v = vv.first;
            t = v;
            forn(j, m) if (from[j] <= i && to[j] >= i) {
                t[j] |= 1 << col;
            }
            bool ok = true;
            forn(j, m) if (to[j] == i && pc[t[j]] != cnt[j]) {
                ok = false;
                break;
            }
            if (ok) {
                forn(j, m) if (to[j] <= i) {
                    t[j] = 0;
                }
                add(nma[t], vv.second);
            }
        }
        ma = nma;
        nma.clear();
    }
    int ans = 0;
    for (auto vv : ma) {
        add(ans, vv.second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14448
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[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 $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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    input!(
        n: usize,
        p: [usize; n],
    );

    let mut ans = 0;

    for i in 1..n-1 {
        let mut t: Vec<usize> = vec![p[i-1], p[i], p[i+1]];

        t.sort();

        if t[0] != p[i] && t[2] != p[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

vector<int> a( 100000 * 3 );

int main()
{
  int n;
  cin >> n;
  for ( int i = 0; i < 3*n; i++ ) {
    scanf( "%d", &a[i] );
  }

  sort( a.begin(), a.end(), greater<int>() );

  unsigned long ans = 0;
  for ( int i = 0; i < n; i++ ) {
    ans += a[i * 2 + 1];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int H,W,N;
	int times[10]={};
	multiset<pair<int,int>> tes;
	cin>>H>>W>>N;
	for(int i=0;i<N;i++){
		//printf("\n");
		int a,b;
		cin>>a>>b;
		for(int j=0;j<=2;j++){
			for(int k=0;k<=2;k++){
				if(a-j>=1 && a-j<=H-2 && b-k>=1 && b-k<=W-2){
					tes.insert(make_pair(a-j,b-k));
					//printf("%d %d\n",a-j,b-k);
				}
			}
		}
	}
	//printf("\n");
	int A=0,B=0;
	int head=0;
	for(auto it=tes.begin();it!=tes.end();it++){
		if(!A && !B);
		else if(it->first!=A || it->second!=B){
			times[head+1]++;
			head=0;
		}
		else
			head++;
		A=it->first,B=it->second;
		//printf("%d %d\n",A,B);
	}
	if(A && B)
		times[head+1]++;
	ll sum=0;
	for(int i=1;i<10;i++)
		sum+=times[i];
	cout<<(ll)(W-2)*(H-2)-sum<<endl;
	for(int i=1;i<10;i++){
		cout<<times[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 42496
s=input()
ans=10**5
for a in set(list(s)):
  t=s
  for i in range(len(s)):
    u=''
    for j in range(len(t)-1):
      if t[j+1]==a or t[j]==a:
        u+=a
      else:
        u+=t[j+1]
    t=u
    if len(set(list(u)))==1:
      ans=min(ans,i+1)
      break
if len(set(list(s)))==1:
  ans=0
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define for(i,a,b) for(i=a;i<b;i++)
ll i;
int main(){
	ll n;
	cin>>n;
	if(n%1000==0) cout<<"0";
	else cout<<1000-n%1000;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int a1[10];
int a2[100];
int a3[1000];

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i=0; i<n; i++) {
        int v = s[i] - '0';
        for (int k=0; k<100; k++) {
            if (a2[k]) {
                if (!a3[10*k+v]) {
                    a3[10*k+v] = 1;
                    ans += 1;
                }
            }
        }
        for (int j=0; j<10; j++) {
            if (a1[j]) {
                a2[10*j+v] = 1;
            }
        }
        a1[v] = 1;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import bisect

X,Y,Z,K = list(map(int,input().split()))
AA = list(map(int,input().split()))
BB = list(map(int,input().split()))
CC = list(map(int,input().split()))
MAX = max(max(AA),max(BB),max(CC))

AB = []
for a in AA:
  for b in BB:
    AB.append(a+b)
    
AB.sort()
XY = len(AB)

def check(n):
  cnt = 0
  for c in CC:
    cnt += (XY - bisect.bisect_left(AB,n-c))
  return cnt >= K

OK = 0
NG = MAX*3+100
while NG - OK >1:
  mid = (OK+NG)//2
  if check(mid):
    OK = mid
  else:
    NG = mid
    
    
ans = []
for c in CC:
    n = bisect.bisect_left(AB,OK-c)
    for i in range(n,XY):
      ans.append(c+AB[i])
      
ans.sort(reverse=True)
for YUI in range(K):
  print(ans[YUI])
  


Measured memory_bytes: 232688
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;

#define REP(i,a) for(int i=0;i<a;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rREP(i,a) for(int i=(a)-1;i>=0;i--)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define out(S) cout<<(S)<<endl;
#define beginend(v) (v).begin(),(v).end()
#define IfOut(condition,text) if(condition){out(text);return 0;}
#define IfOutElse(condition,if_text,else_text) if(condition){out(if_text);return 0;}else{out(else_text);return 0;}
#define mod(s) ((s)%(ll)(1e9+7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a*modpow((ll)b,(ll)(1e9+5))))
#define pb(i) push_back(i)
#define fst first
#define snd second
#define Foreach(item,collection) for(auto item:collection)
#define INF 1e10
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}
ll sum(vi v) {ll sum=0;Foreach(i,v){sum+=i;}return sum;}
#define ShowAll(v) Foreach(i,v) out(i);

int r,n;
vi ans;
void solve(){
    vi a;
    rREP(i,n) a.pb(i+1);
    REP(i,r){
        int p,c;
        cin>>p>>c;
        vi tmp;
        REP(k,c){
            // cout<<"removeat:"<<p-1<<endl;
            // cout<<"a[p-1]:"<<a[p-1]<<endl;
            tmp.pb(a[p-1]);
            removeAt(a,p-1);
        }
        auto it=a.begin();
        a.insert(it,beginend(tmp));
    }
    ans.pb(a[0]);
}

int main(){
    while (cin>>n>>r, n,r)
    {
        solve();   
    }
    ShowAll(ans);
    return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
 
int main(void){
  string s;cin >> s;
  int n = s.size();
  int k;cin >> k;
  vector<string>a = {};
  for(int i = 1;i<=min(k,n);i++){
    for(int j = 0;j<=n-i;j++){
      a.push_back(s.substr(j,i));
      //cout << s.substr(j,i) << endl;
    }
  }
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  for(int i = 0;i<k+1;i++){
    //cout << a[i] << endl;
  }
  cout << a[k-1] << endl;
}

Measured memory_bytes: 1660
#include<stdio.h>
int memo[33] = {0};

int fib_memo(int n) {
	if (n <= 1) {
		return 1;
	}
	if (memo[n] > 0) {
		return memo[n];
	}
	memo[n] = fib_memo(n - 1) + fib_memo(n - 2);
	return memo[n];
}

int main() {
	int n;
	scanf("%d", &n);
	printf("%d\n", fib_memo(n));
	
	return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int x;
    cin>>x;
    if(x<1200){
        cout << "ABC" << endl;
    }else{
        cout << "ARC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
const double PI = acos(-1);
typedef long long ll;
double A,B,x;

void input(){
    cin >> A >> B >> x;
}

void solve (){
    double sq = x/A;
    double ans;
    double rad;
    if(sq >= (A*B)/2){
        double h = (B*A - sq)*2/A;
      	rad = atan2(h, A);
        
    }else {
        double w = 2*sq/B;
        rad = atan2(B, w);
        
    }
    ans = 360*rad/(2*PI);
    printf("%.10f", ans);
    return ;
}

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

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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}
typedef struct {
  u32 a;
  u32 b;
  u32 c;
  u32 d;
} CondType;
void Calc(u32 n, u32 m);
vector<u32> A(11);
u32 Res = 0;
u32 N, M, Q;
vector<CondType> Cond(50);

int main() {
  cout << setprecision(18);
  cin >> N >> M >> Q;
  for (u32 i = 0; i < Q; ++i) {
    u32 a, b, c, d;
    cin >> a >> b >> c >> d;
    CondType tmp = {a, b, c, d};
    Cond[i] = tmp;
  }
  for (u32 i = 1; i <= M; ++i) {
    Calc(0, i);
  }
  cout << Res << endl;

  return 0;
}

void Calc(u32 n, u32 m) {
  if (n > N)
    return;
  else if (n == N) {
    A[n] = m;
    u32 res = 0;
    for (u32 i = 0; i < Q; ++i) {
      if (A[Cond[i].b - 1] - A[Cond[i].a - 1] == Cond[i].c) {
        res += Cond[i].d;
      }
    }
    Res = Res > res ? Res : res;

  } else {
    for (u32 i = m; i <= M; ++i) {
      A[n] = i;
      Calc(n + 1, i);
    }
  }
}


Measured memory_bytes: 3592
n,m=gets.split.map(&:to_i)
ab=n.times.map{gets.split.map(&:to_i)}
cd=m.times.map{gets.split.map(&:to_i)}
n.times do |i|
  ans=m
  min=Float::INFINITY
  (m-1).downto(0) do |j|
    md=(ab[i][0]-cd[j][0]).abs+(ab[i][1]-cd[j][1]).abs
    if md<=min
      ans=j
      min=md
    end
  end
  puts ans+1
end


Measured memory_bytes: 1788
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

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

    int X = 0, Y = 0, Z = 0;
    rep(i, N)
    {
        if (a[i] % 4 == 0)
        {
            X++;
        }
        else if (a[i] % 2 == 0)
        {
            Y++;
        }
        else
        {
            Z++;
        }
    }
    if (Y > 0)
    {
        Z++;
    }
    if (X + 1 >= Z)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    int n;
    cin>>n;
    cout<<(n-2)*180<<endl;
    return 0;
}

Measured memory_bytes: 256
from math import inf

n, k = map(int, input().split())
a = [int(i) for i in input().split()]
dp = [inf for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if i - j >= 0:
            dp[i] = min(dp[i], abs(a[i] - a[i - j]) + dp[i - j])
        else:
            break

print(dp[-1])


Measured memory_bytes: 91048
def solve():
    N = int(input())
    MOD = 10**9+7
    U = pow(10,N,MOD)
    inc_zero = U - pow(9,N,MOD)
    inc_nine = inc_zero

    inc_both = U - pow(8,N,MOD)

    print((inc_zero+inc_nine-inc_both) % MOD)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 61768
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    from itertools import accumulate

    N = int(input())  # len(A)
    A = list(map(int, input().split()))

    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成

    ans=10**18
    for i in range(1, N):
        snuke=B[i]
        araiguma=B[N]-B[i]
        ans=min(ans,abs(snuke-araiguma))
    print(ans)
resolve()

Measured memory_bytes: 83368
#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
#define mod 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
int n,k,a[3000],cnt=0,s=0;
signed main(){
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j])cnt++;
            else if(a[i]==a[j])s++;
        }
    }
    int t=k*(k-1)/2;
    t%=mod;
    int d=n*(n-1)/2-s;
    int ans=t*d+k*cnt;
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,w[105],ind[105];
int ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>w[i];
	int sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=w[i];
		ind[i]=sum;
	}
	int ans=10005;
	for(int i=0;i<n;i++)
	{
		int n1=abs(ind[i]-(sum-ind[i]));
		ans=min(ans,n1);
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int answer = 0;

		answer = Math.min(S.replace("0", "").length(), S.replace("1", "").length()) * 2;

		System.out.println(answer);
	}
}

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#define IF_DEBUG 0
typedef long long ll;
typedef double db;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}
const int maxn = 100005;

int n, a[maxn], Ans;

int main()
{
	sf("%d",&n);
	fo(i,1,n){int l,r;sf("%d%d",&l,&r);a[l]++;a[r+1]--;}
	fo(i,1,100000) a[i] += a[i-1];
	fo(i,1,100000) if(a[i]) ++ Ans;
	pf("%d\n",Ans);	
	return 0;
}

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

using namespace std;
vector<int> num(3);

int main() {
    
    string S;
    cin >> S;
    int size_S = S.size();
    for (int i = 0; i < size_S; i++) {
        if (S[i] == 'a') num[0]++;
        else if (S[i] == 'b') num[1]++;
        else num[2]++;
    }

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

    bool can = true;

    if (num[2] - num[0] >= 2 or num[1] - num[0] >= 2) can = false;

    if (can) cout << "YES\n";
    else cout << "NO\n";

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x.begin(), x.end())
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
ll INF = 1LL<<60;

template<typename Monoid>
struct segtree {
    using T = typename Monoid::T;
    int n;
    vector<T> dat;

    segtree(int n0) {
        n = 1;
        while(n < n0) n <<= 1;
        dat.assign(n*2, Monoid::id());
    }
    void build(vector<T> v) {
        REP(i, v.size()) dat[i+n] = v[i];
        for(int i=n-1; i>0; --i) dat[i] = Monoid::op(dat[i*2], dat[i*2+1]);
    }

    T query(int a, int b) {
        T l = Monoid::id(), r = Monoid::id();
        for(a+=n, b+=n; a<b; a>>=1, b>>=1) {
            if(a&1) l = Monoid::op(l, dat[a++]);
            if(b&1) r = Monoid::op(dat[--b], r);
        }
        return Monoid::op(l, r);
    }
    void update(int i, T v) {
        i += n;
        dat[i] = v;
        while(i >>= 1) {
            dat[i] = Monoid::op(dat[i*2], dat[i*2+1]);
        }
    }
};

template<typename Tp>
struct max_monoid {
    using T = Tp;
    static constexpr Tp id() { return -INF; }
    static Tp op(const Tp &a, const Tp &b) { return max(a, b); }
};

signed main() {
    string s;
    cin >> s;
    const ll n = s.size();

    segtree<max_monoid<ll>> seg(n*2+1);

    string t = "";
    ll x = 0, ans = 0;
    map<ll,vector<ll>> mp, mp2;
    REP(i, n) {
        if(s[i]=='(') {
            x++;
            mp[x].push_back(i);
            t += s[i];
        } else if(s[i]==')') {
            ll lb = seg.query(0, x+n-1);
            // mp[x]のlbより大きいやつの個数
            ll num = mp[x].size() - (lower_bound(mp[x].begin(), mp[x].end(), lb) - mp[x].begin());
            ans += num;
            // cerr << i << " num=" << num << " lb=" << lb << endl;
            x--;
            seg.update(x+n, i);
            mp2[x].push_back(i);
            t += s[i];
        } else {
            if(t.back() == '(') {
                mp[x].pop_back();
                // seg.update(x+n, (mp[x].size()?mp[x].back():-INF));
                x--;
            } else {
                mp2[x].pop_back();
                seg.update(x+n, (mp2[x].size()?mp2[x].back():-INF));
                x++;
                ll lb = seg.query(0, x+n-1);
                // mp[x]のlbより大きいやつの個数
                ll num = mp[x].size() - (lower_bound(mp[x].begin(), mp[x].end(), lb) - mp[x].begin());
                ans -= num;
            }
            t.pop_back();
        }

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

        cout << ans << "\n";
    }
    cout << flush;
}


Measured memory_bytes: 48880
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
int main(void) {
	std::ios::sync_with_stdio(false);
	int a;
	cin >> a;
	int i = 111;
	while (1) {
		if (a > i)
			i += 111;
		else {
			break;
		}
	}
	printf("%d\n", i);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int cal(long long int g,long long int h)
{
    int i;

    long long s=0;
    while(g)
    {
        s+=g%10;
        g=g/10;
    }
    while(h)
    {
        s+=h%10;
        h=h/10;
    }
    return s;
}
int main()
{
    int n;
    cin>>n;
    long long r;
    int i;
    long long ans=0;
    long long mm=100000000;
    for(i=1;i<=n-1;i++)
    {
        long long g=i;
        long long h=n-i;
        r=cal(g,h);
        if(r<mm)
        {
            ans=i;
            mm=r;
        }
    }
    //cout<<ans<<endl;
    cout<<mm<<endl;
}


Measured memory_bytes: 256
<?php
$n=trim(fgets(STDIN));
$t[]=0;
$x[]=0;
$y[]=0;
$i=1;
while($i<=$n){
  fscanf(STDIN,'%d %d %d',$t[],$x[],$y[]);
  $dt=$t[$i]-$t[$i-1];
  $dxy=abs($x[$i]-$x[$i-1])+abs($y[$i]-$y[$i-1]);
  if($dt<$dxy||$dt%2!==$dxy%2){
    echo 'No';
    exit;
  }
  ++$i;
}
echo 'Yes';

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

using namespace std;

const int MAX_N = 5e5 + 5;

char str[MAX_N];
int ar[MAX_N];

int main() {
    scanf("%s", str + 1);
    int n = strlen(str + 1) + 1;
    memset(ar, -1, sizeof ar);
    if (str[1] == '<') ar[1] = 0;
    if (str[n - 1] == '>') ar[n] = 0;
    for (int i = 2; i < n; i++) {
        if (str[i - 1] == '>' && str[i] == '<')
            ar[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        if (ar[i] != 0) continue;
        int j = i;
        while (j < n && str[j] == '<') {
            ar[j + 1] = max(ar[j + 1], ar[j] + 1);
            j++;
        }
        j = i;
        while (j > 1 && str[j - 1] == '>') {
            ar[j - 1] = max(ar[j - 1], ar[j] + 1);
            j--;
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += ar[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner s = new Scanner(System.in);

		 String a = s.next();
		 String b = s.next();

		 String[] strArrayA = a.split("");
		 String[] strArrayB = b.split("");

		 int cnt = 0;

		 for(int i=0; i<a.length(); i++) {
			 String strA = String.valueOf(a.charAt(i));
			 String strB = String.valueOf(b.charAt(i));
			 if(strA.equals(strB) == false) {
				 cnt++;
			 }
		 }

		 System.out.println(cnt);
	}

}

Measured memory_bytes: 69292