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

#define int long long
#define fi first
#define se second

using namespace std;

const int inf = 1e18;
const int maxN = 2e5 + 10;

int n, q, a, b, p, c, i;
int st[2][maxN * 4], ans[maxN], tmp = 0, res = inf;

void build(int l, int r, int id)
{
    if (l == r)
    {
        st[0][id] = ans[l] - l;
        st[1][id] = ans[l] + l;
    }
    else
    {
        build(l, (l + r) / 2, 2 * id);
        build((l + r) / 2 + 1, r, 2 * id + 1);
        st[0][id] = min(st[0][2 * id], st[0][2 * id + 1]);
        st[1][id] = min(st[1][2 * id], st[1][2 * id + 1]);
    }
}

void update(int l, int r, int a, int id)
{
    if (r < a || l > a)
        return;
    else if (l == a && r == a)
    {
        st[0][id] = ans[l] - l;
        st[1][id] = ans[l] + l;
    }
    else
    {
        update(l, (l + r) / 2, a, 2 * id);
        update((l + r) / 2 + 1, r, a, 2 * id + 1);
        st[0][id] = min(st[0][2 * id], st[0][2 * id + 1]);
        st[1][id] = min(st[1][2 * id], st[1][2 * id + 1]);
    }
}

int query(int l, int r, int L, int R, int x, int id)
{
    if (r < L || l > R)
        return inf;
    else if (L <= l && r <= R)
        return st[x][id];
    else{
        int mid = (l + r) / 2;
        return min(query(l, mid, L, R, x, 2 * id), query(mid + 1, r, L, R, x, 2 * id + 1));
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
    cin >> n >> q >> a >> b;
    fill(ans + 1, ans + n + 1, inf);
    cin >> p;

    ans[a] = abs(b - p);
    ans[b] = abs(a - p);
    --q;

    build(1, n, 1);

    while (q--)
    {
        cin >> c;
        tmp += abs(c - p);
        ans[p] = min(ans[p], min(query(1, n, 1, c - 1, 0, 1) + c, query(1, n, c, n, 1, 1) - c) - abs(c - p));
        update(1, n, p, 1);
        p = c;
    }

    for (i = 1; i <= n; i++)
        res = min(res, ans[i]);

    cout << res + tmp;
}


Measured memory_bytes: 13444
#include<bits/stdc++.h>
using namespace std;
stack<int> pila;
int operacion(string ss){
    int a,b;
    a=pila.top();
    pila.pop();
    b=pila.top();
    pila.pop();
    if(ss=="+") return a+b;
    if(ss=="-") return b-a;
    if(ss=="*") return a*b;
}

int main(){
    ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	int a,b;
	while(cin>>s){
        if(s=="+"||s=="-"||s=="*"){
            pila.push(operacion(s));
        }else{
            pila.push(atoi(s.c_str()));
        }
	}
	cout<<pila.top()<<"\n";
    return 0;
}



Measured memory_bytes: 3200
#include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rep1(i,n) for(int i = 1 ; i < n ; i++)
const int MAX_N = 101;
const int MAX_T = 21;

int main(){
  int n,a[MAX_N],ans;
  long long dp[MAX_N][MAX_T];
  
  cin >> n;
  rep(i,n-1) cin >> a[i];
 
  rep(i,MAX_N) rep(j,MAX_T) dp[i][j] = 0;
  dp[0][a[0]] = 1;
 
  rep1(i,n-1){
    rep(j,MAX_T){
      if(j+a[i] < MAX_T) dp[i][j+a[i]] += dp[i-1][j];
      if(j-a[i] >= 0) dp[i][j-a[i]] += dp[i-1][j];
    }
  }
 
  cin >> ans;
  cout << dp[n-2][ans] << endl;
 
  return 0;
}

Measured memory_bytes: 1172
num = int(input())
count = 1
div_8_list = []
while count < num + 1:
    if count % 2 != 0:
        div = []
        for i in range(1, int(count**0.5)+1):
            if count % i == 0:
                div.append(i)
                if i != count // i:
                    div.append(count//i)
        if len(div) == 8:
            div_8_list.append(div)
    count += 1
print(len(div_8_list))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 

P a1[100001], a2[100001];
int v[100001], n;
int ans;

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        if(i%2==0){
            a2[v[i]].first++;
            a2[v[i]].second = v[i];
        }
        else{
            a1[v[i]].first++;
            a1[v[i]].second = v[i];
        }

    }

    sort(a1, a1+100001);
    sort(a2, a2+100001);

    if(a1[100001-1].second == a2[100001-1].second){
        if(a1[100001-1].second > a2[100001-1].second){
            ans = n-a1[100001-1].first-a2[100001-2].first;
        }
        else if(a1[100001-1].second < a2[100001-1].second){
            ans = n-a1[100001-2].first - a2[100001-1].first;
        }
        else{
            ans = n-a1[100001-1].first - max(a1[100001-2].first,a2[100001-2].first);
        }
    }else{
        ans = n-a1[100001-1].first-a2[100001-1].first;
    }
  //  cout << a2[100001-1].first << ' ' << a2[100001-1].second << endl;
    cout << ans << endl;

}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> A(N + 5, 0), T(N + 5, 0);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
  }

  int total = 0;
  for (int i = 0; i <= N; ++i) {
    total += abs(A[i + 1] - A[i]);
  }

  for (int i = 1; i <= N; ++i) {
    int ans = total - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) +
              abs(A[i - 1] - A[i + 1]);
    printf("%d\n", ans);
  }
  return 0;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
