akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define YOU setprecision
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e,f;
  string s;
  cin >>a>>b;
  a-=1,b-=1;
  cout <<a*b<<'\n';
  return (0);
}


Measured memory_bytes: 256
let id x = x


let n = Scanf.scanf "%d\n" id


let rec f = function
  | i when i * 2 > n -> []
  | i -> (n / i / 2) :: f (i * 5)


let () = print_int @@ if n mod 2 = 1 then 0 else List.fold_left (+) 0 (f 5)

Measured memory_bytes: 384
from sys import stdin
mod = 998244353
def main():
    N,S = map(int,stdin.readline().split())
    a = list(map(int,stdin.readline().split()))
    dp = [0]*(S+1)
    ans = 0
    for A in a:
        dp[0] += 1
        for i in reversed(range(A,S+1)):
            dp[i] += dp[i-A]    
            dp[i] %= mod
        ans += dp[S]
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()

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


int main() {
     int n, a;
     cin >> n >> a;
     
     int left = a;
     int right  = n+a-1;
     
     int eat = 0;
     if(right <= 0) eat = right;
     else if(left >= 0) eat  =left;
     else eat = 0;
     
     int sum =  (right+left)*(right-left+1)/2 - eat;
     
     cout << sum;
     
return 0;

}









  

Measured memory_bytes: 256
//atCoder - Sushi

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <deque>
#include <bitset>
#include <climits>
#include <cstdio>
#include <list>
#include <iomanip>

using namespace std;
#define fill(a,val) memset(a,val,sizeof(a))
#define ll long long int
double dp[302][302][302];
ll n;

double solve(int s1, int s2, int s3)
{

	if (s1 < 0 || s2 < 0 || s3 < 0)
		return 0;


	if (s1 == 0 && s2 == 0 && s3 == 0)
		return 0;

	if (dp[s1][s2][s3] > -0.9 )
		return dp[s1][s2][s3];


	dp[s1][s2][s3]  = n + s1 * solve(s1 - 1, s2, s3) + s2 * solve(s1 + 1, s2 - 1, s3) + s3 * solve(s1, s2 + 1, s3 - 1);


	dp[s1][s2][s3]  = dp[s1][s2][s3] / (s1 + s2 + s3);


	return dp[s1][s2][s3];





}

int main() {



	cin >> n;
	int s1 = 0, s2 = 0, s3 = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a == 1)
		{
			s1++;
		} else if (a == 2)
		{
			s2++;

		}
		else if (a == 3)
		{
			s3++;
		}

	}
	fill(dp, -1);

	cout << fixed << setprecision(8) << solve(s1, s2, s3);

	return 0;
}

Measured memory_bytes: 215552
package main

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

func main() {
	fsc := NewFastScanner()
	S := fsc.Next()
	result := ""
	for i := 0; i < len(S); i++ {
		if i%2 == 0 {
			result += string(S[i])
		}
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}

func (s *FastScanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 13184
H, W, M = map(int,input().split())
row = [0]*H
col = [0]*W
target = set()
for i in range(M):
    h,w = map(int,input().split())
    row[h-1] += 1
    col[w-1] += 1
    target.add((h-1,w-1))
ans = -1
for h,w in target:
    ans = max(ans, row[h]+col[w]-1)
A = max(row)
B = max(col)
a = [x for x in range(H) if row[x] == A]
b = [x for x in range(W) if col[x] == B]
cnt = 0
for i in a:
    for j in b:
        cnt += 1
        if (i,j) not in target:
            print(A+B)
            exit(0)
        if cnt > M:
            print(A+B-1)
            exit(0)
print(A+B-1)

Measured memory_bytes: 83500
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
const ll tl= 1000000007;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} 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);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(n,m);
    vl C(m); in1(C); 
    vl dp(n+1,INF);
    dp[0]=0;
    dp[1]=1;
    REP(i,m){
        REP(j,n+1){
            if(j+C[i]<=n) dp[j+C[i]]= min(dp[j]+1,dp[j+C[i]]);
        }
    }
    out(dp[n]);
}


Measured memory_bytes: 3268
#include<iostream>
#include<queue>
#include<functional>
#include<cstring>

using namespace std;

#define maxn 10240 
#define INF 0x3f3f3f3f;

typedef struct edge{
	int to,dis,cos;
	edge(){}
	edge(int to,int dis,int cos):to(to),dis(dis),cos(cos){}
};
typedef pair<int ,int> P;

vector<edge>G[maxn];

