akhauriyash/Code-Regression huggingface dataset:
# 何でこのプログラムで通らないか分からん
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    a, b, c, d, e, f = MI()
    max_sw = a*100
    max_s = 0
    for an in range(f // (100 * a) + 1):
        for bn in range((f - 100 * a * an) // (100 * b) + 1):
            w = a * an + b * bn
            if w == 0: continue
            if 100 * w > f: break
            for cn in range(f):
                dn = (min(w * e, f - 100 * w) - c * cn) // d
                if dn < 0: break
                # print(an,bn,cn,dn)
                s = c * cn + d * dn
                if s * max_sw > max_s * (s + w * 100):
                    max_sw = s + 100 * w
                    max_s = s
    print(max_sw, max_s)

main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;

int main() {
	long long int n;
	long long int a;
	long long int b;
	cin >> n >> a >> b;
	long long int c = a + b;
	long long int d = n / c;
	long long int e = n - d * c;
	if (e > a)e = a;
	cout << d * a + e;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
s1 = 0
s2 = 0
M = 10**9+7
for item in a:
    s1 += item
    s2 += item**2
    s1 %= M
    s2 %= M
ans = (s1**2 - s2)*pow(2, M-2, M)
print(ans%M)

Measured memory_bytes: 105528
#include <bits/stdc++.h>
using namespace std;
int main()
{
    using ll = long long;
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n+1);
    vector<ll> s(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    s[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        s[i] = (s[i-1] + (a[i] % m)) % m;
    }

    map<ll, ll> cm;
    for(int i = 1; i <= n; i++)
    {
        cm[s[i]]++;
    }
    ll count = 0;
    for(auto itr = cm.begin(); itr != cm.end(); itr++)
    {
        ll key = (*itr).first;
        ll val = (*itr).second;
        if(key == 0) count += val;
        if(val > 1)
        {
            count += (val * (val-1)) / 2;
        }
    }
    cout << count << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin>>d[i];
  sort(d.begin(),d.end());  
  cout << d[n/2]-d[n/2-1];
  return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int s;
int main() {
    while (cin >> s) {
        int res = 0;
        int cur = s;
        set<int> se;
        se.insert(cur);
        for (int i = 0; i < 100000000; ++i) {
            if (cur % 2 == 0) cur /= 2;
            else cur = cur * 3 + 1;
            if (se.count(cur)) {
                res = i + 2;
                break;
            }
            se.insert(cur);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 256
// A - Frog1

#include <bits/stdc++.h>

using namespace std;

// DP時の道具
template<class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		// aよりbの方が小さかったら、aの値をbの値に置き換える
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		// aよりbの方が大きかったら、aの値をbの値に置き換える
		a = b;
		return true;
	}
	return false;
}


int main() {
	int N, t;
	cin >> N;
	vector<int> h;
	for (int i = 0; i < N; i++) {
		cin >> t;
		h.push_back(t);
	}

	const int INF = (1 << 30);
	
	// 初期化
	vector<int> dp = {0, abs(h.at(1) - h.at(0))};
	for (int i = 2; i < N; i++) {
		dp.push_back(INF);
	}

	// 更新
	for (int i = 2; i < N; i++) {
		chmin(dp.at(i), dp.at(i-1) + abs(h.at(i) - h.at(i-1)));
		chmin(dp.at(i), dp.at(i-2) + abs(h.at(i) - h.at(i-2)));
	}

	// 出力
	cout << dp.at(N-1) << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void){
	string s;
	int n, t, a, h, ansi;
	double ans = 10000000.0;
	cin >> n >> t >> a;
	for(int i = 0; i < n; ++i){
		cin >> h;
		double tmp = abs((double)a-(t-h*0.006));
		if(i==0) ans = tmp;
		if(ans > tmp){
			ans = tmp;
			ansi = i;
		}
		//cout << ans << endl;
	}
	cout << ansi + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
int n;
ll a[100001];

int main(void){
	scanf("%d",&n);
	scanf("%lld",&a[0]);
	ll res=a[0]-1LL,now=2;
	for(int i=1;i<n;i++){
		scanf("%lld",&a[i]);
		ll cnt=a[i]/now;
		if(a[i]==cnt*now){
			if(cnt==1)now++;
			cnt--;
		}
		res+=cnt;
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <map>

using namespace std;

int main(){
    long mod = 1000000007;

    int n = 0, m = 0;
    cin >> n; cin >> m;

    int mm = m;

    vector<int> vec;
    for(int i=2; i*i<=mm; i++)
    {
        int cnt = 0;
        while(mm % i == 0)
        {
            cnt++;
            mm /= i;
        }
        if(cnt > 0)
        {
            vec.emplace_back(cnt);
        }
    }
    if(mm > 1)
    {
        vec.emplace_back(1);
    }

    const int MX = 32;
    long dp[32] = {};
    dp[0] = 1;

    for(int i=0; i<n; i++)
    {
        for(int j=MX-1; j >= 0; j--)
        {
            for(int k=0; k<j; k++)
            {
                dp[j] += dp[k];
                dp[j] %= mod;
            }
        }
    }

    long ans = 1;
    for(auto p : vec)
    {
        ans = ans * dp[p] % mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from operator import lt, gt, le, ge
def get_monotonic_section(A, start=0, operator=lt):
    a0 = A[start]
    for i in range(start+1, len(A)):
        a = A[i]
        if not operator(a0, a):
            return i
        a0 = a
    return len(A)

n, *A = map(int, open(0).read().split())
c = t = 0
while t < n:
    t1 = get_monotonic_section(A, start=t, operator=le)
    t2 = get_monotonic_section(A, start=t, operator=ge)
    t = max(t1, t2)
    c += 1
print(c)

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    vector<ll> a;
    vector<ll> b;
    ll most = 0;
    ll point = -1;
    ll tmp;
    ll ans = 5;
    bool flag = true;
    cin >> tmp;
    a.push_back(tmp);
    rep(i,5)
    {
        cin >> tmp;
        a.push_back(tmp);
        if(tmp>a[0])continue;
        flag = false;
        if(a[0]%tmp == 0)
        {
            if(most < a[0]/tmp)
            {
                most = a[0]/tmp;
                point = i;
            }
            b.push_back(a[0]/tmp);
        }
        else
        {
            if(most < a[0]/tmp+1)
            {
                most = a[0]/tmp+1;
                point = i;
            }
            b.push_back(a[0]/tmp+1);
        }
    }
    if(!flag) ans += (4-point);
    //cout << ans << point << endl;
    //cout << ans+most << endl;
    ll ANS = 5;
    if(flag) cout << ANS << endl;
    else
    {
        most--;
        ANS += most;
        cout << ANS << endl;
    }

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int count2 = 0;
            int count4 = 0;
            String strArr[] = br.readLine().split(" ");
            for (int i = 0; i < n; i++) {
                long temp = Long.parseLong(strArr[i]);
                if (temp % 4 == 0) {
                    count4++;
                } else if (temp % 2 == 0) {
                    count2++;
                }
            }
            if (count2 > 1) {
                n = n - (count2 - 1);
            }
            n = n / 2;
            n -= count4;
            if (n > 0) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}


Measured memory_bytes: 38100
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

fn gcd(n: u64, m: u64) -> u64 {
    match (n, m) {
        (n, 0) => return n,
        (0, m) => return m,
        (n, m) => {
            let r = n % m;
            if r == 0 {
                m
            } else {
                gcd(m, r)
            }
        },
    }
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(usize);
    let arr = invec!(u64);
    
    let mut lpart: Vec<u64> = arr[0..(n-1)].iter()
                             .scan(0, |acc, &x| { *acc = gcd(*acc, x);
                                                  Some(*acc)
                                                }).collect();
    
    lpart.insert(0, 0);
    // for v in &lpart {
    //     print!("{}  ", v);
    // }
    // println!("");

    let mut rpart: Vec<u64> = arr[1..n].iter()
                         .rev()
                         .scan(0, |acc, &x| { *acc = gcd(*acc, x);
                                                     Some(*acc)
                                            }).collect();

    rpart.reverse();
    rpart.push(0);
    // for v in &rpart {
    //     print!("{}  ", v);
    // }
    // println!("");


    let ans = lpart.iter().zip(rpart.iter())
        .map(|(&n, &m)| gcd(n,m))
        .max();

    if let Some(ans) = ans {
        println!("{}", ans);
    }
}

fn main() {
    solve();
}


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

class DisjointSet
{
    public:
    vector<int> rank, p;
    DisjointSet(){}
    DisjointSet(int size)
    {
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i=0; i<size; i++) makeSet(i);
    }
    void makeSet(int x)
    {
        p[x] = x;
        rank[x] = 0;
    }
    bool same(int x, int y){return findSet(x)==findSet(y);}
    void unite(int x, int y){link(findSet(x), findSet(y));}
    void link(int x, int y)
    {
        if(rank[x]>rank[y]) p[y] = x;
        else
        {
            p[x] = y;
            if(rank[x] == rank[y]) rank[y]++;
        }
    }
    int findSet(int x)
    {
        if(x != p[x]) p[x] = findSet(p[x]);
        return p[x];
    }
};

int main()
{
    int n, a, b, q;
    int t;
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    for(int i=0; i<q; i++)
    {
        cin >> t >> a >> b;
        if(t==0) ds.unite(a, b);
        else if(t==1)
        {
            if(ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_D = 10;
    int D, G, p[MAX_D], c[MAX_D];
    cin >> D >> G;
    G /= 100;
    REP(i, D) {
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }
    int res = 1001;
    REP(i, 1 << D) {
        int H = G, cnt = 0;
        REP(j, D) {
            if ((1 << j) & i) {
                H -= (j + 1) * p[j] + c[j];
                cnt += p[j];
            }
        }
        RREP(j, D - 1) {
            if (H <= 0) {
                break;
            }
            if ((1 << j) & i) {
                continue;
            }
            int n = min(ceil(H, j + 1), p[j] - 1);
            H -= (j + 1) * n;
            cnt += n;
        }
        if (H <= 0) {
            amin(res, cnt);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    X,Y,A,B,C=map(int,input().split())
    P=list(map(int,input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))

    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    Pmax=P[:X]
    Qmax=Q[:Y]

    Pmax.extend(Qmax)
    Pmax.extend(R)
    Pmax.sort(reverse=True)
    res=0
    for i in range(X+Y):
        res+=Pmax[i]

    print(res)

if __name__=="__main__":
    main()




Measured memory_bytes: 103896
#include <stdio.h>
#include <math.h>

 #define PI 3.14159265358979323846264338327950L

 int main(void) {
int a, b, h, m;
  scanf("%d%d%d%d", &a, &b, &h, &m);
 long double rad = PI * 2 * (
 (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long
double)m / 60.0);
 long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
b) * cosl(rad);

 printf("%20.20Lf\n", sqrtl(rsq));
  return 0;
 }

Measured memory_bytes: 2576
N = int(input())
A = [[int(x) for x in input().split()]for i in range(2)]
S = A[0][0]
G = sum(A[1])
Sum_max = S+G
for i in range (N-1):
  S+=A[0][i+1]
  G-=A[1][i]
  Sum_max = max(Sum_max, S+G) 
print(Sum_max)

Measured memory_bytes: 38384
N, L = map(int, input().split())

if L > 0:
    print(int(((L+1) + (N+L-1)) * (N-1) / 2))
elif (N+L-1) > 0:
    print(int((L+N+L-1)*N/2))
else:
    print(int((L + (N+L-2)) * (N-1) / 2))


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

int main(){
	ll a,b,c;
	cin >> a >> b >> c;
	ll mx = max({a,b,c});
	ll mn = min({a,b,c});
	ll md = a + b + c - mx - mn;
	ll ans = (mx+1)/2*mn*md - (mx)/2*mn*md;
	cout << ans << endl;
    return 0;
}



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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

	int N, K;
	cin >> N >> K;
	if (K == 0) cout << N * N << endl;
	else {
		int res = 0;
		FOR(i, K + 1, N + 1) {
			res += (N / i) * (i - K) + max(0LL, N % i - K + 1);
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 256
S = list(input())
if S.count("N") == 0 and S.count("S") == 0:
	if S.count("E") >= 1 and S.count("W") >= 1:
		print("Yes")
	else:
		print("No")
elif S.count("E") == 0 and S.count("W") == 0:
	if S.count("N") >= 1 and S.count("S") >= 1:
		print("Yes")
	else:
		print("No")
else:
	if S.count("N") >= 1 and S.count("S") >= 1 and S.count("W") >= 1 and S.count("E") >= 1:
		print("Yes")
	else:
		print("No")	

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i, n) {
    int x;
    cin >> x;
    vec[x-1] = i+1;
  }
  rep(i, n) {
    cout << vec[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
const int INF=2.147e9;
int qlen=0;
static inline int Abs(int x){return x<0?-x:x;}
struct nodetag{int y,x,cost;}Q[50000];
static inline void qfix(int idx)
{
  while(1)
  {
    int midx=idx;
    rep(i,2){int cidx=idx*2+i+1;if(cidx<qlen&&Q[midx].cost>Q[cidx].cost){midx=cidx;}}
    if(midx==idx){if(!idx){break;}idx=(idx-1)/2;}
    else{struct nodetag sw=Q[idx];Q[idx]=Q[midx];Q[midx]=sw;idx=midx;}
  }
}
static inline void qpush(int y,int x,int cost)
{
  Q[qlen].y=y;Q[qlen].x=x;Q[qlen].cost=cost;qfix(qlen);qlen++;
}
static inline struct nodetag qpop(void)
{
  if(qlen<=0){exit(EXIT_FAILURE);}
  struct nodetag res=Q[0];qlen--;if(qlen){Q[0]=Q[qlen];qfix(0);}
  return res;
}
const int dx[24]={0,1,0,-1,0,0,1,1,1,1,-1,-1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2},
          dy[24]={1,0,-1,0,2,-2,1,2,-1,-2,1,2,-1,-2,0,1,2,-1,-2,0,1,2,-1,-2};
int main(void)
{
  int H=IN(),W=IN(),Ch=IN(),Cw=IN(),Dh=IN(),Dw=IN(),dist[H][W],field[H][W];char str[W+1];
  rep(i,H)
  {
    if(!scanf("%s",str)){return -1;}
    rep(j,W){dist[i][j]=INF;field[i][j]=(str[j]=='#');}
  }
  qpush(Ch-1,Cw-1,0);dist[Ch-1][Cw-1]=0;
  while(qlen)
  {
    struct nodetag pos=qpop();
    rep(i,24)
    {
      if(dist[Ch-1][Cw-1]){break;}
      int ny=pos.y+dy[i],nx=pos.x+dx[i],warp=!(Abs(dx[i])+Abs(dy[i])<=1),need=dist[pos.y][pos.x]+warp;
      if(field[ny][nx]){continue;}
      if(0<=ny&&ny<H&&0<=nx&&nx<W&&need<dist[ny][nx])
      {
        dist[ny][nx]=need;qpush(ny,nx,need);
      }
    }
  }
  return OUT(dist[Dh-1][Dw-1]<INF?dist[Dh-1][Dw-1]:-1),0;
}

Measured memory_bytes: 9560
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
vector<vector<ll>> hz;
vector<vector<ll>> v;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h, w;
    cin >> h >> w;
    vector<string> l (h);
    F0R(i, h) cin >> l[i];
    hz.assign(h, vector<ll>(w, 0));
    v.assign(h, vector<ll>(w, 0));
    F0R(i, h)
    {
        F0R(j, w)
        {
            if(l[i][j] == '#') hz[i][j] = INT_MIN;
            int cp = j;
            if(l[i][j] == '.')
            {
                while(j < w && l[i][j] == '.')
                {
                    j++;
                }
                ll vx = j - cp;
                FOR(k, cp, j) hz[i][k] = vx;
                j--;
            }
        }
    }
    F0R(i, w)
    {
        F0R(j, h)
        {
            if(l[j][i] == '#') v[j][i] = INT_MIN;
            int cp = j;
            if(l[j][i] == '.')
            {
                while(j < h && l[j][i] == '.')
                {
                    j++;
                }
                ll vx = j - cp;
                FOR(k, cp, j) v[k][i] = vx;
                j--;
            }
        }
    }
    ll res = 0;
    F0R(i, h) F0R(j, w) res = max(res, v[i][j] + hz[i][j]);
    cout << res - 1; 
    // cout << "\n";
    // F0R(i, h)
    // {
    //     F0R(j, w) cout << v[i][j] << " ";
    //     cout << "\n";
    // }
    // cout << "\n";
    // F0R(i, h)
    // {
    //     F0R(j, w) cout << hz[i][j] << " ";
    //     cout << "\n";
    // }
    // cout << "\n";
    return 0;
}

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

#define endl '\n'
#define rep(i,s,n)      for (int i = s ; i < n ; i++)
#define repp(i,s,n)    for (int i = s ; i <= n ;i++)
#define all(a)      a.begin(),a.end()
#define sz(v)    (int)v.size()
#define digg(n)    ((long long)log10(n)+1)
#define Unique(n)         (n).erase(unique(all(n)), (n).end())
#define tests    int s ; cin >> s; while (s--)
#define test    int tt = 1 ; while (tt--)
#define readArr    int n ; cin >> n ; int arr[n]; rep(i,0,n)cin>>arr[i]
#define isvowel(a)   (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' )
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define s second
#define f first
#define deb(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " : " << arg1 <<'\n';
}
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

void readFromText (){
    #ifndef ONLINE_JUDGE
freopen("C:/Users/Anas-Hagras/Desktop/input.txt","r",stdin);
    #endif // ONLINE_JUDGE
}

typedef long long ll ;
typedef unsigned long long ull ;
typedef pair<int,int> pii;
typedef vector<long long> vll;
typedef vector<pii>vii;
typedef map<long long, long long> mll ;

const int mx = 2e5 ;
int freq[mx];
int pref[mx];

int main()
{
    fast;
    readFromText();
    int t = 1 ;
//    cin >> t ;
    while(t--)
    {
        string s ; cin >> s;
        s = s ;
        int c = 0 ;
        int mx = INT_MIN;
        for (int i = 0 ; i < s.length() ; i++){
            if (s[i]=='R')c++;
            else c = 0 ;
            mx = max(c,mx);
        }
        cout << mx << endl ;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  int a[3010];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int s = 0;
  for (int i = 0; i < N; i++)
    s += a[i]-1;
  cout << s << endl;
}


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

using namespace std;

int main(){
  int n, cnt=0;
  cin >> n;
  int prev=-1;
  for(int i=1;i<=n;i++){
    int p;cin >> p;
    if(i==p){
      if(prev!=i-1){
        cnt++;
        prev=i;
      }
    }
  }
  cout << cnt << endl;
}


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

  int W,H,x,y,r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if( r <= x && x <= W - r && r <= y && y <= H - r){
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
  
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n; cin>>n;
  vector<ll> a(5);
  rep(i, 5) cin>>a[i];
  sort(a.begin(),a.end());
  ll t = a[0];

  cout << (n-1+t)/t + 4 << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int dir[][2] = {
	1, 0,
	0, 1,
	-1, 0,
	0, -1
};

int comp( VI &x1, VI &x2, int W )
{
	const int N = x1.size();

	VI xs;

	REP( i, 0, N )
	{
		REP( j, -1, 2 )
		{
			int tmp1 = x1[i] + j, tmp2 = x2[i] + j;

			if ( 0 <= tmp1 && tmp1 < W )
			{
				xs.PB( tmp1 );
			}

			if ( 0 <= tmp2 && tmp2 < W )
			{
				xs.PB( tmp2 );
			}
		}
	}

	sort( ALL( xs ) );
	xs.erase( unique( ALL( xs ) ), xs.end() );

	REP( i, 0, N )
	{
		x1[i] = lower_bound( ALL( xs ), x1[i] ) - xs.begin();
		x2[i] = lower_bound( ALL( xs ), x2[i] ) - xs.begin();
	}

	return xs.size();
}

void paint( VVI &board, int x1, int y1, int x2, int y2 )
{
	REP( i, y1, y2 )
	{
		REP( j, x1, x2 )
		{
			board[i][j] = 1;
		}
	}

	return;
}

void bfs( VVI &board, int y, int x )
{
	const int H = board.size(), W = board[0].size();

	queue< PII > que;
	que.push( MP( y, x ) );

	while ( !que.empty() )
	{
		auto cur = que.front();
		que.pop();

		if ( board[ cur.fst ][ cur.snd ] )
		{
			continue;
		}

		board[ cur.fst ][ cur.snd ] = 1;

		REP( d, 0, 4 )
		{
			auto next = cur;

			next.fst += dir[d][0];
			next.snd += dir[d][1];

			if ( !( 0 <= next.fst && next.fst < H && 0 <= next.snd && next.snd < W ) )
			{
				continue;
			}

			que.push( next );
		}
	}

	return;
}

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

	while ( true )
	{
		int w, h;
		cin >> w >> h;

		if ( !( w | h ) )
		{
			break;
		}

		int n;
		cin >> n;

		VI x1( n ), y1( n ), x2( n ), y2( n );

		REP( i, 0, n )
		{
			cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		}

		const int W = comp( x1, x2, w ), H = comp( y1, y2, h );

		VVI board( H, VI( W, 0 ) );

		REP( i, 0, n )
		{
			paint( board, x1[i], y1[i], x2[i], y2[i] );
		}

		int res = 0;

		REP( i, 0, H )
		{
			REP( j, 0, W )
			{
				if ( board[i][j] )
				{
					continue;
				}

				res++;

				bfs( board, i, j );
			}
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 8216
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	vector<string> v = {"Sunny", "Cloudy", "Rainy", "Sunny"};
	string s;
	cin>>s;

	auto it = find(all(v),s);
	it++;
	cout<<*it;
 
	return 0;	
}

Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  ll ans=0LL;
  int res=0;
  rep(i, n){
    int a;cin>>a;
    if(res==1 && a>0){
      a--;ans+=a/2+1;
      res=a%2;
    }else if(res==0 && a>0){
      ans+=a/2;
      res=a%2;
    }else{
      res=0;
    }
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int A,B;
	cin>>A>>B;
	if(A%3==0||B%3==0||(A+B)%3==0)
	{
        cout<<"Possible"<<endl;
	}
		
	else
	{
		cout<<"Impossible"<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll n;
ll a[300000];
P  t[300000];

int main(){
  scanf("%lld",&n);
  for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);
    t[i]=P(a[i],i);  
  }

  set<ll> st;
  st.insert(-1);
  st.insert(n);
  
  sort(t,t+n);

  ll ans=0;
  
  for(int i=0;i<n;i++){
    set<ll> :: iterator it;
    ll num=t[i].second;
    
    it=st.lower_bound(num);
    ll R=(*it);
    it--;
    ll L=(*it);

    ans+= ( t[i].first * ( R-num  ) * (num-L) );

    st.insert( num );
  }

  printf("%lld\n",ans);
  return 0;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int n;
    cin>>n;
    cout<<n/3;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int a[110000];
int b[110000];
int c[110000];

int main() {
	int n, q;
	cin >> n;
	map<int, int> mp;
	long ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (mp.count(a[i])) {
			mp[a[i]]++;
		} else {
			mp.emplace(a[i], 1);
		}
		ans += a[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> b[i] >> c[i];
		if (mp.count(b[i])) {
			int bn = mp[b[i]];
			if (mp.count(c[i])) {
				mp[c[i]] += bn;
			} else {
				mp.emplace(c[i], bn);
			}
			mp[b[i]] = 0;
			ans += (c[i] - b[i]) * bn;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 8584
#include<bits/stdc++.h>
using namespace std;
#define MOD 998244353
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
char s[200010];
int f[200010][3][3][2];
set<string> S;
inline void dfs(string st) {
	//cerr << "string " << st << endl;
	int n = st.size();
	for(int i = 0; i + 1 < n; ++ i) {
		if(st[i] == st[i + 1]) continue;
		string en = st;
		char New = 3 - (st[i] - 'a') - (st[i + 1] - 'a') + 'a';
		en[i] = en[i + 1] = New;
		if(S.find(en) == S.end()) {
			S.insert(en);
			dfs(en);
		}
	}
}
inline void solve(int n){
	string st = "";
	for(int i = 1; i <= n; ++ i) {
		st += s[i];
	}
	S.insert(st);
	//cerr << st << endl;
	dfs(st);
	printf("%d\n", S.size());
}
int main() {
	//freopen("a.in", "r", stdin);
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	if(n <= 3) solve(n);
	else {
		int flag = 0;
		for(int i = 1; i < n; ++ i) {
			if(s[i] != s[i + 1]) ++ flag;
		}
		int Sum = 0;
		for(int i = 1; i <= n; ++ i) {
			Sum += s[i] - 'a';
		}
		Sum %= 3;
		if(!flag) {
			return puts("1"), 0;
		}
		f[1][0][0][0] = f[1][1][1][0] = f[1][2][2][0] = 1;
		for(int i = 1; i < n; ++ i) {
			for(int j = 0; j <= 2; ++ j) {
				for(int k = 0; k <= 2; ++ k) {
					for(int w = 0; w <= 1; ++ w) {
						for(int t = 0; t <= 2; ++ t) {
							(f[i + 1][t][(k + t) % 3][w | (t == j)] += f[i][j][k][w]) %= MOD;
						}
					}
				}
			}
		}
		int Ans = 0;
		for(int i = 0; i <= 2; ++ i) {
			Ans += f[n][i][Sum][1];
			Ans %= MOD;
		} 
		if(flag == n - 1) (++ Ans) %= MOD;
		printf("%d\n", Ans);
	}
} 

Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1000000007;


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    int ans;

    ans = N /3;

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
typedef long long ll;
const int inf=1<<30;
const double pi=acos(-1);

int n;
vi sosu;

int main(){
	vector<bool> used(300000,1);
	for(int i=2;sosu.size()<=10005;i++){
		if(used[i]){
			sosu.push_back(i);
			for(int j=i+i;j<=300000;j+=i) used[j]=0;
		}
	}
//	for(int i=0;i<sosu.size();i++) cout<<sosu[i]<<endl;
	while(1){
		cin>>n;
		if(!n) break;
		int ans=0;
		for(int i=0;i<n;i++) ans+=sosu[i];
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1348
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;
vector<int> bas;

int main(){
	int n,m;
	cin>>n>>m;
	string st;
	cin>>st;
	int kac=n;
	int temp;
	while(1){
		temp=m;
		while(kac-temp<0){
			temp--;
		}
		while(st[kac-temp]=='1'){
			temp--;
			if(temp==0){
				cout<<-1<<endl;
				return 0;
			}
		}
		kac-=temp;
		bas.pb(temp);
		if(kac==0){
			break;
		}
	}
	for(int i=bas.size()-1;i>=0;i--){
		cout<<bas[i]<<" ";
	}
	

	return 0;
}



Measured memory_bytes: 1144
object Main extends App {
  import scala.io.StdIn._


  val str = readLine.trim
  val characters = ('a' to 'z').map(c ⇒ str.count(_ == c)).toArray
  val numbers = ('0' to '9').map(c ⇒ str.count(_ == c)).toArray
  var replaced = 0
  for (from ← 0 until 26; to ← (from + 2 until 26).reverse) {
    while ((from to to).forall(i ⇒ characters(i) > 0)) {
      replaced += 3
      (from to to).foreach(i ⇒ characters(i) -= 1)
    }
  }
  for (from ← 0 to 9; to ← (from + 2 to 9).reverse){
    while((from to to).forall(i ⇒ numbers(i) > 0)){
      replaced += 3
      (from to to).foreach(i ⇒ numbers(i) -= 1)
    }
  }
  println(replaced + characters.sum + numbers.sum)
  implicit class Scope[T](val value: T) extends AnyVal{
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}



Measured memory_bytes: 45124
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
        return
    ans = 1
    for ai in a:
        ans *= ai
        if ans > 10**18:
            print(-1)
            return
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 87816
#include<bits/stdc++.h>
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int MX=2e5+9;
const ll inf=(1ll<<60);
const ll mod=1e9+7;
int n,a[MX];
string s;
bool check(ll x,char c,ll f,ll s){
    if(x&&c=='o'&&f!=s)return 1;
    if(x&&c=='x'&&f==s)return 1;
    if(!x&&c=='o'&&f==s)return 1;
    if(!x&&c=='x'&&f!=s)return 1;
    return 0;
}
int main(){
    scanf("%d",&n);
    cin>>s;
    s="^"+s;
    for(int i=0;i<=1;i++){
        for(int j=0;j<=1;j++){
            a[1]=i;a[2]=j;
            for(int k=3;k<=n;k++){
                if(a[k-1]==0&&s[k-1]=='o')a[k]=a[k-2];
                if(a[k-1]==0&&s[k-1]=='x')a[k]=a[k-2]^1;
                if(a[k-1]==1&&s[k-1]=='o')a[k]=a[k-2]^1;
                if(a[k-1]==1&&s[k-1]=='x')a[k]=a[k-2];
            }
            if(check(a[1],s[1],a[n],a[2])&&check(a[n],s[n],a[1],a[n-1])){
               for(int i=1;i<=n;i++){
                    if(a[i])printf("W");
                    else printf("S");
                }
                return 0;
            }
        }
    }
    puts("-1");
}


Measured memory_bytes: 892
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <map>
#include <list>
#include <set>

using namespace std;

typedef long long ll;

bool calcDistance(vector<int> p1, vector<int> p2)
{
    double suma = 0;
    for(int i = 0; i < p1.size(); i++)
    {
        suma += pow(p1[i]-p2[i],2);
    }

    suma = sqrt(suma);
    //cout << suma << endl;
    if(floor(suma) == ceil(suma))
        return true;
    return false;
}
int main() {

    int n, d;
    cin >> n >> d;
    vector<vector<int>> points (n);
    for(int i = 0; i < n; i++)
    {
       for(int j = 0; j < d; j++)
       {
           int temp;
           cin >> temp;
           points[i].push_back(temp);
       }
    }

    int counter = 0;

    for(int i = 0; i < n;i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(j != i)
            {
                if(calcDistance(points[i],points[j]))
                    counter++;
            }
        }

    }

    cout << counter;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int i, n, ai;
    int min = 1000000, max = -1000000;
    long sum = 0;
    //数値を入力
    scanf("%ld", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &ai);
        if(ai < min){
            min = ai;
        }
        if(ai > max){
            max = ai;
        }
        sum = sum + ai;
    }
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, string>
const int INF = INT_MAX / 2;
const int MAX_M = 1010;

P cntSpace(string str){
    int cnt = 0;
    while(str[cnt] == ' ') cnt++;
    return P(cnt, str.substr(cnt));
}

bool isParent(int x, int y, vector<int> parent){
    if(parent[y] == x) return true;
    else return false;
}

bool checkQ(string str, map<string, int> list_i, vector<int> parent){
    stringstream ss(str);
    vector<string> vec;
    string tmp;
    while(ss >>tmp) vec.push_back(tmp);

    int x = list_i[vec[0]];
    int y = list_i[vec[5].erase(vec[5].size() - 1)];

    if(vec[3] == "child") return isParent(y, x, parent);
    if(vec[3] == "parent") return isParent(x, y, parent);
    if(vec[3] == "sibling") return parent[x] == parent[y];
    if(vec[3] == "descendant"){
        int now_x = x;
        while(parent[now_x] != -1){
            if(isParent(y, now_x, parent) == true) return true;
            now_x = parent[now_x];
        }
        return false;
    }
    if(vec[3] == "ancestor"){
        int now_y = y;
        while(parent[now_y] != -1){
            if(isParent(x, now_y, parent) == true) return true;
            now_y = parent[now_y];
        }
        return false;
    }
}



int main(){
    while(true){
        string str_m_n;
        getline(cin, str_m_n);
        stringstream ss(str_m_n);
        int m, n;
        ss >>m >>n;
        if(!m && !n) break;

        vector<int> parent(m);
        int current_parent_i[MAX_M];
        map<string, int> list_i;

        parent[0] = -1;

        REP(i, m){
            string name_line;
            getline(cin, name_line);
            stringstream ss(name_line);
            P rank_and_name = cntSpace(name_line);
            current_parent_i[rank_and_name.first + 1] = i;
            list_i[rank_and_name.second] = i;
            if(i != 0){
                int now_parent = current_parent_i[rank_and_name.first];
                parent[i] = now_parent;
            }
        }

        REP(i, n){
            string q;
            getline(cin, q);
            bool ans = checkQ(q, list_i, parent);
            if(ans) cout <<"True" <<endl;
            else cout <<"False" <<endl;
        }
        cout <<endl;
    }
    return 0;
}

Measured memory_bytes: 1432
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
ld distance(ll x,ll y){
  return (double)(sqrt(x*x+y*y));
}
int main(void){
  ll n;
  cin>>n;
  string s;
  cin>>s;
  if(n%2==1){
    cout<<"No";
    return 0;
  }
  rep(i,n/2){
    if(s[i]!=s[i+n/2]){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  return 0;
}

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

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with \"n\" of \"nCk\" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

int main() {
	int n;
    cin >> n;
    vector<ll> a(n);
    vector<mint> ps(n+1);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ps[i+1] = mint(a[i]) + ps[i];
    }

    mint ans;
    for (int i = 0; i+1 < n; ++i) {
        mint sum = ps[n] - ps[i+1];
        ans += sum * mint(a[i]);
    }
    cout << ans.x << endl;
}


Measured memory_bytes: 6360