akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using Path = std::pair<long long, int>;
using Graph = std::vector<std::vector<Path>>;
using List = std::vector<long long>;

List find_min(const Graph &g, int s) {
  int n = g.size();
  std::priority_queue<Path, std::vector<Path>, std::greater<Path>> heap;
  List dist(n, 1e18);
  dist[s] = 0;
  heap.push({0, s});
  while (not heap.empty()) {
    long long t = heap.top().first;
    int pos = heap.top().second;
    heap.pop();
    if (t != dist[pos]) continue;
    for (Path p : g[pos]) {
      long long t2 = t + p.first;
      long long v = p.second;
      if (t2 < dist[v]) {
        dist[v] = t2;
        heap.push({t2, v});
      }
    }
  }
  return dist;
}

int main() {
  int n, m, s, t;
  std::cin >> n >> m >> s >> t;
  Graph ga(n), gb(n);
  for (int mi = 0; mi < m; ++mi) {
    int u, v, a, b;
    std::cin >> u >> v >> a >> b;
    ga[u - 1].push_back({a, v - 1});
    ga[v - 1].push_back({a, u - 1});
    gb[u - 1].push_back({b, v - 1});
    gb[v - 1].push_back({b, u - 1});
  }
  List da = find_min(ga, s - 1);
  List db = find_min(gb, t - 1);
  List ans(n);
  ans[n - 1] = da[n - 1] + db[n - 1];
  for (int i = n - 2; i >= 0; --i) ans[i] = std::min(ans[i + 1], da[i] + db[i]);
  for (long long x : ans) std::cout << 1000000000000000 - x << std::endl;
  return 0;
}


Measured memory_bytes: 19016
#include <iostream>
using namespace std;
int main() {
  int a,b,c,d,e;
  cin>>a>>b;
  c=-10000000;
  if (a+b>c)c=a+b;
  if (a-b>c)c=a-b;
  if (a*b>c)c=a*b;
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long

using namespace std;


//A:答え
//d:桁数
//value:値
void dfs(vector<ll> &A, int d, ll value){
    A.push_back(value);

    if(d == 10) return;

    //次の桁へ進む
    for(int j = -1; j <= 1; j++){
        int add = (value % 10) + j;
        if(add >= 0 && add <= 9) dfs(A, d+1, value*10 + add);
    }
}

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

    vector<ll> A;
    for(int v = 1; v < 10; v++) dfs(A, 1, v);

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

    cout << A[k-1] << endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>


using namespace std;


using ll = long long;


const long long MAX = 200001;
const long long MOD = 1000000007;


ll fact[MAX];
ll inv[MAX];


ll pow(ll x, ll n)
{
    ll ret = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ret = (ret * x) % MOD;
        }
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}


void init()
{
    fact[0] = fact[1] = 1;
    for (ll i = 2; i <= MAX; i++) {
        fact[i] = (fact[i - 1] * i) % MOD;
    }
    inv[MAX - 1] = pow(fact[MAX - 1], MOD - 2) % MOD;
    for (ll i = MAX - 2; i >= 1; i--) {
        inv[i] = (inv[i + 1] * (i + 1)) % MOD;
    }
    inv[0] = 1;
}


ll comb(ll x, ll y)
{
    return fact[x] * inv[x - y] % MOD * inv[y] % MOD;
}


int main()
{
    init();
    ll n, k;
    cin >> n >> k;
    k = min(n, k);
    ll ans = 0;
    for (ll i = 0; i <= k; i++) {
        ans += (comb(n, i) * comb(n - 1, i)) % MOD;
    }
    cout << ans % MOD << endl;
}


Measured memory_bytes: 3328
import itertools
N=int(input())
XY=[]
for _ in range(N):
    tmp=list(map(int,input().split()))
    XY.append(tmp)
l=[i for i in range(N)]
permutation = itertools.permutations(l, 2)
total=0
for p in permutation:
    i=p[0]
    j=p[1]
    total+=((XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2)**0.5

print(total/N)

Measured memory_bytes: 3064
import java.util.Scanner;



public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] array = new int[6 + 1];
		array[0] = 0;
		for (int i = 1; i < array.length; i++) {
			array[i] = scan.nextInt();
		}
		String order = scan.next();
		scan.close();
		Dice dice = new Dice(array);
		array = dice.roll(order);
		System.out.println(array[0]);
	}
}
	

class Dice {
	int[] num = new int[6 + 1];
	Dice() {
	}

	Dice(int[] array) {
		for (int i = 0; i < array.length; i++) {
			this.num[i] = array[i];
		}
	}
	
	public int[] getNum() {
		return this.num;
	}
	
	public int getNumber(int i) {
		return this.num[i];
	}
	