int d[maxn];
int v;//定点

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;//优先输出小数据；
	memset(d,0x3f,sizeof(d));
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty())
	{
		P p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		for(int i=0;i<G[v].size();i++)
		{
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.dis)
			{
				d[e.to]=d[v]+e.dis;
				que.push(P(d[e.to],e.to));
			}
		}
	}	
} 
int main()
{
	int m;
	while(cin>>v>>m)
	{
		if(v==0&&m==0)break;
		for(int i=0;i<v;i++)
		{
			G[i].clear();
		}
		for(int i=0;i<m;i++)
		{
			int u,v,d,c;
			cin>>u>>v>>d>>c;
			u--,v--;
			G[u].push_back(edge(v,d,c));
			G[v].push_back(edge(u,d,c)); 
		}
		dijkstra(0);
		int ans=0;
		for(int i=1;i<v;i++)
		{
			int min=INF;
			for (int j=0;j<G[i].size();j++)
			{
				if(d[G[i][j].to]+G[i][j].dis==d[i]&&G[i][j].cos<min)
				{
					min=G[i][j].cos;
				}
				
			} 
			ans+=min;
		}cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 5080
/*ॐॐ*/
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different.
Change variable names or change some Data structres or anything just make sure MOSS do not
Detect Anything.
Yours Faithfully
Shobhit Yadav */

/* I do not fear this new challenge. Rather like a true warrior I will rise to meet it. 
                                       -Prince Vegeta  */

 /* “Strength is the only thing that matters in this world. Everything else is just a delusion for the weak.” – Vegeta */

#include<bits/stdc++.h>
using namespace std;
#define ll long long 



ll N,M;
const ll int MOD = 1e9+7;
/*ll freq[200005];*/
void solve(){
   /*memset(freq,0,sizeof(freq));*/
  cin>>N;
  ll a[N];

  ll sum = 0;
  ll ans = 0;
  for(ll i = 0 ; i<N ; i++)
    cin>>a[i];


  sum = a[0];


  for(ll i = 1 ; i<N ; i++){
    ans += sum*a[i];
    ans %= MOD;
    sum += a[i];
    sum %= MOD;
  }

  cout<<ans%MOD<<'\n';




}



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

  return 0;
}


Measured memory_bytes: 5176
#include<cstdio>
#include<iostream>
const long long Maxn=1000000+10;
long long a[Maxn],cnt[Maxn][2];
long long n,ans;
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	n=read();
	for(long long i=1;i<=n;++i)
	{
		a[i]=read();
		if(i-a[i]>=0)++cnt[i-a[i]][1];
		if(i+a[i]<=n)++cnt[i+a[i]][0];
	}
	for(long long i=1;i<=n;++i)
	{
		if(i-a[i]>=0)ans+=cnt[i-a[i]][0];
		if(i+a[i]<=n)ans+=cnt[i+a[i]][1];
	}
	printf("%lld\n",ans>>1);
	return 0;
}


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

int main() {
    ll N, M, C, ans = 0;
    cin >> N >> M >> C;
    vi B(M);
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }

    for (int j = 0; j < N; j++) {
        ll x = C;
        for (int i = 0; i < M; i++) {
            ll a;
            cin >> a;
            x += a * B[i];
        }
        if (x > 0) ans++;
    }

    cout << ans << endl;
}


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

typedef tuple<int, int, int> T;
T a[222222];
int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; i++) {
        int n;
        cin >> n;
        for(int j = 0; j < n; j++) {
            int k, l, r;
            cin >> k >> l >> r;
            if(l < r)
                a[j] = {l - r, r, -k};
            else
                a[j] = {r - l, l, k};
        }
        sort(a, a + n, [](auto x, auto y) { return get<2>(x) < get<2>(y); });
        priority_queue<T> q, Q;
        long s = 0;
        for(int j = 0; j < n; j++) {
            auto [m, l, k] = a[j];
            if(k < 0)
                continue;
            q.push(a[j]), s += l;
            if(q.size() > k)
                s += get<0>(q.top()), q.pop();
        }
        for(int j = 0; j < n; j++) {
            auto [m, r, k] = a[j];
            if(k > 0)
                continue;
            Q.push(a[j]), s += r;
            if(Q.size() > n + k)
                s += get<0>(Q.top()), Q.pop();
        }
        cout << s << '\n';
    }
    return 0;
}


Measured memory_bytes: 8908
import sys

N, M = map(int, input().split())
S = input()[::-1]
ans = ''
i = 0
while i < N - M:
    found = False
    for j in range(M, 0, -1):
        if S[i + j] == '0':
            ans += str(j) + ' '
            i += j
            found = True
            break
    if not found:
        print(-1)
        sys.exit()
