akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int N; cin >> N;
    vector<string> v;
    for(int i=0; i<N; ++i){
        string s;
        cin >> s;
        v.push_back(s);
    }
    int ans=0;
    for(int i=0; i<N; ++i){
        bool flag=true;
        for(int p=0; p<N; ++p){
            for(int q=p+1; q<N; ++q){
                if(v[(i+p)%N][q]!=v[(i+q)%N][p]){
                    flag=false;
                    break;
                }
            }
        }
        if(flag) ans += N;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#入力を受け取る
a = []
for i in range (5):
  a += [int(input())]
#各メニューが届くのに必要な時間を計算
b = []
c = 9
d = -1
if (a[0] % 10 == 0 and a[1] % 10 == 0 and a[2] % 10 == 0 and a[3] % 10 == 0 and a[4] % 10 == 0):
  time = 0
  for i in range (5):
    time += a[i]
else:
  for i in range (5):
    m = a[i] % 10
    if m == 0:
      b += [a[i]]
    elif c >= m:
      c = m
      b += [((d // 10) + 1) * 10]
      d = a[i]
    else:
      b += [(a[i] // 10 + 1) * 10]
  time = d
  for i in range (5):
    time += b[i]
print(time)

Measured memory_bytes: 3064
import sys

def readQuestion():
    line = sys.stdin.readline()
    sline = line.rstrip()
    return sline  

def solve(s):
    count = 0
    for c in s:
        if c == 'o':
            count += 1
    y = 700 + 100 * count
    return y

def main():
    s = readQuestion()
    answer = solve(s)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
//ここまで共通
llong A, B, N;
int main() {
	cin >> A >> B >> N;
	if (N >= B) {
		cout << (A * (B - 1)) / B;
	}
	else {
		cout << (A * N) / B;
	}
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& x : a){
        cin >> x;
    }

    int i = 0; int j = n - 1;

    while (j >= 0){
        cout << a[j];
        if (i != n - 1){
            cout << " ";
        } else{
            cout << endl;
            return 0;
        }
        ++i;
        j -= 2;
    }

    j = (j == -1) ? 0 : 1;

    while (i < n){
        cout << a[j];
        if (i != n - 1){
            cout << " ";
        } else{
            cout << endl;
            return 0;
        }
        ++i;
        j += 2;
    }

    return 0;
}


Measured memory_bytes: 2944
import heapq
N = int(input())
c = input()

w = [i for i in range(N) if c[i]=='W']
r = [-i for i in range(N) if c[i]=='R']
heapq.heapify(w)
heapq.heapify(r)
ans = 0
for i in range(N):
    if w and r:
        a = heapq.heappop(w)
        b = -heapq.heappop(r)
        if a-b==1:
            break
        else:
            heapq.heappush(w,b)
            heapq.heappush(r,-a)
            ans += 1
print(ans)

Measured memory_bytes: 81512
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll N;cin>>N;
  ll i,j,k,l;
  ll A[N+1];
  rep(i,N) cin>>A[i];
  ll ans[N];
  rep(i,N) ans[i]=0;
  // ll left=-1,right=INF+1;
  for(i=0;i<N-1;i=i+2){
    ans[i+2]=ans[i]+2*(A[i+1]-A[i]);
  }
  ans[1]=ans[N-1]+2*(A[0]-A[N-1]);
  for(i=1;i<N-1;i+=2){
    ans[i+2]=ans[i]+2*(A[i+1]-A[i]);
  }
  ll tmp1=0,tmp2=0;
  rep(i,N) tmp1+=ans[i];
  rep(i,N) tmp2+=A[i];
  ll plus = (tmp2-tmp1)/N;
  rep(i,N) ans[i]+=plus;
  rep(i,N){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int A, B, C;
signed main() {
    cin >> A >> B >> C;
    if (A + B + C >= 22) { cout << "bust" << endl; }
    else { cout << "win" << endl; }
}


Measured memory_bytes: 256
N = int(input())
S = []

for i in range(N):
    S.append(input())

M = int(input())
T = []

for i in range(M):
    T.append(input())

U = list(set([''] + S + T))

R = []

for u in U:
    R.append(sum([s == u for s in S]) - sum([t == u for t in T]))

print(max(R))


Measured memory_bytes: 3060
n = int(input())  # 数値入�?
str = list(input())  # 一�?字ずつ格�?
dotto = str.count(".")
ans = dotto
syapu = 0

for i in range(0, n):
    if str[i] == ".":
        dotto -= 1
    else:
        syapu += 1

    if dotto + syapu < ans:
        ans = dotto + syapu

print(ans)


Measured memory_bytes: 4840
#include<queue>
#include<cstdio>
#include<algorithm>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;
typedef	pair<pii,int>	ppiii;

const int inf=1<<29,dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int inst[30][30],memo[30][30][4];

int main(){
	for(int w,h;scanf("%d%d",&w,&h),w;){
		int cost[4];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	scanf("%d",inst[i]+j),inst[i][j];
		for(int i=0;i<4;i++)	scanf("%d",cost+i);

		for(int i=0;i<h;i++)for(int j=0;j<w;j++)for(int k=0;k<4;k++)	memo[i][j][k]=inf;

		priority_queue< pair<int,ppiii> > pq;
		pq.push(mp(0,mp(mp(0,0),0)));
		while(!pq.empty()){
			pair<int,ppiii> a=pq.top();	pq.pop();
			int nowcost=-a.first;
			int y=a.second.first.first;
			int x=a.second.first.second;
			int dir=a.second.second;
			if(y==h-1 && x==w-1)	continue;

			for(int i=0;i<4;i++){
				int nextdir=(dir+4-i)%4;
				int yy=y+dy[nextdir],xx=x+dx[nextdir];
				if(yy<0 || h<=yy || xx<0 || w<=xx)	continue;

				int nextcost=nowcost+(inst[y][x]==i?0:cost[i]);
				if(nextcost<memo[yy][xx][nextdir]){
					memo[yy][xx][nextdir]=nextcost;
					pq.push(mp(-nextcost,mp(mp(yy,xx),nextdir)));
				}
			}
		}

		printf("%d\n",min(memo[h-1][w-1][0],memo[h-1][w-1][3]));
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
 
int main (void) {
    int x, n, max = 0;
    scanf("%d", &x);

    for ( int i = 1; i <= x; i++ ) {
        n = i;
        for ( int j = 0; j < x; j++ ) {
            n *= i;
            if( n > x ) break;
            if ( max < n ) max = n;
        }
    }

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

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int i, j, k;
  int n;
  int b, f, r, v;
  
  int tenants[4][3][10] = { 0 };

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    tenants[b -1][f - 1][r - 1] += v;
  }

  for (i = 0; i < 4; i++) {
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 10; k++) {
        printf(" %d", tenants[i][j][k]);
      }
      putchar('\n');
    }
    if (i != 3) {
      printf("####################\n");
    }
  }
  return 0;
}
        
    



Measured memory_bytes: 2108
require 'set'

n, m = gets.split.map &:to_i

friend = (1..n).map{ [] }
cost = {}

(1..m).each{
	i, j, f = gets.split.map &:to_i
	i -= 1
	j -= 1
	friend[i] << j
	friend[j] << i
	cost[[i,j]] = f
	cost[[j,i]] = f
}

rabbits = (0..n-1).to_a

best = 0

until rabbits.empty? 
	i = rabbits.min_by{|i| friend[i].size}
	clique = [[]]

	f = friend[i]
	(1..(1<<friend[i].size)-1).each{|x|
		y = x & (x - 1)
		k = Math.log2(x ^ (x-1)).to_i
		if c = clique[y]
			if c.all?{|j| j == f[k] || friend[j].include?(f[k])}
				clique[x] = c + [f[k]]
			else
				clique[x] = nil
			end
		else
			clique[x] = nil
		end
	}

	clique.compact!
	clique.map!{|c| c + [i]}
	clique.select!{|c| c.size > 1}

	clique.each{|c|
		x = c.map{|i|
			(c - [i]).map{|j|
				cost[[i,j]]	
			}.min
		}.inject(:+)
		best = x if x > best
	}

	rabbits.delete(i)
	friend.map{|f| f.delete(i)}
end

p best

Measured memory_bytes: 10012
#include <stdio.h>
#include <string.h>

typedef struct
{
    char line[102];
} cards_st;

int main(int argc, char *argv[])
{
    cards_st cards[1000] = {};
    int n;
    scanf("%d", &n);
    getchar();
    for (cards_st *elm = cards, *const end = elm + n; elm != end; ++elm)
    {
        fgets(elm->line, 102, stdin);
    }
    int taro_score = 0, hanako_score = 0;
    for (cards_st *elm = cards, *const end = elm + n; elm != end; ++elm)
    {
        const char *const taro = strtok(elm->line, " \n");
        const char *const hanako = strtok(NULL, " \n");
        const int cmp = strcmp(taro, hanako);
        taro_score += (cmp > 0) ? 3 : !cmp;
        hanako_score += (cmp < 0) ? 3 : !cmp;
    }
    printf("%d %d\n", taro_score, hanako_score);
    return 0;
}



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

using namespace std;

int main() {
  int n, r;
  while (cin >> n, cin >> r, n && r) {
    vector<int> card;
    for (int i = 0; i < n; i++) {
      card.push_back(i);
    }
    for (int i = 0; i < r; i++) {
      int p, c;
      cin >> p >> c;
      p--;
      for (int j = n-p-c; j < n-p; j++) {
        card.push_back(card[j]);
      }
      card.erase(card.begin() + n-p-c, card.begin() + n-p);
      for (int j = 0; j < card.size(); j++) {
        //cerr << card[j]+1 << " ";
      }
      //cerr << endl;
    }

    cout << card.back() +1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a)
    cout << "Yes" << endl;
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
typedef long long ll;

ll k, a, b;
ll x, y;

int main()
{
	scanf("%lld %lld %lld", &k, &a, &b);

	x = k + 1;

	y = a + (b - a) * ((k - a + 1) / 2) + (k - a + 1) % 2;

	printf("%lld\n", max(x, y));


	return 0;
}


Measured memory_bytes: 128
n = int(input())
aas = list(map(int, input().split()))
cnt = 0
res = 0
mini = float('inf')
for i in aas:
    if i < 0:
        cnt += 1
    res += abs(i)
    mini = min(mini, abs(i))
if cnt%2 == 0:
    print(res)
    exit()
print(res - mini*2)

Measured memory_bytes: 19940
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N;
    cin >> N;
    vec a(N);
    bool one = false;
    Rep (i, N) {
        char c;
        cin >> c;
        a[i] = c - '1';
        if (a[i] == 1) one = true;
    }

    ll cnt = 0;
    Rep (i, N) {
        if (a[i] == 1 and N-1 == (i | (N-1-i))) {
            cnt++;
        }
    }

    if (cnt % 2 == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (one) {
        cout << 0 << endl;
        return 0;
    }

    cnt = 0;
    Rep (i, N) {
        if (a[i] == 2 and N-1 == (i | (N-1-i))) cnt++;
    }
    if (cnt % 2 == 1) {
        cout << 2 << endl;        
    } else {
        cout << 0 << endl;
    }


}

Measured memory_bytes: 11064
N, M = map(int, input().split())
alist = [0] * M
blist = [0] * M
for i in range(M):
    alist[i], blist[i] = map(int, input().split())
city = list(range(1,N+1))
judge = [0] * N
count = dict(zip(city,judge))
for a,b in zip(alist,blist):
    count[a] += 1
    count[b] += 1
for c in count:
    print(count[c])
    

Measured memory_bytes: 3064
// Problem : E - Sequence Sum
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
#define F first
#define pii pair<int,int>
#define S second
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define eps 1e-7
#define I (int)
#define mod 1000000007
#define pb push_back
const long long INF = 1000000000000000000LL;
//const int WASTE=∞
const int N=1e5+5;
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  	// cout<<fixed;
  	// cout.precision(10);
   	// ofstream cout (".out");
    // ifstream cin  (".in");
    #define int ll
	ll n,X,m;
	cin>>n>>X>>m;
	vector<int>v;
	int z[N]; mem(z,-1);
	v.pb(X); z[X]=0;
	int sp;
	for(int x=1;x<=n;x++){
		X=((X%m)*(X%m))%m;
		if(z[X]>-1){
			sp=z[X]; break;
		}
		z[X]=x; v.pb(X);
	}
	ll ans=0,sz=v.size();
	int ps[sz]; ps[0]=v[0];
	for(int x=1;x<sz;x++) ps[x]=ps[x-1]+v[x];
	if(n<=sz){
		ans=ps[I n-1]; cout<<ans;
		return 0;
	}
	else ans+=ps[sp-1];
	int len=n-sp,l=sz-sp;
	ans+=len/l*(ps[sz-1]-ps[sp-1]);
	len%=l;
	ans+=ps[sp+len-1]-ps[sp-1];
   	// int lll=n-sp;
   	// ans+=lll/(nn-sp)*(ps[nn-1]-ps[sp-1]);
   	// ans+=ps[sp+(lll%(nn-sp))]-ps[sp-1];
   	cout<<ans;
   	
   	
   	
   	
   	
   	
   	
   	
   	
   	
  	return 0;
}



Measured memory_bytes: 4928
while line = gets
    break if line.chomp == "."
    s = []
    b = true
    line.chomp.each_char do |c|
        case c
        when "(", "["
            s.push(c)
        when ")", "]"
            pair = s.pop
            if (c == ")" && pair != "(") || (c == "]" && pair != "[")
                b = false
                break
            end
        end
    end
    if b && s.empty?
        puts "yes"
    else
        puts "no"
    end
end

Measured memory_bytes: 6108
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int A = int.Parse(Console.ReadLine());
		int[]B = new int[101];
		for(var i=2;i<=A;i++){
			int t = i;
			int j = 2;
			while(j*j<=i){
				if(t%j==0){
					B[j] += 1;
					t /= j;
				} else {
					j++;
				}
			}
			if(t>1){
				B[t] += 1;
			}
		}
		//for(var i=0;i<=100;i++){
		//	Console.Write(B[i]+" ");
		//}
		int ans = 0;
		if(B[2]>=74){
			ans += 1;
		}
		for(var h=2;h<=7;h++){
			if(B[h]>=24){
				for(var i=2;i<=100;i++){
					if(B[i] >= 2 && h!=i){
						ans += 1;
					}
				}
			}
		}
		for(var h=2;h<=7;h++){
			if(B[h]>=14){
				for(var i=2;i<=100;i++){
					if(B[i] >= 4 && h!=i){
						ans += 1;
					}
				}
			}
		}
		for(var h=2;h<=100;h++){
			if(B[h]>=4){
				for(var i=h+1;i<=100;i++){
					if(B[i] >= 4 && h!=i){
						for(var j=2;j<=100;j++){
							if(B[j] >= 2 && h!=i && h!=j && i!=j){
								ans += 1;
							}
						}
					}
				}
			}
		}
		Console.Write(ans);
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[55],b[55],c[55],d[55];
int n,m,q;
int num[12]={0};
int cal(){
    int ret = 0;
    for(int i=0;i<q;i++){
        if(num[b[i]-1]-num[a[i]-1]==c[i])
            ret+=d[i];
    }
    return ret;
}
int dfs(int ind,int maxnum){
    if(ind==n){
        return cal();
    }
    int ret = 0;
    for(int i=maxnum;i<=m;++i){
        num[ind]=i;
        ret = max(ret,dfs(ind+1,max(maxnum,i)));
    }
    return ret;
}
int main()
{
    cin >> n >> m >> q;
    for(int i=0;i<q;i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    cout << dfs(0,1)<<endl;
    return 0;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
void alert(vector<int> vec){
  int64_t N = vec.size();
  for(int64_t i=0; i<N-1; i++) cout << vec.at(i) << " ";
  cout << vec.at(N-1) << endl;
}

int main(){
  int64_t N; cin >> N;
  vector<int64_t> A(N), B(N), C(N+1), D;
  for(int64_t i=0; i<N; i++) cin >> A.at(i);
  B = A;
  sort(B.begin(), B.end());
  for(int64_t i=0; i<N; i++){
    if(C.at(B.at(i))==0) D.push_back(B.at(i));
    C.at(B.at(i))++;
  }
  int64_t res = 0;
  int64_t c;
  for(int64_t i=0; i<D.size(); i++){
    c = C.at(D.at(i));
    res += c*(c-1)/2;
  }
  vector<int64_t> ans(N);
  for(int64_t i=0; i<N; i++){
    c = C.at(A.at(i));
    ans.at(i) = res - c*(c-1)/2 + (c-1)*(c-2)/2;
  }
  for(int64_t i=0; i<N; i++) cout << ans.at(i) << endl;
}

Measured memory_bytes: 8948
#include<bits/stdc++.h>
using namespace std;
int n;
int l,r;
int a[10000005];
inline int read()
{
   int s=0,w=1;
   char ch;
   ch=getchar();
   while(ch>'9'||ch<'0')
   {
	  if(ch=='-')
	 {
	   w=-1;
	 }
	   ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
	  s=(s<<1)+(s<<3)+(ch^48);
	  ch=getchar();}
	  return s*w;
}
inline bool check(int a,int b,int c)
{
	return a<=c&&b<=c;
}
inline bool checkb(int a,int b,int c)
{
	return a>c&&b>c;
}
inline int pd(int x)
{
	for(int i=0;i<n-1;i++)
	{
		if(checkb(a[n+i],a[n+i+1],x)||checkb(a[n-i],a[n-i-1],x)) 
		{
			return 0;
		}
		if(check(a[n+i],a[n+i+1],x)||check(a[n-i],a[n-i-1],x))
		{
			return 1;
		}
		
	}
	return check(a[1],a[1],x);
}
int main()
{
	//freopen("pyramid.in","r",stdin);
	//freopen("pyramid.out","w",stdout);
	n=read();
	for(int i=1;i<=2*n-1;i++)
	{
		a[i]=read();
	}
	l=1;
	r=2*n-1;
	int mid;
	while(l<r)
	{
		mid=(l+r)>>1;
		if(pd(mid))
		{
			r=mid;
		}
		else 
		{
			l=mid+1;	
		}
	}
	cout<<r;
	return 0;

}




Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;


int main(){
    string s;
    cin >> s;
    int cnt = 0;
    for(int i=0;i<s.size()-1;i++){
        string sub=s.substr(i,2);
        if(sub == "WB" || sub == "BW") cnt++;
    }
    cout << cnt <<endl;
}


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

int main(void) {
	// input
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for(int i = 0; i < n; ++i) std::cin >> a[i];

	// /2 for each a
	int sum2 = 0;
	for(int i = 0; i < n; ++i) {
		while(a[i] % 2 == 0) {
			a[i] /= 2;
			++sum2;
		}
	}

	std::cout << sum2 << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a-c) <= d || abs(a-b) <= d && abs(b-c) <= d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#define FOR(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
int H, W;
bool flag = true;
bool x[50][50];
bool y[50][50];
int main(void) {
	cin >> H>>W;
	FOR(i,0,H){
		FOR(k,0,W){
			char a;
			cin >> a;
			if (a == '#')x[i][k] = true;
		}
	}

	FOR(i, 0, H)FOR(k, 0, W) {
		if (i != 0)if (x[i][k] == x[i - 1][k])y[i][k] = y[i - 1][k] = true;
		if (i != H - 1)if (x[i][k] == x[i + 1][k])y[i][k] = y[i + 1][k] = true;
		if (k != 0)if (x[i][k] == x[i][k - 1])y[i][k] = y[i][k - 1] = true;
		if (k != W - 1)if (x[i][k] == x[i][k + 1])y[i][k] = y[i][k + 1] = true;
		if (x[i][k])if(!y[i][k]) {
			flag = false;
			break;
		}
		if (!flag)break;
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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


int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    while(A > 0 && C > 0){
        C-=B;
      if(C <= 0)break;
        A-=D;
    }

    if(A<=0) cout << "No" << endl;
    else cout << "Yes" << endl;
}


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

int main() {
  int c[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c[i][j];
    }
  }
  for (int a1 = -100; a1 <= 100; a1++) {
    bool flag = true;
    int b1 = c[0][0] - a1;
    int b2 = c[0][1] - a1;
    int b3 = c[0][2] - a1;
    int a2 = c[1][0] - b1;
    if (a2 + b2 != c[1][1]) flag = false;
    if (a2 + b3 != c[1][2]) flag = false;
    int a3 = c[2][0] - b1;
    if (a3 + b2 != c[2][1]) flag = false;
    if (a3 + b3 != c[2][2]) flag = false;
    if (flag) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;

#define UPDATE do {\
 int w = A*cntA + B*cntB;\
    if(cntA+cntB < ansA+ansB || (cntA+cntB == ansA+ansB && w < ansW)) {\
        ansA = cntA; ansB = cntB; ansW = w;\
    }\
} while(0)

int main() {
    while(true) {
        int A, B, D;
        cin >> A >> B >> D;
        if(!A && !B && !D) break;

        int lim = 2000000000/A;
        int cur = 0;
        int ansA = 100000, ansB = 100000;
        int ansW = A*ansA + B*ansB;

        for(int cntA = 0; cntA <= lim; ++cntA) {
            if(cur <= D && (D-cur) % B == 0) {
                int cntB = (D-cur) / B;
                UPDATE;
            }
            if((A*cntA+D) % B == 0) {
                int cntB = (A*cntA+D) / B;
                UPDATE;
            }
            if(A*cntA-D > 0 && (A*cntA-D) % B == 0) {
                int cntB = (A*cntA-D) / B;
                UPDATE;
            }
            if(D-A*cntA > 0 && (D-A*cntA) % B == 0) {
                int cntB = (D-A*cntA) / B;
                UPDATE;
            }
            cur += A;
            lim = ansA + ansB;
        }

        cout << ansA << ' ' << ansB << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// #define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}
bool check(string s)
{
	for (int i=0; i<sz(s); i++)
	{
		if (s[i]!=s[sz(s)-i-1])
			return false;
	}
	return true;
}
int LIM=3010;
vv64 dp(LIM,v64(LIM,0));
void solve()
{
//Read Comments below main
	ll n,s;
	cin>>n>>s;
	v64 arr(n+1,0);
	for (int i=1; i<=n; i++)
		cin>>arr[i];
	for (int i=1; i<=n; i++)
	{
		dp[i][arr[i]]=i;
		for (int j=1; j<=s; j++)
		{	
			dp[i][j]+=dp[i-1][j];
			dp[i][j]%=MOD;
			if (j>=arr[i])
				dp[i][j]+=dp[i-1][j-arr[i]];
			dp[i][j]%=MOD;
		}
	}
	ll ans=0;
	for (int i=1; i<=n; i++)
	{
		ll temp=dp[i][s]-dp[i-1][s]+MOD;
		temp%=MOD;
		temp=(temp*(n-i+1))%MOD;
		ans=(ans+temp)%MOD;
	}
	cout<<ans<<endl;
}
 
int main() {
    fast_cin();
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
// BITMASK:
// 1)When some constraint is of the order of 15-20, think of bitmask DP.
// 2)When some constraint is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algo

Measured memory_bytes: 71296
#include <algorithm>
#include <cstdio>
#include <map>
#include <utility>
#define x first
#define y second
typedef std::pair<int,int> pii;
const int MAXN = 2e5+5;
const int MOD = 998244353;
std::map<int,int> X, Y;
int two[MAXN];
pii S[MAXN];
int N;

struct SegmentTree {
  int data[MAXN<<2];

  void build() {
    return build(1, 1, N);
  }

  int get(int i, int j) {
    if (i > j) return 0;
    return get(1, 1, N, i, j);
  }

  void set(int i, int v) {
    return set(1, 1, N, i, v);
  }

private:
  void build(int f, int l, int r) {
    if (l == r) return;

    int g = f<<1;
    int m = (l+r)/2;
    build(g  , l  , m);
    build(g|1, m+1, r);
    data[f] = 0;
  }

  int get(int f, int l, int r, int i, int j) {
    if (j < l || r < i) return 0;
    if (i <= l && r <= j) return data[f];

    int g = f<<1;
    int m = (l+r)/2;
    return
      get(g  , l  , m, i, j) +
      get(g|1, m+1, r, i, j);
  }

  void set(int f, int l, int r, int i, int v) {
    if (i < l || r < i) return;
    if (l == r) {
      if (i == l) data[f] = v;
      return;
    }
    int g = f<<1;
    int m = (l+r)/2;
    set(g  , l  , m, i, v);
    set(g|1, m+1, r, i, v);
    data[f] = data[g] + data[g|1];
  }
} segtr;

void init() {
  two[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    two[i] = 2LL * two[i-1] % MOD;
  }
}

int main() {
  init();
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf(" %d%d", &S[i].x, &S[i].y);
    X[S[i].x] = 0;
    Y[S[i].y] = 0;
  }
  // Coordinate Compression
  int xn = 0;
  for (auto& xtr: X) xtr.second = ++xn;
  int yn = 0;
  for (auto& ytr: Y) ytr.second = ++yn;
  for (int i = 0; i < N; ++i) {
    S[i].x = X[S[i].x];
    S[i].y = Y[S[i].y];
  }
  std::sort(S, S+N);
  segtr.build();
  int ret = 0;
  for (int i = 0; i < N; ++i) {
    // Segment Tree queries.
    int NN = N - S[i].y;
    int SS = S[i].y - 1;
    int NW = segtr.get(S[i].y + 1, N);
    int SW = segtr.get(1, S[i].y - 1);
    int sum = two[N];
    sum = (1LL * sum - two[NN] + MOD) % MOD; // N
    sum = (1LL * sum - two[SS] + MOD) % MOD; // S
    sum = (1LL * sum - two[N - S[i].x] + MOD) % MOD; // E
    sum = (1LL * sum - two[S[i].x - 1] + MOD) % MOD; // W
    sum = (1LL * sum + two[NN - NW]) % MOD; // NE
    sum = (1LL * sum + two[SS - SW]) % MOD; // SE
    sum = (1LL * sum + two[NW]) % MOD; // NW
    sum = (1LL * sum + two[SW]) % MOD; // SW
    sum = (sum + MOD - 1) % MOD; // empty set
    segtr.set(S[i].y, 1);
    ret = (1LL * ret + sum) % MOD;
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 24448
#include <iostream>
#include <cstdlib>
typedef long long ll;
using namespace std;

int main() {
    int n, m;
    ll a[50], b[50], c[50], d[50];
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }

    /* for (int i = 0; i < n; i++) { */
    /*     cout << a[i] << b[i] << endl; */
    /* } */

    ll ans[50];
    int ansnum[50];
    ll ky;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ky = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (j == 0) {
                ans[i] = ky;
                ansnum[i] = 0;
            } else if (ky < ans[i]) {
                ans[i] = ky;
                ansnum[i] = j;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ansnum[i] + 1 << endl;
    }

    return 0;
}


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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

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

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 3e5 + 5;

ll A, B, N;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> A >> B >> N;
	ll x = min(N, B-1);
	ll a = A * x / B;
	ll b = x / B;
	ll c = b * A;
	cout << a - c;
}


Measured memory_bytes: 3648
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define track  1;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

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

void solve()
{
	int i,j,cnt=0;
	bool flag=0;
	string s,t;
	cin>>s>>t;

	if(t.length()==s.length()+1)
	{
		string temp = t.substr(0,t.length()-1);
		if(temp==s)
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	else
	{
		cout<<"No"<<endl;
	}



	

}

Measured memory_bytes: 3616
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = 0
    for i in range(1, N+1):
        for j in range(i, N+1, i):
            ans += j
    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 73404
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, s;
    cin >> n >> s;
    ll dp[n+5][s+5] = {};
    ll ans = 0;
    for (int i = 1 ; i <= n ; i++) {
        int add;
        cin >> add;
        for (int j = 0 ; j <= s ; j++) {
            dp[i][j] = dp[i-1][j];
            if (j == add) {
                dp[i][j] += i;
            }
            if (j >= add) {
                dp[i][j] += dp[i-1][j-add];
            }
            dp[i][j] %= mod;
        }
        ans += (dp[i][s] - dp[i-1][s] + mod) * (n - i + 1);
        ans %= mod;
    }
    cout << ans << '\n';
}

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

int main(){
  int N;
  double X=0;
  cin>>N;
  vector<int> num(N);
  for(int i=0;i<N;i++){
    cin>>num.at(i);
    X+=(double)1/num.at(i);
  }
  cout<<1/X<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(){
    int N,i,x,temp=0;
    long int SUM=0;

    scanf("%d",&N);

    int a[N+1],b[N+1];
    for(i=0;i<N+1;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<N;i++){
        scanf("%d",&b[i]);
    }
    b[N]=0;
    for(i=0;i<N+1;i++){
        x=a[i]+temp;
        if(x>0){
            x-=b[i];
            if(x>0){
                SUM+=b[i]-temp;
                temp=0;
            }else{
              SUM+=a[i];
                temp=x;
            }
        }else{
            SUM+=a[i];
            temp=-b[i];
        }
    }
    printf("%ld\n",SUM);
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //命令の数
        ArrayList<Integer> a = new ArrayList<Integer>();
        int q;
        for (int i=0; i<n; i++) {
            q = sc.nextInt();
            if(q==0) pushBack(sc.nextInt(), a);
            else if(q==1) randomAccess(sc.nextInt(), a);
            else popBack(a);
        }
    }
    static void pushBack(int q, ArrayList<Integer> a) {
        a.add(q);
    }
    static void randomAccess(int q, ArrayList<Integer> a) {
        System.out.println(a.get(q));
    }
    static void popBack(ArrayList<Integer> a) {
        a.remove(a.size()-1);
    }
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r,D,x;
    cin >> r >> D >> x;
    REP(i,10){
        x = r*x-D;
        cout <<x << "\n";
    }
}

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

using namespace std;

int main(){
  int A[3][3];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
    cin >> A[i][j];
    }  
    }

    int N;
    cin >> N;
    

    int A1[3][3];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
    A1[i][j] = 0;
    }  
    }
 int b[N];
 for(int i = 0; i < N; i++) cin >> b[i];
    for(int i = 0; i < N; i++){
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
          if(A[j][k] == b[i]) A1[j][k] = 1;
        }
      }
    }

    if(A1[0][0] == 1 && A1[1][1] == 1 && A1[2][2] == 1 ){ cout << "Yes"; return 0;}
    if(A1[0][2] == 1 && A1[1][1] == 1 && A1[2][0] == 1 ){ cout << "Yes"; return 0;}
    int count = 0;
    for(int i = 0; i < 3; i++){
       count = 0;
      for(int j = 0; j < 3; j++){
        if(A1[i][j] == 1) count++;
       
      }
      if(count == 3){ cout << "Yes"; return 0; }

    }
for(int j = 0; j < 3; j++){
  count = 0;
      for(int i = 0; i < 3; i++){
        if(A1[i][j] == 1) count++;
        
      }
      if(count == 3){ cout << "Yes"; return 0; }

    }

    cout << "No";


  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,a,b, x, ans=0, y;
    cin>>n>>a>>b;
    x = n/(a+b);
    ans+=(x*a);
    y = n%(a+b);
    ans+=(min(a, y));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(n)]
a=sorted(a)
money=0
cnt=0
for i in a:
    if cnt+i[1]<=m:
        cnt+=i[1]
        money+=i[0]*i[1]
    else:
        money+=(m-cnt)*i[0]
        break
print(money)

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

int main()
{
  char c;
  cin >> c;

  if ( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' )
  {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

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

int main()
{
    long long int n;cin>>n;
    vector<char>v;

    while(n>0)
    {
        n-=1;
        v.push_back('a'+(n%26));
        n/=26;
    }
    for(auto i=v.rbegin();i!=v.rend();i++)cout<<*i;cout<<endl;
}


Measured memory_bytes: 3576
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    vector<int> a(N+5,0);
    for (int i=1; i<=N; i++) {
        cin >> a[i];
    }
 
    vector<int> l(N+5,0);
    l[1]=a[1];
    for (int i=2; i<=N; i++) {
        l[i]= __gcd(l[i-1], a[i]);
    }
 
    vector<int> r(N+5,0);
    r[N]=a[N];
    for (int i=N-1; i>=1; i--) {
        r[i]=__gcd(r[i+1], a[i]);
    }
 
 
    int ans=0;
    for (int i=1; i<=N; i++) {
        ans=max(ans, __gcd(l[i-1],r[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

struct ModCombination {
    vector<mint> Fac;
    vector<mint> Facinv;

    ModCombination(int x) {
        Fac.assign(x+1,1);
        Facinv.resize(x+1);
        for (long long i = 1; i <= x; i++) Fac[i] = Fac[i-1]*i;
        for (int i = 0; i <= x; i++) Facinv[i] = mint(1)/Fac[i];
    }

    mint get(int n, int k) {
        return Fac[n]*Facinv[k]*Facinv[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,M,K; cin >> N >> M >> K;

    ModCombination MC(N*M);

    mint cntN = 0;
    mint cntM = 0;
    for (ll i = 1; i <= N; i++) cntN += (i-1LL)*i;
    for (ll i = 1; i <= N; i++) cntN -= i*(N-i);
    for (ll i = 1; i <= M; i++) cntM += (i-1LL)*i;
    for (ll i = 1; i <= M; i++) cntM -= i*(M-i);
    cntN *= M*M;
    cntM *= N*N;
    mint ans = (cntN+cntM)*MC.get(N*M-2,K-2);

    cout << ans.a << endl;
}

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


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

    int b[n][10];
    

    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin >> b[i][j];
        }
    }

    bool check[n];
    for(int i=0;i<n;i++){
        check[i]=true;
    }

    for(int i=0;i<n;i++){
        vector<int> x,y;
        x.push_back(0);
        y.push_back(0);
        x.push_back(b[i][0]);
        
        
        for(int j=1;j<10;j++){
            int pa = x[x.size()-1];
            int pb = y[y.size()-1];

            int p = b[i][j];

            if(p<pa&&p<pb){
                check[i] = false;
            }else if(p<pa&&p>pb){
                y.push_back(p);
            }else if(p>pa&&p<pb){
                x.push_back(p);
            }else{
                if(pa<pb){
                    y.push_back(p);
                }else{
                    x.push_back(p);
                }
            }
        }
    }


    for(int i=0;i<n;i++){
        if(check[i]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n;
  cin >> n;
  vector<int> s(n);
  int sum = 0;
  for (int i = 0; i < n; i++){
    cin >> s[i];
    sum += s[i];
  }
  sort(s.begin(), s.end());

  if (sum % 10 != 0)
    cout << sum << endl;
  else {
    int a = 0;
    for (int i = 0; i < n; i++){
      if (s[i] % 10 != 0){
        a = s[i];
        break;
      }
    }
    if (a == 0)
      cout << 0 << endl;
    else
      cout << sum - a << endl;
  }

  return 0;
}

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n!=0){
		int max = n/2 + 1;
		int min = max -1;
		int cnt = 0;
		int sum = max+min;
		while(min!=0){
		    if(sum == n){
			cnt++;
			min -= 1;
			sum += min;
		    }
		    else if(sum > n){
			sum -= max;
			max -= 1;
		    }
		    else if(sum < n){
			min -= 1;
			sum += min;
		    }
		}
		
		System.out.println(cnt);
	    }
	}
    }
}

Measured memory_bytes: 19316
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define endl '\n'
#define loop(a,b,c) for(ll i=a;i<=b;i+=c)
#define intarr(arr,n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i]
#define inparr(arr,n) for(ll i=0;i<n;i++)cin>>arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define newline cout<<endl
#define ump unordered_map<ll,ll>
#define vec vector<ll>
#define mkp make_pair
#define disp(var1,var2) cout<<var1<<" "<<var2<<endl;
#define all(v)             v.begin(),v.end()
#define cout(var) cout<<var<<endl
#define mod2 998244353
#define fbo find_by_order  /// find kth smallest by passing k-1
#define ook order_of_key  //// find no of smaller items less than k
#define teensort(a,r,g,b) a[0]=r;a[1]=g;a[2]=b;sort(a,a+3);
#define ss second
#define ff first
#define displayarray(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
#define pi pair<ll,ll>
#define meramax 1e18
#define meramin -1e18
#define percentile 1000000007
void AcDegaYe() 
{
    ll n,k;
    cin>>n>>k;
    vec a,v;
    a.pb(-1);
    inpvec(a,n);
    map<ll,ll> h;
    ll start=1;
    ll cnt=0,fs=1;;
    while(1)
    {
        if(h.count(start)==1)
        {
            //cout(cnt);
            break;
        }
        else
        {
            h[start]=1;
            start=a[start];
            cnt++;
            if(cnt==k)
            {
                cout(start);
                return;
            }
        }
    }
    v.pb(start);
    ll s2=a[start];
    ll size=1;
    while(s2!=start)
    {
        v.pb(s2);
        size++;
        s2=a[s2];
    }
    cnt=cnt-(size);
    //cout(size);
    //cout(cnt);
    // for(ll i=0;i<v.size();i++)
    // {
    //     cout<<v[i]<<" ";
    // }
    k-=cnt;
    k=k%size;
    cout(v[k]);
}
int main()
{   
    fastio
    //ll t;
    //cin>>t;
    ll t=1;
    while(t--)
    {
        AcDegaYe();
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 15400
#include <algorithm>
#include <cstdio>
typedef long long LL;
const int N = 100050;
LL w[N], d[N];
int n, k;
bool check(LL m) {
  int r = k;
  for (int i = 0; i < n; ++i) {
    LL t = std::max(0LL, (m - w[i] + d[i]) / d[i]);
    if (t >= r) return true;
    r -= t;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%lld%lld", &w[i], &d[i]);
  LL l = 1, r = 9000000000000000000LL;
  while (l < r) {
    LL mid = (l + r) / 2;
    if (check(mid)) r = mid;
    else l = mid + 1;
  }
  printf("%lld\n", l);
  return 0;
}


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

int main(){
	while(1){
		int m, f, r;
		cin >> m >> f >> r;
		int p = m+f;
		int q = p+r;
		if(q==-3) break;
		if(m==-1 || f==-1 || p<30){
			cout << "F" << endl;
			continue;
		}
		if(p>=80){
			cout << "A" << endl;
			continue;
		}
		if(p<80 && p>=65){
			cout << "B" << endl;
			continue;
		}
		if((p<65 && p>=50) || r>=50){
			cout << "C" << endl;
			continue;
		}
		else cout << "D" <<endl;
	}
	return 0;
}

Measured memory_bytes: 1156