akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.readline


def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    A.sort()

    M = A[-1]
    flg = [0] * (M + 1)
    res = 0

    for a in A:
        if flg[a] == 0:
            res += 1
        if flg[a] == 2:
            res -= 1
            flg[a] = 1
        if flg[a] > 0:
            continue
        flg[a] = 2
        for i in range(2, 10**6):
            if a * i > M:
                break
            flg[a*i] = 1
    
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 93164
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, M; cin >> N >> M;
    Ans(N == M, "Yes", "No");

    return 0;
}


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

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

	int c=0;
	for (int i = 0; i < s.size()-i; i++)
	{
      	c += s[i]==s[s.size()-i-1]?0:1;
	}
  
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
a = [int(input()) for i in range(5)]
k = int(input())

flag = 0
for i in a:
    for j in a:
        if abs(i-j) > k:
            flag = 1
            break            
    else:
        continue
    break

if flag == 1:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
    #define dbug printf("I am here\n");
    #define Fast ios_base::sync_with_stdio(false); cin.tie(0);
    #define vs            v.size()
    #define ss             s.size()
    #define be            v.begin(),v.end()
    #define pii             pair<int,int>
    #define ll               long long
    #define pb             push_back
    #define mpp            make_pair
    using namespace std;

    int main() {

    ll int b,c,d,n,k;
    int tst;
    double a;
    string s;
    cin>>a;
    cout<<a+pow(a,2)+pow(a,3)<<endl;



        return 0;
    }


Measured memory_bytes: 4252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
	    String str=reader.readLine();
	    String s1[]=str.split(" ");

	    int a=Integer.parseInt(s1[0]);
	    int b=Integer.parseInt(s1[1]);
	    int c=Integer.parseInt(s1[2]);
	    int d=Integer.parseInt(s1[3]);

	    int sx=0;
	    int sy=0;
	    int tx=c-a;
	    int ty=d-b;

	    StringBuilder sb=new StringBuilder();
	    for(int i=0;i<ty;i++){
		sb.append("U");
	    }
	    for(int i=0;i<tx;i++){
		sb.append("R");
	    }
	    for(int i=0;i<ty;i++){
		sb.append("D");
	    }
	    for(int i=0;i<tx;i++){
		sb.append("L");
	    }

	    sb.append("L");
	    
	    for(int i=0;i<ty+1;i++){
		sb.append("U");
	    }
	    for(int i=0;i<tx+1;i++){
		sb.append("R");
	    }

	    sb.append("DR");
	    
	    for(int i=0;i<ty+1;i++){
		sb.append("D");
	    }
	    for(int i=0;i<tx+1;i++){
		sb.append("L");
	    }

	    sb.append("U");

	    System.out.println(sb);
	    
	    reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static int gcd (int a, int b){
	return b>0?gcd(b,a%b):a;
    }
    static int lcm (int a, int b) {
	return a*b/gcd(a,b);
    }
}


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

// calc min(a*xs[i] + b)
template <class T>
struct LiCharTree {
  struct Line {
    T a, b;
    Line(T a, T b) : a(a), b(b) {}
    inline T get(T x) const { return a * x + b; }
    inline bool over(const Line &b, const T &x) const {
      return get(x) < b.get(x);
    }
  };
  vector<T> xs;
  vector<Line> seg;
  int xsize;
  LiCharTree() {}
  LiCharTree(const vector<T> &x, T INF) : xs(x) {
    xsize = 1;
    while(xsize < xs.size()) xsize <<= 1;
    while(xs.size() < xsize) xs.push_back(xs.back() + 1);
    seg.assign((xsize << 1) - 1, Line(0, INF));
  }
  void update(Line &x, int k, int l, int r) {
    int mid = (l + r) >> 1;
    bool chl = x.over(seg[k], xs[l]),
         chr = x.over(seg[k], xs[mid]);
    if(chr) swap(seg[k], x);
    if(l + 1 >= r) return;
    if(chl != chr)
      update(x, 2 * k + 1, l, mid);
    else
      update(x, 2 * k + 2, mid, r);
  }
  void update(T a, T b) {
    Line nowl(a, b);
    update(nowl, 0, 0, xsize);
  }
  T query(int k) {
    const T x = xs[k];
    k += xsize - 1;
    T ans = seg[k].get(x);
    while(k > 0) {
      k = (k - 1) >> 1;
      ans = min(ans, seg[k].get(x));
    }
    return ans;
  }
};

long long n, c;
vector<long long> h;
LiCharTree<long long> lct;

long long solve();