ans += str(N-i)
print(' '.join(ans.split()[::-1]))


Measured memory_bytes: 220568
#include <iostream>
using namespace std;
int n,ok;
int main(void){
    cin>>n;
    while(1){
        ok=1;
        for(int i=2;i*i<=n;i++){
            if(n%i==0)ok=0;
        }
        if(ok==1){
            cout<<n<<endl;
            return 0;
        }
        n++;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    vector<vector<ll>> v(3,vector<ll>(3));
    rep(i,3){
        rep(j,3){
            cin>>v[i][j];
        }
    }
    ll n, t; cin>>n;
    set<ll> s;
    rep(i,n){
        cin>>t;
        s.insert(t);
    }
    bool x=false;
    rep(i,3){
        if(s.count(v[i][0]) && s.count(v[i][1]) && s.count(v[i][2])) x=true;
    }
    rep(i,3){
        if(s.count(v[0][i]) && s.count(v[1][i]) && s.count(v[2][i])) x=true;
    }
    if(s.count(v[0][0]) && s.count(v[1][1]) && s.count(v[2][2])) x=true;
    
    if(s.count(v[0][2]) && s.count(v[1][1]) && s.count(v[2][0])) x=true;
    if(x) cout<<"Yes";
    else cout<<"No";
}

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

unsigned GetDigit(unsigned num);

int main() {
    int n, ans;
    cin >> n;
    for(int i=1; i<=n; i++) {
        if (GetDigit(i)%2 == 1) {
            ans++;
        };
    };
    cout << ans << endl;
}

unsigned GetDigit(unsigned num) {
    return to_string(num).length();
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<tuple>
#include<queue>
#define DB double
#define LL long long
#define PP std::pair<DB,DB>
#define MPP std::make_pair
#define TT std::tuple<int,int,int>
#define INF (100000000000000000)
int n, m;
std::vector<int> G[5010];
int h[5010];
std::vector<int> ans;
int main() {
	std::cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		std::cin >> a >> b;
		G[a].push_back(b);
		h[b]++;
	}
	std::queue<int> qu;
	for (int i = 1; i <= n; i++) {
		if (h[i] == 0)qu.push(i);
	}
	bool other = qu.size() - 1;
	while (!qu.empty()) {
		int q = qu.front();
		qu.pop();
		ans.push_back(q);
		for (auto u : G[q]) {
			h[u]--;
			if (h[u] == 0)qu.push(u);
		}
		if (qu.size() > 1)other = true;
	}
	for (auto u : ans) {
		std::cout << u << std::endl;
	}
	std::cout << (other ? 1 : 0) << std::endl;
	return 0;
}


Measured memory_bytes: 3860
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>

using namespace std;

struct Node {
  double lower_bound, x, y, r;

  Node(double lower_bound, double x, double y, double r) : lower_bound(lower_bound), x(x), y(y), r(r) {}

  bool operator>(const Node &node) const {
    return lower_bound > node.lower_bound;
  }
};

int n, k;
vector<int> x, y, c;

double distance(double px, double py) {
  vector<double> dis(n);
  for (int i = 0; i < n; ++i) {
    double dx = abs(px - x[i]), dy = abs(py - y[i]);
    dis[i] = c[i] * hypot(dx, dy);
  }
  nth_element(dis.begin(), dis.begin() + k - 1, dis.end());
  return dis[k - 1];
}

double distance_lb(double px, double py, double r) {
  vector<double> dis(n);
  for (int i = 0; i < n; ++i) {
    double dx = abs(px - x[i]), dy = abs(py - y[i]);
    if (dx <= r) {
      if (dy <= r) {
        dis[i] = 0;
      } else {
        dis[i] = c[i] * (dy - r);
      }
    } else {
      if (dy <= r) {
        dis[i] = c[i] * (dx - r);
      } else {
        dis[i] = c[i] * hypot(dx - r, dy - r);
      }
    }
  }
  nth_element(dis.begin(), dis.begin() + k - 1, dis.end());
  return dis[k - 1];
}

int main() {
  cin >> n >> k;
  x.resize(n);
  y.resize(n);
  c.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i] >> c[i];
  }
  priority_queue<Node, vector<Node>, greater<Node>> que;
  double res = distance(0, 0);
  que.emplace(distance_lb(0, 0, 1000), 0, 0, 1000);
  while (!que.empty()) {
    auto node = que.top();
    que.pop();
    if (res < node.lower_bound) {
      break;
    }
    for (double dx : {-0.5, 0.5}) {
      for (double dy : {-0.5, 0.5}) {
        double nx = node.x + dx * node.r, ny = node.y + dy * node.r, nr = node.r / 2;
        double dis_lb = distance_lb(nx, ny, nr);
        if (res - dis_lb > 5e-7 * max(1.0, dis_lb)) {
          res = min(res, distance(nx, ny));
          que.emplace(dis_lb, nx, ny, nr);
        }
      }
    }
  }
  cout << fixed << setprecision(15) << res << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<algorithm>

