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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiil;
typedef pair<pll, ll> pplll;
typedef pair<pli, int> pplii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<pll>> vvpll;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define pb push_back
#define tostr to_string
#define mkp make_pair
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

void print(ld out) { cout << fixed << setprecision(12) << out << '\n'; }
template<typename T> void print(T out) { cout << out << '\n'; }
template<typename T1, typename T2> void print(pair<T1, T2> out) { cout << out.first << ' ' << out.second << '\n'; }
template<typename T> void print(vector<T> A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } }
template<typename T> void print(set<T> S) { vector<T> A(S.begin(), S.end()); print(A); }

template<typename T> inline bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; }
template<typename T> inline bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; }

ll sum(vector<ll> A) { ll res = 0; for (ll a: A) res += a; return res; }
ll max(vector<ll> A) { ll res = -INF; for (ll a: A) chmax(res, a); return res; }
ll min(vector<ll> A) { ll res = INF; for (ll a: A) chmin(res, a); return res; }

ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; }
int toint(char c) { return c - '0'; }
char tochar(int i) { return '0' + i; }

inline ll pow(int x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; }
inline ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; }

inline ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } }
inline ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } }

int popcount(ll S) { return __builtin_popcountll(S); }
ll gcd(ll a, ll b) { return __gcd(a, b); }

ll N;
vector<ll> A, L, ans;
vvl nodes;

void dfs(ll u, ll prev) {

    // LISの構築
    bool inc = false;
    ll tmp, idx;
    if (A[u] > L.back()) {
        L.pb(A[u]);
        inc = true;
    } else {
        idx = lower_bound(L.begin(), L.end(), A[u]) - L.begin();
        tmp = L[idx];
        L[idx] = A[u];
    }
    ans[u] = L.size();

    for (auto v : nodes[u]) {
        if (v == prev) continue;
        dfs(v, u);
    }

    // LISの状態を元に戻す
    if (inc) {
        L.pop_back();
    } else {
        L[idx] = tmp;
    }
    return;
}

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

    cin >> N;
    A.resize(N);
    nodes.resize(N);
    ans.resize(N);
    rep(i, 0, N) cin >> A[i];
    ll a, b;
    rep(i, 0, N-1) {
        cin >> a >> b;
        a--; b--;
        nodes[a].pb(b);
        nodes[b].pb(a);
    }

    L.pb(A[0]);
    dfs(0, -1);

    for (ll a : ans) {
        print(a);
    }
    return 0;
}


