akhauriyash/Code-Regression huggingface dataset:
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n = int(input())
a = list(map(int, input().split()))

lcm_num = lcm_list(a)
ans = 0
for i in a:
    ans += (lcm_num-1)%i

print(ans)


Measured memory_bytes: 74856
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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; }
#define int long long

void solve() {
	int n, m; cin >> n >> m;
    priority_queue<int> pque;
    rep(i, n) {
        int x; cin >> x;
        pque.push(x);
    }
    rep(i, m) {
        int y = pque.top(); pque.pop();
        pque.push(y / 2);
    }
    int ans = 0;
    rep(i, n) {
        int z = pque.top(); pque.pop();
        ans += z;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 1400
N=input()
a=[]
for i in range(N):
    a.append(raw_input().split())
 
maxim=[0,0]
for i in range(N):
	if int(maxim[0])<=int(a[i][0]):
		maxim[0]=int(a[i][0])
		maxim[1]=i
print maxim[0]+int(a[maxim[1]][1])

Measured memory_bytes: 34132
a=int(input())
lis=[input()[0] for i in range(a)]
lis2=[0,0,0,0,0]
dellist=[]
for m in lis:
  if m=="M":
    lis2[0]+=1
  elif m=="A":
    lis2[1]+=1
  elif m=="R":
    lis2[2]+=1
  elif m=="C":
    lis2[3]+=1
  elif m=="H":
    lis2[4]+=1
a=sum(lis2)
def c3(a):
  return a*(a-1)*(a-2)/6
def c2(a):
  return  a*(a-1)/2
ans=c3(a)
for i in lis2:
  ans=ans-c3(i)-c2(i)*(a-i)
print(int(ans))
  

Measured memory_bytes: 3888
import java.lang.reflect.Array;
import java.util.*;

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

        int N = sc.nextInt();
        int[] A = new int[25];
        int[] B = new int[25];
        int[] C = new int[25];
        int manzokudo = 0;

        for (int i = 0; i < N; i++)
            A[i] = sc.nextInt();

        for (int i = 0; i < N; i++)
            B[i] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            C[i] = sc.nextInt();

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

        System.out.println(manzokudo);


    }
}






Measured memory_bytes: 21844
/*
 * Author:heroming
 * File:heroming.cpp
 * Time:2017/01/15 08:21:15
 */
#include <vector>
#include <list>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;

#define px first
#define py second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define clr(v, e) memset(v, e, sizeof(v))
#define rep(it, v) for (auto it : v)
#define forn(i, n) for (int i = 0; i < (n); ++ i)
#define rforn(i, n) for (int i = (n) - 1; i >= 0; -- i)
#define form(i, a, b) for (int i = (a); i <= (b); ++ i)
#define rform(i, a, b) for (int i = (b); i >= (a); -- i)
#define forv(i, v) for (int i = 0; i < sz(v); ++ i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++ it)

typedef long long lint;
typedef vector<int> vint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef vector<lint> vlint;
typedef vector<pint> vpint;

int n;
string s;

