akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#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()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  string s;
  while (cin >> s) {
    int c = 1;
    VI a;
    REP(i, s.size() - 1) {
      if (s[i + 1] == s[i])
        ++c;
      else {
        if (s[i] == 'I')
          a.push_back(1 * c);
        else if (s[i] == 'V')
          a.push_back(5 * c);
        else if (s[i] == 'X')
          a.push_back(10 * c);
        else if (s[i] == 'L')
          a.push_back(50 * c);
        else if (s[i] == 'C')
          a.push_back(100 * c);
        else if (s[i] == 'D')
          a.push_back(500 * c);
        else if (s[i] == 'M')
          a.push_back(1000 * c);
        c = 1;
      }
    }
    if (s[s.size() - 1] == 'I')
      a.push_back(1 * c);
    else if (s[s.size() - 1] == 'V')
      a.push_back(5 * c);
    else if (s[s.size() - 1] == 'X')
      a.push_back(10 * c);
    else if (s[s.size() - 1] == 'L')
      a.push_back(50 * c);
    else if (s[s.size() - 1] == 'C')
      a.push_back(100 * c);
    else if (s[s.size() - 1] == 'D')
      a.push_back(500 * c);
    else if (s[s.size() - 1] == 'M')
      a.push_back(1000 * c);

    // for(int i: a) cout << i << " "; cout << endl;
    REP(i, a.size() - 1) {
      if (a[i] < a[i + 1]) {
        a[i + 1] -= a[i];
        a[i] = 0;
      }
      // for(int i: a) cout << i << " "; cout << endl;
    }
    int ret = 0;
    for (int i : a) {
      ret += i;
    }
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	int n;
	cin >> n;
	string s;
	cin >> s;
	stack<char> st;
	for(int i = 0; i < n; i++){
		while(!st.empty() && st.top()==s[i])
			st.pop();
		st.push(s[i]);
	}

	cout << st.size() << endl;

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 512
def main():
    H, W, K = map(int, input().split())
    u = [1] + [0] * (W - 1)
    mod = 10**9 + 7
    def cw(n):
        if n == 0:
            return 0
        if n == 1:
            return 2
        return cw(n - 2) + cw(n - 1) 
    CW = [1, 2, 3, 5, 8, 13, 21, 34, 55, 1, 1, 1]

    for _ in range(H):
        v = [0] * W
        for w in range(W):
            t = 0
            if w >= 1:
                t += u[w - 1] * CW[w - 2] * CW[W - w - 2]
            t += u[w] *     CW[w - 1] * CW[W - w - 2]
            if w < W - 1:
                t += u[w + 1] * CW[w - 1] * CW[W - w - 3]
            v[w] = t % mod
        u = v
    print(u[K - 1])

main()


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

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



Measured memory_bytes: 3120
S = input()
OK = False
if S=='KIHBR':
    OK = True
elif S=='KIHBRA':
    OK = True
elif S=='KIHBAR':
    OK = True
elif S=='KIHBARA':
    OK = True
elif S=='KIHABR':
    OK = True
elif S=='KIHABRA':
    OK = True
elif S=='KIHABAR':
    OK = True
elif S=='KIHABARA':
    OK = True
elif S=='AKIHBR':
    OK = True
elif S=='AKIHBRA':
    OK = True
elif S=='AKIHBAR':
    OK = True
elif S=='AKIHBARA':
    OK = True
elif S=='AKIHABR':
    OK = True
elif S=='AKIHABRA':
    OK = True
elif S=='AKIHABAR':
    OK = True
elif S=='AKIHABARA':
    OK = True
print('YES' if OK else 'NO')


Measured memory_bytes: 38256
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

#define ll long long

const ll mod = (ll)1e9 + 7;

using namespace std;

signed main() {
	string s, t;
	cin >> s >> t;

	int ans = 0;
	for (int i = 0; i < 3; ++i)
		ans += (s[i] == t[i]) ? 1 : 0;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}

const int maxn = 5e4 + 5;
const int mod = 7;

int a[8];
char s[10];

int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << a[2] * 10 + a[1] + a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

a, b = [int(i) for i in input().split()]

tmp = 0
res = 0

res = a * b

print(res)


Measured memory_bytes: 31064
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	string s; cin >> s;
	replace(s.begin(), s.end(), ',', ' ');
	cout << s << endl;
}

Measured memory_bytes: 764
#include <iostream>
#define REP(i, a, n) for(int i = (a); i <= (n); i++)
using namespace std;

int N, M, R, RT[1001], RN[1001], RM[1001], RS[1001], Q, p[1261], q[1001];