#define INT_MAX 2147483647
using namespace std;

int cmp_count=0;

void merge(int A[], int left, int mid, int right){
    int n1 = mid -left;
    int n2 = right - mid;
    int L[n1+1], R[n2+1];
    for(int i=0; i<n1; i++) L[i] = A[left + i];
    for(int i=0; i<n2; i++) R[i] = A[mid + i];
    L[n1]=R[n2]= INT_MAX;
    
    int i=0, j=0;
    for(int k=left; k<right; k++){
        if(L[i]<=R[j]){
            A[k]=L[i++];
            cmp_count++;
        }else{
            A[k]=R[j++];
            cmp_count++;
        }
    }
}

void mergeSort(int A[], int left, int right){
    if(left+1 < right){
        int mid = (left+right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n;
    scanf("%d", &n);
    int S[n];
    for(int i = 0; i < n; i++) scanf("%d",&S[i]);

	mergeSort(S,0,n);

	for(int i = 0; i < n-1; i++) printf("%d ",S[i]);
	printf("%d\n",S[n-1]);
	printf("%d\n",cmp_count);
}


Measured memory_bytes: 7080
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

char S[222222];
char T[222222];
int X[222222];

int main() {
  // ios_base::sync_with_stdio(0);

  scanf("%s", S);
  int N = strlen(S);
  int M = 0;

  int cnt = 0;
  REP(i,N) {
    if (S[i] == 'x') ++cnt;
    else {
      X[M] = cnt;
      T[M] = S[i];
      cnt = 0;
      M++;
    }
  }
  X[M] = cnt;

  REP(i,M) if (T[i] != T[M-1-i]) {
    printf("-1\n");
    return 0;
  }

  int result = 0;
  REP(i,(M+1)/2) result += abs(X[i] - X[M-i]);
  printf("%d\n", result);
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
int main(){
	ll a,b,c; cin>>a>>b>>c;
	if(a+b+1>=c) cout<<b+c;
	else cout<<b+a+b+1;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n,k;

vector<int> pow2;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);

  cin>>n>>k;
  double ans = 0;
  pow2.resize(22);
  pow2[0]=1;
  for (int i=1; i<22; i++) {
    pow2[i] = 2*pow2[i-1];
  }

  for (int i=1; i<=n; i++) {
    int cur = i;
    // how many doubles until cur >= k?
    int p = 0;
    while (cur < k) {
      cur = cur*2;
      p++;
    }
    // 1/2^p
    ans += (1.0 / pow2[p]);
  }

  ans = ans / n;


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


Measured memory_bytes: 256
n = int(input())

def ans(x):
    dp = [i for i in range(x+1)]
    yenlist = [6,9]
    for i in yenlist:
        k = 1
        while i**k <= x:
            q = i**k
            for j in range(x+1-q):
                dp[j+q] = min(dp[j]+1,dp[j+q]) 
            k += 1
    return dp[x]

answer = ans(n)
print(answer)

Measured memory_bytes: 7064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout << x << endl;
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    ll a[n],b[n];
    rep(i,n) cin >> a[i];
    priority_queue<pair<ll,int>> pq;
    rep(i,n){
        cin >> b[i];
        if(a[i]!=b[i]) pq.push({b[i],i});
    }
    ll ans=0;
    while(!pq.empty()){
        pair<ll,int> p=pq.top();
        pq.pop();
        int idx=p.se;
        if(b[idx]<=b[(idx+1)%n]+b[(idx-1+n)%n]){
            cout << -1 << endl;
            return 0;
        }
        if((b[idx]-a[idx])%(b[(idx+1)%n]+b[(idx-1+n)%n])==0){
            ans+=(b[idx]-a[idx])/(b[(idx+1)%n]+b[(idx-1+n)%n]);
            b[idx]=a[idx];
            continue;
        }
        ans+=b[idx]/(b[(idx+1)%n]+b[(idx-1+n)%n]);
        b[idx]%=(b[(idx+1)%n]+b[(idx-1+n)%n]);
        if(b[idx]!=a[idx]) pq.push({b[idx],idx});
    }
    cout << ans << endl;
}


Measured memory_bytes: 9584
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
#include <complex>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	vector<vector<int> > graph(n);
	for(int i = 0; i < n - 1; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	vector<int> c;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		c.push_back(tmp);
	}
	sort(c.begin(), c.end());
	queue<int> qu;
	vector<bool> ischecked(n, false);
	vector<int> ans(n);
	qu.push(0);
	ischecked[0] = true;
	for(int i = n - 1; i >= 0; i--){
		int now = qu.front();
		qu.pop();
		ans[now] = c[i];
		for(int j = 0; j < graph[now].size(); j++){
			int next = graph[now][j];
			if(!ischecked[next]){
				ischecked[next] = true;
				qu.push(next);
			}
		}
	}
	long long int m = accumulate(c.begin(), c.end(), 0) - c[n - 1];
	cout << m << endl;
	for(int i = 0; i < n; i++){
		cout << ans[i];
		if(i == n - 1) cout << endl;
		else cout << " ";
	}
}

Measured memory_bytes: 1024
import sys

K, T = map(int, input().split())
A = list(map(lambda x, y: [int(x), y], sys.stdin.readline().rsplit(), range(T)))
A.sort(reverse=True)

if T == 1:
    print(K - 1)
    exit()

res = 0
pre = -1
t = []
for k in range(K):
    if pre != A[0][1]:
        A[0][0] -= 1
        pre = A[0][1]
    elif pre == A[0][1] and A[1][0] > 0:
        A[1][0] -= 1
        pre = A[1][1]
    else:
        res += 1
    A.sort(reverse=True)

print(res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define F first
#define S second
#define mod 1000000007

signed main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	/************************************/
	
	char c; cin>>c;
	cout<< (char) (c + 1)<<"\n";
	
	
/**End of Main***/}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
//#define inf 10000000000000001ll
//#define fi first
//#define se second
typedef long long ll;
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;cin>>s;
    int n=(int)s.size();
    int k;cin>>k;
    if (s[0]!=s.back()){
        int cnt=1;
        int res=0;
        for (int i=1;i<n;i++){
            if (s[i]==s[i-1]) cnt++;
            else res+=cnt/2,cnt=1;
        }
        res+=cnt/2;
        cout<<res*k;
    } else {
        string t=s;
        sort(t.begin(),t.end());
        if (t==s) cout<<(n*k)/2;
        else {
            int l=0;
            while (s[0]==s[l]) l++;
            int cnt=1;
            int res=0;
            for (int i=l+1;i<n;i++){
                if (s[i]==s[i-1]) cnt++;
                else res+=cnt/2,cnt=1;
            }
            res*=k;
            res+=l/2;
            res+=cnt/2;
            res+=((l+cnt)/2)*(k-1);
            cout<<res;

        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n,x,t;
	cin >> n >> x >> t;
	if(n%x==0){
		cout << n/x*t << endl;
	}
	else{
		cout << (n/x+1)*t << endl; 
	}
	return 0;
}

Measured memory_bytes: 3160
//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int differ(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	return 1;
}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,J,n,m,r,R;
	for(;scanf("%d%d",&n,&m),n;printf("%d\n",R)){
		for(i=0;i<m;i++)scanf("%d%d%d",a+i,b+i,&node[i].first),node[i].second=i,a[i]--,b[i]--;
		sort(node,node+m);
		for(R=-1,i=0;i<m;i++){
			for(J=j=0;j<n;j++)parent[j]=j;
			for(j=i;j<m;j++)if(unite(a[node[j].second],b[node[j].second]))J++,r=node[j].first-node[i].first;
			if(J==n-1&&(R==-1||R>r))R=r;
		}
	}
}