Measured memory_bytes: 31556
#include<bits/stdc++.h>
using namespace std;
const int M=998244353;
const int N=200005,E=524288;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
long long qpow(long long a,long long b)
{
	long long ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%M;
		a=a*a%M;
		b>>=1;
	}
	return ans;
}
void FWT(long long *a,int n,int f)
{
	int i,j;
	int T=(1<<n);
	for(i=0;i<n;++i)
		for(j=0;j<T;++j)
			if((j>>i)&1)
			{
				long long u=a[j^(1<<i)],v=a[j];
				a[j^(1<<i)]=u+v;
				a[j]=u-v;
			}
	for(i=0;i<T;++i)
		a[i]%=M;
	if(f==-1)
	{
		long long inv=qpow(T,M-2);
		for(i=0;i<T;++i)
			a[i]=a[i]*inv%M;
	}
}
long long a[E],b[E],s;
int n,i,T;
int main()
{
	scanf("%d",&n);
	T=1<<n;
	for(i=0;i<T;++i)
	{
		scanf("%lld",&a[i]);
		s+=a[i];
	}
	s=qpow(s,M-2);
	for(i=0;i<T;++i)
		a[i]=a[i]*s%M;
	--a[0];
	b[0]=qpow(2,n)-1;
	for(i=1;i<T;++i)
		b[i]=-1;
	FWT(a,n,1);
	FWT(b,n,1);
	for(i=0;i<T;++i)
		a[i]=qpow(a[i],M-2)*b[i]%M;
	FWT(a,n,-1);
	for(i=0;i<T;++i)
		printf("%lld\n",((a[i]-a[0])%M+M)%M);
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }
    int count = 0;
    while(true){
        bool ok = true;
        rep(i, N){
            if (A[i] % 2 != 0){
                ok = false;
                break;
            }
            A[i] = A[i] / 2;
        }
        if (!ok){
            break;
        }
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
include Math

if __FILE__==$0
	inf=Float::INFINITY
	readln_i=lambda{|dl|gets.chomp.split(dl).map(&:to_i)}
	read_i=lambda{gets.chomp.to_i}
	readln_s=lambda{|dl|fp.gets.chomp.split(dl)}
	read_s=lambda{fp.gets.chomp}
	
	n=read_i[]
	num=readln_i[" "]
	z=Array.new(100002){0}
	
	for x in num
		z[x-1]+=1
		z[x]+=1
		z[x+1]+=1
	end
	
	z.sort!
	
	p z.last
end

Measured memory_bytes: 12288
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
    ll N;
    string S;
    cin>>N>>S;
    vector<ll> trans;
    ll kuro_num[200000],shiro_num[200000];
    kuro_num[0]=0;
    shiro_num[0]=0;
    rep(i,N){
        if(i==0 && S[i]=='.') shiro_num[i]=1;
        else if(i==0 && S[i]=='#') kuro_num[i]=1;
        else if(S[i]=='.'){
            shiro_num[i]=shiro_num[i-1]+1;
            kuro_num[i]=kuro_num[i-1];
        }else{
            shiro_num[i]=shiro_num[i-1];
            kuro_num[i]=kuro_num[i-1]+1;
        }
    }
    ll ans=N,pos;
    rep(i,N){
        ans=min(ans,kuro_num[i]+shiro_num[N-1]-shiro_num[i]);
    }
    ans=min(ans,shiro_num[N-1]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3716
N,P=map(int,input().split())
D=dict()
k=2
Q=P
while(True):
    if k*k>P:
        break
    if Q%k==0:
        if k in D:
            D[k]+=1
        else:
            D[k]=1
        Q=Q//k
    else:
        k+=1
if Q in D:
    D[Q]+=1
else:
    D[Q]=1
ans=1
for p in D:
    ans=ans*(p**(D[p]//N))
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200000 + 10;
struct point{
    ll x,y;
    point(){}
    point(ll x,ll y):x(x),y(y){}
    point operator - (point p){
        return point(x-p.x,y-p.y);
    }
};
ll det(point a,point b){
    return a.x * b.y - a.y * b.x;
}
ll a[N],b[N],c[N];
point var[N];
int main(){
    int n; scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    for(int i=0;i<n;i++) scanf("%lld",&b[i]);
    int pos = max_element(a,a+n)-a;
    rotate(a,a+pos,a+n);
    rotate(b,b+pos,b+n);
    c[0] = c[1] = 1;
    for(int i=1;i<n;i++) c[i+1] = 2*c[i]+2*b[i]-c[i-1];
    vector<point> v; int r = 0;
    for(int i=0;i<=n;i++){
        point p(i,a[i%n]-c[i]);
        while(r>=2&&det(v[r-1]-v[r-2],p-v[r-1])>=0) v.pop_back(), r--;
        v.push_back(p), r++;
    }
    ll ans = 0;
    for(int i=1;i<(int)v.size();i++){
        ans += (v[i-1].y+v[i].y)*(v[i].x-v[i-1].x+1);
        ans -= 2*v[i].y;
    }
    for(int i=0;i<n;i++) ans += 2*c[i];
    printf("%.12f\n",0.5*ans/n);
}


Measured memory_bytes: 12132
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;
vector<int> g[200002];
ll dp[200002];
int sz[200002];
ll ans[200002];
ll f1[200002], f2[200002];
ll pow2(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b%2 == 1) ans = ans*a%mod;
        a = a*a%mod;
        b/=2;
    }
    return ans;
}
ll ncr(int a, int b){
    return f1[a]*f2[b]%mod*f2[a-b]%mod;
}
void dfs1(int u, int p){
    sz[u] = 1;
    dp[u] = 1;
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs1(v, u);
        sz[u] += sz[v];
        dp[u] = dp[u]*dp[v]%mod;
        dp[u] = dp[u]*f2[sz[v]]%mod;
    }
    dp[u] = dp[u]*f1[sz[u]-1]%mod;
}
int n;
void dfs2(int u, int p, int sz2, ll pv){
    ll res = pv, comb = f2[sz2];
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        if(v == p) continue;
        res = res*dp[v]%mod;
        comb = comb*f2[sz[v]]%mod;
        sz2 += sz[v];
    }
    ans[u] = res*f1[n-1]%mod*comb%mod;
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs2(v, u, sz2-sz[v]+1, res*pow2(dp[v], mod-2)%mod*f1[sz2-sz[v]]%mod*comb%mod*pow2(f2[sz[v]], mod-2)%mod);
    }
}
int main(){
    f1[0] = f2[0] = 1;
    for(int i=1;i<=200000;i++) f1[i] = f1[i-1]*i%mod, f2[i] = pow2(f1[i], mod-2);
    scanf("%d", &n);
    for(int i=1;i<=n-1;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    dfs1(1, 0);
    dfs2(1, 0, 0, 1);
    for(int i=1;i<=n;i++){
        printf("%lld\n", ans[i]);
    }
}

Measured memory_bytes: 20980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> towns(n);
    rep(i,n){
        cin >> towns[i].first >> towns[i].second;
    }
    double sum = 0.0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            int xdif = abs(towns[i].first - towns[j].first);
            int ydif = abs(towns[i].second - towns[j].second);
            sum += sqrt(xdif*xdif + ydif*ydif);
            ///cout << sum << endl;
        }
    }
    printf("%.6f\n", sum/n);
}


