akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


void solve1(int N, int K, string S){
    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);
    if(Nums.size() % 2 == 0) Nums.push_back(0);
    int Add = 2 * K + 1;
    int ans = 0;
    for(int i = 0; i < Nums.size(); i += 2){
        int tmp = 0;
        int left = i;
        int right = min(i + Add, (int)Nums.size());
        for(int j = left; j < right; j++){
            tmp += Nums[j];
        }
        ans = max(tmp, ans);
    }
    cout << ans << endl;
}

void solve2(int N, int K, string S){
    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);
    if(Nums.size() % 2 == 0) Nums.push_back(0);
    int Add = 2 * K + 1;
    int ans = 0;
    int left = 0;
    int right = 0;
    int tmp = 0;

    for(int i = 0; i < Nums.size(); i += 2){
        int Nextleft = i;
        int Nextright = min(i + Add, (int)Nums.size());
        while(Nextleft > left){
            tmp -= Nums[left];
            left++;
        }
        while(Nextright > right){
            tmp += Nums[right];
            right++;
        }
        ans = max(tmp, ans);
    }
    cout << ans << endl;
}

void solve3(int N, int K, string S){
    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);
    if(Nums.size() % 2 == 0) Nums.push_back(0);
    int Add = 2 * K + 1;
    vector<int> sum(Nums.size() + 1);
    for(int i = 0; i < Nums.size(); i++){
        sum[i + 1] = sum[i] + Nums[i];
    }

    int ans = 0;
    for(int i = 0; i < Nums.size(); i += 2){
        int left = i;
        int right = min(i + Add, (int)Nums.size());
        int tmp = sum[right] - sum[left];
        ans = max(tmp, ans);
    }
    cout << ans << endl;
}

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    //solve1(N, K, S);
    solve2(N, K, S);
    //solve3(N, K, S);
    return 0;
}

Measured memory_bytes: 1148
import heapq as hp
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()))

lp = hp.nlargest(x, p)
lq = hp.nlargest(y, q)
pq = lp + lq
lpq = hp.nlargest(x+y, pq)
lr = hp.nlargest(c, r)
d = min(len(lr),len(lpq))
for i in range(1,d+1):
  if lpq[x+y-i] < lr[i-1]:
    lpq[x+y-i] = lr[i-1]
  else:
    break

ans = 0
for i in range(0,len(lpq)):
  ans += lpq[i]
print(ans)

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

using namespace std;
typedef long long ll;
typedef long double ld;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

//const ll MOD = 1e9+7;
//const ll MOD = 998244353;
//const ll MAX = 3e5+1;
//const ll INF = 1e18;
//const ld PI = acos(-1L);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int X, N;
    in(X); in(N);
    // 0 to 101
    vector<int> p(101, 0);
    rep(i, N) {
        int tmp;
        in(tmp);
        p[tmp] = 1;
    }
    int ans;
    for(int i=X; i>=0; i--) {
        if (p[i] == 0) {
            ans = i;
            break;
        }
    }
    for(int i=X+1; i<=101; i++) {
        if (p[i] == 0 && X - ans > i - X) {
            ans = i;
            break;
        }
    }
    out(ans);


        return 0;
    }


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  vector<bool>sosu(1e7, true);
  vector<ll> sosuu;
  sosu[0] = sosu[1] = false;
  for (int i = 0; i < 1e7; i ++) {
    if (sosu[i]) {
      sosuu.push_back((ll)i);
      for (int j = 2; j * i < 1e7; j ++) {
        ll k = (ll)i * j;
        sosu[k] = false;
      }
    }
  }
  int n = (int)sosuu.size();
  ll N, P;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 0; i < n; i ++) {
    int cnt = 0;
    while (P % sosuu[i] == 0) {
      cnt ++;
      P /= sosuu[i];
      if (cnt == N) {
        ans *= sosuu[i];
        cnt = 0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 12660
#include <iostream>
#include <algorithm>
using namespace std;
int MIN(int a, int b){
    return a<b;
}
int list[1005];
int main(){
    int N, K;
    cin >> N >> K ;
    for(int i = 0 ; i < N ; i++ ){
        cin >> list[i] ;
    }
    sort(list,list+N,MIN);
    int result = 0 ;
    for(int i = 0 ; i < K ; i++ )
    result += list[i];
    cout << result << endl ;

    return 0;
}

Measured memory_bytes: 3176
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
	static final int MAX = 2_147_483_646; // intMax 
	static final int INF = 1_000_000_000; // 10^9  
	public static void main(String[] args) throws Exception{
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
		}
		int ans = 0;
		for(int i = 0;i < n;i++){
			if((i+1) % 2 != 0 && a[i] % 2 != 0){
				ans++;
			}
		}
		System.out.println(ans);
		saori.close();
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}


Measured memory_bytes: 32336
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input! {
        n: i32, k: usize,
        l: [i32; n],
    }

    let mut ll = l.clone();
    ll.sort_by(|a, b| b.cmp(a));
    
    let mut ans = 0;

    for i in 0..k {
        ans += ll[i];
    }

    println!("{}", ans);
}



Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a,b,c,d;
    string s,s1;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int A,B;
	cin>>A>>B;
	if((A+B)%2==0){
		cout<<(A+B)/2<<endl;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
def bubblesort(N, A):
    c, flag = 0, 1
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j- 1], A[j]
                c += 1
                flag = True
    return (A, c)

A, c = bubblesort(int(input()), list(map(int, input().split())))
print(' '.join([str(v) for v in A]))
print(c)

Measured memory_bytes: 7776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n,ans = 0,tmp = 0;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i] >> t[i];
        ans += t[i];
    }
    string x;
    cin >> x;
    int it;
    for (int i = 0; i < n; ++i) {
        if(s[i] == x){
            it = i;
            break;
        }
    }

    for (int i = 0; i <= it; ++i) {
        tmp += t[i];
    }


    cout << ans-tmp << endl;
    return 0;
}

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