Measured memory_bytes: 1152
/*氏名：保坂優介, 学籍番号：200441141
  概要：円の面積と円周を求める*/

#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>

int main(void)
{
    double r, area, circle;

    scanf("%lf", &r);

    area = (r * r) * M_PI;
    circle = (2 * r) * M_PI;

    printf("%f %f\n", area, circle);

    return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int red = 0, blue = 0;
    for (auto c : s) {
        if (c == '0') red++;
        else blue++;
    }
    cout << 2 * min(red, blue) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
char gc(){
	char ch=getchar();
	while(ch<'A'||ch>'Z')ch=getchar();
	return ch;
}
const int N=2e5+5;
int n,m;char s[N],a[N],b[N];

int check(int x){
	for(int i=1;i<=m;++i)
		if(s[x]==a[i]){
			x+=b[i]=='L'?-1:1;
			if(x<1)return 1;
			if(x>n)return -1;
		}
	return 0;
}
int main(){
	n=gi();m=gi();scanf("%s",s+1);
	for(int i=1;i<=m;++i)a[i]=gc(),b[i]=gc();
	int l,r,L=0,R=n+1;
	l=1;r=n;while(l<=r){
		int mid=l+r>>1;
		if(check(mid)==1)L=mid,l=mid+1;
		else r=mid-1;
	}
	l=1,r=n;while(l<=r){
		int mid=l+r>>1;
		if(check(mid)==-1)R=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",n-min(n,L+n+1-R));
	return 0;
}


Measured memory_bytes: 768
n, x=gets.split.map &:to_i
n=2*n-1

if x==1 or x==n
    puts :No
    exit
end

res=[]*n
res[n/2-1..n/2+1]=x-1, x, x+1
a=[*1..n].select{|e| e<x-1 or e>x+1}
puts :Yes, (0..n).map{|i| res[i]||=a.pop}


Measured memory_bytes: 8700
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main() {
	int n; cin>>n;
	VL a(n);
	rep(i,n) cin>>a[i];
	sort(ALL(a));
	ll ans=1LL;
	if(a[0]==0LL) return cout<<0<<endl,0;
	if(a[n-1]==1000000000000000000) return cout<<-1<<endl,0;
	rep(i,n){
		if((1e18+ans)/ans<a[i]) return cout<<-1<<endl,0;
		ans*=a[i];
		if(ans>1000000000000000000) return cout<<-1<<endl,0;
	}
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 4052
n, m = map(int, input().split())
L = []
for i in range(m):
    a,b = map(int, input().split())
    L.append((a,b))

st,go = set(),set()
for i in range(m):
    if 1 in L[i]:
        st.add(L[i][1])
    if n in L[i]:
        go.add(L[i][0])

if set(st)&set(go):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

int main()
{
  //Digit=log2_10^18=59.7...
  constexpr int Digit=60;
  
  uint64_t N,K;
  std::cin>>N>>K;
  
  std::vector<std::vector<uint64_t>> a(Digit,std::vector<uint64_t>(N,0));
  for(uint64_t i=0;i!=N;i++)
  {
    std::cin>>a[0][i];
  }
  
  for(uint64_t i=1;i!=Digit;i++)
  {    
    for(uint64_t j=0;j!=N;j++)
    {
      a[i][j]=a[i-1][a[i-1][j]-1];
    }
  }
  
  uint64_t pos=1;
  for(uint64_t i=0;i!=Digit;i++)
  {
    if(K&(1ull<<i))
    {
      pos=a[i][pos-1];
    }
  }
  
  std::cout<<pos<<std::endl;
  
  return 0;
}

Measured memory_bytes: 98184
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
bool matchesACGT(char c) {
  bool res = false;
  char acgt[] = {'A', 'C', 'G', 'T'};
  rep(i, 4) if(c == acgt[i]) res = true;
  return res;
}

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for(int len = 0; len <= s.size(); len++)
    for(int pos = 0; pos <= s.size() - len; pos++) {
      string subs = s.substr(pos, len);
      bool isACGT = true;
      rep(i, len) {
        if(!matchesACGT(subs[i])) {
          isACGT = false;
          break;
        }
      }
      if(isACGT) ans = max(ans, len);
    }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	string a;
	int n = 0, z = 0, b = 0;
	cin >> n >> a;
	z = n / 2;
	if (n%2!= 0) {
		cout << "No";
	}
	else {
		while (z != 0) {
			z -= 1;
			b += 1;
			if (a[z] == a[a.size()-b]) {
				continue;

			}
			else {
				cout << "No";
				return 0;
			}
		}
		cout << "Yes";
	}

}
 

Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))