Measured memory_bytes: 256
#include <stdio.h>

int max3(int x, int y, int z)

{

    int max = x;
    if (y >= max) max = y;

    if (z >= max) max = z;

    return max;

}
int min3(int x, int y, int z)

{

    int min = x;
    if (y <= min) min = y;

    if (z <= min) min = z;

    return min;

}

int main(void){
    int NUM[1000];
    int i,n,m;


    //スキャン
    for(i = 0; i<3; i=i+1){
        scanf("%d",&NUM[i]);
    }
    n = max3(NUM[0],NUM[1],NUM[2]);
    m = min3(NUM[0],NUM[1],NUM[2]);


printf("%d",n-m);

    return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N, M;

struct UnionFind {
  vector< int > par;
  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n) {
    par.resize(n);
    for(int i = 0; i < n; i++)
      par[i] = -1;
  }
  
  int root(int n) {
    if (par[n] < 0) return n;
    return par[n] = root(par[n]);
  }

  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;

    return true;
  }
};

ll cnt[MAX_N];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> N >> M;
  vector< int > p(N);
  REP(i, N) {
    cin >> p[i];
    p[i]--;
  }

  UnionFind uf(N);

  fill_n(cnt, MAX_N, -INF);
  ll tmp = 0ll;
  REP(i, M) {
    CIN(x, y);
    x--; y--;
    uf.unite(x, y);
  }

  ll ans = 0ll;

  REP(i, N) {
    if (uf.root(i) == uf.root(p[i]))
      ans++;
  }
  
  cout << ans << endl;

  /*
  REP(i, N + 1) {
    debug(cnt[i]);
  }
  */

  return 0;
}



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

int N,M;

int dfs(int i, int cnt,
    bitset<500> cur, vector<bitset<500>> &bs){
    if(N == i) return cur.count() == 0 ? cnt : 0;
    return max(dfs(i+1,cnt,cur,bs), dfs(i+1,cnt+1,cur^bs[i],bs));
}

