akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

int a[200005];
map<int,int>Q;

int main(){
	int now=0;
	int n,k;
	scanf("%d%d",&n,&k);
	for(register int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		a[x]++;
		if(!Q.count(x)){
			Q[x]=1;
			now++;
		}
	}
	sort(a+1,a+n+1);
	int ans=0;
	for(register int i=n-now+1;i<=n-k;i++){
		ans+=a[i];
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol a,b,c=0,d=0;
  lol ans=INF;
  string s;
  cin >>a>>s;
  for(int n=0;n<s.size();n++){
    if(s[n]+a>'Z') s[n]+=a-26;
    else s[n]+=a;
  }
  cout <<s<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>

using namespace std;

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

int
main()
{
  int a, b;
  cin >> a >> b;
  
  int dif = abs(a-b);
  if (dif % 2 != 0) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  if (a<b)
    cout << abs(a+(dif/2)) << endl;
  else
    cout << abs(b+(dif/2)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<random>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;



// /////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// ////////////////////////////////

#define int long long
const int mod = 1e9 + 7;
int power(int a , int n){

	int res = 1;
	while(n > 0){
		res*=a;
		--n;
	}

	return res;
}
void solve(){

	int n , k , c;
	cin>>n>>k>>c;

	string s;
	cin>>s;

	int left[n+1] , right[n+1];

	memset(left , 0 , sizeof left);
	memset(right , 0 , sizeof right);
	int job = 0;
	for(int i = 0 ; i < n ; ++i){

		if(s[i]=='x')
			continue;

		int j = i;
		++job;
		left[i] = job;
		if(job==k)
			break;
		i+=c;
	}

	reverse(s.begin(),s.end());
	job = k;
	for(int i = 0 ; i < n ; ++i){

		if(s[i]=='x')
			continue;

		int j = i;
		///++job;
		right[n-i-1] = job--;
		if(job==0)
			break;
		i+=c;
	}

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

		if(left[i]==right[i] && left[i]!=0){

			cout<<i+1<<endl;
		}
		//debug(i , left[i] , right[i]);
	}
}

signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t ; ++i){

    	solve();
    	
    	//cout<<"Case #"<<i<<": ";
    }
}


Measured memory_bytes: 5012
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

#include <bits/stdc++.h>
using namespace std;
#define int long long
class BDistance {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int n,d;
cin>>n>>d;
int cnt=0;
        for (int i = 0; i < n; i++) {
            int x,y;
            cin>>x>>y;
            if (x*x+y*y<=d*d) cnt++;
        }
        cout<<cnt;
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    BDistance solver;
    solver.solve(in, out);
}


Measured memory_bytes: 3652
#include <stdio.h>

#define MAX 16

int main()
{
	char s[MAX];
	int count = 0, max = 0, i, j;

	scanf("%s", s);

	for (i = 0; i < MAX && s[i] != '\0'; i++) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' ||  s[i] == 'T') {
			count++;
		    for (j = i + 1; j < MAX && (s[j] == 'A' || s[j] == 'C' ||
										s[j] == 'G' ||  s[j] == 'T');
				 j++) {
				count++;
			}
			if (count > max)
				max = count;
			count = 0;
			i = j;
		}
	}

	printf("%d\n", max);
	return 0;
}


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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
   
    
    int n, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x % 2 && i % 2 == 0)ans++;
    }
    cout << ans << '\n';
    return 0;
}
// Write Here


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <tuple>

int num_mizuyari(std::vector<int>::iterator first, std::vector<int>::iterator last, int base)
{
	auto min_it = std::min_element(first, last);
	int n = *min_it - base;

	auto jt = first;
	auto it = std::find(jt, last, *min_it);
	while (true) {
		if (it != jt)
			n += num_mizuyari(jt, it, *min_it);
		if (it == last)
			break;
		jt = it + 1;
		it = std::find(jt + 1, last, *min_it);
	}
	return n;
}

