akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a) )
#define M 4000010
#define md 1000000007

ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}
/*inline ll add(ll a,ll b){return (a+b)%md;}
inline ll mul(ll a,ll b){return (a*b)%md;}
ll f[M],iv[M];
ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));}
void prep_fac(){
    f[0]=1;
    rep(i,1,M)f[i]=mul(i,f[i-1]);
    iv[M-1]=power(f[M-1],md-2,md);
    for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
}*/



int main()
{
	IOS;
	int l,r,d;
	cin>>l>>r>>d;
	int ans=0;
	for(int i=l;i<=r;i++)
	{
		if(i%d==0)
		ans++;
	}
	cout<<ans;
}



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

int main() {
   int N;
   cin >> N;
   if(N < 2) cout << 1 << endl;
   else if(N < 4) cout << 2 << endl;
   else if(N < 8) cout << 4 << endl;
   else if(N < 16) cout << 8 << endl;
   else if(N < 32) cout << 16 << endl;
   else if(N < 64) cout << 32 << endl;
   else cout << 64 << endl;
   
}

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

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

  vector<int> seq;
  if (s[0] == '0') seq.push_back(0);
  int si = 0;
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i-1]) {
      seq.push_back(i-si);
      si = i;
    }
  }
  seq.push_back(n-si);
  if (s[s.size()-1] == '0') seq.push_back(0);

  vector<int> cum(seq.size()+1);
  cum[0] = 0;
  rep(i, seq.size()) cum[i+1] += cum[i] + seq[i];

  int ans = -1;
  int l = 0;
  int r = 2 * k + 1;
  while (r < cum.size()) {
    ans = max(ans, cum[r] - cum[l]);
    l += 2;
    r += 2;
  }
  if (ans == -1) ans = n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4096
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int r; cin >> r;
    cout << 3*r*r << endl;
  
    return 0;
}



Measured memory_bytes: 256
using System;

namespace ABC070
{
    class B
    {
        static void Main(string[] args)
        {
            string[] intput = Console.ReadLine().Split();
            int A = int.Parse(intput[0]);
            int B = int.Parse(intput[1]);
            int C = int.Parse(intput[2]);
            int D = int.Parse(intput[3]);

            Console.WriteLine(Math.Max(0, Math.Min(B, D) - Math.Max(A, C)));
        }
    }
}


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

const int INF=1e9;

int main()
{
	for(int n,e,t;cin>>n>>e>>t && n|e|t;){
		t--;
		vector<int> obtainable(n);
		for(int& x:obtainable) cin>>x;
		vector<vector<int>> rules(e);
		for(int i=0;i<e;i++){
			int v,m; cin>>v>>m; v--;
			rules[i].push_back(v);
			for(int j=0;j<m;j++){
				cin>>v; v--;
				rules[i].push_back(v);
			}
		}
		
		vector<int> dp(n,INF);
		for(int i=0;i<n;i++) if(obtainable[i]) dp[i]=1;
		for(int k=0;k<n-1;k++){
			for(auto rule:rules){
				vector<int> tmp(rule.size()-1);
				transform(begin(rule)+1,end(rule),begin(tmp),[&](int i){return dp[i];});
				if(count(begin(tmp),end(tmp),0)) continue;
				sort(begin(tmp),end(tmp),greater<int>());
				int u=rule[0],mx=0;
				for(int i=0;i<tmp.size();i++)
					mx=max(mx,i+tmp[i]);
				dp[u]=min(dp[u],mx);
			}
		}
		
		cout<<(dp[t]==INF?-1:dp[t])<<endl;
	}
}

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

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    for (int i = 0; i < n; ++i) {
        cout << s[i] << t[i];
    }

    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()

l = len(str(N))

if l == 1 or l == 2:
    print(min(9, N))
elif l == 3 or l == 4:
    print(min(9 + N - 100 + 1, 909))