if n == 1:
    if d[0] == 0:
        print(1)
    else:
        print(0)
    exit()

if d[0] != 0:
    print(0)
    exit()

MOD = 998244353

r = [0] * (n+1)

for x in d[1:]:
    if x == 0:
        print(0)
        exit()
    else:
        r[x] += 1

mode = 0
for i in range(1, n+1):
    if mode == 0:
        if r[i] == 0:
            mode = 1
    else:
        if r[i] > 0:
            print(0)
            exit()

def mod_pow(x, y):
    bi = str(format(y, "b"))  # 2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res * res) % MOD
        if bi[i] == "1":
            res = (res * x) % MOD
    return res

ans = 1
for i in range(1, n+1):
    if r[i+1] == 0:
        break
    else:
        ans = (ans * mod_pow(r[i], r[i+1])) % MOD

print(ans)

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

int main(){

    char a, b;

    cin >> a >> b;

    if(a == 'H'){
        if(b == 'H'){
            cout << "H" << endl;
        }
        else{
            cout << "D" << endl;
        }
    }
    else{
        if(b == 'H'){
            cout << "D" << endl;
        }
        else{
            cout << "H" << endl;
        }
    }


    return 0;

}


Measured memory_bytes: 3516
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int sod(int n){
	int s=0;
	while(n){
		s += n%10;
		n/=10;
		}
	return s;
	}