int main()
{
	int N;
	std::vector<int> h;

	std::cin >> N;
	h.reserve(N);
	for (int i = 0; i < N; ++i) {
		int x;
		std::cin >> x;
		h.push_back(x);
	}

	std::cout << num_mizuyari(h.begin(), h.end() ,0) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int A, B, C;
int main() {
	cin >> A >> B >> C;
	cout << min(A * B / 2, min(B * C / 2, C * A / 2)) << endl;
	return 0;
}

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

using namespace std;

/*
Useful link - https://math.stackexchange.com/questions/521609/finding-expected-value-with-recursion/521720#521720
Essentially,
E(E(X|Y=y)) = E(X)
X = # of moves needed to eat all sushi
E(X|Y=n0 with empty pieces), E(X|Y=n1 piles of sushi with 1 sushi), E(X|Y=n2 piles of sushi wit 2 pieces), E(X|Y=n3 with 3 pieces)
E(X|n1, n2, n3) = 1 + E(X|Y=n0) + E(E(X|Y=n1) + E(E(X|Y=n2)) + E(E(X|Y=n3)) (linearity of expectation + law of total prob)
E(X|Y = n1) = E(X|n1-1, n2, n3) with probability of n1/(n1 + n2 + n3)
E(E(X|Y = n1)) =  E(X|n1-1, n2, n3) * n1/(n1 + n2 + n3)
symetrically, applies to Y=n2, n3 and n0.
*/

int main() {
  int n; cin >> n;
  vector<int>p(n); for (int i = 0; i < n; i++) cin >> p[i];
  int c1 = 0, c2 = 0, c3 = 0;
  for (const auto& x: p) {
    if (x == 1) c1++;
    if (x == 2) c2++;
    if (x == 3) c3++;
  }
  //cout << c1 << " " << c2 << " " << c3 << endl;
  vector<vector<vector<double>>>dp(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, 0.0)));
  //cout << "started\n";
  int mx = n;
  int i,j,k;
  for (k = 0; k <= mx; k++) {
    for (j = 0; j + k <= mx; j++) {
      for (i = 0; j + i + k <= mx; i++) {
        if (i + j + k == 0) continue;
        //if (i > c1 || j > c2 || k > c3) continue;
        double empty = 1.0 * n / (i + j + k);
        double one = 1.0 * i / (i + j + k);
        double two = 1.0 * j / (i + j + k);
        double three = 1.0 * k / (i + j + k);
        //cout << "calculated\n";
        if (i)
          dp[i][j][k] += dp[i-1][j][k] * one;
        if (j)
          dp[i][j][k] += dp[i+1][j-1][k] * two;
        if (k)
          dp[i][j][k] += dp[i][j+1][k-1] * three;
        dp[i][j][k] += empty;
      }
    }
  }
  cout<<fixed<<setprecision(9) << dp[c1][c2][c3] << endl;
  return 0;
}

Measured memory_bytes: 216832
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int 
#define pb   push_back
#define mp   make_pair
#define F    first
#define S    second
int main()
{
       ll n,s;
       cin>>n;
       while(1){
              s=n;
              vector<ll> vi;
              while(s>0){
                     vi.pb(s%10);
                     s=s/10;
              }
              if(vi[0]==vi[1]&&vi[1]==vi[2]&&vi[0]==vi[2]){
                     cout<<n;
                     break;
              }
              n++;
       }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());

        if (a > b)
            System.out.println("a > b");
        else if (a < b)
            System.out.println("a < b");
        else
            System.out.println("a == b");
    }
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll dp[3][n+1];
	ll a[n+1],b[n+1],c[n+1];
	rep(i,1,n)
	cin>>a[i]>>b[i]>>c[i];
	dp[0][1]=a[1];
	dp[1][1]=b[1];
	dp[2][1]=c[1];
	rep(i,2,n)
	{
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
		dp[2][i]=max(dp[1][i-1],dp[0][i-1])+c[i];
	}
	ll ans;
	ans=max(dp[0][n],dp[1][n]);
	ans=max(ans,dp[2][n]);
	cout<<ans;


	return 0;
	
}

Measured memory_bytes: 8276
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    xs <- U.unfoldr parseInt <$> C.getLine
    putStrLn.bool"No""Yes"$solve n xs

solve :: Int -> U.Vector Int -> Bool
solve n xs = go (-1) $ U.toList xs
  where
    go !prev (x:xs)
        | prev == x = go x xs
        | prev < x = go (x-1) xs
        | otherwise = False
    go _ [] = True


-------------------------------------------------------------------------------
type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

Measured memory_bytes: 4092
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
    string S;
    int tmp, result, n;
    int cnt1 = 0;
    int cnt2 = 0;
    string ss;
    cin >> S;
    n = S.length();
    ss = S;
    for(int i = 0; i < n; i++){
        if((ss[i] != '1' and i % 2 == 0) or (ss[i] != '0' and i % 2 == 1)){
            cnt1++;
        }else if((ss[i] != '0' and i % 2 == 0) or (ss[i] != '1' and i % 2 == 1)){
            cnt2++;
        }
    }
    result = cnt1;
    if(cnt1 > cnt2) result = cnt2;
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 512
# D - Cake 123

import heapq

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
B = sorted(list(map(int, input().split())), reverse = True)
C = sorted(list(map(int, input().split())), reverse = True)

d = []
heapq.heappush(d, (-(A[0]+B[0]+C[0]), 0, 0, 0)) # heapqにタプルを与えると最初の要素でソートする
ijk_set = set((0,0,0))