using namespace std;

int x, y;

int main()
{
	scanf("%d%d", &x, &y);
	
	int b = (y - 2 * x) / 2;
	if ((y - 2 * x) % 2 != 0) {
		printf("No\n");
		return 0;
	}
	
	int a = x - b;
	
	if ((a >= 0) && (b >= 0))
		printf("Yes\n");
	else
		printf("No\n");
		
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

struct d{ll a,b;};
bool operator<(const d &l, const d &r){  // なるべく全順序になるようにしたほうが良い
	ll cl = l.b-l.a, cr = r.b-r.a;
	if(cl>=0 && cr<0)return true;
	if(cl<0 && cr>=0)return false;
	if(cl>=0 && cr>=0){
		if(l.a<r.a)return true;
	}else{
		if(l.b>r.b)return true;
	}
	return false;
}

ll n;
d p[1000010];
string s[1000010];

ll cur=0;
bool ok=true;

int main(void){
	cin>>n;
	rep(i,n)cin>>s[i];
	rep(i,n){
		ll c=0,d=0;
		p[i].a=0;  // ')'の個数
		p[i].b=0;  // '('の個数
		rep(j,s[i].size()){
			if(s[i][j]==')')c++;
			if(s[i][j]=='(')c--;
			p[i].a = max(p[i].a,c);
		}
		irep(j,s[i].size()){
			if(s[i][j]=='(')d++;
			if(s[i][j]==')')d--;
			p[i].b = max(p[i].b,d);
		}
	}
	sort(p,p+n);
	// rep(i,n)cout<<p[i].a<<" "<<p[i].b<<endl;
	rep(i,n){
		if(cur-p[i].a<0)ok=false;
		cur += -p[i].a+p[i].b;
	}
	if(cur!=0)ok=false;
	cout<<(ok ? "Yes" : "No")<<endl;
	return 0;
}

Measured memory_bytes: 50472
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int n; cin >> n;
    vector<int> a(n+1,0);
    rep(i,n) cin >> a[i];
    ll m = 1000;
    ll cabu = 0;
    rep(i,n) {
        if (a[i] < a[i+1]) {
            cabu += m / a[i];
            m -= (m / a[i]) * a[i];
        } else if (a[i] > a[i+1]){
            m += cabu * a[i];
            cabu = 0;
        } else {
            continue;
        }
    }
    cout << m << endl;

    return 0;
}


Measured memory_bytes: 3568
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n, m, p;
	cin >> n >> m >> p;
	cout << (n + m + p - max({n, m, p}))<< endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scaner sc = new Scaner();
        write wr = new write();
        //ここから

        var N=sc.Int1;
        var s=new Dictionary<string,long>();
        for(int i=0;i<N;++i){
           var ss=sc.Str.ToCharArray();
           Array.Sort(ss);
           var sss=new string(ss);

           if(!s.ContainsKey(sss))s.Add(sss,1);
           else s[sss]++;
        }

        long ans=0;

        foreach(var x in s){
            ans+=(x.Value*(x.Value-1)/2);
        }
        wr.wri(ans);

        //ここまで
    }
    
        


    static int factmod(int X){
        int ret=1;
        for(int i=1;i<=X;++i){
            ret*=i;
            ret%=MOD;
        }
        return ret;
    }
}