int main() {
    while (cin >> n) {
        cin >> s;
        int x = 0, ans = 0;
        forn (i, n) {
            if (s[i] == 'I') {
                ++ x;
            } else {
                -- x;
            }
            ans = max(ans, x);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import random

D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]

plus=0
minus=0
data=[[1 for i in range(D)] for j in range(26)]
ans=[0]*D
for i in range(D):
    t=random.randint(1,26)
    ans[i]=t
    plus+=s[i][t-1]
    if i!=0:
        for j in range(26):
            data[j][i]=data[j][i-1]+1
    data[t-1][i]=0
    minus+=sum(c[j]*data[j][i] for j in range(26))

eval=plus-minus
count=600000
check=[]
while count:
    d=random.randint(1,D)
    q=random.randint(1,26)
    if ans[d-1]==q:
        continue
    testplus=plus+s[d-1][q-1]-s[d-1][ans[d-1]-1]
    testminus=minus
    pre=ans[d-1]
    #print("pre",pre)

    day=0
    for j in range(d-1,D):
        if data[q-1][j]!=0:
            if j==d-1:
                testminus+=day*c[q-1]-data[q-1][d-1]*c[q-1]
            else:
                testminus+=(day+1-data[q-1][j])*c[q-1]
                day+=1
        else:
            break

    day=0
    for j in range(d-1,D):
        if j==d-1:
            if j==0:
                day=1
                testminus+=c[pre-1]*day
            else:
                day=1+data[pre-1][j-1]
                testminus+=c[pre-1]*day
        elif data[pre-1][j]!=0:
            testminus+=(day+1-data[pre-1][j])*c[pre-1]
            day+=1
        else:
            break

    if testplus-testminus>eval:
        eval=testplus-testminus
        plus=testplus
        minus=testminus
        ans[d-1]=q
        for j in range(d-1,D):
            if data[q-1][j]!=0:
                if j==d-1:
                    data[q-1][d-1]=0
                else:
                    data[q-1][j]=data[q-1][j-1]+1
            else:
                break

        for j in range(d-1,D):
            if j==d-1:
                if j==0:
                    data[pre-1][j]=1
                else:
                    data[pre-1][j]=1+data[pre-1][j-1]
            elif data[pre-1][j]!=0:
                data[pre-1][j]=data[pre-1][j-1]+1
            else:
                break
    elif random.randint(1,10**4)<=150:
        A=[eval]+[ans[i] for i in range(D)]
        check.append(A)
        eval=testplus-testminus
        plus=testplus
        minus=testminus
        ans[d-1]=q
        for j in range(d-1,D):
            if data[q-1][j]!=0:
                if j==d-1:
                    data[q-1][d-1]=0
                else:
                    data[q-1][j]=data[q-1][j-1]+1
            else:
                break

        for j in range(d-1,D):
            if j==d-1:
                if j==0:
                    data[pre-1][j]=1
                else:
                    data[pre-1][j]=1+data[pre-1][j-1]
            elif data[pre-1][j]!=0:
                data[pre-1][j]=data[pre-1][j-1]+1
            else:
                break
    count-=1
check.sort(reverse=True)
if check:
    if check[0][0]>eval:
        #print(check[0][0])
        for i in range(1,D+1):
            print(check[0][i])
    else:
        #print(eval)
        for i in range(D):
            print(ans[i])
else:
    #print(eval)
    for i in range(D):
        print(ans[i])


Measured memory_bytes: 121960
n=int(input())
A=[0]*(n+1)
for x in range(1,101):
    for y in range(1,101):
        if x**2+y**2+x*y>n :break
        for z in range(1,101):
            qq= x**2+y**2+z**2+x*y+y*z+z*x 
            if qq>n:break
            A[qq]+=1
print(*A[1:],sep="\n")

Measured memory_bytes: 68640
#![allow(non_snake_case)]

// Input
#[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)*} }; }
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)*} };}
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
#[allow(unused_imports)]
use std::cmp::{min,max};

// Main
fn main(){
    input!{
        a: u64,
        b: u64,
        c: u64,
    }
    let x = [a,b,c];
    println!("{}", 
        if x.iter().filter(|&&x| x==5).count()==2 &&
           x.iter().filter(|&&x| x==7).count()==1 {"YES"}else{"NO"});
}


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

int gcd(int a, int b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
int main() {
  int a, b;
  cin >> a >> b;
  cout << (a+1) + (b+1) - (gcd(a,b)+1) << endl;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int main(){
	cin.sync_with_stdio(false);
	int a, b, c, d;

	cin >> a >> b >> c >> d;
	if (a*b > c*d) {
		cout << a*b << endl;
	} else {
		cout << c*d << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

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

  int begin_index = -1;
  int end_index = -1;
  int s_size = s.size();
  for (int i=0; i<s_size; ++i){
    if ((begin_index == -1) && ('A' == s[i])) begin_index = i;
    if ((begin_index != -1) && ('Z' == s[i])) end_index = i;
  }

  cout << (end_index - begin_index + 1) << endl;
  return 0;
}

Measured memory_bytes: 640
def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
        x%=MOD
    return K * x

# nCk
K_MAX = 10**7
MOD = 10**9 + 7
fac, finv, inv = [0]*(K_MAX+1), [0]*(K_MAX+1), [0]*(K_MAX+1)
# nCk (k<=10^7, n<=10^9)
def com_init():
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2,K_MAX+1):
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

def com(n, k):
    ans = 1
    for i in range(n-k+1,n+1):
        ans *= i
        ans %= MOD
    return (ans * finv[k]) % MOD


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

all_comb = pow_k(2,n)
a_comb = com(n,a)
b_comb = com(n,b)

ans = all_comb - a_comb - b_comb -1
print(ans%MOD)


Measured memory_bytes: 267292
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int N, A, B;
  string S;
  cin >> N >> A >> B >> S;
  int a = 0;
  int b = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == 'a') {
      if (a + b < A + B) {
        printf("Yes\n");
        ++a;
      } else {
        printf("No\n");
      }
    } else if (S[i] == 'b') {
      if (a + b < A + B && b < B) {
        printf("Yes\n");
        ++b;
      } else {
        printf("No\n");
      }
    } else {
      printf("No\n");
    }
  }
}

