akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VMM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

uread :: VU.Unbox a => Int -> VM.IOVector a -> a    
uread i v = unsafePerformIO $ VM.read v i

uwrite :: VU.Unbox a => Int -> a -> VM.IOVector a -> VM.IOVector a
uwrite i !a v = unsafePerformIO $ VM.write v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VM.IOVector a -> VM.IOVector a
umodify i f v = unsafePerformIO $ VM.modify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VM.IOVector a
uthaw = unsafePerformIO . VU.thaw

ufreeze :: VU.Unbox a => VM.IOVector a -> VU.Vector a
ufreeze = unsafePerformIO . VU.freeze

dijkstra
  :: Int  -- ^ nodes
  -> V.Vector (VU.Vector (Int, Double))  -- ^ edges from i-th node: (end, cost)
  -> Int  -- ^ start node
  -> VU.Vector Double  -- ^ constructed graph
dijkstra !n !edges !s =
  ufreeze $ snd $ fix (\f (nodes,costs) -> case S.minView nodes of
    Nothing -> (S.empty,costs)
    Just ((c,n), nodes) ->
      if c <= uread n costs
        then
          let es = edges V.! n in
            f $ VU.foldl' (\(!ns,!cs) (!e,!ec) ->
              let c' = c + ec in c' `seq` if c' < uread e costs
                then let a = S.insert (c',e) ns; b = uwrite e c' cs in a `seq` b `seq` (a, b)
                else (ns,cs)
              ) (nodes,costs) es
        else f (nodes,costs)) (nodes0,costs0)
  where
    costs0 :: VM.IOVector Double
    costs0 = uwrite s 0 (uthaw $ VU.replicate n $ fromIntegral (maxBound :: Int))

    nodes0 :: S.Set (Double,Int)
    nodes0 = S.singleton (0,s)

solve :: Int -> Int -> Int -> Int -> Int -> VU.Vector (Int,Int,Int) -> Double
solve xs ys xt yt n xyr = graph VU.! (n+1)
  where
    big = fromIntegral (maxBound :: Int)

    dist2C :: (Int,Int,Int) -> (Int,Int,Int) -> Double
    dist2C (x1,y1,r1) (x2,y2,r2) = (sqrt (fromIntegral $ (x1-x2)^2 + (y1-y2)^2) - fromIntegral (r1+r2)) `max` 0

    toIndex (i,j) = i * (n+2) + j

    distMemo = ufreeze $ foldl' (\acc (i,j) ->
      let c1 = if i == n then (xs,ys,0) else if i == n+1 then (xt,yt,0) else xyr VU.! i
          c2 = if j == n then (xs,ys,0) else if j == n+1 then (xt,yt,0) else xyr VU.! j in
        uwrite (toIndex (i,j)) (dist2C c1 c2) acc
      ) (uthaw $ VU.replicate ((n+2)*(n+2)) big) [(i,j) | i <- [0..n+1], j <- [0..n+1], i /= j]
    edges = V.force $ V.generate (n+2) (\e -> VU.map (\i -> (i, distMemo VU.! toIndex (i,e))) $ VU.fromList [0..n+1])
    graph = dijkstra (n+2) edges n

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (xs,ys,xt,yt) <- (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2, vec VU.! 3)) . VU.unfoldrN 4 readInt <$> B.getLine
  n <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  xyr <- VU.replicateM n $ (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) . VU.unfoldrN 3 readInt <$> B.getLine
  print $ solve xs ys xt yt n xyr


Measured memory_bytes: 103804
import java.util.Scanner;

public class Main{
  static int a, b, c, d;

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

    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();
    d = sc.nextInt();

    System.out.println(Math.max(a * b, c * d));
  }
}


Measured memory_bytes: 23248
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef pair<int,int> P;