int main() {
  cin >> n >> c;
  h.resize(n);
  for(int i = 0; i < n; ++i) cin >> h[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  lct = LiCharTree<long long>(h, (long long)(1e16));
  lct.update(-2 * h[0], h[0] * h[0]);
  for(int i = 1; i < n; ++i) {
    long long now = lct.query(i) + h[i] * h[i] + c;
    lct.update(-2 * h[i], now + h[i] * h[i]);
    if(i == n - 1) return now;
  }
  assert(0);
  return -1;
}

Measured memory_bytes: 13044
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123456
typedef pair<lb, int> P;
typedef pair<int, P> PP;

const int maxn =1e3 + 10;

//initialization here
//

//
//initialization finish


// your function is here
//

//
// your function finished



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int n; cin >> n;
	int memo[30];
	rep(i, 30) memo[i] = 0;
	int cnt = 0;
	rep(i, n)
	{
		char s; cin >> s;
		if (memo[s - 'A'] == 0)
		{
			memo[s - 'A']++;
			cnt++;
		}
	}

	if (cnt == 3) Print("Three");
	else Print("Four");
	//
	// your code finished


	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
from numba import jit, void, i8
input = sys.stdin.readline

def main():
    R, C, K = map(int, input().split())

    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    cell = np.full((R+1, C+1), 0, dtype=np.int64)

    for i in range(K):
        x, y, c = map(int, input().split())
        cell[x-1][y-1] = c

    f(dp, cell, R, C)

    print(dp[R][C][3])

@jit(void(i8[:,:,:],i8[:,:],i8,i8))
def f(dp, cell, R, C):
    dp[0][1][0] = dp[1][0][0] = 0
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 469392
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n, m;
	cin >> n >> m;
	int a[n], b[n], c[n];
	int arr[n];
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}

	
	int fans = 0, ans = 0;
	for(int x = 0; x < 9; x++){
		int sign[3];
		for(int k = 0; k < 3; k++){
			if( ((1<<k)&x) != 0 )
				sign[k] = -1;
			else
				sign[k] = 1;
		}

		for(int i = 0; i < n; i++){
			arr[i] = a[i]*sign[0] + b[i]*sign[1] + c[i]*sign[2];
		}

		sort(arr, arr+n);
		ans = 0;
		for(int i = 0, j = n-1; i < min(n, m); i++, j--){
			ans = ans + arr[j];
		}

		fans = max(fans, ans);
	}

	cout << fans << endl;
	return 0;
}

Measured memory_bytes: 3524
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
 