for _ in range(K):
    tmp, i, j, k = heapq.heappop(d)
    print(-tmp)
    if (i+1,j,k) not in ijk_set and i+1 <= X-1:
        heapq.heappush(d, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
        ijk_set.add((i+1,j,k))
    if (i,j+1,k) not in ijk_set and j+1 <= Y-1:
        heapq.heappush(d, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
        ijk_set.add((i,j+1,k))
    if (i,j,k+1) not in ijk_set and k+1 <= Z-1:
        heapq.heappush(d, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
        ijk_set.add((i,j,k+1))

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

const int N = 200010;

int a[N], b[N];

int main() {
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
		scanf("%d%d", &a[i], &b[i]);
	sort(a+1, a+n+1);
	sort(b+1, b+n+1);
	if(n&1)
		printf("%d\n", b[(n+1)/2]-a[(n+1)/2]+1);
	else {
		int mn = a[n/2+1]+a[n/2];
		int mx = b[n/2+1]+b[n/2];
		printf("%d\n", mx-mn+1);
	}
	return 0;
}

Measured memory_bytes: 5364
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long K = sc.nextLong();
		long[] count = new long[100001];
		for( int i=0; i<N; i++ ){
			int a = sc.nextInt();
			long b = sc.nextLong();
			count[a] += b;
		}
		long ans = 0;
		for( int i=1; i<=100000; i++ ){
			ans += count[i];
			if( ans>=K ){
				System.out.println(i);
				break;
			}
		}
	}
}


Measured memory_bytes: 64880
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = Counter(c.values())

dx = [0 for _ in range(n+1)]
for i in range(1, n+1):
	dx[i] = dx[i-1] + i*d[i]

xdx = [0 for _ in range(n+2)]
xdx[n] = d[n]
for i in range(n-1, 0, -1):
	xdx[i] = xdx[i+1] + d[i]

res = [0] + [(dx[i] + i*xdx[i+1]) // i for i in range(1, n+1)]
ans = [0 for _ in range(n)]
cur = n
for i in range(n):
	while cur > 0 and res[cur] < i+1:
		cur -= 1
	if cur > 0:
		ans[i] = cur
print(*ans, sep="\n")

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

from collections import deque
'''
d = deque([1,2,3])
d.append(1)であれば右(末尾)
d.appendleft(1)であれば左(先頭)
d.pop()であれば3、つまり末尾
d.popleft()であれば1、つまり先頭
'''
h,w = map(int,readline().split())
grid = '#'*(w+2)
A = []
A.append(grid)
for i in range(h):
    tmp = "#" + readline().rstrip().decode() + "#"
    A.append(tmp)
A.append(grid)

def bfs(i,j ):
    inf = 10 ** 9
    dist = [[inf]*(w+2) for i in range(h+2)]
    dist[i][j] = 0
    q = deque()
    q.append((i,j ))
    ans = 0
    while q:
        hh, ww = q.popleft()
        dv = dist[hh][ww]
        for k,l in [(1,0),(0,1),(-1,0),(0,-1)]:
            if A[hh+k][ww+l] == "#":
                continue
            if dist[hh+k][ww+l] <= dv +1:
                continue
            dist[hh+k][ww+l] = dv +1
            ans = dv + 1
            q.append((hh+k,ww+l))

    return ans

anss = 0
for i in range(h+2):
    for j in range(w+2):
        if A[i][j] == "#":
            continue
        anss = max(anss,bfs(i,j))
print(anss)
            
    



Measured memory_bytes: 3316
h,w=map(int,input().split())
a=[]
ans=[]
visited=[]
for i in range(h):
  r=list(map(int,input().split()))
  a.append(r)
#print a
#print (a)
#print (visited)
for i in range(h):
  visited.append([])
  for j in range(w):
    visited[i].append(0)
    #print ("i,j,a[i][j]",i,j,a[i][j])
    if visited[i][j]==0:
      if a[i][j]%2==1:
        #print ("odd")
        if j+1 < w:
          a[i][j]-=1
          a[i][j+1]+=1
          ans.append("%d %d %d %d" %(i+1,j+1,i+1,j+2))
          visited[i][j]=1
          #print (visited)
        elif i+1 < h:
          a[i][j]-=1
          a[i+1][j]+=1
          ans.append("%d %d %d %d" %(i+1,j+1,i+2,j+1))
          visited[i][j]=1
          #print (visited)
#print (a)
#print (visited)
#print (ans)
print (len(ans))
for i in range(len(ans)):
  print (ans[i])


Measured memory_bytes: 18548
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

class Node {
public:
  int to;
  int dist;
  Node() {}
  Node(int _t,int _d) : to(_t),dist(_d){}
};

bool is_LPG[6001];
bool dp[6001][2001]; //dp[city_id][remaining_LPG] = dist;

int get_city_id(map<string,int>& cities,const string& city){
  if(cities.find(city) == cities.end()){
    int idx = cities.size();
    cities[city] = idx;
  }
  return cities[city];
}

class State {
public:
  int city_id;
  int dist;
  int remaining_LPG;
  State(int _city_id,int _dist,int _con){
    city_id = _city_id;
    dist = _dist;
    remaining_LPG = _con;
  }

  bool operator <(const State& s) const{
    return (dist < s.dist);
  }

  bool operator >(const State& s) const{
    return (dist > s.dist);
  }
};

int main(){
  int total_roads;
  int total_LPG_stations;
  int capacity;
  while(cin >> total_roads >> total_LPG_stations >>capacity){
    if(total_roads == 0
       && total_LPG_stations == 0
       && capacity == 0) break;

    map<string,int> cities;
    memset(is_LPG,false,sizeof(is_LPG));
    memset(dp,false,sizeof(dp));

    string src,dst;
    cin >> src >> dst;
    get_city_id(cities,src);
    get_city_id(cities,dst);

    vector<Node> nodes[6001];
    for(int road_idx = 0; road_idx < total_roads; road_idx++){
      string from_str,to_str;
      int dist;

      cin >> from_str >> to_str >> dist;
      int from_num = get_city_id(cities,from_str);
      int to_num = get_city_id(cities,to_str);

      nodes[from_num].push_back(Node(to_num,dist));
      nodes[to_num].push_back(Node(from_num,dist));
    }

    for(int LPG_idx = 0; LPG_idx < total_LPG_stations; LPG_idx++){
      string city;
      cin >> city;
      is_LPG[get_city_id(cities,city)] = true;
    }

    priority_queue<State,vector<State>, greater<State> > que;
    que.push(State(get_city_id(cities,src),0,10*capacity));

    int dst_id = get_city_id(cities,dst);

    int res = INF;
    while(!que.empty()){
      State s = que.top();
      que.pop();

      if(s.city_id == dst_id){
	res = s.dist;
	goto found;
      }
      if(dp[s.city_id][s.remaining_LPG]) continue;
      dp[s.city_id][s.remaining_LPG] = true;

      for(int to_idx=0;to_idx<nodes[s.city_id].size();to_idx++){
	int to = nodes[s.city_id][to_idx].to;
	int dist = nodes[s.city_id][to_idx].dist;
	if(s.remaining_LPG < dist) continue;

	int next_remaining_LPG = (is_LPG[to] ? 10 * capacity : s.remaining_LPG - dist);

	que.push(State(to,s.dist + dist,next_remaining_LPG));
      }
    }
  found:;
    printf("%d\n",res >= INF ? -1 : res);
  }
  return 0;
}

Measured memory_bytes: 63728
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm> 
#include<queue>
using namespace std;
int main()
{
int a,b,c,x,cnt=0;
cin>>a>>b>>c>>x;
for(int i=0;i<=a;i++)
{for(int j=0;j<=b;j++)
 {if((x-i*500-j*100)%50==0 &&(x-i*500-j*100)/50<=c && (x-i*500-j*100)/50>=0)
  cnt++;}}
cout<<cnt;
system("pause"); 
return 0;
}


Measured memory_bytes: 504
h,w = map(int, input().split())
s = [list(input()) for i in range(h)]

for i in range(h):
    s[i].insert(0, ".")
    s[i].append(".")

s1 = []
for i in range(w+2):
    s1.append(".")

s.insert(0, s1)
s.append(s1)

ans = "Yes"

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == "#":
            if s[i-1][j] == s[i][j-1] == s[i][j+1] == s[i+1][j] == ".":
                ans = "No"

print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    int N, D;
    cin >> N >> D;
    int syo, amari;
    syo = N / (2 * D + 1);
    amari = N % (2 * D + 1);
    int out;
    if(amari == 0){
      out = syo;
    }else{
      out = syo + 1;
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c,n,i;
    cin>>n;
    for(i=0;i<n;++i){
        cin>>a>>b>>c;
        if(a*a+b*b==c*c){
            cout<<"YES"<<endl;
        }
        else if(a*a+c*c==b*b){
            cout<<"YES"<<endl;
        }
        else if(c*c+b*b==a*a){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main(void) {
	int d,v,N,M;
	while (cin >> N >> M,N,M) {
		vector<int> prob(M,0);
		for (int i = 0; i < N; ++i) {
			cin >> d >> v;
			prob[d-1] = max(v,prob[d-1]);
		}
		int res = 0;
		for (int i = 0; i < M; ++i) {
			res += prob[i];
		}
		cout << res << endl;
	}
	return 0;
}



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

typedef long long ll;

ll o[65],z[65];

bool checkbit(ll N,int pos)
{
    return (bool)(N & (1LL<<pos));
}

ll mulMod(ll a,ll b,ll M)
{
    return ((a%M)*(b%M))%M;
}

ll addMod(ll a,ll b,ll M)
{
    return ((a%M)+(b%M))%M;
}

int main()
{
    //freopen("in.txt","r", stdin);
    //freopen("out.txt","w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);

    ll n,x,m = 1e9+7;

    cin>>n;

    for(int i=0; i<n; i++)
    {
        cin>>x;
        for(int j=0; j<=61; j++)
        {
            if(checkbit(x,j))   o[j]++;
            else                z[j]++;
        }
    }

    ll ans = 0;

    for(ll i=0; i<=61; i++)
        ans = ((ans%m)+mulMod(o[i]*z[i],(1LL<<i),m))%m;

    cout<<ans<<endl;

    return 0;
}


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

int main()
{
    int n,i,c=0;
    cin>>n;
    int arr[n];

    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(i=1;i<n-1;i++)
    {
        if((arr[i]>arr[i+1] && arr[i]<arr[i-1]) || (arr[i]<arr[i+1] && arr[i]>arr[i-1]))
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k,l,ii,jj;
ll n,m;
ll a[305][305];
bool used[305];
ll ans=INF;
ll b[305];
ll v=-1,w;
 
int main(){
    cin>>n>>m;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin>>a[i][j];
			used[i+1]=false;
        }
    }
    while(true){
        ll x=0;
        for(i=1;i<=m;i++){
            b[i]=0;
        }
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                if(!used[a[i][j]]){
                    x=1;
                    b[a[i][j]]++;
                    break;
                }else{
                    continue;
                }
            }
        }
        if(x==0)break;
        v=-1;
		w=-1;
        for(i=1;i<=m;i++){
            if(b[i]>v){
                v=b[i];
                w=i;
            }
        }
        if(v==0)break;
        ans = min(ans,v);
		//cout<<"v= "<<v<<" w="<<w<<endl;
        used[w]=true;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5632
Tre_words = input().split()
s1 = (Tre_words[0].title())
s2 = (Tre_words[1].title())
s3 = (Tre_words[2].title())
A = list(s1)
B = list(s2)
C = list(s3)

print(A[0]+B[0]+C[0])

Measured memory_bytes: 9028
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;

int main(){
  int k,a,b;cin>>k>>a>>b;
  
  string ans="NG";
  for(int i=a;i<=b;i++){
    if(i%k==0){
      ans="OK";
      break;
    }
  }
  cout<<ans;
  
  
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin >> n;
    vector <ll> arr(n);
    map <ll,ll> mapp;
    for (int z=0;z<n;z++){
        cin >> arr[z];
    }
    for (int z=0;z<n;z++){
        mapp[z+arr[z]+1]++;
    }
    ll ans = 0;
    for (int z=0;z<n;z++){
        ans += mapp[z-arr[z]+1];
    }
    cout << ans << endl;
} 

Measured memory_bytes: 27436
N = int(input())

if N < 10:
  X = N
elif N < 100:
  X = 9
elif N < 1000:
  X = N - 90
elif N < 10000:
  X = 909
elif N < 100000:
  X = N - 9090
else:
  X = 90909
  
print(X)


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

#define DEBUG(C) std::cerr << #C << " = " << C << std::endl;

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

/**
* Binary_Indexed_Tree(BIT) 2d by mod
* Fenwick Tree
* 0-indexed!!!
* O((log N)(log M))
*/
template<int mod>
class binary_indexed_tree_2d_by_mod {
private:
    int N;
    int M;
    std::vector<std::vector<int>> bit;

    void add(int &a, int b) {
        if (b < 0) b += mod;
        a += b;
        if (a >= mod) a -= mod;
    }

    int sum(int x, int y) {
        int res = 0;

        for (int i = x; i > 0; i -= i & (-i)) {
            for (int j = y; j > 0; j -= j & (-j)) {
                this->add(res, this->bit[i - 1][j - 1]);
            }
        }
        return res;
    }

public:
    binary_indexed_tree_2d_by_mod() {}
    binary_indexed_tree_2d_by_mod(int n, int m) : N(n + 1), M(m + 1), bit(n + 1, std::vector<int>(m + 1)) {}

    void add(int x, int y, long long val) {
        // for mod calc
        val %= mod;
        // for 0-indexed
        x++; y++;

        for (int i = x; i - 1 < N; i += i & (-i)) {
            for (int j = y; j - 1 < M; j += j & (-j)) {
                this->add(this->bit[i - 1][j - 1], val);
            }
        }
    }

    // [ (x1, y1), (x2, y2) )
    int sum(int x1, int y1, int x2, int y2) {

        int res = this->sum(x2, y2);
        add(res, -sum(x1, y2));
        add(res, -sum(x2, y1));
        add(res, sum(x1, y1));

        return res;
    }
};



const int MAX = 2e3 + 10;
int N, M;
binary_indexed_tree_2d_by_mod<MOD> bit;

int main(void) {
    std::cin >> N >> M;
    std::vector<int> S(N);
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
    }
    std::vector<int> T(M);
    for (int i = 0; i < M; i++) {
        std::cin >> T[i];
    }
    bit = binary_indexed_tree_2d_by_mod<MOD>(N + 1, M + 1);

    bit.add(0, 0, 1);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (S[i] == T[j]) {
                bit.add(i + 1, j + 1, bit.sum(0, 0, i + 1, j + 1));
            }
        }
    }

    std::cout << bit.sum(0, 0, N + 1, M + 1) << std::endl;
}


Measured memory_bytes: 16000
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b, c, d ] <- readInts
	putStrLn $ convStr $ compare ( a + b ) ( c + d )

convStr GT = "Left"
convStr EQ = "Balanced"
convStr LT = "Right"


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(rall(a));
    ll ans = 0;
    for(int i = 1; i < n; i++){
        int j = i/2;
        ans += a[j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4060
/*
    Code written by Talant I.D.
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9	
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353

inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
 
bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2) 
		if(n % i == 0) return false;
	return true;
}

const int N = 1e5+7;
vector <vector <int>> graph;
int used[N], dept[N], depa[N];
char q = 't';

void dfs(int v, int p, int cnt = 0){
	used[v] = 1;
	if(q == 't' && p != v) dept[v] = dept[p]+1;
	else if(p != v) depa[v] = depa[p]+1;
	
	for(auto to : graph[v]){
		if(!used[to]){
			dfs(to, v, cnt+1);
		}
	}
}

int main(){
    do_not_disturb
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n, taka, aoki, i, x, y, in = -1, mx = 0;
	cin >> n >> taka >> aoki;
	graph.resize(n+1);
	
	for(i = 0; i < n-1; i++){
		cin >> x >> y;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	
	if(graph[taka].size() == 1 && graph[taka][0] == aoki){
		cout << 0;
		return 0;
	}
	
	dfs(taka, taka);
	q = 'a';
	memset(used, 0, sizeof(used));
	dfs(aoki, aoki);
	
	for(i = 1; i <= n; i++){
		if(dept[i] < depa[i]){
			if(mx < depa[i]){
				mx = depa[i];
				in = i;
			}
		}
	}
	
	if(in == -1)in = graph[graph[aoki][0]][0];
	
	cout << depa[in]-1;
	
    return 0;
} // What is to be written here?


Measured memory_bytes: 10752
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashMap<Long, Long> map = new HashMap<Long, Long>();
    for(int i = 0; i < n; i++) {
      String s = sc.next();
      ArrayList<Integer> list = new ArrayList<Integer>();
      for(int j = 0; j < s.length(); j++) {
        int t = s.charAt(j) - 'a';
        list.add(t);
      }
      Collections.sort(list);
      long t = 0;
      for(int j = 0; j < list.size(); j++) {
        t += ((long)(Math.pow(26, j)) * (long)list.get(j));
      }
      if(map.containsKey(t)) {
        map.put(t, map.get(t) + 1);
      } else {
        map.put(t, (long)1);
      }
    }
    long ans = 0;
    for(long key : map.keySet()) {
      long t = map.get(key);
      ans += ((t * (t - 1)) / 2);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 57512
#include <iostream>
#include <cmath>
using namespace std;
int s[10];
int c[10];
int main(){
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++){
    cin >> s[i];
    cin >> c[i];
  }
  //先頭チェック
  if (N > 1){
    for (int i = 0; i < M; i++){
      if (s[i] == 1 && c[i] == 0){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  //重複チェック
  for (int i = 0; i < M; i++){
    for (int j = i + 1; j < M; j++){
      if (s[i] == s[j] && s[i] != -1){
        if (c[i] != c[j]){
          cout << -1 << endl;
          return 0;
        } else {
          s[i] = -1;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++){
    if (s[i] == -1) continue;
    ans += c[i] * pow(10, N - s[i]);
  }
  if (ans == 0 && N == 1){
    cout << 0 << endl;
    return 0;
  }
  if (ans < pow(10, N - 1)){
    ans += pow(10, N - 1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long,long long>
#define ppp pair<long long, pair<long long,long long> >
#define f first	
#define s second
#define pd pair<double,long long>
ll stree[800100][2],lazy[800100][2],arr[200100];
ll query(ll strt,ll ed,ll qs,ll qe,ll  idx,ll flag) {
	stree[idx][flag]=min(stree[idx][flag],lazy[idx][flag]);
	if (strt!=ed) {
		lazy[idx*2+1][flag]=min(lazy[idx*2+1][flag],lazy[idx][flag]);
		lazy[idx*2+2][flag]=min(lazy[idx*2+2][flag],lazy[idx][flag]);
	}
	lazy[idx][flag]=1e9;
	if (qs>ed || qe<strt || qs>qe || strt>ed)
		return 2;
	if (qs<=strt && qe>=ed) {
		return stree[idx][flag];
	}
	ll mid=(strt+ed)/2;
	return max(query(strt,mid,qs,qe,idx*2+1,flag),query(mid+1,ed,qs,qe,idx*2+2,flag));
}
void update(ll strt,ll ed,ll qs,ll qe,ll val,ll idx,ll flag) {
	stree[idx][flag]=min(stree[idx][flag],lazy[idx][flag]);
	if (strt!=ed) {
		lazy[idx*2+1][flag]=min(lazy[idx*2+1][flag],lazy[idx][flag]);
		lazy[idx*2+2][flag]=min(lazy[idx*2+2][flag],lazy[idx][flag]);
	}
	lazy[idx][flag]=1e9;
	if (qs>ed || qe<strt)
		return;
	if (qs<=strt && qe>=ed) {
		stree[idx][flag]=min(stree[idx][flag],val);
		if (strt!=ed) {
			lazy[idx*2+1][flag]=min(lazy[idx*2+1][flag],val);
			lazy[idx*2+2][flag]=min(lazy[idx*2+2][flag],val);
		}
		return;
	}
	ll mid=(strt+ed)/2;
	update(strt,mid,qs,qe,val,idx*2+1,flag);

	update(mid+1,ed,qs,qe,val,idx*2+2,flag);
	stree[idx][flag]=min(stree[idx*2+1][flag],stree[idx*2+2][flag]);
}
void build(ll strt,ll ed,ll idx,ll flag) {
	lazy[idx][flag]=1e9;
	if (strt==ed) {
		stree[idx][flag]=arr[strt];
		return;
	}
	ll mid=(strt+ed)/2;
	build(strt,mid,idx*2+1,flag);
	build(mid+1,ed,idx*2+2,flag);
	stree[idx][flag]=min(stree[idx*2+1][flag],stree[idx*2+2][flag]);
}
void solveTestCase() {
	ll n,i,j,k,l,x,m;
	cin>>n>>m;
	for (i=1;i<=n;i++)
		arr[i]=n;
	build(1,n,0,0);
	build(1,n,0,1);
	ll ans=(n-2)*(n-2);
	set<ll> st1,st2;
	while (m--) {
		cin>>j>>k;
		if (j==1) {
			if (k==1 || k==n || st1.find(k)!=st1.end())
				continue;
			else {
				ll op = query(1,n,k,k,0,0);
				ans-=(op-2);
				update(1,n,2,op,k,0,1);
			}
			st1.insert(k);
		} else {
			if (k==1 || k==n || st2.find(k)!=st2.end())
				continue;
			else {
				ll op = query(1,n,k,k,0,1);
				ans-=(op-2);
				update(1,n,2,op,k,0,0);
			}
			st2.insert(k);
		}
	}
	cout<<ans<<'\n';
}
int main() {
	ll t,n,i,j,k,l,m;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll p;
	t=1;
	//cin>>t;
	for (ll T=1;T<=t;T++) {
		solveTestCase();
	}
	return 0;
}

Measured memory_bytes: 30916
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	long long Z, W;
	cin >> N >> Z >> W;
	long long a1 = 0ll;
	long long a2 = 0ll;
	for (auto i = 0; i < N; ++i)
	{
		a1 = a2;
		cin >> a2;
	}

	if (N == 1)
	{
		cout << abs(a2 - W) << endl;
	}
	else
	{
		cout << max(abs(a2 - a1), abs(a2 - W)) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from math import ceil, floor


def main():
    h, w = map(int, input().split())
    d = h * w
    d = min((ceil(h / 3) - floor(h / 3)) * w, d)
    d = min((ceil(w / 3) - floor(w / 3)) * h, d)
    dd = h * w
    for i in range(h):
        u = i * w
        d1 = (h - i) * ceil(w / 2)
        d2 = (h - i) * floor(w / 2)
        di = max(abs(u - d1), abs(u - d2))
        if di > dd:
            break
        dd = di
    d = min(dd, d)
    dd = h * w
    for i in range(w):
        u = i * h
        d1 = (w - i) * ceil(h / 2)
        d2 = (w - i) * floor(h / 2)
        di = max(abs(u - d1), abs(u - d2))
        if di > dd:
            break
        dd = di
    d = min(dd, d)
    print(d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
long long a, b, c;
int d[1000000];
int ans;
long long gcd(long long x, long long y) {
	if (x < y) {
		long long z;
		z = x;
		x = y;
		y = z;
	}
	if (x % y)return gcd(y, x % y);
	else return y;
}
int main() {
	scanf("%lld%lld", &a, &b);
	c = gcd(a, b);
	for (long long i = 2; i * i <= c; i++) {
		if (c % i == 0) {
			d[i]++;
			c /= i;
			i = 1;
		}
	}
	if (1 < c && c < 1000000) {
		d[c]++;
		c = 1;
	}
	ans = 1;
	for (int i = 0; i < 1000000; i++) {
		if (d[i])ans++;
	}
	if (c != 1)ans++;
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;++i){
		string a,b;
		int al,bl;
		cin >> a >> b;
		a = ' ' + a;b = ' ' + b;
 		al = a.length();bl = b.length();
		vector<vector<int> > dp;
		dp.resize(al);
		for(int i=0;i<al;++i){
			dp[i].resize(bl);
		}
		for(int i=0;i<al;++i)dp[i][0] = 0;
		for(int i=0;i<bl;++i)dp[0][i] = 0;
		for(int i=1;i<al;++i){
			for(int j=1;j<bl;++j){
				if(a[i]==b[j])dp[i][j] = dp[i-1][j-1] + 1;
				else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
		cout << dp[al-1][bl-1] << endl;
	}
}


Measured memory_bytes: 6916
N,K=map(int,input().split())
A=[]
B=[]
for i in range(N):
	a,b=map(int,input().split())
	A+=a,
	B+=b,
z=0
for i in range(31):
	if K>>i&1 or i==30:
		S=(K>>i<<i)-1if i<30else K
		x=0
		for j in range(N):
			if (S|A[j])==S:
				x+=B[j]
		z=max(z,x)
print(z)

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

using namespace std;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}



int main(){

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

    string s;
    cin >> s;

    int n = s.size();

    int one = 0,zero = 0;

    for(int i = 0; i < n; ++i){
        if(s[i] == '1') ++one;
        if(s[i] == '0') ++zero;
    }

    ppp(min(one,zero)*2);




    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int A,B; cin >> A >> B;
    cout << (A<9 && B<9 ? "Yay!" : ":(") << endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> v(n+1),sol,vu(n+1);
	for (int i=1; i<=n; ++i){
		cin >> v[i];
	}
	for (int i=n; i>=1; --i){
		int j=2*i;
      vu[i] = v[i];
		while (j <= n){
			vu[i] += vu[j];
			j += i;
			vu[i] %= 2;
		}
		if (vu[i] == 1) sol.emplace_back(i);
	}
	cout << sol.size() << '\n';
	for (int i:sol) cout << i << ' ';
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n,k;cin >> n >>k;
  vector<int>a(n);
  for(int &x:a)cin >> x ;
  vector<int>dp(n,1e9) ;
  dp[0]=0;
  for(int i=1;i<n;i++)
    for(int j=i-1,c=0;~j&&c<k;--j,c++)
      dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
  cout << dp[n-1] ;
}


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

int main(){
    string buf;
    while(cin>>buf,buf!="0"){
        int n=buf.size();
        vector<int> a(n);
        for(int i=0;i<n;i++) a[i]=buf[i]-'0';
        int sum=0;
        map<int,int> cnt;
        for(int i=0;i<n;i++){
            if(i&1) sum=((sum-a[i])%11+11)%11;
            else sum=(sum+a[i])%11;
            cnt[sum]++;
        }
        sum=0;
        int res=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0) res+=cnt[sum];
            if(i&1) sum=((sum-a[i])%11+11)%11;
            else sum=(sum+a[i])%11;
            cnt[sum]--;
        }
        cout<<res<<endl;
    }
    return 0;
}


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

#define ll long long

const int mxN=1e5, M=1e9+7;
int n, ui, vi;
ll dp[mxN][2];
vector<int> adj[mxN];

void dfs(int u, int p) {
	dp[u][0]=dp[u][1]=1;
	for(int v : adj[u]) {
		if(v==p)
			continue;
		dfs(v, u);
		dp[u][0]=dp[u][0]*(dp[v][0]+dp[v][1])%M;
		dp[u][1]=dp[u][1]*dp[v][0]%M;
	}
}

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

	cin >> n;
	for(int i=0; i<n-1; ++i) {
		cin >> ui >> vi, --ui, --vi;
		adj[ui].push_back(vi);
		adj[vi].push_back(ui);
	}
	dfs(0, -1);
	cout << (dp[0][0]+dp[0][1])%M;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a, b;
    ll sum=0;
    bool flag=true;
    a.push_back(sum);
    rep(i, n){
        ll x;
        cin >> x;
        sum += x;
        if(flag){
            if(sum<=k){
                a.push_back(sum);
            }else{
                flag=false;
            }
        }
    }
    sum=0;
    flag = true;
    b.push_back(sum);
    rep(i, m) {
      ll x;
      cin >> x;
      sum += x;
      if (flag) {
        if (sum <= k) {
            b.push_back(sum);
        } else {
            flag = false;
        }
      }
    }
    int l = 0, maxim=0, bsize=b.size()-1;
    for(int i=a.size()-1;i>=0;i--){
      ll rem = k - a[i];
      while(l<bsize&&b[l+1]<=rem){
        l++;
      }
      maxim = max(maxim, i+l);
    }
    cout << maxim << endl;
    return 0;
}

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

using namespace std;
using ll = long long;



int main(){
  ll n, m;
  cin >> n >> m;
  vector<ll> s(n, 0);
  vector<ll> g(n, 0);
  
  
  for(int i=0; i<m; i++){
    int a, b; cin >> a >> b;
    if(a==1){
      s[b-1] = 1;
    }else if(b==n){
      g[a-1] = 1;
    }
  }

  bool flag = false;
  
  for(int i=1; i<n; i++){
    if(s[i]==1 && g[i]==1) flag=true;
  }
  
  
  if(flag) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  
  return 0;
}

Measured memory_bytes: 6284
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int n, K, D[501000], S[501000];
char p[501000], q[501000];
struct STK {
	int num, T;
};
deque<STK> Deq[2];
void Ins(int a) {
	int T = D[a] - S[a + 1] / 2 + 1;
	int pv = S[a + 1] % 2;
	while (!Deq[pv].empty() && Deq[pv].back().T >= T)Deq[pv].pop_back();
	Deq[pv].push_back({ a,T });
}
int main() {
	int i;
	scanf("%d%d", &n, &K);
	scanf("%s", p + 1);
	scanf("%s", q + 1);
	for (i = 2; i <= n; i++) {
		S[i] = S[i - 1];
		if (q[i] != q[i - 1])S[i]++;
	}
	Ins(0);
	for (i = 1; i <= n; i++) {
		int pv = S[i] % 2;
		if (p[i] == q[i])D[i] = D[i - 1];
		else D[i] = D[i - 1] + 1;
		while (!Deq[pv].empty() && Deq[pv].front().num + K < i)Deq[pv].pop_front();
		if (!Deq[pv].empty())D[i] = min(D[i], S[i]/2 + Deq[pv].front().T);
		Ins(i);
	}
	printf("%d\n", D[n]);
}

Measured memory_bytes: 7688