int main(void){
    while(cin>>N>>M, N|M){
        vector<bitset<500>> bs(N);
        rep(i,N) cin>>bs[i];
        if(N <= 23){
            cout<<dfs(0,0,bitset<500>(""),bs)<<endl;
        }else{
            vector<int> cur(1<<M),nxt(1<<M);
            rep(i,N){
                int bit = bs[i].to_ullong();
                nxt[bit] = max(cur[bit],cur[0]+1);
                rep(mask,1<<M)if(cur[mask]){
                    nxt[bit^mask] = max(nxt[bit^mask],cur[mask]+1);
                }
                cur = nxt;
            }
            cout<<cur[0]<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 11280
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nFlowers := scanInt(sc)

	heights := make([]int, nFlowers+1)
	max := 0
	for i := 0; i < nFlowers; i++ {
		heights[i] = scanInt(sc)
		if heights[i] > max {
			max = heights[i]
		}
	}
	heights[nFlowers] = 0

	total := 0
	for min := 0; min < max; min++ {
		cnt := 0
		seq := false
		for _, h := range heights {
			if h <= min {
				if seq {
					cnt += 1
					seq = false
				}
			} else {
				seq = true
			}
		}
		total += cnt
	}

	fmt.Println(total)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


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

int main()
{
    char s[100001];
    cin >> s;
    int length=strlen(s);
    char ans[10];
    if(s[0]==s[length-1]){//最初と最後が同じ時は奇数長で終わる
        if(length%2==0){
            strcpy(ans, "First");
        }else{
            strcpy(ans, "Second");
        }
    }else{//異なる時偶数長で終わる
        if(length%2==0){
            strcpy(ans, "Second");
        }else{
            strcpy(ans, "First");
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

ll c[1000000];

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

  ll n, a;
  cin >> n;
  REP(i, n - 1) {
    cin >> a;
    c[a - 1]++;
  }
  REP(i, n) cout << c[i] << endl;

  return 0;
}

Measured memory_bytes: 5212
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

	int N;
	cin >> N;
	LL ret = 0;
	LL pre = 0, cur = 0;
	REP(i, N){
		cin >> cur;
		ret += min(pre, cur);
		cur -= min(pre, cur);
		ret += cur / 2;
		pre = cur % 2;
	}

	cout << ret << endl;

	return 0;
}


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

int tmp[1000010] = {};
int main(){
  int s;
  cin >> s;

  int ans = 1;
  while(tmp[s] == 0){
    ans++;
    tmp[s] = 1;
    if(s % 2 == 0){
      s /= 2;
    }else{
      s = s*3+1;
    }
  }

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


Measured memory_bytes: 256
N, M = map(int,input().split())
G = [[0]*N for _ in range(N)]
edge = []
for i in range(M) :
    a, b = map(int,input().split())
    edge.append([a-1, b-1])
    G[a-1][b-1] = G[b-1][a-1] = 1

visited = [0]*N
visited[0] = 1

def dfs(n) :
    ans = 0
    if min(visited) == 1 :
        return 1
    for i in range(N) :
        if G[n][i] == 1 and visited[i] == 0 :
            visited[i] = 1
            ans += dfs(i)
            visited[i] = 0
    return ans

print(dfs(0))


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int a, b;
    double f;
    cin >> a >> b;
    f = (double)a / b;
    cout << a / b << " " << a % b << " ";
    cout << fixed << setprecision(5) << f << endl;
    return 0;
}


Measured memory_bytes: 3244
#include <iostream>

int main(int argc, const char * argv[]) {
    
    int c = 0;
    
    while( 1 ) {
        c ++ ;
        int n ;
        std::cin >> n ;
        if ( n==0 ) break ;
        std::cout << "Case " << c << ": " << n << "\n" ;
    }
    
    return 0;
}



Measured memory_bytes: 3068
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i32 h, w, k;
bool a[800][800];
i32 sx, sy;
i32 ox[4] = { -1, 0, 1, 0 };
i32 oy[4] = { 0, -1, 0, 1 };
vec<pair<i32, i32>> v;

i32 solve(i32 tx, i32 ty) {
    i32 ans = INT_MAX;
    times(v.size(), i) {
        if (v[i].first == 0 || v[i].first == h - 1 || v[i].second == 0 || v[i].second == w - 1) {
            ans = 0;
            break;
        }
        i32 d = abs(v[i].second - tx) + abs(v[i].first - ty);
        if ((d % k) == 0) {
            ans = min(ans, d / k);
        }
        else {
            ans = min(ans, d / k + 1);
        }
    }
    return ans + 1;
}

i32 main()
{
    cin >> h >> w >> k;
    times(h, i) {
        str s; cin >> s;
        times(w, j) {
            a[i][j] = s[j] != '#';
            if (s[j] == 'S') {
                sx = j;
                sy = i;
            }
        }
    }
    bool fp[800][800] = {};
    set<tuple<i32, i32, i32>> s;
    s.insert(make_tuple(0, sy, sx));
    while (s.size() > 0) {
        i32 d, y, x;
        tie(d, y, x) = *s.begin();
        s.erase(s.begin());
        if (fp[y][x]) {
            continue;
        }
        v.append(make_pair(y, x));
        fp[y][x] = true;
        if (d >= k) {
            continue;
        }
        times(4, i) {
            i32 nx, ny;
            nx = x + ox[i];
            ny = y + oy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h) {
                if (a[ny][nx] && !fp[ny][nx]) {
                    s.insert(make_tuple(d + 1, ny, nx));
                }
            }
        }
    }

    i32 ans = INT_MAX;
    range(0, w - 1, i) {
        ans = min(ans, solve(i, 0));
        ans = min(ans, solve(i, h-1));
    }
    range(0, h - 1, i) {
        ans = min(ans, solve(0, i));
        ans = min(ans, solve(w - 1, i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10884
#include<stdio.h>

int main(){
	char s[11];
	scanf("%s",s);
	
	if(s[0]!='A'||s[1]<'a') {
		printf("WA");	return 0;
	}
	
	int i,c=0,end=0;
	for(i=2;i<10&&s[i]!='\0'&&end==0;i++) {
		if(s[i]=='C'){
			if(c==0) c++;
			else {
				printf("WA");	return 0;
			}
		} else if(s[i]=='\0') end=1;
		else if(s[i]<'a'){
			printf("WA");	return 0;
		}
	}
	
	if(s[i-1]=='C') c=c-1;
	if(c<1) printf("WA");
	else printf("AC");
	
	return 0;
}

Measured memory_bytes: 128
import copy

def warshall_floyd(d,n):
    D = copy.deepcopy(d) 
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if i == k  or k == j:
                    continue
                if d[i][k] + d[k][j] < d[i][j]:
                    return -1 
                elif d[i][k] + d[k][j] == d[i][j]:
                    D[i][j] = 0
    ans = sum([sum(i) for i in D])
    assert not (ans % 2)
    return ans // 2
  
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
ans = warshall_floyd(a,n)
print(ans)

Measured memory_bytes: 55004
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;
ll n,k;
vl a,b;
signed main() {
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>k;
        a.push_back(k);
        b.push_back(k);
    }
    sort(all(a));
    for(int i=0;i<n;i++){
        ll point=lower_bound(all(a),b.at(i))-a.begin();
        (point+1<=(n/2))?cout<<a.at(n/2)<<endl:cout<<a.at(n/2-1)<<endl;
    }
}

Measured memory_bytes: 6756
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  map<int64_t,int64_t>M;
  int64_t sum=0;
  for(int i=0;i<N;i++){
  int64_t a; cin>>a; sum+=a;
    if(!M.count(a))
      M[a]=1;
    else
      M.at(a)++;
  }
    
  int Q; cin>>Q;
  vector<int64_t>B(Q);
  vector<int64_t>C(Q);
  for(int i=0;i<Q;i++){
  int64_t b,c; cin>>b>>c;
    B.at(i)=b; C.at(i)=c;
  }for(int i=0;i<Q;i++){
  if(!M.count(B.at(i)))
    cout<<sum<<endl;
    else{
    int64_t c=M.at(B.at(i));
      sum+=(C.at(i)-B.at(i))*c;
      M.erase(B.at(i));
      if(!M.count(C.at(i)))
        M[C.at(i)]=c;
      else
        M.at(C.at(i))+=c;
      cout<<sum<<endl;
    
    }
  
  
  }
  
  return 0;
}

Measured memory_bytes: 8748
#include <stdio.h>
#include<math.h>
int main(void) {
double a,b,c,d;
double e;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
e=(a-c)*(a-c)+(b-d)*(b-d);
e=sqrt(e);
printf("%f",e);
  return 0;
}

Measured memory_bytes: 652
n=input()
a=int(n[0]+n[1])
b=int(n[2]+n[3])
if 1 <= a <= 12 and 1 <= b <= 12:
  print("AMBIGUOUS")
elif 1 <= a <= 12:
  print("MMYY")
elif 1 <= b <= 12:
  print("YYMM")
else:
  print("NA")

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

int main()
{
  int N, sum;
  cin >> N;
  vector<int> p(N);
  for(int i = 0; i < N; i++)
    cin >> p.at(i);
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sum = 0;
  p.at(0) /= 2;
  for(int i = 0; i < N; i++)
    sum += p.at(i);
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N, M;
    cin >> N;
    int H[N];
    for (int i=0;i<N;i++)
        cin >> H[i];

    M = H[0]-1;
    for (int i=1;i<N;i++){
        if (M < H[i])
            M = H[i] - 1;
        else if ( M > H[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val H = readLine()!!.split(" ").map(String::toInt)
    var old = 0
    var max = 0
    var now = 0
    for (h in H) {
        if (old < h) {
            now = 0
        } else {
            now += 1
        }
        if (max < now) max = now
        old = h
    }
    println(max)
}

Measured memory_bytes: 59788
#include<bits/stdc++.h>
#define WHITE 0
#define GREY 1
#define BLACK 2
using namespace std;
int depth[500500];
vector<int> G[500500];
int color[500500];
int Ans;
int low[500500];
void dfs(int x,int last)
{
	color[x]=GREY;
	if(last!=-1)
		depth[x]=depth[last]+1;
	low[x]=depth[x];
	for(int i=0;i<(G[x].size());i++)
		if(G[x][i]!=last)
			if(color[G[x][i]]==WHITE)
			{
				dfs(G[x][i],x);
				low[x]=min(low[x],low[G[x][i]]);
			}
			else	low[x]=min(low[x],depth[G[x][i]]);
	if(low[x]==depth[x])
		Ans++;
	color[x]=BLACK;
}
int main()
{
	int N,K;
	cin>>N>>K;
	while(K--) 
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(0,-1);
	cout<<Ans-1<<endl;
	return 0;
}

Measured memory_bytes: 15324
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let s = get!(usize);
    let mae = s/100;
    let usiro = s%100;

    if (mae > 0 && mae <= 12) && (usiro > 0 && usiro <= 12) {
        println!("AMBIGUOUS");
    } else if mae > 0 && mae <= 12 {
        println!("MMYY");
    } else if usiro > 0 && usiro <= 12 {
        println!("YYMM");
    } else {
        println!("NA");
    }
}


Measured memory_bytes: 8572
input()
a = list(map(int, input().split()))
for i in range(min(a),max(a)+1):
    cost_min = 0 if i == min(a) else cost_min
    cost = 0
    for e in a:
        add_cost = abs((e - i)) ** 2
        cost_min += add_cost if i == min(a) else 0
        cost += add_cost if i != min(a) else 0
    if not i == min(a) and cost_min > cost:
        cost_min = cost
print(cost_min)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main(){
    int i,n,h,sum=0;
    int *a;
    
    scanf("%d %d",&h,&n);
    
    a=(int *)malloc(sizeof(int) * n);
    
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    for(i=0;i<n;i++){
        sum=sum+a[i];
    }
    
    if(sum>=h){
        printf("Yes\n");
    }
    
    else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define int long long
// #define int long long
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << endl;
}
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...);
}

int32_t main()
{
    int n, k;
    cin >> n >> k;
    vector<int> arr(n), dp(n + 1, INT_MAX);
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int d = 1; d <= k; d++)
        {
            if (i - d >= 0)
            {
                dp[i] = min(dp[i], dp[i - d] + abs(arr[i] - arr[i - d]));
            }
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    ll r, D, x0;
    cin >> r >> D >> x0;
    ll tmp=x0;
    for(int i=0; i<10; i++){
        tmp=r*tmp-D;
        cout << tmp << endl;
    }

    return 0;
}

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

int main()
{
  int n, m; cin >> n >> m;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vector<ll> c(m);
  vector<ll> d(m);
  rep(i, m) cin >> c[i] >> d[i];

  vector<int> ans(n);
  rep(i, n) {
    ll tmp = 1LL<<60;
    rep(j, m) {
      ll t = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if (tmp > t) {
        tmp = t;
        ans[i] = j+1;
      }
    }
  }
  for (auto v:ans) cout << v << endl;

  return 0;
}


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

namespace ConsoleApp1
{
    static class CRally
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var x = Console.ReadLine().Split(' ').ToList();

            var xList = new List<int>();
            x.ForEach(a => xList.Add(int.Parse(a)));

            var ansList = new List<int>();
            for (int p = 1; p <= 100; p++)
            {
                int sum = 0;
                xList.ForEach(a => sum += (int)Math.Pow(a - p, 2));
                ansList.Add(sum);
            }

            Console.WriteLine(ansList.Min());
            Console.ReadLine();
        }
    }
}

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

int main(void){
    int n, m;
    cin >> n >> m;

    vector<pair<ll, int>> shop;
    rep(i, n){
        ll tmp1;
        int tmp2;
        cin >> tmp1 >> tmp2;
        shop.push_back({tmp1, tmp2});
    }

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

    int num = 0;
    ll cost = 0;
    rep(i, n){
        if(shop[i].second >=  m - num){
            cost += (m - num) * shop[i].first;
            cout << cost << endl;
            return 0;
        }else{
            cost += shop[i].first * shop[i].second;
            num += shop[i].second;
        }
    }
}


Measured memory_bytes: 2420
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <regex>
#include <sstream>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

int main() {
    ios::sync_with_stdio(false);
    string t;
    cin >> t;

    for (int i = 0; i < t.size(); i++) {
        if (t[i] == '?')
            t[i] = 'D';
    }

    cout << t << endl;

    return 0;
}


Measured memory_bytes: 3340
#include<iostream>
#include<cstdio>
using namespace std;

int main() {
    int H, W;
    while (true) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;

        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (h == 0 || h == H -1) {
                    printf("#");
                } else if (w == 0 || w == W -1) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }

        printf("\n");
    }
}

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

namespace Atc_0035
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            int r = 0;

            for (int i = 0; i < s.Length; i++)
            {
                r += int.Parse(s.Substring(i, 1));
            }

            if (int.Parse(s) % r == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


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

int N; vector<int> A;
void input()
{
    cin >> N;
    A.resize(N+2);
    A[0] = A[N+1] = 0;
    for (int i = 0; i < N; ++i) cin >> A[i+1];
}

void solve()
{
    int cost = 0;
    for (int i = 0; i < N+1; ++i){
        cost += abs(A[i+1] - A[i]);
    }
    for (int i = 1; i <= N; ++i){
        cout << cost - abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i+1]-A[i-1]) << endl;
    }
}

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

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

