akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1e9 + 7
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
int main() {
    ll k;
    string ss;
    cin >> k;
    cin >> ss;
    if(ss.length() <= k)
        cout << ss << "\n";
    else {
        string ans = ss.substr(0, k) + "...";
        cout << ans << "\n";
    }
}



Measured memory_bytes: 3564
#include <iostream>
#include <queue>
#include <vector>

int main()
{
    using namespace std;
    int n, q, query, x, t;
    cin >> n >> q;
    vector<priority_queue<int> > Q(n);
    for (int i = 0; i < q; ++i)
    {
        cin >> query;
        switch (query)
        {
        case 0:
            cin >> t >> x;
            Q[t].push(x);
            break;
        case 1:
            cin >> t;
            if (!Q[t].empty()) //Q[t]が空でなければ
            {
                cout << Q[t].top() << endl;
            }
            break;
        case 2:
            cin >> t;
            if (!Q[t].empty())
            {
                Q[t].pop();
            }
            break;
        }
    }
}


Measured memory_bytes: 4044
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

K = int(input())
res = [-1]*N
for i in range(K):
    v, p = map(int, input().split())
    v -= 1
    if i == 0:
        root = v
    res[v] = p


# トポソ, 偶奇チェック
dist = [-1] * N
parent = [-1] * N
dist[root] = 0
order = []
node = [root]
bm = (dist[root] ^ res[root]) & 1
while node:
    s = node.pop()
    order.append(s)
    if res[s] != -1 and bm != (dist[s] ^ res[s]) & 1:
        print("No")
        exit()
    for t in edge[s]:
        if dist[t] != -1:
            continue
        parent[t] = s
        dist[t] = dist[s] + 1
        node.append(t)

inf = 10**18
inf = float("inf")
U = [inf] * N
L = [-inf] * N
for v in order[::-1]:
    if res[v] != -1:
        if res[v] < L[v] or U[v] < res[v]:
            print("No")
            exit()
        U[v] = res[v]
        L[v] = res[v]

    if v != root:
        p = parent[v]
        if L[v] - 1 > U[p] or U[v] + 1 < L[p]:
            print("No")
            exit()
        L[p] = max(L[p], L[v] - 1)
        U[p] = min(U[p], U[v] + 1)

for v in order[1:]:
    p = parent[v]
    if L[v] <= res[p] + 1 <= U[v]:
        res[v] = res[p] + 1
    else:
        res[v] = res[p] - 1

print("Yes")
print(*res, sep="\n")

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

int main(){
    string S,T;
  	cin >> S >> T; 
    int count=0;
    for(int i=0;i<S.size();i++){
       if(S[i]!=T[i]){
            count++;
        }
    }
    cout << count << endl;
}

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

int main(int argc, char *argv[])
{
    int H, N;
    cin >> H >> N;
    const int INF = 1e9;
    vector<int> dp(H + 1, INF);
    dp[0] = 0;
    for (int i = 1; i <= N; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = 1; j <= H; j++) {
            dp[j] = min(dp[j], dp[max(0, j - a)] + b);
        }
    }
    cout << dp[H] << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
#define chmax(a, b) a = max(a, b)
using ll = long long;

ll dp[109][100009];

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>w(n);
  vector<int>v(n);
  rep(i,n)cin>>w[i]>>v[i];
  rep(i,n){
    rep(j,k+1){
      chmax(dp[i+1][j],dp[i][j]);
      if(j+w[i]<=k){
        chmax(dp[i+1][j+w[i]],dp[i][j]+v[i]);
      }
    }
  }
  cout<<dp[n][k]<<endl;
  return(0);
}


Measured memory_bytes: 79360
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, C[5010], Mod = 1000000007;
vector<int>E[5010];
void DFS(int a, int pp) {
	int i;
	C[a] = 1;
	for (i = 0; i < E[a].size(); i++) {
		if (E[a][i] != pp) {
			DFS(E[a][i], a);
			C[a] += C[E[a][i]];
		}
	}
}
int D[5010][5010], F[5010], Comb[5010][5010];
int Calc(vector<int> &V) {
	int i, j, k, sz = V.size(), s = 0;
	D[0][0] = 1;
	for (i = 0;i<sz; i++) {
		int c = V[i];
		for (j = 0; j <= s + c; j++)D[i + 1][j] = 0;
		for (j = 0; j <= s; j++) {
			for (k = 0; k <= c; k++) {
				D[i + 1][j + k] = (D[i + 1][j + k] + 1ll * D[i][j] * Comb[c][k] % Mod * Comb[c][k] % Mod * F[k]) % Mod;
			}
		}
		s += c;
	}
	for (i = s; i >= 0; i--) {
		int r = 1ll * D[sz][i] * F[s - i] % Mod;
		for (j = i + 1; j <= s; j++) {
			r = (r - 1ll * D[sz][j] * Comb[j][i]%Mod+Mod) % Mod;
		}
		D[sz][i] = r;
	}
	return D[sz][0];
}
int main() {
	int i, a, b, j;
	scanf("%d", &n);
	F[0] = 1;
	for (i = 1; i <= n; i++)F[i] = 1ll * F[i - 1] * i%Mod;
	for (i = 0; i <= n; i++) {
		Comb[i][0] = 1;
		for (j = 1; j <= i; j++) {
			Comb[i][j] = (Comb[i - 1][j - 1] + Comb[i - 1][j]) % Mod;
		}
	}
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);	
	}
	DFS(1, 0);
	int M = 1e9, pv = -1;
	for (i = 1; i <= n; i++) {
		if (C[i] * 2 >= n && M > C[i])M = C[i], pv = i;
	}
	if (M * 2 == n) {
		int res = 1;
		for (i = 1; i <= n / 2; i++) {
			res = 1ll * res*i*i%Mod;
		}
		printf("%d\n", res);
		return 0;
	}
	vector<int>V;
	for (i = 0; i < E[pv].size(); i++) {
		int t = C[E[pv][i]];
		if (t > M) t = n-M;
		V.push_back(t);
	}
	int s = Calc(V);
	V.push_back(1);
	printf("%d\n", (s + Calc(V)) % Mod);
}