int main(void) {
  while(cin >> N >> M, N || M) {
    cin >> R;
    REP(i, 1, R) cin >> RT[i] >> RN[i] >> RM[i] >> RS[i];
    cin >> Q;
    REP(i, 1, Q) {
      int ts, te, m; cin >> ts >> te >> m;
      REP(j, 1, 1260) p[j] = 0;
      REP(j, 1, R) {
        if(RM[j] != m) continue;
        if(RS[j] == 1) q[RN[j]] = RT[j];
        if(RS[j] == 0) REP(k, q[RN[j]], RT[j] - 1) p[k] = 1;
      }
      int u = 0;
      REP(j, ts, te - 1) if(p[j]) u++;
      cout << u << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    unordered_set<int> us;
    rep(i,4){
        us.insert(s[i]);
    }
    if(us.size() == 2 && count(s.begin(), s.end(), s[0]) == 2){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		//入力A
		int a = sc.nextInt();

		//入力B
		int b = sc.nextInt();

		if (a >= 10 || b >= 10) {

			System.out.println("-1");

		} else {
			System.out.println(a * b);

		}

	}

}


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

int main(){
    int n, k;
    cin >> n >> k;
    int d[k];
    rep(i, k){
        cin >> d[i];
    }

    for (int i = n; i < 1000000; i++){
        int ii = i;
        bool flag = true;
        while(ii>0 && flag){
            int ama = ii%10;
            for (int j = 0; j < k; j++)
            {
                if(ama==d[j]){
                    flag = false;
                    break;
                }
            }
            ii /=10;
        }
        if(flag){
            cout << i << endl;
            return 0;
        }
    }
    

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	double a, b, h, m, ax, bx, ay, by, pi = 3.141592653589793238;
	cin >> a >> b >> h >> m;
	ax = a * cos((-90 + h * 30 + m * 0.5) * pi / 180);
	ay = a * sin((-90 + h * 30 + m * 0.5) * pi / 180);
	bx = b * cos((-90 + m * 6) * pi / 180);
	by = b * sin((-90 + m * 6) * pi / 180);
	cout << fixed << setprecision(20) << sqrt(pow(ax - bx, 2) + pow(ay - by, 2)) << endl;
	return 0;
}


Measured memory_bytes: 4164
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

    if(1+2*(k-1)<=n) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    dp[i] = min((dp[i - 2] + abs(h[i - 2] - h[i])), (dp[i - 1] + abs(h[i - 1] - h[i])))
print(dp[-1])


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

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
typedef pair<int,int> P;
P f(int a,int b){
  if(a<b)swap(a,b);
  return P(a,b);
}

signed main(){
  int n;cin>>n;
  vector<int> a(n),b(n);
  for(int i=0;i<n-1;i++)cin>>a[i]>>b[i];
  map<P,int> m;
  vector<int> edge[n];
  for(int i=0;i<n-1;i++){
    edge[--a[i]].push_back(--b[i]);
    edge[b[i]].push_back(a[i]);
  }
  int r=0;
  for(int i=0;i<n;i++)if(edge[i].size()==1)r=i;
  queue<int> que;
  que.push(edge[r][0]);
  m[f(r,edge[r][0])]=1;
  while(que.size()){
    int p=que.front();que.pop();
    set<int> s;
    for(int q:edge[p]){
      if(m.count(f(p,q)))s.insert(m[f(p,q)]);
    }
    int now=1;
    for(int q:edge[p]){
      if(m.count(f(p,q)))continue;
      while(s.count(now))now++;
      m[f(p,q)]=now++;
      que.push(q);
    }
  }
  int k=0;
  for(int i=0;i<n-1;i++)chmax(k,m[f(a[i],b[i])]);
  cout<<k<<endl;
  for(int i=0;i<n-1;i++)cout<<m[f(a[i],b[i])]<<endl;
}


Measured memory_bytes: 13056
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const ll P = 1e9+7;

int main(){
	string S;
	cin >> S;
	int N = S.size();

	vector<ll> n_all(N+1), n_a(N+1), n_ab(N+1), n_abc(N+1);
	n_all[0] = 1;
	for(int i=0; i<N; i++){
		n_all[i+1] = n_all[i];
		n_a[i+1] = n_a[i];
		n_ab[i+1] = n_ab[i];
		n_abc[i+1] = n_abc[i];
		if(S[i]=='A'){
			n_a[i+1] += n_all[i];
		} else if(S[i]=='B'){
			n_ab[i+1] += n_a[i];
		} else if(S[i]=='C'){
			n_abc[i+1] += n_ab[i];
		} else if(S[i]=='?'){
			n_all[i+1] = 3*n_all[i];
			n_a[i+1] = 3*n_a[i]+n_all[i];
			n_ab[i+1] = 3*n_ab[i]+n_a[i];
			n_abc[i+1] = 3*n_abc[i]+n_ab[i];
		}
		n_all[i+1] %= P;
		n_a[i+1] %= P;
		n_ab[i+1] %= P;
		n_abc[i+1] %= P;
		//cout << S[i] << " " << n_all[i+1] << " " << n_a[i+1] << " " << n_ab[i+1] << " " << n_abc[i+1] << endl;
	}

	cout << n_abc[N] << endl;

	return 0;
}


Measured memory_bytes: 3584
// Apna Time Aayega...
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define ll long long
#define inf 100000000000000000
int addMod(int x, int y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

int mulMod(int x, int y)
{
    return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
    int z = 1;
    while(y)
    {
        if(y & 1) z = mulMod(z, x);
        x = mulMod(x, x);
        y >>= 1;
    }
    return z;
}

int inv(int x)
{
    return binpow(x, MOD - 2);
}

int divide(int x, int y)
{
    return mulMod(x, inv(y));
}

ll gcd(int a, int b) 
{   if (a == 0) return b; 
    if (b == 0) return a;  
    if (a == b) return a; 
    if (a > b)  return gcd(a-b, b); 
    return gcd(a, b-a); 
} 

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

ll h(ll* A, int N){
    ll pro = 1;
    for(int i=0; i<N; ++i) pro = mulMod(A[i], pro);
    return pro;
}

ll f(ll* A, int N){
    int alpha = A[0];
    for(int i=1; i<N; ++i){
        alpha = gcd(alpha, A[i])%MOD;
    }
    return alpha;
}

void generateNormal(string ans, int N, int charUsed){
    if(N==0) {cout<<ans<<endl; return;}
    for(int i=0; i<charUsed+1; ++i){
        char currentChar = 'a' + i;
        generateNormal(ans+currentChar, N-1, i+1);
    }
    return;
}
int N, X;
int A[100005];
vector <int> adj[100005];
int dfs(int u, int p){
    int sum = A[u];
    for(auto &i:adj[u]){
        if(i!=p){
            sum += dfs(i, u);
        }
    }
    return max(sum, -X);
}

void cl()
{
    for(int i=1;i<=N;i++)
        adj[i].clear();
}

unsigned long long int counting(int a, int b){
    unsigned long long int count = 1;
    while(a>0 || b>0){
        if(a&1 && b&1){
            count = mulMod(2, count);
        }
        a = a>>1;
        b = b>>1;
    }
    return count;
}

int main(){
    FIO
    int i; cin>>i;
    int x = (i/500);
    x = x*1000;
    i = i%500;
    x = x + (i/5)*5;
    cout<<x<<endl;
}


Measured memory_bytes: 2560
n = STDIN.gets.chomp.to_i
a = STDIN.gets.chomp.split.collect do |e| e.to_i end
h = Hash.new

a.each do |e|
  if h.include?(e)
    h[e] += 1
  else
    h[e] = 1
  end
end

keys = h.keys.sort {|x, y| y <=> x }

x = -1
y = -1

keys.each do |k|
  if x != -1 && y != -1
    break
  end

  if (x == -1 && h[k] >= 2)
    x = k
    h[k] -= 2
  end

  if (x != -1 && y == -1 && h[k] >= 2)
    y = k
    h[k] -= 2
  end
end

if (x == -1 || y == -1)
  puts 0
else
  puts x * y
end


Measured memory_bytes: 18312
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [Int] -> Int
solve n as = snd . foldl' go (IM.empty, 0) $ zip [1..] as where
    
    go (waMap, total) (index, height) = let
        diff = index - height
        !newAns = IM.findWithDefault 0 diff waMap
        !newMap = IM.alter (Just . maybe 1 (+1)) (index + height) waMap
        in
        (newMap, total + newAns)

main :: IO ()
main = do
    n <- readInt
    as <- readInts
    print $ solve n as


Measured memory_bytes: 33864
#include<iostream>
#include<vector>
#include<stdio.h>

const static int MAX = 6;
int A[MAX][MAX], B[MAX][MAX];
int h, w, k, cnt, ans;
std::vector<int> bit;

int bit_search(int a, int m){
    if(a == m){
	for(int i = 0; i < h; i++){
	    for(int j = 0; j < w; j++){
		B[i][j] = A[i][j];
	    }
	}
	int cnt = 0;

	for(int i = 0; i < h; i++){
	    if(bit[i] == 1){
		for(int j = 0; j < w; j++){
		    B[i][j] = 0;
	    	}
	    }
	}
	for(int i = h; i < h + w; i++){
	    if(bit[i] == 1){
		for(int j = 0; j < h; j++){
		    B[j][i-h] = 0;
	    	}
	    }
	}

	for(int i = 0; i < h; i++){
	    for(int j = 0; j < w; j++){
		if(B[i][j] == 1) cnt++;
	    }
	}
	if(cnt == k) ans++;

	return 0;
    }
    bit_search(a+1, m);
    bit[a] = 1;
    bit_search(a+1, m);
    bit[a] = 0;
    return 0; 
}

int main(void){

    std::cin >> h >> w >> k;
    std::vector<std::string> str(h);
    bit.resize(h + w);
    ans = 0;

    for(int i = 0; i < h; i++){
	std::cin >> str[i];
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
	    if(str[i][j] == '#'){
		A[i][j] = 1;
	    }
        }
    }


    bit_search(0, h + w);
    std::cout << ans << std::endl;
    
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cstdlib>
#include <typeinfo>


using namespace std;

const int INF = -1;

typedef pair<int, int> P;

const int MAX_H = 1000;
const int MAX_W = 1000;
char field[MAX_H][MAX_W + 1];
int d[MAX_H][MAX_W];
int H, W, N;
int sx, sy;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int bfs(){
  int time = 0;
  for (int i = 1; i <= N; i++) {
    queue<P> que;
    que.push(P(sx, sy));

    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) d[i][j] = INF;
    d[sx][sy] = 0;

    while (que.size()){
      P p = que.front();
      que.pop();

      if (field[p.first][p.second]-'0' == i) {
        time += d[p.first][p.second];
        sx = p.first;
        sy = p.second;
        break;
      }

      for (int i = 0; i < 4; i++) {
        int nx = p.first + dx[i], ny = p.second + dy[i];

        if(0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] != 'X'&& d[nx][ny] == INF){
          que.push(P(nx, ny));
          d[nx][ny] = d[p.first][p.second] + 1;
          }
        }
      }
  }
  return time;
}


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

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
      if (field[i][j] == 'S'){
        sx = i;
        sy = j;
      }
    }
  }

  cout << bfs() << endl;
}

