akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, C, K = Scanner.map_int()
    T = Scanner.int_cols_list(N)
    T.sort()
    ans = 0
    cnt = 0
    lim = 0
    for i in range(N):
        if cnt == 0:
            lim = T[i] + K
        elif lim < T[i]:
            ans += 1
            lim = T[i] + K
            cnt = 0
        cnt += 1
        if cnt == C:
            ans += 1
            cnt = 0
            lim = 0
    if cnt > 0:
        ans += 1
    print(ans)
    return


if __name__ == "__main__":
    main()


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

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()
    return divisors

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

ans = 0
alr = set()
while True:
    divisors = set(make_divisors(N))
    diff = divisors.difference(alr)
    pos = list(diff)
    pos.sort()
    for num in pos:
        fact = prime_factorize(num)
        if len(set(fact)) == 1:
            alr.add(num)
            ans += 1
            N = N // num
            break
    else:
        break

print(ans)




Measured memory_bytes: 9712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  string n;
  cin >> n;
  rep(i,n.size()){
    if(n[i]=='7'){
      cout << "Yes" << endl;
      return 0;
    }

  }
  cout << "No" << endl;
  return 0;
    

}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1000;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl h(n+1);
    rep(i, n) {
        cin >> h[i];
    }

    ll ans = 0;
    while(1) {

        bool allZero = true;
        rep(i, n) {
            if(h[i] > 0) {
                allZero = false;
                break;
            }
        }
        if(allZero) {
            out(ans);
            re0;
        }
        
        ll l = -1;
        ll u = INF;
        exrep(i, 0, n) {
            if(l == -1 && h[i] > 0) {
                l = i;
            }
            else if(l != -1 && h[i] == 0) {
                exrep(j, l, i-1) {
                    h[j] -= u;
                }
                ans += u;
                l = -1;
                u = INF;
            }
            if(h[i] > 0) {
                chmin(u, h[i]);
            }
        }

    }

    re0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////

//cf: 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);  
    #endif

	string s;
	cin >> s;
	int l = s.length();
	int counter = 0;
	for (int i = 0; i < l/2; i++) {
			if (s[i] != s[l-i-1])
				counter++;
	}
	cout << counter;

    #ifndef ONLINE_JUDGE   
    //cout << endl << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <typeinfo>
#include <queue>
#include <set>
#include <sstream>

using namespace std;

#define RSORT(c) sort((c).begin(),(c).end(),std::greater<int>())
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SORT(c) sort((c).begin(),(c).end())

static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
#define MAX 200000
#define SENTINEL 10000000000
typedef long long ll;


void c1(){
  int l = 10;
  string s;
  cin >> s;
  //s[4] = "8";
  s.replace(3, 1, "8");
  cout << s << endl;
}

void c2(){
  int n;
  cin >> n;
  int tmp;
  vector<int> vec;
  REP(i,n){
    cin >> tmp;
    vec.push_back(tmp);
  }
  SORT(vec);
    //erace(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec.size() << endl;
}