	// ??????????????¢??????????????????
	public int[] roll(String order) {
		int now_1 = 1;	int now_2 = 2;	int now_3 = 3;	int tmp;
		int[] array = getNum();
		char[] check = {'N', 'E', 'S', 'W'};
		for (int i = 0; i < order.length(); i++) {
			for (int j = 0; j < check.length; j++) {
				if (order.charAt(i) == check[j]) {
					switch (j + 1) {
						case 1:
							tmp = now_1;
							now_1 = now_2;
							now_2 = 7 - tmp;
							break;
						case 2:
							tmp = now_1;
							now_1 = 7 - now_3;
							now_3 = tmp;
							break;
						case 3:
							tmp = now_1;
							now_1 = 7 - now_2;
							now_2 = tmp;
							break;
						case 4:
							tmp = now_1;
							now_1 = now_3;
							now_3 = 7 - tmp;
							break;
					}
				}
			}
		}
		int[] cp_array = new int[array.length];
		cp_array[0] = array[now_1]; cp_array[1] = array[now_2];
		cp_array[2] = array[now_3]; cp_array[3] = array[7 - now_3];
		cp_array[4] = array[7 - now_1]; cp_array[5] = array[7 -now_2];
		return cp_array;
	}
}

Measured memory_bytes: 26236
import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

mod = 998244353

def main():
    n = int(input())
    XY = []
    X = set()
    Y = set()
    for i in range(n):
        x,y = map(int, input().split())
        XY.append((x, y))
        X.add(x)
        Y.add(y)

    X = list(X)
    Y = list(Y)
    X.sort()
    Y.sort()
    dx = {}
    for i, x in enumerate(X):
        dx[x] = i
    dy = {}
    for i, y in enumerate(Y):
        dy[y] = i

    XY.sort()
    XY = [(dx[x], dy[y]) for x, y in XY]

    class BIT:
        def __init__(self, n):
            self.n = n
            self.bit = [0]*(self.n+1) # 1-indexed

        def init(self, init_val):
            for i, v in enumerate(init_val):
                self.add(i, v)

        def add(self, i, x):
            # i: 0-indexed
            i += 1 # to 1-indexed
            while i <= self.n:
                self.bit[i] += x
                i += (i & -i)

        def sum(self, i, j):
            # return sum of [i, j)
            # i, j: 0-indexed
            return self._sum(j) - self._sum(i)

        def _sum(self, i):
            # return sum of [0, i)
            # i: 0-indexed
            res = 0
            while i > 0:
                res += self.bit[i]
                i -= i & (-i)
            return res

        def lower_bound(self, x):
            s = 0
            pos = 0
            depth = self.n.bit_length()
            v = 1 << depth
            for i in range(depth, -1, -1):
                k = pos + v
                if k <= self.n and s + self.bit[k] < x:
                        s += self.bit[k]
                        pos += v
                v >>= 1
            return pos

    UL = [0]*n
    UR = [0]*n
    LL = [0]*n
    LR = [0]*n

    bit = BIT(2*10**5+5)
    for i in range(n):
        x, y = XY[i]
        LL[i] = bit.sum(0, y+1)
        UL[i] = i-LL[i]
        bit.add(y, 1)

    bit = BIT(2*10**5+5)
    for i in reversed(range(n)):
        x, y = XY[i]
        LR[i] = bit.sum(0, y+1)
        UR[i] = (n-1-i)-LR[i]
        bit.add(y, 1)

    #print(LL)
    #print(UL)
    #print(LR)
    #print(UR)

    ans = 0
    for i in range(n):
        ans += (pow(2, UL[i], mod)-1)*(pow(2, LR[i], mod)-1)*pow(2, UR[i], mod)*pow(2, LL[i], mod)
        ans += pow(2, UL[i], mod)*pow(2, LR[i], mod)*(pow(2, UR[i], mod)-1)*(pow(2, LL[i], mod)-1)
        ans -= (pow(2, UL[i], mod)-1)*(pow(2, LR[i], mod)-1)*(pow(2, UR[i], mod)-1)*(pow(2, LL[i], mod)-1)
        ans += pow(2, UL[i], mod)*pow(2, LR[i], mod)*pow(2, UR[i], mod)*pow(2, LL[i], mod)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 194920
def solve(a, op, b):
    ans = 0
    if op == '+':
        ans = int(a) + int(b)
    else:
        ans = int(a) - int(b)
    return ans
 
 
def main():
    a, op, b = map(str, input().split())
    ans = solve(a, op, b)
    print(ans)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int n;
   cin >> n;
   vector<string>x(n);
   vector<double>y(n);
   rep(i,n) cin >> y[i] >> x[i];

   double sum = 0;
   rep(i,n){
      if(x[i] == "JPY"){
         sum += y[i]; 
      }else{
         sum += y[i]*380000;
      }
   }

   cout << fixed << setprecision(5) << sum << endl;



   return 0;
}

Measured memory_bytes: 256
n = int(input())
t = [int(input()) for _ in range(n)]