Measured memory_bytes: 3188
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (unfoldr)

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    rev :: (Int, [(Int, [Int])])
    rev = until p f (1, [(0, [0])])
      where
        p :: (Int, [(Int, [Int])]) -> Bool
        p = (== n) . fst
        f :: (Int, [(Int, [Int])]) -> (Int, [(Int, [Int])])
        f = (,) <$> succ . fst <*> (>>= g) . snd
          where
            g :: (Int, [Int]) -> [(Int, [Int])]
            g (m, ds) = (succ m, (succ m) : ds) : map ((,) m . (: ds)) [m, (pred m)..0]
  mapM_ putStrLn $ map (map (toEnum . (97 +)) . reverse) . reverse . map snd . snd $ rev

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 26236
# coding: utf-8

s=input()
min=abs(int(s[0])*100+int(s[1])*10+int(s[2])-753)

for i in range(len(s)-3):
    if min>abs(int(s[i+1])*100+int(s[i+2])*10+int(s[i+3])-753):
        min=abs(int(s[i+1])*100+int(s[i+2])*10+int(s[i+3])-753)

print(min)

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

ll ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d, n;
int x, y;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;
    cin >> a >> b >> c >> d;
    ans = min(b, d) - max(a, c);
    pr(ans <= 0 ? 0 : ans);

    return 0;
}


Measured memory_bytes: 3668
#include<stdio.h>
int main(void){
	int a,b,A,B;
	scanf("%d\n",&A);
	scanf("%d",&B);
	if(A<B)
	printf("a < b\n",A,B);
	else if(A>B)
	printf("a > b\n",A,B);
	else if(A==B)
	printf("a == b\n",A,B);
	return 0;
}

Measured memory_bytes: 580
# coding: utf-8
# Here your code !
#coding: utf-8

while True:
    l = map(int,raw_input().split())
    if l == [0,0,0,0,0]:
        break
    else:
        A = l[1]
        B = l[2]
        C = l[3]
        X = l[4]
        f = -1
        Yl = map(int,raw_input().split())
        for Y in Yl:
            while f <= 10000:
                f = f + 1
                if X == Y:
                    X = (A * X + B) % C
                    break
                X = (A * X + B) % C
        if f > 10000:
            print -1
        else:
            print f

Measured memory_bytes: 6328
<?php
define("MOD", 10**9+7);
list($H, $W) = ints();
$map[] = str_repeat("#", $W+1);
for($y = 0; $y < $H; $y++){
    $map[] = '#'.str();
}
$dp = array_fill(0, $H+1, array_fill(0, $W+1, 0));
$dp[1][1] = 1;

//print_r($dp);
for($y = 1; $y <= $H; $y++){
    for($x = 1; $x <= $W; $x++){
        if($map[$y][$x] == '.'){
            $dp[$y][$x] += ($dp[$y-1][$x] + $dp[$y][$x-1]) % MOD;
        }
    }
}
echo $dp[$H][$W];



function r($n){
  return range(0, $n-1);
}
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 41464
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define trace(x) cerr << #x << " " << x << endl;
#define dprintf(...) fprintf(stderr, __VA__ARGS__)
#define dln()        fprintf(stderr, "\n")
using namespace std;
typedef long long LL;
typedef long double db;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
const	int N = 1000005;
const	int P = 1e9 + 7;
const	int inf = 1e9;
const	LL Inf = 1e15;