else:
    print(min(9 + 900 + N - 10000 + 1, 90909))


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/any.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto i:v)output(i);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define sum(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
int main(){
    lint a;string s;
    cin>>a>>s;
    if(a>=3200)cout<<s;
    else cout<<"red";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    int X = A*B;
    int Y = A+B;
    int Z = A-B;
    if((X>=Y)&&(X>=Z))
    {
        cout << X;

    }
    else if((Y>=X)&&(Y>=Z))
    {
        cout << Y;
    }
    else if((Z>=Y)&&(Z>=X))
    {
        cout << Z;
    }

    return 0;

}


Measured memory_bytes: 3600
<?php
define('MOD', 10 ** 9 + 7);
list($n) = ints();
list($s) = strs();
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$s[$i]])) ++$cnt[$s[$i]];
    else $cnt[$s[$i]] = 1;
}
$ans = 1;
foreach ($cnt as $c) {
    $ans = $ans * ($c + 1) % MOD;
}
echo $ans - 1;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16448
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int d[10101];

inline int calc(int i, int x)
{
	return i * (100 + x) / 100;
}

int main()
{
	while(1) {
		int x, y, s;
		cin >> x >> y >> s;
		if (!x && !y && !s) break;
		int l = 0, r = s;
		int a, b;
		int ans = 0;
		rep(i,1,s+1) rep(j,1,s+1) {
			if (calc(i, x) + calc(j, x) == s) {
				ans = max(ans, calc(i, y) + calc(j, y));
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    int r = inputValue();
    int ans = r * r;
    cout << ans << endl;
}


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

namespace ABC098A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B,max;

            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);

            max = A + B;

            if (max < A - B) max = A - B;
            if (max < A * B) max = A * B;
        

            Console.WriteLine(max);

            Console.ReadKey();


        }
    }
}


Measured memory_bytes: 11092
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random


def main():
    h,w = map(int, input().strip().split())
    g = [input().strip() for _ in range(h)]
    gg  = [col for col in zip(*g) if("#" in col)]
    
    eprint("gg ",end=": \n")
    eprint(gg)
    for elem in gg:
        eprint(elem)
        
    gg = [row for row in zip(*gg) if("#" in row)]
    eprint("gg ",end=": \n")
    eprint(gg)
    # for elem in gg:
    #     eprint(elem)
    
    for S in gg:
        print("".join(S))
    return

if __name__ == '__main__':
    main()


# trA  = [list(col) for col in zip(*A)]