int a[N*N];
int G[N][N];
int main() {
    int h,w,n;
    scanf("%d%d",&h,&w);
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
 
    int cnt=1;
    for(int i=1; i<=h; i++) {
        if(i%2) {
            for(int j=1; j<=w; j++) {
                if(a[cnt]==0) {
                    cnt++;
                    G[i][j]=cnt;
                    a[cnt]--;
                }
                else if(a[cnt]>0) {
                    G[i][j]=cnt;
                    a[cnt]--;
                }
            }
        }
        else {
            for(int j=w; j>=1; j--) {
                if(a[cnt]==0) {
                    cnt++;
                    G[i][j]=cnt;
                    a[cnt]--;
                }
                else if(a[cnt]>0) {
                    G[i][j]=cnt;
                    a[cnt]--;
                }
            }
        }
    }
 
    for(int i=1; i<=h; i++) {
        for(int j=1; j<=w; j++)
            printf("%d ",G[i][j]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
    int N;
    int a[205];
    cin >> N;
    for(int i = 1; i <= N; i ++){
        cin >> a[i] ;
    }
    int ans = 0;
    while(1){
        int flag = 0;
        for(int i = 1; i <= N; i++){
        if(a[i]%2 != 0)flag = 1;
        else a[i] /=2;
        }

        if(flag == 1) break;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import types

_atcoder_code = """
# Python port of AtCoder Library.

__version__ = '0.0.1'
"""

atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)

_atcoder_fenwicktree_code = """
import typing


class FenwickTree:
    '''Reference: https://en.wikipedia.org/wiki/Fenwick_tree'''

    def __init__(self, n: int = 0) -> None:
        self._n = n
        self.data = [0] * n

    def add(self, p: int, x: typing.Any) -> None:
        assert 0 <= p < self._n

        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, left: int, right: int) -> typing.Any:
        assert 0 <= left <= right <= self._n

        return self._sum(right) - self._sum(left)

    def _sum(self, r: int) -> typing.Any:
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r

        return s
"""

atcoder.fenwicktree = types.ModuleType('atcoder.fenwicktree')
exec(_atcoder_fenwicktree_code, atcoder.fenwicktree.__dict__)
FenwickTree = atcoder.fenwicktree.FenwickTree

# https://atcoder.jp/contests/practice2/tasks/practice2_b

# from atcoder.fenwicktree import FenwickTree


def main() -> None:
    import sys

    n, q = map(int, sys.stdin.readline().split())
    fenwick_tree = FenwickTree(n)

    a = map(int, sys.stdin.readline().split())
    for i, ai in enumerate(a):
        fenwick_tree.add(i, ai)

    for _ in range(q):
        t, x, y = map(int, sys.stdin.readline().split())
        if t == 0:
            fenwick_tree.add(x, y)
        if t == 1:
            print(fenwick_tree.sum(x, y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 68036
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int prefa[100005];
int prefb[100005];
void solve() {
  string s, t;
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++) {
    prefa[i+1] = prefa[i];
    if(s[i] == 'A') prefa[i+1]++;
    else prefa[i+1] += 2;
  }
  for(int i = 0; i < t.size(); i++) {
    prefb[i+1] = prefb[i];
    if(t[i] == 'A') prefb[i+1]++;
    else prefb[i+1] += 2;
  }
  int q;
  cin >> q;
  while(q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((prefa[b] - prefa[a-1]) % 3 == (prefb[d] - prefb[c-1]) % 3) {
      cout << "YES\n";
    }
    else {
      cout << "NO\n";
    }
  }
}

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


Measured memory_bytes: 1744
let dbg = Printf.printf "[debug]%s"

let id = fun x -> x
let tuple2 x y = (x,y)
let succ x = x + 1
let pred x = x - 1

let (++) n m =
  let rec aux i acc =
    if i = m then List.rev (m::acc)
    else aux (i+1) (i::acc) in
  if n > m then [] else aux n []

let (++^) n m = n ++ (m-1)

let scan fmt f = Scanf.sscanf (read_line ()) fmt f

let scan_lines n fmt f =
  List.map (fun _ -> scan fmt f) (0++^n)

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  Array.iteri (fun i line ->
      let s = Scanf.Scanning.from_string @@ read_line () in
      Array.iteri (fun j _ ->
          arr.(i).(j) <- Scanf.bscanf s " %s" conv;
        ) line) arr; arr

let between n x m = n <= x && x < m

let string_to_list s =
  List.map (String.get s) (0 ++^ String.length s)

let m = List.map (fun i -> i*(i+1)*(i+2)/6) (1++200)

let max_val = 1_000_000

let dp = Array.init (max_val+1) (fun i -> if i = 0 then 0 else max_int)
let dp_odd = Array.init (max_val+1) (fun i -> if i = 0 then 0 else max_int);;

List.iter (fun i ->
    dp.(i) <-
      List.fold_left (fun acc num ->
          min acc
            (if i >= num then succ dp.(i-num) else max_int)) max_int m)
  (1++max_val);;

let m = List.filter (fun x -> x mod 2 = 1) m in
List.iter (fun i ->
    dp_odd.(i) <-
      List.fold_left (fun acc num ->
          min acc
            (if i >= num then succ dp_odd.(i-num) else max_int)) max_int m)
  (1++max_val)

let () =
  let rec aux () =
    let n = scan "%d" id in
    if n <> 0 then
      begin
        Printf.printf "%d %d\n" dp.(n) dp_odd.(n);
        aux ()
      end
  in
  aux ()



Measured memory_bytes: 79040
A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

for i in range(3):
    for j in range(3):
        for k in range(n):
            if A[i][j] == B[k]:
                A[i][j] = 0

cnt = 0
for i in range(3):
    S = 0
    for j in range(3):
        S += A[i][j]
    if S == 0:
        cnt = 1

for j in range(3):
    S = 0
    for i in range(3):
        S += A[i][j]
    if S == 0:
        cnt = 1

S = A[0][0] + A[1][1] + A[2][2]
if S == 0:
    cnt = 1

S = A[0][2] + A[1][1] + A[2][0]
if S == 0:
    cnt = 1

if cnt == 1:
    print("Yes")
else:
    print("No")

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

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

int N;
vector<P> red, blue;

signed main(){
	cin >> N;
	int a,b,c,d;
	REP(i, 0, N) {
		cin >> a >> b;	red.pb(mp(a, b));
	}
	REP(i, 0, N) {
		cin >> c >> d;	blue.pb(mp(c, d));
	}
//	VSORT(red);
//	reverse(red.begin(), red.end());
	VSORT(blue);
	
	int ans = 0;
	int sp, sv;
	REP(i, 0, blue.size()) {
		sp = sv = -1;
//	    cout << "blue[[" << i << "] = (" << blue[i].first << ", " << blue[i].second << ") " << endl;
		REP(j, 0, red.size()) {
//		    cout << "red[[" << j << "] = (" << red[j].first << ", " << red[j].second << ") " << endl;
			if(red[j].first < blue[i].first && red[j].second < blue[i].second && sv < red[j].second) {
				sv = red[j].second;
				sp = j;
//    		    cout << " --> save  red[[" << j << "] = (" << red[j].first << ", " << red[j].second << ") " << endl;
			}
		}
		if(sp > -1) {
			ans++;
//			cout << "count up = " << ans << "  delete red[" << sp << "]" << endl;
			red.erase(red.begin() + sp);
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import math

def Sieve_of_Eratosthenes(N):
    if N<2: return set()
    prime=set(i for i in range(2,N+1))
    for i in range(2,math.ceil(N**0.5)+1):
        tmp=set()
        for j in prime:
            if j>i and j%i==0: tmp.add(j)
        for j in tmp:
            prime.remove(j)

    return prime

def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)なるxを返す
def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    return inv % m

MOD=10**9+7
prime=Sieve_of_Eratosthenes(10**3+1)
dic={}
for p in prime:
    dic[p]=0

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

zz=set()
for i in range(n):
    x=a[i]

    tmpdic={}
    for p in prime:
        if x==1: break
        while x%p==0:
            x=x//p
            if p in tmpdic: tmpdic[p]+=1
            else: tmpdic[p]=1

    if x>1:
        if x in prime:
            if p in tmpdic: tmpdic[p]+=1
            else: tmpdic[p]=1
        else: zz.add(x)

    for p in tmpdic:
        dic[p]=max(tmpdic[p],dic[p])

lcm=1
for p in dic:
    for j in range(dic[p]):
        lcm=(lcm*p)%MOD
for p in zz:
    lcm=(lcm*p)%MOD

ans=0
for i in range(n):
    ans+=modinv(a[i],MOD)
    ans%=MOD
print((ans*lcm)%MOD)

Measured memory_bytes: 4596
using System;

namespace B_Bite_Eating
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var l = int.Parse (input[1]);
            var a = int.MaxValue;
            var b = 0;
            var c = 0;
            for (var i = 1; i <= n; i++)
            {
                if (Math.Min (a, Math.Abs (l + i - 1)) == Math.Abs (l + i - 1))
                {
                    a = Math.Abs (l + i - 1);
                    c = l + i - 1;
                }
                b += l + i - 1;
            }
            Console.WriteLine (b - c);
        }
    }
}

Measured memory_bytes: 13140
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    ans = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            k = x - i - j
            if k > j and k <= n:
                ans += 1
    print(ans)


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

int main(){
  string S;
  cin >>S;
  bool s=false, n=false, w=false, e=false;
  rep(i,S.size()){
    if(S[i]=='S') s=true;
    if(S[i]=='N') n=true;
    if(S[i]=='W') w=true;
    if(S[i]=='E') e=true;
  }
  bool sn = false, we = false;
  if(s==n) sn=true;
  if(w==e) we=true;
  if(sn==true && we==true) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E,typename F,typename G,typename H>
struct SegmentTree{
  //using F = function<T(T,T)>;
  //using G = function<T(T,E)>;
  //using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  void update(int a,int b,E x){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    while(a>>=1)
      dat[a]=f(reflect((a<<1)|0),reflect((a<<1)|1));
    while(b>>=1)
      dat[b]=f(reflect((b<<1)|0),reflect((b<<1)|1));
  }
  T query(int a,int b){
    a+=n;b+=n-1;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval(b>>i);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
};
//END CUT HERE
signed DSL_2_G(){
  int n,q;
  scanf("%d %d",&n,&q);
  using P = pair<Int, Int>;
  auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};
  auto g=[](P a,Int b){return P(a.first+b*a.second,a.second);};
  auto h=[](Int a,Int b){return a+b;};
  
  SegmentTree<P,Int,decltype(f),decltype(g),decltype(h)> ch(n,f,g,h,P(0,0),0);  
  ch.build(n,vector<P>(n,P(0,1)));
  for(int i=0;i<q;i++){
    int c,s,t,x;
    scanf("%d",&c);
    if(c){
      scanf("%d %d",&s,&t);
      printf("%lld\n",ch.query(s-1,t).first);
    }else{
      scanf("%d %d %d",&s,&t,&x);
      ch.update(s-1,t,x);
    }
  }
  return 0;
}

/*
  verified on 2018/08/21
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G&lang=jp
*/

signed main(){
  DSL_2_G();
  return 0;
}



Measured memory_bytes: 10432
# your code goes here
N=int(input())
A=[int(i) for i in input().split()]
B=""
for k in range(N-1):
    B+=str(A[k])+" "
B+=str(A[N-1])
print(B)
for i in range(1,N):
    j=i-1
    v=A[i]
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    B=""
    for k in range(N-1):
        B+=str(A[k])+" "
    B+=str(A[N-1])
    print(B)

Measured memory_bytes: 7712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

struct Node {
  ll value;
  Node *left = nullptr,
       *right = nullptr,
       *parent = nullptr;

  Node(ll value = -1): value(value) {}
};

class BST {
  Node *root = nullptr;

  string tos_pre(Node *nd) {
    string s = "";

    s += " " + to_string(nd->value);
    if (nd->left) s += tos_pre(nd->left);
    if (nd->right) s += tos_pre(nd->right);

    return s;
  }

  string tos_in(Node *nd) {
    string s = "";

    if (nd->left) s += tos_in(nd->left);
    s += " " + to_string(nd->value);
    if (nd->right) s += tos_in(nd->right);

    return s;
  }

public:
  void insert(ll value) {
    Node *x = root, *y = nullptr, *z = new Node(value);
    
    while (x) {
      y = x;
      x = z->value < x->value ? x->left : x->right;
    }
    z->parent = y;

    if (!y) root = z;
    else if (z->value < y->value) y->left = z;
    else y->right = z;
  }
  
  string print_pre() {
    return tos_pre(root);
  }

  string print_in() {
    return tos_in(root);
  }
};

int main() {
  int n;
  cin >> n;
  
  auto bst = BST();
  rep(i, n) {
    string cmd;
    cin >> cmd;

    if (cmd == "insert") {
      ll opr;
      cin >> opr;

      bst.insert(opr);
    } else if (cmd == "print") {
      cout << bst.print_in() << endl;
      cout << bst.print_pre() << endl;
    }
  }
}



Measured memory_bytes: 35004
#include <stdio.h>
#include <string.h>
 
int main(void)
{
 
    int start, ans, diff;
    int i;
    int s, t;
    char S[1000], T[1000];
 
    scanf("%s", S);
    scanf("%s", T);
 
    s = strlen(S);
    t = strlen(T);
  
    ans = 1001;
 
    for (start = 0; start <= s - t; start++)
    {
        diff = 0;
        for (i = 0; i < t; i++)
        {
            if (T[i] != S[start + i])
            {
                diff++;
            }
            
        }
        if (ans > diff)
        {
            ans = diff;
        }
        
    }
 
    printf("%d",ans);
 
    return 0;
}
  

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

int main(void){
    // Your code here!
    int n;
    cin>>n;
    string s;
    cin>>s;
    //int ct=0;
    
    long long int a=0,b=0,c=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='R') a++;
      else if(s[i]=='G') b++;
      else if(s[i]=='B') c++;
    }
    
    long long int sum = a*b*c;
    
    for(int i=1;i<n;i++){
      for(int j=i;j+i<n;j++){
        if(s[j-i]!=s[j] && s[j]!=s[j+i] && s[j-i]!=s[j+i]) sum--;
      }
    }
    
    //cout<<ct<<endl;
    //cout<<sum<<endl;
    cout<<sum<<endl;
}


Measured memory_bytes: 3628
#include<algorithm>
#include<cstdio>

const int MAX_N = 100;
int a[MAX_N];

int main() {
	int n, x;
	scanf("%d %d", &n, &x);
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
	std::sort(a, a+n);
	int ans = 0;
	for(int i=0;i<n;i++) {
		if(a[i] > x) break;
		x -= a[i];
		ans++;
	}
	if(ans == n && x > 0) ans--;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
import fractions
def lcm(a,b):
    return a*b//fractions.gcd(a,b)

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

P=[c,d,lcm(c,d)]
A=[]
for p in P:
    if a%p==0:
        left=a//p
    else:
        left=a//p+1
    right=b//p
    if left<=right:
        A.append(right-left+1)
    else:
        A.append(0)
print(b-a+1-A[0]-A[1]+A[2])

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
int A[3][3];
int bingo[3][3];

void solve() {
    for (int i = 0; i < 3; ++i) cin >> A[i][0] >> A[i][1] >> A[i][2];
    int N;
    cin >> N;
    for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 3; ++k) {
            bingo[j][k] = 0;
        }
    }

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

        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if(A[j][k] == b) bingo[j][k] = 1;
            }
        }
    }

    bool ans = false;
    int row = 1;
    int col = 1;
    int dia = 1;
    int odia = 1;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            col *= bingo[i][j];
            row *= bingo[j][i];
            if (i == j) dia *= bingo[i][j];
            if (i == 2 - j) {
                odia *= bingo[i][j];
            }
        }
        if (row == 1 || col == 1) {
            ans = true;
        } else {
            row = 1;
            col = 1;
        }
    }
    if (dia == 1) ans = true;
    if (odia == 1) ans = true;
    cout << (ans ? "Yes" : "No") << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void debug() { std::cerr << '\n'; }