#a>b
def gcd(a, b):
    if b:
        return gcd(b, a%b)
    else:
        return a

def lcm(a, b):
    if a>b:
        g = gcd(a, b)
        return a*b//g
    else:
        g = gcd(b, a)
        return a*b//g

ans = 1
for i in range(n):
    ans = lcm(ans, t[i])

print(ans)

Measured memory_bytes: 3064
import collections
import math

H, W = map(int, input().split())
bomb_dict = collections.defaultdict(bool)
count_dict = collections.defaultdict(int)
for i in range(H):
    S = input()
    for j in range(len(S)):
        if S[j] == '#':
            bomb_dict[i, j] = True
            count_dict[i - 1, j - 1] += 1
            count_dict[i - 1, j] += 1
            count_dict[i - 1, j + 1] += 1

            count_dict[i, j - 1] += 1
            count_dict[i, j + 1] += 1

            count_dict[i + 1, j - 1] += 1
            count_dict[i + 1, j] += 1
            count_dict[i + 1, j + 1] += 1

for i in range(H):
    for j in range(W):
        if bomb_dict[i, j]:
            print('#', end='')
        else:
            print(count_dict[i, j], end='')

    print()


Measured memory_bytes: 46572
h,w = map(int, raw_input().split())
i = 1
j = 0
while True:
    s = raw_input()
    if len(s) > 6:
        s = s.split(' ')
    try:
        j = s.index("snuke") + 1
        break
    except ValueError:
        i += 1

print "{0}{1}".format(chr(64+j), i)

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

using namespace std;
#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

double PI=3.141592653589793;


void solve(){
	string in;
	cin >> in;
	forn(i,sz(in)){
		if(in[i]=='?') in[i]='D';
	}
	cout << in;
//	cout << cnt;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
	//	cout << "Case #" << cid << ": ";
		solve();
	}
}


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

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

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p;
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    p.push_back(make_pair(a-1, b));
  }
  int init = 0;
  if(n > 1) init = pow(10, n-1);
  else init = 0;
  for (int i = init; i < pow(10, n); i++)
  {
    string s = to_string(i);
    bool ans = true;
    for (int j = 0; j < p.size(); j++)
    {
      int index = p.at(j).first;
      int num = p.at(j).second;
      if(s.at(index) - '0' != num) ans = false;
    }
    if(ans)
    {
      cout << s << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    private final static Scanner sc = new Scanner(System.in);

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int n = nextInt();
        int sum = 0;

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

            sum += Math.abs(l - r) + 1;
        }

        out(sum);
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt();
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}

Measured memory_bytes: 25712
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e18;

using namespace std;

/*===========================================*/

ll gcd( ll m, ll n )
{
	if ( ( 0 == m ) || ( 0 == n ) ) return 0;
  if(m < n){
    swap(m,n);
  }
	while(n > 0){
    ll r = m % n;
    m = n;
    n = r;
  }

	return m;
}

ll lcm( ll m, ll n )
{
	if ( ( 0 == m ) || ( 0 == n ) ) return 0;
	return ((m / gcd(m, n)) * n);
}

/*===========================================*/

int N;
ll T[105];

int main(){
  cin>>N;
  REP(i,0,N){
    cin>>T[i];
  }

  ll ans = T[0];
  REP(i,1,N){
    ans = lcm(ans, T[i]);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let S = read string

    seq {
        for i in 0 .. S.Length - 1 do
            if S.[i] = 'C' then
                for j in i + 1 .. S.Length - 1 do
                    if S.[j] = 'F' then yield ()
    }
    |> Seq.length
    |> fun x ->
        if x > 0 then "Yes"
        else "No"
    |> printfn "%s"
    0 // return an integer exit code


Measured memory_bytes: 14160
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
using namespace std;
int main(){
	
	int n;
	long long int m;
	while(cin>>n>>m,n!=0&&m!=0){
	
	vector<long long> v(n+1,0);
	vector<long long> s;

	
	for(int i=1;i<=n;i++)
		cin>>v[i];
		
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				s.push_back(v[i]+v[j]);
			}
		}
	
	
	
	sort(s.begin(),s.end());
	long long ans=0;
		for(int i=0;i<s.size();i++){
	vector<long long>::iterator it=upper_bound(s.begin(),s.end(),m-s[i]);
			if(it!=s.begin()){
				it--;
			ans=max(ans,s[i]+s[it-s.begin()]);
			}
		}
	cout<<ans<<endl;
	}

	
}