Measured memory_bytes: 67308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
ll ans = 0;
int main(){

    int N,K;cin >> N >> K;
    ll small = 0;
    for(ll i=K;i<=N+1;i++){
        ll mi = ((i-1)*i)/2;
        ll ma = ((N+(N-i+1))*i)/2;
        ma %= MOD;
        mi %= MOD;
        if(ma<mi)ma += MOD;
        ll cou = ma - mi + 1;
        cou %= MOD;
        ans += cou;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
// きりみんちゃんの配信からきました
// 左右をとる+-1のしゃくとり、左がマイナスかつ右がプラスの場合には「左に行った後折り返す」vs「右に行ったあと折り返す」が発生する
// ゼロ含む場合マジでなんなんだよ
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	includeZero := false
	zeroIdx := -1
	for i := 0; i < n; i++ {
		var j int
		fmt.Scan(&j)
		a[i] = j
		if j == 0 {
			includeZero = true
			zeroIdx = i
		}
	}
	if includeZero && n > 1 {
		if zeroIdx != 0 && zeroIdx != n-1 {
			if abs(a[zeroIdx-1]) < abs(a[zeroIdx+1]) {
				a[zeroIdx] = a[zeroIdx-1]
			} else {
				a[zeroIdx] = a[zeroIdx+1]
			}
			// a[zeroIdx] = min(a[zeroIdx-1], a[zeroIdx+1])
			// } else {
			// 	a[zeroIdx] = a[zeroIdx+1]
		}
	}
	ans := 10000000000000000
	r := 0
	tmp := 0
	for l := 0; l <= n-k; l++ {
		for r < n && r-l < k {
			tmp += a[r]
			r += 1
		}
		if a[r-1] <= 0 {
			tmp = a[l] * -1
		} else if a[l] >= 0 {
			tmp = a[r-1]
		} else if a[l] < 0 {
			tmp = min(a[l]*-2+a[r-1], a[r-1]*2+a[l]*-1)
		}
		// fmt.Println(a[l:r], tmp)
		ans = min(ans, tmp)
		tmp -= a[l]
	}
	fmt.Println(ans)
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 5504
#ゲームのログイン（1日1回）でコイン獲得
# a:coins/1day b:bounus/week c:goal of gained coins
# 毎日ログイン前提
a,b,c = list(map(int,input().split()))


days_needed = 0
coins = 0

flag = True
while flag:  
    days_needed += 1
    coins += a
    if days_needed % 7 == 0:
        coins += b

    if coins >= c:
        flag=False

print(days_needed)




Measured memory_bytes: 5596
s = list(input())
n = int(input())
for i in range(n):
    cmd = input().split()
    if cmd[0] == 'print':
        print(''.join(s[int(cmd[1]):int(cmd[2]) + 1]))
    elif cmd[0] == 'reverse':
        s[int(cmd[1]):int(cmd[2]) + 1] = s[int(cmd[1]):int(cmd[2]) + 1][::-1]
    elif cmd[0] == 'replace':
        s[int(cmd[1]):int(cmd[2]) + 1] = list(cmd[3])

Measured memory_bytes: 7688
def GCD(a,b):
    if a%b == 0:
        return b
    return GCD( b, a%b )

A,B,K = map(int, input().split())
g = GCD(A,B)
i = 1
glist = []
while i*i<=g:
    if g % i == 0:
        glist.append( i )
        if i*i!=g:
            glist.append( g//i )
    i+=1;
glist.sort(reverse=True)
print(glist[K-1])


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

uint64_t diff_abs(uint64_t x, uint64_t y)
{
  return x >= y ? x - y : y - x;
}

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

  vector<uint64_t> h(N);
  N_TIMES(n, N) { cin >> h[n]; }

  vector<uint64_t> dp(N, 1e+12);
  dp[0] = 0;

  N_TIMES(n, N - 1) {
    if (n + 1 < N) {
      dp[n + 1] = min(dp[n + 1], dp[n] + diff_abs(h[n], h[n + 1]));
    }

    if (n + 2 < N) {
      dp[n + 2] = min(dp[n + 2], dp[n] + diff_abs(h[n], h[n + 2]));
    }
  }

  cout << dp[N - 1] << endl;

  return 0;
}

Measured memory_bytes: 1792
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Ord
import Data.Maybe
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  (n,m) <- getIntPair
  cs <- getInts
  let oddCs = filter odd cs
  let evenCs = filter even cs
  if length oddCs >= 3
  then putStrLn "Impossible"
  else do
    let (as,bs) = solve oddCs evenCs
    printList as
    print $ length bs
    printList bs

solve [1] [] = ([1], [1])
solve [o] [] = ([o], [1,o-1])
-- solve [o] es = ([o]++es, [o-1]++init es++[last es + 1])
solve [o] es = ([o]++es, [o+1]++init es++[last es - 1])
solve [] es = (es, [1]++init es++[last es - 1])
solve [1,o] es = ([1]++es++[o], es++[o+1])
-- solve [o,1] es = ([1]++es++[o], es++[o+1])
solve [o1,o2] es = ([o1]++es++[o2], [o1-1]++es++[o2+1])

type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"

printList =
  putStrLn . unwords . map show


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%lld ",a)
using namespace std;
int n;
ll l,r,lbound,rbound,mid=0,qaq;
ll now;
int a[100050];
bool flag,f;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read(); l=2;
	for (int i=1;i<=n;i++)
	  a[i]=read();
	  r=1e15;
	  lbound=l; rbound=r;
	while (l<=r) {
	  f=false;
	  mid=(l+r)>>1; now=mid;
	  for (int i=1;i<=n;i++) {
	    now=(now/a[i])*a[i];
	    if (now<2&&i!=n) {
	      f=true; break;
	    }
	    if (now<a[i]) {
	      f=true; break;
	    }
	  }
	  if (now<2) f=true;
	    if (now==2) flag=true;
	    //printf("%d\n",now);
	  if (not f) r=mid-1;
	  else l=mid+1;
    }
    while (lbound<=rbound) {
    	f=false;
      mid=(lbound+rbound)>>1; now=mid;
      for (int i=1;i<=n;i++) {
        now=(now/a[i])*a[i];
        if (now<2&&i!=n) {
	      f=true; break;
	    }
	    if (now<a[i]) {
	      f=true; break;
	    }
	  }
	  if (now<=2) f=true;
        if (now==2) flag=true;
      //printf("%d\n",now);
      if (not f) rbound=mid-1;
      else lbound=mid+1;
  }
    if (flag) out(l),out(rbound);
    else puts("-1");
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#define MAX 10
using namespace std;

int main(int argc, char *argv[]){
	int unco[MAX];
	for(int i=0;i<MAX;i++)cin>>unco[i];
	sort(unco, unco+MAX);
	cout<<unco[9]<<endl;
	cout<<unco[8]<<endl;
	cout<<unco[7]<<endl;
	return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
vector<ll>adj[100005];
bool vist[100005];
void dfs(ll x){
  vist[x]=1;
  for(auto u:adj[x])
    if(!vist[u])
      dfs(u);
}
int main(){
    setIO();
    ll n,m;
    cin>>n>>m;
    ll cnt=0;
    for(int i=0;i<m;i++){
      ll x,y;
      cin>>x>>y;
      adj[x].pb(y);
      adj[y].pb(x);
    }
    for(int i=1;i<=n;i++)
      if(!vist[i]){
        dfs(i);
        cnt++;
      }
  cout<<cnt-1;
}


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

signed main(void)
{
	string s;
	cin >> s;
	int cnt;
	bool b;
	if (s[0] == '0') b = true;
	else b = false;
	cnt = 0;
	for(int i = 1; i < s.size(); i++)
	{
		if (s[i] == '0')
		{
			if (b)
			{
				cnt++;
				b = false;
			}
			else
				b = true;
		}
		else
		{
			if (!b)
			{
				b = true;
				cnt++;
			}
			else
				b = false;
		}
	}
	cout << cnt << endl;
	return 0;
}


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

int main()
{
    int n, a[105];
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    int sum = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        sum += a[i];
    }
    if (a[n - 1] < sum)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1,i,j;
   // cin>>t;
    while(t--)
    {
        int n,m,cnt=0,sum=0,maxi=0,mini=1e18;
        cin>>n>>m;
        
         if(n%2==0 && m%2==1)
        {
            for(i=1;i<n;i++)
            {
            if(cnt>m/2)
            {
                cout<<i<<" "<<n-i<<"\n";
            }
            else
            {
                cout<<i<<" "<<n-i+1<<"\n";
            }
            cnt++;
            if(cnt==m) break;
            }
        }
        
            else if(n%2==0 && m%2==0)
        {
            for(i=1;i<n;i++)
            {
            if(cnt>=m/2)
            {
                cout<<i<<" "<<n-i<<"\n";
            }
            else
            {
                cout<<i<<" "<<n-i+1<<"\n";
            }
            
            cnt++;
            if(cnt==m) break;
            }
        }
        
        else
        {
            for(i=1;i<n;i++)
            {
                cout<<i<<" "<<n-i<<"\n";
                cnt++;
                if(cnt==m) break;
            } 
        }
    }
}

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

bool isPrime(int x)
{
	long t = sqrt(x);
	if (x == 2)return true;
	for (int i = 2; i <= t; ++i)
	{
		if (x%i == 0)
			return false;
	}
	return true;
}

int main()
{
	int N;
	long long cnt = 0;
	cin >> N;
	int temp;
	while (N--)
	{
		cin >> temp;
		if (isPrime(temp))
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    using namespace std;
    
    void add_self(int&a,int b)
    {
        a+=b;
        if(a>=mod)
            a-=mod;
        //return;
    }
    int mul(int a,int b)
    {
        return (ll) a*b%mod;
    }

    int n;

    struct M
    {
        vector<vector<int>> t;
        M()
        {
            t.resize(n,vector<int>(n));
        }
        M operator* (const M& b) const
        {
            M c=M();
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                {
                    for(int k=0;k<n;k++)
                    {
                        add_self(c.t[i][k],mul(t[i][j],b.t[j][k]));
                    }
                }
            }
            return c;
        }
    };
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T=1;
        //cin>>T;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            //int n;
            
            ll k;
            cin>>n>>k;
            vector<vector<int>> can(n,vector<int>(n));
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                    cin>>can[i][j];
            }  
            M answer=M();
            for(int i=0;i<n;i++)
                answer.t[i][i]=1;

            M m=M();
            m.t=can;
            while(k)
            {
                if(k%2==1)
                    answer=answer*m;
                m=m*m;
                k=k/2;
            }
            int ans=0;
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                    add_self(ans,answer.t[i][j]);
            }
            cout<<ans;
        }
        return 0;
    }


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    char[] b = a.toCharArray();
    int[] count = new int[2];
    for(char i : b) {
      count[i - 'A']++;
    }
    if(count[0] == 0 || count[1] == 0) System.out.println("No");
    else System.out.println("Yes");
  }
}