int main(){
  //c1();
  c2();
  return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
H, W = map(int, readline().split())
c = [list(map(int, readline().split())) for _ in range(10)]

for i in range(10):
    for j in range(10):
        for k in range(10):
            c[j][k] = min(c[j][k], c[j][i] + c[i][k])
magic = [c[i][1] for i in range(10)]
ans = 0
for _ in range(H):
    row = map(int, readline().split())
    ans += sum(magic[i] for i in row if i != -1)
print(ans)


Measured memory_bytes: 3188
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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

int digit(int v){
	int ret=0;
	while(v){
		ret+=v%10;
		v/=10;
	}
	return ret;
}
int main() {
	int N;
	cin >> N;
	int ret=INT_MAX;
	for(int i=1;i<N;i++){
		ret=min(ret,digit(i)+digit(N-i));
	}
	cout << ret << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}   

/* 
NxMのマス目にK個コマを置いた時の
コマ同士のマンハッタン距離の総和を
全てのコマの置き方について合計

XとYは独立なのでまずXについて考える
ある2つのコマの組み合わせを考えると、
それ以外のコマの置き方の組合わせは Combination(N*M-2, K-2) = tmp1
距離がdとなる2つのコマの組み合わせは (N-d) * M * M = tmp2
よってXの総和は tmp1 * (すべてのdについてのtmp2の合計)
*/
int main() {
	// 入力
	ll N,M,K;cin>>N>>M>>K;
    
	// 解法
    COMinit();

    ll X = 0;
    REP(d,N){
        X += d * (N-d) * M * M;
        X %= MOD;
    }
    X *= COM(N*M-2, K-2);
    X %= MOD;

    
    ll Y = 0;
    REP(d,M){
        Y += d * (M-d) * N * N;
        Y %= MOD;
    }
    Y *= COM(N*M-2, K-2);
    Y %= MOD;
    ll ans = X + Y;
    ans %= MOD;

	//出力
	cout << ans << endl;
}


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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int odd = 0;
  while (n--) {
    int x;
    scanf("%d", &x);
    odd += (x & 1);
  }
  puts(odd % 2 == 0 ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

#define N 1000005
ll dp[N][256];
void solve(){
    while(1){
        ll n,m;cin>>n>>m;
        if(n==0&&m==0)return;
        vl c(m);rep(i,m)cin>>c[i];
        vl x(n);rep(i,n)cin>>x[i];

        rep(i,n+1)rep(j,256)dp[i][j]=LINF;
        dp[0][128]=0;
        rep(i,n){
            rep(j,256){
                rep(k,m){
                    ll to=max(0LL,min(j+c[k],255LL));
                    chmin(dp[i+1][to],dp[i][j]+(to-x[i])*(to-x[i]));
                }
            }
        }
        ll ans=LINF;
        rep(i,256)chmin(ans,dp[n][i]);
        cout<<ans<<endl;
    }
}

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



Measured memory_bytes: 43184
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let s = sc.chars();
    if s.len() % 2 != 0 {
        println!("No");
        return;
    }
    for i in 0..s.len() {
        if i % 2 == 0 && s[i] != 'h' {
            println!("No");
            return;
        }
        if i % 2 != 0 && s[i] != 'i' {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <cstdio>
int main(void){
    int a[100+1],i,n,v,j,m;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        i==n-1?printf("%d\n",a[i]):printf("%d ",a[i]);
    }
    
    for(i=1;i<n;i++){
        v=a[i];
        j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        for(m=0;m<n;m++)m==n-1?printf("%d\n",a[m]):printf("%d ",a[m]);
    }
    return 0;
}

Measured memory_bytes: 2684
def dist(p0, p1):
    return abs(p0[0] - p1[0]) + abs(p0[1] - p1[1])


def main():
    n, m = map(int, input().split())
    ss = [list(map(int, input().split())) for _ in range(n)]
    pp = [list(map(int, input().split())) for _ in range(m)]
    for i in range(n):
        d_min = dist(ss[i], pp[0])
        d_min_j = 0
        for j in range(1, m):
            d = dist(ss[i], pp[j])
            if d < d_min:
                d_min = d
                d_min_j = j
        print(d_min_j + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (isok).erase(unique(ALL((isok))),(isok).end())
# define LOWER(s)    transform(ALL((maze)),(maze).begin(),TL<char>)
# define UPPER(s)    transform(ALL((maze)),(maze).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)


int n, m;
int h[1510], w[1510];
LL hcnt[1500001] = {}, wcnt[1500001] = {};


int main() {
	while (cin >> n >> m&&n&&m) {
		for (int i = 1; i <= n; i++) {
			cin >> h[i];
		}
		for (int i = 1; i <= m; i++) {
			cin >> w[i];
		}
		REP(i, 1500001)hcnt[i] = wcnt[i] = 0;
		for (int i = 1; i <= n; i++) {
			int he = h[i];
			hcnt[he]++;
			for (int j = i + 1; j <= n; j++) {
				he += h[j];
				hcnt[he]++;
			}
		}
		for (int i = 1; i <= m; i++) {
			int he = w[i];
			wcnt[he]++;
			for (int j = i + 1; j <= m; j++) {
				he += w[j];
				wcnt[he]++;
			}
		}
		LL ans = 0;
		REP(i, 1500001) {
			if(i)ans += wcnt[i] * hcnt[i];
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 26524
{-# LANGUAGE PartialTypeSignatures #-}
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L

main :: IO ()
main = do
  [x,n] <- readInts
  readInts >>= output . solve (x,n)

solve :: (Int,Int) -> [Int] -> _
-- solve (x,0) _ = x
solve (x,_) xs = check $ zip [x,x-1..] [x..]
  where
    check ((y1,y2):ys)
      | y1 `elem` xs && y2 `elem` xs = check ys
      | y1 `elem` xs = y2
      | y2 `elem` xs = y1
      | otherwise = y1

output :: _ -> IO ()
output = print

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

Measured memory_bytes: 3780
// ref: https://img.atcoder.jp/arc094/editorial.pdf
// ref: https://drken1215.hatenablog.com/entry/2018/09/08/195000

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int64 solve(int64 a, int64 b){
    if(a==b){ return (a-1)*2; }
    int64 lim = a*b-1;
    int64 low=1, high=INT_MAX; // INT_MAX is int32 max.
    while(high - low > 1){
        int64 mid = (low+high)/2;
        int64 val = ( (mid+1)/2 )*( (mid+1) - (mid+1)/2 );
        if(val > lim){ high=mid;
        }    else    { low =mid; }
    }
    return low-1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int Q; cin >> Q;
    for(int i=0; i<Q; ++i){
        int A, B; cin >> A >> B;
        cout << solve(A, B) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -----------------------------------------------------------------------
int dp[100];
int func(int n){
	if(n==0)
	return 2;
	if(n==1)
	return 1;
	if(dp[n]!=0)
	return dp[n];
	dp[n]=func(n-1)+func(n-2);
	return dp[n];
}
// -----------------------------------------------------------------------

int fre[26];
void solve(){
	int n;
	cin>>n;
	cout<<func(n);
}


// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll n;
    cin>>n;
    vector<ll>v(n);
    rep(i,n)cin>>v[i];
    sort(v.begin(),v.end());
    long double now=0;
    rep(i,n){
        if(now==0)now=v[i];
        else{
            now=(now+v[i])/2.0;
        }
    }
     cout<<now<<endl;
}


Measured memory_bytes: 3724
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long chk = 0;
		for(int i=0;i<s.length();i++){
		    chk += (s.charAt(i)-48);
		}
		if(chk%9==0){
		    System.out.println("Yes");
		}
		else{
		    System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 40248
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
 
int main(){
	string str,str1,str2;
	char A,C,Sn;
	stack<char> st;
	int n;
	
	cin >> str >> str1 >> str2;
	n = str.size();
	
			st.push(str1[0]);
			Sn = st.top();
	A = 'A';
	C = 'C';
	cout << A ;
	cout << Sn;
	cout << C;
	
		 
 
     
	return 0;
}

Measured memory_bytes: 256
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

n = int(input())
a = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    a.append([s, -p, i + 1])

a.sort()

for i in a:
    print(i[2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

int main() {
    cin>>N;
    set<ll> rest;
    vec num(1000100, 0);
    rep(i,N){
        cin>>A;
        ++num[A];
        rest.insert(A);
    }
    ll ans = 0;
    if(*rest.begin() == 1){
        cout<<(num[1] == 1)<< endl;
        return 0;
    }
    for(ll v : rest){
        ans += num[v] == 1;
        for(ll i = v * 2; i <= 1000100; i += v){
            rest.erase(i);
        }
    }
    cout<<ans<<endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define CLR(a, b) memset((a), (b), sizeof((a)))
template <typename t> bool ckmin(t& a, const t& b) {return a > b ? a = b, true : false;}
template <typename t> bool ckmax(t& a, const t& b) {return a < b ? a = b, true : false;}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
if (DEBUG) std::cerr

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

    int n;
    cin >> n;
    vi amt(n);
    F0R(i, n - 1) {
        int k;
        cin >> k;
        amt[k - 1]++;
    }
    F0R(i, n)
        cout << amt[i] << endl;
}




Measured memory_bytes: 3952
s=input()
t=input()
l=max(len(s),len(t))
slist = []
tlist = []
for i in range(l):
    if i < len(s):
        slist.append(s[i])
    if i < len(t):
        tlist.append(t[i])
slist.sort()
tlist.sort(reverse=True)
result = 'Yes'
if s==t:
    result = 'No'
else:
    for j in range(l):
        if j < len(s) and j < len(t):
            if slist[j] == tlist[j]:
                continue
            elif slist[j] < tlist[j]:
                break
            else:
                result = 'No'
                break
        elif len(s) > len(t):
            result = 'No'
            break
print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

class unionFindTree {
private:
	vector <int> tree;
	vector <int> rank;

public:
	unionFindTree() {}

	unionFindTree(int sz) {
		tree = vector <int> (sz);
		rank = vector <int> (sz, 0);
		for(int i = 0; i < tree.size(); i++)
			tree[i] = i;
	}

	unionFindTree(const unionFindTree &o) {
		tree = o.tree;
		rank = o.rank;
	}

	unionFindTree &operator=(const unionFindTree &o) {
		tree = o.tree;
		rank = o.rank;
		return (*this);
	};

	int root(int x) {
		return tree[x] == x ? x : tree[x] = root(tree[x]);
	}

	bool same(int a, int b) {
		return root(a) == root(b);
	}

	void unite(int a, int b) {
		a = root(a);
		b = root(b);
		if(a == b)return;

		if(rank[a] < rank[b]) swap(a, b);

		tree[b] = a;
		rank[a] += (rank[a] == rank[b]);
	}

	int size() {
		return tree.size();
	}

	int showRank(int i) {
		return rank[i];
	}
};


signed main() {
	int n, k, l;
	cin >> n >> k >> l;
	unionFindTree road(n), rail(n);
	rep (i, k) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		road.unite(a, b);
	}
	rep (i, l) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		rail.unite(a, b);
	}
	pair <int, int> pear[n];
	map <pair <int, int>, int> berry;
	rep (i, n) {
		pear[i] = {road.root(i), rail.root(i)};
		berry[make_pair(road.root(i), rail.root(i))]++;
	}

	rep (i, n) cout << berry[pear[i]] << (i == n - 1 ? '\n' : ' ');
	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back

vec<vec<int>> p;
int n, m;

int ans = 0;
vec<int> check;

void solve(vec<int> dp, int point)
{
	rep(i, p[point].size()) {
		int x = p[point][i];
		if (!dp[x]) {
			dp[x] = 1;
			solve(dp, x);
			dp[x] = 0;
		}
	}
	if (dp == check) ans++;
}

int main(void)
{
	cin >> n >> m;
	p.resize(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		p[a].pb(b);
		p[b].pb(a);
	}

	check.resize(n);
	rep(i, n) check[i] = 1;
	vec<int> give(n);
	give[0] = 1;
	solve(give, 0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(long long i=0; i<n; i++)

int main(){
  long long K;
  cin >> K;

  queue<long long> q;

  rep(i, 9)
    q.push(i+1);

  if(K<10){
    rep(i, K-1)
      q.pop();
    cout << q.front() << endl;
    return 0;
  }
  
  long long count = 9;
  long long i, j;
  long long n, one_d;
  while(1){
    n = q.front(); q.pop();
    one_d = n%10;
    if(one_d != 0){
      q.push(n*10 + one_d-1);
      if(++count == K){
	cout << q.back() << endl;
	return 0;
      }
    }
    
    q.push(n*10+one_d+0);
    if(++count == K){
      cout << q.back() << endl;
      return 0;
    }

    if(one_d != 9){
      q.push(n*10 + one_d+1);
      if(++count == K){
        cout << q.back() << endl;
        return 0;
      }
    }  
  }
  
  return 0;
}


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

using namespace std;

struct UnionFind {
  UnionFind(int32_t n)
      : parent(vector<int32_t>(n, 0)), size(vector<int32_t>(n, 0)) {
    for (int i = 0; i < n; i++) {
      parent[i] = i;
      size[i] = 1;
    }
  }

  int32_t Root(int32_t a) {
    if (parent[a] == a) {
      return a;
    } else {
      return parent[a] = Root(parent[a]);
    }
  }

  bool IsSame(int32_t a, int32_t b) { return Root(a) == Root(b); }

  void Unite(int32_t a, int32_t b) {
    a = Root(a);
    b = Root(b);

    if (a == b) return;

    if (size[a] > size[b]) {
      parent[b] = a;
      size[a] += size[b];
      size[b] = 0;
    } else {
      parent[a] = b;
      size[b] += size[a];
      size[a] = 0;
    }
  }

  int32_t Size(int a) { return size[Root(a)]; }

  vector<int32_t> parent;
  vector<int32_t> size;
};  // struct UnionFind

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.Unite(a, b);
  }
  int answer = 0;
  for (int i = 0; i < N; i++) {
    answer = max(answer, uf.Size(i));
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 4836
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
ans = p[:x]+q[:y]+r[:x+y]
ans.sort(reverse = True)
print(sum(ans[:x+y]))


Measured memory_bytes: 113004
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	double adLine[2][2];
	double adDirection[2];
	int i, nPoint;

	for (i = 0; i < 2; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		adLine[i][0] = x;
		adLine[i][1] = y;
	}

	{
		double dLength;
		adDirection[0] = adLine[1][0] - adLine[0][0];
		adDirection[1] = adLine[1][1] - adLine[0][1];
		dLength = sqrt(adDirection[0] * adDirection[0] + adDirection[1] * adDirection[1]);
		adDirection[0] /= dLength;
		adDirection[1] /= dLength;
	}

	scanf("%d", &nPoint);

	for (i = 0; i < nPoint; i++) {
		double adPointVector[2], dInnerProduct, dProjection[2];
		int x, y;
		scanf("%d%d", &x, &y);
		adPointVector[0] = x - adLine[0][0];
		adPointVector[1] = y - adLine[0][1];

		dInnerProduct = adPointVector[0] * adDirection[0] + adPointVector[1] * adDirection[1];

		dProjection[0] = adLine[0][0] + adDirection[0] * dInnerProduct;
		dProjection[1] = adLine[0][1] + adDirection[1] * dInnerProduct;

		printf("%.10f %.10f\n", dProjection[0], dProjection[1]);
	}

	return 0;
}

Measured memory_bytes: 640
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		while (true) {
			String s = sc.next();
			if (s.equals("0")) return;
			int sum = 0;
			for (int i=0; i<s.length(); i++) {
				sum += s.charAt(i) - '0';
			}
			System.out.println(sum);
		}
		
		
	}
}


Measured memory_bytes: 26296
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    int num;
    int *x;
    int *y;

    std::cin >> num;

    x = new int[num];
    y = new int[num];

    for (int i = 0; i < num; i++)
        std::cin >> x[i];
    
    for (int i = 0; i < num; i++)
        std::cin >> y[i];

    double d1 = 0, d2 = 0, d3 = 0, di = 0;
    for (int i = 0; i < num; i++)
    {
        double temp = std::abs(x[i]-y[i]);
        d1 += temp;
        d2 += pow(temp, 2);
        d3 += pow(temp, 3);
        
        if (temp > di) di = temp;
    }

    d2 = sqrt(d2);
    d3 = cbrt(d3);

    std::cout << std::fixed << std::setprecision(5) << d1 << std::endl;
    std::cout << std::fixed << std::setprecision(5) << d2 << std::endl;
    std::cout << std::fixed << std::setprecision(5) << d3 << std::endl;
    std::cout << std::fixed << std::setprecision(5) << di << std::endl;
}


Measured memory_bytes: 3468
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        double sum = 0;
        sc.close();
        for(int i = 1 ; i <= n ; i++){
            int a = i;
            double yono = 1;
            while(k > a){
                yono /= 2.0;
                a *= 2;
            }
            sum += yono;
        }
        System.out.println(sum / n);
    }
}


Measured memory_bytes: 35900
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

ll comb(ll n, ll r) {
    ll ret = 1;
    for (ll i = 0; i < r; i++) ret = ret * (n - i);
    for (ll i = 1; i <= r; i++) ret = ret / i;
    return ret;
}

int main(){
   ll n; cin >> n;
   vector<ll> a(n);
   vector<ll> sum(n+1,0);
   ll ans = 0, count = 0, mem = 0;

   rep(i,n) cin >> a[i];

   sum[0] = 0;
   rep(i,n) sum[i+1] = sum[i] + a[i];

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

   mem = -1;

   rep(i,n+1){
        if(mem == sum[i]){
            count ++;
        }else{
            if(count >= 2) ans += comb(count,2);
            count = 1;
            mem = sum[i];
        }
   }

    if(count >= 2) ans += comb(count,2);

    cout << ans;



}

Measured memory_bytes: 6280
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	ll x, n = 100, ans = 0;
	cin >> x;
	while (n < x) {
		n += n / 100;
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
// -*- coding:utf-8-unix -*-

#[macro_use]
extern crate lazy_static;
extern crate num_bigint;
// 0.2.2
extern crate num_traits;

// 0.2.8
use num_bigint::BigInt;
use num_bigint::ToBigInt;
use num_traits::{Pow, ToPrimitive};
use num_traits::{One, Zero};

// use proconio::derive_readable;
use itertools::*;
use itertools_num::*;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
// use ascii::Chars;
// use libm::*;
use proconio::marker::{Bytes, Chars};
use std::cmp::*;
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::*;
use std::ops::Range;
use std::str::FromStr;
use superslice::*;

use lazy_static::lazy_static;
use std::sync::Mutex;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

lazy_static! {
    // static ref PARENTS: Mutex<Vec<usize>> = Mutex::default();
    // static ref CHILDS: Mutex<Vec<Vec<usize>>> = Mutex::default();
    static ref ADJ: Mutex<Vec<Vec<usize>>> = Mutex::default();
}

// const MOD: usize = 9997063;
// const MOD: usize = 100_000_000_ + 7;

//abc164-D
// #[fastout]
fn main() {
    input![s: Chars];

    let mut charge = 0;
    let mut ans = 0;
    for s in s.iter(){
        if *s == 'g' {
            if charge > 0 {
                ans += 1;
                charge -= 1;
                // eprintln!("p: {}", charge);
            }else{
                charge += 1;
                // eprintln!("g: {}", charge);
            }
        }else{
            if charge > 0 {
                // ans += 1;
                charge -= 1;
                // eprintln!("p: {}", charge);
            }else{
                charge += 1;
                ans -= 1;
                // eprintln!("g: {}", charge);
            }
        }
    }


    // eprintln!("{:?}", adj);
    println!("{}", ans);
}

// let mut values = VALUES.lock().unwrap();
// values.extend_from_slice(&[1, 2, 3, 4]);
// assert_eq!(&*values, &[1, 2, 3, 4]);

// -100000000

//  1000000000


Measured memory_bytes: 2496
import random
def N():
    num=Dice[0]
    Dice[0]=Dice[1]
    Dice[1]=Dice[5]
    Dice[5]=Dice[4]
    Dice[4]=num
def E():
    num=Dice[0]
    Dice[0]=Dice[3]
    Dice[3]=Dice[5]
    Dice[5]=Dice[2]
    Dice[2]=num
def W():
    num=Dice[0]
    Dice[0]=Dice[2]
    Dice[2]=Dice[5]
    Dice[5]=Dice[3]
    Dice[3]=num
def S():
    num=Dice[0]
    Dice[0]=Dice[4]
    Dice[4]=Dice[5]
    Dice[5]=Dice[1]
    Dice[1]=num
Dice=[int(i) for i in input().split()]
a=int(input())
for i in range(a):
    x,y=map(int,input().split())
    while True:
        rand=random.randint(1,4)
        if rand==1:
            N()
        elif rand==2:
            E()
        elif rand==3:
            W()
        else:
            S()
        if Dice[0]==x and Dice[1]==y:
            break
    print(Dice[2])

Measured memory_bytes: 11748
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0;
  cin >> N;
  vector<ll>A(N);
  vector<ll>B(N);
  rep(i,N){
    cin >> A[i];
    B[i] = A[i];
  }
  sort(A.begin(), A.end()); //小さい順
  reverse(A.begin(), A.end());
  rep(i,N){
    if(B[i] == A[0]){
      cout << A[1] << endl;
    }
    else{
      cout << A[0] << endl;
    }
  }
}

Measured memory_bytes: 6424
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	for(int i = 0; i < n; i++) {
		a[i] = 0;
		std::cin >> a[i];
	}
	while(k--) {
		std::vector<int> b(n+1, 0);
		for(int i = 0; i < n; i++) b[std::max(0, i - a[i])]++;
		for(int i = 0; i < n; i++) b[std::min(n, i + a[i] + 1)]--;
		bool go = false;
		for(int i = 0; i < n; i++) {
			if(i) b[i] += b[i-1];
			a[i] = b[i];
			if(a[i] != n) go = true;
		}
		if(!go) break;
	}
	for(int i = 0; i < n; i++) {
		std::cout << a[i] << (i + 1 == n ? '\n' : ' ');
	}
}

Measured memory_bytes: 5048
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <iomanip>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int t = 1000;

    vector<vector<int>> x(a, vector<int>(b, t));

    for (int i = 0; i + c - 1 < a; i += c) {
        for (int j = 0; j + d - 1 < b; j += d) {
            x[i + c - 1][j + d - 1] = -t * (c * d - 1) - 1;
        }
    }

    long long s = 0;

    for (int i = 0; i < a; i++) {
        for (int j = 0; j < b; j++) {
            s += x[i][j];
        }
    }

    if (s <= 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;

        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                cout << x[i][j] << " \n"[j + 1 == b];
            }
        }
    }
}


Measured memory_bytes: 2560
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
import Data.Array.IArray
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
-- end of templete

f :: Int -> Int -> Int -> Int -> Int -> Int
f a b c d e = f' a (a>0)
  where
    f' t j
      | t==b = 0
      | t<0 = let v = min b 0 in c * (v - t) + f' v j
      | t>0 = e * (b - t)
      | j = e * (b - t)
      | not j = d + f' t True

main = replicateM 5 getInt >>= \[a,b,c,d,e] -> print $ f a b c d e


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long 
#define vi vector<int>
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;

const int N=5e5+1;

ll n,r;
int main(){
    cin>>n>>r;
    if(n>=10) cout<<r;
    else cout<<(r+100*(10-n));   
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = {}
for i in range(N):
    S = list(input())
    S.sort()
    S = ''.join(S)
    A[S] = A.get(S, 0) + 1
 
ans = 0
for i in A.values():
    if i > 1:
        iL = [j for j in range(i)]
        ans += sum(iL)
    
print(ans)

Measured memory_bytes: 17924
#coding: utf-8

n = list(map(int, input().split()))
sx = n[0]
sy = n[1]
tx = n[2]
ty = n[3]
x = tx - sx
y = ty - sy

if x >= 0 and y >= 0:
    print("R" * x + "U" * y + "L" * x + "D" * y + "D" + "R" * (x + 1) + "U" * (y + 1) + "L" + "U" + "L" * (x + 1) + "D" * (y + 1) + "R")
elif x < 0 and y >= 0:
    print("L" * x + "U" * y + "R" * x + "D" * y + "D" + "L" * (x + 1) + "U" * (y + 1) + "R" + "U" + "R" * (x + 1) + "D" * (y + 1) + "L")
elif x >= 0 and y < 0:
    print("R" * x + "D" * y + "L" * x + "U" * y + "U" + "R" * (x + 1) + "D" * (y + 1) + "L" + "D" + "L" * (x + 1) + "U" * (y + 1) + "R")
else:
    print("L" * x + "D" * y + "R" * x + "U" * y + "U" + "L" * (x + 1) + "D" * (y + 1) + "R" + "D" + "R" * (x + 1) + "U" * (y + 1) + "L")

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<deque>
#include<set>
#define inf 1e9
#define eps 1e-6
#define N 1010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
const int mod=998244353;
map<string,int>ma[2];
string s;
inline int Z(int x){return x>=mod?x-mod:x;}
int dfs(int opt,string a)
{
	if(ma[opt].find(a)!=ma[opt].end())return ma[opt][a];
	int len=a.length(),ans=0;
	if(opt)
	{
//		cout<<"EEE:"<<a<<endl;cout<<"WTF:"<<a.substr(0,0)<<" "<<a.substr(0,len)<<endl;
		for(register int i=0;i<len;i++)ans=Z(ans+1LL*dfs(1,a.substr(0,i))*dfs(0,a.substr(i,len))%mod);
	}
	else
	{
		for(register int t=1;t<len;t++)
		{
			if(len%t)continue;
			string tmp="";int p=t;while(p--)tmp+='1';
			for(register int i=0;i<len;i+=t)
			{
				for(register int j=0;j<t;j++)
				{
					if(a[i+j]=='0')tmp[j]='0';
				}
			}
			ans=Z(ans+dfs(1,tmp));
		}
	}
	return ma[opt][a]=ans;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ma[0][""]=ma[1][""]=ma[0]["0"]=ma[1]["0"]=1;
	ma[0]["1"]=ma[1]["1"]=2;
	cin>>s;
	printf("%d\n",dfs(1,s));
	return 0;
}


Measured memory_bytes: 14008
/*
* Created by: WeirdBugsButOkay
*/

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

void solve()
{
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n], b[m];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    for(ll i = 0; i < m; i++)
        cin >> b[i];
    ll ans = 0;
    ll sum = 0;
    ll psum[m];
    psum[0] = b[0];
    for(ll i = 1; i < m; i++)
        psum[i] = psum[i - 1] + b[i];
    for(ll i = -1; i < n; i++)
    {
        if(i > -1)
            sum += a[i];
        ll left = k - sum;
        if(left < 0)
            break;
        ll pos = upper_bound(psum, psum + m, left) - psum;
        //cout << i << " " << pos << endl;
        ans = max(ans, i + 1 + pos);
    }
    cout << ans << endl;
}

int main()
{
    int q = 1;
    //scanf("%d", &q);
    for(int i = 1; i <= q; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 8312
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1001001001001;
int main(){
  int n;
  cin >> n;
  vector<long long> acc(n + 1);
  acc[0] = 0;
  long long temp;
  for(int i = 0; i < n; ++i){
    cin >> temp;
    acc[i + 1] += temp + acc[i];
  }
  long long ans = INF;
  for(int i = 1; i < n; ++i){
    ans = min(ans, abs((acc[n] - acc[i]) - acc[i]));
  }
  cout << ans << endl;
}

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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string X; cin >> X;
  int t = 0;
  int s = 0;
  for (int i = 0; i < (int)X.size(); i++) {
    if (X.at(i) == 'S') {
      s++;
    }else if (X.at(i) == 'T') {
      if (s > 0) s--;
      else t++;
    }else {
      assert(false);
    }
  }
  cout << t + s << endl;

  return 0;
}



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

long long max(long long a, long long b)
{
    if (a >= b){
        return a;
    }
    else {
        return b;
    }
}

long long min(long long a, long long b, long long c) 
{
    if (a <= b) {
        if (a <= c){
            return a;
        }
        else {
            return c;
        }
    }
    else {
        if (b <= c) {
            return b;
        }
        else {
            return c;
        }
    }
}

int main()
{
    long long a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    long long ans_1, ans_2, ans_3, ans;
    long long  z;
    long long D = 1000000;

    ans_1 = a*x+b*y;
    ans_2 = 2*c*max(x,y);

    if (min(x,y,D) == x) {
        z = b;
    }
    else {
        z = a;
    }
    ans_3 = 2*c*min(x,y,D) + z*(max(x,y)-min(x,y,D));

    ans = min(ans_1,ans_2,ans_3);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256