Measured memory_bytes: 8012
class Vector
  attr_accessor :x, :y
  
  def initialize(x = 0, y = 0)
    @x = x
    @y = y
  end

  def cross(v)
    return (@x * v.y - @y * v.x)
  end

  def -(v)
    return Vector.new(@x - v.x, @y - v.y)
  end
end

class Line
  attr_accessor :a, :b

  def initialize(a, b)
    @a = a
    @b = b
  end

  def intersect?(l)
    if (b - a).cross(l.a - a) * (b - a).cross(l.b - a) < 0 &&
      (l.b - l.a).cross(a - l.a) * (l.b - l.a).cross(b - l.a) < 0
      return true
    end
  end
end

if __FILE__ == $0
  while line = gets
    xa, ya, xb, yb, xc, yc, xd, yd = line.split(',').map{|i| i.to_f}
    a = Vector.new(xa, ya)
    b = Vector.new(xb, yb)
    c = Vector.new(xc, yc)
    d = Vector.new(xd, yd)

    ac = Line.new(a, c)
    bd = Line.new(b, d)

    if ac.intersect?(bd)
      puts "YES"
    else
      puts "NO"
    end
  end
end

Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define b 1000000007
int main()
{
  int h, w;
  cin >> h >> w;
  char A[h][w];
  ll f[h][w];
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin >> A[i][j];
      f[i][j]=0;
    }
  }
  bool flag= false;
  for(int i=0; i<h; i++){
    if(A[i][0]!='#' && flag==false)
      f[i][0]=1;
    else
        flag=true;
  }
  flag= false;
  for(int j=0; j<w; j++){
    if(A[0][j]!='#' && flag==false)
      f[0][j]=1;
    else
      flag= true;
  }
  for(int i=1; i<h; i++){
    for(int j=1; j<w; j++){
      if(A[i][j]!='#'){
        f[i][j]= (f[i-1][j]+ f[i][j-1])%b;
      }
    }
  }

  cout << f[h-1][w-1] << endl;

  return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
