akhauriyash/Code-Regression huggingface dataset:
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
MOD=10**9+7
N=int(input())

S=dict(zip(list(range(1,1001)),[0]*1000))
for n in range(1,N+1):
    D=prime_factorize(n)
    for d in D:
        S[d]+=1

ans=1
for s in S.values():
    ans*=(s+1)%MOD
print(ans%MOD)

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

        using namespace std;
        typedef long long ll;




        int main(){

int n;
cin >> n ;
int X[n];
for(int i=0 ; i<n ; i++){
    cin >> X[i] ;
}
int Cost[n];
if(n==1){
    cout << 0 <<endl;
    return 0;
}

Cost[0]=0;
Cost[1]=abs(X[1]-X[0]);

if(n==2){
    cout << Cost[n-1];
    return 0;
}
for(int i=2 ; i<n ; i++){

    Cost[i]=min(Cost[i-2]+abs(X[i]-X[i-2]),Cost[i-1]+abs(X[i]-X[i-1]));
}

cout << Cost[n-1];



          return 0;
        }


Measured memory_bytes: 4372
#include <stdio.h>

int main()
{
	int N;
	int A[1000] = { 0 };
	int i, j, k;
	int v = 0;

	scanf("%d", &N);
	for (i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
	}



	for (i = 0; i < N; i++)
	{
		if (i == N - 1){
			printf("%d", A[i]);
		}
		else printf("%d ", A[i]);
	}

	printf("\n");


	for (i = 1; i < N; i++)
	{
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j]>v)
		{
			A[j + 1] = A[j];
			j--;
		}

		A[j + 1] = v;

		for (k = 0; k < N; k++)
		{
			if (k == N - 1){
				printf("%d", A[k]);
			}
			else printf("%d ", A[k]);
		}
		printf("\n");

	}
	return 0;
}