Measured memory_bytes: 21972
#include <stdio.h>
int main()
{
	int a, b, n, ans = 0;
	scanf("%d%d", &a, &b);
	n = b - a;
	for (int i = 1; i < n; i++)
	{
		ans += i;
	}
	printf("%d", ans - a);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100003;
int n,fa[MaxN],dep[MaxN],sz[MaxN];
vector<int> e[MaxN];

void dfs(int x) {
	sz[x]=1;
	for (vector<int>::iterator i=e[x].begin();i!=e[x].end();++i)
		if (!fa[*i]) {
			fa[*i]=x;
			dep[*i]=dep[x]+1;
			dfs(*i);
			sz[x]+=sz[*i];
		}
}

int main() {
	scanf("%d",&n);
	for (int i=1;i<n;++i) {
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	fa[1]=1,dep[1]=0;
	dfs(1);
	int meet_dep=dep[n]/2;
	int x=n;
	while (dep[x]>meet_dep+1) x=fa[x];
	int a=sz[1]-sz[x],b=sz[x];
	if (a<=b) puts("Snuke");
	else puts("Fennec");
	return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int N = 1005;
int map[N][N];
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
const int INF = 0x3f3f3f3f;

int h, w;

struct Node
{
    int x, y;
    Node(int x, int y) : x(x), y(y) {}
};

int main()
{
    memset(map, INF, sizeof map);
    cin >> h >> w;
    char c;
    queue<Node> q;
    for (int i = 1; i <= h; i++)
        for (int j = 1; j <= w; j++)
        {
            cin >> c;
            if (c == '#')
            {
                map[i][j] = 0;
                q.push(Node(i, j));
            }
        }
    for (int i = 1; i <= h; i++)
        map[i][0] = map[i][w + 1] = 0;
    for (int i = 1; i <= w; i++)
        map[0][i] = map[h + 1][i] = 0;

    Node now(0, 0), nn(0, 0);
    while (!q.empty())
    {
        now = q.front();
        q.pop();
        for (int k = 0; k < 4; k++)
        {
            nn.x = now.x + dir[k][0];
            nn.y = now.y + dir[k][1];
            if (map[nn.x][nn.y] == INF)
            {
                map[nn.x][nn.y] = map[now.x][now.y] + 1;
                q.push(nn);
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= h; i ++)
        for (int j = 1; j <= w; j ++)
            if (map[i][j] > ans) ans = map[i][j];

    cout << ans << endl;
}

Measured memory_bytes: 12432
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var sb = new StringBuilder();
            string line;
            while((line = Console.ReadLine()) != null) sb.Append(line);
            line = sb.ToString();
            int num = 0;
            for(int i = 0; i < line.Length; i++)
            {
                if (line[i] >= '0' && line[i] <= '9')
                {
                    num += ParseNum(line, ref i);
                }
            }
            Console.WriteLine(num);
        }

        static int ParseNum(string s, ref int index)
        {
            int num = 0;
            for (; index < s.Length; index++)
            {
                if (s[index] < '0' || s[index] > '9') break;
                num = num * 10 + (s[index] - '0');
            }
            return num;
        }
    }
}

Measured memory_bytes: 5576
#include<stdio.h>

int main(void)
{
    int a,b,sum=0,i;
    scanf("%d%d",&a,&b);
    for(i = 0; i < 2; i++)
    {
        if(a>b){
        sum += a;
        a--;
    }else{
        sum += b;
        b--;
    }
    }
    
    printf("%d",sum);

    
    return 0;
}

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

int main(){
    int a,b,c,k ;
    cin >> a >> b >> c >> k ;
    if(a>b){
        int d = a ; a = b ; b = d ;
    }
    if(b>c){
        int d = b ; b = c ; c = d ;
    }
    for(int i=0;i<k;i++){
        c *= 2 ;
    }
    cout << a+b+c << endl ;
}


Measured memory_bytes: 256
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int K, N;
    cin >> K >> N;
    vector<ll> A(N);
    REP(i, N)
    {
        cin >> A[i];
    }
    ll dmax = K - A[N - 1] + A[0];
    for (int i = 1; i < N; ++i)
    {
        ll d = A[i] - A[i - 1];
        dmax = max(dmax, d);
    }
    ll ans = K - dmax;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4856
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 土  9/ 8 21:24:49 2018

# Usage
#
"""
from operator import and_
from functools import reduce
def get_nlines():
    N = int(input())
    return [input() for i in range(N)]


def tsunagari_check(first, second):
    if first[-1] == second[0]:
        return True
    else:
        return False

def judge(data):
    """
    >>> judge(["hoge","english", "hoge"])
    False
    >>> judge(["basic","cpp","python"])
    True
    >>> judge(["agg","abc", "cba"])
    False
    """
    # 1st check
    if len(set(data)) == len(data):
        pass
    else:
        return False

    # 2nd check
    checked = [tsunagari_check(data[i], data[i+1]) for i in range(len(data)-1)]
    # print(checked)
    return reduce(and_, checked)

if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    RES = judge(get_nlines())
    if RES:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c && a == c){
        cout << "No" << endl;
        return 0;
    }
    if(a != b && b != c && a != c){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    ll cnt = 0;
    ll cnt2 = 0;
    for(ll i=0;i<n;i++){
        ll x;
        cin >> x;
        if(x%4==0){
            cnt++;
        }else if(x%2==0){
            cnt2++;
        }
    }
    if(cnt+cnt2/2<n/2){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
    typedef Point P;
    T x, y;
    explicit Point(T x=0, T y=0) : x(x), y(y) {}
    bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
    bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
    P operator+(P p) const { return P(x+p.x, y+p.y); }
    P operator-(P p) const { return P(x-p.x, y-p.y); }
    P operator*(T d) const { return P(x*d, y*d); }
    P operator/(T d) const { return P(x/d, y/d); }
    T dot(P p) const { return x*p.x + y*p.y; }
    T cross(P p) const { return x*p.y - y*p.x; }
    T cross(P a, P b) const { return (a-*this).cross(b-*this); }
    T dist2() const { return x*x + y*y; }
    double dist() const { return sqrt((double)dist2()); }
    // angle to x-axis in interval [-pi, pi]
    double angle() const { return atan2(y, x); }
    P unit() const { return *this/dist(); } // makes dist()=1
    P perp() const { return P(-y, x); } // rotates +90 degrees
    P normal() const { return perp().unit(); }
    // returns point rotated 'a' radians ccw around the origin
    P rotate(double a) const {
        return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
    friend ostream& operator<<(ostream& os, P p) {
        return os << "(" << p.x << "," << p.y << ")"; }
};

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    typedef Point<double> P;

    int w, h, x, y; cin >> w >> h >> x >> y;
    bool can = x * 2 == w && y * 2 == h;

    double area = 1.0 * w * h / 2;
    cout << fixed << setprecision(11) << area << " " << can << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
q = int(input())
p = [list(map(int, input().split())) for _ in range(q)]


counter = [0] * 1000000
for i in a:
    counter[i] += 1
 
ans = sum(a)
 
for _ in p:
    ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]
    counter[_[1]] += counter[_[0]]
    counter[_[0]] = 0
    print(ans)

Measured memory_bytes: 39200
from sys import stdin

n, k = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
for i in range(1,n+1):
  m = 0
  x = i
  while x < k:
    m += 1
    x *= 2
  if m == 0:
    ans += 1
  else:
    ans += 1/(2**m)

ans /= n
print(ans)


Measured memory_bytes: 39664
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std; 
vector<int> v(1234);
int a, b; int c; int ans[1000];
int main()
{
     int n; cin >> n;
    for (int i = 0; i < n; i++)
        cin >> v[i];
    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> a >> b >> c;
        ans[i] = count(v.begin() + a , v.begin() + b, c);
    }
    for (int i = 0; i < q; i++)
        cout << ans[i] << endl;
}


Measured memory_bytes: 3100
from collections import defaultdict
N = int(input())
V = list(map(int,input().split()))
V1 = []
V2 = []
for i in range(N):
    if i % 2 == 0:
        V1.append(V[i])
    else:
        V2.append(V[i])

dic1 = defaultdict(int)
for v in V1:
    dic1[v] += 1
dic1 = sorted(dic1.items(), key=lambda x:x[1], reverse=True)

dic2 = defaultdict(int)
for v in V2:
    dic2[v] += 1
dic2 = sorted(dic2.items(), key=lambda x:x[1], reverse=True)

if dic1[0][0] != dic2[0][0]:
    ans = (N//2 - dic1[0][1]) + (N//2 - dic2[0][1])
else:
    ans1 = N//2 - dic1[0][1]
    if len(dic2) >= 2:
        ans1 += N//2 - dic2[1][1]
    else:
        ans1 += N//2

    ans2 = N//2 - dic2[0][1]
    if len(dic1) >= 2:
        ans2 += N//2 - dic1[1][1]
    else:
        ans2 += N//2

    ans = min(ans1, ans2)

print(ans)

Measured memory_bytes: 21084
using System;
using System.Linq;

namespace ABC080
{
    public class Problem_B
    {
        public static void Main(string[] args)
        {
            var n = Console.ReadLine();
            var sum = n.Select(c => (int) Char.GetNumericValue(c)).Sum();
            if (int.Parse(n) % sum == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <string>
#include <vector>
#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(){
    string a;
    float b;
    cin >> a >> b;
    ll ans = 0;
    int n = a.size();
    vector<ll> s(n);
    rep(i,n-2){
        ans *= 10;
        ll digit = a[i] - '0';
        s[i] = b * 100*digit + 0.5; 
        ans += ll(s[i]);
    }
    ll addi = 0;
    if(n-1 >= 1 ){
         addi = b*(10*(a[n-2] - '0') + a[n-1] - '0') + 0.001;
         //cout << addi << endl;
    }else {
        addi = b*(a[n-1] - '0') + 0.001;
        //cout << addi << endl;
    }
    ans += addi;
    cout << ans << endl;
}

Measured memory_bytes: 3700
N = int(input())
p_t = 0
p_x = 0
p_y = 0
answer = 'Yes'
for _ in range(N):
  n_t, n_x, n_y = map(int, input().split())
  time = n_t - p_t
  distance = abs(n_x - p_x) + abs(n_y - p_y)
  if time < distance or time % 2 != distance % 2:
    answer = 'No'
    break
  p_t = n_t
  p_x = n_x
  p_y = n_y
print(answer)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	defer stdout.Flush()
	a := readInt()
	b := readInt()
	c := a + b
	d := a - b
	e := a * b
	println(max(c, max(d, e)))
}

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}


Measured memory_bytes: 640
#pragma GCC target("avx")
#pragma GCC optimize ("Ofast")
#include <iostream>
#include <cmath>

template<typename T> void fastscan(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) { 
    putchar('0');
    putchar('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar('0');
  putchar('\n');
}
 
int main(){    
    int N; fastscan(N);
    int v[N];
    for (int i = 0; i < N; ++i) fastscan(v[i]);
    int sum = 0;
 
    for (int i = 1; i < N; ++i) sum += abs(v[i - 1] - v[i]);
    sum += abs(0 - v[0]) + abs(v[N - 1]);
    int diff[N]; 
    diff[0] = abs(0 - v[0]) + abs(v[0] - v[1]) - abs(0 - v[1]);
    for (int i = 1; i < N - 1; ++i){
        diff[i] = abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1]) - abs(v[i - 1] - v[i + 1]);
    }
    diff[N - 1] = abs(v[N - 2] - v[N - 1]) + abs(v[N - 1]) - abs(v[N - 2]);
 
    for (int i = 0; i < N; ++i){
        int ans = sum - diff[i];
        fastout(ans);
    }
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define endl '\n'

#define debug(x) cout << #x << " is " << x << endl;

int n,k;

string s;

deque<bool> dq;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin>>n>>k;
	cin>>s;
	
	for (int x=0;x<n;x++){
		dq.push_back(s[x]=='B');
	}
	
	//A is false
	//B is true
	bool parity=false;
	
	while (k--){
		while (!dq.empty() && (dq.back()^parity)==((n-dq.size())&1)) dq.pop_back();
		if (dq.empty()){
			if (n&1) putchar((k&1)?'A':'B');
			for (int x=n&1;x<n;x++){
				putchar(((n-x)&1)?'A':'B');
			}
			return 0;
		}
		if (!(dq.front()^parity)){
			dq.front()^=true;
		}
		else{
			dq.pop_front();
			parity^=true;
		}
	}
	
	for (auto &it:dq){
		putchar((it^parity)?'B':'A');
	}
	for (int x=dq.size();x<n;x++){
		putchar(((n-x)&1)?'A':'B');
	}
}

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

int main()
{
	int a, b, c, d, e;
	int ans;
	
	cin >> d;
		for(int i = 0; i < d; i++)
		{
			cin >> a >> b >> c;
			
			if(a > b && a > c)
			{
					e = c;
					c = a ;
					
					ans = c * c - e * e - b * b;
				if(ans == 0)
				{
					cout << "YES" << endl;
				}
				else
				{
					cout << "NO" << endl;
				}
			}
	
			else if (b > c && b > a)
			{
				e = c;
				c = b;
			
					ans = c * c - e * e - a * a;
					if(ans == 0)
					{
						cout << "YES" << endl;
					}
					else
					{
						cout << "NO" << endl;
					}
			}
			else 
			{
				ans = c * c - a * a - b * b;
				if(ans == 0)
				{
					cout << "YES" << endl;
				}
				else
				{
					cout << "NO" << endl;
				}
			}
		}
			
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define pi =3.14159265358979323846264338327950L;
typedef long long int ll;
int mod=1e9+7;


int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
	long double a,b;
	cin>>a>>b;
	long double ans= a*b;
	cout<<(ll)ans<<endl;
	return 0;
}


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

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

    int arr[11] = { 0 };
    int a, b, c;
    cin >> a >> b >> c;
    arr[a]++;
    arr[b]++;
    arr[c]++;

    if (arr[5] == 2 && arr[7] == 1)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256