long n,ans,M=1e7,i,j;
int main(){
  cin>>n;
  for(i=2;i<=min(n,M);i++){
    j=i;
    while(!(n%j))ans++,n/=j,j*=i;
    while(!(n%i))n/=i;
  }
  cout<<ans+(n>=M)<<endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
long long dp[401][401];

int main(){
    int N;
    cin >> N;
    int a[N + 1];
    a[0] = 0;
    dp[0][0] = 0;
    long long cumu[N + 1];
    cumu[0] = 0;
    for(int i = 1; i < N + 1; ++i){
        for(int j = i; j < N + 1; ++j){
            dp[i][j] = (long long) 1e20;
        }
    }
    for(int i = 1; i < N + 1; ++i){
        cin >> a[i];
        cumu[i] = cumu[i - 1] + a[i];
        dp[i][i] = 0;
    }
    for(int dif = 1; dif < N; ++dif){
        for(int i = 1; i < N - dif + 1; ++i){
            for(int mid = i; mid < i + dif; ++mid){
                dp[i][i + dif] = min(dp[i][i + dif], dp[i][mid] + dp[mid + 1][i + dif] + cumu[i + dif] - cumu[i - 1]);
            }
        }
    }
    cout << dp[1][N] << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define maxn 100005
#define ll long long
using namespace std;
struct Node{
  ll x,y;
}a[maxn];
int n,m;

bool cmp(Node a,Node b){
  return a.x < b.x;
}

int main()
{
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%lld%lld",&a[i].x,&a[i].y);
  }
  sort(a, a + n, cmp);
  ll ans = 0;
  int cnt = 0;
  for(int i=0;i<n;i++){
    if(cnt + a[i].y >= m){
      ans += ((m - cnt) * a[i].x);
      break;
    }
    else{
      ans += a[i].x * a[i].y;
      cnt += a[i].y;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

#define inf 1e18+5

int m_self(long long& a, long long b){
    a = std::min(a, b);
    return a;
}

int main(){
    int n, w;
    scanf("%d%d", &n, &w);
    
    std::vector<int>es_w(n), es_v(n);
     for(int i=0; i<n;i++){
         scanf("%d%d", &es_w[i], &es_v[i]);
     }
     long long v = std::accumulate(std::begin(es_v), std::end(es_v), 0);
     std::vector<long long>dp(v+1, inf);
     dp[0]=0;
     for(int i =0 ; i<n; i++){
         for(int al_v = v-es_v[i]; al_v>=0; al_v--){
             m_self(dp[al_v + es_v[i]], dp[al_v] + es_w[i]);
         }
     }
     long long a=0;
     for(long long i=0 ;i<=v; i++){
         if(dp[i]<=w){
             a = std::max(a ,i);
         }
     }
     printf("%d\n", a);
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
  ll n;string s;
  cin>>n>>s;
  ll a=0,b=0;
  for(int i=0;i<n;i++){
      if(s[i]=='R')a++;
      if(s[i]=='B')b++;
  }
  if(a>b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    return 0;
}



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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

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

    int n;
    cin>>n;
    vector<int> arr(n+1, 0);
    int x;
    for(int i=0;i<n-1;i++) {
        cin>>x;
        arr[x]++;
    }
    for(int i=1;i<=n;i++) {
        cout<<arr[i]<<"\n";
    }


    return 0;
}

Measured memory_bytes: 4768
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
signed main() {
	int n;
	cin >> n;
	cout <<48 - n << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
def main():
    S = list(input().rstrip())
    list1, list2 = [], []
    for i in range(len(S)):
        if i % 2 == 0:
            list1.append('1')
            list2.append('0')
        else:
            list1.append('0')
            list2.append('1')
    v1 = sum([1 for e, s in zip(list1, S) if e != s])
    v2 = sum([1 for e, s in zip(list2, S) if e != s])
    print(min([v1, v2]))


if __name__ == '__main__':
    main()


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			List<int>[] to = new List<int>[n];
			for (int i = 0; i < n; i++) {
				to[i] = new List<int>();
			}

			for (int i = 0; i < n - 1; i++) {
				int a = cin.Int() - 1;
				int b = cin.Int() - 1;
				to[a].Add(b);
				to[b].Add(a);
			}

			var bq = new Queue<int>();
			bq.Enqueue(0);
			var wq = new Queue<int>();
			wq.Enqueue(n - 1);

			var colors = new int[n];
			colors[0] = -1;
			colors[n - 1] = 1;
			while (bq.Count() > 0 || wq.Count() > 0) {
				var bb = bq.ToArray();
				bq.Clear();
				foreach (int b in bb) {
					foreach (int nextB in to[b]) {
						if (colors[nextB] == 0) {
							colors[nextB] = -1;
							bq.Enqueue(nextB);
						}
					}
				}

				var ww = wq.ToArray();
				wq.Clear();
				foreach (int w in ww) {
					foreach (int nextW in to[w]) {
						if (colors[nextW] == 0) {
							colors[nextW] = 1;
							wq.Enqueue(nextW);
						}
					}
				}
			}

			int wc = 0;
			int bc = 0;
			for (int i = 0; i < n; i++) {
				if (colors[i] == 1) {
					++wc;
				} else {
					++bc;
				}
			}

			if (bc > wc) {
				Console.WriteLine("Fennec");
			} else {
				Console.WriteLine("Snuke");
			}
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 29448
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

using P = pair<int, int>;

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

    vector<P> xi(N);
    vector<int> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
        x[i]--;

        xi[i] = {x[i], i + 1};
    }
    sort(xi.begin(), xi.end());

    static int num[510];

    vector<int> ans(N * N, -1);
    int idx = 0;

    cerr << "bbb" << endl;

    for (int i = 0; i < N; i++) {
        // xi[i].secondを見ようとしている
        int f = xi[i].first;
        int s = xi[i].second;

        while (idx < f and num[s] < s - 1) {
            if (ans[idx] < 0) {
                ans[idx] = s;
                num[s]++;
            }
            idx++;
        }
        if (num[s] != s - 1) {
            cout << "No" << endl;
            return 0;
        }
        ans[f] = s;
        num[s]++;
    }

    cerr << "aaa" << endl;
    cerr << num[1] << endl;

    for (int i = 0; i < N; i++) {
        int n = xi[i].second;
        while (idx < N * N and num[n] < N) {
            if (ans[idx] < 0) {
                ans[idx] = n;
                num[n]++;

                if (idx <= x[n - 1]) {
                    cerr << "n: " << n << endl;
                    cerr << "idx: " << idx << endl;
                    cout << "No" << endl;
                    return 0;
                }
            }
            idx++;
        }
    }

    cerr << "cccc" << endl;

    int sum = 0;
    for (int n = 1; n <= N; n++) sum += num[n];

    if (sum != N * N) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    for (int a : ans) {
        cout << a << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int front_num(int n)
{
    int ret;

    while (n)
	{
        ret = n % 10;
        n /= 10;
	}

	return ret;
}

int digit(int n)
{
	int ret = 0;

	while (n)
	{
		ret++;
		n /= 10;
	}

	return ret;
}

int a[10][10];

int main(void)
{
    int n, i, ans = 0;

    scanf("%d" ,&n);

    for (i = 1; i <= n; i++)
    {
		int first = front_num(i), last = i % 10;

		a[first][last]++;
    }

    for (i = 1; i <= n; i++)
	{
		int first = front_num(i), last = i % 10;

		ans += a[last][first];
	}

	printf("%d" ,ans);
	return 0;
}

Measured memory_bytes: 128
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll a, inf = 1e18;
vec<ll> m, ps;
vec<vec<ll>> dp;

ll rec(ll l, ll r){
    if(dp[l][r]!=-inf) return dp[l][r];
    if(l==r) return dp[l][r] = m[l];
    return dp[l][r] = max((ps[r]-ps[l-1])-rec(l+1,r), (ps[r]-ps[l-1])-rec(l,r-1));
}

int main() {
    fast;
    cin>>a;
    m = vec<ll>(a+1);
    ps = vec<ll>(a+1);
    for(int q=1; q<=a; q++){
        cin>>m[q];
        ps[q] = m[q] + (q ? ps[q-1] : 0);
    }
    dp = vec<vec<ll>>(a+1, vec<ll>(a+1, -inf));
    ll X = rec(1, a);
   // cout<<X<<endl;
    cout<<2*X-ps[a];
}

Measured memory_bytes: 70912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h)*(W - w) << endl;


	return 0;
}

Measured memory_bytes: 256
n,k=map(int, input().split())
h=[]
for i in range(n):
  h.append(int(input()))
h.sort()
ans=h[k-1]-h[0]
for i in range(1,n-k+1):
  ans=min(ans,h[i+k-1]-h[i])
print(ans)

Measured memory_bytes: 13392
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    string p = "";
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        p += s;
    }
    string q = "";
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        q += s;
    }

    vector<int> v;
    for(int i = 1; i <= n; i++){
        v.push_back(i);
    }
    int count = 1;
    int a = 0;
    int b = 0;
    do {
        string s = "";
        for(int i = 0; i < v.size(); i++){
            s += to_string(v[i]);
        }
        if(s == p){
            a = count;
        }
        if(s == q){
            b = count;
        }
        count++;
    } while( next_permutation(v.begin(), v.end()) );
    cout << abs(a-b) << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> ans(N);
    rep(i,N-1) {
        int a; cin >> a;
        --a;
        ans[a]++;
    }

    for (auto i : ans) cout << i << ln;
}