Measured memory_bytes: 608
#include<iostream>
#include<cstdio>
using namespace std;
int n, x, ans;
int main(){
	scanf("%d", &n);
	while(n--){
		scanf("%d", &x);
		while(!(x & 1)){
			ans++;
			x >>= 1;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  vector<int> cord(5);
  rep(i, 5) cin >> cord[i];
  int k; cin >> k;

  int dist;
  for (int i = 0; i < 5; ++i){
    for (int j = i + 1; j < 5; ++j){
      dist = abs(cord[i] - cord[j]);
      if (dist > k) {cout << ":(" << endl; return 0;}
    }
  }
  cout << "Yay!" << endl;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

dp = [0]*N
dp[1] = abs(H[1]-H[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]), dp[i-2] + abs(H[i]-H[i-2]))

print(dp[-1])

Measured memory_bytes: 20524
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>

using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> grid;
    for (int i = 0; i < H; ++i)
    {
        string s;
        cin >> s;
        vector<char> v(W);
        for (int x = 0; x < W; ++x)
        {
            v[x] = *(s.c_str() + x);
        }
        grid.push_back(v);
    }

    for (int y = 0; y < H; ++y)
    {
        for (int x = 0; x < W; ++x)
        {
            if (grid[y][x] == '#')
            {
                continue;
            }
            int sum = 0;
            for (int dy = -1; dy <= 1; ++dy)
            {
                for (int dx = -1; dx <= 1; ++dx)
                {
                    auto xx = x + dx;
                    auto yy = y + dy;
                    if (0 <= xx && xx < W && 0 <= yy && yy < H)
                    {
                        if (grid[yy][xx] == '#')
                        {
                            ++sum;
                        }
                    }
                }
            }
            grid[y][x] = '0' + sum;
        }
    }

    for (int y = 0; y < H; ++y)
    {
        for (int x = 0; x < W; ++x)
        {
            cout << grid[y][x];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
    static boolean arr[];

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        long n = s.nextInt(),k=s.nextInt(),x=s.nextInt(),y=s.nextInt();
        long sum=0;
        if(n<=k) System.out.println(n*x);
        else{
            System.out.println((k*x)+((n-k)*y));
        }


    }


}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25416
#include <bits/stdc++.h>
using namespace std;
signed main(){
  string a,b,c,ans[3],AL="ABCDEFGHIJKLMNOPQRSTUVWXYZ",al="abcdefghijklmnopqrstuvwxyz";
  cin>>a;
  cin>>b;
  cin>>c;

  for(int i=0;i<26;i++){
    if(a[0] == al[i])
      ans[0] = AL[i];
    if(b[0] == al[i])
      ans[1] = AL[i];
    if(c[0] == al[i])
      ans[2] = AL[i];
  }

  for(int i=0;i<3;i++)
    cout<<ans[i];
  
  cout<<endl;
  return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n],b[n],sum[n];
  rep(i,n){
    cin>>a[i]>>b[i];
    sum[i]=a[i]+b[i];
  }
  sort(sum,sum+n);
  reverse(sum,sum+n);
  int ans=0;
  rep(i,n){
    if(i%2==0)ans+=sum[i];
    ans-=b[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = 0;
        int c = 0;	
        for(int i=0;i<a;i++){int d = sc.nextInt();
                             b+=d; 
                             c+=d*d;
                            }        	      
		System.out.println((b*b-c)/2);
	}
}


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

int main() {
    int N, K;
    long double p = 0;

    cin >> N >> K;

    int sum = 1, cnt = 0;
    while (sum < K) {
        sum *= 2;
        cnt++;
    }
    int num = 1, den = pow(2, cnt) * N;

    for (int i = 2; i <= N; i++) {
        int j = 0;
        sum = i;
        while (sum < K) {
            sum *= 2;
            j++;
        }

        num += pow(2, cnt - j);
    }

    p = ((long double)num / den);

    cout << fixed << setprecision(10) << p << endl;
    
    return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

llint gcd(llint a, llint b) {
    if (a<b) swap(a, b);

    if (a%b==0) return (b);
    else return(gcd(b, a%b));
}

llint lcm(llint a, llint b) {
    return (a/gcd(a, b)*b);
}

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

    llint t, ans = 1LL;
    for(int in=0;in<n;in++) {
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll n,W;
vector<ll> w,v;
ll dp[101][200001];

ll f(int i, int W){
	if(i==n){
		return 0;
	}
	if(dp[i][W] != -1){
		return dp[i][W];
	}
	if(w[i] <= W){
		dp[i][W] = max(dp[i][W],f(i+1,W-w[i])+v[i]);
	}
	dp[i][W] = max(dp[i][W],f(i+1,W));
	return dp[i][W];
}



int main(){
	cin>>n>>W;
	w.resize(n);
	v.resize(n);
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	cout<<f(0,W)<<endl;
}

Measured memory_bytes: 158080
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/25/20 20:57:10
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int MAX = 2e5;

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

  int n; cin>>n;
  auto dtoi = [](char u) {
    switch (u) {
      case 'L':
        return 0;
      case 'R':
        return 1;
      case 'U':
        return 2;
      case 'D':
        return 3;
      default:
        return 4;
    }
  };
  struct AP {
    int x,y;
    bool operator<(const AP& r) const {
      return x!=r.x ? x<r.x : y<r.y;
    }
    char d;
  };
  vector<AP> APs;
  map<int, set<AP>> apmap[4][4];
  for (int i = 0; i < n; i++) {
    int x,y; cin>>x>>y;
    char u; cin>>u;
    AP ap = {x,y,u};
    APs.push_back(ap);
    auto d = dtoi(u);
    apmap[0][d][y+x].insert(ap);
    apmap[1][d][y-x].insert(ap);
    if (d == 0 or d == 1) {
      apmap[3][d][y].insert(ap);
    } else {
      apmap[2][d][x].insert(ap);
    }
  }
  constexpr int INF = MAX*30;
  int ans = INF;
  for (const auto& ap:APs) {
    auto d = dtoi(ap.d);
    auto& map0 = apmap[0][((d^1)+2)%4][ap.y+ap.x];
    if (!map0.empty()) {
      if (d == 1 or d == 3) {
        auto it = map0.upper_bound(ap);
        if (it != map0.end()) {
          ans = min(ans, (it->x-ap.x)*10);
        }
      } else {
        auto it = map0.lower_bound(ap);
        if (it != map0.begin()) {
          it = prev(it);
          ans = min(ans, (ap.x-it->x)*10);
        }
      }
    }
    auto& map1 = apmap[1][((d)+2)%4][ap.y-ap.x];
    if (!map1.empty()) {
      if (d == 1 or d == 2) {
        auto it = map1.upper_bound(ap);
        if (it != map1.end()) {
          ans = min(ans, (it->x-ap.x)*10);
        }
      } else {
        auto it = map1.lower_bound(ap);
        if (it != map1.begin()) {
          it = prev(it);
          ans = min(ans, (ap.x-it->x)*10);
        }
      }
    }
    if (d == 2 or d == 3) {
      auto& mapx = apmap[2][d^1][ap.x];
      if (!mapx.empty()) {
        if (d == 3) {
          auto it = mapx.lower_bound(ap);
          if (it != mapx.begin()) {
            it = prev(it);
            ans = min(ans, (ap.y-it->y)*5);
          }
        } else {
          auto it = mapx.upper_bound(ap);
          if (it != mapx.end()) {
            ans = min(ans, (it->y-ap.y)*5);
          }
        }
      }
    } else {
      auto& mapy = apmap[3][d^1][ap.y];
      if (!mapy.empty()) {
        if (d == 0) {
          auto it = mapy.lower_bound(ap);
          if (it != mapy.begin()) {
            it = prev(it);
            ans = min(ans, (ap.x-it->x)*5);
          }
        } else {
          auto it = mapy.upper_bound(ap);
          if (it != mapy.end()) {
            ans = min(ans, (it->x-ap.x)*5);
          }
        }
      }
    }
  }
  if (ans == INF) {
    cout << "SAFE" << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 153944
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  ll ans = 0;
  rep(i, 0, n) {
    int a;
    cin >> a;
    ans += a;
  }

  cout << ans - n << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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,b,c;
  cin >> a >> b >> c;
  cout << (a*b/2) << endl;
}


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

const long long MAX = 510000;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    //input
    long long N,M;
    cin >> N >> M;
    
    //calc
    long long ans=0;
    long long val, sub;
    long long i;
    val = 1;
    val %= MOD;
    sub = fac[M]*finv[M-N];
    sub %= MOD;
    sub = sub*sub;
    sub %= MOD;
    val *= sub;
    val %= MOD;
    ans += val;
    ans %= MOD;
    for(i=1; i<=N-1; i++){
        val = fac[M]*finv[M-i];
        val %= MOD;
        sub = fac[M-i]*finv[M-N];
        sub %= MOD;
        sub = sub*sub;
        sub %= MOD;
        val *= sub;
        val %= MOD;
        val *= COM(N,i);
        val %= MOD;
        if(i%2==1){
            val = MOD - val;
        }
        ans += val;
        ans %= MOD;
    }
    val = fac[M]*finv[M-N];
    val %= MOD;
    if(N%2==1){
        val = MOD - val;
    }
    ans += val;
    ans %= MOD;
    
    //answer
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 15648
#include <iostream>
#include <cstdio>
using namespace std;
int main(){

  int i=0;
  double a[100000],max,min;

  while(scanf("%lf",&a[i]) != EOF ){
    i++;
  }
  
  max=a[0];
  min=a[0];

  for(int j=0 ; j < i ; j++){
    
    if( max < a[j] ){
      max=a[j];
    }
    if( min > a[j] ){
      min=a[j];
    }

  }

  printf("%.1f\n",max-min);

  return 0;

}

Measured memory_bytes: 1240
import Data.Maybe
import Data.Char
import Data.Word
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as C

parseInt :: C.ByteString -> Int
parseInt = fst . fromJust . C.readInt

suffixSums :: Int -> C.ByteString -> M.IntMap Int
suffixSums p s = snd $ C.foldr' acc ((1, 0), M.empty) s
  where
  acc c ((x, y), mp) = ((x', y'), M.alter f y' mp)
    where
    x' = 10 * x `mod` p
    y' = (x * digitToInt c + y) `mod` p
    f Nothing = Just 1
    f (Just cnt) = Just (cnt + 1)

fpm :: Int -> Int -> Int -> Int
fpm p a e
  | e == 0 = 1
  | otherwise = (if odd e then a * aa' else aa') `mod` p
  where
  aa = fpm p a $ e `div` 2
  aa' = aa * aa `mod` p

solve :: Int -> Int -> C.ByteString -> Word64
solve pp p s
  | n == 0 = 0
  | n == 1 = if parseInt s `mod` p == 0 then 1 else 0
  | otherwise = cnt + solve pp p x + solve pp p y
  where
  n = C.length s
  (x, y) = C.splitAt (n `div` 2) s
  mp = suffixSums p x
  cnt = snd $ C.foldl' acc ((0, 1), 0) y
  acc ((val, pow), total) c =
    let val' = (val * 10 + digitToInt c) `mod` p
        pow' = pow * pp `mod` p
        o = (p - val') * pow' `mod` p
    in ((val', pow'), total + (fromIntegral $ M.findWithDefault 0 o mp))

solve2 :: Int -> C.ByteString -> Word64
solve2 p s
  | n == 0 = 0
  | n == 1 = if parseInt s `mod` p == 0 then 1 else 0
  | otherwise = fromIntegral (cnt * n') + solve2 p x + solve2 p y
  where
  n = C.length s
  n' = n `div` 2
  (x, y) = C.splitAt n' s
  cnt = C.foldl' acc 0 y
  acc total c = if digitToInt c `mod` p == 0 then total + 1 else total

main :: IO ()
main = do
  [_, p] <- map parseInt . C.words <$> C.getLine
  s <- C.getLine
  let pp = fpm p 10 (p - 2)
  putStrLn $ show $ (if p == 2 || p == 5 then solve2 else solve pp) p s

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

int judge(int n){
    if(n == 1){
        return 1;
    }
    else if(1 < n && n < 4){
        return 2;
    }
    else if(4 <= n && n < 8){
        return 4;
    }
    else if(8 <= n && n < 16){
        return 8;
    }
    else if(16 <= n && n < 32){
        return 16;
    }
    else if(32 <= n && n < 64){
        return 32;
    }
    else{
        return 64;
    }
}

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

    int ans = judge(n);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

from itertools import product
from math import ceil

INF = 99999999999999999999999999

def main():
    d, g = map(int, input().split())
    pcs = []
    for i in range(d):
        p, c = map(int, input().split())
        pcs.append((p, c))
    comps = product((False, True), repeat=d)
    mi = INF
    for comp in comps:
        so = minimum_solution_g(d, g, pcs, comp)
        mi = min(mi, so)
    print(mi)

def minimum_solution_g(d, g, pcs, comp):
    score = 0
    used = 0
    avail = []
    for i in range(d):
        if comp[i]:
            score += pcs[i][1] + (i + 1) * 100 * pcs[i][0]
            used += pcs[i][0]
            avail.append(0)
        else:
            avail.append(pcs[i][0] - 1)
    for i in reversed(range(d)):
        if score >= g:
            break
        score_one = (i + 1) * 100
        use = min(avail[i], int(ceil((g - score) / score_one)))
        assert use >= 0
        used += use
        score += score_one * use
    if score >= g:
        return used
    else:
        return INF

main()




Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	Int N, M, Q;
	cin >> N >> M >> Q;

	vector<vector<Int>> x(N,vector<Int>(N));
	Int L, R;
	for (Int i = 0; i < M; i++) {
		cin >> L >> R;
		L--;
		R--;
		x[L][R]++;
	}

	////累積和
	//vector<vector<Int>> s(N+1, vector<Int>(N+1));
	//for (Int i = 0; i < N; i++) {
	//	for (Int j = 0; j < N; j++) {
	//		s[i][j + 1] = s[i][j] + x[i][j];
	//	}
	//}

	//二次元累積和
	vector<vector<Int>> s(N + 1, vector<Int>(N + 1));
	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < N; j++) {
			s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] + x[i][j] - s[i][j];
		}
	}

	//クエリ
	Int p, q;
	for (Int i = 0; i < Q; i++) {
		cin >> p >> q;
		p--;
		q--;

		/*Int ans = 0;
		for (Int j = p; j <= q; j++) {
			ans += s[j][q + 1] - s[j][p];
		}*/

		Int ans = s[q + 1][q + 1] - s[p][q + 1] - s[q + 1][p] + s[p][p];

		//cout << ans << "\n";
		printf("%lld\n", ans);
	}

}


Measured memory_bytes: 4864
#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 n;
  string s;
  cin >> s;
  cout << s[0] << (s.size()-2) << s[s.size()-1] <<endl;
    return 0;
}


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

using namespace std;

int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(a>b)
        cout<<0<<endl;
    else if(n==1&&a!=b)
        cout<<0<<endl;
    else if(n==1&&a==b)
        cout<<1<<endl;
    else
    cout <<b*(n-2)-a*(n-2)+1<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int x;
    cin>>x;
    for(int i=x;0<1;i++){
        int check=0;
        for(int j=2;j<i;j++)
            if(i%j==0)
                check=1;
        if(check==0){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll N;
    ll P, Pleast;
    ll ans = 0;

    cin >> N;

    cin >> Pleast;
    ans++;
    for(ll i = 1; i < N; i++){
        cin >> P;
        if(P <= Pleast){
            ans++;
            Pleast = P;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, d: "List[int]"):
    if N % 2 != 0: return 0

    d = sorted(d)
    midl = d[(1 + N) // 2 - 1]
    midr = d[(1 + N) // 2]

    if midl == midr: return 0

    return midr - midl


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    print(solve(N, d))

if __name__ == '__main__':
    main()


Measured memory_bytes: 15220
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n,m;cin>>n>>m;
    ll a=m/n;
    if(m%n==0){
        cout<<a<<endl;
        return 0;
    }
    else{
        for(int i=a;i>0;i--){
            if(m%i==0){
                cout<<i<<endl;
                return 0;
            }
        }
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    check = [[True]*n for i in range(n)]
    d =  [[min(i, n-i-1, j, n-j-1) for j in range(n)] for i in range(n)]

    ans = 0
    for t in l:
        t -=1
        x = t//n
        y = t%n
        check[x][y] = False
        ans += d[x][y]
        q = []
        q.append([x,y,d[x][y]])
        while q:
            bx,by,z = q.pop()

            if bx != 0:
                if d[bx-1][by] > z:
                    d[bx-1][by] = z
                    q.append([bx-1,by,z+check[bx-1][by]])
            if bx != n-1:
                if d[bx+1][by] > z:
                    d[bx+1][by] = z
                    q.append([bx+1,by,z+check[bx+1][by]])
            if by != 0:
                if d[bx][by-1] > z:
                    d[bx][by-1] = z
                    q.append([bx,by-1,z+check[bx][by-1]])
            if by != n-1:
                if d[bx][by+1] > z:
                    d[bx][by+1] = z
                    q.append([bx,by+1,z+check[bx][by+1]])  
    print(ans)
if __name__ =="__main__":
    main()

Measured memory_bytes: 185620
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    int A[N];
    for(int i=0; i<N; i++) cin >> A[i];
    
    deque<int> l;
    for(int i=0; i<N; i++){
        if(l.empty()){
            l.push_front(A[i]);
            continue;
        }

        auto it = lower_bound(l.begin(), l.end(), A[i]);
        if(it == l.begin())l.push_front(A[i]);
        else{
            *(--it) = A[i];
        }
    }
    cout << l.size() << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> botan(N);
  for (int i=0;i<N;i++){
   int red =0;
    cin >> red;
     botan.at(i) = red;
  }
  int hikari=1;
  int count =0;
   while (hikari !=2 && count != N ){
     hikari = botan.at(hikari-1);
     count++;
   }
  
  if(hikari==2){ cout << count << endl;}
  else{ cout << "-1" << endl;  }
  
}

Measured memory_bytes: 640
X,K,D = map(int,input().split())
X = abs(X)
a = 0

a = X//D
if a <= K:
    K -= a
else:
    a = K
    K = 0

X -= D*a
    
if K == 0:
    print(X)
else:
    if X == 0:
        if K % 2 == 0:
            print(X)
        else:
            print(D)
    elif X > 0:
        if abs(X-D) < abs(X):
            X -= D
            K -= 1
        if K % 2 == 0:
            print(abs(X))
        else:
            print(min(abs(X-D),abs(X+D)))
    elif X < 0:
        if abs(X+D) < abs(X):
            X += D
            K -= 1
        if K % 2 == 0:
            print(abs(X))
        else:
            print(min(abs(X-D),abs(X+D)))

Measured memory_bytes: 9212
#include <iostream>
#include <map>
#define endl '\n'
using namespace std;

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

    map<string, int> sTable;
    map<string, int>::iterator iter;
	int N, ans = 0;
	string s;
	cin >> N;
	//int *s = new int[N];
	for(int i = 0; i<N; i++) {
        cin >> s;
        iter = sTable.find(s);
        sTable[s] = 1;
        if(iter == sTable.end())
           ans++;
	}
	cout << ans;



    return 0;
}



Measured memory_bytes: 19284
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <map>
#include <iomanip>
using namespace std;

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

    for (int i = 0; i < N; i++) {
        cout << "ACL" ;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3636
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

      
n,m = map(int,input().split())
a_b_list = []
for i in range(m):
  a_b_list.append(list(map(int,input().split())))
  
count = 0
for i in range(m):
  a_b_copy = a_b_list.copy()
  uf = UnionFind(n)
  a_b_copy.pop(i)
  for a_b in a_b_copy:
    uf.union(a_b[0]-1,a_b[1]-1)
  if uf.group_count() != 1:
    count+= 1
print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    ll idx_a, idx_z;
    for(ll i=0; i<s.size(); i++) if(s[i] == 'A'){ idx_a = i; break;}
    for(ll i=s.size()-1; i>=0; i--) if(s[i] == 'Z'){ idx_z = i; break;}
    cout << idx_z - idx_a + 1 << endl;
}

Measured memory_bytes: 720
/* 
   AOJ 2155
   Infected Computer
*/

#include<stdio.h>
#include<stdlib.h>

#define PACKETS_MAX 20001
#define COMPUTERS_MAX 20001
#define TIME_MAX 1000000000

struct log
{
  int time, source, dest;
};

struct log log_set[PACKETS_MAX];
int computers[COMPUTERS_MAX];

int comp(const void *a, const void *b)
{
  struct log *x = (struct log*)a;
  struct log *y = (struct log*)b;

  return x->time - y->time;
}

int main(void)
{
  int i, computers_num, packetes_num, infected_computers_num = 0;

  while(1)
    {
      scanf("%d %d", &computers_num, &packetes_num);
      if(computers_num == 0 && packetes_num == 0)
	{
	  break;
	}

      computers[1] = 1;
      for(i = 2; i <= computers_num; i++)
	{
	  computers[i] = 0;
	}

      for(i = 0; i < packetes_num; i++)
	{
	  scanf("%d %d %d", &log_set[i].time, &log_set[i].source, &log_set[i].dest);
	}

      qsort(log_set, packetes_num, sizeof(struct log), comp);
      
      for(i = 0; i < packetes_num; i++)
      	{
      	  if(computers[log_set[i].source])
      	    {
      	      computers[log_set[i].dest] = 1;
      	    }
      	}
      for(i = 1; i <= computers_num; i++)
	{
	  if(computers[i])
	    {
	      infected_computers_num++;
	    }
	}
      printf("%d\n", infected_computers_num);
      infected_computers_num = 0;
    }
  return 0;
}

Measured memory_bytes: 1192
N=int(input())
list1=[]
for i in range(N-1):
    A=input()
    A=A.rstrip().split(" ")
    list1.append([int(A[0]),int(A[1]),int(A[2])])
#print(list1)

t=0
for k in range(N-1):
    for j in range(N-1-k):
        if t<list1[j+k][1]:
            t=list1[j+k][1]
        if (t-list1[j+k][1])%list1[j+k][2]==0:
            pass
        else:
            t+=list1[j+k][2]-(t-list1[j+k][1])%list1[j+k][2]
        t+=list1[j+k][0]
    print(t)
    t=0
print(0)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    size_t n=G.size();
    vector<T> d(n, INF<T>);
    priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
    d[s]=0;
    Q.emplace(0,s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    vector<vector<edge<ll>>> G(n);
    ll ans = 0;
    for (int i = 0; i < m; ++i) {
        int a, b; ll x;
        scanf("%d %d %lld", &a, &b, &x);
        G[a-1].emplace_back(b-1, x);
        G[b-1].emplace_back(a-1, x);
        ans += x;
    }
    ll S = ans;
    auto dist = dijkstra(0, G);
    vector<pair<ll, int>> v(n);
    for (int i = 0; i < n; ++i) {
        v[i] = {dist[i], i};
    }
    sort(v.begin(),v.end());
    vector<int> no(n);
    for (int i = 0; i < n; ++i) {
        no[v[i].second] = i;
    }
    for (int itr = 0; itr < n; ++itr) {
        int i = v[itr].second;
        for (auto &&e : G[i]) {
            if(no[e.to] < itr){
                S -= e.cost;
            }
        }
        ans = min(ans, S + v[itr].first*c);
    }
    cout << ans << "\n";
    return 0;
}


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

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

    vector<vector<int>> s(H, vector<int>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            char c;
            cin >> c;
            if (c == '#')
                s[i][j] = 1;
            else
                s[i][j] = 0;
        }
    }

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

    int isolated = 0;
    
    for (int h = 0; h < H; h++)
    {
        for (int w = 0; w < W; w++)
        {
            if(s[h][w] == 1){
                int neighbor = 0;
                for(int i = 0; i < 4; i++){
                    int hi = h + dy[i];
                    int wi = w + dx[i];

                    if(hi <0 || hi >= H || wi < 0 || wi >= W) continue;
                    
                    if(s[hi][wi] == 1) neighbor++;
                }

                if(neighbor == 0) isolated++;
            }
        }
    }

    if(isolated == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007

bool dbgflag = true;

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

  int N, M, Q;
  cin >> N >> M >> Q;

  vector<vector<int>>trains(N+1, vector<int>(N+1, 0));
  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    trains[l][r]++;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      trains[i][j] += trains[i-1][j] + trains[i][j-1] - trains[i-1][j-1];
    }
  }

  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;
    cout << trains[q][q] - trains[p-1][q] - trains[q][p-1] + trains[p-1][p-1] << endl;
  }
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int left=s.size();
	while(left>0){
		if(left>6 && s.substr(left-7,7)=="dreamer")
			left-=7;
		else if(left>5 && s.substr(left-6,6)=="eraser")
			left-=6;
		else if(left>4 && (s.substr(left-5,5)=="dream" || s.substr(left-5,5)=="erase"))
			left-=5;
		else
			break;
	}
	if(left==0)
		cout<<"YES";
	else
		cout<<"NO";
}


Measured memory_bytes: 512
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{try {
	    
	
	    Scanner k=new Scanner(System.in);
		int n=k.nextInt();int kg=0;
		BigInteger f=new BigInteger("1");	
		BigInteger ff=new BigInteger("1000000000000000000");
		long ar[]=new long[n];
		for(int i=0;i<n;i++)
		{
		    ar[i]=k.nextLong();
		    
		}
		for(int i=0;i<n;i++)
		{
		    if(ar[i]==0)
		    {
		        System.out.print(0);kg=99;
		        break;
		    }}
		    if(kg==0)
		  {  for(int i=0;i<n;i++)
		{
		    f=f.multiply(BigInteger.valueOf(ar[i]));
		    if(f.compareTo(ff)==1 && kg==0)
		{
		    System.out.print("-1");kg=99;
		break;}
		}
		if(kg==0)
			System.out.print(f);}}
			catch(Exception e) {
	return;}
	}}
	



Measured memory_bytes: 62132
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;

void main(){
    int n = readln.chomp.to!int;
    auto a = readln.split.to!(int[]);

    int amax = -1, amin = 2000;

    foreach(ai; a){
        amax = max(amax, ai);
        amin = min(amin, ai);
    }

    auto ans = amax - amin;

    writeln(ans);
}


void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int s , H , J , I ;
    cin >> s ;
    H = s / 100;
    J = (s - H * 100) / 10;
    I = s - H * 100 - J * 10;
  cout << H + J + I << endl;
}

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



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

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

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;

