akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
const int N = six;
int min_prime[N];
void sieve()
{
       fri(i,0,N){min_prime[i] = i;}
       for(int i = 2 ; i*i <= N ; i++)
       {
              if(min_prime[i] != i){continue;}
              for(int j = i*i ; j < N ; j += i)
              {
                     if(min_prime[j] != j){continue;}
                     min_prime[j] = i;
              }
       }
}
map<ll,ll> prime_fact(ll x)
{
       map<ll,ll> mp;
       while(x!=1)
       {
              mp[min_prime[x]]++;
              x/=min_prime[x];
       }
       return mp;
}
int main()
{
       sieve();
       int n;
       cin>>n;
       int a[n];
       arrin(a,n);
       map<int,int> mp;
       fri(i,0,n){
              map<ll,ll> tm = prime_fact(a[i]);
              tra(it,tm){
                     mp[it->fr]++;
              }
       }
       bool ans = true;
       tra(it,mp){
              if(it->sc > 1)ans = false;
       }
       if(ans){
              cout<<"pairwise coprime"<<endl;
              return 0;
       }
       int gg = a[0];
       fri(i,1,n){
       gg = __gcd(a[i],gg);
       }
       if(gg==1){
              cout<<"setwise coprime"<<endl;
       }
       else{
              cout<<"not coprime"<<endl;
       }
}


Measured memory_bytes: 14896
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
using llong = long long;

llong n, m;
llong a[55], l[55];
llong w[128];
llong b[128];

llong f() {
    for (int i = 0; i < n; i++) {
        if (w[i] == 0) return i;
    }
    return n;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> l[i];
        for (int j = 0; j < l[i]; j++) {
            w[(a[i] + j) % n] = 1;
        }
    }

    llong s = f();

    if (s == n) {
        cout << n << ' ' << 1 << endl;
        return 0;
    }

    for (int i = s; i < n + s; i++) {
        llong len = 0;
        while (w[i % n]) {
            len++;
            i++;
        }
        b[len]++;
    }

    for (int i = n; i > 0; i--) {
        if (b[i]) {
            cout << i << ' ' << b[i] << endl;
        }
    }
}



Measured memory_bytes: 3108
#include <iostream>
#include <numeric>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

	vector<int> c(s.size() + 1, false);
	int h = 0;
	c[0] = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		switch (s[i])
		{
		case '_': break;
		case '\\': h -= 1; break;
		case '/': h += 1; break;
		}
		c[i + 1] = h;
	}

	int sum = 0;
	vector<int> area;
	stack<bool> d;
	for (int i = 0; i < s.size(); ++i)
	{
		switch (s[i])
		{
		case '_':
			sum += (1 * d.size());
			break;

		case '\\':
			for (int j = s.size(); j > i; --j)
				if (c[i] <= c[j]) { d.push(true); break; }
			break;

		case '/':
			if (!d.empty())
				sum += 2 * d.size() - 1, d.pop();
			break;
		}

		if (d.empty() && sum != 0)
			area.push_back(sum), sum = 0;
	}

	cout << accumulate(area.begin(), area.end(), 0) << endl;
	cout << area.size();
	for (auto a : area)
		cout << " " << a;
	cout << endl;

	return 0;
}

Measured memory_bytes: 3272
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>

using namespace std;

static const int MAX = 100000;
static const int NIL = -1;

vector<int> G[MAX];
int color[MAX];
int n;