Measured memory_bytes: 3992
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,K,*A = map(int,read().split())

MOD = 10 ** 9 + 7

def cumprod(A, MOD = MOD):
    L = len(A); Lsq = int(L**.5+1)
    A = np.resize(A, Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        A[:,n] *= A[:,n-1]; A[:,n] %= MOD
    for n in range(1,Lsq):
        A[n] *= A[n-1,-1]; A[n] %= MOD
    return A.ravel()[:L]
def make_fact(U, MOD = MOD):
    x = np.arange(U, dtype = np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact,fact_inv

def convolve(f, g, MOD=MOD):
    """
    数列 (多項式) f, g の畳み込みの計算．上下 15 bitずつ分けて計算することで，
    30 bit以下の整数，長さ 250000 程度の数列での計算が正確に行える．
    """
    Lf = len(f); Lg = len(g); L = Lf + Lg - 1
    fl = f & (1 << 15) - 1; fh = f >> 15
    gl = g & (1 << 15) - 1; gh = g >> 15
    if L < (1<<8):
        conv = lambda f,g: \
            np.convolve(f,g) % MOD
    else:
        fft = np.fft.rfft; ifft = np.fft.irfft; fft_len = 1 << L.bit_length()
        conv = lambda f,g: \
            np.rint(ifft(fft(f,fft_len) * fft(g,fft_len))[:L]).astype(np.int64) % MOD
    x = conv(fl, gl)
    z = conv(fh, gh)
    y = conv(fl+fh, gl+gh)
    return (x + ((y - x - z) << 15) + (z << 30)) % MOD

fact, fact_inv = make_fact(10 ** 5)

f = np.zeros(N+1,np.int64)
f[0] = 1
for a in A:
    g = fact[N-a:N+1] * fact_inv[0:a+1] % MOD * fact_inv[N-a] % MOD
    g = g[::-1]
    g *= fact_inv[:len(g)]; g %= MOD
    f = convolve(f,g)[:N+1]

f *= fact[:N+1]; f %= MOD

answer = f[N]
print(answer)

Measured memory_bytes: 25456
"""
B - ATCoder
https://atcoder.jp/contests/abc122/tasks/abc122_b
"""
if __name__ == '__main__':
    input = str(input())
    i_list = list(input)

    for i, e in enumerate(i_list):
        if e in {'A', 'C','G', 'T'}:
            i_list[i] = '1'
        else:
            i_list[i] = '0'

    c_list = ''.join(i_list).split('0')
    answer = len(max(c_list, key = len))

    print(answer)


Measured memory_bytes: 3064
import math
N = int(input())
S = str(input())
r=0
g=0
b=0
error=0
n=0

if N%2==0:
    n=(N//2)-1
else:
    n=N//2

for i in range(N):
    if S[i]=='R':
        r+=1
    if S[i]=='G':
        g+=1
    if S[i]=='B':
        b+=1

for p in range(n+1):
    for i in range(N-(p*2)):
        if S[i]==S[i+p] or S[i+p]==S[i+2*p] or S[i]==S[i+2*p]:
            continue
        else:
            error+=1
d=r*g*b

print(d-error)

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

int main()
{
	int k,s;cin>>k>>s;
	int cnt=0;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			if(s-i-j>=0&&s-i-j<=k)cnt+=1;
		}
	}
	cout<<cnt<<"\n";
	return 0;
}


Measured memory_bytes: 256
import heapq
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
if k == 0:
    print(a[0])
    exit(0)
mean_a = sum(a) / k
q = []
for aa in a:
    d = max(math.floor(aa / mean_a), 1)
    q.append((-aa/d, d))
    k -= (d-1)
heapq.heapify(q)

for _ in range(k):
    aa, n = heapq.heappop(q)
    heapq.heappush(q, (aa*n/(n+1), n+1))

ans, _ = heapq.heappop(q)
print(math.ceil(-ans))


Measured memory_bytes: 44488
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define INF 1e18
#define MOD 998244353
int iso_lower(vector<int> V, int x) {
    //ソートされたVの中から、V[i]>=xとなる最小のiを返す.存在しなければVの要素数を返す
    int s = V.size();
    //V.push_back(INF);
    int l = -1;
    int r = s;  //rが常にtrue
    while(r - l > 1) {
        int mid = (l + r) / 2;
        if(V[mid] < x)
            l = mid;
        else
            r = mid;
    }
    return r;
}
int extgcd(int a,int b,int& x,int& y){
    //a,bに対し,ax+by=gcd(a,b)となるx,yを求める.返り値はgcd(a,b)
    int d=a;
    if(b!=0){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }else{
        x=1;y=0;
    }
    return d;
}

int mod_inverse(int a,int m){
    //ax≡1 (mod m)となるxを返す.m=1のときは1を返す.
    if(m==1)return 1;
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}
signed main(){
    int n,N;cin>>n;
    n*=2;
    N=n;
    map<int,int>M;
    for(int i=2;i*i<=N;i++){
        if(N%i==0){
            while(N%i==0){
                M[i]++;
                N/=i;
            }
        }
    }
    if(N>1)M[N]++;
    vector<int>Prime;
    for(auto p:M){
        int q=p.first,a=p.second;
        int m=1;
        rep(i,a)m*=q;
        Prime.push_back(m);
    }
    int S=Prime.size();
   // for(auto x:Prime)cout<<x<<' ';
    //cout<<endl;
    //bit全探索
    
    int ans=INF;
    for(int i=0;i<(1<<S);i++){
        int m=1;
        rep(j,S){
            if(i&(1<<j))m*=Prime[j];
        }
        int l=n/m;
        //cout<<m<<' '<<l<<endl;
        //k+1がmで割り切れて,kがlで割り切れる
        //mx≡1(mod l)なる最小のxを求める
        int x=mod_inverse(m,l);
       // cout<<m<<':'<<x<<':'<<l<<endl;
        if(m*x==1)ans=min(ans,n);
        else ans=min(ans,m*x-1);
    }
    cout<<ans<<endl;
    
    
    
    
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

struct BinaryIndexedTree {
private:
    int n,b;
    vector<int> bit;
public:
    BinaryIndexedTree(int n_) {
        n = n_+10;
        b = 1;
        while (b < n) b <<= 1;
        b >>= 1;
        bit = vector<int>(n,0);
    }

    void add(int a,int w) {
        a++;
        for (int x = a;x < n;x += x&-x) bit[x] += w;
    }

    int sum(int a) {
        a++;
        int ret = 0;
        for (int x = a;x > 0;x -= x&-x) ret += bit[x];
        return ret;
    }

    void update(int a,int w) {
        // a++;
        int v = w-sum(a)+sum(a-1);
        add(a,v);
    }

    int lower_bound(int w) {
        if (w <= 0) return 0;
        int x = 0;
        for (int k = b;k > 0;k /= 2) {
            if (x+k < n && bit[x+k] < w) {
                w -= bit[x+k];
                x += k;
            }
        }
        return x;
    }
};

struct query {
    int l,r,i;
    bool operator<(const query& a) const {
        return r < a.r;
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    vector<int> c(n);
    BinaryIndexedTree bit(n);
    vector<query> a(q);
    vector<int> ans(q),b(n,-1);
    for (int i = 0;i < n;++i) {scanf("%d",&c[i]);c[i]--;}
    for (int i = 0;i < q;++i) {
        scanf("%d%d",&a[i].l,&a[i].r);
        a[i].i = i;
    }
    sort(a.begin(),a.end());
    int j = 0;
    for (int i = 0;i < n;++i) {
        if (b[c[i]] >= 0) bit.add(b[c[i]],-1);
        bit.add(i+1,1);
        b[c[i]] = i+1;
        while (j < q && a[j].r <= i+1) {
            ans[a[j].i] = bit.sum(a[j].r)-bit.sum(a[j].l-1);
            j++;
        }
    }
    for (int i = 0;i < q;++i) printf("%d\n",ans[i]);
}

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

using namespace std;

int main(){
    int minn=0, poss=0;
    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='+') poss++;
        else minn++;
    }
    poss *= 1;
    minn *= (-1);
    cout<<poss+minn<<endl;

    return 0;
}


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

using namespace std;
char arr[1211][1211];

int main() {
	int H, W;
	cin >> H >> W;
	queue<pair<int, pair<int, int> > > q;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> arr[i][j];
			if (arr[i][j] == '#') {
				q.push(make_pair(i, make_pair(j, 0)));

			}
		}
	}
	int ans = 0;
	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second.first;
		int dist = q.front().second.second;
		q.pop();
		ans = max(ans, dist);
		//atas
		if (x - 1 >= 0 && arr[x - 1][y] == '.') {
			q.push(make_pair(x - 1, make_pair(y, dist + 1)));
			arr[x - 1][y] = '#';
		}
		//kanan
		if (y + 1 < W && arr[x][y + 1] == '.') {
			q.push(make_pair(x, make_pair(y + 1, dist + 1)));
			arr[x][y + 1] = '#';
		}
		//bawah
		if (x + 1 < H && arr[x + 1][y] == '.') {
			q.push(make_pair(x + 1, make_pair(y, dist + 1)));
			arr[x + 1][y] = '#';
		}
		//kiri
		if (y - 1 >= 0 && arr[x][y - 1] == '.') {
			q.push(make_pair(x, make_pair(y - 1, dist + 1)));
			arr[x][y - 1] = '#';
		}
	}
	cout << ans << endl;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	https://beta.atcoder.jp/contests/abc070/tasks/abc070_d