Measured memory_bytes: 194944
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(){
    string s;
    int n;
    cin >> s;
    n = stoi(s);
    int ans;
    if (s.size() % 2 == 0)
    {
        ans = 0;
        for (int i = 1; i <s.size(); i += 2)
        {
            ans += 9*pow(10, s.size() - (i+1));
            
        }
        
    }
    else
    {
        ans = n;
        for (int i = 1; i < s.size() - 1; i += 2)
        {
            ans -= 9*pow(10, s.size() - (i+1));
        }
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll dp[105][105][305][2]={0};
ll col[105][105];
const ll inf=1744174417441744;
int main(){
  ll h,w;
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char c;
      cin>>c;
      if(c=='.') col[i][j]=0;
      else col[i][j]=1;
    }
  }
  for(int i=0;i<105;i++){
    for(int j=0;j<105;j++){
      for(int k=0;k<305;k++){
        for(int l=0;l<2;l++){
          dp[i][j][k][l]=inf;
        }
      }
    }
  }
  if(col[0][0]==0) dp[0][0][0][0]=0;
  else dp[0][0][1][1]=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<305;k++){
        if(i+1<h){
          if(col[i+1][j]==0){
            dp[i+1][j][k][0]=min(dp[i+1][j][k][0],dp[i][j][k][1]);
            dp[i+1][j][k][0]=min(dp[i+1][j][k][0],dp[i][j][k][0]);
          }
          else{
            dp[i+1][j][k][1]=min(dp[i+1][j][k][1],dp[i][j][k][1]);
            if(k>0) dp[i+1][j][k][1]=min(dp[i+1][j][k][1],dp[i][j][k-1][0]+1);
          }
        }
        if(j+1<w){
          if(col[i][j+1]==0){
            dp[i][j+1][k][0]=min(dp[i][j+1][k][0],dp[i][j][k][1]);
            dp[i][j+1][k][0]=min(dp[i][j+1][k][0],dp[i][j][k][0]);
          }
          else{
            dp[i][j+1][k][1]=min(dp[i][j+1][k][1],dp[i][j][k][1]);
            if(k>0) dp[i][j+1][k][1]=min(dp[i][j+1][k][1],dp[i][j][k-1][0]+1);
          }
        }
      }
    }
  }
  for(int k=0;k<305;k++){
    if(dp[h-1][w-1][k][0]!=inf||dp[h-1][w-1][k][1]!=inf){
      cout<<k<<endl;
      return 0;
    }
  }
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

ll mod_pow(ll n,ll p){
  if(p<0)return 0;
  ll ans=1LL;
  while(p){
    if(p&1)ans*=n;
    n*=n;
    p>>=1;
    ans%=MOD;
    n%=MOD;
  }
  return ans;
}