struct Diameter{
  vector<ll>dep,ret;
  ll n;
  vector<vector<ll>>g;
  ll diam,root,end;
  Diameter(vector<vector<ll>>&G):g(G),n(G.size()){
    dep.assign(n,-1LL);
    dfs(0,0);
    root = max_element(ALL(dep)) - dep.begin();
    fill(ALL(dep),-1LL);
    dfs(root,0);
    end = max_element(ALL(dep)) - dep.begin();
    diam = dep[end];
  }
  void dfs(ll k, ll d){
    dep[k] = d;
    for(auto to:g[k]){
      if(dep[to]==-1)dfs(to,d+1);
    }
  }
  vector<ll>diam_path(){
    vector<ll>tmp;
    dfs2(root,-1,tmp);
    return ret;
  }
  void dfs2(ll k, ll par,vector<ll>&v){
    v.PB(k);
    if(k==end)ret=v;
    for(auto to:g[k]){
      if(par!=to)dfs2(to,k,v);
    }
    v.pop_back();
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<vector<ll>>g(n);
  rep(i,0,n-1){
    ll a,b;cin>>a>>b;a--;b--;
    g[a].PB(b);
    g[b].PB(a);
  }
  Diameter dia(g);
  //cout<<dia.diam<<endl;
  ans(dia.diam%3==1,"Second","First");
  return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, M, tmp=0;
vector<pair<ll,ll>> ans;

signed main(){
    cin >> N >> M;
    for(int i=1;i<=M;i++) {
        tmp = 0;
        if(N%2==0&&4*i>=N) tmp++;
        cout << (N-i-tmp)%N << " " << (N+i)%N << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

int main(){
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for(ll i = k; i <= n+1; i++){
        ll first = i*(i-1)/2;
        ll final = i*(2*n-(i-1))/2;
        ll add = final - first + 1;
        ans += add;
    }
    ans %= MOD;
    cout << ans << endl;
    return 0;
}



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

// calculate |gcd|.
// if  ether num is 0, return 0
long long GCD(long long left, long long right) {
  if(left == 0 || right == 0) return 0;
  if(left < 0) left *= -1;
  if(right < 0) right *= -1;
  if(left < right) swap(left, right);
  long long nextnum, ansgcd = -1;
  while(ansgcd == -1) {
    nextnum = left % right;
    if(nextnum == 0) ansgcd = right;
    left = right;
    right = nextnum;
  }
  return ansgcd;
}

long long LCM(long long left, long long right) {
  return left / GCD(left, right) * right;
}

long long n;
vector<long long> v;

long long solve();

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

long long solve() {
  long long ans = v[1] - v[0];
  for(int i = 0; i < n; ++i)
    ans = GCD(ans, v[i + 1] - v[i]);
  return ans;
}

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

int main(){
    string a, b, c;
    cin>>a>>b>>c;
    int an = a.size();
    int bn = b.size();
    int cn = c.size();

    if(a[an-1] == b[0] && b[bn-1] == c[0]){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque
N = int(input())
A = list(map(int, input().split()))
A.sort()
q = deque(A)
ansq = deque()
i = 0
while i != N - 2:
    """if i % 2 == 0:
        l, r = q.popleft(), q.pop()
        q.appendleft(l - r)
        ansq.append((l,  r))
    else:
        l, r = q.popleft(), q.pop()
        q.append(r - l)
        ansq.append((r,  l))"""
    l, r = q.popleft(), q.pop()
    if l < 0 and r < 0: # どちらもマイナス
        if l < r:
            q.append(r - l)
            ansq.append((r, l))
        else:
            q.append(l - r)
            ansq.append((l, r))
    elif l >= 0 and r >= 0: # どちらもプラス
        if l < r:
            q.appendleft(l - r)
            ansq.append((l, r))
        else:
            q.appendleft(r - l)
            ansq.append((r, l))
    else: # 異符号
        if abs(r - l - q[-1]) > abs(q[0] - l + r):
            q.append(r - l)
            ansq.append((r, l))
        else:
            q.appendleft(l - r)
            ansq.append((l, r))
    i += 1
print(q[1] - q[0])
for ans in ansq:
    print("{} {}".format(ans[0], ans[1]))
print(q[1], q[0])

Measured memory_bytes: 19592
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    n,k=intLine()
    println(cld(n,k)-div(n,k))
end
main()

Measured memory_bytes: 116448
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int h = in.nextInt(), w = in.nextInt();
        in.nextLine();
        char[][] field = new char[h + 2][w + 2];
        for(int i = 1; i <= h; i++)  {
            String str = in.nextLine();
            for(int j = 1; j <= w; j++) {
                field[i][j] = str.charAt(j- 1);
            }
        }
        for(int i = 1; i <= h; i++)  {
            for(int j = 1; j <= w; j++) {
                if(field[i][j] == '#' &&
                field[i-1][j] != '#' && field[i][j-1] != '#' &&
                field[i+1][j] != '#' && field[i][j+1] != '#') {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=998244353;
typedef pair<int,int> P;
typedef pair<P,int> PI;
typedef pair<int,P> IP;
typedef pair<P,P> PP;

int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}

int f(int a){
  if(a<=2)return 0;
  int res=pw(2,a);
  res--;
  res-=a;
  res-=a*(a-1)/2;
  res%=MOD;res+=MOD;res%=MOD;
  return res;
}

signed main(){
  int n;cin>>n;
  vector<P> a(n);
  for(int i=0;i<n;i++){
    int x,y;cin>>x>>y;
    a[i]=P(x,y);
  }
  sort(a.begin(),a.end());
  map<PP,int> m;
  for(int i=0;i<n;i++){
    map<P,PI> mp;
    for(int j=i+1;j<n;j++){
      int x=a[j].first-a[i].first,y=a[j].second-a[i].second;
      P ka;
      int g=__gcd(x,y);
      if(g)ka=P(x/g,y/g);
      else ka=P(1e9,1e9);
      mp[ka]=PI(a[j],mp[ka].second+1);
    }
    for(auto p:mp){
      P ka=p.first,po=p.second.first;
      int v=p.second.second;
      if(m.count(PP(ka,po)))continue;
      m[PP(ka,po)]=v+1;
    }
  }

  int ans=f(n);
  for(auto p:m){
    ans-=f(p.second);
    ans+=MOD;
    ans%=MOD;
  }
  ans%=MOD;ans+=MOD;ans%=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}

struct Point { LL x, y, d; };   // d はマンハッタン距離
vector<Point> moves{Point{-1, 0, 0}, Point{1, 0, 0}, Point{0, -1, 0}, Point{0, 1, 0}};   // 第3引数はダミー
    

int main(){
    LL H, W;
    cin >> H >> W;
    VS s(H);
    LL tot_n_white = 0;
    REP(i, H) {
        cin >> s[i];
        REP(j, W) {
            if (s[i][j] == '.') tot_n_white++;
        }
    }

    vector<VB> visited(H, VB(W));
    queue<Point> q;
    q.push(Point{0, 0, 1});
    LL n_white = -1;
    while (!q.empty()) {
        Point p = q.front(); q.pop();
        if (0 <= p.x && p.x < H && 0 <= p.y && p.y < W && s[p.x][p.y] != '#' && !visited[p.x][p.y]) {
            if (p.x == H - 1 && p.y == W - 1) {
                n_white = p.d;
                break;
            }
            visited[p.x][p.y] = true;
            EACH(move, moves) {
                q.push(Point{p.x + move.x, p.y + move.y, p.d + 1});
            }
        }
    }
    if (n_white == -1) {
        cout << "-1" << endl;
        return 0;
    }
    cout << tot_n_white - n_white << endl;
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int A[N] = {};
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  long long int dist = abs(A[0]) + abs(A[0] - A[K - 1]);
  
  for (int i = 0; i <= N - K; i++) {
    long long int dist_temp = abs(A[i]) + abs(A[i] - A[K + i - 1]);
    if (dist_temp < dist)
      dist = dist_temp;
    
    dist_temp = abs(A[N - i - 1]) + abs(A[N - i - 1] - A[N - i - K]);
    if (dist_temp < dist)
      dist = dist_temp;    
  }

  cout << dist << endl;
    
}

Measured memory_bytes: 640
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for a_i in range(a + 1):
    for b_i in range(b + 1):
        for c_i in range(c + 1):
            if x == (a_i * 500 + b_i * 100 + c_i * 50):
                count = count + 1

print(count)


Measured memory_bytes: 3060
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define pk putchar(' ')
#define ph puts("")
typedef long long ll;
using namespace std;
template <class T>
void rd(T &x)
{
    x = 0;
    int f = 1;
    char c = getchar();
    while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    x *= f;
}
template <class T>
void pt(T x)
{
    if (x < 0)
        putchar('-'), x = (~x) + 1;
    if (x > 9)
        pt(x / 10);
    putchar(x % 10 ^ 48);
}
const int N = 2e5 + 5;
int n, a[N];
ll ans;
map<int, ll> M;
int main() 
{
	rd(n);
	for (int i = 1, x; i <= n; i++)
		rd(a[i]), M[a[i] + i]++;
	for (int i = 1; i <= n; i++)
		ans += M[i - a[i]];
	pt(ans);
    return 0;
}

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

int main(){
  int A[2];
  cin >> A[0] >> A[1];
  sort(A, A+2);
  if (A[0] == 1 && A[1] == 2){
    cout << 3 << "\n";
  }
  else if (A[0] == 1 && A[1] == 3){
    cout << 2 << "\n";
  } else {
    cout << 1 << "\n";
  }
  return 0;
}

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

int main(){
string txt;
 cin >> txt;
 int N = txt.length();
  int n = (N-1)/2;
  int m = (N+3)/2-1;
  int i;
  char c;
  char d;
  int t=0;
  for(i=0;i<n;i++){
   c = txt[i];
   d = txt[n-i-1];
   if(c!=d)t++;}
  for(i=m;i<N;i++){
   c = txt[i];
   d = txt[N-1-i+m];
   if(c!=d)t++;}
  for(i=0;i<N;i++){
   c = txt[i];
   d = txt[N-i-1];
   if(c!=d)t++;}
  if(t>0)cout << "No" << endl; 
  else{cout << "Yes" << endl;} 
  return 0;
}

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

#define N 1000006

const int mod = 1e9 + 7;
int san = (mod+1)/3;
int ers = san * 2;

int dp[N][2], iv[N] = {1, 1};
int f[N] = {1, 1}, rf[N] = {1, 1};

int main() {
    dp[0][1] = 1;
    dp[0][0] = 0;
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) {
        dp[i][0] = dp[i-1][1] << 1;
        if (dp[i][0] >= mod) dp[i][0] -= mod;
        dp[i][1] = dp[i-1][0] + dp[i-1][1];
        if (dp[i][1] >= mod) dp[i][1] -= mod;
    }
    for (int i = 2; i <= n+1; i ++) {
		iv[i] = 1ll * (mod/i) * (mod-iv[mod%i]) % mod;
		f[i] = 1ll * f[i-1] * i % mod;
		rf[i] = 1ll * rf[i-1] * iv[i] % mod;
    }
    int ans = 0;
    for (int i = 1; i <= n; i ++) {
        ans = (ans + 1ll * rf[i] * iv[i] % mod * rf[n-i] % mod * dp[i-1][1]) % mod;
    }
    ans = 1ll * ans * iv[n] % mod;
    ans = 1ll * ans * f[n] % mod;
    for ( ; n; n >>= 1) {
        if (n&1) ans = 1ll * ans * san % mod;
        san = 1ll * san * san % mod;
    }
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 19712
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int h,w,n;

template<typename int_t>
void readx(int_t &x)
{
	x=0; int_t k=1; char ch=0;
	while (ch<'0' || ch>'9') { ch=getchar(); if (ch=='-') k=-1; }
	while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	x*=k;
}



int main()
{
	readx(h); readx(w); readx(n);
	if (h<w) swap(h,w);
	printf("%d\n", (n/h) + (bool)(n%h) );
	return 0;
}

Measured memory_bytes: 3728
#include<iostream>  
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; 
char s[10001]; 
int ans=0;
int main()  
{
	int n=strlen(s);
	scanf("%s",s);
	if(s[0]!='C')ans++;
	if(s[1]!='O')ans++;
	if(s[2]!='D')ans++;
	if(s[3]!='E')ans++;
	if(s[4]!='F')ans++;
	if(s[5]!='E')ans++;
	if(s[6]!='S')ans++;
	if(s[7]!='T')ans++;
	if(s[8]!='I')ans++;
	if(s[9]!='V')ans++;
	if(s[10]!='A')ans++;
	if(s[11]!='L')ans++;
	if(s[12]!='2')ans++;
	if(s[13]!='0')ans++;
	if(s[14]!='1')ans++;
	if(s[15]!='6')ans++;
	printf("%d\n",ans);
	return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ll n;
	cin>>n;
	ll cur = 10000000000000;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			cur = min(cur,n/i+i-2);
		}
	}
	cout<<cur;
}


Measured memory_bytes: 256
#include <cstdio>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
int main( void ){
	int n;
	if (!scanf( "%d", &n )){
		return 1;
	}
	rep( i, 1, 10 ){
		if (n % i == 0){
			if (( n / i ) <= 9){
				printf( "Yes\n");
				return 0;
			}
		}
	}
	printf( "No\n" );
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n,k;
  cin>>n;
  cin>>k;
  int arr[200006];
  int dp[200006];
  for(int i=0;i<n;i++){
    cin>>arr[i];
    dp[i] = 1000000000;
  }
  dp[0] = 0;
  for(int i = 1;i<n;i++){
    for(int j = 0; j<min(i,k);j++){
        dp[i] = min(dp[i], dp[i-j-1] + abs(arr[i]-arr[i-j-1]));
    }
  }
  cout<<dp[n-1];
  
 return 0; 
}


Measured memory_bytes: 1024
def possible(m):
    l = 0
    r = 1
    zeroes = int(s[0] == '0')
    ans = N
    while r != N + 1:
        if r - l > m:
            l += 1
            if s[l] != s[l - 1] and s[l] == '1':
                zeroes -= 1
        if r - l == m:
            ans = min(ans, zeroes)
        if r == N:
            break
        if s[r] != s[r - 1] and s[r] == '0':
            zeroes += 1
        r += 1
    return min(zeroes, ans) <= K
            
N, K = map(int, input().split())
s = input()
l = 1
r = N + 1
while r - l > 1:
    m = (l + r) // 2
    if possible(m):
        l = m
    else:
        r = m
print(l)

Measured memory_bytes: 3316
from collections import defaultdict

n, m = [int(i) for i in input().split()]

graph = defaultdict(list)

for _ in range(m):
    a, b = [int(i) for i in input().split()]
    graph[a].append(b)
    graph[b].append(a)

for hop in graph[1]:
    for goal in graph[hop]:
        if goal == n:
            print("POSSIBLE")
            quit()
        else:
            continue

print("IMPOSSIBLE")


Measured memory_bytes: 136120
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std; 
#define MAXN 200
#define MAXM 50
int main(int argc,char const* argv[])
{
  int n,ans=0;
  cin >> n;
  vector<long long > A(n,0);
  for(int i=0;i<n;i++)
    {
      cin >> A[i];
    }
  bool end=true;
   while(1)
       {
	 for(int i=0;i<n;i++)
	   {
	     if(A[i]%2 != 0) end=false;
	     else A[i]=A[i]/2;
	   }
	 if(end == false) break;
	 ans++;
	 end=true;
       }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N ,M ,X ,Y = list(map(int,input().strip().split()))
xlist = list(map(int,input().strip().split()))
ylist = list(map(int,input().strip().split()))

x_max = -100
y_min = 100

for i in range(0,N):
    x = xlist[i]
    x_max = max(int(x),x_max)

for j in range(0,M):
    y = ylist[j]
    y_min = min(int(y),y_min)

if X < Y\
    and int(x_max) < int(y_min)\
    and X < int(y_min)\
    and int(x_max) < Y:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int count = 0;
        
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        
        for (int i = n; i >= 1; i--) {
            int num = i;
            int sum = 0;
            for (int j = i * 2; j <= n; j += i) {
                sum += b[j - 1];
            }
            
            if (a[i - 1] != sum % 2) {
                count++;
                b[i - 1] = 1;
            }
        }
        
        System.out.println(count);
        for (int i = 1; i <= n; i++) {
            if (b[i - 1] == 1) {
                System.out.println(i);
            }
        }
    }
}


Measured memory_bytes: 66000
# usage: update, query = SegmentTreeClosure(init_val=dp, segfunc=max, ide_ele=0)
# 再帰なしsegment tree
# https://proc-cpuinfo.fixstars.com/2017/07/optimize-segment-tree/
# class版original: @solzard_
def SegmentTreeClosure(init_val, segfunc, ide_ele) -> 'update,query':
    size = 1 << (len(init_val) - 1).bit_length()

    # _build
    tree = [ide_ele] * (size * 2 - 1)
    for idx, val in enumerate(init_val, size - 1):  # set
        # modify val if needed (e.g. str -> ord())
        tree[idx] = val
    for idx in range(size - 2, -1, -1):  # build
        tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

    # closure_1
    def update(idx: int, val) -> None:
        nonlocal size
        nonlocal tree
        nonlocal segfunc

        idx += size - 1
        # modify val if needed as same as in _build()
        tree[idx] = val
        while idx > 0:
            idx = (idx - 1) // 2
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

    # closure_2
    def query(left: int, right: int) -> 'result':
        nonlocal size
        nonlocal tree
        nonlocal segfunc

        left += size
        right += size
        ret = ide_ele  # left >= right: return ide_ele
        while left < right:  # どの段も奇偶...順
            if left % 2:  # odd
                ret = segfunc(ret, tree[left - 1])
                left += 1
            if right % 2:  # odd
                right -= 1
                ret = segfunc(ret, tree[right - 1])
            left //= 2
            right //= 2

        return ret

    return update, query


n = int(input())
h = tuple(map(int, input().split()))
a = tuple(map(int, input().split()))

dp = [0] * (n + 1)
# dp[j] := 末尾jの単調増加列の美しさの総和の最大値

update, query = SegmentTreeClosure(init_val=dp, segfunc=max, ide_ele=0)
for h_, a_ in zip(h, a):
    # i本目を取って末尾にするとき
    max_ = query(0, h_) + a_
    update(h_, max_)
print(query(0, n + 1))


Measured memory_bytes: 129488
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = 998244353;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
const int maxN = 2e5 + 10;
int dp[maxN];
int pref[maxN];
int n, k;
int l[maxN], r[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    dp[1] = 1;
    pref[1] = 1;
    cin >> n >> k;
    for (int i = 1; i <= k; i++) {
        cin >> l[i] >> r[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int c = 1; c <= k; c++) {
            int from = max(1, i - r[c]);
            int to = i - l[c];
            if (from > to) continue;
            dp[i] = sum(dp[i], sub(pref[to], pref[from - 1]));
        }
        pref[i] = sum(pref[i - 1], dp[i]);
    }
    cout << dp[n];
    return 0;
}

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a==b)cout<<"Draw"<<endl;
    else if(a>b&&!(a==13&&b==1))cout<<"Alice"<<endl;
    else if(!(a==1&&b==13))cout<<"Bob"<<endl;
    else cout<<"Alice"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K,N;
    cin >> K >> N;
    int current = 0;
    int last = 0;
    int max = 0;
    int diff = 0;
    int fir = 0;
    int la;
    for(int i=0;i<N;i++){
        last = current;
        cin >> current;
        if(i ==0)
            fir = current;
        if(i == N-1)
            la = current;
        diff = current - last;
        if(diff > max)
            max = diff;
    }
    int x = K-la+fir;
    if(x>max)
        max = x;
    cout << K-max << "\n";
    return 0;
}

Measured memory_bytes: 256
s = input()
wa = 0
if s[0] == 'A':
    s = s[1:]
else:
    wa = 1

for i in range(len(s)):
    if i in [0,len(s)-1]:
        continue
    if s[i] == 'C':
        s = s[:i]+s[i+1:]
        break
else:
    wa = 1

if not s.islower():
    wa = 1

if bool(wa):
    print('WA')
else:
    print('AC')

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

int main(){
	int x;
	vector<int> a;
	a.push_back(1);
	for(int i=2; i<=31; i++){
		int cnt=i;
		while(cnt*i<=1000){
			cnt*=i;
			a.push_back(cnt);
		}
	}
	cin>>x;
	sort(a.begin(),a.end());
	for(int i=(signed)a.size()-1; i>=0; i--){
		if(a[i]<=x){
			cout<<a[i]<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;

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

struct dat{
	int f, a, t, x, y;
	dat(){};
	dat(int f, int a, int t, int x, int y):f(f), a(a), t(t), x(x), y(y){};
};

int main(){
	int n;
	cin>>n;
	double la = -1, ta = -60;
	double lb = -1, tb = -60;
	dat d[1010];
	rep(i, n) {
		cin>>d[i].f>>d[i].a>>d[i].t>>d[i].x>>d[i].y;
	}
	for(int i = 0; i < n -1; i++){
		if(d[i].t!=d[i+1].t) continue;
		if(d[i].a==d[i+1].a) continue;
		if(d[i].t==0){
			if(la < hypot(d[i].x-d[i+1].x, d[i].y-d[i+1].y)){
				la = hypot(d[i].x-d[i+1].x, d[i].y-d[i+1].y);
				ta = d[i+1].f-d[i].f;
			}
			else if(abs(la - hypot(d[i].x-d[i+1].x, d[i].y-d[i+1].y))<EPS){
				ta = min(ta, (double)d[i+1].f-d[i].f);
			}
		}
		if(d[i].t==1){
			if(lb < hypot(d[i].x-d[i+1].x, d[i].y-d[i+1].y)){
				lb = hypot(d[i].x-d[i+1].x, d[i].y-d[i+1].y);
				tb = d[i+1].f-d[i].f;
			}
			else if(abs(lb - hypot(d[i].x-d[i+1].x, d[i].y-d[i+1].y))<EPS){
				tb = min(tb, (double)d[i+1].f-d[i].f);
			}
		}
	}
	if(la==-1){
		cout<<-1<<" "<<-1<<endl;
	}
	else printf("%.15lf %.15lf\n", la, ta/60.0);
	if(lb==-1){
		cout<<-1<<" "<<-1<<endl;
	}
	else printf("%.15lf %.15lf\n", lb, tb/60.0);
}

Measured memory_bytes: 1260
#include<iostream>
#include<stack>
#include<map>
using namespace std;

#define W 501

#define rep(i, n) for(int i=0; i<n; ++i)
#define max(a,b) (a>b?a:b)

typedef pair<int, int> P;

int main() {
	char c[W][W]; int h, w;
	int m[W][W];
	while(cin >> h >> w && h && w) {
		rep(i, h) {
			rep(j, w) {
				cin >> c[i][j];
			}
		}
		rep(i, w) {
			int cnt = 0;
			for(int j=h-1; j>=0; --j) {
				if(c[j][i]=='.') ++cnt;
				else cnt = 0;
				m[j][i] = cnt;
			}
		}
		int ans = 0;
		rep(i, h) {
			stack<P> st;
			rep(j, w) {
				int mi = -1;
				// cout << i << " " << j << " : " << ans << endl;
				while(!st.empty() && m[i][j]<st.top().second) {
					P p = st.top(); st.pop();
					mi = p.first;
					// cout << "output : " << p.first << ", " << p.second << " " << j << endl;
					ans = max(ans, (j - p.first)*p.second);
				}
				if(m[i][j]>0) {
					if(mi!=-1 && (st.empty() || st.top().second<m[i][j])) {
						st.push(P(mi, m[i][j]));
					}else if(st.empty() || st.top().second<m[i][j]) {
						st.push(P(j, m[i][j]));
					}
				}
			}
			while(!st.empty()) {
				P p = st.top(); st.pop();
				// cout << "*output : " << p.first << ", " << p.second << " " << w << endl;
				ans = max(ans, (w - p.first)*p.second);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

long long MOD = 10000000000 + 7;

vector<vector<vector<int>>> F;
vector<vector<ll>> P;
int N;

ll max_val = -1000000000000000;

void solve(string S){
  if(S.size() < 10){
    solve(S+'0');
    solve(S+'1');
    return;
  }

  vector<int> Open(N,0);
  reverse(S.begin(), S.end());

  int num = 0;
  for(int j = 0; j < 5; j++){
    for(int k = 0; k < 2; k++){
      char c = S[j + 5 * k];

      if(c == '1'){ // 営業していたら
        num++; // 営業回数
        for(int i = 0; i < N; i++){
          if(F[i][j][k] == 1){ // 店iも営業していたら
            Open[i]++; // 被っている回数
          }
        }
      }
    }
  }

  if(num == 0) return;

  ll val = 0;

  for(int i = 0; i < N; i++){
    // cerr << "i: " << i << " open: " << Open[i] << endl;
    val += P[i][Open[i]];
  }

  // cerr << S << " num: " << num << " val: " << val << endl;
  max_val = max(max_val, val);

  return;
}

int main(){
  cout << setprecision(10);
  cin >> N;

  F.assign(N, vector<vector<int>>(5, vector<int>(2,0)));

  for(int i = 0; i < N; i++){
    for(int j = 0; j < 5; j++){
      for(int k = 0; k < 2; k++){
        cin >> F[i][j][k];
      }
    }
  }

  P.assign(N, vector<ll>(11,0));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 11; j++){
      cin >> P[i][j];
    }
  }

  solve("");

  cout << max_val << endl;

}


Measured memory_bytes: 3684
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	//cout << min(min(a + b, b + c), c + a) << endl;
	printf((a<=c&&c<=b) ? "Yes\n" : "No\n");
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


vector<int> edge[100005];
ll A[100005];

ll dfs(int n, int b){
	if( edge[n].size() == 1 ){
		return A[n];
	}
	ll mx = 0, sum = 0;
	for(auto t: edge[n]) if( t != b ){
		auto r = dfs(t, n);
		if( r < 0 ) return -1;
		chmax(mx, r);
		sum += r;
	}
	if( A[n] < mx ) return -1;
	if( A[n]*2ll < sum ) return -1;
	if( A[n] > sum ) return -1;
	ll ret = A[n]*2ll - sum;
	//cout << "dfs: " << n << " "  << ret << endl;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int N;

	cin >> N;
	rep(i,N) cin >> A[i];
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	bool ans;
	rep(i,N) if( edge[i].size() > 1 ){
		auto ret = dfs(i, -1);
		ans = (ret == 0);
		break;
	}

	if( N == 2 ){
		ans = (A[0] == A[1]);
	}

	cout << (ans ? "YES" : "NO") << endl;

	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-6

int N;
vector<double> r;

int main(){
  cin>>N;
  r.resize(N);
  rep(i,N){
    cin>>r[i];
  }
  sort(all(r));
  double res=0;
  do{
    repl(k,3,N+1){
      double lb=0,ub=PI;
      rep(_,100){
        double X=(lb+ub)/2.0;
        double cos1=cos(X);
        double theta=0;
        bool ok=true;
        rep(i,k){
          double p=((r[0]*r[1])/(r[i]*r[(i+1)%k]))*cos1;
          if(p<-1.0)p=-1.0;
          if(p>+1.0)p=+1.0;
          theta+=acos(((r[0]*r[1])/(r[i]*r[(i+1)%k]))*cos1);
        }
        if(theta<2*PI)lb=X;
        else ub=X;
      }
      double sum=0;
      double cos1=cos(lb);
      double thetasum=0;
      rep(i,k){
        double p=((r[0]*r[1])/(r[i]*r[(i+1)%k]))*cos1;
        if(p<-1.0)p=-1.0;
        if(p>+1.0)p=+1.0;
        sum+=(r[i]*r[(i+1)%k])*sin(acos(p));
        thetasum+=acos(p);
      }
      if(abs(thetasum-2.0*PI)<eps)maxch(res,sum/2.0);
    }
  }while(next_permutation(all(r)));
  printf("%.10f\n",res);
  return 0;
}



Measured memory_bytes: 3716
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
A = LI()
for i in range(N):
    A[i] = (A[i],i)
A.sort()

print(*[A[i][1]+1 for i in range(N)])


Measured memory_bytes: 92876
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array
int main()
{   
	int n;
	cin >> n;
	ar<int, 2> a[n];
	for (int i=0; i<n; i++) {
		int x, y;
		cin >> x >> y;
		a[i][0]=x+y, a[i][1]=x-y;
	}
	int ans=INT_MIN;
	for (int k=0; k<2; k++) {
		int h=INT_MIN, m=INT_MAX;
		for (int i=0; i<n; i++) {
			h=max(h, a[i][k]);
			m=min(m, a[i][k]);
		}
		ans=max(ans, h-m);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5132
#import <iostream>
#import <math.h>
using namespace std;
 
int main() {
 
long a;
cin >> a;
 
unsigned long long int b;
long long int realtotal = 1;
long long temp = 1;
bool error = false;
int i;
for(i = 0; i<a; i++){
  cin >> b;
  temp = temp*b;
  if(b != 0 && realtotal != temp/b){
    error = true;
    realtotal = -1;
    break;
  }
  realtotal = realtotal*b;
  if(realtotal == 0){
    cout << 0;
    return 0;
 	}
  }
  if(error){
    for(;i<a; i++){
      cin >> b;
      if(b == 0){
        realtotal = 0;
        break;
      }
    }
  }
  
  if(0 <= realtotal && realtotal<= 1000000000000000000){
    cout << realtotal; 
  }
  else{
    cout << -1;
  }
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using namespace std; 

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";} 
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

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

    string s;
    cin >> s;

    int ans = 0;
    for(char a = '0'; a <= '9'; a++) {
        for(char b = '0'; b <= '9'; b++) {
            for(char c = '0'; c <= '9'; c++) {
                string t;
                t += a; t += b; t += c;

                int p = 0;
                int q = 0;
                while(p < n) {
                    while(p < n && s[p] != t[q]) {
                        p++;
                    }
                    if(p < n) { p++; q++; }
                    if(q == 3) { ans++; break; } 
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

/*atcoder*/


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n,a[100001];
	cin>>n;
	for (int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	unsigned long long sum[100001];sum[0]=a[0];
	for (int i=1;i<n;i++)sum[i]+=sum[i-1]+a[i];
	for (int i=n-2;i>=0;i--)if (sum[i]*2>=a[i+1])sum[i]=sum[i+1];
	int ans=0;
	for (int i=0;i<n;i++){
		if (sum[i]==sum[n-1])ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int Min(int a,int b){return a<b?a:b;}
const int N=2e5+1,M=(N<<2),oo=(~0u>>2);
int n,m,mn[M],z[M],t[M],g[M],ql,qr,qx;
static inline void pu(int x){z[x]=z[x*2];t[x]=t[x*2+1];mn[x]=Min(mn[x*2],mn[x*2+1]);}
void build(int x,int l,int r){
  if(l==r){
    z[x]=l;
    t[x]=l;
    return;
  }
  int m=(l+r)/2;
  build(x*2,l,m);
  build(x*2+1,m+1,r);
  pu(x);
}
static inline void pt(int x,int w,int r){g[x]=w;t[x]=w;z[x]=w;if(w<=m){mn[x]=w-r;}else{mn[x]=oo;}}
static inline void upd(int x,int l,int r)
{
  if(z[x]>qr||t[x]<ql){return;}
  if(z[x]>=ql&&t[x]<=qr){pt(x,qr+1,r);return;}
  int m=(l+r)/2;
  if(g[x]){pt(x*2,g[x],m);pt(x*2+1,g[x],r);g[x]=0;}
  upd(x*2,l,m);upd(x*2+1,m+1,r);pu(x);
}
int main()
{
  //https://atcoder.jp/contests/abc177/submissions/16378643
  int i,p=1;n=IN(),m=IN();
  build(1,1,m);
  for(int i=0;i<n;i++)
  {
    ql=IN(),qr=IN();upd(1,1,m);if(mn[1]>m){puts(""),puts("-1");}else{OUT(mn[1]+i+1);}
  }
}

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

int main()
{
    // 入力
    long long N,step=0;
    //int result;
    cin >> N;
    long long A[N];
    rep (i,N){
        cin >> A[i];
        //cout << "flag " << flag << endl;
    }

    //cout << "" << endl;
    // 計算
    rep (i,N-1){
        if (A[i] > A[i+1]){
            step += A[i] - A[i+1];
            A[i+1] = A[i];
            //cout << "step " << step << endl;
            //cout << "A[" << i+1 << "]" << A[i+1] << endl;
        }
    }

    // 出力
    cout << step << endl;
    return 0;  
}


Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

long long gcd(long long m, long long n){
    while (n > 0){
        long long r = m % n;
        m = n;
        n = r;
    }
    return m;
}

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

    long long x[N];
    for(int i=0;i<N;i++){
        cin >> x[i];
        x[i] = x[i] - X;
    }

    long long res;
    res = abs(x[0]);
    for(int i=0;i<N;i++){
        res = gcd(res, abs(x[i]));
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	float a, b, c, d, e, f;
	float aa, bb, cc, dd, ee, ff;
	float x, y;
	
	while (scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f) != EOF){
		aa = a * d; bb = b * d; cc = c * d;
		dd = d * a; ee = e * a; ff = f * a;
		bb -= ee; cc -= ff;
		cc /= bb; y = cc;
		c -= b * y;
		c /= a;
		x = c;
		
		printf("%.3f %.3f\n", x, y);
	}
	
	return (0);
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
int keta_kount(int x){
  int keta_count = 0;
  while(x > 0){
    keta_count++;
    x /=10;
  }
  return keta_count;
}
int main(){
int N;
cin >> N;
int all_count= 0;
for(int i = 1;i<=N;i++){
  if(keta_kount(i)%2 != 0){
    all_count++;
  }
}
cout << all_count<<endl;
}

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

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            var word = Console.ReadLine().Split(' ');
            x = int.Parse(word[0]);
            if(x == 3 || x == 5 || x == 7)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main() {
	int K, N; cin >> K >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	int max_d = 0;
	for (int i = 0; i < N; ++i) {
		int d = (A[(i + 1) % N] - A[i] + K) % K;
		max_d = max(max_d, d);
	}
	cout << (K - max_d) << endl;
	return 0;
}

Measured memory_bytes: 1024
//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define ALL(a)					(a).begin(),(a).end()
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	if (A + B >= C) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}



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

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

	int team = n*3;
	int  a[500000];
	for(int i=0;i<team;++i) cin>>a[i];

	sort(a,a+team,greater<int>());
	long long sum = 0;
	int pick = 1;
	for(int i=0;i<n;++i){
		sum += a[pick];
		pick += 2;
	}

	cout<<sum<<endl;
}

Measured memory_bytes: 1408