akhauriyash/Code-Regression huggingface dataset:
a,b = list(map(int, input().split()))

def div(n):
    divs = set([1])
    i = 2
    while i*i <= n:
        while n%i==0:
            divs.add(i)
            n//=i
        i+=1
        
    if n>1:
        divs.add(n)
        
    return divs

div_set = div(a) & div(b)

print(len(div_set))

Measured memory_bytes: 9140
#include<iostream>
#include<vector>
#include<set>
#include<unordered_map>
using namespace std;
#define int long long int
const int MOD = 1e9+7;
int cnt = 0;

vector<int>dp;
int dfs(int n){

	if(n<=0){
		if(n==0){
			return 1;
		}
		return 0;
	}

	if(dp[n] != -1){
		return dp[n];
	}

	int ans = 0;
	for(int i = 3;i<=n;i++){
		if(n-i>=0){
			ans += dfs(n-i);
		}
		
	}

	return dp[n] = ans%MOD;


}

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

	int n;
	cin>>n;
	dp.resize(n+1,-1);

	cout<<dfs(n);
	
	//cout<<cnt;

}



Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    ll x; cin >> x;

    ll m = 1;
    
    for(ll i=2LL; i*i<=x; ++i){
        if(x%i==0) m = max(i, m);
    }

    cout << m+(x/m)-2 << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#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 MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

//#define __DEBUG__
#ifdef  __DEBUG__
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// pair出力
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#endif

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N,K; cin >> N >> K;
    VI h(N);
    REP(i, N) cin >> h[i];
    VI dp(N, INF);
    dp[0] = 0;
    REP(i, N-1) {
        REP(j,K) {
            if (i + j + 1 < N) {
                dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(h[i] - h[i + j + 1]));
            }
            else {
                break;
            }
        }
    }
    cout << dp[N - 1] << endl;
    getchar(); getchar();
}


Measured memory_bytes: 1024
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			// t
			scanner.nextInt();
			int[] a = new int[n];
			IntStream.range(0, n).forEach(i -> a[i] = scanner.nextInt());
			// max[i] はa[i]〜a[n-1]の最大値
			int[] max = new int[n];
			max[n - 1] = a[n - 1];
			IntStream.range(1, n).map(i -> n - 1 - i).forEach(i -> max[i] = Math.max(max[i + 1], a[i]));
			Map<Integer, Integer> map = new HashMap<>();
			int maxResult = IntStream.range(0, n).map(i -> {
				int result = max[i] - a[i];
				map.put(result, map.getOrDefault(result, 0) + 1);
				return result;
			}).max().getAsInt();
			System.out.println(map.get(maxResult));
		}
	}
}


Measured memory_bytes: 61760
// Author : heyuhhh
// Created Time : 2020/09/19 20:31:18
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2e5 + 5, MOD = 998244353;

int sumv[N << 2];

void push_up(int o) {
    sumv[o] = (sumv[o << 1] + sumv[o << 1|1]) % MOD;
}
void build(int o, int l, int r) {
    if(l == r) {
        sumv[o] = 0;
        return;
    }
    int mid = (l + r) >> 1;
    build(o << 1, l, mid), build(o << 1|1, mid + 1, r);
    push_up(o);
}
void update(int o, int l, int r, int L, int R, ll v) {
    if(L <= l && r <= R) {
        sumv[o] = v;
        return;
    }   
    int mid = (l + r) >> 1;
    if(L <= mid) update(o << 1, l, mid, L, R, v);
    if(R > mid) update(o << 1|1, mid + 1, r, L, R, v);
    push_up(o);
}
int query(int o, int l, int r, int L, int R) {
    if(L <= l && r <= R) {
        return sumv[o];
    }
    int mid = (l + r) >> 1;
    int res = 0;
    if(L <= mid) res = query(o << 1, l, mid, L, R);
    if(R > mid) res = (res + query(o << 1|1, mid + 1, r, L, R)) % MOD;
    return res;
}