signed main(){

  string s;
  cin>>s;

  int n = s.size();
  vector<ll> a(n+1),c(n+1),q(n+1);
  rep(i,n){
    if(s[i]=='A')a[i+1]++;
    if(s[i]=='C')c[i+1]++;
    if(s[i]=='?')q[i+1]++;
  }
  rep(i,n){
    a[i+1] += a[i];
    c[i+1] += c[i];
    q[i+1] += q[i];
  }
  ll ans = 0;
  rep(i,n){
    if(s[i]=='A'||s[i]=='C')continue;
    ll aq = (a[i]*mod_pow(3,q[i])+q[i]*mod_pow(3,q[i]-1))%MOD;
    ll cq = ((c[n]-c[i])*mod_pow(3,q[n]-q[i+1])+(q[n]-q[i+1])*mod_pow(3,q[n]-q[i+1]-1))%MOD;
    dump(aq,cq);
    ans += aq*cq%MOD;
    ans %= MOD;
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;



int main(void) {
  ll t1, t2;
  ll a1, a2, b1, b2, c1, c2, t;
  cin >> t1 >> t2;
  cin >> a1 >> a2;
  cin >> b1 >> b2;
  c1=a1-b1;
  c2=a2-b2;
  
  ll P=c1*t1, Q=c2*t2;
  if(P>0) {
    P*=-1; Q*=-1;
  }
  
  if(P+Q<0) {
    pt(0);
  }else if(P+Q==0) {
    pt("infinity");
  }else {
    pt(abs(P)/(P+Q)*2+(abs(P)%(P+Q)!=0));
  }
  
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

template< typename T >
struct BinaryIndexedTree {
    vector< T > data;

    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }

    T sum(int k) {
        T ret = 0;
        for(++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    void add(int k, T x) {
        for(++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

template< typename T >
vector<int> compress(const vector<T> &v) {
    int n = v.size();
    vector<int> res(n);
    vector< T > tmp = v;
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
    for(int i=0; i<n;i++) {
        res[i] = distance(tmp.begin(), lower_bound(tmp.begin(), tmp.end(), v[i]));
    }
    return res;
}

int main(void) {
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> a(N+1);
    for(int i=1; i<=N; i++) {
        cin >> a[i];
        a[i] -= K;
    }

    partial_sum(a.begin(), a.end(), a.begin());

    auto cmp = compress(a);

    int64_t ans = 0;
    BinaryIndexedTree<int64_t> bit(N+1);
    for(int i=0; i<=N; i++) {
        cerr << cmp[i] << endl;
        ans += bit.sum(cmp[i]);
        bit.add(cmp[i], 1);
    }

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


Measured memory_bytes: 4224
#include <iostream>
#include <utility>

using namespace std;

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

	if (n > m) swap(n, m);

	long long ans;
	if (n > 1 && m > 1) {
		ans = (n - 2) * (m - 2);
	} else if (m > 1) {
		ans = m - 2;
	} else {
		ans = 1;
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cout << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

using P = pair<int,int>;
//random_device seed_gen; mt19937_64 mtrand(seed_gen());
//////////////////////////////////////////

int p;
int inv(int i){
  return i == 1 ? 1 : p - inv(p % i) * (p / i) % p;
};

int main(){
  in(p);
  int a[3000];
  rep(i , p) in(a[i]);

  vi ans(p,0);
  // k=0
  ans[0] = a[0];
  // k=1~p-2
  for(int l = 1; l <= p - 1; l++){
    int cur = 1;
    for(int k = p - 1; k >= 1; k--){
      ans[k] += a[l] * cur;
      cur = cur * l % p;
    }
  }
  for(int k = 1, x = inv(p-1); k <= p - 1; k++){
    ans[k] = (ans[k] % p) * x % p;
  }
  // k = p-1
  ans[p-1] = (ans[p-1] + p - a[0]) % p;

  out(ans);
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

A = getList()
for i in range(len(A)):
    if A[i] == 0:
        print(i + 1)
        break

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


import numpy as np
x,y,z,K = list(map(int, input().split()))
a = np.array(list(map(int, input().split())), dtype=np.int64)
b = np.array(list(map(int, input().split())), dtype=np.int64)
c = np.array(list(map(int, input().split())), dtype=np.int64)
ab = (a + b.reshape(-1,1)).reshape(-1)
ab.sort()
c.sort()
abk = ab[-K:]
ck = c[-K:]
l = (abk + ck.reshape(-1,1)).reshape(-1)
l.sort()
l = l[::-1]
write("\n".join(map(str, l[:K])))

Measured memory_bytes: 58548
#include<iostream>
#include<algorithm>

using namespace std;

long long gcd(long long a,long long b)
{
    if(a < b) swap(a,b);
    if(a % b ==0)
    {
        return b;
    }
    else
    {
        return(gcd(b,a%b));
    }
    
}
int main()
{
    long long a,b;cin >> a >> b;

    cout << (a * b) /gcd(a,b)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
typedef std::pair<int,int> P;


	ll ans=0;
	ll N,A[500010];


int main(){
	ios_base::sync_with_stdio(false);
	cin>>N;
	REP(i,N)cin>>A[i];
	REP(i,N){
		int a=A[i];
		while(a%2==0){
			a/=2;
			ans++;
		}
	}
	cout<<ans<<endl;
}

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

int main() {
    string s;
    cin>>s;
    //key was not to look for the whole string but just look for any three character as
    //it would also accomplish the task we were trying to figure out
    if(s.length()==2){
        if(s[0]==s[1])cout<<1<<" "<<2<<endl;
        else cout<<-1<<" "<<-1<<endl;
    }else{
        for(int i=0;i<s.length()-2;i++){
            if(s[i]==s[i+1] || s[i+1]==s[i+2] || s[i+2]==s[i]){
                cout<<i+1<<" "<<i+3<<endl;
                return 0;
            }    
        }
        
        cout<<-1<<" "<<-1<<endl;
        return 0;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin>>n>>s;

    int cnt=1;
    char mark=s[0];
    for(int i=1;i<s.size();i++){
        if(mark != s[i]){
            cnt++;
            mark=s[i];
        }
    }
    cout << cnt << endl;
}


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

int main() {
  string s;
  cin >> s;
  
  if(s.at(5) == '1'){
    cout << "TBD" << endl;
  }
  
  else if(s.at(6) >= '5'){
    cout << "TBD" << endl;
  }
  
  else{
    cout << "Heisei" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
using namespace std;

int n;
char str[100005];
queue<int> que;

int check(char str[], int n);

int main()
{
	str[0] = '0';
	scanf("%s", &str[1]);

	n = strlen(str + 1);

	if (str[1] == '0' || str[n] == '1' ||
			check(str, n)) {
		cout << -1 << endl;
	}
	else {
		que.push(1);

		for (int i = 2; i <= n; i++) {
			if (str[i] == '1' || i == n) {

				while (!que.empty()) {
					printf("%d %d\n", i, que.front());
					que.pop();
				}

			}
			que.push(i);
		}
	}

	return 0;
}

int check(char str[], int n)
{
	int i = 1;

	while (i <= n && str[i] == str[n - i]) {
		i++;
	}

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


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    int n, x = 0, m = 0;
    string s;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> s[i];


    for(int i = 0; i < n; i++)
    {
        if(s[i] == 'I')
            x++;
        if(s[i] == 'D')
            x--;
        if(x > m)
            m = x;
    }
    cout << m ;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
  int a;
  cin >> a;
  int b = 0;
  b += a % 2;
  b += a % 20 / 10;
  b += a % 200 / 100;
  cout << b << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
N = len(S)
d = {}
d1 = {}
for i in range(N):
    if S[i] in d:
        if d[S[i]] != T[i]:
            print('No')
            exit()
    elif T[i] in d1:
        if d1[T[i]] != S[i]:
            print('No')
            exit()
    else:
        d[S[i]] = T[i]
        d1[T[i]] = S[i]

print('Yes')



Measured memory_bytes: 3632
#include<algorithm>
#include<iostream>
#include<map>

int main(){
  int N; std::cin >> N;
  std::map<int, int> cnt {};
  for(auto i=0; i<N; ++i){
    int j; std::cin >> j;
    ++cnt[j];
  }
  auto max = 0;
  for(auto& p: cnt){
    auto my = p.second;
    auto s = cnt.find(p.first-1);
    if(s != cnt.end())
      my += s->second;
    s = cnt.find(p.first+1);
    if(s != cnt.end())
      my += s->second;
    max = std::max(max, my);
  }
  std::cout << max << '\n';
}


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

int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    rep(i,n-1)    cin >> b[i];
    vector<int> a(n);
    a[n-1] = b[n-2];
    a[0] = b[0];
    for(int i = n-2; 0 < i; --i){
            a[i] = min(b[i], b[i-1]);
    }

    cout << accumulate(a.begin(), a.end(), 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;


int main(){
	int n, a[100];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	reverse(a, a + n);
	printf("%d", a[0]);
	for (int i = 1; i < n; i++) {
		printf(" %d", a[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 2672
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(void){
  int N, D, X;
  cin >> N >> D >> X;
  int A[N];
  rep(i, N)
    cin >> A[i];
  //入力終了

  //1日目に食べる分を0日目にずらす
  D--;
  
  int ans = 0;
  rep(i, N){
    //1日目に食べるため1で初期化
    int tmp = 1;
    //0日目から何回食べられるか
    tmp += D/A[i];
    ans += tmp;
  }

  //解答
  //残っていたチョコを足す
  cout << ans + X << endl;
  
  return 0;
}


Measured memory_bytes: 3596
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int rem = n % 500;
        if(a >= rem) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 20948
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 500;

class P{
public:
  string name;
  int wd, st;
  P(){}
  P(string name, int wd, int st) : name(name), wd(wd), st(st) {}
  bool operator < (const P& s) const {
    if(wd == s.wd) return st < s.st;
    return wd < s.wd;
  }
};

int n, m;
vector<P> data;
vector<int> f;
bool used[N];

int solve(){
  fill(used, used+n, false);
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(!used[j]) continue;
      if(data[f[i]].wd != data[j].wd) continue;
      if(data[f[i]].st <= data[j].st && data[j].st < data[f[i]].st + 30 ||
        data[j].st <= data[f[i]].st && data[f[i]].st < data[j].st + 30) return -1;
    }
    used[f[i]] = true;
  }
  int res = m;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(!used[j]) continue;
      if(data[i].wd != data[j].wd) continue;
      if(data[i].st <= data[j].st && data[j].st < data[i].st + 30 ||
        data[j].st <= data[i].st && data[i].st < data[j].st + 30) goto FAILED;
    }
    res++;
    used[i] = true;
    FAILED:;
  }
  /*for(int i=0;i<n;i++){
    cout << data[i].name << ' ' << data[i].wd << ' ' << data[i].st;
    if(used[i]) cout << " o" << endl;
    else cout << " x" << endl;
  }
  cout << "================" << endl;*/
  return res;
}

main(){
  while(cin >> n && n){
    data.clear();
    f.clear();
    for(int i=0;i<n;i++){
      string name, time;
      int wd, st;
      cin >> name >> wd >> time;
      st = atoi(time.substr(0, (int)time.size()-2).c_str()) * 60 + atoi(time.substr((int)time.size()-2).c_str());
      data.push_back(P(name, wd, st));
    }
    sort(data.begin(), data.end());
    cin >> m;
    for(int i=0;i<m;i++){
      string in;
      cin >> in;
      for(int j=0;j<n;j++) if(data[j].name == in) f.push_back(j);
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1292
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
  int d, n, k = 1;
  cin >> d >> n;
  for(int i=0; i<d; i++)
    k *=100;
  if(n == 100) cout << 101*k << endl;
  else cout << n*k << endl;
}

Measured memory_bytes: 256
#ifndef ATCODER_DSU_HPP
#define ATCODER_DSU_HPP 1

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder

#endif  // ATCODER_DSU_HPP




#include <bits/stdc++.h>
#include <iostream>
// struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0 ; i < n ; i++) // for i in range(b)
#define FOR(i,a,b) for(ll i = a ; i < b ; i++) // for i in range(a,b)
#define FORD(i,a,b) for(ll i = a ; i > b ; i--) // for i in range(a,b,-1)
#define ALL(x) x.begin(),x.end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int IINF = 1'001'001'001;
const ll INF = 1'001'001'001'001'001'001ll;
const int MOD = 1'000'000'007;


void solve(){
    int n,m; cin >> n >> m;
    dsu uf = dsu(n);
    REP(i,m){
        int x,y,z; cin >> x >> y >> z;
        uf.merge(x-1,y-1);
    }
    cout << uf.groups().size() << endl;
}

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

Measured memory_bytes: 9748
w=list(input());n=len(w);t=-1
def Z(s):
    m=len(s);z=[0]*m;c=0;f=[1]*m;
    for i in range(1,m):
        if i+z[i-c]<c+z[c]:z[i]=z[i-c]
        else:
            j=max(0,c+z[c]-i)
            while i+j<n and s[j]==s[i+j]:j=j+1
            z[i]=j;c=i
    for p in range(1,m):
        for k in range(2,z[p]//p+2):f[k*p-1]=0
    return f
for j in range(1,n//2+1):
    if n%j==0 and w[:n-j]==w[j:]:t=j;break;
if t==-1:print ('1\n1')
elif t==1:print (n);print (1)
else:
    zl=Z(w)
    w.reverse()
    zr=Z(w)
    cnt=0
    for i in range(0,n-1):
        if zl[i] and zr[n-2-i]:cnt=cnt+1
    print(2);print(cnt);


Measured memory_bytes: 26500
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
long double ans,sum,n,d,x,d1,x1,sum1;
int main()
{
//	freopen("Pushing Balls.in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>d>>x; sum=2*d*n+n*x*(2*n-1);
	for(int i=n;i;i--)
	{
		ans+=sum/2/n;
		d1=(2*d+2*n*d+5*x)/2/n, sum1=sum-(2*d+(2*n-1)*x)/n;
		n-=1;
		x1=(sum1-2*d1*n)/n/(2*n-1);
		d=d1, x=x1, sum=sum1;
	}
	printf("%.15lf\n",(double)ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100005;

int n,m,k,tot[4],b[N*2],val[N],p1[N],p2[N];
struct data{int x,id;}a[4][N*2];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

bool cmp(data a,data b)
{
	return a.x<b.x;
}

bool check(int x,int y)
{
	return x==0||x==n||y==0||y==m;
}

int main()
{
	n=read();m=read();k=read();
	for (int i=1;i<=k;i++)
	{
		int x1=read(),y1=read(),x2=read(),y2=read();
		if (check(x1,y1)&&check(x2,y2))
		{
			if (!x1) a[0][++tot[0]]=(data){y1,i};
			else if (y1==m) a[1][++tot[1]]=(data){x1,i};
			else if (x1==n) a[2][++tot[2]]=(data){y1,i};
			else a[3][++tot[3]]=(data){x1,i};
			if (!x2) a[0][++tot[0]]=(data){y2,i};
			else if (y2==m) a[1][++tot[1]]=(data){x2,i};
			else if (x2==n) a[2][++tot[2]]=(data){y2,i};
			else a[3][++tot[3]]=(data){x2,i};
		}
	}
	for (int i=0;i<4;i++) sort(a[i]+1,a[i]+tot[i]+1,cmp);
	int s=0;
	for (int i=1;i<=k;i++) val[i]=rand()*rand()+1;
	for (int j=0;j<2;j++)
		for (int i=1;i<=tot[j];i++)
		{
			int x=a[j][i].id;
			s++;b[s]=b[s-1]^val[x];
			if (!p1[x]) p1[x]=s;
			else p2[x]=s;
		}
	for (int j=2;j<4;j++)
		for (int i=tot[j];i>=1;i--)
		{
			int x=a[j][i].id;
			s++;b[s]=b[s-1]^val[x];
			if (!p1[x]) p1[x]=s;
			else p2[x]=s;
		}
	for (int i=1;i<=k;i++)
	{
		if (p1[i]>p2[i]) swap(p1[i],p2[i]);
		if (b[p2[i]]^b[p1[i]-1]) {puts("NO");return 0;}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 7296
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/23
Solved on 2019/3/
@author: shinjisu
"""


# ABC 0xx C xxx
#import math
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]


def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替


class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    dic = {}
    for e in A:
        if e in dic:
            dic[e] += 1
        else:
            dic[e] = 1
    d.dmp((dic), 'dic')
    side = []
    for k in dic.keys():
        if dic[k] >= 4:
            side.append(k)
            side.append(k)
        elif dic[k] >= 2:
            side.append(k)
    side.sort()
    d.dmp((side), 'side')
    if len(side) >= 2:
        return side[-1]*side[-2]
    else:
        return 0


ans = prob()
print(ans)


Measured memory_bytes: 17960
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  return ~~(48-intShift());
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
7
50
30
50
100
50
80
30
`);

Measured memory_bytes: 7372
#include <iostream>
#include <vector>

using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    int cnt = 0;
    for (int i = 0; i < n; ++i)
        cin >> v[i];
    for (int i = 1; i < n - 1; ++i) {
        int a = v[i - 1], b = v[i], c = v[i + 1];
        if ((a < b && b < c) || (c < b && b < a))
            ++cnt;
    }
    cout << cnt << endl;
    return 0;
}


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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)

int main(){
    int n,m,ans=0,chk=1;
    sc2(n,m);
    int d[8][8];
    vector <int> v(n);
    rep(i,n) v[i]=i;
    rep(i,8) rep(j,8) d[i][j]=0;
    rep(i,m) {
        int a,b;
        sc2(a,b);
        d[a-1][b-1]=1;
        d[b-1][a-1]=1;
    }
    do {
        if (v[0]!=0) continue;
        chk=1;
        rep(i,n-1) chk*=d[v[i+1]][v[i]];
        ans+=chk;
    } while (next_permutation(v.begin(),v.end()));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second

using namespace :: std;

const ll maxn=52;
const ll mod=1e9+7;
const ll inf=1e9+500;


ll a[maxn];
int main(){
ll n;
cin>>n;
for(ll i=0;i<n;i++){
	cin>>a[i];
}
ll ans=0;
while(1){
	ll res=0;
	for(ll i=0;i<n;i++){
		res+=a[i]/n;
	}	
	if(res==0){
		break;
	}
	ans+=res;
	for(ll i=0;i<n;i++){
		a[i]=(a[i]%n)+(res-a[i]/n);
	}
}
cout<<ans;


}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;


int main() {

	int n, m;
	cin >> n >> m;
	vector<vector<int>>a(m);

	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		if (x > m)continue;
		a[m - x].push_back(y);
	}
	priority_queue<int>t;
	long long int ans = 0;
	for (int i = m - 1; i >= 0; i--) {
		for (int j = 0; j < a[i].size(); j++)t.push(a[i][j]);

		if (t.size()) {
			ans += t.top();
			t.pop();
		}
	}
	cout << ans << endl;


	return 0;


}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int x;
		scanf("%d",&x);
		if (n<x)
		{
			printf("-1");
			return 0;
		}
		else n-=x;
	}
	printf("%d",n); 
	return 0; 
}

Measured memory_bytes: 3816
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>

#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

using namespace std;

int main(){

  char word;


  while(1){

    if((word=getchar())==EOF) break;

    if(islower(word)==0){
      word=tolower(word);
    }
    else if(isupper(word)==0){
      word=toupper(word);
    }
      cout <<word;

  }
  return 0;
}

Measured memory_bytes: 1088
/*Unknown_Ghost*/
/*AGC033D Complexity*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;

#define LL long long
#define MAXN 200
#define MOD 998244353
#define Pr pair<int,int>
#define X first
#define Y second
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}
int add(int x,int y){return (x+y>=MOD)?x+y-MOD:x+y;}
int dec(int x,int y){return (x-y<0)?x-y+MOD:x-y;}
int mul(int x,int y){return 1LL*x*y%MOD;}

int n,m;
char c[MAXN+5][MAXN+5];
int f[MAXN+5][MAXN+5][MAXN+5],g[MAXN+5][MAXN+5][MAXN+5];
int main()
{
    n=read(),m=read();
    for(int i=1;i<=n;i++)scanf("%s",c[i]+1);
    for(int i=n;i>=1;i--)
        for(int j=i;j<=n;j++)
            for(int k=m;k>=1;k--)
            if(i==j)f[i][j][k]=(c[i][k]==c[i][k+1])?f[i][j][k+1]:k+1;
            else f[i][j][k]=(c[i][k]==c[i+1][k])?min(f[i][i][k],f[i+1][j][k]):k;
    for(int ans=0;;ans++){
        if(f[1][n][1]==m+1)
        {printf("%d\n",ans);return 0;}
        for(int i=n;i>=1;i--)
            for(int j=i;j<=n;j++)
                for(int k=m;k>=1;k--){
                    g[i][j][k]=(f[i][j][k]==m+1)?m+1:f[i][j][f[i][j][k]];
                    int l=i,r=j-1;
                    while(l<=r){
                        int mid=(l+r)>>1;
                        if(f[i][mid][k]<=f[mid+1][j][k])
                            g[i][j][k]=max(g[i][j][k],f[i][mid][k]),r=mid-1;
                        else g[i][j][k]=max(g[i][j][k],f[mid+1][j][k]),l=mid+1;
                    }
                }
        for(int i=1;i<=n;i++)
            for(int j=i;j<=n;j++)
                for(int k=1;k<=m;k++)
                f[i][j][k]=g[i][j][k];
    }
}


Measured memory_bytes: 63488
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    a,b,c,d=mis()
    lcm = c*d//gcd(c,d)
    print((b - (a-1)) - (b//c - (a-1)//c) - (b//d - (a-1)//d) + (b//lcm - (a-1)//lcm))

main()







Measured memory_bytes: 5428
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <cassert>
#include <deque>
#include <cstring>
#include <sys/time.h>
#include <sys/time.h>
using namespace std;
long long INF = 2e9;
int idx[220][5010];
 
int st,en;
 
void solve(long long N, long long M, vector<long long> A, vector<vector<long long>> B){
	
	memset(idx,-1,sizeof(idx));
	long long ans = 0;
	for(int i = 0 ; i < N ; i++){
		long long sub = 0;
		for(int j = 0 ; j < M ; j++){	
			sub += B[i][j];
		}
		ans = max(sub,ans);
	}
	for(int i = 1 ; i < A.size() ; i++)
		A[i] = A[i-1] + A[i];
	//cout << "><" << endl;
	for(int i = 0 ; i < M ; i++){
		deque<long long> X;
		deque<long long> Y;
		
		X.push_front(INF);
		Y.push_front(N);
		
		for(int j = N - 1 ; j >= 0 ; j--){
			int l = 0, r = X.size() - 1;
			while( l != r ){
				int m = (l+r) / 2;
				if( X[m] > B[j][i] ){
					r = m;
				}else{
					l = m + 1;
				}
			}
			idx[i][j] = Y[r];
			//cout << "idx[" << i << "][" << j << "]" << "=" << Y[r] << "(" << B[j][i] << ")" << endl;
			assert(j < Y[r]);
			
			while( X.front() <= B[j][i] ){
				X.pop_front();
				Y.pop_front();
			}
			X.push_front(B[j][i]);
			Y.push_front(j);
		}
	}
	
	for(int i = N-1 ; i >= 0 ; i--){
		en = clock();
		//cout << en << endl;
		if( 1.0 * (en - st) / CLOCKS_PER_SEC > 1.9  ) break;
		//cout << 1.0 * (en - st) / CLOCKS_PER_SEC  << endl;
		long long mx[200]={};
		int id[200]={};
		long long dist = 0;
		
		
		for(int j = i ; j < N ; ){
			
			for(int k = 0 ; k < M ; k++){	
				mx[k] = max(mx[k],B[j][k]);
			}
			long long sub = 0;
			for(int k = 0 ; k < M ; k++){	
				sub += mx[k];
			}
			ans = max(sub-dist,ans);
			//cout << sub << "|" <<  dist << "[" << i << "," << j << "]" << endl;
			int nx = N;
			
			for(int k = 0 ; k < M ; k++)
				id[k] = max(id[k], idx[k][j]);
			
			for(int k = 0 ; k < M ; k++)
				nx = min(id[k],nx);
			dist += A[nx-1] - (j?A[j-1]:0);
			//cout << j << "->" << nx << " " << N << endl;
			j = nx;
			//cout << i << " " << nx << endl;
			
			
		}
	}
	cout << ans << endl;
}
 
int main(){
	st = clock();
 
	long long N;
	long long M;
	scanf("%lld",&N);
	vector<long long> A((N-1)-1+1);
	scanf("%lld",&M);
	vector<vector<long long>> B(N-1+1,vector<long long>(M-1+1));
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		for(int j = 0 ; j <= M-1 ; j++){
			scanf("%lld",&B[i][j]);
		}
	}
	solve(N, M, A, B);
	return 0;
 
/*
	long long N;
	long long M;
	//scanf("%lld",&N);
	N = 5000;
	M = 200;
	vector<long long> A((N-1)-1+1);
	//scanf("%lld",&M);
	vector<vector<long long>> B(N-1+1,vector<long long>(M-1+1));
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		//scanf("%lld",&A[i]);
		A[i] = rand() % 1000;
	}
	for(int i = 0 ; i <= N-1 ; i++){
		for(int j = 0 ; j <= M-1 ; j++){
			B[i][j] = rand() % 1000000;
		}
	}
	solve(N, M, A, B);
	return 0;
*/
}

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

long long max_8(long long* m) {
    long long max = m[0];

    for(int i = 1; i < 8; i++) {
        if(m[i] > max) {
            max = m[i];
        }
    }
    return max;
}

long long cou(long long* s, int N, int M, bool sign) {
    long long sum = 0;
    if(sign) {
        for(int i = 0; i < M; i++) {
            sum += s[i];
        }
        return -1 * sum;
    } else {
        for(int i = N - 1; i > N - 1 - M; i--) {
            sum += s[i];
        }
        return sum;
    }
}

int main() {
    using namespace std;

    int N, M;
    cin >> N >> M;
    long long x[N], y[N], z[N], s1[N], s2[N], s3[N], s4[N];
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> z[i];
        s1[i] = x[i] + y[i] + z[i];
        s2[i] = x[i] + y[i] - z[i];
        s3[i] = x[i] - y[i] + z[i];
        s4[i] = x[i] - y[i] - z[i];
    }
    sort(s1, s1 + N);
    sort(s2, s2 + N);
    sort(s3, s3 + N);
    sort(s4, s4 + N);
    
    long long m[8];
    m[0] = cou(s1, N, M, true);
    m[1] = cou(s2, N, M, true);
    m[2] = cou(s3, N, M, true);
    m[3] = cou(s4, N, M, true);
    m[4] = cou(s1, N, M, false);
    m[5] = cou(s2, N, M, false);
    m[6] = cou(s3, N, M, false);
    m[7] = cou(s4, N, M, false);

    cout << max_8(m) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


const int MAX = 3000000;
const ll MOD = 1e9+7;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll r1, c1, r2, c2;
int xleft(int x, int y) {
	return max(-c2+x+y,r1);
}
int yleft(int x, int y) {
	return min(-r1+x+y,c2);
}
ll morau(int x, int y) {
	ll ret = 0;
	if (x == r1)ret += comb(x+y-1, x-1);
	if (y == c1)ret += comb(x+y-1, y-1);
	return ret;
}
ll kubaru(int x, int y) {
	ll ret = 0;
	if (x != r2)ret += comb(x+y, y);
	if (y != c2)ret += comb(x+y, y);
	return ret;
}

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

	combinit();

	cin >> r1 >> c1 >> r2 >> c2;
	ll ans = 0;
	ll cursum = 0;
	for (int xr = r1; xr < r2; xr++) {
		int yr = c1;
		int xl = xleft(xr, yr);
		int yl = yleft(xr, yr);
		ll sr = comb(xr+yr,yr);
		ll sl = comb(xl+yl,yl);
		int fl = ((xr == xl) && (yr == yl));
		//貰うパート
		cursum += morau(xr,yr);
		if(!fl)cursum += morau(xl,yl);
		ans += cursum;
		//配るパート
		cursum = 2LL * (cursum - sr - ((!fl)?sl:0) + 10LL*MOD) % MOD;
		cursum += kubaru(xr,yr);
		if(!fl)cursum += kubaru(xl,yl);
		ans %= MOD;
		cursum %= MOD;
	}
	for (int yr = c1; yr <= c2; yr++) {
		int xr = r2;
		int xl = xleft(xr,yr);
		int yl = yleft(xr,yr);
		ll sr = comb(xr+yr,yr);
		ll sl = comb(xl+yl,yl);
		int fl = ((xr == xl) && (yr == yl));
		//貰うパート
		cursum += morau(xr, yr);
		if (!fl)cursum += morau(xl, yl);
		ans += cursum;
		//配るパート
		cursum = 2LL * (cursum - sr - ((!fl) ? sl : 0) + 10LL*MOD) % MOD;
		cursum += kubaru(xr, yr);
		if (!fl)cursum += kubaru(xl, yl);
		ans %= MOD;
		cursum %= MOD;
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 70528
#include <stdio.h>
#include <math.h>
#define mod 1000000000000000000
int main(int argc, char *argv[])
{
	long long n,i;
	scanf("%lld",&n);
	signed long long a[n],d,sum=1;
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(a[i]==0)
			sum=0;
	}
	if(!sum)goto rr;
	sum=(a[0]);
	for(i=1;i<n;i++){
		d=mod/sum;
		if(mod%sum)d++;
		if(d<a[i]){
			sum=-1;break;
		}
		sum*=a[i];
		if(sum>mod){sum=-1;
		break;}
	}rr:
	printf("%lld\n",sum);
}

Measured memory_bytes: 2452