int main()
{
	int i,n,x,a,b,s=0;
	cin>>n>>a>>b;
	for(i=1 ; i<=n ; i++){
		x = sod(i);
		if(x>=a && x<=b) s += i;
		}
	cout<<s<<nw;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }

    replace(dist.begin(), dist.end(), INT_MAX, -1);
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<Edge> > cost(m+1);
        vector<vector<Edge> > time(m+1);
        for(int i=0; i<n; ++i){
            int a, b, x, y;
            cin >> a >> b >> x >> y;
            cost[a].push_back(Edge(b, x));
            cost[b].push_back(Edge(a, x));
            time[a].push_back(Edge(b, y));
            time[b].push_back(Edge(a, y));
        }

        int k;
        cin >> k;

        vector<vector<int> > minCost(m+1), minTime(m+1);
        for(int i=0; i<k; ++i){
            int p, q, r;
            cin >> p >> q >> r;
            if(r == 0){
                if(minCost[p].size() == 0)
                    shortestPath(cost, p, minCost[p]);
                cout << minCost[p][q] << endl;
            }else{
                if(minTime[p].size() == 0)
                    shortestPath(time, p, minTime[p]);
                cout << minTime[p][q] << endl;
            }
        }
    }
}

Measured memory_bytes: 1072
# from random import randint

MOD = 10**9+7

N = int(input())
A = list(map(int, input().split()))
# N = 10000
# A = [randint(1, 10**6) for _ in range(N)]

def modinv(a):
    return pow(a, MOD-2, MOD)

# a = 12345678900000
# b = 100000
# a %= MOD
# print(a * modinv(b) % MOD)

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(b%a, a)
def lcm(a, b):
    return (a * b) // gcd(a, b)

a_lcm = A[0]
for a_i in A[1:]:
    a_lcm = lcm(a_lcm, a_i)
a_lcm %= MOD

sum_num = 0
for a_i in A:
    sum_num = (sum_num + (a_lcm * modinv(a_i))) % MOD

print(sum_num)