void dfs(int r, int c) {
    stack<int> S;
    S.push(r);
    color[r] = c;
    while (!S.empty()) {
        int u = S.top();
        S.pop();
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            if (color[v] == NIL) {
                color[v] = c;
                S.push(v);
            }
        }
    }
}
void assignColor() {
    int id = 0;
    for (int i = 0; i < n; i++) color[i] = NIL;
    for (int u = 0; u < n; u++) {
        if (color[u] == NIL) dfs(u, id++);
    }
}
int main() {
    int m, s, t, q;

    cin >> n >> m;
    for (int i; i < m; i++) {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >> q;

    for (int i = 0; i < q; i++) {
        cin >> s >> t;
        if (color[s] == color[t]) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 8944
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;
typedef long long ll;

int main(){
  ll N, tmp;
  cin >> N;
  vector<ll> num;
  unordered_map<ll, ll> counts;
  for (ll i=0; i<N; i++){
    cin >> tmp;
    num.push_back(tmp);
    counts[tmp]++;
  }
  ll all_sum = 0;
  for (auto e : counts){
    all_sum += (e.second >= 2 ? (e.second*(e.second - 1)/2) : 0);
  }
  vector<ll> rem;
  for (ll i=0; i<N; i++){
    ll num2 = counts[num[i]];
    rem.push_back(all_sum - (num2 >= 2 ? num2*(num2-1)/2 : 0));
  }
  
  for (ll i=0; i<N; i++){
    ll ans = rem[i];
    ll cnt = counts[num[i]] - 1;
    ans += (cnt >= 2 ? cnt*(cnt-1)/2 : 0);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 10812
s=input()
for bit in range(1<<3):
  ans=int(s[0])
  f=s[0]
  for i in range(3):
    if bit & (1<<i):
      ans+=int(s[i+1])
      f+="+"
    else:
      ans-=int(s[i+1])
      f+="-"
    f+=s[i+1]
  if ans==7:
    print(f+"=7")
    exit()
      

Measured memory_bytes: 38256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

bool calcX(const vector<int>& v, int D) {
    const int BASE = 8050;
    const int SZ = 10010 * 2;
    vector<vi> dp(2, vi(SZ, 0));
    int n = v.size();
    if(n == 0) return D == 0;
    dp[1][BASE+v[0]] = 1;
    REP(i, 1, n) {
        int now = i&1, nxt = (i+1)&1;
        if(v[i] == 0) {
            dp[nxt] = dp[now];
            continue;
        }
        dp[nxt].clear();
        dp[nxt].assign(SZ, 0);
        rep(j, SZ) {
            if(dp[now][j] == 0) continue;
            if(j + v[i] < SZ) dp[nxt][j+v[i]] = 1;
            if(j - v[i] >= 0) dp[nxt][j-v[i]] = 1; 
        }

    }
    return dp[n&1][D+BASE] == 1;
}
bool calcY(const vector<int>& v, int D) {
    const int BASE = 8050;
    const int SZ = 10010 * 2;
    vector<vi> dp(2, vi(SZ, 0));
    dp[0][BASE] = 1;
    int n = v.size();
    rep(i, n) {
        int now = i&1, nxt = (i+1)&1;
        dp[nxt].clear();
        dp[nxt].assign(SZ, 0);
        rep(j, SZ) {
            if(dp[now][j] == 0) continue;
            if(j + v[i] < SZ) dp[nxt][j+v[i]] = 1;
            if(j - v[i] >= 0) dp[nxt][j-v[i]] = 1; 
        }
    }
    return dp[n&1][D+BASE] == 1;
}

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string yes = "Yes", no = "No";
    string s;
    cin >> s;
    int n = s.size();
    int X, Y;
    cin >> X >> Y;
    int idx = 0, cnt = 0;
    vector<vi> v(2);
    rep(i, n) {
        if(s[i] == 'T') {
            v[idx].pb(cnt);
            cnt = 0;
            idx = (idx+1)%2;
        }
        else cnt++;
    }
    v[idx].pb(cnt);
    cout << ((calcX(v[0], X) && calcY(v[1], Y)) ? yes: no) << endl;
    // rep(i, 2) {
    //     rep(j, v[i].size()) cout << " " << v[i][j];
    //     cout << endl;
    // }

    return 0;
}

Measured memory_bytes: 532
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <fstream>
#include <tuple>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto& i : a)
#define foraj(a) for(auto& j : a)
#define forak(a) for(auto& k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pb(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort(a.begin(), a.end());
#define sortm(a, n) sort(a, a + n);
#define reversi(a) reverse(a.begin(), a.end());
#define fi first
#define se second
#define yes cout << "Yes\n";
#define no cout << "No\n";
#define ans(a) cout << a << '\n';
#define res(a, n) a.resize(n);
#define read(a, n) a.resize(n); fori(n) cin >> a[i];
#define int long long
//#define double long double

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<int, pair<int, int>>> viii;
typedef pair<int, pair<int, int>> iii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;
typedef vector<bool> vb;
typedef set<int> si;
typedef set<ii> sii;
typedef unsigned long long ull;
typedef pair<ull, ull> ullll;
typedef pair<double, double> dd;
typedef vector<dd> vdd;
typedef vector<pair<ull, ull>> vullll;
typedef pair<bool, bool> bb;
typedef vector<bb> vbb;
typedef vector<vector<ii>> vvii;
typedef vector<vector<iii>> vviii;

const int INF = 2147483647;
const ll LONGINF = 9223372036854775807;
const ll MOD = 1e9 + 7;

void solve()
{
    ll x, k, d;
    cin >> x >> k >> d;
    ll times = min(k, llabs(x) / d);
    if (x > 0) x -= d * times;
    else x += d * times;
    k -= times;
    if (k % 2 == 0) ans(llabs(x))
    else ans(llabs(x > 0 ? x - d : x + d))
}

signed main()
{
    fast
    bool mult = false;
    if (mult)
    {
        int t;
        cin >> t;
        while (t--) solve();
    }
    else solve();
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


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

	vector<int> dp(100100, 0);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < N; i++)
	{
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
			        dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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


int main(){
    int n; cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    int q; cin >> q;
    REP(i, q){
        int b, e; cin >> b >> e;
        reverse(a.begin() + b, a.begin() + e);
    }
    REP(i, n){
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;


int main() {
	int n; cin >> n;
	vector<pair<int, int> > ans;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (n % 2 == 0) {
				if (i + j != n + 1) ans.push_back({ i, j });
			}
			else {
				if (i + j != n) ans.push_back({ i, j });
			}
		}
	}
	cout << ans.size() << endl;
	for (auto p : ans) cout << p.first << " " << p.second << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
main(){
    int n,m;
    cin >> n >> m;
    int arr[n];
    int solved[n];
    memset(arr,0,sizeof(arr));
    memset(solved,0,sizeof(solved));
    for (int i = 0; i < m; i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if (solved[p]) continue;
        if (s == "AC"){
            solved[p] = 1;
        }
        else arr[p]++;
    }
    int ac = 0,pen = 0;
    for (int i = 0; i < n; i++){
        if (solved[i]) ac++,pen+=arr[i];
    }
    cout << ac << " " << pen;
}


Measured memory_bytes: 1792
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
map<string,int> m;
void solve(){
    ll n;
    ll ans=0;
    cin>>n;
    string s;
    rep(i,1,n){
        cin>>s;
        string curr="";
        mii mm;
        rep(j,0,sz(s)-1){
            ll ch=s[j]-'a';
            mm[ch]++;
        }
        rep(j,0,25){
            curr.pb(mm[j]+'0');
        }
        ans+=m[curr];
        m[curr]++;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 14336
import java.util.Scanner;

class Main{
       public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	String s = scan.next();
    	String p = scan.next();
    	String ss = s + s;
    	
    	if(ss.indexOf(p) != -1){
    		System.out.println("Yes");
    	}else{
    		System.out.println("No");
    	}
     }
    	
}

Measured memory_bytes: 26204
n, x = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
count = 0
(1...n).each do |i|
  sum = arr[i - 1] + arr[i]
  next if sum <= x
  if sum - x <= arr[i]
    count += sum - x
    arr[i] -= sum - x
  else
    count += sum - x - arr[i]
    count += arr[i]
    arr[i - 1] = sum - x - arr[i]
    arr[i] = 0
  end
end
print count

Measured memory_bytes: 9612
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<math.h>
#include<cmath>
using namespace std;
int main() {
	double r;
	cin >> r;
	cout << fixed;
	cout <<setprecision(10)<< r*r*M_PI << endl;
	cout << fixed;
	cout << setprecision(10) << 2 * r*M_PI << endl;
	
	
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll a[200010];
int main() {
	ll n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ans+=a[i];
	}
	ll sum=0;
	ll ans2=INF;
	for(int i=0;i<n-1;i++){
		sum+=a[i];
		ans2=min(ans2,abs(sum-(ans-sum)));
	}
	cout << ans2;
	// your code goes here
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<tuple<int, int, int>> V(N);
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    V.at(i) = {i, x, y};
  }
  double sum = 0;
  int cnt = 0;
  do {
    double tmp = 0;
    for (int i = 0; i + 1 < N; i++) {
      auto [a, b, c] = V.at(i);
      auto [d, e, f] = V.at(i + 1);
      tmp += sqrt((b - e) * (b - e) + (c - f) * (c - f));
    }
    sum += tmp;
    cnt++;
  } while (next_permutation(V.begin(), V.end()));
  cout << fixed << setprecision(6) << sum / cnt << "\n";
}

Measured memory_bytes: 3808
nm = lambda : map(int,input().split())
nl = lambda : list(nm())

import bisect

n = int(input())
l = nl()
l.sort()
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        a,b = l[i],l[j]
        if a > b:
            a,b = b,a
        lef = bisect.bisect_right(l,b-a)
        rig = bisect.bisect_left(l,a+b)
        t = rig - lef - 1 - (b < 2*a)
        ans += t
print(ans//3)

Measured memory_bytes: 47580
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    fun pow10(n : Int) : Int {
        // special case
        if (n == 0) return 0

        var ret = 1
        repeat(n) {
            ret *= 10
        }
        return ret
    }
    val arr = Array(m) {
        readLine()!!.split(" ").map { it.toInt() }
    }
    for (i in pow10(n-1) until pow10(n)) {
        val s = i.toString()
        if (arr.all { list ->
                    val fst = list.component1()
                    val snd = list.component2().toString().first()
                    s[fst - 1] == snd
                }) {
            println(i)
            return
        }
    }
    println(-1)
}

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

using namespace std;

const int maxn = 100010;

int n = 0;

int l[maxn], a[maxn], deg[maxn], val[maxn], e = 0, rt = 0, ok = 1;

struct Edge {
	int v, x;
} E[maxn << 1];

inline void addEdge(int u, int v) {
	E[e].v = v; E[e].x = l[u]; l[u] = e++;
}

void dfs(int u, int f) {
	if (deg[u] == 1) {
		val[u] = a[u];
		return;
	}
	int s = 0, mx = 0;
	for (int p = l[u]; p >= 0; p = E[p].x) {
		int v = E[p].v;
		if (v != f) {
			dfs(v, u);
			s += val[v];
			mx = max(mx, val[v]);
		}
	}
	if (!ok) return;
	int c = s - a[u];
	if (c < 0 || 2*c > s) {
		ok = 0;
		return;
	}
	val[u] = s - 2*c;
	if (mx > s - mx) {
		if (c > s - mx) {
			ok = 0;
			return;
		}
	}
}

int main() {
	memset(l, -1, sizeof(l));
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i < n; i++) {
		int u, v; scanf("%d%d", &u, &v);
		addEdge(u, v);
		addEdge(v, u);
		deg[u] ++;
		deg[v] ++;
	}
	if (n == 2) {
		if (a[1] == a[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	for (int i = 1; i <= n; i++) if (deg[i] > 1) rt = i;
	dfs(rt, 0);
	if (ok && !val[rt]) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 10496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int a[][][] = new int[4][3][10]; 
        String str[];
        int b,f,r,v;
        while(n-->0){
            str = br.readLine().split(" ");
            b = Integer.parseInt(str[0]);
            f = Integer.parseInt(str[1]);
            r = Integer.parseInt(str[2]);
            v = Integer.parseInt(str[3]);
            a[b-1][f-1][r-1] = a[b-1][f-1][r-1] + v;
        }
        for(int i=0;i<4;i++){
            for(int j=0;j<3;j++){
                for(int k=0;k<10;k++){
                    System.out.print(" "+a[i][j][k]);
                }
                System.out.println();
            }
            if(i!=3) System.out.println("####################");
        }
    }
}

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


n = int(input())
for k in range(1,n+3):
    if k*(k-1)//2==n:
        print("Yes")
        print(k)
        size = (k-1)//2
#         l = [set() for _ in range(n)]
        l = [set() for _ in range(k)]
        ind  = 1
        for i in range(k):
            for j in range(i+1,k):
                l[i].add(ind)
                l[j].add(ind)
                ind += 1
                    
        for i in range(k):
            print(len(l[i]), " ".join(map(str, l[i])))
        break
else:
    print("No")

Measured memory_bytes: 73444
#include <bits/stdc++.h>
#define F first
#define S second
#define ld long douroote
#define pb push_back
#define sz size
#define ll long long
#define ull unsigned long long
#define INF 0x7f7f7f7f
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define me(a,b) memset(a,b,sizeof a)
#define all(a) a.begin(),a.end()
#define allr(a,n) a,a+n
#define loop(a,s,e) for(ll a=s;a<=e;a++)
#define read_arr(a,s,n) for(int i=s;i<n+s;i++){sc(a[i]);}
#define read_arr_ll(a,s,n) for(int i=s;i<n+s;i++){scll(a[i]);}
#define err(a,s) cerr<<a<<s;
#define err_arr(a,s,n) for(int i=s;i<n+s;i++){cerr<<a[i]<<" ";}cerr<<endl;
#define prtll(x) printf("%lld",x);
#define prt(x) printf("%d",x);
using namespace std;
const ll N=(1e5)+10;
ll mem[N][3],mod=1e9+7,n,x,y;
vector<int>adj[N],tree[N];
ll dp(ll v,ll p,ll col){
if(adj[v].size()==1){return 1;}
ll &ret=mem[v][col];
if(ret!=-1){return ret;}
ret=1;
if(col){
   for(auto u:adj[v]){
      if(u==p){continue;}
      ret*=dp(u,v,col)%mod+dp(u,v,!col)%mod;
      ret%=mod;
   }
}
else{
      for(auto u:adj[v]){
      if(u==p){continue;}
      ret*=dp(u,v,!col)%mod;
      ret%=mod;
   }
}
return ret;
}
int main(){
sc(n);
adj[1].pb(0);
loop(i,1,n-1){
sc(x);sc(y);
adj[x].pb(y);
adj[y].pb(x);
}
me(mem,-1);
ll ans=(dp(1,0,0)+dp(1,0,1))%mod;
printf("%d\n",ans);
}

/**
**/


Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vd(T) vector<vector<T>>
#define v(T) vector<T>
#define mod (ll)(1e9+7)
#define pp(T) pair<T,T>
#define pb push_back
#define mp make_pair
#define NN 100005
#define IO ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG cout<<"***********DEBUGGING***********"<<endl
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 
ll power(ll a,ll b){ if(b==0) return 1; ll s=power(a,b/2); s*=s;if(b&1) return s*a; return s;}
ll powermod(ll a,ll b,ll m){ if(b==0) return 1; ll s=power(a,b/2);s*=s; s%=m; if(b&1) return (s*a)%m; return s;}
inline int add(ll a,ll b,ll m=0){
    if(m==0) return a+b;
    return (a%m+b%m)%m;
}

inline int sub(ll a,ll b ,ll m=0){
    if(m==0) return a-b;
    return ((a%m-b%m)%m+m)%m;
}

inline int mul(ll a,ll b,ll m=0){
    if(m==0)return (a*b);
    return ((a%m)*(b%m))%m;
}

inline int div(ll a,ll b,ll m=0){
    if(m==0) return a/b;
    return ((a%m)*(powermod(a,b,m-2)%m))%m;
}

bool isopen(char c){
    return ((c=='(')||(c=='{')||(c=='['));
}

ll longest_balanced_parenthesis(string a,ll n){
    stack<char> s;
    ll start=0;
    ll ans=0,m=0;
    for(ll i=0;i<n;i++){
        if(isopen(a[i])){
            s.push(a[i]);
        }
        else{
            if(isopen(a[i])|| s.empty()){
                m=max(m,ans);
                continue;
            }
            else{
                s.pop();
                ans+=2;
                m=max(ans,m);
            }
        }
    }

    return m;

}

ll setup_k(ll *a,ll k){
  ordered_set x;
  // Now , insert and then check number of integers less than k by just using x.order_of_key(k+1)
}

int main() {

    IO; 

    ll x;
    cin>>x;
    string s;
    cin>>s;
    ll ans=0;
    x=0;
    for(ll i=0;s[i];i++){
        if(s[i]=='I')x++;
        else x--;
        ans=max(ans,x);
    }
    cout<<ans<<endl;
    

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

signed main() {
    int k,x;
    cin>>k>>x;
    if(k*500 >= x){
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,A,B,C;
  cin >> A >> B >> C >> N;
  rep(i,N)
  {
    if(A>=B)
    {
      B *= 2;
    }
    else if(B>A)
    {
      C *= 2;
    }
  }
  if(A<B&&B<C)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,M=MI()
    A=LI()
    B=LI()
    ans = min(A)+min(B)
    for i in range(M):
        a,b,c=MI()
        ans = min(ans, A[a-1]+B[b-1]-c)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 89884
def calculate(S):
    result = []

    rNum = 0
    lNum = 0
    for i in range(len(S)):
        if S[i] == "L":
            lNum = lNum + 1
        else:
            rNum = rNum + 1

        if i > 0:
            if (S[i] == "R") and (S[i-1] == "L"):
                result.append([rNum-1,lNum])
                rNum = 1
                lNum = 0

        if i == len(S) - 1:
            result.append([rNum,lNum])

    return result

def constructZero(n):
    res = ""
    for i in range(n):
        res = res + "0 "
    return res

def calculate2(arr):
    ret = ""
    for index in range(len(arr)):

        arr[index][0]
        arr[index][1]

        s1 = constructZero(arr[index][0]-1)
        s2 = constructZero(arr[index][1]-1)

        if arr[index][0] % 2 == 0:
            l1 = arr[index][0]//2
        else:
            l1 = (arr[index][0] + 1) // 2

        g1 = arr[index][0] - l1

        if arr[index][1] % 2 == 0:
            l2 = arr[index][1]//2
        else:
            l2 = (arr[index][1] + 1) // 2

        g2 = arr[index][1] - l2


        ret = ret + s1 + str(l1 + g2) + " " + str(l2 + g1)+ " " + s2

    return ret

S = input()
result = calculate(S)
ret = calculate2(result)
print(ret)

Measured memory_bytes: 8836
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long N,a,b,c,d,e;
    cin >> N >> a >> b >> c >> d >> e;
    long long mx = min({a,b,c,d,e});
    cout << 4+(N+mx-1)/mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1e5+5;
const int inf=1e9;
const ll mod=1e9+7;
int main() {
	
	int n;cin>>n;

	ll a[n+1];
	a[0]=0;

	ll t=0;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		t+=a[i];
		t%=mod;
	}


	ll ans=0;
	for(int i=1;i<=n;i++) {
		ll cur=(t-a[i]+mod)%mod;

		ans+= a[i]*cur;
		ans=ans%mod;
	}


	ll  mi=(mod+1)/2;

	cout<<(ans*mi)%mod<<endl;



}

Measured memory_bytes: 5184
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int main() {
	ll N,K,cnt=0;
	pair<int,int> x[55];
	ll ans=0;
	cin>>N>>K;
	rep(i,0,N)cin>>x[i].first>>x[i].second;
	sort(x,x+N);
	rep(i,0,N){
		rep(j,i,N){
			rep(k,0,N){
				rep(l,k,N){
					int maxx=max({x[i].first,x[j].first,x[k].first,x[l].first});
					int minx=min({x[i].first,x[j].first,x[k].first,x[l].first});
					int maxy=max({x[i].second,x[j].second,x[k].second,x[l].second});
					int miny=min({x[i].second,x[j].second,x[k].second,x[l].second});
					cnt=0;
					rep(z,0,N){
						if(minx<=x[z].first&&maxx>=x[z].first)
							if(miny<=x[z].second&&maxy>=x[z].second)
								cnt++;
					}
					if(cnt>=K){
						ll divx=abs(maxx-minx);
						ll divy=abs(maxy-miny);
						if(ans==0||divx*divy==0)ans=divx*divy;
						else ans=min(ans,divx*divy);
					}
				}
			}
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	string s,t;
	cin>>s>>t;
	int sn=s.size(), tn=t.size();

	vector<vector<int>> dp(sn+1,vector<int>(tn+1,0));

	repi(i,1,sn+1){
		repi(j,1,tn+1){
			if(s[i-1]==t[j-1])dp[i][j] = dp[i-1][j-1]+1;
			else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}

	string ans;
	int len = dp[sn][tn];
	while(len>0){
		if(sn>0&&dp[sn][tn]==dp[sn-1][tn])sn--;
		else if(tn>0&&dp[sn][tn]==dp[sn][tn-1])tn--;
		else ans+=s[sn-1], sn--, tn--, len--;
	}
	reverse(all(ans));
	cout<<ans<<endl;


	return 0;
}

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

//#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b,d)-max(a,c)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    static char[][] map;

    static int h;
    static int w;

    static boolean check(int i, int j){
        if(i != 0){
            if(map[i-1][j] == '#')  return true;
        }
        if(i != h-1){
            if(map[i+1][j] == '#')  return true;
        }
        if(j != 0){
            if(map[i][j-1] == '#')  return true;
        }
        if(j != w-1){
            if(map[i][j+1] == '#')  return true;
        }

        return false;
    }

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        h = Integer.parseInt(input[0]);
        w = Integer.parseInt(input[1]);
        
        map = new char[h][w];

        for(int i = 0; i < h; i++){
            map[i] = br.readLine().toCharArray();
        }

        boolean res = true;
        a:
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(map[i][j] == '#' && !check(i, j)){
                    res = false;
                    break a;
                }
            }
        }

        if(res){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
main(){
    int h,w;
    int i,j;
    scanf("%d %d",&h,&w);
    while(h||w){
        for(i=0;i<h;i++){
            for(j=0;j<w;j++)printf("#");
            printf("\n");
        }
        printf("\n");
        scanf("%d %d",&h,&w);
    }
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

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

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	int n;
	cin>>n;
	vector<int> l(n+1),r(n+1);
	REP(i,n)cin>>l[i]>>r[i];
	l[n]=r[n]=0;
	sort(l.begin(),l.end(),greater<int>());
	sort(r.begin(),r.end());
	ll ans=0;
	REP(i,n+1){
		if(l[i]>r[i])ans+=2*(l[i]-r[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
N = int(input())

lst_W = []
for i in range(N):
    lst_W.extend(input().split())

ans = "Yes"

for i in range(N - 1):
    if (lst_W[i])[-1:] != (lst_W[i+1])[:1]:
        ans = "No"
        break

if len(lst_W) != len(set(lst_W)):
    ans = "No"

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#define ll long long
int main(void){
    ll x;
    ll p,q;
    scanf("%lld",&x);
    p=x/11;
    q=x%11;
    if(q==0) printf("%lld\n",p*2);
    else if(q<=6) printf("%lld\n",p*2+1);
    else printf("%lld\n",p*2+2);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void) {
	int a, b, c,d,i,j,z;
	int q[200];
	for (i = 0; i < 200; i++) {
		q[i] = 0;
	}
	scanf("%d%d%d", &a, &b, &c);
	for (i = 0; i < b; i++) {
		scanf("%d", &d);
		q[d] = 1;
	}
	z = 0;
	for (i = c; i != 0; i--) {
		if (q[i] == 1)z++;
	}
	j = 0;
	for (i = c; i < a; i++) {
		if (q[i] == 1)j++;
	}
	printf("%d\n", (j > z) ? z : j);
	return 0;
}

Measured memory_bytes: 128
import fractions as math

n = int(input()) # 入力データの個数
a = list(map(int, input().split())) # 入力データ
 
l = [a[0] for _ in range(n+2)] # データの左端を初期値として追加
r = [a[-1] for _ in range(n+2)] # データの右端を初期値として追加
 
for i in range(n): # データのどこを置き換えるか
    l[i+1] = math.gcd(l[i], a[i]) # 置きかえる部分より左の最大公約数と置きかえる部分の最大公約数を更新する
    r[-(i+2)] = math.gcd(r[-(i+1)], a[-(i+1)]) # 置きかえる部分より右の最大公約数と置きかえる+1の最大公約数を更新する 
l[0] = r[0] = l[-1] = r[-1] = 0 # 初期値形に0を入れていく
 
ans = [math.gcd(l[i], r[i+2]) for i in range(n)] # 最大公約数のセットを改めて配列へ
print(max(ans)) # 最大公約数を出力

Measured memory_bytes: 16156
#include <bits/stdc++.h>
#include <string>
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
#define ll long long int
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)

using namespace std;
int prime(int n);
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b);
ll gcd(ll a, ll b);

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int prime(int n){
    int flag=1;
for(int i=2;i<=sqrt(n);i++){
    if(n%i==0){flag=0;break;}
}
  return flag;
}

int main(){
       ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int dp[n]={0};
dp[1]=abs(a[0]-a[1]);
for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
}
cout<<dp[n-1];
}


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

long long ds(long long n, long long b){
  if (n == 0) return 0;
  return n % b + ds(n/b, b);
}

int main(){
  long long n, s; cin >> n >> s;
  if (n == s) {
    cout << n + 1 << endl;
    return 0;
  }
  if ((n+1)/2 < s || n < s) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 2; i*i <= n; i++) {
    if (ds(n, i) == s) {
      cout << i << endl;
      return 0;
    }
  }
  long long mi = n+1;
  for (long long i = 1; i * i < n && s - i >= 0; i++) {
    if ((n - (s - i)) % i == 0 && (s-i) < (n - (s - i)) / i) {
      mi = min(mi, (n - (s - i)) / i);
    }
  }
  if (mi != n+1) cout << mi << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<string.h>
  int func()
  {
    int i,j,k;
    int a,b,n=0;
    bool e = 0;
    cin >> a >> b;
    if(b%2==0 && b>=a*2 && b<=a*4)
    {
      cout << "Yes";
      return 0;
    }
    cout << "No";
    return 0;
  }
  int main()
  {
  ios::sync_with_stdio(0);
  cin.tie(0);
/*  long long tc;
  cin >> tc;
  while(tc--)
  {
    func();
  }*/
//  int tc;
//  cin >> tc;
//  while(tc--)
  func();
  return 0;
  }


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

int main(){
  int A;
  cin >> A;
  int counter=0;
  if(A==1||A==2){
    cout << 4 <<endl;
  }else {
    while(A!=4){
      if(A%2==0){
        A /= 2;
      }else{
        A = A*3+1;
      }
      counter++;
    }
    cout << (counter+4) << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    long long int n;cin>>n;
    long long int dp[n];
    long long int arr[n];
    for(long long int i=0;i<n;i++)
        cin>>arr[i];
    dp[n-1]=0;
    dp[n-2]=abs(arr[n-1]-arr[n-2]);
    for(long long int i=n-3;i>=0;i--){
        if(i<0){
            break;
        }
        dp[i]=min((dp[i+1]+abs(arr[i]-arr[i+1])),dp[i+2]+abs(arr[i]-arr[i+2]));
    }    
    cout<<dp[0]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 1792
#include <stdio.h>

int main() {

    int x, cont_quinhentos, cont_cinco, hap, resto_quinhentos, resto_cinco;
    scanf("%d", &x);

        cont_quinhentos = x / 500;
        resto_quinhentos = x % 500;

        cont_cinco = resto_quinhentos / 5;
        resto_cinco = resto_quinhentos % 5;

    hap = (cont_quinhentos * 1000) + (cont_cinco * 5);
    printf("%d", hap);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;
 
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   cout << setprecision(14) << fixed;
   int n;
   cin >> n;
   vector<int> a(n);
   vector<ld> b(n);
   ld sum = 0;
   f(i,0,n){
      cin >> a[i];
      b[i] = 1;
      b[i] = b[i]/a[i];     
      sum += b[i];
   }
   ld ans = 1/sum;
   cout << ans << '\n';
   return 0;
} 

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

int main()
{
    int n;
    cin >> n;
    int d[20][20];
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) d[i][j] = 2;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        int x[20], y[20];
        for(int j = 0; j < a; j++){
            cin >> x[j] >> y[j];
            d[i][x[j] - 1] = y[j];
        }
    }
    int ans = 0;
    for(int i = 0; i < (1 << n); i++){
        bool f = true;
        for(int j = 0; j < n; j++){
            if(((i >> j) & 1) == 0) continue;
            for(int k = 0; k < n; k++){
                if((d[j][k] == 1 && ((i >> k) & 1) == 0) || (d[j][k] == 0 && ((i >> k) & 1) == 1)){
                    f = false;
                    break;
                }
            }
            if(!f) break;
        }
        if(f){
            int r = 0;
            for(int j = 0; j < n; j++) if((i >> j) & 1) r++;
            ans = max(ans, r);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

ll fn(ll b,ll n){
	if(n<b){
		return n;
	}
	return (n%b) + fn(b,n/b);
}


void solve(){
	ll n,s;
	cin>>n>>s;
	
	if(s > n){
		cout<<-1<<endl;
		return;
	}
	if(n==s){
		cout<<n+1<<endl;
		return;
	}

	for(ll b=2;b*b<=n;b++){
		if(fn(b,n) == s){
			cout<<b<<endl;
			return;
		}
	}

	ll dif = n-s;
	vector<ll> f;

	for(ll i=1; i*i<=dif;i++){
		if(dif%i==0){
			f.pb(i);
			if(dif/i != i){
				f.pb(dif/i);
			}
		}
	}

	sort(f.begin(), f.end());
	for(ll i:f){
		ll b = i;
		ll q = dif/i;
		b += 1;

		if(fn(b,n) == s){
			cout<<b<<endl;
			return;
		}
	}
	cout<<-1<<endl;

}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<vector>
int N,K;
struct S{double l,a,b;}a[20];
std::vector<int>v;
double H(double x){return x*x;}
double G(S&l,S&r){return H(l.l-r.l)+H(l.a-r.a)+H(l.b-r.b);}
double F(int n,int k,double d)
{
	if(k==K)return d;
	double r=0,x=0;
	if(N-n>K-k)r=F(n+1,k,d);
	for(int i=0;i<v.size();++i)d+=G(a[n],a[v[i]]);
	v.push_back(n);
	x=F(n+1,k+1,d);
	v.pop_back();
	return r>x?r:x;
}
int main()
{
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;++i)scanf("%lf%lf%lf",&a[i].l,&a[i].a,&a[i].b);
	printf("%.12f\n",F(0,0,0));
	return 0;
}

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

int mx;
string n;
int main()
{
	int i, t;
	cin >> n;
	for (i = 0; i < n.size(); i++) mx += n[i] - '0';
	t = (n.size() - 1) * 9 + n[0] - '0' - 1;
    cout << max(mx, t) << endl;
    return 0;
}

Measured memory_bytes: 256
N,K,Q = map(int,input().split(" "))
score = [0]
for _ in range(N):
    score.append(K)

for _ in range(Q):
    ans = int(input())
    score[ans] +=1

for i in range(1,N+1):
    if score[i] > Q:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 6620
N=int(input())
A=list(map(int,input().split()))
s=0

for i in range(N):
  if A[i]%2==0 and A[i]%3!=0 and A[i]%5!=0:
    s+=1
if s==0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060