Measured memory_bytes: 17176
{-# OPTIONS_GHC -O2 #-}

import qualified Data.ByteString.Char8 as C
import Data.List
import qualified Data.Vector.Unboxed as U

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main = do
    n <- readLn :: IO Int
    as <- (sortBy (flip compare)) <$> r'
    print $ sum (take (div (n-1) 2 + 1) (map (*2) as))
        - head as
        - (if odd n then as!!(div (n-1) 2) else 0)


Measured memory_bytes: 35432
#include<iostream>
using namespace std;
 
int main(){
  	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
    int n;
    cin>>n;
    int a[n], b[n], c[n], dp[3][n];
    for (int i=0; i<n; i++)
        cin>>a[i]>>b[i]>>c[i];
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for (int i=1; i<n; i++){
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout<<max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1]));
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  ll x;
  cin >> x;
  ll now = 100;
  int cnt = 0;
  while (now < x) {
    double k = now;
    now = floor(k * 1.01);
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3768
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N;
    cin >> N;

    map<long long, long long> m;
    m[-1] = 3;
    long long c = 1;
    for (long long i = 0; i < N; i++)
    {
        long long t;
        cin >> t;
        c *= (m[t - 1] - m[t]);
        c %= MOD;
        m[t]++;
    }

    cout << c << endl;
}

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

int main(){
  unsigned long long N, M, d, cnt = 0;
  cin >> N >> M;

  if(2 * N <= M){
    cnt += N;
    M -= 2 * N;
    if(M >= 4){
      cnt += M / 4;
    }
  }else{
    if(M >= 2){
      cnt += M / 2;
    }
  }
  cout << cnt << endl;
}


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

int main(){
  int A,B,M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  int mina=1001001001, minb=1001001001;
  for(int i=0;i<A;i++){
    cin >> a[i];
    mina = min(mina,a[i]);
  }
  for(int i=0;i<B;i++){
    cin >> b[i];
    minb = min(minb,b[i]);
  }
  
  int ans = mina + minb;
  for(int i=0;i<M;i++){
    int x,y,c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans,a[x]+b[y]-c);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
from bisect import bisect_left, bisect_right

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

cnt = 0

for b_e in b:
    a_cases = bisect_left(a, b_e)
    c_cases = bisect_right(c, b_e)
    cnt += a_cases * (n - c_cases)
print(cnt)

Measured memory_bytes: 29352
n = gets.to_i
a, b = gets.split(' ').map(&:to_i)
point_list = gets.split(' ').take(n).map(&:to_i)

list1 = point_list.select { |n| n <= a }
list2 = point_list.select { |n| a + 1 <= n && n <= b }
list3 = point_list.select { |n| b + 1 <= n }

puts [list1.size, list2.size, list3.size].min


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int s;
  cin >> s;
  set<int> st; // set 集合
  int x = s;
  while (st.count(x) == 0)
  {
    st.insert(x);
    if (x % 2 == 0)
    {
      x /= 2;
    }
    else
    {
      x = x * 3 + 1;
    }
  }
  cout << st.size() + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
 
public class AtCoder{
	public static void Main(){
		string[] s;
		s = Console.ReadLine().Trim().Split(' ');
		int n,m;
		n = int.Parse(s[0]);
		m = int.Parse(s[1]);
		
		long[] cp = new long[m];
		int[] y = new int[m];
		int[] x = new int[m];
		int[] o = new int[m];
		for (int i = 0; i < m; i++){
			o[i] = i;
			s = Console.ReadLine().Trim().Split(' ');
			cp[i] = long.Parse(s[0]);
			y[i] = int.Parse(s[1]);
			x[i] = int.Parse(s[1]);
		}
		Array.Sort(y,cp);
		Array.Sort(x,o);
		
		long[] p = new long[n];
		long[] ans = new long[m];
		string t;
		for (int i = 0; i < m; i++){
			p[cp[i]-1]++;
			ans[o[i]] = p[cp[i]-1] + cp[i]*1000000;
		}
		for (int i = 0; i < m; i++){
			t = ans[i].ToString();
			while(t.Length<12){
				t = "0"+t;
			}
			Console.WriteLine(t);
		}
		
	}
}

Measured memory_bytes: 20024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int N; cin >> N;
  vector<int> A(N+2);
  A.at(0) = 0;
  for(int i = 1; i <= N; i++){
    cin >> A.at(i);
  }
  A.at(N+1) = 0;
  int money = 0;
  rep(i, N+1) money += abs(A.at(i+1) - A.at(i));
  vector<int> ans(N+1);
  for(int i = 1; i <= N; i++){
    ans.at(i) = money - abs(A.at(i+1)-A.at(i)) - abs(A.at(i)-A.at(i-1)) + abs(A.at(i+1)-A.at(i-1));
  }
  for(int i = 1; i <= N; i++){
    cout << ans.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 4028
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a; cin >> a;
    cout << a*a*a+a*a+a << ln;
}


Measured memory_bytes: 3644
a, b = [int(i) for i in input().split()]
small = min(a, b)
big = max(a, b)

import sys

if small == 1:
    print(1)
    sys.exit(0)

import math
import collections

# FYI: https://ja.wikipedia.org/wiki/%E8%A9%A6%E3%81%97%E5%89%B2%E3%82%8A%E6%B3%95
def prime_factorization(num, divisors=None):
    if num <= 1:
        assert False
    factors = []

    # divisorsを使い回せるようにする。
    #   - 二度生成した場合にかかる時間が許容できない場合
    #   - エラトステネスの篩などで素数テーブルを既に持っている場合
    if not divisors:
        divisors = [2] + [i for i in range(3, int(math.sqrt(num)) + 1) if i % 2 != 0]

    for d in divisors:
        # divisorsを引数で与えた場合のみ起こりうる
        if num < d:
            break
        while num % d == 0:
            factors.append(d)
            num //= d

    if num != 1:
        factors.append(num)
    return factors

#divisors = [2] + [i for i in range(3, int(math.sqrt(big)) + 1) if i % 2 != 0]
#small_factors = set(prime_factorization(small, divisors))
#big_factors = set(prime_factorization(big, divisors))
small_factors = set(prime_factorization(small))
big_factors = set(prime_factorization(big))

print(len(small_factors.intersection(big_factors)) + 1)


Measured memory_bytes: 29840
/*
      author  : nishi5451
      created : 14.08.2020 19:55:30
*/

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


int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i+=2){
        int now = 0;
        for(int j=1; j<=i; j++){
            if(i%j==0) now++;
        }
        if(now == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3468
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int K = sc.nextInt();
    	StringBuilder sb = new StringBuilder();
    	Set<Integer> set = new HashSet<>();
    	for (int i = A; i < A+K; i++) {
    		if (i <= B) {
    			set.add(i);
    		}
    	}
    	for (int i = B-(K-1); i < B+1; i++) {
    		if (A <= i) {
    			set.add(i);
    		}
    	}
    	List<Integer> list = new ArrayList<>(set);
    	Collections.sort(list);
    	for (int i = 0; i < list.size(); i++) {
    		if (i < K || list.size() - 1 - K < i) {
    			sb.append(list.get(i) + "\n");
    		}
    	}
    	System.out.println(sb);
    }
}

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