int main()
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int Much=a+b;
  if(Much>=c)
    printf("Yes\n");
  else 
    printf("No\n");
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def k_cut(k, nums):
    return nums[k:] + nums[:k]

def riffle_shuffle(n, nums):
    return [nums[i//2 + n*(i%2)] for i in range(2*n)]

n = int(input())
nums = [i + 1 for i in range(2*n)]

m = int(input())
for i in range(m):
    k = int(input())
    if k == 0:
        nums = riffle_shuffle(n, nums)
    else:
        nums = k_cut(k, nums)

for num in nums:
    print(num)

Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,m;
  cin >> n >> m;
  vector<bool> st(n+1,1);
  vector<ll> dp(n+1,0);
  rep(i,m){
    int a;
    cin >> a;
    st[a] = 0;
  }
  dp[0] = 1;
  dp[1] = 1;
  for(int i=2;i<=n;i++){
    dp[i] = dp[i-2]*st[i-2] + dp[i-1]*st[i-1];
    dp[i] %= 1000000007;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    string str;
    cin >> n >> k >> str;
    vector<ll> ary;

    char prev = 0xff;
    if (str[0] == '0') {
        ary.push_back(0);
        prev = '1';
    }
    for (ll i = 0; (i < n); i++) {
        char curr = str[i];
        if (prev != curr) {
            prev = curr;
            ary.push_back(1);
        } else {
            ary[ary.size()-1]++;
        }
    }
    if (str[n-1] == '0') ary.push_back(0);

    vector<ll> sum(ary.size()+1, 0);
    for (ll i = 0; (i < ary.size()); ++i) {
        sum[i+1] = sum[i] + ary[i];
    }

    ll maxv = 0;
    for(ll i = 0; (i < ary.size()); i+=2) {
        ll left = i;
        ll right = min((ll)(sum.size()-1), i+k*2+1);
        maxv = max(maxv, sum[right] - sum[left]);
    }
    cout << maxv << endl;
    return 0;
}


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

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<pair<pair<string, int>, int>> p(N);
    string S;
    int P;
    for (int i = 0; i < N; i++) {
        cin >> S >> P;
        p[i] = make_pair(make_pair(S, -P), i+1);
    }
    sort(p.begin(), p.end());
    for (int i = 0; i < N; i++) {
        cout << p[i].second << endl;
    }
}

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

Measured memory_bytes: 3644
N = int(input())
c = [[0 for _ in range(10)] for _ in range(10)]

for n in range(1, N+1):
    i, j = int(str(n)[0]), int(str(n)[-1])
    if i == 0:
        continue
    c[i][j] += 1
    
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j]*c[j][i]
        