template <class H, class... T> void debug(H &&head, T &&... args) {
    std::cerr << head;
    sizeof...(args) == 0 ? std::cerr << "" : std::cerr << ' ';
    debug(std::forward<T>(args)...);
}
template <class T> void debug(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cerr << v[i];
        i == v.size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
    }
}
template <class T> void debug(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cerr << v[i][j];
            j == v[i].size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
        }
    }
}

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

    string s, t;
    cin >> s >> t;
    int ans = 0;
    REP(i, 3) {
        if (s[i] == t[i])
            ans++;
    }
    print(ans);

    return 0;
}

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

#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
typedef long long ll;

int n, x, m[100];

signed main() {
	cin >> n >> x;
	rep(i,n) {
		cin >> m[i];
		x -= m[i];
	}
	cout << n + x / *min_element(m,m+n) << endl;
}

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

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>

#define int64 long long
using namespace std;

int main()
{
	int64 nn, mm;
	cin >> nn >> mm;
	int64 tmpa, tmpb, now, xx;
	vector<int64> memo[nn];
	int64 visited[nn];
	for(int64 ii = 0;ii < nn;ii++)
	{
		visited[ii] = -1;
	}
	for(int64 ii = 0;ii < mm;ii++)
	{
		cin >> tmpa >> tmpb;
		memo[tmpa - 1].push_back(tmpb - 1);
		memo[tmpb - 1].push_back(tmpa - 1);
	}
	queue<int64> que;
	que.push(0);
	while(!que.empty())
	{
		now = que.front();
		que.pop();
		for(int ii = 0;ii < memo[now].size();ii++)
		{
			xx = memo[now].at(ii);
			if(visited[xx] == -1)
			{
				visited[xx] = now;
				que.push(xx);
			}
		}
	}
	
	cout << "Yes\n";
	for(int64 ii = 1;ii < nn;ii++)
	{
		cout << (visited[ii] + 1) << '\n';
	}
	return 0;
}