#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)

const int maxN = 1e5 + 1;

bool check(long long n, int i) {
  while (n > 0 && n % i == 0)
    n /= i;
  return (n % i == 1);
}
int main() {
  FASTIO;
  long long n;
  cin >> n;
  set<long long> ans;
  ans.insert(n);
  for (int i = 2, end = sqrt(n); i <= end; i++) {
    if (n % i == 0 && check(n, i)) {
      ans.insert(i);
      if (n % (n / i) == 0 && check(n, n / i))
        ans.insert(n / i);
    }
  }
  --n;
  ans.insert(n);
  for (int i = 2, end = sqrt(n); i <= end; i++) {
    if (n % i == 0) {
      ans.insert(i);
      if (n % (n / i) == 0)
        ans.insert(n / i);
    }
  }
  ans.erase(0), ans.erase(1);
  cout << (int) ans.size() << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int mod = 1_000_000_007;
		
		int count[] = new int[26];

		for(int i = 0 ; i < n ; i ++) {
			count[s[i]- 'a']++;
		}
		long sum = 1;
		for(int i = 0 ;i < 26; i++) {
			sum = (sum  * (count[i]+1)) % mod;
		}
		System.out.println(sum-1);
		
	}
}


Measured memory_bytes: 25940
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    input! {
        s: String,
    }
    let mut ans = 0;
    for c in s.chars() {
        if c == '1' {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<stack>
using namespace std;
string str;

bool solve(){
  stack<char> st;
  for(int i=0;i<(int)str.size();i++){
    if(str[i]=='(')st.push(str[i]);
    else if(str[i]=='[')st.push(str[i]);
    else if(str[i]==')'){
      if(st.empty())return false;
      if(st.top()!='(')return false;
      st.pop();
    }else if(str[i]==']'){
      if(st.empty())return false;
      if(st.top()!='[')return false;
      st.pop();
    }
  }
  return st.empty();
}

int main(){
  while(1){
    getline(cin,str);
    if(str==".")break;
    if(solve())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int num;
    cin >> n;
    vector<int>ans(n + 1,0);

    for(int x = 1; x< 100; x++)
    {
        for(int y = 1; y < 100; y++)
        {
            for(int z = 1; z < 100; z++)
            {
                num = x * x + y * y + z * z + x * y + y * z + z * x;
                if(num <= 10000)
                    ans[num]++;
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3556
def edpcA(n, hs):
    hm2, hm1 = hs[0], hs[1]
    dp = [0, abs(hm2-hm1)]
    hs = list(reversed(hs[2:]))
    for i in range(2, n):
        h = hs.pop()
        d1 = dp[i-1] + abs(h-hm1)
        d2 = dp[i-2] + abs(h-hm2)
        dp.append(min(d1, d2))
        hm2, hm1 = hm1, h
    print(dp[-1])
n = int(input())
hs = list(map(int, input().split(' ')))
edpcA(n, hs)

Measured memory_bytes: 13980
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    que = deque(r[1:])
else:
    que = deque(r)

i = 0
while True:
    for num in r:
        new = que[i]*10 + num
        que.append(new)
    if que[-1] >= 10**6:
        break
    i += 1

ind = bisect.bisect_left(que, N)
#print(que)
#print(ind)
print(que[ind])

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

bool linear_search(int A[], int n, int key) {
    int i = 0;
    A[n] = key;
    while(A[i] != key) {
        i++;
    }
    return i != n;
}

bool linear_search2(int A[], int n, int key) {
    for (int i = 0; i < n; ++i) {
        if(A[i] == key) {
            return true;
        }
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; ++i) {
        cin >> S[i];
    }
    int q;
    int count = 0;
    cin >> q;
    int t;
    for (int j = 0; j < q; ++j) {
        cin >> t;
        if(linear_search2(S, n, t)){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3104
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	if(a <= c && c <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int selectionSort(int A[],int N){
int i,j,t,sw=0,minj;
for(i=0;i<N-1;i++){
minj=i;
for(j=i;j<N;j++){
if(A[j]<A[minj]) minj=j;
}
t=A[i];A[i]=A[minj];A[minj]=t;
if(i!=minj) sw++;
}
return sw;
}
int main(){
int A[100],N,i,sw;
scanf("%d",&N);
for(i=0;i<N;i++) scanf("%d",&A[i]);
sw=selectionSort(A,N);
for(i=0;i<N;i++){
if(i>0) printf(" ");
printf("%d",A[i]);
}
printf("\n");
printf("%d\n",sw);
return 0;
}

Measured memory_bytes: 3212
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, M;
Vec< Vec< int > > adj;
Vec< int > vis;

bool dfs(int v, int x) {
	if (vis[v] != -1) return vis[v] == x;
	vis[v] = x;
	for (int u : adj[v]) if (!dfs(u, 1-x)) return false;
	return true;
}

int main() {
	cin >> N >> M;
	adj.assign(N, Vec< int >());
	
	for_(i,0,M) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	vis.assign(N, -1);
	if (dfs(0, 0)) {
		int A = accumulate(allof(vis), int());
		int B = N - A;
		cout << (lint)A * B - M << endl;
	} else {
		cout << (lint)N * (N-1) / 2 - M << endl;
	}
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 6400
#include<algorithm>
#include<iostream>
#include<numeric>
#include<stdio.h>
 
using namespace std;

int main(){
int n;
	char str[9];
	std::cin >> n;
  while( n-- ){
  	cin >> str;
         
		sort(str,str+8,greater<int>());
		int max=atoi(str);
		sort(str,str+8);
		int min=atoi(str);
		cout<<max-min<<endl;
	}
	
}

Measured memory_bytes: 1192
{
  const main = (input: string): void | string | number => {
    const r = reader(input)
    const N = r.n()
    const a = r.ns()

    const dp: number[][] = []

    dp[0] = []
    dp[0][0] = 0
    dp[0][1] = -Infinity
    for (let i = 1; i < N + 1; i++) {
      // console.log(dp[i - 1])
      dp[i] = []
      dp[i][0] = Math.max(dp[i - 1][0] + a[i - 1], dp[i - 1][1] - a[i - 1])
      dp[i][1] = Math.max(dp[i - 1][0] - a[i - 1], dp[i - 1][1] + a[i - 1])
    }
    // console.log(dp[N - 1])

    return dp[N][0]
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const res = main(getInput())

  if (typeof res === 'number' || typeof res == 'string') console.log(res)
}


Measured memory_bytes: 53720
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if(x-r < 0 || y-r < 0 || x+r > w || y+r > h) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1160
import sys,heapq

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,K=map(int,input().split())
hen={i:[] for i in range(1,N+1)}
for i in range(0,N-1):
    a,b=map(int,input().split())
    hen[a].append(b)
    hen[b].append(a)

parent={i:-1 for i in range(1,N+1)}
parent[1]=0
q=[1]
heapq.heapify(q)
sub=[]
heapq.heapify(sub)
while q:
    while q:
        x=heapq.heappop(q)
        for p in hen[x]:
            if parent[p]==-1:
                parent[p]=x
                heapq.heappush(sub,p)
        #何らかの操作
        #ここでsubキューに次に使うものを格納
        if q==[]:
            q=sub
            sub=[]
            heapq.heapify(sub)
            break

ans={i:1 for i in range(1,N+1)}
flag={i:0 for i in range(1,N+1)}
q=[]
for i in range(1,N+1):
    if i!=1 and len(hen[i])==1:
        q.append(i)
sub=[]
heapq.heapify(sub)
while q:
    while q:
        x=heapq.heappop(q)
        p=parent[x]
        if p!=1:
            if len(hen[p])-1>K-2:
                ans[p]=0
            else:
                ans[p]=(ans[p]*ans[x])%mod
            flag[p]+=1
            if flag[p]==len(hen[p])-1:
                ans[p]=(ans[p]*g1[K-2]*g2[K-2-flag[p]])%mod
                heapq.heappush(sub,p)
        #何らかの操作
        #ここでsubキューに次に使うものを格納
        if q==[]:
            q=sub
            sub=[]
            heapq.heapify(sub)
            break

if len(hen[1])>K-1:
    print(0)
else:
    for i in hen[1]:
        ans[1]=(ans[1]*ans[i])%mod
    ans[1]=(ans[1]*g1[K]*g2[K-1-len(hen[1])])%mod
    print(ans[1])

Measured memory_bytes: 122116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i1 = sc.nextInt();
		int i2 = sc.nextInt();
		int i1g = 3;
		int i2g = 4;

		int g1[] = new int[7];
		int g2[] = new int[4];

		g1[0] = 1;
		g1[1] = 3;
		g1[2] = 5;
		g1[3] = 7;
		g1[4] = 8;
		g1[5] = 10;
		g1[6] = 12;

		g2[0] = 4;
		g2[1] = 6;
		g2[2] = 9;
		g2[3] = 11;



		if (i1 == 2 && i2 == 2 ){
			System.out.println("Yes");
		}else{

			for (int  i=0; i<7; i++){
				if (i1 == g1[i]){
					i1g =1;
				}
				if (i2 == g1[i]){
					i2g =1;
				}
			}

			for (int  i=0; i<4; i++){
				if (i1 == g2[i]){
					i1g =2;
				}
				if (i2 == g2[i]){
					i2g =2;
				}
			}

			if (i1g == i2g){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}

		sc.close();
	}

}

Measured memory_bytes: 21972
<?php
fscanf(STDIN,"%d",$N);
for($i=0;$i<$N;$i++){
    fscanf(STDIN,"%d %d",$A[$i],$B[$i]);
    $AB[$i] = $A[$i]+$B[$i];
}
$Tak=0;
$Aok=0;
$i = 0;
arsort($AB);
foreach($AB as $k => $val) {
    if($i%2) {
        $Aok += $B[$k];
    }else{
        $Tak += $A[$k];
    }
    $i++;
}
echo ($Tak - $Aok);
?>

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n);
  rep(i, n) cin >> a[i];
  int cnt = 0;
  bool update = true;
  while(update) {
    update = false;
    bool flag = true;
    rep(i, n) {
      flag &= (a[i]%2 == 0);
      a[i] /= 2;
    }
    update = flag;
    if(update) ++cnt;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
vector<int> mode2(vector<int> a){
    sort(a.begin(),a.end());
    int temp1,temp1n;
    int temp2,temp2n;
    int p = 0;
    temp1n = 0;
    temp2n = 0;
    for(int i = 0;i<a.size() - 1;i++){
        if (a[i] == a[i + 1]){
            p++;
        }
        else{
            if(temp1n < p+1){
                temp2 = temp1;
                temp2n = temp1n;
                temp1n = p + 1;
                temp1 = a[i];
            }
            else if(temp2n < p+1){
                temp2n = p + 1;
                temp2 = a[i];
            }
            p = 0;
        }
    }
    if(a[a.size()-2] == a[a.size()-1]){
        if(temp1n < p+1){
            temp2 = temp1;
            temp2n = temp1n;
            temp1n = p + 1;
            temp1 = a[a.size()-1];
        }
        else if(temp2n < p+1){
            temp2n = p + 1;
            temp2 = a[a.size()-1];
        }
    }
    vector<int> mode = {temp1,temp1n,temp2,temp2n};
    return mode;
}

int main(){
    int n;
    cin >> n;
    vector<int> a;
    vector<int> b; 
    int p;
    for(int i = 0;i<(n/2);i++){
        cin >> p;
        a.push_back(p);
        cin >> p;
        b.push_back(p);
    }
    vector<int> amode = mode2(a);
    vector<int> bmode = mode2(b);
    int ans;
    if(amode[0] != bmode[0]){
        ans = n - amode[1] - bmode[1];
    }
    else{
        ans = min(n - amode[3] - bmode[1],n - amode[1] - bmode[3]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

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

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = (a); (i) < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

int main(int argc, const char* argv[]) {
  string s;
  cin >> s;
  
  u64 l = s.length();
  
  vector<u64> b(2, 0);
  vector<u64> w(2, 0);
  
  rep(i, l) {
    if(s[i] == '0') {
      ++b[i % 2];
    } else {
      ++w[i % 2];
    }
  }
  
  cout << min(b[0] + w[1], b[1] + w[0]) << endl;
  
  return 0;
}


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

ll euclidean_gcd(ll a, ll b) {
  if(a < b) euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
	ll N;
    cin >> N;
	ll a,b,ans,tmp;
	cin >> a;
	ans = a;
	for (ll i(0);i<N-1;++i){
		cin >> b;
		tmp = euclidean_gcd(a,b);
		if (tmp < ans){
			ans = tmp;
		}
		a = b;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){
	int m,f,r,pls,i;
	m=0;
	f=0;
	r=0;
	
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		pls=m+f;
		if(m==-1 && f==-1 && r==-1){
			return 0;
		}else if(m<0 || f<0){
			printf("F\n");
		}else if(pls>=80){
			printf("A\n");
		}else if(pls<80 && pls>=65){
			printf("B\n");
		}else if(pls<65 && pls>=50 || pls<50 && pls>=30 && r>=50){
			printf("C\n");
		}else if(pls<50 && pls>=30 && r<50){
			printf("D\n");
		}else {
			printf("F\n");
		}
	}
}

Measured memory_bytes: 584
N = int(input())
A = list(map(int, input().split()))
is_ok = True

for i in range(N):
  if A[i] % 2 == 0:
    if A[i] % 3 != 0 and A[i] % 5 != 0:
      is_ok = False
      break

if is_ok:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
#include<stdio.h>
#define N 10000
int A[2000001],C[N],B[2000001];
int main()
{
  int i,n;

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

  for(i=0;i<N;i++){
    C[i]=0;
  }
  for(i=1;i<n+1;i++){
    C[A[i]]+=1;
  }
  for(i=0;i<N;i++){
    C[i]+=C[i-1];
  }
  for(i=n+1;i>0;i--){
    B[C[A[i]]]=A[i];
    C[A[i]]-=1;
  }

  for(i=1;i<n;i++){
    printf("%d ",B[i]);
  }
  printf("%d",B[i]);
  printf("\n");
  return 0;
}



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

#define N 100

int comp(const void *a,const void *b);

int main(){
	int i;//,j,k,l;
	int n;
	int l[2*N];
	int res = 0;
	scanf("%d",&n);
	for(i = 0;i < 2 * n;i++){
		scanf("%d",&l[i]);
	}

	qsort(l,2*n,sizeof(int),comp);
	for(i = 0;i < n;i++){
		res += l[2*i];
	}
	printf("%d\n", res);

	return 0;
}

int comp(const void *a,const void *b){
	return *(int*)a - *(int*)b;
}

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

map<int,vector<int>> graph;

int dfs(int node,vector<int> &dp)
{
    if(dp[node]!=0)
    return dp[node];
    
    for(auto i:graph[node])
    {
        dp[node]=max(dp[node],dfs(i,dp));
    }
    dp[node]++;
    return dp[node];
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        graph[a].push_back(b);
    }
    
    vector<int> dp(n+1);
    for(int i=1;i<=n;i++)
    {
        if(dp[i]==0)
        {
            dp[i]=dfs(i,dp);
        }
    }
    int maxm=0;
    for(int i=1;i<=n;i++)
    {
        maxm=max(maxm,dp[i]);
    }
    cout<<maxm-1;
    
}

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

#define IO                       \
    std::ios_base::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define LL long long
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;

const int INF = 0x3f3f3f3f;

int main(void) {
    IO;

    int n, m;

    cin >> n >> m;
    if (n == m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
        

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <complex>
#include <algorithm>
using namespace std;

#define X real()
#define Y imag()

typedef complex<double> Point;

Point ps[4];

int main() {
  while (1) {
    for (int i=0; i<4; i++) {
      double x, y;
      if (scanf("%lf%lf", &x, &y) != 2) return 0;
      ps[i] = Point(x, y);
    }
  
    if (max(ps[0].X, ps[2].X) > min(ps[1].X, ps[3].X)) puts("NO");
    else if (max(ps[0].Y, ps[2].Y) > min(ps[1].Y, ps[3].Y)) puts("NO");
    else puts("YES");
  }
}

Measured memory_bytes: 2624
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
			break;
		}
	}
}


Measured memory_bytes: 2768
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  int ans = 0;
  for(int i = 0; i < n; i++) {
    cin >> p[i];
    if(i >= 2) {
      vector<int> v{p[i-2], p[i-1], p[i]};
      sort(begin(v), end(v));
      if(v[1] == p[i-1]) ans++;
    }

  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(void)
{
    int n;

    while(std::cin >> n)
    {
        int result = 0;
        
        for(int a = 0; a < 10; ++a)
        {
            for(int b = 0; b < 10; ++b)
            {
                for(int c = 0; c < 10; ++c)
                {
                    for(int d = 0; d < 10; ++d)
                    {
                        result += (a + b + c + d == n);
                    }
                }
            }
        }
        
        std::cout << result << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3072