void run() {
    int n, k;
    cin >> n >> k;
    build(1, 1, n);
    vector<pii> a(k);
    for (int i = 0; i < k; i++) {
        int l, r;
        cin >> l >> r;
        a[i] = MP(l, r);
    }
    vector<int> dp(n + 1, 0);
    dp[1] = 1;
    update(1, 1, n, 1, 1, 1);
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < k; j++) {
            int L = max(1, i - a[j].se), R = i - a[j].fi;
            if (L > R) continue;
            dp[i] = (dp[i] + query(1, 1, n, L, R)) % MOD;
        }
        update(1, 1, n, i, i, dp[i]);
    }
    cout << dp[n] << '\n';
}
int main() {
#ifdef Local
    freopen("input.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 6100
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N,Vn,Cn,sumv,sumc,h,ans = 0;
  vector<int> v;
  vector<int> c;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> Vn;
    v.push_back(Vn);
  }
  for(int i=0;i<N;i++){
    cin >> Cn;
    c.push_back(Cn);
  }
  for(int i=0;i<N;i++){
  	sumv = v[i];
    sumc = c[i];
    h = sumv-sumc;
	if(h>0){
    	ans+=h;
    }
  }
  cout << ans;
}    

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
int a[12][12],c[12],in[12];
int main(){
	int n,m,x;read(n),read(m),read(x);
	for(int i=0;i<n;++i){
		read(c[i]);
		for(int j=0;j<m;++j){
			read(a[i][j]);
		}
	}
	int U=1<<n,ans=-1;
	for(int s=0;s<U;++s){
		for(int i=0;i<m;++i)
			in[i]=0;
		int sm=0;
		for(int i=0;i<n;++i){
			if((s>>i)&1){
				for(int j=0;j<m;++j)
					in[j]+=a[i][j];
				sm+=c[i];
			}
		}
		int spe=true;
		for(int i=0;i<m;++i)
			spe&=(in[i]>=x);
		if(spe){
			if(~ans)
				ans=min(ans,sm);
			else
				ans=sm;
		}
	}
	write(ans);
	return 0;
}


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;
  for(int i=0;i<(1<<3);i++){
    int t;
    int a = s[0]-'0';
    int b = s[1]-'0';
    int c = s[2]-'0';
    int d = s[3]-'0';

    string ans="";
    ans += s[0];
    t = a;
    if(i & 0b100){
      t += b;
      ans+="+";
    }else{
      t -= b;
      ans+="-";
    }
    ans+=s[1];
    if(i & 0b010){
      t += c;
      ans+="+";
    }else{
      t -= c;
      ans+="-";
    }
    ans+=s[2];
    if(i & 0b001){
      t += d;
      ans+="+";
    }else{
      t -= d;
      ans+="-";
    }
    ans+=s[3];
    ans+="=7";
    if(t==7){
      cout<<ans<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifdef STOPIT
#define debug(...) 0
#else
#define debug(...)\
do {\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;\
} while (false)
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template <typename T>
auto make_vector_impl(size_t sz, T t) {return std::vector<T>(sz, t);}

template <size_t N, typename T, typename U, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {return make_vector_impl(sz, T(u));}

template <size_t N, typename T, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {return std::vector<T>(sz);}

template <size_t N, typename T, typename... Args, std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {return make_vector_impl(a, make_vector<N - 1, T>(args...));}

template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {return t.at(i);}

template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {return at(t.at(i), args...);}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  int n = s.length();
  char prv = '$';
  std::string tmp;
  std::vector< std::string > a;
  rep(i, 0, n) {
    char crr = s.at(i);
    if (prv == '>' && crr == '<') {
      a.emplace_back(tmp);
      tmp.clear();
    }
    tmp.push_back(crr);
    prv = crr;
  }
  if (!tmp.empty()) {
    a.emplace_back(tmp);
  }
  // debug(a);

  auto cal = [&] (std::string s) {
    lint a = std::find(all(s), '>') - s.begin();
    lint b = s.length() - a;
    if (a > b) std::swap(a, b);
    return (a * (a - 1) + b * (b + 1)) / 2;
  };
  lint ret = 0;
  for (auto const & t : a) {
    ret += cal(t);
  }
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 7704
//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define int ll

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//std::ios::sync_with_stdio(false);
stack<int>st;
vector<int>vec,vec1;
int a[105];
main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int n,i,id,j;
	cin>>n;
	rep(i,n){
		cin>>a[i];
		a[i]--;
		vec.pb(a[i]);
	}
	rep(i,n){
		vec1.clear();
		id=-1;
		rep(j,vec.size()){
			if(vec[j]==j){
				id=j;
			}
		}
		if(id==-1){
			cout<<-1<<endl;
			return 0;
		}
		else{
			st.push(id+1);
			rep(j,vec.size()){
				if(j==id){
					continue;
				}
				vec1.pb(vec[j]);
			}
			vec=vec1;
		}
	}
	while(!st.empty()){
		cout<<st.top()<<endl;
		st.pop();
	}
	return 0;
} 
	


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int64_t> vs(n);
    for (auto& v : vs)
    {
        cin >> v;
    }

    vector<int64_t> sum_vs(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        sum_vs[i + 1] = sum_vs[i] + vs[i];
    }

    auto sum = [&](int l, int r) {
        return sum_vs[r + 1] - sum_vs[l];
    };

    vector<vector<int64_t>> dp(n, vector<int64_t>(n, 1000000000000000ll));
    for (int i = 0; i < n; i++)
    {
        dp[i][i] = 0;
    }

    for (int w = 1; w < n; w++)
    {
        for (int l = 0; l < n - w; l++)
        {
            const int r = l + w;
            for (int m = l + 1; m <= r; m++)
            {
                dp[l][r] = min(dp[l][r], dp[l][m - 1] + dp[m][r] + sum(l, r));
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int y, x; cin >> x >> y;
    bool dir = false, first = true;
    bool dp[2][16004] = {}, tmp[2][16004] = {};
    dp[0][8002] = dp[1][8002] = true;
    int count = 0;
    rep (i, s.size() + 1) {
        if (i == i_len - 1 || s[i] == 'T') {
            rep (i, 16004) tmp[dir][i] = false;
            rep (i, 16004 - count) tmp[dir][i + count] |= dp[dir][i];
            if (!first) repp (i, count, 16004) tmp[dir][i - count] |= dp[dir][i];
            rep (i, 16004) dp[dir][i] = tmp[dir][i];
            eprintf("(%d,%d)", dir, count);
            dir ^= true;
            first = false;
            count = 0;
        } else {
            count++;
        }
    }
    eprintf("\n");
    repp (i, 7997, 8007+1) eprintf("%d ", dp[0][i]); eprintf("\n");
    repp (i, 7997, 8007+1) eprintf("%d ", dp[1][i]); eprintf("\n");
    cout << ((dp[0][8002 + x] && dp[1][8002 + y]) ? "Yes" : "No") << "\n";
    return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	int a[4][4] = {};
	bool f[4][4] = {};
	rep(i, 3) {
		rep(j, 3) {
			cin >> a[i][j];
		}
	}
	in(n);
	rep(k, n) {
		in(b);
		rep(i, 3) {
			rep(j, 3) {
				if (b == a[i][j]) {
					f[i][j] = true;
				}
			}
		}
	}

	rep(i, 3) {
		if (f[i][0] && f[i][1] && f[i][2]) {
			out("Yes");
			return 0;
		}
		if (f[0][i] && f[1][i] && f[2][i]) {
			out("Yes");
			return 0;
		}
	}

	if (f[0][0] && f[1][1] && f[2][2]) {
		out("Yes");
		return 0;
	}
	if (f[2][0] && f[1][1] && f[0][2]) {
		out("Yes");
		return 0;
	}

	out("No");

	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

def solve(a,b,n)
  ans = 0
  n.times do |i|
    if a[i] > b[i]
      ans += b[i]
    else
      ans += a[i]
      b[i] -= a[i]
      if a[i+1] > b[i]
        ans += b[i]
        a[i+1] -= b[i]
      else
        ans += a[i+1]
        a[i+1] = 0
      end
    end
  end
  ans
end

puts solve(a,b,n)

Measured memory_bytes: 17556
def main():
    n = int(input())
    words = {}
    for i in range(n):
        s = list(input())
        s.sort()
        s = tuple(s)
        if s not in words.keys():
            words[s] = 1
        else:
            words[s] += 1

    ans = 0
    for i in words.keys():
        x = words[i]
        ans += x*(x-1)//2

    print(ans)


main()


Measured memory_bytes: 23644
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MAX = 1000000000000000000LL;

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

    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    ll sum = 1;
    for (int i = 0; i < n; i++) {
        if (sum <= MAX / a[i]) {
            sum *= a[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << sum << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " <<  y << endl;
    return 0;
}



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

using namespace std;
const int MAXN=888;
const int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int n,m,k;
char g[MAXN][MAXN];
int dist[MAXN][MAXN];
struct State
{
    int x,y;
    State(int x=0,int y=0):x(x),y(y){}
};
bool inRange(int x,int y)
{
    return (x>=0&&y>=0&&x<n&&y<m);
}
void bfs(int bx,int by)
{
    queue<State> q;
    while(!q.empty()) q.pop();
    q.push(State(bx,by));
    dist[bx][by]=0;
    while(!q.empty())
    {
        State u=q.front();
        q.pop();
        for (int i=0;i<4;i++)
        {
            int tx=u.x+dir[i][0],ty=u.y+dir[i][1];
            if (inRange(tx,ty)&&dist[tx][ty]==-1&&g[tx][ty]=='.')
            {
                dist[tx][ty]=dist[u.x][u.y]+1;
                q.push(State(tx,ty));
            }
        }
    }
}
int main()
{
    cin >> n >> m >> k;
    int bx=0,by=0,ans=INT_MAX;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        {
            cin >> g[i][j];
            if (g[i][j]=='S')
            {
                bx=i;
                by=j;
                g[i][j]='.';
            }
        }
    }
    memset(dist,-1,sizeof(dist));
    bfs(bx,by);
    for (int i=0;i<n;i++)
        for (int j=0;j<m;j++)
    {
        if (dist[i][j]<=k&&dist[i][j]!=-1)
        {
            ans=min(ans,1+(min(min(i,n-i-1),min(j,m-j-1))+k-1)/k);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3968
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long t[11111];
int main(void){
  int n;
  while(cin >> n && n){
    for(int i = 0; i < n; i++) cin >> t[i];
    sort(t,t+n);
    long long res = 0;
    for(int i = 0; i < n-1; i++){
      res += t[i];
      t[i+1] += t[i];
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b+a); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

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

  string n;
  cin >> n;

  if (n.find('7') == string::npos) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}


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


using namespace std;

#define ll long long
int gcd(int a,int b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}

int main(){
    ll a,b;
    cin>>a>>b;
    ll g1=gcd(a,b);
    ll ans=(a*b)/g1;
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0] << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
int min(int a, int b){
    if(a<b){
        return a;
    }
    else{
        return b;
    }
}
int main(){
    ll N, K;
    ll ans;
    cin >> N >> K;
    ans = min(N%K, abs(N%K - K));
    cout << ans << endl;
    return 0;
       
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

N = int(input())
A = [deque(map(lambda x: int(x)-1, input().split())) for _ in range(N)]
ans = 0
used_prev = set(range(N))
while any(A):
    used = set()
    for i in used_prev:
        if not A[i] or i in used:
            continue
        j = A[i][0]
        if j in used:
            continue
        if A[j][0] == i:
            used.add(i)
            used.add(j)
            A[i].popleft()
            A[j].popleft()
    if not used:
        ans = -1
        break
    used_prev = used
    ans += 1
print(ans)


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


int main() {
	int N;
	cin >> N;
	bool ans = false;
	for(int j = 0; j <= 25; j++){
		for(int k = 0; k <= 25; k++){
			if(4 * j + 7 * k == N){
				ans = true;
				break;
			}
		}
	}
	if(ans){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define mod 1000000007;

int main (void) {
	int n,m,i;
	cin >> n >> m;
	for(i=(m-m%n)/n;i>=1;i--){
		if(m%i==0) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define pir pair<int, int>
vector<pair<pir, pir>> ans;
int main() {
  int H, W;
  cin >> H >> W;
  int s[501][501];
  for (int i = 0; i <= 500; i++) {
    for (int k = 0; k <= 500; k++) {
      s[i][k] = 11;
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int k = 1; k <= W; k++) {
      cin >> s[i][k];
    }
  }
  //各行の右端に集める
  for (int i = 1; i <= H; i++) {
    for (int k = 1; k <= W - 1; k++) {
      if (s[i][k] % 2 == 1) {
        s[i][k]--;
        s[i][k + 1]++;
        ans.push_back({{i, k}, {i, k + 1}});
      }
    }
  }
  /*for(int i = 1;i <= H;i++){
    for(int k = 1;k <= W;k++){
      cout<<s[i][k]<<" ";
    }
    cout<<endl;
  }
  */

  //右下に集める
  for (int i = 1; i <= H - 1; i++) {
    if (s[i][W] % 2 == 1) {
      s[i][W]--;
      s[i + 1][W]++;
      ans.push_back({{i, W}, {i + 1, W}});
    }
  }
  cout << ans.size() << endl;
  for (auto p : ans) {
    cout << p.first.first << " " << p.first.second << " " << p.second.first << " " << p.second.second << endl;
  }
  return 0;
}


Measured memory_bytes: 5232
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

#define INF (1000000000)

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

#define L_MAX (100)

void solve_main()
{
	int n, x;
	int aiL[L_MAX];
	int nowPos = 0;
	int boundNum = 0;

	cin >> n >> x;

	REP(i, 0, n) {
		cin >> aiL[i];
	}

	REP(i, 1, n + 2) {
		boundNum++;
		nowPos += aiL[i - 1];
		if (nowPos > x) {
			break;
		}
	}

	cout << boundNum << endl;
}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
struct state{
  int bill,floor,jump;
  state(int b,int f,int j) : bill(b),floor(f),jump(j) {}
};
bool operator < (state s, state m){
  return s.jump > m.jump;
}
int main(void){
  int n;
  while(cin>>n,n){
    priority_queue<state> que;
    que.push(state(0,0,0));
    que.push(state(1,0,0));
    int memo[2][101];
    memset(memo,-1,sizeof(memo));
    int kabe[2][101];
    REP(i,n)cin>>kabe[0][i];
    REP(i,n)cin>>kabe[1][i];
    int ans = -1;
    while(!que.empty()){
      state s = que.top(); que.pop();
      if(memo[s.bill][s.floor]!=-1&&memo[s.bill][s.floor]<=s.jump) continue;
      memo[s.bill][s.floor] = s.jump;
      int k = kabe[s.bill][s.floor];
      if(k!=2&&s.floor == n-1){
        ans = s.jump;
        break;
      }
      if(k==1&&kabe[s.bill][s.floor+1]!=1) k=0;//ツづ債つオツつイツづ個暗ェツ氾板湘」
      if(k==1){
        que.push(state(s.bill,s.floor+1,s.jump));
      }else if(k==2){
        que.push(state(s.bill,s.floor-1,s.jump));
      }else{
        REP(dif,3){
          if(s.floor+dif<n){
            que.push(state((s.bill+1)%2, s.floor+dif, s.jump+1));
          }
        }
      }
    }
    if(ans==-1)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,*a=map(int,open(0).readlines());c,s=1,a[0]\n"
"while s!=2and c<n:c+=1;s=a[s-1]\n"
"print(c*(c<n)or-1)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 13680
fun main(args: Array<String>) {
    while (true) {
        val inStr = readLine() ?: return;
        val (n, x) = inStr.split(' ').map { e -> e.toInt() }

        if ((n == 0) && (x == 0)) {
            return
        }
        val t = countCombination(n, x)
        println(t)
    }
}

fun countCombination(n: Int, x: Int): Int{
    var t: Int = 0

    for (i1 in 1..(n - 2)) {
        for (i2 in (i1+1)..(n - 1)) {
            for (i3 in (i2+1)..n) {
                val sum = i1 + i2 + i3
                if (sum == x) {
                    ++t
                }
            }
        }
    }

    return t
}



Measured memory_bytes: 32852
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


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



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

	int a[30] = {};
	REP(i, str.size()) {
		a[str[i] - 'a']++;
	}


	int f = 0;
	REP(i, 26) {
		if (a[i] % 2 == 1) {
			f = 1;
		}
	}

	if (f == 1) {
		ANS("No")
	}
	else {
		ANS("Yes")
	}
	
	
	




	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <ctype.h>
using namespace std;

typedef long long ll;

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= b) cout << a << endl;
  else cout << a - 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int W, H, x, y, r;
	int f = 0;
	
	scanf("%d %d %d %d %d",&W, &H, &x, &y, &r);
	
	if(x - r < 0){
	    f = 1;
	}
	if(x + r > W){
	    f = 1;
	}
	if(y - r < 0){
	    f = 1;
	}
	if(y + r > H){
	    f = 1;
	}
	
	if(f == 0){
	    printf("Yes\n");
	}else{
	    printf("No\n");
	}
	
	return 0;
}



Measured memory_bytes: 2096
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(string N){
    ll cnt = 0;
    for(auto x:N){
        if(x == '2')
            cnt ++;
    }
    cout << cnt << endl;
}

int main(){
    string N;
    cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(1000000)

def comb(n, r, fact, revfact, mod):
    return (fact[n] * (revfact[n-r] * revfact[r]) % mod) % mod

def dfs(i, parent, DP, sNum, E, fact, revfact, mod):
    Ans = 1
    sonNode = 1
    S = []
    for e in E[i]:
        if e != parent:
            mult, sn = dfs(e, i, DP, sNum, E, fact, revfact, mod)
            S.append(sn)
            Ans *= mult
            Ans %= mod
            sonNode += sn
    stotal = sonNode - 1
    for s in S:
        Ans *= comb(stotal, s, fact, revfact, mod)
        Ans %= mod
        stotal -= s
    DP[i] = Ans
    sNum[i] = sonNode - 1
    return Ans, sonNode

def solve():
    input = sys.stdin.readline
    N = int(input())
    E = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        E[a-1].append(b-1)
        E[b-1].append(a-1)
    mod = 7 + 10 ** 9
    fact = [1] * (N + 1)
    for i in range(N): fact[i+1] = ((i + 1) * fact[i]) % mod
    revfact = [1] * (N + 1)
    revfact[N] = pow(fact[N], mod - 2, mod)
    for i in reversed(range(N)): revfact[i] = ((i + 1) * revfact[i + 1]) % mod

    DP = [1] * N
    sNum = [0] * N
    usNum = [0] * N
    dfs(0, 0, DP, sNum, E, fact, revfact, mod)
    q = deque()
    for e in E[0]: q.append((e, 0))
    while q:
        nn, parn = q.popleft()
        upperMult = DP[parn] * pow(comb(N-1, sNum[nn] + 1, fact, revfact, mod), mod - 2, mod)
        usNum[nn] = upperNum = sNum[parn] - sNum[nn] + usNum[parn]
        DP[nn] = (upperMult * comb(N-1, upperNum, fact, revfact, mod)) % mod
        for e in E[nn]:
            if e != parn: q.append((e, nn))
        
    print("\n".join(map(str, DP)))
      
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 92372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

ll pow_mod(ll n,ll p,ll m){
    ll res = 1;
    while(p>0){
        if(p%2==1) res = (res * n) % m;
        n = n * n % m;
        p /= 2;
    }
    return res;
}

ll modinv(ll a,ll mod){
    return pow_mod(a,mod-2,mod);
}

ll factrial_mod(ll n,ll a,ll mod){
    ll x=1,y=1;
    rep(i,a){
        x = (x*(n - i))%mod;
        y = (y*(i + 1))%mod;
    }
    return (x*modinv(y,mod))%mod;
}

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans=pow_mod(2,n,MOD);
    //cout << ans << endl;
    ans--;
    ans = ((ans - factrial_mod(n,a,MOD)) % MOD + MOD) % MOD;
    ans = ((ans - factrial_mod(n,b,MOD)) % MOD + MOD) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
void intsertionSort(int *a,int n);

int main(){
	int a[1000],n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",a+i);
	
	intsertionSort(a,n);
	
	//output
	for(i=0;i<n;i++){
		printf("%d",a[i]);
		if(i!=(n-1))
			printf(" ");
	}
	printf("\n");
	return 0;
}

void intsertionSort(int *a,int n){
	int i,j,k;
	int v;
	
	for(i=1;i<=n-1;i++){
		
		//output
		for(k=0;k<n;k++){
		printf("%d",a[k]);
		if(k!=(n-1))
			printf(" ");
		}
		printf("\n");
		
		//sort
		v=a[i];
		j=i-1;
		while((j>=0)&&(v<a[j])){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
	}
}

Measured memory_bytes: 608
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <math.h>
#include <iomanip>

namespace ABC168
{

  class C
  {
  public:
    C() = default;
    ~C() = default;


    void Run()
    {

      int A = 0; // hour
      int B = 0; // min
      int H = 0;
      int M = 0;
      std::cin >> A;
      std::cin >> B;
      std::cin >> H;
      std::cin >> M;

      double rad_A = (90 - (double)(H * 30) - ((double)M*30.0f / 60.0f))/180.0f * M_PI ;
      double rad_B = (double)(90 - M * 6) / 180.0f * M_PI;

      auto A_x = A * sin(rad_A);
      auto A_y = A * cos(rad_A);
      auto B_x = B * sin(rad_B);
      auto B_y = B * cos(rad_B);

      double answer = sqrt((A_x - B_x)*(A_x - B_x) + (A_y - B_y)*(A_y - B_y));

      std::cout << std::fixed << std::setprecision(15) << answer << std::endl;
    }
  };

}
int main()
{

  ABC168::C prob;
  prob.Run();

  return 0;
}



Measured memory_bytes: 3664
import sys
sys.setrecursionlimit(10**9)
from collections import deque

N = int(input())
A = [[] for i in range(N)]

for i in range(N-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  if i == 0:
    a = u
  A[u].append((v,w))
  A[v].append((u,w))

H = deque()
H.append(a)
visited = [-1]*(N)
visited[a] = 0

while H:
  x = H.popleft()
  for y, z in A[x]:
    if visited[y] == -1:
      visited[y] = (visited[x] + z%2)%2
      H.append(y)
for i in visited:
  print(i)

Measured memory_bytes: 39152
h, w, k = gets.chomp.split(' ').map(&:to_i)

c0 = h.times.map { nil }
h.times { |i| c0[i] = gets.chomp.chars }
c0t = c0.transpose

answer = 0
(0...(1 << h)).each do |hi|
  (0...(1 << w)).each do |wi|
    b = 0
    (0...h).each do |hj|
      (0...w).each do |wj|
        b += 1 if (hi & (1 << hj)) >> hj == 0 && (wi & (1 << wj)) >> wj == 0 && c0[hj][wj] == '#'
      end
    end
    answer += 1 if b == k
  end
end

puts answer

Measured memory_bytes: 14352
#include<iostream>
using namespace std;
int main(){
    int N,A,P,Q;
    cin >> N >> A;
    P = N / 500;
    Q = N - P * 500;
    if (A >= Q)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    return 0;
    
}

Measured memory_bytes: 3024
n = int(input())
a = list(map(int, input().split()))
color = {"grey":False, "brown":False, "green":False, "light_blue":False, "blue":False, "yellow":False, "orange":False, "red":False}
free = 0
def rate(n):
    global free
    if 1 <= n <= 399:
        color["grey"] = True
    elif 400 <= n <= 799:
        color["brown"] = True
    elif 800 <= n <= 1199:
        color["green"] = True
    elif 1200 <= n <= 1599:
        color["light_blue"] = True
    elif 1600 <= n <= 1999:
        color["blue"] = True
    elif 2000 <= n <= 2399:
        color["yellow"] = True
    elif 2400 <= n <= 2799:
        color["orange"] = True
    elif 2800 <= n <= 3199:
        color["red"] = True
    else:
        free += 1
for i in range(n):
    rate(a[i])
print(max(list(color.values()).count(True), 1), list(color.values()).count(True) + free)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>

signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0,a=0,b=0;
std::cin >> x;
std::vector<int> v(x);
rep(i,x){
  std::cin >> y;
  if(i==0)v[i]=y;
  else v[i]=v[i-1]+y;
}
rep(i,x){
  z = abs(v[x-1]-v[i]-v[i]);
  if(i==0)w=z;
  else if(w>z)w=z;
}
std::cout << w << '\n';
return 0;
}


Measured memory_bytes: 256
# include <stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
	long long int a,b,c,d;
	long long int x,y,z,t;
	long long int max;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	x = a*c;
	y = a*d;
	z = b*c;
	t = b*d;
	max = x;
	if(max<=y)
		max = y;
	if(max<=z)
		max = z;
	if(max <= t)
		max = t;
	printf("%lld",max);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

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

signed main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  ll count = B - A + 1;
  ll CD = lcm(C, D);
  ll countCmod = (count) / C;
  debug(count);

  ll amariC = count - countCmod * C;
  if (amariC >= C - (A % C) + 1) {
    countCmod++;
  }
  ll countDmod = (count) / D;
  ll amariD = count - countDmod * D;
  if (amariD >= D - (A % D) + 1) {
    countDmod++;
  }
  ll countCDmod = (count) / CD;
  ll amariCD = count - countCDmod * CD;
  if (amariCD >= CD - (A % CD) + 1) {
    countCDmod++;
  }

  debug(countCmod);
  debug(countDmod);
  debug(countCDmod);
  // 532105071133627368
  // 532105071133627369

  COUT(count - countCmod - countDmod + countCDmod);

  return 0;
}

Measured memory_bytes: 256
//@author rohit_0801
// help source : https://www.geeksforgeeks.org/given-an-array-arr-find-the-maximum-j-i-such-that-arrj-arri/

 
#include <bits/stdc++.h>
#define ll int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug 0
 
using namespace std;
const ll MOD = 1000000007;
const ll MODD = MOD-1;
 
ll ar[900780], left_max[448390], right_min[123456],br[1234567];
ll dp[505][505], mat[505][505];

vector<ll> vec,pec;

void go(int n, int k)
{
    for (int i=0; i<=n; i++)
        for (int j=0;j<=k;j++)
            dp[i][j] = 0;
 
    dp[0][0] = 0;
 

    for (int i=1;i<=n;i++)
		for (int j=1;j<=k;j++)
 			for (int m=i-1;m>=0;m--)
                dp[i][j] = max(dp[i][j], mat[i-1][m]);
 
 
}

ll solve(ll n)
{
    ll ans;
 
   	left_max[1] = ar[1];
    for (int i = 2; i <=n; i++){
    	left_max[i]=max(left_max[i-1],ar[i]);
	}
 
    right_min[n] = ar[n];
    for (int i = n-1; i>=1; i--){
    	right_min[i] = min(right_min[i+1],ar[i]);
	}
	

    ll i ,j;
	ans = 0;
	i=j=n;
    while (j>=1 && i>=1)
    {
        if (left_max[j] >= right_min[i])
        {
            ans = max(ans, i-j+1);
            j--;
        }
        else
            i--;
    }
 
    return ans;
}
 
 
int main() {
	//srand(time(0));
	ll a,b,n,m,flag=0,r,t,u,v,w,x,y,z,k,res=0,d,maxm=-999999999,i,j,ct,h,ans=0,s,l,e,f,p,minm=999999999,c,type,q,len,siz;
 	
 	set<ll>::iterator it,jt;
 	
 	string str="",ptr="";
 	char ch;
 	
 	cin>>a>>b;
 	
 	d=a*b;
 	p=a+b;
 	ans=d-p+1;
 	
 	cout<<ans;
 	
	
	return 0;
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
    string s;
    cin >> s;
    int arr[26];
    memset(arr, 0, sizeof(arr));
    for(int i=0; i < (int)s.size(); i++){
        if(s[i] >= 'a' && s[i] <= 'z'){
            arr[s[i] - 'a']+=1;
        }
    }
    int flag = 0;
    for(int i=0; i<26; i++){
        if(arr[i] % 2 == 1) flag = 1;
    }
    if(flag) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

ll f(ll n)
{
    return (n & 1 ? 3 * n + 1 : n / 2);
}
int main()
{
    int s;
    cin >> s;
    vector<ll> a;
    a.push_back(s);
    ll ans = 1;
    bool flag = true;
    while (flag)
    {
        ans++;
        a.push_back(f(a.back()));
        repi(j, a.size(), 0)
        {

            repi(i, a.size(), j + 1)
            {
                if (a[j] == a[i])
                {
                    flag = false;
                    break;
                }
            }
            if (!flag)
                break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  bool ok = true;
  rep(i,n) {
    if (a[i]%2 == 1) continue;
    if (a[i]%3 != 0 && a[i]%5 != 0) ok = false;
  }
  if (ok) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int w,n,i,l[31];
  scanf("%d%d",&w,&n);
  for(i=1;i<=w;i++) l[i]=i;
  for(i=0;i<n;i++) {
    int a,b,t;
    scanf("%d,%d",&a,&b);
    t=l[a];l[a]=l[b];l[b]=t;
  }
  for(i=1;i<=w;i++) printf("%d\n",l[i]);
  return 0;
}

Measured memory_bytes: 596
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()

tail = [item for i,item in enumerate(A) if i%2 == 0]
head = [item for i,item in enumerate(A) if i%2 == 1]
ans = head[::-1]+tail if n%2 == 0 else tail[::-1]+head
print(*ans)

Measured memory_bytes: 25632
#include<iostream>
#include<queue>
#include<vector>
#include<string>
using namespace std;

int main(){
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    vector<string> ans;
    int dx=gx-sx;
    int dy=gy-sy;
    for(int i=0;i<abs(dy);i++){
        ans.push_back("U");
    }
    for(int i=0;i<abs(dx);i++){
        ans.push_back("R");
    }
    int N=ans.size();
    for(int i=0;i<N;i++){
        if(ans[i]=="U"){
            ans.push_back("D");
        }else if(ans[i]=="D"){
            ans.push_back("U");
        }else if(ans[i]=="R"){
            ans.push_back("L");
        }else{
            ans.push_back("R");
        }
    }
    vector<string> ans2;
    ans2.push_back("L");
    for(int i=0;i<=abs(dy);i++){
        ans2.push_back("U");
    }
    for(int i=0;i<=abs(dx);i++){
        ans2.push_back("R");
    }
    ans2.push_back("D");
    int N2=ans2.size();
    for(int i=0;i<N2;i++){
        if(ans2[i]=="U"){
            ans2.push_back("D");
        }else if(ans2[i]=="D"){
            ans2.push_back("U");
        }else if(ans2[i]=="R"){
            ans2.push_back("L");
        }else{
            ans2.push_back("R");
        }
    }
    for(int i=0;i<ans.size();i++){
        cout << ans[i];
    }
    for(int i=0;i<ans2.size();i++){
        cout << ans2[i];
    }

}

Measured memory_bytes: 1152