Measured memory_bytes: 13000
#include<stdio.h>
 int main(void) {

int i,n;

int number;

long long int sum=0;

int min=0;

int max=0;

scanf("%d",&n);

for(i=0;i<n;i++)

{

scanf("%d",&number);

if(i==0)

{

min = number;

max = number;

}

if(number<min) min = number;

if(number>max)max = number;

sum += number;

}

printf("%d %d %lld\n",min,max,sum);

return 0;

}

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

int n;
vector<int> to[100005];
vector<int> dist;

// DFS
void dfs(int t, int d=0, int p=-1) {
  dist[t] = d;
  for (int u: to[t]) {
    if (u == p) continue;
    dfs(u, d + 1, t);
  }
}

vector<int> calcDist(int s) {
  dist = vector<int>(n);
  dfs(s);
  return dist;
}

int main() {
  int u, v;
  cin >> n >> u >> v;
  u--; v--;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  vector<int> distU = calcDist(u);
  vector<int> distV = calcDist(v);

  int mx = 0;
  rep(i, n) {
    if (distU[i] < distV[i]) {
      mx = max(mx, distV[i]);
    }
  }

  cout << mx - 1 << endl;
  return 0;
}


Measured memory_bytes: 10744
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=300005;

int main(){
    int a[4];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    int ans=0,f1=0,f2=0;
    ans+=(a[2]-a[0])/2;
    ans+=(a[2]-a[1])/2;
    if((a[2]-a[0])%2) f1=1;
    if((a[2]-a[1])%2) f2=1;
    if(!f1&&!f2) ans=ans;
    else if(f1&&f2) ans++;
    else ans+=2;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
X = int(input())

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


i = X

while is_prime(i) == False:
    i += 1

print(i)

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

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

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

  string s;
  cin >> s;

  int ans = 0;
  rep(i, 3) {
    if (s.at(i) == '1') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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 solve(int x) {
    if(x&1) return 0;
    int ans = 0;
    while(x>0 && (x%2)==0) {
        x /= 2;
        ans++;
    }
    return ans;
}
int main() {
    int n; cin >> n;
    int ans = 0;
    rep(i, n) {
        int a; cin >> a;
        ans += solve(a);
    }
    cout << ans;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,X; cin >> N >> X;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll ans = 0;
    if (A[0] > X) {
        ans += A[0] - X;
        chmin(A[0],X);
    }
    rep(i,N-1) {
        if (A[i] + A[i+1] > X) {
            ll val = A[i] + A[i+1] - X;
            ans += val;
            A[i+1] -= val;
        }
    }

    cout << ans << ln;
}


Measured memory_bytes: 1024
charseq = raw_input()
start = -1
end = -1

for i in range(len(charseq)-1):
    if charseq[i] == charseq[i+1]:
        start = i+1 
        end = i+2 
        break
if start == -1: 
    for i in range(len(charseq)-2):
        if charseq[i] == charseq[i+2]:
            start = i+1 
            end = i+3 
            break

print start, end 


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

int main(void){
    int n;
    cin >> n;
    double ph[n]; 
    for(int i = 0; i < n; i++){
        cin >> ph[i];
    }
    vector<vector<double>>dp(n,vector<double>(n + 1));
    
    dp[0][0] = 1 - ph[0];
    dp[0][1] = ph[0];
    for(int i = 1; i < n; i++){
        for(int j = 0; j <= (i + 1); j++){
            dp[i][j] = (1 - ph[i]) * dp[i - 1][j];
            if(j > 0)
                dp[i][j] += ph[i] * dp[i - 1][j - 1];
        }
    }
    double ans = 0;
    int min_heads = ceil(n/2.0);
    for(int i = min_heads; i <= n; i++){
        ans += dp[n - 1][i];
    }
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
long long kouyakusu(long long a, long long b){
    if(b<a) swap(a,b);
    while(1){
        a = a%b;
        if(a==0) break;
        else swap(a,b);
    }
    return b;
}

long long koubaisu(long long a,long long b){
    return (a*b)/kouyakusu(a,b);
}
int main(){
    long long A,B,C,D;
    long long CD;
    cin >> A >> B >> C >> D;
    CD = koubaisu(C,D);
    long long  ans = B-A+1;
    ans -= (B/C + B/D);
    ans += B/CD;
    ans += ((A-1)/C + (A-1)/D);
    ans -= (A-1)/CD;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
K = int(input())
S = input()

m = 1000000007

result = 0
t = pow(26, K, m)
u = pow(26, -1, m) * 25 % m
l = len(S)
for i in range(K + 1):
    # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
    result = (result + t) % m
    t = (t * u) % m * (l + i) % m * pow(i + 1, -1, m) % m
print(result)


Measured memory_bytes: 10896
from fractions import gcd
n=int(input())
ab=[list(map(int,input().split())) for _ in [0]*n]
l,r=1,1
for i in range(n):
    a,b=ab[i]
    c=max((l-1)//a+1,(r-1)//b+1)
    l=a*c
    r=b*c
print(l+r)

Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
   ll n,i;
   cin>>n;
   ll ans=n;
   for(i=2;i<=sqrt(n);i++)
   {
       if(n%i==0)
       {

           ans=min(i+n/i-2,ans);
       }
   }
   if(ans==n)
   {
       ans=n-1;
   }
   cout<<ans<<e;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;
    cout << s.length() / 2 - count(s.begin(), s.end(), 'p') << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[] p = new int[n];
        int x = 0, y = 0, z = 0;
        for(int i = 0; i < n; i++){
            p[i] = sc.nextInt();
            if(p[i] <= a) x++;
            else if(p[i] <= b)y++;
            else z++;
        }
        System.out.println(Math.min(Math.min(x, y), z));
    }
}

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

int dfs(int idx, int l[], int a, int b, int c, int A, int B, int C)
{
    if (idx < 0)
    {
        if (a > 0 && b > 0 && c > 0)
        {
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        }
        else
        {
            return 100000;
        }
    }
    int ret0 = dfs(idx - 1, l, a, b, c, A, B, C);
    int ret1 = dfs(idx - 1, l, a + l[idx], b, c, A, B, C) + 10;
    int ret2 = dfs(idx - 1, l, a, b + l[idx], c, A, B, C) + 10;
    int ret3 = dfs(idx - 1, l, a, b, c + l[idx], A, B, C) + 10;
    return min(min(min(ret0, ret1), ret2), ret3);
}

int main()
{
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    int l[8] = {};
    for (int i = 0; i < N; i++)
    {
        cin >> l[i];
    }

    cout << dfs(N - 1, l, 0, 0, 0, A, B, C) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int main() {
    int w, h, n;
    cin >> w >> h >> n;

    int x0 = 0, x1 = w, y0 = 0, y1 = h;
    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;

        switch (a) {
            case 1: x0 = max(x0, x); break;
            case 2: x1 = min(x1, x); break;
            case 3: y0 = max(y0, y); break;
            case 4: y1 = min(y1, y); break;
        }
    }

    x1 -= x0; x1 = max(x1, 0);
    y1 -= y0; y1 = max(y1, 0);

    cout << x1 * y1 << endl;

    return 0;
}

Measured memory_bytes: 256
def getMax(a, b):
    if a > b:
        return a
    return b

def getCakeRepeats(cakes):
    front_iter = 0
    back_iter = len(cakes) - 1

    while back_iter > front_iter:
        if cakes[back_iter] < cakes[front_iter]:
            cakes[front_iter] -= cakes[back_iter]
            cakes[back_iter] = 0
            back_iter -= 1
        elif cakes[back_iter] > cakes[front_iter]:
            cakes[back_iter] -= cakes[front_iter]
            cakes[front_iter] = 0
            front_iter += 1
        else:
            cakes[back_iter] = 0
            cakes[front_iter] = 0
            back_iter -= 1
            front_iter += 1

    return getMax(0, sum(cakes) - 1)

if __name__ == "__main__":
    setup = raw_input()
    cakes = list(map(int, raw_input().split()))
    print getCakeRepeats(sorted(cakes))


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define INFI 1000000000000000000

int main() {
    // ll t;
    // cin >> t;
    // while(t--) {
        ll n;
        cin >> n;
        ll arr[n] = {0};
        for(ll i = 0 ; i < n ; i++) {
            cin >> arr[i];
        }
        if(n <= 2) {
            cout << 0 << endl;
        }
        else{
            sort(arr , arr + n);
            ll ans = 0;
            for(ll i = 0 ; i < n - 2 ; i++) {
                for(ll j = i + 1 ; j < n - 1 ; j++) {
                    for(ll k = j + 1 ; k < n ; k++) {
                        if(arr[i] != arr[j] && arr[j] != arr[k] && arr[k] != arr[i]) {
                            if(arr[i] + arr[j] > arr[k]) {
                                ans ++;
                            }
                        }
                    }
                }
            }

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


Measured memory_bytes: 3628
import sys
from collections import Counter
from itertools import combinations

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    L = list(map(int, readline().split()))
    count = Counter(L)
    ans = 0
    for a in combinations(count.keys(),3):
        if sum(a)-max(a)*2>0:
            ans += count[a[0]]*count[a[1]]*count[a[2]]
    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 9520
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    int d = a / b;
    int r = a % b;
    double f = double(a) / double(b);
    cout << d;
    cout << " ";
    cout << r;
    cout << " ";
    cout << fixed << setprecision(5) << f;
    cout << endl;
    
    
}



Measured memory_bytes: 3268
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	string s;
	int n, i, j, k, c0 = 0, c1 = 0, c2 = 0, c3 = 0, ans = 0, sl;
	cin >> n;
	while (n--) {
		cin >> s;
		sl = s.length();
		for (i = 1; i < sl; i++) {
			if ((s[i - 1] == 'A') && (s[i] == 'B')) ans++;
		}
		if ((s[0] == 'B') && (s[sl - 1] == 'A')) c0++;
		if ((s[0] == 'B') && (s[sl - 1] != 'A')) c1++;
		if ((s[0] != 'B') && (s[sl - 1] == 'A')) c2++;
		if ((s[0] != 'B') && (s[sl - 1] != 'A')) c3++;
	}

	if (c0 == 0) ans += min(c1, c2);
	else if (c1 + c2 > 0) ans += c0 + min(c1, c2);
	else ans += c0 - 1;

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 888
import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N,M,K = map(int,input().split())
    for i in range(N + 1):
        for j in range(M + 1):
            if K == i*(M - j) + j*(N - i):
                print('Yes')
                return
    print('No')
if __name__ == '__main__':
    main()
    

Measured memory_bytes: 3064