Measured memory_bytes: 74204
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll a;
    cin>>a;
    for(ll i=1;i<=sqrt(a);i++){
        if(a%i==0)
        if(i<10 and a/i<10){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 256
A = [0]*5
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())
last = -1
mini = 9
for i in range(5):
  if mini >= A[i] % 10 and A[i]%10 != 0:
    mini = A[i] % 10
    last = i
count = 0
for i in range(5):
  if i != last:
    count += (((A[i]-1) // 10) * 10)+10
  else:
    count += A[i]
print(count)

Measured memory_bytes: 3064
//
//  main.cpp
//  kazane
//
//  Created by h3036136 on 2017/07/27.
//  Copyright ?? 2017??´ h3036136. All rights reserved.
#include <iostream>
#include <string>
using namespace std;
int main(){
    long saidai=0;
    int a=0,cnt=0,num=0,max=0,t;
    string str,tango[1000]={""},answer,ans;
    getline(cin,str);
    for(int i=0;i<str.size();i++){
        if(str[i]==' '){
            for(int j=a;j<i;j++){
                tango[cnt]+=str[j];
            }
            cnt=cnt+1;
            a=i+1;
        }
    }
    for(int p=a;p<str.size();p++){
        tango[cnt]+=str[p];
    }
    
    
    
    for(int k=0;k<=cnt;k++){
        if(saidai<tango[k].size()){
            saidai=tango[k].size();
            ans=tango[k];
        }
    }
    
    for(int s=0;s<cnt;s++){
        num=1;
        for(t=s+1;t<=cnt;t++){
            if(tango[s]==tango[t]){
                num=num+1;
            }
        }
        if(max<num){
            max=num;
            answer=tango[s];
        }
    }
    cout<<answer<<" "<<ans<<endl;
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	vector<bool>v(26,false);
	for(auto&i:s)v.at(i-'a')=true;
	auto ans=find(v.begin(),v.end(),false);
	if(ans==v.end())cout<<"None"s;
	else cout<<(char)('a'+ans-v.begin());
	cout<<"\n"s;
}

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

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

	int a, b;
	cin >> a >> b;
	int div = 1;
	while (b / div)
		div *= 10;
	int total = a * div + b;
	int i = 1;
	while (i * i <= total)
	{
		if (i * i == total)
		{
			cout << "Yes" << endl;
			return (0);
		}
		i++;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
from collections import deque

s = deque(map(str, input().rstrip()))

cnt = 0
while s:
    if s[0] != s[-1]:
        if s[0] != "x" and s[-1] != "x":
            print(-1)
            sys.exit()
        elif s[0] == "x":
            tmp = s.popleft()
        else:
            tmp = s.pop()
        cnt += 1
    elif len(s) <= 1:
        break
    else:
        s.popleft()
        s.pop()

print(cnt)

Measured memory_bytes: 4212
N,M=map(int,input().split())
l_list=[]
r_list=[]
for i in range(M):
    l,r =map(int,input().split())
    l_list.append(l)
    r_list.append(r)
x=max(l_list)
y=min(r_list)
z=y-x
if z>=0:
    print(z+1)
else:
    print(0)

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

int main()
{
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> l(N);
    for(int i = 0;i < N;i++){
        cin >> l[i];
    }
    int res = 1e9;
    for(int i = 0;i < (1 << (N * 2));i++){
        int a = 0, b = 0,c = 0, cost = -30;
        for(int j = 0;j < N;j++){
            int v = (i >> (j * 2)) & 3;
            if(v == 1){
                a += l[j];
                cost += 10;
            }
            else if(v == 2){
                b += l[j];
                cost += 10;
            }
            else if(v == 3){
                c += l[j];
                cost += 10;
            }
        }
        if(a == 0 || b == 0 || c == 0) continue;
        cost += abs(A - a) + abs(B - b) + abs(C - c);
        res = min(res, cost);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,ans;
    
    scanf("%d%d",&a,&b);
    
    ans=a*b;
    
    if((1<=a)&&(a<10)&&(1<=b)&&(b<10)){
        printf("%d\n",ans);
    }else{
        printf("-1");
    }
    
    return 0;
    
}


Measured memory_bytes: 1700
#include <iostream>
using namespace std;
int main()
{
    int n, num;
    char rank;
    int s[13]={0}, h[13]={0}, c[13]={0}, d[13]={0};
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>rank>>num;
        if(rank=='S')
            s[num-1]=1;
        else if(rank=='H')
            h[num-1]=1;
        else if(rank=='C')
            c[num-1]=1;
        else
            d[num-1]=1;
    }
    for(int j=0;j<13;j++)
    {
        if(s[j]==0)cout<<"S "<<j+1<<endl;
    }
        for(int j=0;j<13;j++)
    {
        if(h[j]==0)cout<<"H "<<j+1<<endl;
    }
        for(int j=0;j<13;j++)
    {
        if(c[j]==0)cout<<"C "<<j+1<<endl;
    }
        for(int j=0;j<13;j++)
    {
        if(d[j]==0)cout<<"D "<<j+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int[] up = sc.IntArray();
        int[] down = sc.IntArray();

        int[] upSum = new int[n];
        for (int i = 0; i < n; i++)
        {
            if (i == 0)
            {
                upSum[i] = up[i];
            }
            else
            {
                upSum[i] = upSum[i - 1] + up[i];
            }
        }

        int[] downSum = new int[n];
        for (int i = 0; i < n; i++)
        {
            if (i == 0)
            {
                downSum[i] = down[i];
            }
            else
            {
                downSum[i] = downSum[i - 1] + down[i];
            }
        }

        int answer = 0;
        for (int i = 0; i < n; i++)
        {
            int tmpAnswer = upSum[i] + downSum[n - 1] - downSum[i] + down[i];
            answer = Math.Max(answer, tmpAnswer);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13396
n = int(input())
a = list(map(int,input().split()))
for i in a:
    if (i%2) == 0:
        if not((i %3) == 0 or (i%5)==0):
            print("DENIED")
            exit()
print("APPROVED")
    

# h = sorted(h,reverse = True)
# print(sum(h[k:]))zz

# s,t= map(str, input().split())
# a,b= map(int, input().split())
# u = input()
# print("x"*len(u))

# if(u == s):
#     print(a-1,b)
# else:
#     print(a,b-1)


Measured memory_bytes: 2940