class Scaner
{
    public string Str => Console.ReadLine();

    public string[] StrArr => Str.Split(' ');

    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public char[] CharArr => Str.ToArray();
    public long Long1 => LongArr[0];
    public int Int1 => IntArr[0];
    
}



class write
{
    public  void wri<T>(T x)
    {
        Console.WriteLine(x);
    }
}



Measured memory_bytes: 27608
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        System.out.println(N * (N + 1) / 2);
    }
}


Measured memory_bytes: 21716
N, M = [int(w) for w in input().split()]
cake = []
for i in range(N):
    x, y, z = [int(w) for w in input().split()]
    cake.append((x, y, z))

score = []

# x, y, zの極性
for xp in [1, -1]:
    for yp in [1, -1]:
        for zp in [1, -1]:
            key = lambda t: t[0] * xp + t[1] * yp + t[2] * zp
            cake.sort(key=key, reverse=True)
            select = cake[:M]
            s = 0
            for i in range(3):
                s += abs(sum(t[i] for t in select))
            score.append(s)

print(max(score))


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmin(T &a,const T b){if(a>b){a=b; return true;}return false;}
template<typename T> bool chmax(T &a,const T b){if(a<b){a=b; return true;}return false;}


int main(){
    string s; cin >> s;
    int ans=0;
    for(int i=0; i<(int)s.size(); i++){
        bool ok=true;
        for(int j=i; j<(int)s.size(); j++){
            if(s[j] != 'A' && s[j] != 'G' && s[j] != 'C' && s[j] != 'T') ok=false;
            if(ok) chmax(ans, j-i+1);
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define task "B"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Limit

// Struct

// Variables
int n,a,b;
string s;
// Function

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n >> a >> b >> s;
	int tem=0,temb=0;
	rep(i,0,n-1)
	{
	    if (s[i]=='c'||tem>=a+b) puts("No");
	    else if (s[i]=='a') puts("Yes"),tem++;
	    else
        {
            if (temb>=b) puts("No");
            else puts("Yes"),tem++,temb++;
        }
	}
}


Measured memory_bytes: 848
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	cin >> N;
	int res = INF;
	for (int i = 1;i < N;i++) {
		int A = i;
		int B = N - A;
		int sum = 0;
		while (A > 0 || B > 0) {
			sum += A % 10;
			A /= 10;
			sum += B % 10;
			B /= 10;
		}
		res = min(res, sum);
	}
	cout << res << "\n";
	
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll A, B;
    cin >> A >> B;
    if (A <= 9 && B <= 9) {
        cout << A*B << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict
import bisect

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

q,h,s,d = readInts()
n = readInt()

reasonable = [-1,-1]
value = {"0.25":q,"0.5":h,"1":s,"2":d}
t = min(8*q,4*h,2*s,d)
if t==8*q:
  reasonable = [0.25,q]
  ans = (n//reasonable[0])*reasonable[1]
  print(int(ans))
elif t==4*h:
  reasonable = [0.5,h]
  ans = (n//reasonable[0])*reasonable[1]
  print(int(ans))
elif t==2*s:
  reasonable = [1,s]
  ans = (n//reasonable[0])*reasonable[1]
  print(ans)
else:
  reasonable = [2,d]
  remain = n%2
  money = 0
  if remain==1:
    money = min(4*q,2*h,1*s)
  print(int(money)+(n//reasonable[0])*reasonable[1])


Measured memory_bytes: 9484
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
vl v;
void sosu_generate(){
	vl a(1000000,1);
	REP(i,2,1000){
		if(a[i])
			for(int j=0;i*(j+2)<1000000;j++)a[i*(j+2)]=0;
	}
	REP(i,2,1000000)if(a[i])v.push_back(i);
	return;
}


int main(){
	sosu_generate();
	while(1){
		int a,d,n;
		cin>>a>>d>>n;
		if(a==0)break;
		int cnt=0,ans=0;
		int x=0;
		rep(j,10000){
			REP(i,x,v.size()){
				if(a+j*d<v[i])break;
				if(a+j*d==v[i]){
					x=i+1;
					cnt++;
					ans=a+j*d;
					break;
				}
			}
			if(cnt==n){
				print(ans);
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 11524
#ab = [tuple(map(int, input().split())) for _ in range(n)]
import math
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()

def check(j):
    cnt = 0
    for i in range(n):
        tmp = math.ceil((h[i] - b*j) / (a-b))
        if tmp <= 0:
            pass
        else:
            cnt += tmp
    if cnt <= j:
        return True
    else:
        return False


def bs(l,r):
    while l != r:
        m = (l+r)//2
        if check(m):
            r = m
        else:
            l = m+1
    return l

print(bs(0, 10**9))

Measured memory_bytes: 7508
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if (c >= a && c <= b)
    puts("Yes");
  else
    puts("No");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

void dump(const vector<int> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

int toint(char c)
{
	if(c == 'S') return 0;
	if(c == 'H') return 1;
	if(c == 'C') return 2;
	if(c == 'D') return 3;
}

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

	vector<int> V(52);

	fill(ALL(V), 0);

	REP(i, N){
		char c;
		int r;
		cin >> c >> r;

		int index = toint(c) * 13 + r - 1;
		V[index] = 1;
	}

	const char chars[] = { 'S', 'H', 'C', 'D' };

	REP(i, 52){
		if(V[i] == 0){
			cout << chars[i/13] << " " << i%13+1 << endl;
		}
	}

	return 0;
}




Measured memory_bytes: 3092
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = long.Parse(spl[0]);
        var a     = long.Parse(spl[1]) -1;
        var b     = long.Parse(spl[2]) -1;
        var c     = long.Parse(spl[3]) -1;
        var d     = long.Parse(spl[4]) -1;

        var s = input.ReadLine();

        //岩が2つ連続ならNG
        //c > d のとき、どこかに3つ以上連続した空白が必要

        bool over = (c > d);

        for(int i=1; i<n; i++) {
            var c_now = s[i];
            var c_pre = s[i-1];

            if(a+1 <= i && i <= c) {
                if(c_now == Black && c_pre == Black) return No;
            }
            if(b+1 <= i && i <= d) {
                if(c_now == Black && c_pre == Black) return No;
            }

            if (over) {
                if(b <= i && i <= d && i < c) {
                    if(c_now == White && c_pre == White && s[i+1] == White) {
                        over = false;
                    }
                }
            }
        }

        return over ? No : Yes;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }

}


Measured memory_bytes: 11616
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>
#include<limits>
#include <unordered_map>
#include <numeric>
#include <array>
#include <queue>
#include <chrono>
#include <random>
#include <fstream>


using namespace std;
using  ull = unsigned long long int;

#define rep(i,n,m) for(long long int i=n;i<(long long int)(m);i++)
#define INF (1<<29)
#define MD 1000000007

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

	cin >> a >> b >> c >> d;


	if (abs(a - c) <= d) {
		cout << "Yes" << endl;
		return 0;
	}
	else if (abs(a - b) <= d && abs(b - c) <= d) {
		cout << "Yes" << endl;
		return 0;
	}
	else cout << "No" << endl;








	return 0;
}

Measured memory_bytes: 764
n = int(input())
A = list(map(int, input().split()))

balls = [0] * (n + 1)

balls[0] = 1
for i in range(n):
  balls[i+1] = balls[i] * 2 - A[i+1]

for i in range(n+1):
  balls[i] += A[i]

box = [0] * (n + 1)
box[-1] = A[-1]

for i in range(n-1, -1, -1):
  box[i] = box[i + 1] + A[i]

ans = 0
for i, j in zip(balls, box):
  ans += min(i, j)

ans = [min(i, j) for i, j in zip(balls, box)]

# print(balls)
# print(box)
# print(ans)

if any(i * 2 < j for i, j in zip(ans, ans[1:])) or (ans[0] != 1) or any(i < 1 for i in ans) or any(i < j for i, j in zip(ans, A)):
  print(-1)
else:
  print(sum(ans))

Measured memory_bytes: 681344
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

vector<int> par;
vector<int> ran;
vector<int> fac;

void init(int n) {
  rep(i,n) {
    par.push_back(i);
    ran.push_back(0);
    fac.push_back(1);
  }
}

int root(int x) {
  if(par[x]==x) {
    return x;
  }
  return par[x]=root(par[x]);
}

bool same(int x,int y) {
  return root(x)==root(y);
}

void unite(int x,int y) {
  x=root(x);
  y=root(y);
  if(x==y) return;

  if(ran[x]<ran[y]) {
    par[x]=y;
    fac[y]+=fac[x];
  } else {
    par[y]=x;
    fac[x]+=fac[y];
    if(ran[x]==ran[y]) ran[x]++;
  }
}

void coutAll(int n) {
 pr("par[i]","ran[i]","fac[i]");
 rep(i,n) {
   pr(par[i],ran[i],fac[i]);
 }
}

int main(void) {
  int n,m,k;cin>>n>>m>>k;
  vector<vector<int>> df(n);
  vector<int> ans(n,0);

  init(n);

  int a,b;
  rep(i,m) {
    cin>>a>>b;
    --a;
    --b;
    unite(a,b);
    df[a].push_back(b);
    df[b].push_back(a);
  }

  int c,d;
  rep(i,k) {
    cin>>c>>d;
    --c;
    --d;
    if(same(c,d)) {
      ans[c]--;
      ans[d]--;
    }
  }

  // coutAll(n);

  rep(i,n) {
    int tmp=root(i);
    ans[i]+=fac[tmp]-df[i].size()-1;
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

#if 0
4 4 1
2 1
1 3
3 2
3 4
4 1
#endif


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

using namespace std;

int main()
{
    int num;
    double Wei, Hei, BMI;
 
    while (scanf("%d,%lf,%lf", &num, &Wei, &Hei) != EOF) {
	BMI = Wei / (Hei * Hei); 
	if (BMI >= 25) printf("%d\n", num);
    }
    return 0;
}

Measured memory_bytes: 3200
#!/usr/bin/python3
# -*- coding: utf-8 -*-

N, X = map(int, input().split())
L = list(map(int, input().split()))

D = 0
count = 1
for i in range(N):
    D += L[i]
    if D > X:
        print(count)
        exit()
    else:
        count += 1
print(count)

Measured memory_bytes: 3060
solve :: Int -> Int -> Int -> Bool
solve a b x = (knownCats <= expectCats) && (expectCats <= catsPlusDogs)
  where catsPlusDogs = a + b
        knownCats = a
        expectCats = x

main :: IO ()
main = do
  [a, b, x] <- map read . words <$> getLine
  putStrLn $ if solve a b x then "YES" else "NO"

Measured memory_bytes: 508
#include <iostream>

using namespace std;

int main(){
  int n;
  int nenrei;

  while(cin >> n,n ){
  int ans0=0,ans10 = 0,ans20 = 0,ans30 = 0,ans40 = 0,ans50 = 0;
  int ansover = 0;

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

      cin >> nenrei;
      if(nenrei<10)ans0++;
      else if(nenrei<20)ans10++;
      else if(nenrei<30)ans20++;
      else if(nenrei<40)ans30++;
      else if(nenrei<50)ans40++;
      else if(nenrei<60)ans50++;
      else ansover++;
         }
    cout << ans0 << endl;
    cout <<ans10 << endl;
    cout <<ans20 << endl;
    cout << ans30 << endl;
    cout <<ans40 << endl;
    cout <<ans50 << endl;
    cout <<ansover << endl;

  }
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main()
{
	int sa,sb,sc,sd;
	int ta,tb,tc,td;
	int sums,sumt;
	scanf("%d %d %d %d",&sa,&sb,&sc,&sd);
	scanf("%d %d %d %d",&ta,&tb,&tc,&td);
	sums=sa+sb+sc+sd;
	sumt=ta+tb+tc+td;
	
	if(sums>=sumt)printf("%d\n",sums);
	else {printf("%d\n",sumt);}
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

const int MAX_N = 50;
const double g = 9.8;
const double EPS = 1e-8;

int N, V, X, Y, L[MAX_N], B[MAX_N], R[MAX_N], T[MAX_N];

double calc(double vy, double t){
  return vy * t - g * t * t / 2.0;
}

int cmp(double lb, double ub, double a){
  return a < lb + EPS ? -1 : a > ub - EPS ? 1 : 0;
}

bool check(double qx, double qy){
  double a = g * g / 4.0, b = g * qy - V * V, c = qx * qx + qy * qy;
  double D = b * b - 4 * a * c;
  if(D < 0 && D > -EPS) D = 0;
  if(D < 0) return false;
  for(int d = -1;d<=1;d += 2){
    double t2 = (-b + d * sqrt(D)) / (2.0 * a);
    if(t2 <= 0) continue;
    double t = sqrt(t2);
    double vx = qx / t, vy = (qy + g * t * t / 2.0) / t;
    double yt = calc(vy, X / vx);
    if(yt < Y - EPS) continue;

    bool ok = true;
    for(int i=0;i<N;i++){
      if(L[i] >= X) continue;
      if(R[i] == X && Y <= T[i] && B[i] <= yt) ok = false;
      int yL = cmp(B[i], T[i], calc(vy, L[i] / vx));
      int yR = cmp(B[i], T[i], calc(vy, R[i] / vx));
      int xH = cmp(L[i], R[i], vx * (vy / g));
      int yH = cmp(B[i], T[i], calc(vy, vy / g));
      if(xH == 0 && yH >= 0 && yL < 0) ok = false;
      if(yL * yR <= 0) ok = false;
    }
    if(ok) return true;
  }
  return false;
}

bool solve(){
  for(int i=0;i<N;i++){
    R[i] = min(R[i], X);
  }
  bool ok = check(X, Y);
  for(int i=0;i<N;i++){
    ok |= check(L[i], T[i]);
    ok |= check(R[i], T[i]);
  }
  return ok;
}

main(){
  cin >> N >> V >> X >> Y;
  for(int i=0;i<N;i++) cin >> L[i] >> B[i] >> R[i] >> T[i];
  cout << (solve() ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int n,k,s;
    cin>>n>>k>>s;
    vector<int64_t> wa(n+1);
    wa[0]=0;
    int j=0;
    if(k==0){
        rep(i,n){
            if(s==1000000000){
                cout<<s-1<<" ";
            }
            else{
            cout<<s+1<<" ";
            }
        }
        
        cout<<endl;
        return 0;
    }
    rep(i,n){
        if(j<k){
        wa[i+1]=wa[i]+s;
        }
        else{
            if(s>2){
                wa[i+1]=wa[i]+s-1;
            }
            else{
                wa[i+1]=wa[i]+s+1;
            }
        }
        j++;
    }
    /*
    rep(i,n+1){
        cout<<wa[i]<<" ";
    }
    cout<<endl;
    */
    vector<int64_t> a(n);
    rep(i,n){
        a[i]=wa[i+1]-wa[i];
        cout<<a[i]<<" ";
    }
    cout<<endl;
    
}

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

int main(){
  int n, p;
  string s;
  cin >> n >> p >> s;
  long long ans = 0;
  if(p == 2 || p == 5 ){
    for(int i=0; i<n; ++i){
      if((s[i]-'0')%p == 0){
        ans += i+1;
      }
    }
    cout << ans << endl;
    return 0;
  }
  map<int, int> mp;
  ++mp[0];
  int rui = 0;
  int keta = 1;
  for(int i=n-1; i>=0; --i){
    rui += (s[i]-'0') * keta;
    rui %= p;
    keta *= 10;
    keta %= p;
    ans += mp[rui];
    ++mp[rui];
  }
  cout << ans << endl;
}

Measured memory_bytes: 900
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int x=sc.nextInt();
            int y=sc.nextInt();
            if(x==0&&y==0)break;
            if(x<y)System.out.println(x+" "+y);
            else System.out.println(y+" "+x);
        }
    }
}


Measured memory_bytes: 35976
n,k,s = [int(i) for i in input().split()]

for i in range(k):
    print(s,end="")
    if i!=k-1:
        print(" ",end="")

s = s-1 if s==10**9 else s+1

for i in range(k,n):
    print(" "+str(s),end="")

Measured memory_bytes: 4592
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 200000;
int N;
int a[MAX_N];
int ans[MAX_N];

int main() {
  cin >> N;
  rep(i,N) cin >> a[i];

  vector<pii> v;
  for (int i = 0; i < N; ++i) {
    v.push_back(pii(a[i], i));
  }

  sort(all(v));

  for (int i = 0; i < N; ++i) {
    if (i < N/2) {
      ans[v[i].sc] = v[N/2].fi;
    } else {
      ans[v[i].sc] = v[N/2-1].fi;
    }
  }

  for (int i = 0; i < N; ++i) {
    cout << ans[i] << endl;
  }

}


Measured memory_bytes: 5488
from collections import deque

h,w = map(int,input().split())
hw = [list(input()) for _ in range(h)]

for i in range(h):
  for j in range(w):
    if hw[i][j] == ".":
      cnt = 0
      for x in [-1, 0, 1]:
        for y in [-1, 0, 1]:
          if i+y in range(h) and j+x in range(w):
            if hw[i+y][j+x]=="#":
              cnt += 1
      hw[i][j]=cnt

for line in hw:
  print("".join(list(map(str, line))))


Measured memory_bytes: 3444
def main():
    inlis = []
    n, x = map(int,input().split())
    while n != 0 or x != 0:
        inlis.append([n,x])
        n, x = map(int,input().split())

    #print (inlis)

    ans = 0
    for nx in inlis:
        ans = 0
        n = nx[0]
        x = nx[1]
        for i in range(1, n+1):
            for j in range(1, n+1):
                for k in range(1, n+1):
                    if i <= j <= k:
                        if i + j + k == x and i != j and j != k and k != i:
                            ans += 1
                            #print(i, j, k)
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5596
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  ll x;
  cin>>x;

  cout<<x + x * x + x * x * x<<endl;
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=2*1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,k;
	cin>>n>>k;
	int cnt=0;
	while(n)
	{
		int o=n%k;
		cnt+=to_string(o).size();
		n/=k;
	}
	cout<<cnt;
} 
// I never lose. I either win or I learn

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;
int N;

int main()
{
  cin >> N;
  vector<ll> A(N);
  string ans;

  rep(i, N)
  {
    cin >> A[i];
//    cout << A[i] << endl;
    if (A[i] == 0)
    {
      cout << "0" << endl;
      return 0;
    }
  }

  ll sum = 1;
  ll max = 1000000000000000000;
  rep(i, N)
  {
    if (sum > max/A[i])
    {
      cout << "-1" << endl;
      return 0;
    }
    sum *= A[i];
  }
  cout << sum << endl;
}


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

using namespace std;

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

  int N; cin>>N;
  vector<int> A(N), B(N);
  for (auto& a : A) cin>>a;
  for (auto& a : B) cin>>a;
  vector<int> C(N), D(N);
  for (int i = 0; i < N; i++) {
    C[i] = A[i] xor A[(i+1)%N];
  }
  for (int i = 0; i < N; i++) {
    D[i] = B[i] xor B[(i+1)%N];
  }
  vector<int> lcp(N+1);
  lcp[0] = -1;
  int n = 0;
  for (int i = 1; i < N; i++) {
    if (C[i] == C[n]) {
      lcp[i] = lcp[n];
    } else {
      lcp[i] = n;
      n = lcp[n];
      while (n >= 0 and C[i] != C[n])
        n = lcp[n];
    }
    n++;
  }
  lcp[N] = n;

  int i = 0;
  int p = 0;
  int x = B[0] xor A[0];
  vector<pair<int, int>> ans;
  while (i < N*2-1 and p < N) {
    if (D[i%N] == C[i-p]) {
      if (i-p == N-1) {
        ans.emplace_back((N-p)%N, x);
        p = i+1 - lcp[i+1-p];
        x = B[(i+1)%N] xor A[(i+1-p)%N];
      }
    } else {
      p = i - lcp[i-p];
      x = B[(i+1)%N] xor A[(i+1-p)%N];
    }
    i++;
  }
  sort(ans.begin(), ans.end());
  for (auto a : ans)
    cout << a.first << " " << a.second << endl;

  return 0;
}


Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
int main()
{
  ll N, M, ans = 0; cin >> N >> M;
  vector<ll> H(N + 1); H[0] = 0;
  vector<bool> good(N + 1, true);
  for (ll i = 1; i <= N; i++) {
  	cin >> H[i];
  }
  for (ll i = 0; i < M; i++) {
  	ll A, B; cin >> A >> B;
    if (H[A] > H[B]) {
    	good[B] = false;
    } else if (H[A] < H[B]) {
    	good[A] = false;
    } else {
      	good[A] = false;
    	good[B] = false;
    }
  }
  for (ll i = 1; i <= N; i++) {
  	if (good[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int now=0;
  int ans=s.size();
  rep(i,s.size()){
    if(s[i]=='S'){
      now++;
    }
    if(s[i]=='T'){
      if(now!=0){
	ans-=2;
	now--;
      }
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <functional>

template <int K, class T>
struct Trie {
    struct Node {
        int c;
        std::array<int, K> nxt;
        std::array<int, K> cnt;  // 文字cを含むような子孫の数
        int sz;                  // 部分木のサイズ

        explicit Node(int c) : c(c), sz(0) {
            nxt.fill(-1);
            cnt.fill(0);
        }
    };

    std::vector<Node> nodes;
    std::function<int(T)> enc;

    explicit Trie(T base) {
        nodes.emplace_back(-1);
        enc = [=](T c) { return c - base; };
    }

    explicit Trie(const std::function<int(T)>& enc) : enc(enc) {
        nodes.emplace_back(-1);
    }

    template <class Container>
    void add(const Container& s) {
        int pos = 0;
        for (T c : s) {
            int ci = enc(c);

            int npos = nodes[pos].nxt[ci];
            if (npos == -1) {
                npos = nodes.size();
                nodes[pos].nxt[ci] = npos;
                nodes.emplace_back(ci);
            }
            pos = npos;
        }

        ++nodes[pos].sz;
    }

    template <class Container>
    int find(const Container& s) const {
        int pos = 0;
        for (char c : s) {
            int ci = enc(c);
            pos = nodes[pos].nxt[ci];
            if (pos == -1) return -1;
        }
        return pos;
    }

    // cntを埋める
    void fillcnt() {
        for (int pos = (int)nodes.size() - 1; pos >= 0; --pos) {
            auto& node = nodes[pos];

            for (int c = 0; c < 26; ++c) {
                int npos = node.nxt[c];
                if (npos == -1) continue;

                const auto& cnode = nodes[npos];
                node.sz += cnode.sz;
                for (int d = 0; d < 26; ++d) {
                    node.cnt[d] += cnode.cnt[d];
                }
            }

            // 全ての子孫はcを含む
            if (node.c != -1) node.cnt[node.c] = node.sz;
        }
    }
};

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<std::string> ss(n);
    for (auto& s : ss) {
        std::cin >> s;
        std::reverse(s.begin(), s.end());
    }

    Trie<26, char> trie('a');
    for (const auto& s : ss) trie.add(s);

    trie.fillcnt();

    lint ans = 0;

    for (auto s : ss) {
        // 末尾とそれ以外に分離
        int last = s.back() - 'a';
        s.pop_back();

        int pos = trie.find(s);

        // posの子でlastを含むものを数え上げ
        for (int ci = 0; ci < 26; ++ci) {
            int npos = trie.nodes[pos].nxt[ci];

            if (npos == -1) continue;
            ans += trie.nodes[npos].cnt[last];

            // 自分自身は除く
            if (ci == last) --ans;
        }
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 228024
import math
from itertools import permutations, combinations,combinations_with_replacement,product
def length(x,y,p,q):
    ans= math.sqrt((x-p)**2+(y-q)**2)
    return ans
N=int(input())
S= [list(map(int, input().split())) for i in range(N)]
S_list=list(permutations(S))
leng_sum=0
for i in S_list:
    for j in range(N-1):
        x1=i[j][0]
        y1=i[j][1]
        x2=i[j+1][0]
        y2=i[j+1][1]
        leng_sum=leng_sum+length(x1,y1,x2,y2)
print(leng_sum/math.factorial(N))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
const int maxn = int(1e5) + 7;
int n, same[maxn];
struct Ans {
    bool data[maxn];
    bool & operator [] (int index) {
        return data[(index + n) % n];
    }
} S;
void gao(int cur, int other) {
    bool flag = true;
    if (S[cur]) flag = false;
    if (same[cur] ^ flag) S[cur * 2 - other] = S[other];
    else S[cur * 2 - other] = !S[other];
}
bool check(int cur) {
    bool flag = true;
    if (S[cur]) flag = false;
    if (same[cur] ^ flag) return S[cur - 1] == S[cur + 1];
    return S[cur - 1] ^ S[cur + 1];
}
int main() {
//    freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    char ch;
    for (int i = 0; i < n; i++) scanf(" %c", &ch), same[i] = ch == 'o';
    bool flag = false;
    for (int i = 0; i < 2 && (!flag); i++)
        for (int j = 0; j < 2 && (!flag); j++) {
            S[0] = bool(i), S[1] = bool(j);
            gao(0, 1);
            for (int cur = 1; cur < n - 2; cur++) gao(cur, cur - 1);
            if (check(n - 2) && check(n - 1)) flag = true;
        }
    if (flag) for (int i = 0; i < n; i++) printf("%c%s", S[i] ? 'S' : 'W', i == n - 1 ? "\n" : "");
    else puts("-1");
    return 0;
}

Measured memory_bytes: 768