template<class T> bool ckmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template <typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template <typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template <class X, class Y>
std::ostream & operator << (std::ostream & os, std::pair <X, Y> const& p) {
    return os << p.first << " " << p.second;
}

template <class Ch, class Tr, class Container>
std::basic_ostream <Ch, Tr> & operator << (std::basic_ostream <Ch, Tr>& os, Container const& x) {
    bool first = true;
    for(auto& y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class CSubarraySum {

    static const int INF = 1'000'000'000;

public:
	void solve(std::istream& in, std::ostream& out) {
        int n, k, s;
        in >> n >> k >> s;
        vi res(n, s);
        fill(k + all(res), s == INF ? INF - 1 : INF);
        out << res << '\n';
	}

	void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
	CSubarraySum solver;
    solver.setup();
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}

int main() {
    int x[MAX_N] = {}, y[MAX_N] = {};
    int n, q;
    scanf("%d%d", &n,&q);
    ll ans = (ll)(n-2)*(n-2);
    srep(i,2,n){
        x[i] = n;
        y[i] = n;
    }
    int xx = n;
    int yy = n;
    while(q--){
        int t, z;
        // scanf("%d%d", &t,&z);
        read(t), read(z);
        if(t == 1){
            if(z < xx){
                ans -= yy - 2;
                srep(i,z+1,xx) x[i] = yy;
                xx = z;
            }else{
                ans -= x[z] - 2;
            }
        }else{
            if(z < yy){
                ans -= xx - 2;
                srep(i,z+1,yy) y[i] = xx;
                yy = z;
            }else{
                ans -= y[z] - 2;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}




Measured memory_bytes: 5356
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    vector<int> b;
    int n;
};

template <class F>
int lower_bound(int i0, int i1, F f) {
    while (i0 < i1) {
        int i = (i0 + i1) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

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

    int n;
    cin >> n;

    vector<int> q(n);
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        p--;
        q[p] = i;
    }

    ll r = 0;
    BIT bt(n);
    for (int i = n - 1; i >= 0; i--) {
        int j = q[i];

        int jl = lower_bound(0, j, [&](int j1) {
            return bt.sum(j) - bt.sum(j1) <= 0;
        });
        jl--;
        int jl2 = lower_bound(0, j, [&](int j1) {
            return bt.sum(j) - bt.sum(j1) <= 1;
        });
        jl2--;
        int jr = lower_bound(j + 1, n, [&](int j1) {
            return bt.sum(j1 + 1) - bt.sum(j + 1) > 0;
        });
        int jr2 = lower_bound(j + 1, n, [&](int j1) {
            return bt.sum(j1 + 1) - bt.sum(j + 1) > 1;
        });
        if (jl >= 0 || jr < n) {
            if (jr < n) r += (ll)(i + 0) * (jl >= 0 ? j - jl : j + 1) * (jr2 - jr);
            //cout << i + 1 << ' ' << (n - jr) << endl;
            if (jl >= 0) r += (ll)(i + 0) * (jr < n ? jr - j : n - j) * (jl - jl2);
            //cout << i+1 << ' ' << r << endl;
        }
        bt.add(j, 1);
    }

    r += (ll)n * (n - 1) / 2;
    cout << r << endl;

    return 0;
}

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

 using namespace std;
 typedef long long ll;

 int main() {
   int K, T;
   cin >> K >> T;

   vector<int> a(T);

   int max_T = 0, sum = 0;

   for (int i = 0; i < T; i++) {
     cin >> a.at(i);
     max_T = max(max_T, a.at(i));
     sum += a.at(i);
   }
   cout << max(0, 2 * max_T - sum - 1) << endl;
 }


Measured memory_bytes: 256
S = input()
T = input()
m, n = len(S), len(T)
C = [[0 for j in range(n+1)] for i in range(m+1)]
for i in range(m):
    for j in range(n):
        if S[i] == T[j]:
            C[i+1][j+1] = C[i][j] + 1
        else:
            C[i+1][j+1] = max(C[i][j+1], C[i+1][j])
l = C[m][n]
X = ''
while l:
    if S[m-1] == T[n-1]:
        X = S[m-1]+X
        m -= 1
        n -= 1
        l -= 1
    elif C[m][n] == C[m-1][n]:
        m -= 1
    else:
        n -= 1
print(X)


Measured memory_bytes: 119772
#include <stdio.h>
#include <stdlib.h>

#define SENTINEL (1000000001)

int count = 0;
int S[500000];
int L[500000];
int R[500000];

static void Merge(int A[], int left, int mid, int right);
static void MergeSort(int A[], int left, int right);

int main(void) {
	int i;
	int n;
	
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", &S[i]);
	}
	
	MergeSort(S, 0, n);
	
	for (i = 0; i < n; ++i) {
		if (i > 0) {
			putchar(' ');
		}
		printf("%d", S[i]);
	}
	putchar('\n');
	
	printf("%d\n", count);

	return 0;
}

void Merge(int A[], int left, int mid, int right) {
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	memcpy(L, A + left, n1 * sizeof(int));
	memcpy(R, A + mid, n2 * sizeof(int));
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for (k = left; k < right; ++k) {
		++count;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			++i;
		} else {
			A[k] = R[j];
			++j;
		}
	}
}

void MergeSort(int A[], int left, int right) {
	int mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		MergeSort(A, left, mid);
		MergeSort(A, mid, right);
		Merge(A, left, mid, right);
	}
}

Measured memory_bytes: 5504
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0577().doIt();
	}

	class AOJ0577{
		void doIt() {
			int n = in.nextInt();
			HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
			int[][] hyou = new int[n][3];
			for(int i=0;i<n;i++){
				hyou[i][0] = in.nextInt();
				hyou[i][1] = in.nextInt();
				hyou[i][2] = in.nextInt();
			}
			int[] result = new int[n];
			for(int i=0;i<3;i++){
				map = new HashMap<Integer, Integer>();
				for(int s=0;s<n;s++){
					if(!map.containsKey(hyou[s][i]))map.put(hyou[s][i], 0);
					map.put(hyou[s][i],map.get(hyou[s][i])+1);
				}
				for(int s=0;s<n;s++)if(map.get(hyou[s][i])==1)result[s]+=hyou[s][i];
			}
			for(int i=0;i<n;i++)System.out.println(result[i]);
		}

	}
}

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

typedef long long ll;

int main(void)
{
    int n;
    cin >> n;
    vector<tuple<string, int, int> > A;
    for(int i = 1; i <= n; ++i)
    {
        string s; cin >> s;
        int p; cin >> p;
        p *= -1;
        A.push_back(tie(s, p, i));
    }
    sort(A.begin(), A.end());
    rep(i, n)
    {
        cout << get<2>(A[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 256