*/
const LL INF = (LL)1e18;
int n, q, k;
vector<vector<pair<int, LL> > > adj;
VL dijkstra(int start)
{
	VL dist(n, INF);
	priority_queue<pair<LL, int> > pq;

	dist[start] = 0;
	pq.push({0ll, start});
	while(pq.empty() == false)
	{
		LL cost = -pq.top().first; int here = pq.top().second;
		pq.pop();
		if(dist[here] < cost) continue;

		for(auto pr : adj[here])
		{
			int there = pr.first;
			LL nextDist = cost + pr.second;
			if(nextDist < dist[there])
			{
				dist[there] = nextDist;
				pq.push({-nextDist, there});
			}
		}
	}
	return dist;
}
void query()
{
	cin >> q >> k;
	--k;
	VL dist = dijkstra(k);
	for(int it = 0; it < q; ++it)
	{
		int src, dst;
		cin >> src >> dst;
		--src, --dst;

		cout << dist[src] + dist[dst] << '\n';
	}
	cout << flush;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	adj.resize(n);
	REP(i, 0, n - 1) {
		int u, v; LL w;
		cin >> u >> v >> w;
		--u, --v;
		adj[u].emplace_back(v, w);
		adj[v].emplace_back(u, w);
	}

	query();

	return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

map<char,char> S_,T_;

int main(void){
  string S,T;
  cin >> S >> T;
  int i;
  bool flg = true;
  REP(i,S.length()){
    if(S_.count(S[i])){
      if(S_[S[i]] != T[i]){
        flg = false;
        break;
      }
    }else S_[S[i]] = T[i];

    if(T_.count(T[i])){
      if(T_[T[i]] != S[i]){
        flg = false;
        break;
      }
    }else T_[T[i]] = S[i];
  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
#define Maxn 5005
#define LL long long
const int mod = 1e9+7;
int n;
LL h[Maxn],p[Maxn];
char s[Maxn];
map<int,int>M;
bool check(int s)
{
    M.clear();
    for(int i=s;i<=n;i++) 
    {
        int t=(h[i]-(LL)h[i-s]*p[s])%mod;
        if(t<0) t+=mod;
        int pre=M[t];
        if(pre) 
        {
            if(i-pre>=s) return true; 
        }
        else M[t]=i;
    }
    return false;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    p[0]=1; h[0]=0;
    for(int i=1;i<=n;i++) h[i]=((LL)h[i-1]*29+s[i])%mod,p[i]=(LL)p[i-1]*29%mod;
    int l=0,r=n;
    while(l<r)
    {
        int mid=(l+r+1)>>1;
        if(check(mid))l=mid;
        else r=mid-1;
    }
    printf("%d\n",l);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int h, w, ch, cw, dh, dw;
vector<string> vec;
using P = pair<int, int>;

int main()
{
  const int INF = 1e9;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  rep(i, h) {
    string s;
    cin >> s;
    vec.push_back(s);
  }
  vector<vector<int>> dist(h, vector<int>(w, INF));

  int idx = 0;
  vector<int> dx = {1, -1, 0, 0};
  vector<int> dy = {0, 0, 1, -1};
  deque<P> dq;
  dq.emplace_front(ch, cw);
  dist.at(ch).at(cw) = 0;
  while(!dq.empty()) {
    P v = dq.front(); dq.pop_front();
    int x = v.second;
    int y = v.first;
    int d = dist.at(y).at(x);
    rep(i, 4) {
      int nx = x + dx.at(i);
      int ny = y + dy.at(i);
      
      if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if (vec.at(ny).at(nx) == '#') continue;
      if (dist.at(ny).at(nx) <= d) continue;
      dist.at(ny).at(nx) = d;
      dq.emplace_front(ny, nx);
    }
    for (int ci = -2; ci <= 2; ci++) {
      for (int cj = -2; cj <= 2; cj++) {
        int cny = y + ci;
        int cnx = x + cj;
        if (cnx < 0 || cny < 0 || cnx >= w || cny >= h) continue;
        if (vec.at(cny).at(cnx) == '#') continue;
        if (dist.at(cny).at(cnx) <= d+1) continue;
        dist.at(cny).at(cnx) = d+1;
        dq.emplace_back(cny, cnx);
      }
    }
  }
  if (dist.at(dh).at(dw) != INF) {
    cout << dist.at(dh).at(dw) << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 8588
#include <iostream>
using namespace std;
int main()
{
  int i;
  cin >> i;
  if(i==22)
    cout << "Christmas Eve Eve Eve" << endl;
  else if(i==23)
    cout << "Christmas Eve Eve" << endl;
  else if(i==24)
    cout << "Christmas Eve" << endl;
  else
    cout << "Christmas" << endl;
  
  return 0;
}

Measured memory_bytes: 256