akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 998244353
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define int long long
#define MOD 998244353

long long mod_pow(long long a,long long b)
{
    a %= MOD;
    long long res = 1;
    while(b){
        if(b & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

signed main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n){
        cin >> a[i];
    }
    if(a[0]!=0){
        cout << 0 << endl;
        return 0;
    }
    vector<int>c(n);
    rep(i,n){
        c[a[i]]++;
    }
    bool flag = 0;
    ll res = 1;
    rep(i,n-1){
        if(i==0){
            if(c[i]!=1){
                cout << 0 << endl;
                return 0;
            }
        }else{
            if(flag){
                if(c[i]!=0){
                    res = 0;
                }
            }else{
                if(c[i]==0){
                    flag = 1;
                }else{
                    res *= mod_pow(c[i-1],c[i]);
                    res %= mod;
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2424
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;


signed main(){
    cin >> n;
    vec(a,n);
    input(a,n);
    int tot = 0;
    REP(i,n){
        int t;
        cin >> t;
        tot += t;
    }
    vec(b,n-1);
    input(b,n-1);
    REP(i,n-1){
        if(a[i+1]-a[i] == 1){
            tot += b[a[i]-1];
        }
    }
    print(tot);
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define LL long long
#define zeros(x) x^(x-1)&x
#define pint pair<int,int>
#define inf 2e9
using namespace std;

long long n,l,res;
string s;

struct trie{
    trie *st,*dr;
    bool UZ;

    trie(){
        st = NULL;
        dr = NULL;
        UZ = 0;
    }
}*T;

void dfs(trie *nod,long long niv)
{
    if (niv>l)
        return;
    if (nod->st==NULL)
    {
        long long x = l-niv,nr=1;
        while (x%2==0)
        {
            x/=2;
            nr*=2;
        }
        res ^= nr;
    }
    else if (!nod->st->UZ)
        dfs(nod->st,niv+1);

    if (nod->dr==NULL)
    {
        long long x = l-niv,nr=1;
        while (x%2==0)
        {
            x/=2;
            nr*=2;
        }
        res ^= nr;
    }
    else if (!nod->dr->UZ)
        dfs(nod->dr,niv+1);
}

int main()
{


    cin>>n>>l;
    T = new trie();
    for (int i=1;i<=n;i++)
    {
        cin>>s;
        trie *nod = T;
        for (int i=0;i<s.size();i++)
        {
            if (s[i]=='0')
            {
                if (nod->st==NULL)
                    nod->st = new trie();
                nod = nod->st;
            }
            else
            {
                if (nod->dr==NULL)
                    nod->dr = new trie();
                nod = nod->dr;
            }
        }
        nod->UZ = 1;
    }

    dfs(T,0);

    if (res==0)
        cout<<"Bob\n";
    else
        cout<<"Alice\n";


    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
int binarySearch(int *, int, int);
int main(){
  int i,count,n,S[100000],q,T[50000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
}
  scanf("%d",&q);
  for(i=0;i<n;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
  count+=binarySearch(S,n,T[i]);
  //printf("test1\n");
  }

  printf("%d\n",count);
  return 0;
}

int binarySearch(int *S,int n,int key){
  int left=0,right=n,mid;
  while(left < right){
    mid=(left + right) / 2;
    if(S[mid]==key){
      //printf("test2\n");
      return 1;
}
    else if(key < S[mid]){
      //printf("test3\n");
      right = mid;
}
    else{
      //printf("test4\n");
      left = mid +1;
}
}
  return 0;
}



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

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

  vector<int> a(N), b(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  for(int i = 0; i < N; i++){
    cin >> b[i];
  }

  long long a_op = 0, b_op = 0;

  for(int i = 0; i < N; i++){
    if(a[i] > b[i]){
      b_op += a[i] - b[i];
    }else if(a[i] < b[i]){
      if(a[i] % 2 == b[i] % 2){
	a_op += (b[i] - a[i]) / 2;
      }else{
	a_op += (b[i] - a[i]) / 2 + 1;
	b_op += 1;
      }
    }
  }

  cout << ((a_op >= b_op)? "Yes": "No") << endl;
}



Measured memory_bytes: 384
# -*- coding: utf-8 -*-

answers = []

def plus(length, target):
    if len(target) == length:
        if not (("3" not in target) or ("5" not in target) or ("7" not in target)):
            answers.append(int(target))
            return
    else:
        for i in ["3","5","7"]:
            next = target + i
            plus(length, next)

def main(N):
    for d in range(3,10):
        plus(d, "")
    print(len([a for a in answers if a<=N]))

if __name__ == "__main__":
    N = int(input())
    main(N)


Measured memory_bytes: 4340
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>



using ll = long long;


using namespace std;
int gcd(int a, int b) {
	if (a < b) {
		int t = a;
		a = b;
		b = t;
	}
	
	while (b != 0) {
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}

int factorial(ll n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else
		return 1;
}
int main()
{/*13日目*/
	
		int n;
		cin >> n;
		vector<int> p(n), q(n);
		vector<int> a(n);
		for (int i = 0;i < n;i++)
			cin >> p[i];
		for (int i = 0;i < n;i++)
			cin >> q[i];
		map<vector<int>, int> mp;
		for (int i = 0;i < n;i++)
			a[i] = i + 1;
		do {
			mp[a] = mp.size();
		} while (next_permutation(a.begin(), a.end()));

		int ans = abs(mp[p] - mp[q]);
		cout << ans;
	
	

}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()
using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (v.empty()) return os << "vector{}";
  os << "vector{" << *v.begin();
  for (auto it = ++v.begin(); it != v.end(); ++it)
    os << ", " << *it;
  return os << "}";
}
template<typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
  if (s.empty()) return os << "set{}";
  os << "set{" << *s.begin();
  for (auto it = ++s.begin(); it != s.end(); ++it)
    os << ", " << *it;
  return os << "}";
}
template<typename S, typename T>
ostream &operator<<(ostream &os, const map<S, T> &m) {
  if (m.empty()) return os << "map{}";
  os << "map{" << (*m.begin()).first << ": " << (*m.begin()).second;
  for (auto it = ++m.begin(); it != m.end(); ++it)
    os << ", " << (*it).first << ": " << (*it).second;
  return os << "}";
}
template<typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
  return os << "pair{" << p.first << ", " << p.second << "}";
}

vector<ll> topological_sort(const vector<vector<ll>> &graph) {
  ll size = graph.size();

  // 入次数
  vector<ll> ins(size, 0);
  each (vs, graph) {
    each (v, vs) {
      ins[v]++;
    }
  }

  // 入次数がゼロのやつを集める
  vector<ll> zeros;
  rep (v, size) {
    if (ins[v] == 0) {
      zeros.push_back(v);
    }
  }

  // ゼロのやつから追加してく
  vector<ll> ret;
  while (!zeros.empty()) {
    ll v = zeros.back();
    zeros.pop_back();
    ret.push_back(v);
    each (u, graph[v]) {
      ins[u]--;
      if (ins[u] == 0) {
        zeros.push_back(u);
      }
    }
  }
  // 閉路があると入次数が絶対ゼロにならない
  if (ret.size() != size) {
    throw invalid_argument("閉路があります");
  }

  return ret;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (getenv("LOCAL") != nullptr) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll V, E;
  cin >> V >> E;
  vector<ll> S(E), T(E);
  rep (i, E) {
    cin >> S[i] >> T[i];
  }

  vector<vector<ll>> graph(V, vector<ll>());
  rep (i, E) {
    graph[S[i]].push_back(T[i]);
  }

  vector<ll> ans = topological_sort(graph);
  each (r, ans) {
    cout << r << "\n";
  }
}



Measured memory_bytes: 4772
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline

N,K = map(int,(input().split()))
ans = 0
def count(n,k,b):
    return (n//b)*(b-k) + max(0,n%b-k+1 )
for b in range(K+1,N+1):
    ans += count(N,K,b) - count(0,K,b)
print(ans)

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

typedef long long ll;
using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;

    for (int i = 0; i < n; ++i) {
        cout << s1[i] << s2[i];
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int sum=0;
	for(int i=0;i<s.size();i++) sum+=s[i]-'0';
	if(sum%9) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
const int M=1000000007;
int f[555555];
int d[555555],p[555555],pp;
int ex(int b,int e)
{
	int ans=1;
	for(;e;e>>=1,b=(long long)b*b%M)
		if(e&1)ans=(long long)ans*b%M;
	return ans;
}
struct edge
{
	int to;
	int next;
}e[3333333];
int pe=555555;
void insert(int a,int to)
{
	e[pe]=(edge){to,e[a].next};
	e[a].next=pe++;
}
int dfn[555555],dfc,low[555555],bl[555555],pb;
int s[1111111],ts;
int ifac[1111111];
int ok[1111111];
int ans=1;
int n,m,k;
void dfs(int o,int fa)
{
	low[o]=dfn[o]=++dfc;
	s[++ts]=o;
	for(register int p=e[o].next;p;p=e[p].next)
		if(!dfn[e[p].to])
		{
			s[++ts]=o;
			dfs(e[p].to,o);
			cmin(low[o],low[e[p].to]);
			if(low[e[p].to]>=dfn[o])
			{
				int cl=ts;
				int V=0;
				++pb;
				do
				{
					if(bl[s[ts]]!=pb)++V,bl[s[ts]]=pb,ok[ts]=1;
						else ok[ts]=0;
				}while(s[ts--]!=o);
				int E=0;
				for(register int i=ts+1;i<=cl;++i)
					if(ok[i])
						for(register int p=e[s[i]].next;p;p=e[p].next)
							if(p&1&&bl[e[p].to]==pb)++E;
				if(E==1)ans=(long long)ans*k%M;
					else if(V==E)ans=(long long)ans*f[V]%M;
						else
						{
							int tmp=ifac[E];
							for(register int i=k;i<k+E;++i)
								tmp=tmp*(long long)i%M;
							ans=(long long)ans*tmp%M;
						}
			}
		}
		else if(e[p].to!=fa)cmin(low[o],dfn[e[p].to]);
}
int main()
{
	n=io::F(),m=io::F(),k=io::F();
	for(register int i=2;i<=n;++i)
	{
		if(!d[i])d[i]=p[++pp]=i;
		for(register int j=1,u=dmin(n/i,d[i]);j<=pp&&p[j]<=u;++j)
			d[i*p[j]]=p[j];
	}
	f[0]=1;
	for(register int i=1;i<=n;++i)
		f[i]=(long long)f[i-1]*k%M;
	for(register int j=1;j<=pp;++j)
		for(register int i=n/p[j];i;--i)
			f[i*p[j]]=(f[i*p[j]]+M-f[i])%M;
	ifac[0]=1;
	for(register int i=1;i<=n||i<=m;++i)
		ifac[i]=ex(i,M-2);
	for(register int i=1;i<=n;++i)
		f[i]=(long long)f[i]*ifac[i]%M;
	for(register int i=2;i<=m;++i)
		ifac[i]=(long long)ifac[i]*ifac[i-1]%M;
	for(register int j=1;j<=pp;++j)
		for(register int i=1;i<=n/p[j];++i)
			f[i*p[j]]=(f[i*p[j]]+f[i])%M;
	for(register int i=1;i<=m;++i)
	{
		int x=io::F(),y=io::F();
		insert(x,y);
		insert(y,x);
	}
	for(register int i=1;i<=n;++i)
		if(!dfn[i])
		{
			dfs(i,0);
			int cl=ts;
			int V=0;
			++pb;
			do
			{
				if(bl[s[ts]]!=pb)++V,bl[s[ts]]=pb;
			}while(ts--!=1);
			int E=0;
			for(register int j=ts+1;j<=cl;++j)
				for(register int p=e[s[j]].next;p;p=e[p].next)
					if(p&1&&bl[e[p].to]==pb)++E;
			if(E==1)ans=(long long)ans*k%M;
				else if(V==E)ans=(long long)ans*f[V]%M;
					else
					{
						int tmp=ifac[E];
						for(register int j=k;j<k+E;++j)
							tmp=tmp*(long long)j%M;
						ans=(long long)ans*tmp%M;
					}
		}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main() {
	long long int n, m;
	long long int nn, mm, i, j, k;

	k = (long long int)pow(10, 9) + 7;

	cin >> n >> m;

	if (abs(n - m) <= 1) {
		nn = 1;
		i = 2;
		j = 2;
		while (i <= n && j <= m) {
			nn *= (i++ * j++) % k;
			nn %= k;
		}
		if (i <= n) {
			nn *= i;
			nn %= k;
		}
		else if (j <= m) {
			nn *= j;
			nn %= k;
		}
		if (n == m) {
				cout << (nn * 2) % k;
		}
		else {
			cout << nn % k;
		}
	}
	else {
		cout << 0;
	}

	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ret = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if ((i*500)+(j*100)+(k*50) == x):
                ret += 1

print(ret)


Measured memory_bytes: 3060
N, A, B = map(int, input().split())
S = input()

yosen = 0
overseas = 0
for i in range(N):
  if S[i] == "c":
    print("No")
  elif yosen < A + B:
    if S[i] == "a":
      print("Yes")
      yosen += 1
    elif S[i] == "b" and overseas < B:
      print("Yes")
      yosen += 1
      overseas += 1
    else: print("No")
  else: print("No")

Measured memory_bytes: 4016
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=100000000;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)

int main(){
	ll n,t;
	cin>>n>>t;
	ll ans=inf;
	rep(i,0,n){
		ll x,y;
		cin>>x>>y;
		if(y<=t){
			if(x<ans)ans=x;
		}
	}
	if(ans==inf)cout<<"TLE"<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		sc.close();

		double ret = getProcess(R);

		System.out.println(ret);
	}

	public static double getProcess(int R){
		double ret = 2 * Math.PI * R ;

		return ret;
	}


}

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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
const int inf = 1 << 28;

struct Edge {
    int to, cost;
    Edge(int to, int cost):to(to), cost(cost){}
};

vector<vector<Edge> > G;
vector<int> Cs;

int solve(int cur, int prev){
    if(Cs[cur])return inf;
    int sum = 0;
    for(auto e: G[cur])if(e.to != prev)sum += min(e.cost, solve(e.to, cur));
    return sum;
}

int main(){
    int N;
    cin >> N;
    Cs.assign(N, 0);
    for(int i=1; i<N; ++i)cin >> Cs[i];
    G.assign(N, vector<Edge>());
    rep(i, N-1){
        int u, v, p;
        cin >> u >> v >> p;
        G[u].emplace_back(v, p);
        G[v].emplace_back(u, p);
    }
    cout << solve(0, -1) << '\n';
    return 0;
}

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

using namespace std;

int main () {

    int A, B, K;
    cin >> A >> B >> K;

    for (int i = A; i <= min(B, A + K -1); i++) {
        cout << i << endl;
    }

    for (int i = max(B - K + 1, A + K); i <= B; i++) {
        cout << i << endl;
    }
    
    return 0;
}

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

using namespace std;

int main() {
	int x, y;
	scanf("%d%d", &x, &y);
	
	if (y & 1) return 0 * printf("No\n");
	
	if (y >= 2 * x && y <= 4 * x) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 3680
N=int(input())
S=input()
lsR=[]
lsG=[]
lsB=[]

for i in range(N):
  if S[i]=="R":
    lsR.append(i)
  elif S[i]=="G":
    lsG.append(i)
  else:
    lsB.append(i)
a=len(lsR)*len(lsG)*len(lsB)
b=0
for i in range(N):
  for j in range(i+1,N):
    if S[i]!=S[j]:
      k=2*j-i
      if k<N:
        if S[i]!=S[k] and S[j]!=S[k]:
          b+=1
print(a-b)

Measured memory_bytes: 9248
x1,y1,x2,y2 = map(int,input().split())
d_x,d_y = x2-x1, y2-y1

x3 = x2-d_y
y3 = y2+d_x
x4 = x1-d_y
y4 = y1+d_x

print(x3,y3,x4,y4)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    int p[100];
    rep(i, N) cin >> p[i];
    sort(p, p + N);
    rep(i, N - 1) ans += p[i];
    cout << ans + p[N - 1] / 2 << endl;

    return 0;
}


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


int main(void){
  int n,m,i,j,k,a,f[33]={};
  
  cin >> n >> m;
  for (i=0;i<n;i++){
    cin >> k;
    for (j=0;j<k;j++){
      cin >> a;
      f[a-1]++;
    }
  }
  
  int ans=0;
  for (i=0;i<m;i++){
    if (f[i]==n) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int igcd(int a, int b) {
	if(a<0) a=b;
	if(b<0) b=a;
    if (b == 0) return a;
    return igcd(b, a%b);
}

int main(){

	int n, ma=0;
	vector<int> v, r, l;
	cin>> n;

	v.resize(n);
	l.resize(n);
	r.resize(n);
  
  	/*if(n==2){
      cin>> v[0] >> v[1];
      cout<< max(v[0], v[1]) <<endl;
      return 0;
    }*/
  
  	rep(i, n) cin>> v[i];
  
  	l[0]=v[0];
  	rep(i, n-1) l[i+1]=igcd(l[i], v[i+1]);
  	reverse(all(v));
  
  	r[0]=v[0];
  	rep(i, n-1) r[i+1]=igcd(r[i], v[i+1]);
  	reverse(all(r));
  
  	ma=r[1];
  //cout<< r[n-2] <<endl;
  	ma=max(ma, l[n-2]);
  //cout<< l[n-2] <<endl;
  	rep(i, n-2){
      ma=max(ma, igcd(l[i], r[i+2]));
      //cout<< gcd(l[i], r[i+2]) <<endl;
    }
  
  	cout<< ma <<endl;

	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#define int long long
const int maxn = 2005;
const int mo = 924844033;
using namespace std;
int f[maxn][maxn][2], g[2][maxn], n, k;
int fac[maxn];
signed main(){
	scanf("%lld%lld", &n, &k); fac[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mo;
	f[1][0][0] = 1;
	for (int i = 1; i <= n / k; i++){
		for (int j = 0; j <= i / 2; j++){
			f[i + 1][j][0] = (f[i][j][1] + f[i][j][0]) % mo;
			f[i + 1][j + 1][1] = f[i][j][0];
		}
	} g[0][0] = 1; int cnt = 0;
//	printf("%d\n", (f[n / k + 1][5][0] + f[n / k + 1][5][1]));
	int T = 0;
	for (int s = 1; s <= k; s++){
		int len = (n - s) / k + 1;
		for (int i = 0; i <= cnt; i++)
			for (int j = 0; j <= len / 2; j++)
				g[T ^ 1][i + j] = (g[T ^ 1][i + j] + 1ll * g[T][i] * (f[len][j][0] + f[len][j][1]) % mo) % mo;
		for (int i = 0; i <= cnt; i++) g[T][i] = 0; T ^= 1;
		cnt += len / 2;
		for (int i = 0; i <= cnt; i++)
			for (int j = 0; j <= len / 2; j++)
				g[T ^ 1][i + j] = (g[T ^ 1][i + j] + 1ll * g[T][i] * (f[len][j][0] + f[len][j][1]) % mo) % mo;
		for (int i = 0; i <= cnt; i++) g[T][i] = 0; T ^= 1;
		cnt += len / 2;
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)
		ans = (ans + mo + ((i & 1) ? -1 : 1) * 1ll * g[T][i] % mo * fac[n - i] % mo) % mo;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 60672
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define sqr(x) (x) * (x)
#define cube(x) (z) * (z) * (x)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}

int dp[60][60][2560]{};
signed main() {
  int N, A;
  cin >> N >> A;
  vector<int> x(N);
  rep(i, N) {
    cin >> x[i];
  }
  dp[1][1][x[0]] = 1;
  FOR(i, 1, N) {
    dp[i + 1][1][x[i]] = 1;
    rep(j, 51) {
      rep(k, 2501) {
        dp[i + 1][j][k] += dp[i][j][k];
        dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
      }
    }
  }
  int ans = 0;
  FOR(i, 1, 51) {
    ans += dp[N][i][A * i];
  }
  cout << ans << endl;
}

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

using namespace std;

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

#define pb push_back
#define ff first
#define ss second
#define SIZE 200001
#define INF int(2e9 + 9)
#define BIG_INF ll(4e18 + 9)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define _sz(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

//#pragma GCC optimize("Ofast")

ll binpow(ll a, ll b, ll mod = BIG_INF)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= mod;
        res %= mod;
    }
    res %= mod;
    return res;
}




int T = 1, n, k, a[SIZE], x;
string s;


bool used[SIZE];

void solve()
{

    cin >> k >> n;
    for(int i = 0 ;i < n; i++)
    {
        cin >> x;
        used[x] = 1;
    }

    int ans1 = 101;
    for(int i = k; i <= 100; i++)
    {
        if(!used[i]) {ans1 = i; break;}
    }

    int ans2 = -1;
    for(int i = k; i >= 0; i--)
    {
        if(!used[i]) {ans2 = i;break;}
    }

//    cout << ans1 << ' ' << ans2 << '\n';

    if(abs(k - ans1) > abs(k - ans2))
    {
        cout << ans2;
    }else if(abs(k - ans1) < abs(k - ans2))
    {
        cout << ans1;
    }else cout << min(ans1, ans2);

    return;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

//    cin >> T;

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




    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}

int main()
{
    string s;cin>>s;
    if(s[0]==s[1]&&s[1]==s[2])cout<<"No";else cout<<"Yes";
}


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

int main() {
  int a,b;
  cin >> a >> b;
  
  if (a * b % 2 != 0){
    cout << "Odd" << endl;
  }
  if (a * b % 2 == 0){
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define mp make_pair
#define pb push_back
#define tp make_tuple
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define pr(a) printf("%lld\n",a)
using namespace std;

#define mod 1000003

ll a[1000005];
void fact()
{
    a[0]=1;

    for(ll i=1; i<=1000000; i++)
    {

        a[i]=(i*a[i-1])%mod;
    }
}



int main()
{
    ll n,m,t,x,k;


     cin>>n>>k;

     vector<pair<ll,ll>>v;


     ll a[n+5];

     for(ll i=0;i<n;i++){

        cin>>a[i];

     }

     sort(a,a+n);

     x=0;

     for(ll i=0;i<k;i++)x+=a[i];


     cout<<x<<endl;
}


Measured memory_bytes: 3640
N = int(input())
S = list(input())

int_ = list(map(lambda x: int(hex(ord(x)),16), S))
incre_ = list(map(lambda x: x+N, int_))
incre_ = [x if x <= 90 else x - 26 for x in incre_]
str_ = list(map(lambda x: chr(x), incre_))
print(''.join(str_))


Measured memory_bytes: 3316
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def invalid(a, b):
    if a > b:
        a, b = b, a
    return (b % a == 0 and ((b - a) // 2) % a != 0)

def main():
    N, M = map(int, input().split())
    A = list(set(map(int, input().split())))
    A.sort(reverse=True)
    if len(A) == 1:
        l = A[0]
    else:
        if invalid(A[0], A[1]):
            return 0
        l = lcm(A[0], A[1])
        for i in A[2:]:
            if invalid(l, i):
                return 0
            if l % i == 0:
                continue
            if l // 2 > M:
                return 0
            l = lcm(l, i)
    return (M + l // 2) // l

print(main())


Measured memory_bytes: 19740
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int N; cin >> N;
	int K; cin >> K;
	string s; cin >> s;

	int c = 0;
	for (int i = 0; i < N - 1; i++) {
		if (s[i] == s[i + 1]) {
			c++;
		}
	}
	c += K * 2;
	c = min(c, N - 1);
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{

int ans=0,maxx=0;
int n;
int a[111],b[111];
cin>>n;
for(int i=0;i<n;i++)
    cin>>a[i];
for(int i=0;i<n;i++)
    cin>>b[i];
    
for(int i=0;i<n;i++)
    {for(int j=0;j<=i;j++)
         ans+=a[j];
     for(int j=i;j<n;j++)
          ans+=b[j];
     maxx=max(ans,maxx);
     ans=0;}
cout<<maxx;

system("pause");
return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  string s;cin>>s;
  string t=s;
  for(;;){
    int x=0;
    string d="";
    for(int i=0;i<s.size();i++){
      if(i==0){
        if(s[i]!='('||s[i+1]!=')')
          d+=s.substr(i,1);
      }
      else if(i==s.size()-1){
        if(s[i]!=')'||s[i-1]!='(') 
          d+=s.substr(i,1);
      }
      else{
        if(s[i]!='('||s[i+1]!=')'){
          if(s[i]!=')'||s[i-1]!='('){
            d+=s.substr(i,1);
          }
        }
      }
    }
    if(d==s)break;
    s=d;
  }
  int a=0,b=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='(')a++;
    if(s[i]==')')b++;
  }
  for(int i=0;i<a;i++)t+=")";
  for(int i=0;i<b;i++)t="("+t;
  cout<<t<<endl;
}
    
        

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

using namespace std;


int main(void){
  int H,A;
  cin >> H >> A;
  if (H%A != 0) {
  cout << H/A  +1 << endl;
  }else {
  cout << H/A << endl;
  }


  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll=long long; //using lll=__int128;
using pii=pair<int,int>;
#define repeat(i,a,b) for(int i=(a),iE=(b);i<iE;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,iE=(a);i>=iE;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define N (100*101-100-101+1)
#define inf 1e9
#define qwq {cout<<"qwq"<<endl;}
//#define int ll
const int mod=1000000007;
int a[6]={100,101,102,103,104,105};
int dp[N];
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	dp[0]=1;
	repeat(i,0,6){
		repeat(j,a[i],N)
			dp[j]|=dp[j-a[i]];
	}
	//repeat(i,0,n+1)if(dp[i])cout<<i<<endl;
	if(n>=N){
		cout<<1<<endl;
		exit(0);
	}
	else cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
import kotlin.math.sqrt

fun main() {
    var n = readLine()!!.toLong()
    if (n < 10) {
        print(1)
        return
    }

    val x = sqrt(n.toDouble()).toInt()

    var i = 1L

    var divs = mutableListOf<Int>()
    var answer = Int.MAX_VALUE
    while (i <= x) {
        if ( n % i == 0L) {
            val a= i.toString().toCharArray().size
            val b= (n/i).toString().toCharArray().size
            val max = if (a < b ) b else a

            if (max < answer) {
                answer = max
            }
        }
        i+= 1
    }

    print(answer)

}

Measured memory_bytes: 34616
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> food(m+1);
  rep(i,n){
    int k,a;
    cin>>k;
    rep(j,k){
      cin>>a; food[a]++;
    }  
  }
  int ans=0;
  rep(i,m+1){
    if(food[i]==n) ans++;
  }
  cout<<ans;
return 0;
}

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

int d,g,mini = 999999999;
vector<int> qn,bn;
vector<int> stb,st_nob;

void dfs4(int gr,vector<bool> sn) {
    if (gr == d) {
        int pt=0,cont=0;
        for (int i=0;i<d;i++) {
            if (sn[i]) {pt+=stb[i];cont+=qn[i];}
        }
        if (pt>=g) { 
            if (mini>cont) mini = cont;
        }
        else {
            for (int j=d-1;j>=0;j--) {
                if (sn[j]==false) {
                    if (pt+st_nob[j]>=g) {
                        int sub = (g-pt)/((j+1)*100);
                        if ((g-pt)%((j+1)*100)!=0)++sub;
                        if (mini > cont+sub) mini = cont+sub;
                    }
                    break;
                }
            }
        }
    }
    else {
        vector<bool> tmp1(sn),tmp2(sn);
        tmp1[gr] = true;
        dfs4(gr+1,tmp1);
        tmp2[gr] = false;
        dfs4(gr+1,tmp2);
    }
}

int main() {
    cin >> d >> g;
    qn = vector<int>(d);bn = vector<int>(d);
    for (int i=0;i<d;i++) {
        int p,c; cin >> p >> c;
        qn[i] = p;bn[i] = c;
    }

    stb = vector<int>(d);
    st_nob = vector<int>(d);
    for (int i=0;i<d;i++) {
        stb[i] =    (i+1) * qn[i]*100 + bn[i];
        st_nob[i] = (i+1) * (qn[i]-1)*100;
    }
    vector<bool> s(d,false);
    dfs4(0,s);
    cout << mini << endl;
    return 0;
}

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

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
ll N, A[100010];

/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N) cin>>A[i];

    ll ans = 0;
    REP(i,0,N){

        ans += A[i]/2;
        A[i] -= (A[i]/2)*2;

        if(i < N-1){
            if(A[i] <= A[i+1]){
                ans += A[i];
                A[i+1] -= A[i];
            }else{
                ans += A[i+1];
                A[i+1] = 0;
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int A=read(),B=read(),C=read(),X=read();
	int ans=0;
	For(i,0,A)
	{
		For(j,0,B)
		{
			For(k,0,C)
			{
				if(i*500+j*100+k*50==X)ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
A,B,K = map(int,input().split(" "))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return int(a)

GCA = gcd(A, B)
A_all_div=[]
B_all_div=[]


for i in range(1,A+1):
    if A % i == 0:
        if i <= GCA:
            A_all_div.append(i)
A_all_div.sort(reverse=True)

for i in range(1,B+1):
    if B % i == 0:
        if i <= GCA:
            B_all_div.append(i)
B_all_div.sort(reverse=True)

ALL_DIV = set(A_all_div) & set(B_all_div)
all_div = list(ALL_DIV)

all_div.sort(reverse=True)

print(all_div[K-1])

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <numeric>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

struct edge{
  int to;
  long dist;
};

int main(){
  int n;
  cin >> n;
  vector<edge> connected[n];
  REP(i,n-1){
    long a,b,c;
    cin >> a >> b >> c;
    connected[a-1].push_back({b-1,c});
    connected[b-1].push_back({a-1,c});
  }
  int q,k;
  cin >> q >> k;
  long long distance[n] = {};
  queue<int> wait;
  wait.push(k-1);
  while(wait.size()>0){
    int node = wait.front();
    wait.pop();
    for(edge e : connected[node]){
      if(distance[e.to]==0){
        distance[e.to]=distance[node]+e.dist;
        wait.push(e.to);
      }
    }
  }
  REP(i,q){
    int x,y;
    cin >> x >> y;
    cout << distance[x-1]+distance[y-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 9984
#include<stdio.h>
#include<string.h>
int main(){
  int n;
  char s[100000];
  int ans;
  scanf("%d",&n);
  ans=n;
  for(int i=0;i<n;i++){
    scanf("%s",&s[i]);
    if(i>0){
      if(s[i-1]==s[i]){
      ans-=1;
      }
    }
  }

  printf("%d",ans);
 return 0; 
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct point{
  int x,y;
  point(const int x,const int y){
    this->x=x;
    this->y=y;
  }  
  point(const point& p){
    this->x=p.x;
    this->y=p.y;
  }

  point(){
    x=y=0;
  }
  ~point(){}
};
constexpr int row=8,col=8;
void bombchain(vector<string> &field,const point& p){
  if(p.x<0||col<=p.x||p.y<0||row<=p.y) return;
  if(field[p.y][p.x]=='1'){
    field[p.y][p.x]='0';
    for(int i=1;i<=3;i++){
      bombchain(field,point(p.x-i,p.y));
      bombchain(field,point(p.x+i,p.y));
      bombchain(field,point(p.x,p.y-i));
      bombchain(field,point(p.x,p.y+i));
    }
  }

}

int main(){
  int datasize;
  cin>>datasize;
  for(int idx=0;idx<datasize;idx++){
    vector<string> field(row);
    for(int i=0;i<row;i++){
      cin>>field[i];
    }
    point p;
    cin>>p.x>>p.y;
    p.x--,p.y--;
    bombchain(field,p);
    cout<<"Data "<<idx+1<<":"<<endl;
    for(int i=0;i<row;i++){
      cout<<field[i]<<endl;
    }
  }

}

Measured memory_bytes: 1212
from itertools import accumulate
while True:
  n, s = map(int, input().split())
  if n == 0:break
  lst = [0] * 102
  for _ in range(n):
    lst[int(input())] += 1
  acc_lst = list(reversed(list(accumulate(reversed(lst)))))
  ans = 0
  for i in range(1, 101):
    if s + 1 - i > i:
      ans += lst[i] * acc_lst[s + 1 - i]
    else:
      ans += lst[i] * (lst[i] - 1) // 2
      ans += lst[i] * acc_lst[i + 1]
  print(ans)



Measured memory_bytes: 5676
function main()
    n, m = parse.(Int, split(readline()))
    adj = [Int[] for i in 1:n]
    for i in 1:m
        a, b = parse.(Int, split(readline()))
        push!(adj[a], b)
        push!(adj[b], a)
    end
    
    q = [1]
    visited = falses(n)
    mark = Tuple{Int, Int}[]
    while !isempty(q)
        visited[1] = true
        cv = popfirst!(q)
        nv = adj[cv]
        for i in 1:length(nv)
            visited[nv[i]] && continue
            push!(q, nv[i])
            push!(mark, (cv, nv[i]))
            visited[nv[i]] = true
        end
    end
    
    head = zeros(Int, n)
    for i in 1:length(mark)
        head[mark[i][2]] = mark[i][1]
    end
    println("Yes")
    for i in 2:length(head)
        println(head[i])
    end
end


main()


Measured memory_bytes: 237032
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int main(){
	string s;
	cin >> s;

	vector<ll> ind;
	string t = "";

	REP(i,s.size()) {
		if(s[i] != 'x') {
			t.pb(s[i]);
			ind.pb(i);
		}
	}

	bool f = true;

	ll m = t.size();
	if(m == 0) {
		cout << 0 << endl;
		return 0;
	}
	REP(i,m / 2) {
		if(t[i] != t[m - i - 1]) {
			f = false;
		}
	}
	if(!f) {
		cout << -1 << endl;
		return 0;
	}

	ll n = s.size();

	ll ans = abs(ind[0] - (n - 1 - ind[m - 1]));

	REP(i,(m - 1) / 2) {
		ans += abs((ind[i + 1] - ind[i]) - (ind[m - 1 - i] - ind[m - 1 - i - 1]));
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1656
#define REP(i,n) for (int i=1;i<(n);i++)
#include <iostream>
using namespace std;

int tax(int p,int x){
        int ans = (p*(100+x))/100;
        return ans;
}

int main(){
        int x, y, s;
        cin >> x;
        while(x > 0){
                int ans = 0;
                cin >> y >> s;
                REP(i,s){
                REP(j,s){
                        if(tax(i,x)+tax(j,x) == s){
                                if (tax(i,y)+tax(j,y) > ans)
                                        ans = tax(i,y)+tax(j,y);
                        }
                }
                }
                cout << ans << endl;
                cin >> x;
        }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

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

	bool res = true;
	H[0]--;
	for(int i = 1; i < N; i++){
		if(H[i-1] > H[i]){
			res = false;
		}else if(H[i-1] < H[i]){
			H[i]--;
		}
	}

	cout << (res ? "Yes" : "No") << '\n';

	return 0;
}

Measured memory_bytes: 640
N,M=map(int,input().split())
pr=10**9+7
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort(reverse=1)
B.sort(reverse=1)
A.append(0)
B.append(0)
at,bt=0,0
m=0
a=1
for i in range(N*M,0,-1):
    if A[at]==B[bt]==i:
        m+=at+bt
        at+=1
        bt+=1
    elif A[at]==i:
        a=a*bt%pr
        m+=bt-1
        at+=1
    elif B[bt]==i:
        a=a*at%pr
        m+=at-1
        bt+=1
    else:
        if m>0:
            a=a*m%pr
            m-=1
        else:
            a=0
if at==N and bt==M:
    print(a)
else:
    print(0)

Measured memory_bytes: 3188
x = input()
y = input()
lx, ly = len(x), len(y)

length = [[0] * (ly + 1) for _ in range(lx + 1)]

for i_x in range(lx):
    for i_y in range(ly):
        if x[i_x] == y[i_y]:
            length[i_x+1][i_y+1] = length[i_x][i_y] + 1
        else:
            length[i_x+1][i_y+1] = max(length[i_x+1][i_y], length[i_x][i_y+1])

lcs = ''
i_x, i_y = lx, ly
while i_x and i_y:
    if x[i_x-1] == y[i_y-1]:
        lcs += x[i_x-1]
        i_x -= 1
        i_y -= 1
    elif length[i_x][i_y-1] > length[i_x-1][i_y]:
        i_y -= 1
    else:
        i_x -= 1

print(lcs[::-1])


Measured memory_bytes: 112220
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);++i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 


int main () {
	int n;
	cin >> n;
	int a[n],nums[n];
	fop (i,0,n) {
		cin >> a[i];
	}
	nums[0]=0;
	fop (i,1,n) {
		if (a[i]<=a[i-1]) {
			nums[i]=nums[i-1]+1;
		} else {
			nums[i]=0;
		}
	}
	int maxx=0;
	fop (i,0,n) {
		maxx=max(maxx,nums[i]);
	}
	cout << maxx << endl;
}

Measured memory_bytes: 1024
nl = input().split(' ')
n = int(nl[0])
l = int(nl[1])

taste = 0
judge = True
for i in range(n):
	taste_i = l + (i + 1) - 1 
	if taste_i == 0:
		judge = False
	taste += l + (i + 1) - 1

if judge:
	if taste_i < 0:
		taste = taste - taste_i
	else:
		taste = taste - (l + 1 - 1)

print(taste)

Measured memory_bytes: 3064
h,w,k = map(int,input().split())
c = []
for i in range(h):
    c += [input()]
ans = 0
for i in range(2**(w+h)):
    count = 0
    for y in range(h):
        for x in range(w):
            if c[y][x] == '#' and ((i >> x) & 1) == 0 and ((i >> (y+w)) & 1) == 0:
                count += 1
    if count == k:
        ans += 1
print(ans)

Measured memory_bytes: 9144
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: String};
    let n: String = n;

    let n1 = &n[0..3].parse().unwrap();
    let n2 = &n[1..4].parse().unwrap();

    if n1 % 111 == 0 || n2 % 111 == 0 {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    int a;
    cin >> a;
    if(a % 2 == 0){
        cout << a/2 << endl;
    }else
    {
        cout << a/2 + 1 << endl;
    }
    
  

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
class Data{
    private int a;
    private int b;
    public Data(int a, int b) {
        this.a = a;
        this.b = b;
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
}
public class Main {    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        int [] in2 = new int [a];
        int t = 0;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                             in2[i] = sc.nextInt();
                            }
        Data [] d = new Data [a];
         for(int i=0;i<a;i++){d[i] = new Data(in[i],in2[i]);                            
                             }
        Arrays.sort(d, new Comparator<Data>() {
            public int compare(Data d1, Data d2) {
                return d1.getB() - d2.getB();
            }
        });
		String s = "Yes";        
        for(int i=0;i<a;i++){t+=d[i].getA();
                             if(d[i].getB()<t){s="No";break;
                                              }
                             
                            }        
		System.out.println(s);
	}
}


Measured memory_bytes: 96628
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

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

    if (x < 600)cout << 8 << endl;
    else if (x < 800) cout << 7 << endl;
    else if (x < 1000)cout <<6 << endl;
    else if (x < 1200)cout << 5 << endl;
    else if (x < 1400)cout << 4 << endl;
    else if (x < 1600)cout << 3 << endl;
    else if (x < 1800)cout << 2 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3628