int main() {
    int i,j,p,q,temp;
    int flag=0;
    int count=1;
    int basunokazu=0;
    int n,c,k;
    string s;

    cin>>n>>c>>k;
    temp=n;
    int t[n];
    int a[n];
    for(i=0; i<n; ++i){
        cin>>t[i];
    }
    sort(t,t+n);
    for(i=0; i<n; ++i){
        if(count==c){flag=0;}//満員
        if(flag==0){temp=t[i];count=1;flag=1;++basunokazu;continue;}

        if(t[i]-temp>k){temp=t[i];count=1;++basunokazu;continue;}//時間切れ
        count++;
    }
    cout<<basunokazu;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vl;

#define all(x) x.begin(), x.end()
#define pb push_back
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define ford(i, n) for(int i = 1; i <= (int)(n); ++i)
#define en '\n'
#define debug(x) cout << #x  << " : " << x << en
#define debug2(x, y) cout << #x << " : " << x  << " " << #y << " : " << y << en

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

  int n;
  cin >> n;
  if(!(n%1000)) cout << 0;
  else cout << 1000*(n/1000 + 1)-n;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

#define N_MAX n+1

int main() {
	
	int x;
	cin >> x;
	
	double i,j,su;
	int ans=0;
	for(i=1;i<x;++i){
	    for(j=2;j<x;++j){
	        su = pow(i,j);
	        if(su>ans&&su<=x)ans=su;
	    }
	}
	if(x==1)cout<<"1";
	else cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

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

long long binpow(long long x, long long p) {
  long long res = 1;
  while (p > 0) {
    if (p & 1) {
      res = (res * x) % mod;
      p--;
    } else {
      x = (x * x) % mod;
      p /= 2;
    }
  }
  return res % mod;
}

long long inv(long long x) {
  return binpow(x, mod - 2) % mod;
}

int n;
string s;
int cntC, cntQ;
long long cntQQ, cntBC, cntBQ, cntQC;
long long ans;
long long totalQ;

int main() { 

  getline(cin, s);
  n = sz(s);

  for (int i = 0; i < n; i++) {
    if (s[i] == '?') {
      totalQ++;
    }
  }

  for (int i = n - 1; i >= 0; i--) {

    if (s[i] == 'A') {
      ans = (ans + 1ll * cntQQ * binpow(3, totalQ - 2) % mod) % mod;
      ans = (ans + 1ll * cntBC * binpow(3, totalQ) % mod) % mod;
      ans = (ans + 1ll * cntBQ * binpow(3, totalQ - 1) % mod) % mod;
      ans = (ans + 1ll * cntQC * binpow(3, totalQ - 1) % mod) % mod;
    }
    if (s[i] == '?') {
      ans = (ans + 1ll * cntQQ * binpow(3, totalQ - 3) % mod) % mod;
      ans = (ans + 1ll * cntBC * binpow(3, totalQ - 1) % mod) % mod;
      ans = (ans + 1ll * cntBQ * binpow(3, totalQ - 2) % mod) % mod;
      ans = (ans + 1ll * cntQC * binpow(3, totalQ - 2) % mod) % mod;
    }

    if (s[i] == 'B') {
      cntBC += cntC;
      cntBQ += cntQ;
    }
    if (s[i] == '?') {
      cntQQ += cntQ;
      cntQC += cntC;
    }
    if (s[i] == '?') {
      cntQ++;
    } 
    if (s[i] == 'C') {
      cntC++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

long gcd(long x, long y) {
  if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}

long num_divisible(long n, long k) { return n / k; }

int main(int argc, char *argv[]) {
  // read inputs
  long A, B, C, D;
  scanf("%ld %ld %ld %ld", &A, &B, &C, &D);

  // solve
  long g = C / gcd(C, D) * D;

  printf("%ld\n",
         (B - num_divisible(B, C) - num_divisible(B, D) + num_divisible(B, g)) -
             (A - 1 - num_divisible(A - 1, C) - num_divisible(A - 1, D) +
              num_divisible(A - 1, g)));

  return 0;
}


Measured memory_bytes: 128
import itertools

a = [int(input()) for i in range(5)]

perm = list(itertools.permutations(a))
ans = sum(a)+100

for b in perm:
	hoge = 0
	for i in range(5):
		hoge += b[i]
		if i != 4:
			hoge += (10-(hoge%10))%10
	ans = min(hoge,ans)
print(ans)





Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
    int n = 0;
    long int max = 0;
    long int temp = 0;
    long long sum = 0;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%d", &temp);

        if(temp < max){
            sum += (max - temp);
        } else {
            max = temp;
        }
    }

    printf("%ld",sum);
    
    return 0;
}

Measured memory_bytes: 2120
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b

YES = "Yes"
NO = "No"


def check(x, nums):
    x = abs(x)
    dp = [False] * (x + 1)
    dp[0] = True
    for y in nums:
        tmp = [False] * (x + 1)
        for i in range(len(dp)):
            if i + y < len(tmp):
                tmp[i + y] |= dp[i]
            if i - y >= 0:
                tmp[i - y] |= dp[i]
        dp = tmp
    return dp[x]


def solve(s, x, y):
    type_num = [(k, len(list(g))) for k, g in groupby(s)]
    if s[0] == "F":
        x -= type_num[0][1]
        type_num.pop(0)

    h, v = [], []
    now = 0
    for t, n in type_num:
        if t == "F":
            if now == 0:
                h.append(n)
            else:
                v.append(n)
        else:
            if n % 2 != 0:
                now = (now + 1) % 2
    return YES if check(x, h) and check(y, v) else NO


def main():
    s = input()
    x, y = map(int, input().split())

    print(solve(s, x, y))

if __name__ == '__main__':
    main()


Measured memory_bytes: 45148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=998244353;

int main(){
  int n,s;
  cin>>n>>s;
  int a[n];
  rep(i,0,n) cin>>a[i];
  ll dp[n+1][s+1];
  dp[0][0]=1;
  rep(i,1,s+1) dp[0][i]=0;
  rep(i,0,n){
    rep(j,0,s+1){
      dp[i+1][j]=2*dp[i][j];
      dp[i+1][j]%=mod;
      if(a[i]<=j){
        dp[i+1][j]+=dp[i][j-a[i]];
        dp[i+1][j]%=mod;
      }
    }
  }
  cout<<dp[n][s]<<endl;
}


Measured memory_bytes: 74012
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(let* ((x (read))
	   (y (read))
	   (z (read))
	   (k (floor x (+ y z))))
  (princ (if (<= (+ (* k (+ y z)) z) x)
		   k
		   (1- k))))


Measured memory_bytes: 15544
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
typedef double d;
typedef int i;
 
int main() {
  i w , a , b;
  cin >> w >> a >> b;
  if ( a < b && b - w - a > 0 ) cout << b - w - a;
  else if ( a < b && b - w - a <= 0 ) cout << 0;
  else if ( b < a && a - w - b > 0 ) cout <<  a - w - b;
  else cout << 0;
}

Measured memory_bytes: 256
N = int(input())
T = []
for _ in range(N):
    T.append(int(input()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
def lcm(a, b):
	return a * b // gcd (a, b)
if N == 1:
    print(T[0])
else:
    result = lcm(T[0],T[1])

    for x in range(2,N):
        result = lcm(result, T[x])

    print(result)
    


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

bool check(long long N, long long M, vector<long long> s, vector<long long> c, string str){
    if(str.size() != N) return false;
    for(long long i = 0; i < M; ++i){
        if(str[s[i]] != (char)(c[i] + '0')) return false;
    }
    return true;
}

void solve(long long N, long long M, std::vector<long long> s, std::vector<long long> c){
    for(int i = 0; i <= 999; ++i){
        string str = to_string(i);
        if(check(N, M, s, c, str)){
            cout << str << endl;
            return;
        }
    }
    cout << -1 << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> s(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&s[i]);
        s[i]--;
        scanf("%lld",&c[i]);
    }
    solve(N, M, std::move(s), std::move(c));
    return 0;
}


Measured memory_bytes: 3760
#2  次元平面上に辺の長さがそれぞれ L1,L2,...,LN の N 角形(凸多角形でなくてもよい)が描けるかを判定してください。
#ここで、次の定理を利用しても構いません。
#定理 : 一番長い辺が他の N−1 辺の長さの合計よりも真に短い場合に限り、条件を満たす N 角形が描ける。

N = int(input())
L = sorted(map(int, input().split()), reverse=True)

sum = 0
for i in range(1, N):
    sum = sum + L[i]

if sum>L[0]:
    print('Yes')
else:
    print('No')
    

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




bool check(string s, string dore, int cp) {
  int len_dore = dore.size();

  for(int i = 0; i < len_dore; i++) {
    if(s.at(i + cp) != dore.at(i)) {
      return false;
    }
  }

  return true;
}

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

  string dream = "dream", dreamer = "dreamer", erase = "erase", eraser = "eraser";
  int len_dream = dream.size(), len_dreamer = dreamer.size(), len_erase = erase.size(), len_eraser = eraser.size();
  int len_s = s.size();

  int current_pos = 0;

  while(1){
    //cout  << ' ' << current_pos << endl;
    if(current_pos == len_s) {
      cout << "YES" << endl;
      return 0;
    }
    else if(current_pos > len_s) {
      break;
    }
    
    if(current_pos + len_eraser <= len_s && check(s,eraser,current_pos)) {
    //  cout << 1 << endl;
      current_pos += len_eraser;
      continue;
    }
    else if(current_pos + len_erase <= len_s && check(s,erase,current_pos)) {
      //cout << 2 << endl;
      current_pos += len_erase;
      continue;
    }
    else if(current_pos + len_dreamer <= len_s && check(s,dreamer,current_pos)) {
    //  cout << 3 << endl;
      current_pos += len_dreamer;
      
      if(current_pos < len_s && s.at(current_pos) != 'd' && s.at(current_pos) != 'e') {
      //  cout << 4 << endl;
        current_pos -= len_dreamer;
        current_pos += len_dream;
      }
      continue;
    }
    else if(current_pos + len_dream <= len_s && check(s,dream,current_pos)) {
      //cout << 5 << endl;
      current_pos += len_dream;
      continue;
    }
    else {
      //cout << 6 << endl;
      break;
    }
  }
  
  cout << "NO" << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;
typedef unsigned long long ull;

#define f first
#define s second
#define en end()
#define bg begin()
#define rev reverse
#define mp make_pair
#define pb push_back
#define y1 y1234567890
#define um unordered_map                         
#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))

const ll INF = (ll)1e18;
const int inf = (int)1e9;
const ll mod = (ll)1e9 + 7;
const double pi = acos(-1.0);
const double eps = (double)1e-9;

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

const int N = 300500;

int n;
ll x[N], dp[N], t, e, dp2[N];

int main() {
	srand(time(NULL));

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	cout << setprecision(10) << fixed;

	cin >> n >> e >> t;

	for(int i = 1; i <= n; ++i)
		cin >> x[i];

	dp[0] = 0;
	
	int cur = 1;

	dp2[0] = INF;

	for(int i = 1; i <= n; ++i){
		while(t - 2LL * (x[i] - x[cur]) < 0)
			cur++;
		dp2[i] = min(dp2[i - 1], dp[i - 1] - 2LL * x[i]);
	   	dp[i] = min(dp2[cur - 1] + 2LL * x[i], dp[cur - 1] + t);
	}

	cout << dp[n] + e;

	//cerr << (clock() + 0.0) / 1000.0;
    return 0;
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int side = 0, row = 0, col = 0;
    vector< vector<int> > c(h, vector<int>(w, 0));
    rep(t, 0, n) {
        int x;
        cin >> x;
        for (int i = 0; i < x; ++i) {
            c[row][col] = t + 1;
            if (side == 0) ++col;
            else --col;
            if (col == w) row++, col = w - 1, side ^= 1;
            else if (col == -1) ++row, col = 0, side ^= 1; 
        }
    }
    for (auto &vec : c) {
        for (auto v : vec) cout << v << ' ';
        cout << '\n';
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    long long N;
    string x;
    set<string> S;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> x;
        S.insert(x);
    }

    cout << S.size() << endl;
}


Measured memory_bytes: 19192
# 全て赤にする
# 全て白にする
# 垢を左に集める

def main():
    n = int(input())
    c = input()
    all_r = c.count('R')
    all_w = c.count('W')
    trade = all_r - c[:all_r].count('R')
    print(min(all_r,all_w,trade))

    return 

if __name__ == "__main__":
    main()

Measured memory_bytes: 63196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Training
int main(void){
  fastio;
  string s;
  c(s);
  if(s == "ABC"){
    pl("ARC");
  }
  else{
    pl("ABC");
  }
}


Measured memory_bytes: 3648
#import heapq
#import itertools
#import math
#import numpy as np
#import sys

S = int(input())
#A,B = list(map(int, input().split()))
#S = [input() for _ in range(H)]
#T = [list(map(int,input().split())) for _ in range(N)]
#sys.exit()
print(int(S * S))

Measured memory_bytes: 2940
#include <stdio.h>

int main(){
  int A=0,B=0,C=0;
  scanf("%d %d %d",&A,&B,&C);
  if((A==7)&&(B==5)&&(C==5)){
    printf("YES\n");
  }else if((A==5)&&(B==7)&&(C==5)){
    printf("YES\n");
  }else if((A==5)&&(B==5)&&(C==7)){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long N, P; cin >> N >> P;
  string S; cin >> S;
  long long count = 0;
  if(P == 2 || P == 5) {
    for(long long i = 0; i < N; i++) {
      if((S.at(i) - '0') % P == 0) {
        count += (i + 1);
      }
    }
    cout << count << endl;
    return 0;
  }
  vector<long long> mods(P, 0);
  long long d = 1, m = 0;
  for(long long i = 0; i < N; i++) {
    m = ((S.at(N - 1 - i) - '0') * d + m) % P;
    //cout << m << endl;
    mods.at(m)++;
    d *= 10; d %= P;
  }
  mods.at(0)++;
  for(long long i = 0; i < P; i++) {
    count += (mods.at(i) * (mods.at(i) - 1) / 2);
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

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

using namespace std;
typedef long long unsigned int ll;


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

	string ss = s;
	REP(i, s.size()) {
		ss[i] = s[s.size() - 1 - i];
	}

	int cnt = 0;
	REP(i, s.size()) {
		if (s[i] != ss[i])cnt++;
	}

	cout << cnt / 2;

}

Measured memory_bytes: 256
from sys import stdin

N=int(stdin.readline().rstrip())
num_list=[int(x) for x in stdin.readline().rstrip().split()]
output=0
for n in range(N-2):
    if (num_list[n]-num_list[n+1])*(num_list[n+2]-num_list[n+1])<0:
        output+=1

print(output)

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

#define MAX_N 100006
using namespace std;

int black[MAX_N];
int red[MAX_N];

int main(){
    int n,m;
    scanf(" %d %d",&n, &m);
    for(int i=0;i<n;i++){
        black[i] = 1;
        red[i] = 0;
    }
    black[0] = 0;
    red[0] = 1;
    
    
    for(int i=0;i<m;i++){
        int x,y;
        scanf(" %d %d", &x, &y);
        x--; y--;
        if(black[x]>0){
            black[x]--;
            if(red[y]>0){
              red[y]++;
            } else {
              black[y]++;
            }
        } else if(red[x]>0){
            red[x]--;
            red[y] += 1 + black[y]; 
            black[y] = 0;
        }
        
    }
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(red[i]>0) cnt++;
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
package main


import (
    "fmt"
)

func main() {
    var A,B,C,D int32
    fmt.Scan(&A,&B,&C,&D)

    if  A+B > C+D {
      fmt.Println("Left")

    } else if A+B == C+D {
      fmt.Println("Balanced")

    } else {
      fmt.Println("Right")

    }


}


Measured memory_bytes: 512
n = int(input())
members = list(map(int, input().split(" ")))


sum = 0
for i in range(1, len(members)):
    if members[i] < members[i-1]:
        fumidai = members[i-1] - members[i]
        sum += fumidai
        members[i] += fumidai

print(sum)


Measured memory_bytes: 32200
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

	public static void main(String[] args){

		solve_abc159_d_();
	}
  
  	public static void solve_abc159_d_(){

		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();
		long[] A = new long[(int)N];

		Set<Long> as = new HashSet<Long>();
		int[] ar = new int[210000];
//		long[] ansr = new long[210000];
		long[] ansr_ = new long[210000];

		for(int i=0;i<N;i++){
			long ai =sc.nextLong();
			A[i] = ai;
			ar[(int)ai] += 1;
			as.add(ai);
		}
		
		long ans_base = 0;
		
		for(Long asi: as){
			long key = asi.longValue();
			long value = ar[(int)key];
			
			if(value >= 2){
				//ansr[(int)key]  = value * (value -1) / 2;
				ansr_[(int)key] = value * (value -1) / 2 - (value-1)  * (value-2) / 2;
				ans_base += value * (value -1) / 2;
			}
		}

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

			long ai = A[i];
			long ans = ans_base - ansr_[(int)ai];
			
			System.out.println(ans);
		}

		sc.close();

	}
}

Measured memory_bytes: 114344
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer arr[] = new Integer[n];

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

        Arrays.sort(arr, Comparator.reverseOrder());

        int alice = 0;
        int bob = 0;
        for (int i = 0; i < n; i+=2) {
            alice += arr[i];
        }
        for (int i = 1; i < n; i+=2) {
            bob += arr[i];
        }

        System.out.println(alice - bob);



    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
	int N,K;
	scanf("%d %d",&N,&K);
	int l[N];
	for(int i=0; i<N; i++){
		scanf("%d",&l[i]);
	}
	for(int i=0; i<N; i++){
		for(int j=N-1; j>i; j--){
			if(l[i] < l[j]){
				int tmp;
				tmp = l[i];
				l[i] = l[j];
				l[j] = tmp;
			}
		}
	}
	
	/*for(int i=0; i<N; i++){
		printf("%d ",l[i]);
	}
	printf("\n");*/

	int sum = 0;
	for(int i=0; i<K; i++){
		sum += l[i];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    
    int a[99999];
    int sign = 1;
    int d = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      d += a[i] * sign;
      sign *= -1;
    }
    cout << d;
    for (int i = 1; i < n; i++) {
      d = -d + a[i-1] * 2;
      cout << " " << d;
    }
    cout << endl;
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, K;
  cin >> N >> K;

  VL xs(N);
  cin >> xs;

  LL ans = 1e18;
  for(int B=0;B<(1<<N);++B){
    if(__builtin_popcount(B) != K) continue;

    LL sum = 0;
    LL mx = 0;
    REP(i,N){
      if(B>>i&1){
        if(xs[i] <= mx){
          sum += mx - xs[i] + 1;
          ++mx;
        }
        else{
          mx = xs[i];
        }
      }
      maxi(mx, xs[i]);
    }
    mini(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N,M=map(int, input().split())
key=[]
for i in range(M):
    a,b=map(int, input().split())
    C=list(map(int, input().split()))
    c=0
    for d in C:
        c+=2**(d-1)
    key.append((a,b,c))

dp=[10**8+10]*(2**N)
dp[0]=0
for bi in range(0,2**N):
    for i in range(M):
        t=key[i]
        a,b,c=t
        

        dp[bi|c]=min(dp[bi]+a,dp[bi|c])
if dp[-1]<10**8+10:
    print(int(dp[-1]))
else:
    print(-1)
    



Measured memory_bytes: 45800
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <functional>
#include <iterator>
using namespace std;
using VI = vector<long>;

int main() {
    string s;
    cin >> s;
    long k;
    cin >> k;
    
    if (k > s.size()) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] != '1') {
                cout << s[i] << endl;
                return 0;
            }
        }
    }
    
    bool flag = true;
    char c;
    for (int i = 0; i < k; i++) {
        if (s[i] != '1') {
            flag = false;
            c = s[i];
            break;
        }
    }
    if (flag) {
        cout << 1 << endl;
    } else {
        cout << c << endl;
    }
}


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

using namespace std;

int main(){
    int N;
    int p;
    vector<int> Ps(10, 0);
    cin >> N;
    int maxP = 10;
    int maxIndex = 0;
    for(int i = 0; i < N; i++){
        cin >> p;
        if(p > maxP){
            maxIndex = i;
            maxP = p;
        } 
        Ps[i] = p;
    }

    int ans = 0;
    for(int i = 0; i < N; i++){
        if(i == maxIndex){
            ans += Ps[i]/2;
        }else{
            ans += Ps[i];
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int k;
  cin >> k;
  ll sum = 0;
  for(int a = 1; a<=k; a++){
    for(int b = 1; b<=k; b++){
      for(int c = 1; c<=k; c++){
        sum+=gcd(gcd(a,b),c);
      }
    }
  }
  cout << sum << endl;
}


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

int main(){
    int N;  cin >> N;
    vector<int> d(N);
    for(int i=0; i<N; i++){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int M = d[N-1];
    int ans = 0;
    for(int i=1; i<=M; i++){
        int cnt = upper_bound(d.begin(), d.end(), i) - d.begin();
        if(cnt==N/2) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int cnt = 0;
  int ans = 0;
  REPS(i, N) {
    int p;
    cin >> p;
    if (p == i) {
      cnt++;
    } else {
      ans += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  ans += (cnt + 1) / 2;
  print(ans);
}

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

typedef long long ll;
typedef long double ld;

ll a[200005];
ll dp[200005];
ll h[200005];
ll bit[200005];

void bitadd(int x, ll val){
    while(x <= 200000){
        bit[x] = max(bit[x], val);
        x += x & -x;
    }
}

ll bitget(int x){
    ll res = 0;
    while(x){
        res = max(res, bit[x]);
        x -= x & -x;
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> h[i];
    }
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    ll res = 0;
    for(int i=1; i<=n; i++){
        dp[i] = a[i] + bitget(h[i]);
        res = max(res, dp[i]);
        bitadd(h[i], dp[i]);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
using namespace std;


int main(void) {

  int n, x;
  while(cin >> n >> x){
    if( n == 0 && x == 0 ) break;

    long long int cnt = 0;
    for(int i=1; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        if( i >= x - i - j || j >= x - i - j ) continue;
        if( x - i - j <= n && x - i - j > 0 ) cnt++;
      }
    }
    cout << cnt << endl;
  }


  return 0;
}

Measured memory_bytes: 3076
#include "bits/stdc++.h"
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};
struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right){
	int i,j,k;
	int n1=mid-left;
	int n2=right-mid;
	for ( i = 0; i < n1; ++i) {L[i]=A[left+i];	}
	for ( i = 0; i < n2; ++i) {R[i]=A[mid+i];	}
	L[n1].value=R[n2].value=SENTINEL;
	i=j=0;
	for ( k = left; k < right; ++k) {
		if(L[i].value<=R[j].value){
			A[k]=L[i++];
		}else{
			A[k]=R[j++];
		}
	}
}
void mergeSort(struct Card A[],int n,int left,int right){
	int mid;
	if(left+1<right){
		mid=(left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int partition(struct Card A[],int n,int p,int r){
    int i,j;
    struct Card t,x;
    x=A[r];
    i=p-1;
    for ( j = p; j < r; ++j) {
        if(A[j].value<=x.value){
            i++;
            t=A[i];A[i]=A[j];A[j]=t;
        }
    }
    t=A[i+1];A[i+1]=A[r];A[r]=t;
    return i+1;
}
void quickSort(struct Card A[],int n,int p,int r){
	int q;
	if(p<r){
		q=partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(){
	int n,i,v;
	struct Card A[MAX],B[MAX];
	char S[10];
	int stable=1;
	scanf("%d",&n);
	for ( i = 0; i < n; ++i) {
		scanf("%s %d",S,&v);
		A[i].suit=B[i].suit=S[0];
		A[i].value=B[i].value=v;
	}
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);

	for (i = 0; i < n; ++i) {
		if(A[i].suit!=B[i].suit)stable=0;
	}
	if (stable==1) {printf("Stable\n");
	} else {printf("Not stable\n");	}
	for (i = 0; i < n; ++i) {
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}

Measured memory_bytes: 5544
#include <iostream>
#include <string>

using namespace std;

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

    int begin;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            begin = i;
            break;
        }
    }

    int end;
    for (int i = s.size() - 1; i > begin; i--) {
        if (s[i] == 'Z') {
            end = i;
            break;
        }
    }

    cout << end - begin + 1 << endl;
}

Measured memory_bytes: 640
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();
		sc.close();
		
		int AB = A * B;
		
		for (int i=1; i<=3; i++) {
			int mul = AB * i;
			if (mul % 2 != 0) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 21716
#include<string>
#include<iostream>
#include<utility>

using namespace std;

int main() {
	string str;

	cin >> str;

	auto it1 = str.begin();
	auto it2 = str.end() - 1;

	while (it1 < it2) {
		swap(*it1++, *it2--);
	}

	cout << str << endl;
	return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
	int N;
	while(cin>>N,~N){
		ll ans=0;
		for(int i=0;i<N;i++){
			ans++;
			for(ll j=1; ans/j%10==4; j*=10) ans += j*6;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1136
N,K = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**10] * N

dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i+k < N:
            dp[i+k] = min(dp[i+k], dp[i] + abs(h[i]-h[i+k]))
        else:
            break
print(dp[N-1])


Measured memory_bytes: 52448
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	static int[] p;
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		p=new int[N];
		int counter=0;
		for(int i=0; i<N; i++) {
			p[i]=sc.nextInt();
		}
		int check=0;
		while(check<N) {
			if(check+2<N) {	//更に奥の列を見れる時
				if(p[check]!=check+1 && p[check+1]==check+2 && p[check+2]==check+3) {
					//1つ先の2つくみを見る前に自分を木にする
					//1こ先のやつがどっちもスワップしたほうがいい時
					counter++;
					swap(check+1,check+2);
					check++;
				}
				else {
					//1個先の2つ組がどちらかがp_i != i　ならわざわざ先でやる必要はない
					if(p[check]==check+1 || p[check+1]==check+2) {
						counter++;
						swap(check,check+1);
						check++;
					}
					else {
						check++;
						//特に無いなら次を見る
					}
				}
			}
			else if(check+1<N){
				//1個先の2つ組がどちらかがp_i != i　ならわざわざ先でやる必要はない
				if(p[check]==check+1 || p[check+1]==check+2) {
					counter++;
					swap(check,check+1);
					check++;
				}
				else {
					check++;
					//特に無いなら次を見る
				}
			}
			else {
				check++;
			}
		}
		pl(counter);
	}
	static void swap(int i,int j) {
		int tmp1=p[i];
		int tmp2=p[j];
		p[i]=tmp2;
		p[j]=tmp1;
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 34488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
	int i,n;
	cin>>n;
	map <string,int> mp;
	string s;
	for(i=0;i<n;i++)
	{
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<"\n";
	cout<<"WA x "<<mp["WA"]<<"\n";
	cout<<"TLE x "<<mp["TLE"]<<"\n";
	cout<<"RE x "<<mp["RE"]<<"\n";

}
int main()
{

   // int t;
   // cin>>t;
   // while(t--)
   // {
    	solve();
   // }
}

Measured memory_bytes: 3656
import java.io.*;
import java.util.*;
class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println((a+b)/2);
    }
/*    public static void main(String[] a) { new Main().solve(); }*/
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int X,Y,Z; cin >> X >> Y >> Z;

	cout << (X-Z)/(Y+Z) << endl;

	return 0;

}


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

signed main() {
    int n, l, one, other;
    cin >> n;
    one = 0;
    other = 0;
    
    for ( int i = 0; i < n; i++ ) {
        cin >> l;
        
        other += l;
        one = max(l, one);
    }
    
    cout << (other - one > one ? "Yes\n" : "No\n");
    return (0);
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 2000000000
#define mOD 1000000007
#define EPS (1e-10)

using namespace std;


double distance(double x, double y, double x2, double y2) {
	return sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));	
}

int main(int argc, char *argv[]) {

	int A,B; cin >> A >> B;
	int H,M; cin >> H >> M;

	double ji = (H * (360.0 / 12.0)) + M * (1.0 / 2.0);
	ji *= M_PI /180.0;
	double hun = M * (360.0 / 60.0);
	hun *= M_PI /180.0;

	double jix = A * sin(ji);
	double jiy = A * cos(ji);
	double hunx = B * sin(hun);;
	double huny = B * cos(hun);;
	
	cout << setprecision(10) << distance(jix, jiy, hunx, huny) << endl;



	return 0;
}


Measured memory_bytes: 4100
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
	int n,ans=INF;
	string s;
	cin >> n >> s;
	vector<int> headE(n+1),headW(n+1);
	headE[0]=0;headW[0]=0;
	for(int i=1; i<=n; i++){
		headE[i]=headE[i-1]+(s[i-1]=='E'?1:0);
		headW[i]=headW[i-1]+(s[i-1]=='W'?1:0);
	}
	for(int i=1; i<=n; i++){
		int temp=headW[i-1]+(headE[n]-headE[i]);
		ans=min(ans,temp);
	}
	cout << ans << endl;
	return 0;
}


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

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

bool is_prime[200010];
int n,p;

void init() {
    rep(i,200010) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<200010;i++) {
        if(is_prime[i]) for(int j=i+i;j<200010;j+=i) is_prime[j]=false;
    }
}

int next_prime(int m) {
    m++;
    while(true) {
        if(is_prime[m]) break;
        m++;
    }
    
    return m;
}

void solve() {
    vector<int> vec,ans;
    int t = n;
    for(int i=0;i<p;i++) {
        t = next_prime(t);
        vec.push_back(t);
        
    }
    for(int i=0;i<p;i++)  for(int j=i;j<p;j++) {
        ans.push_back(vec[i]+vec[j]);

    }
    sort(ans.begin(),ans.end());
    cout<<ans[p-1]<<endl;

}
int main() {
    init();

    while(cin>>n>>p) {
        if(n==-1 && p==-1) return 0;
        solve();
    }
}

Measured memory_bytes: 1472
n,x=map(int,input().split())
lx=sorted(list(map(lambda y:abs(y-x),list(map(int,input().split())))),reverse=True)

def gcd(a,b):
	while b!=0:
		a,b=b,a%b
	return a

a=lx[0]
for i in range(1,n):
	a=gcd(a,lx[i])

print(a)

Measured memory_bytes: 14252
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 c = sc.nextInt();
		int d = sc.nextInt();

		System.out.println(Math.min(a, b) + Math.min(c, d));
  }
}


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

int main (){
  int K,N;
  cin >> K >> N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int max=A.at(0)+K-A.at(N-1);
  for(int i=1;i<N;i++){
    if(max<A.at(i)-A.at(i-1)){
      max=A.at(i)-A.at(i-1);
    }
  }
  cout << K-max << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int st[200][3],poi[200],cop[200][3];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>st[i][j];
        }
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                if(j!=k){
                    if(st[j][i]==st[k][i]){
                        cop[j][i]=-1;
                        cop[k][i]=-1;
                    }
                }
            }
        }
    }
    for(int i=0;i<3;i++){
            for(int j=0;j<n;j++){
                if(cop[j][i]!=-1)poi[j]+=st[j][i];
        }
    }
    for(int i=0;i<n;i++){
        cout<<poi[i]<<endl;
    }
return 0;
}

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

int main(){
  int N,A;//Nは金額、Aは1円玉の数
  cin>>N>>A;
  
  if(N%500<=A){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n;
	cin>>n;
	ll lambda=0;
	vector<int>a(n);
	rep(i,n){
		cin>>a[i];
		lambda= lambda xor a[i];
	}
	rep(i,n){
		ll ans=lambda xor a[i];
		cout<<ans;
		if(i==n-1){
			cout<<endl;
		}else{
			cout<<" ";
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3940
N = int(raw_input())
A = map(int, raw_input().split())

mod = 10**9+7

A = sorted(A)
is_possible = True
if N%2 == 0:
    for i in range(N/2):
        if A[2*i] != 2*i+1 or A[2*i+1] != 2*i+1:
            is_possible = False
else:
    for i in range(1, (N+1)/2):
        if A[2*i-1] != 2*i or A[2*i] != 2*i:
            is_possible = False

if is_possible:
    ans = 1
    for i in range(N/2):
        ans = ans*2%mod
    print ans
else:
    print 0


Measured memory_bytes: 11304
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	int a, b, c, d;
	a = stoi(s.substr(0, 1));
	b = stoi(s.substr(1, 1));
	c = stoi(s.substr(2, 1));
	d = stoi(s.substr(3, 1));
	for (uint8_t i = 0; i < 8; i++) {
		int sum = a;
		if ((i >> 2 & 1) != 0)
			sum += b;
		else
			sum -= b;
		if ((i >> 1 & 1) != 0)
			sum += c;
		else
			sum -= c;
		if ((i >> 0 & 1) != 0)
			sum += d;
		else
			sum -= d;
		if (sum == 7) {
			cout << a;
			if ((i >> 2 & 1) != 0)
				cout << "+";
			else
				cout << "-";
			cout << b;
			if ((i >> 1 & 1) != 0)
				cout << "+";
			else
				cout << "-";
			cout << c;
			if ((i >> 0 & 1) != 0)
				cout << "+";
			else
				cout << "-";
			cout << d;
			cout << "=7" << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256