print(ans)

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

void solve(){
	
	int d,t,s ;	
	cin>>d>>t>>s ;

	if(s*t>=d)
		cout<<"Yes" ;
	else
		cout<<"No" ;
}	

int main(){


	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 3592
import sys
# sys.setrecursionlimit(100000)
from collections import deque
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    # 各ノードで幅優先探索を行う
    # 計算量(O(n^2))
    n, x, y = input_int_list()
    g = defaultdict(list)
    g[x].append(y)
    g[y].append(x)
    for i in range(1, n):
        g[i].append(i + 1)
        g[i + 1].append(i)
    ans = [0] * (n + 1)
    for i in range(1, n + 1):
        # 幅優先探索
        seen = set()
        dq = deque()
        dq.append((i, 0))  # node,depth
        while dq:
            p, d = dq.popleft()
            if p > i:  # 整数の組(i,j) (1 <= i <= j <= N)
                ans[d] += 1
            for q in g[p]:
                if q not in seen:
                    dq.append((q, d + 1))
                    seen.add(q)

    for i in range(1, n):
        print(ans[i])

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 80756
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
 
bool dp[100100];
 
 
int main () {
    int N;
    cin >> N;
 
    vector<long long>A(N);
    rep(i,N){
        long long s;
        cin >> s;
        if(s == 0 ){
            cout << 0 << endl;
            return 0;
        }else  A[i] = s;
    }
    
    long long ans = 1;     
    rep(i,N){
        if(A[i] > 1000000000000000000/ans){
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4056
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 1000000000;

typedef pair<int,int> P;

int main() {
    int n,x,y; cin >> n >> x >> y;
    vector<int> dis(n,0);
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j < n + 1; j++) {
            int tmp = min(j - i, min(abs(x - i) + abs(y - j) + 1, abs(x - j) + abs(y - i) + 1));
            dis[tmp]++;
        }
    }
    for (int k = 1; k < n; k++) cout << dis[k] << "\n";
}

Measured memory_bytes: 3616
from fractions import gcd
def F(a, b, c, d):
	if a < b or d < b:
		return False
	a -= c
	a %= gcd(b, d)
	if a == 0:
		a = gcd(b, d)
	return a - b >= -c
for t in range(input()):
	a, b, c, d = map(int, raw_input().split())
	print ['No', 'Yes'][F(a, b, c, d)]


Measured memory_bytes: 4392
#include <iostream>
using namespace std;
int ball_cnt[200001];
int A[200001];
int main()
{
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    ball_cnt[i] = 0;
  }

  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    ball_cnt[A[i]]++;
  }

	long long sum = 0;
	for (int i = 1; i <= N; i++) {
    sum += (long long)(ball_cnt[i]) * (ball_cnt[i]-1) / 2;
	}
	
	for (int i = 1; i <= N; i++) {
    int num = A[i];
		long long ans = sum;
    ans -= (ball_cnt[num]) * (ball_cnt[num]-1) / 2;
		ans += (ball_cnt[num]-1) * (ball_cnt[num]-2) / 2;

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


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


int gcd(int a,int b){return(a? gcd(b%a,a): b);}

int main(){
    int n; cin>>n;
    vector<int> p(n);
    int x; cin>>x;
    rep(i,n){
        cin>>p[i];
        p[i]=abs(p[i]-x);
    }
    if(n==1){
        cout<<p[0]<<endl;
        return 0;
    }
    int ans=gcd(p[0],p[1]);
    rep(i,n-2) ans=gcd(ans,p[i+2]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <math.h>
int main(){
	//Input
	int N;
	std::cin >> N;

  double H, M;
	while(N--){
		scanf("%lf:%lf",&H,&M);
		//Processing
		//ツ角ツ度ツづーツ仰づ淞づゥ
		double aH = (60 * H + M) / 2, aM = 6 * M, a;
		//std::cout << aH << "," << aM << std::endl;
		a = std::min(fabs(aH-aM), 360-fabs(aH-aM));

		//ツ甘ォツ個ッツつウツづーツ板サツ津ィ
		std::string res;
		if(a < 30){
			res = "alert\n";
		}
		else if(a >= 90){
			res = "safe\n";
		}
		else{
			res = "warning\n";
		}

		std::cout << res;
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 5010

int n;
int a[SIZE];
vector<int> tree[SIZE];

ll dp[SIZE][SIZE][2];
bool dp2[SIZE][SIZE][2];

int dfs(int now, int prev = -1) {
  int sum_child = 1;

  dp[now][0][0] = a[now];
  dp2[now][0][0] = a[now] > 0;

  for(int to : tree[now]) {
    if (prev == to) continue;
    int child = dfs(to, now);

    for(int i=0;i<=sum_child;i++){
      for(int j=0;j<=child;j++){
        dp[now][i+j][1] = min(dp[now][i+j][1], dp[now][i][0] + dp[to][j][0]);
        dp2[now][i+j][1] = dp2[now][i+j][1] || (dp2[now][i][0] && dp2[to][j][0]);
      }
    }
    sum_child += child;

    for(int i=0;i<=sum_child;i++){
      dp[now][i][0] = dp[now][i][1];
      dp2[now][i][0] = dp2[now][i][1];
      dp[now][i][1] = LLINF;
      dp2[now][i][1] = false;
    }
  }

  for(int i=0;i<sum_child;i++){
    if(dp2[now][i][0] || dp[now][i][0] < 0) {
      dp2[now][i+1][0] = true;
      dp[now][i+1][0] = min(dp[now][i+1][0], 0LL);
    }
  }

  debug(sum_child);
  return sum_child;
}

int main(){
  scanf("%d", &n);

  for(int i=0;i<n;i++){
    scanf("%d", a+i);
  }

  for(int i=0;i<n-1;i++){
    int u, v;
    scanf("%d%d", &u, &v);
    u--; v--;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }

  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      dp[i][j][0] = dp[i][j][1] = LLINF;
      dp2[i][j][0] = dp2[i][j][1] = false;
    }
  }

  dfs(0);

  int ans = INF;

  for(int i=0;i<n;i++){
    if(dp2[0][i][0]) ans = min(ans, i);
    if(dp[0][i][0] < 0) ans = min(ans, i);
  }

  assert(ans != INF);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 441728
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++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;}

int main(){
	ll a,b,q;
	cin >> a >> b >> q;
	vector<ll> s(a),t(b),x(q);
	REP(i,a) cin >> s[i];
	REP(i,b) cin >> t[i];
	REP(i,q) cin >> x[i];
	
	REP(i,q){
		ll ok,ng,mid; // 二部探索用
		ll sl,sr,tl,tr;
		
		ok = -1;
		ng = a;
		while(ng-ok>1){
			mid = (ok+ng)/2;
			if(s[mid] < x[i]) ok = mid;
			else ng = mid;
		}
		if(ok!=-1) sl = x[i]-s[ok];
		else sl = 1e11;
		if(ok!=a-1) sr = s[ok+1]-x[i];
		else sr = 1e11;
		
		ok = -1;
		ng = b;
		while(ng-ok>1){
			mid = (ok+ng)/2;
			if(t[mid] < x[i]) ok = mid;
			else ng = mid;
		}
		if(ok!=-1) tl = x[i]-t[ok];
		else tl = 1e11;
		if(ok!=b-1) tr = t[ok+1]-x[i];
		else tr = 1e11;
		
		ll ans = max(sr, tr);
		chmin(ans, max(sl, tl));
		chmin(ans, min(sr,tl)*2+max(sr,tl));
		chmin(ans, min(sl,tr)*2+max(sl,tr));
		
		cout << ans << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 5564
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

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

    if(c >= b-1) cout << floor(a*(b-1)/(double)b) << endl;
    else cout << floor(a*c/(double)b) - a*floor(c/(double)b) << endl;
    return 0;
}

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

int main(){
    int N;
    int ans = 0;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    int h = N/2;
    if(vec.at(h) == vec.at(h-1)){
        ans = 0;
    }else{
        if(vec.at(h)-vec.at(h-1) == 1){
            ans = 1;
        }else{
        ans = (vec.at(h)-vec.at(h-1));
        }
    }
cout << ans << endl;
}

Measured memory_bytes: 640