inline int IN(){
	char ch = getchar(); int x = 0, f = 0;
	while(ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return f ? (-x) : x;
}

inline int Pow(int x, int y, int p){
	int an = 1;
	for(; y; y >>= 1, x = (LL)x * x % p) if(y & 1) an = (LL)an * x % p;
	return an;
}

void renew(int &x, int y){
	x += y;
	if(x < 0) x += P;
	else if(x >= P) x -= P;
}

template<typename T> inline void chkmin(T &a, const T &b) {if(a > b) a = b;}
template<typename T> inline void chkmax(T &a, const T &b) {if(a < b) a = b;}

int n, Q, etot;
int ue[N], ve[N], we[N];

void adde(int x, int y, int z){
	++etot;
	ue[etot] = x;
	ve[etot] = y;
	we[etot] = z;
}

VI V[N];

void addx(int x, int y){
	V[x].pb(y);
	V[1].pb(y + (n - x + 1) * 2);
}

int id[N], fa[N];
int get(int x){
	return (fa[x] == x) ? x : fa[x] = get(fa[x]);
}

int main(){
	scanf("%d%d", &n, &Q);	
	REP(i, 1, Q){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		++a, ++b;
		adde(a, b, c);
		addx(a, c + 1);
		addx(b, c + 2);
	}

	set<int> st;

	REP(i, 1, n){
		for(int v : V[i]) st.insert(v - 2 * i);
		adde(i, i % n + 1, 2 * i + (*(st.begin())));
	}

	REP(i, 1, etot) id[i] = i;
	REP(i, 1, n) fa[i] = i;

	sort(id + 1, id + etot + 1, [&](const int &a, const int &b){return we[a] < we[b];});
	LL ans = 0;
	REP(i, 1, etot){
		int tt = id[i];
		int x = get(ue[tt]), y = get(ve[tt]);
		if(x != y){
			fa[x] = y;
			ans += we[tt];
		}
	}
	cout << ans << endl;
	return 0;
}





















Measured memory_bytes: 82800
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
int dx[4] = {0, 1, 0 ,-1}, dy[4] = {-1, 0, 1, 0};

main()
{
  int w, h;
  bool data[101][101][4];
  
  while( cin >> w >> h, !(w == 0 && h == 0) ) {
    int ans = 0;
    fill_n(**data, 101*101*4, false);
    
    for(int i=0; i<h*2-1; i++) {
      int a;
      if( i % 2 == 0 ) {
	for(int j=0; j<w-1; j++) {
	  cin >> a;
	  data[i/2][j][1] = data[i/2][j+1][3] = a;
	}
      }
      
      else { 
	for(int j=0; j<w; j++) {
	  cin >> a;
	  data[i/2][j][2] = data[(i+1)/2][j][0] = a;
	}
      }
      
    }			    
	

    queue<Pip> q;
    bool used[101][101] = {{0}};
    q.push( Pip(0, Pii(0, 0)) );
    
    while( !q.empty() ) {
      Pip p = q.front(); q.pop();
      int c = p.fr, y = p.sc.fr, x = p.sc.sc;
     
      if( y == h-1 && x == w-1 ) {
	ans = c+1;
	break;
      }
      
      if( used[y][x] ) continue;
      used[y][x] = true;

      Rep(i, 4) {
	int nx = x + dx[i], ny = y + dy[i];
	if( nx < 0 || nx >= w || ny < 0 || ny >= h || data[y][x][i] ) continue;
	q.push( Pip(c+1, Pii(ny, nx)) );
      }
      
    }

    cout << ans << endl;
    
  }
  
}

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

int main(){
  string s;
  cin>>s;
  int cnt=0;
  int k=0,u=0,p=0,c=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='K')k++;
    if(s[i]=='U')u++;
    if(s[i]=='P')p++;
    if(s[i]=='C')c++;
  }
  cnt=min(min(k,u),min(p,c));
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 1188
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
/*
w x   a b   wa+xc wb+xd
	*     =
y z   c d   ya+zc yb+zd
*/
class mat2x2 {
public:
	int a11, a12, a21, a22;
	mat2x2(int a11, int a12, int a21, int a22) :a11(a11), a12(a12), a21(a21), a22(a22) {}
	mat2x2&operator*=(const mat2x2&m) {
		int a11_t = m.a11 * a11 + m.a12 * a21;
		int a12_t = m.a11 * a12 + m.a12 * a22;
		int a21_t = m.a21 * a11 + m.a22 * a21;
		int a22_t = m.a21 * a12 + m.a22 * a22;
		a11 = a11_t;
		a12 = a12_t;
		a21 = a21_t;
		a22 = a22_t;
		return *this;
	}
};
int main() {
	int a = in(), b = in();
	mat2x2 ans(1, 0, 0, 1);
	do {
		ans *= mat2x2(0, 1, 1, -a / b);
		int temp = a;
		a = b;
		b = temp % b;
	} while (b != 0);
	cout << ans.a11 << ' ' << ans.a12 << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,m,R;
    cin >> n >> m >> R;
    vector<int> r(R);
    rep(i,R) {cin >> r[i]; r[i]--;}
    sort(r.begin(), r.end());
    const int INF = INT32_MAX>>3;
    vector<vector<int>> d(n, vector<int>(n,INF));
    rep(i,n) d[i][i] =0;
    rep(i,m) {
        int a,b,c;
        cin >> a >> b >> c;
        d[a-1][b-1] = c;
        d[b-1][a-1] = c;
    }
    rep(k,n) rep(i, n) rep(j,n) chmin(d[i][j], d[i][k] + d[k][j]);
    int ans = INF;
    do {
        int d_sum = 0;
        rep(i,R-1) d_sum += d[r[i]][r[i+1]];
        chmin(ans, d_sum);
    } while(next_permutation(r.begin(), r.end()));
    cout << ans << endl;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

# 4で割り切れる場合と、2で割り切れる場合、どちらでも割り切れない場合の値の数を求める
# どちらでも割り切れない場合の値は4で割り切れる値の場合との組み合わせで4の倍数の積になる
# 達成できるかの判定はどちらでも割り切れない値の数が、4で割り切れる値の数以下であった場合に成立する
b1 = b2 = b4 = 0
for i in range(n):
  if a[i]%4 == 0: b4 += 1
  elif a[i]%2 == 0: b2 += 1
  else: b1 += 1

# 2で割り切れる値が存在しない場合、
# どちらでも割り切れない値の数が、4で割り切れる値の数+1以下であった場合に成立する
if b2 == 0: b4 += 1 
  
if b1 <= b4: print("Yes")
else: print("No")

Measured memory_bytes: 20744
import math
def isPerfect(a):
  x1=math.floor(math.sqrt(a))
  if((x1*x1)==a):
    return True
  return False
n,d=map(int,input().split())
mat=[]
for _ in range(n):
  l=list(map(int,input().split()))
  mat.append(l)
c=0
for i in range(n):
  l1=mat[i]
  for j in range(i+1,n):
    l2=mat[j]
    sm=0
    for k in range(len(l2)):
      x=abs(l2[k]-l1[k])
      sm=sm+(x*x)
    if(isPerfect(sm)):
        c+=1
print(c)

Measured memory_bytes: 3064
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M=I()
    dig=0
    S=0
    for i in range(M):
        d,c=MI()
        dig+=c
        S+=d*c

    print(dig-1+(S-1)//9)

main()



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

int main(){
 
  long long A, B, C, K, i, cnt = 0;
  cin >> A >> B >> C >> K;
  
  for (long long i = 0; i < K; i++){
    
    if (i + 1 <= A){
      cnt++;
    }else if(i + 1 > A + B){
      cnt--;
    }
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#define rep(i,n) for(ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main(){
    int a[3];
    int ans = 0;

    cin >> a[0] >> a[1] >> a[2];
    for(int i = 0; i < 3; i++) ans += a[i];

    if(ans >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
  char a[2][100000],b[50],c;
  long i,j,n,p,r,s;

  while(1){
    scanf("%ld",&n);
    if(n==0) break;
    scanf("%s",a[0]);
    for(i=0;i<n;i++){
      p=1;
      r=i%2; c=a[r][0];
      s=1-r; a[s][0]=0;
      for(j=1;j<100000;j++){
        if(a[r][j]==c) p++;
        else {
          sprintf(b,"%ld%c",p,c);
          strcat(a[s],b);
          p=1;
          c=a[r][j];
        }
        if(c==0) break;
      }
    }
    printf("%s\n",a[s]);
  }
  return 0;
}

Measured memory_bytes: 704
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for(auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    set<string> S;
    rep(i, n) {
        string SS;
        cin >> SS;
        S.insert(SS);
    }

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

Measured memory_bytes: 19232
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    ll n;
    ll s = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
    
        ll a = i % 3;
        ll b = i % 5;
        if (a == 0 || b == 0) {
            continue;
        }
        s += i;

    }
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		int N = s.length();
		int p = 0;
		int g = 0;
		int t = 0;
		for(int i = 0; i < N; i++) {
			char c = s.charAt(i);
			if(c == 'g') {
				if(p < g) {
					p++;
					t++;
				}else {
					g++;
				}
			}else {
				if(p < g) {
					p++;
				}else {
					g++;
					t--;
				}
			}
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 24840
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mood;
		}
		x = x * x % mood;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n;
int cnt;

signed main() {
	cin >> n;
	for (int i = 1; i <= sqrt(n); i++) {
		if (!(n%i)) {
			cnt = i + n / i;
		}
	}
	cout << cnt - 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,t,n=5,ans;
     for(i=1;i<=5;i++)
     {
        cin>>t;
        if(t==0)
        {
            ans=i;
        }
     }
     cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int n,a,b;
	int ans=0;
	scanf("%d%d%d",&n,&a,&b);
	for (int i=1;i<=n;i++)
	{
		int k=i;
		int tot=0;
		while (k!=0)
		{
			tot=tot+k%10;
			k/=10;
		}
		if (a<=tot&&tot<=b) ans+=i;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()


int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	//std::ostringstream oss;
	//oss<<R"(^[0-9]{)" << a<<R"(}-[0-9]{)"<<b << R"(}$)";
	//string exp = oss.str();

	string t = R"(^[0-9]{)" + to_string(a) + R"(}-[0-9]{)" + to_string(b) + R"(}$)";
	regex r(t);
	cout << (regex_match(s, r) ? "Yes" : "No") << endl;
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5; 
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}

ll raise(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}


int n;

void solve()
{
    cin >> n;
    if (n<600) nout(8);
    else if (n<800) nout(7);
    else if (n<1000) nout(6);
    else if (n<1200) nout(5);
    else if (n<1400) nout(4);
    else if (n<1600) nout(3);
    else if (n<1800) nout(2);
    else if (n<2000) nout(1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

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


int main() 
{
    int A,B,C;
    cin >> A >> B >> C;
    
    if (A == B && B == C) {
        cout << "No" << endl;
    }else if (A != B && B != C && A != C) {
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
cnt = 0
dic = defaultdict(list)
ab = []
cd = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
for i in range(n):
    c, d = map(int, input().split())
    cd.append((c, d))
for i in ab:
    for j in cd:
        a, b = i
        c, d = j
        if a < c and b < d:
            dic[i].append(j)
seen = set()
for key, value in sorted(dic.items(), key=lambda x: x[0][1], reverse=True):
    for co in sorted(value, key=lambda x: x[0]):
        if co not in seen:
            cnt += 1
            seen.add(co)
            break
print(cnt)




Measured memory_bytes: 39280
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int N;cin>>N;
	vector<int>H(N);
	for(int i=0;i<N;i++){
		cin>>H[i];
	}
	
	int ans=1;
  	int max=H[0];
	for(int i=1;i<N;i++){
      	if(min(max,H[i])==max){
          	max = H[i];
			ans += 1;
        }
	}
	
	cout << ans << endl;
}

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

int main() {
  int a, b, c, d;
  cin >> a;
  b = a / 100;
  c = (a - b * 100) / 10;
  d = a - b * 100 - c * 10;
  cout << b + c + d << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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);
	vector<int> a(3);
	rep(i,3) cin >> a[i];
	int ans = 0;
	while(a[0] != a[1] || a[1] != a[2] || a[2] != a[0]){
		sort(a.begin(), a.end());
		if(a[0] == a[1]){
			a[0]++;
			a[1]++;
		}
		else a[0] += 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define N 2000000

int A[N],j=0;

int Parent(int i){
  return i/2;
}

int Left(int i){
  return 2*i;
}

int Right(int i){
  return 2*i+1;
}

void exchange(int x,int y){
  int tmp;

  tmp=A[x];
  A[x]=A[y];
  A[y]=tmp;
}

void heapIncreaseKey(int i,int key){
  if(key<A[i])  return;
  A[i]=key;
  while(i>1 && A[Parent(i)]<A[i]){
    exchange(i,Parent(i));
    i=Parent(i);
  }
}

void maxHeapInsert(int key){
  j++;
  A[j]=INT_MIN;
  heapIncreaseKey(j,key);
}

void maxHeapify(int i){
  int l=Left(i);
  int r=Right(i);
  int largest;

  if(l<=j && A[l]>A[i]) largest=l;
  else largest=i;

  if(r<=j && A[r]>A[largest])largest=r;

  if(largest!=i){
    exchange(i,largest);
    maxHeapify(largest);
  }
}

int heapExtractMax(){
  int max;

  if (j<1) return 0;
  max=A[1];
  A[1]=A[j];
  j--;
  maxHeapify(1);
  return max;
}

main(){
  char str[20];
  int x;
  
  while(1){
    scanf("%s",str);
    if(strcmp(str,"end")==0) break;

    if(str[0]=='i') {
      scanf("%d",&x);
      maxHeapInsert(x);
    }
    else printf("%d\n",heapExtractMax());
  }
  return 0;
}

Measured memory_bytes: 4696
#include <stdio.h>
int main(void){
int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if((a==1||b==1||c==1||d==1)&&(a==9||b==9||c==9||d==9)&&(a==4||b==4||c==4||d==4)&&(a==7||b==7||c==7||d==7)){printf("YES");}
else {printf("NO");}
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int a,b,c;

int main(){
	cin >> a >> b >> c;
	
	cout << min(c, b/a) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

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

Double distance(Int x1, Int y1, Int x2, Int y2){
    Int x = x1 - x2;
    Int y = y1 - y2;
    return sqrt(x * x + y * y);
}


Double path(int n, const V& xs, const V& ys, const V& as){
    Double s = 0;
    for(int i = 0; i < n - 1; i++){
        s += distance(xs[as[i]], ys[as[i]], xs[as[i + 1]], ys[as[i + 1]]);
    }
    return s;
}

Double solve(int n, const V& xs, const V& ys){
    Double s = 0;
    Int c = 0;
    V as(n);
    iota(begin(as), end(as), 0);
    do{
        s += path(n, xs, ys, as);
        c++;
    }while(next_permutation(begin(as), end(as)));
    return s / c;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    V xs(n), ys(n);
    for(int i = 0; i < n; i++){
        cin >> xs[i] >> ys[i];
    }
    cout << solve(n, xs, ys) << "\n";

    return 0;
}


Measured memory_bytes: 256
def cul(A,B):
	ret = pow(A,5)-pow(B,5)
	return ret

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse = True)
    return divisors

if __name__ == '__main__':
	X = int(input())
	ls = make_divisors(X)
	c = 0
	A = 0
	B = 0
	#print(ls) #debug
	ls.append(0)
	for d in ls:
		a = d//2
		v = 0

		while(v < X):
			b = a-d
			v = cul(a,b)
			#print('{} {}'.format(a,b)) #debug
			#print(v) #debug
			if v == X:
				A = a
				B = b
				c = 1
			else:
				a += 1

		if c == 1:
			break

	print('{} {}'.format(A,B))

Measured memory_bytes: 63560
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;
 
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}
 
int main() {
    int n, m;
    while(cin >> n >> m) {
        int a[1010];
        memset(a, 0, sizeof(a));
        if(n == 0 && m == 0) break;
        int p = 0, i = 0, cnt = 0;
        while(i < n) {
            //printf("%d %d %d\n",i, cnt, p);
            if(a[p] == 0) {
                cnt++;
                if(cnt % m == 0) {
                    // cout << p + 1 << endl;
                    a[p] = 1;
                    i++;
                    p = (p + 1) % n;
                }
                else {p = (p + 1) % n;}
            }
            else p = (p + 1) % n;
        }
        cout << (p == 0 ? n : p) << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(void){
  int A;
  scanf("%d",&A);
  
  int a , b , c ,d;
  d = A%10;
  A = A/10;
  c = A%10;
  A = A/10;
  b = A%10;
  A = A/10;
  a = A;
  int ans = a;
  int i , j , k;
  int i1 ,j1 ,k1;
  for(i = 0;i < 2;i ++){
    for(j = 0;j < 2;j ++){
      for(k = 0;k < 2;k ++){
          if(i==0){
            ans += b;
          }
          if(i!=0){
            ans -= b;
          }
         if(j==0){
           ans += c;
         }
         if(j!=0){
          ans -= c;
         }
         if(k==0){
           ans += d;
         }
         if(k!=0){
          ans -= d;
        }
        if(ans == 7){
          i1 = i;
          j1 = j;
          k1 = k;
          i = 4;
          j = 4;
          k = 4;
        }
        else{
          ans = a;
        }
      }
    }
  }
 
  printf("%d",a);
  if(i1==0){
    putchar('+');
  }
  else{
    putchar('-');
  }
    printf("%d",b);
  if(j1==0){
    putchar('+');
  }
  else{
    putchar('-');
  }      
    printf("%d",c);
  if(k1==0){
    putchar('+');
  }
  else{
    putchar('-');
  }
  printf("%d=7",d);
  
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int a[102];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    int ans = 0;
    for(i=1;i<n;i++)
        if (a[i] == a[i - 1])
        {
            ans++;
            a[i] = 10001;
        }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
const max = 512;

var col = "#.",
	end = false;
	
while (col.length < max) col = col + col;

require('fs').readFileSync('/dev/stdin', 'ascii').split('\n').forEach(main);

function main(line) {
	if (line === '0 0') {
		end = true;
		return;
	}
	if (end) return;
	var hw = line.split(' ').map(Number);
	var h = hw[0];
	var w = hw[1];
	even = col.slice(0, w);
	odd = col.slice(1, w + 1);
	for (j = 0; j < hw[0]; j++) {
		if (j % 2 === 0) console.log(even);
		else console.log(odd);
	}
	console.log("");
}

Measured memory_bytes: 17028
#include<bits/stdc++.h>
using namespace std;
int dp[4][50][50][1 << 12];
int H, W, K;
char mas[50][50];
int dy[] = { 0, 1, 0, -1}, dx[] = { 1, 0, -1, 0};
int mask;

int getdir(int bit, int i){
  return bit >> (i << 1) & 3;
}
#define INF (1 << 30)
int rec(int x, int y, int mul, int bit){
  if(y == H - 1 && x == W - 1 && mul == 0) return 0;
  if(~dp[mul][y][x][bit]) return dp[mul][y][x][bit];

  int ret = -INF, value = 0, mx = x, my = y;
  bool hoge = false;
  if(mas[y][x] != '.'){
    for(int i = 0; i < 2 * K; i++){
      my -= dy[getdir( bit, i)];
      mx -= dx[getdir( bit, i)];
      if(mx == x && my == y){
        hoge = true;
        break;
      }
    }
    if(!hoge) value = mas[y][x] - '0';
  }

  for(int i = 0; i < 4; i++){
    if(mul == 0 && i > 1) break;
    int ny = y + dy[i], nx = x + dx[i];
    if(ny < 0 || ny >= H || nx < 0 || nx >= W || mas[ny][nx] == '#') continue;
    ret = max( ret, rec( nx, ny, mul - (i > 1), (bit << 2 | i) & mask) + value);
  }
  return dp[mul][y][x][bit] = ret;
}

int main()
{
  cin >> H >> W >> K;
  mask = (1 << (K * 2 * 2)) - 1;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> mas[i][j];
    }
  }
  fill_n( ***dp, 4 * 50 * 50 * (1 << 12), -1);
  cout << rec( 0, 0, K, 0) << endl;
  return 0;
}

Measured memory_bytes: 161168
#include <stdio.h>


int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a>=b&&b>=c){printf("%d\n",a-c);}
	else if(a>=c&&c>=b){printf("%d\n",a-b);}
	else if(b>=c&&c>=a){printf("%d\n",b-a);}
	else if(b>=a&&a>=c){printf("%d\n",b-c);}
	else if(c>=b&&b>=a){printf("%d\n",c-a);}
	else if(c>=a&&a>=b){printf("%d\n",c-b);}
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N,C;
	cin >> N >> C;
	vector<int> A(N),B(N);
	for(int i =0; i < N; i++) cin >> A[i];
	for(int i =0; i < N; i++) cin >> B[i];
	long long mod =1000000007;
	vector< vector<long long> > X(500,vector<long long>(C+1,0));
	for(int i =1; i < 500; i++) {
		X[i][0] =1;
		for(int j =1; j <= C; j++) X[i][j] =(X[i][j-1]*i)%mod;}
	for(int i =0; i <= C; i++) for(int j =1; j < 500; j++) X[j][i] =(X[j-1][i]+X[j][i])%mod;
	vector< vector<long long> > ans(C+1,vector<long long>(N+1,0));
	ans[0][0] =1;
	for(int i =0; i < N; i++) for(int c =0; c <= C; c++) for(int d =0; d <= C-c; d++) {
		long long x =(X[B[i]][d]-X[A[i]-1][d])%mod;
		ans[c+d][i+1] =(ans[c+d][i+1]+ans[c][i]*x)%mod;}
	if(ans[C][N] < 0) ans[C][N] +=mod;
	cout << ans[C][N] << "\n";
	return 0;}

// look at my code
// my code is amazing


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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int m, n;
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int tot = 0;
    for (auto &v : a) {
        tot += v;
    }
    double thresh = tot / (4.0 * m);
    int select = 0;
    for (auto &v : a) {
        if (v >= thresh) {
            select++;
        }
    }
    cout << (select >= m ? "Yes" : "No") << endl;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256