akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

// Order statistics tree (if supported by judge!):
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// template<class TK, class TM> using order_tree = tree<TK, TM, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
// iterator	find_by_order(int r) (zero based)
// int		order_of_key(TK v)
// template<class TV> using order_set = order_tree<TV, null_type>;

#define x first
#define y second
#define rs resize
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define rep(i,a,b) for(auto i=(a);i!=(b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<ii> vii;
template<class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;

template<class T1, class T2>
ostream& operator<<(ostream &out, const pair<T1,T2> &a) { return out << '(' << a.x << ", " << a.y << ')'; }
template<class T1, class T2>
istream& operator>>(istream &in, pair<T1,T2> &a) { return in >> a.x >> a.y; }

template<class T> int sz(const vector<T> &v) { return (int) v.size(); }

template<class T> ostream& operator<<(ostream &os, vector<T> v) {
	os << "\n[";
	for(T &x : v) os << x << ',';
	return os << "]\n";
}

const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

// lambda-expression: [] (args) -> retType { body }

void run() {
	int a, b;
	cin >> a >> b;

	string s, t;
	REP(i, a) s += ('0' + b);
	REP(i, b) t += ('0' + a);

	cout << min(s, t) << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr << boolalpha;
	(cout << fixed).precision(10);

	run();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int n;
    cin>>n;
    set<char> st;
    rep(i,0,n){
        char  c;
        cin>>c;
        st.insert(c);
    }
    if(st.size()==3)cout<<"Three"<<endl;
    else cout<<"Four"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N, 0);
for(int i = 0; i < N; i++){
cin >> A.at(i);}
vector<int> Cul(N);
for(int i = 0; i < N; i++){
Cul.at(A.at(i) - 1)++;}
sort(Cul.begin(), Cul.end());
reverse(Cul.begin(), Cul.end());
int sum = 0;
for(int i = K; i < N; i++){
sum += Cul.at(i);}
cout << sum << endl;}


Measured memory_bytes: 1792
#include <cstdio>

using namespace std;

int cost(int a, int b)
{
    int rezultat = a - b;
    if (rezultat < 0)
        rezultat = -rezultat;
    return rezultat;
}

int min(int a, int b)
{
    if (a < b) return a;
    return b;
}

int main()
{
    int n(0);
    scanf("%d",&n);

    int a(0), b(0), c(0), costA(0), costB(0), costC(0);
    scanf("%d %d",&a,&b);
    if (n == 2)
    {
        printf("%d",cost(a,b));
    }
    else
    {
        costB = cost(a,b);
        for (int i = 3 ; i <= n ; i++)
        {
            scanf("%d",&c);
            costC = min(costA + cost(a,c),costB + cost(b,c));

            a = b;
            b = c;
            costA = costB;
            costB = costC;
        }
        printf("%d",costC);
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

ll cut_calc(ll A, ll L) {
    return A / L - (A % L == 0);
}

ll calc(vector<ll> *A, ll L) {
    ll cnt = 0;
    for (ll i : *A) {
        cnt += cut_calc(i, L);
    }
    return cnt;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    cin >> A;
    ll left = 0, right = INF;
    while (right - left > 1) {
        ll mid = left + (right - left) / 2;
        if (calc(&A, mid) <= K) right = mid;
        else left = mid;
    }
    cout << right << endl;
}

Measured memory_bytes: 4844
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
 ll ans = 0;
  int n;
  cin>>n;
  vector<ll>d(n);
  for(int i=0;i<n;i++)cin>>d[i];
  for(int i=0;i<n;i++){
   for(int j=i+1;j<n;j++){
     ans+=d[i]*d[j];
   }
  }
  cout<<ans;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int dfs(vector<int> &ps, vector<int> &d, vector<bool> &visited, int v){
    if(visited[v])
        return d[v];
    
    visited[v] = true;
    if(ps[v] == 0)
        return d[v] = v;
    
    return d[v] = dfs(ps, d, visited, v + ps[v]);
}

int bfs(vector<int> &d, vector<int> &dp){
    int N = d.size();
    queue<int> q;
    dp[0] = 0;
    q.push(0);
    
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int i=1; i<=6; i++){
            if(N-1 <= v+i || d[v+i] == N-1)
                return dp[v] + 1;
            
            if(d[v+i] >= 0 && dp[d[v+i]] == INF){
                dp[d[v+i]] = dp[v] + 1;
                q.push(d[v+i]);
            }
        }
    }
    
    //No Implement
    return -1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    vector<int> ps(N);
    vector<int> d(N, -1);
    vector<int> dp(N, INF);
    vector<bool> visited(N, false);
    
    for(auto &p: ps)
        cin >> p;
    
    for(int i=0; i<N; i++)
        d[i] = dfs(ps, d, visited, i);
    
    cout << bfs(d, dp) << endl;
    
    return 0;
}

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

int n, m;
int C[21];

int solve() {
  int t[21][50001];
  
  for (int i = 0; i <= m; i++) t[i][0] = 0;
  for (int j = 1; j <= n; j++) t[0][j] = 999999;
  
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (j < C[i]) {
        t[i][j] = t[i-1][j];
      } else {
        t[i][j] = min(t[i][j - C[i]] + 1, t[i - 1][j]);
      }
    }
  }
  
  return t[m][n];
}

int main(void){
    
    cin >> n >> m;
    C[0] = 0;
    for (int i = 1; i <= m; i++) cin >> C[i];
    
    int res = solve();
    
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 5260
using namespace std;
#include<bits/stdc++.h>
/*
 aca
 accc
 ca
 */
int main() {
	string s[3];
	for (int i = 0; i < 3; ++i) {
		cin >> s[i];
	}
	int i = 0, aj = 0, bj = -1, cj = -1, j = 0;

	while (s[i][j] == 'a'||s[i][j] == 'b'||s[i][j] == 'c') {
		if (s[i][j] == 'a') {
			aj = aj + 1;
			j = aj;
			i = 0;
		} else if (s[i][j] == 'b') {
			bj = bj + 1;
			j = bj;
			i = 1;
		} else if (s[i][j] == 'c') {
			cj = cj + 1;
			j = cj;
			i = 2;
		}
	}
	if (i == 0) {
		cout << 'A' << endl;
	} else if (i == 1) {
		cout << 'B' << endl;
	} else if (i == 2) {
		cout << 'C' << endl;
	}
}


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

#define   REP(i, n) for(int i = 0;            i <  (int)(n); i++)
#define  CREP(i, n) for(int i = 1;            i <= (int)(n); i++)
#define  RREP(i, n) for(int i = (int)(n) - 1; i >= 0;        i++)
#define RCREP(i, n) for(int i = (int)(n);     i >  0;        i++)

#define INF  std::numeric_limits<int>::max()
#define NINF std::numeric_limits<int>::min()

#define D_MAX 10

using namespace std;
using ll = long long;

int D, G;
int p[D_MAX];
int c[D_MAX];

int solve() {
    int min_solve_num = INF;

    // bit全探索
    for(int mask = 0; mask < (1 << D); mask++) {
        int solve_num = 0;
        int point = 0;

        for(int i = 0; i < D; i++) {
            if((mask >> i) & 1) {
                solve_num += p[i];
                point += 100 * (i + 1) * p[i];
                point += c[i];
            }
        }

        // 端数を処理
        if(point < G) {
            int stride = 0;
            while(stride < D) {
                if(((mask << stride) & (1 << (D - 1))) == 0) {
                    break;
                }
                stride++;
            }

            int cnt = 0;
            while(point < G && cnt < p[D - stride - 1]) {
                point += 100 * (D - stride);
                solve_num++;
                cnt++;
            }
        }

        if(G <= point) {
            min_solve_num = min(min_solve_num, solve_num);
        }
    }

    return min_solve_num;
}

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

    std::cin >> D >> G;
    REP(i, D) {
        std::cin >> p[i] >> c[i];
    }

    std::cout << solve() << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  if (n == 2) {
    sort(a.begin() ,a.end());
    if ((a[0] + a[1]) % 3 != 0) {
      cout << "NO" << endl;
      return 0;
    }
    if (a[1] - a[0] > a[0]) {
      cout << "NO" << endl;
      return 0;
    }
    else {
      cout << "YES" << endl;
      return 0;
    }
  }
  a.push_back(a[0]);
  ll diff = -1, cnt = 0, a0 = 0;
  rep(i, n) {
    a[i + 1] += n * cnt;
    if (a[i + 1] - a[i] <= 0) {
      ll rescnt = (a[i] - a[i + 1]) / n + 1;
      cnt += rescnt;
      a0 += (n - i) * rescnt;
      a[i + 1] += n * rescnt;
    }
    if (diff == -1) diff = a[i + 1] - a[i];
    else if (diff != a[i + 1] - a[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  if (a0 != a[0]) {
    if (a0 > a[0]) {
      cout << "NO" << endl;
      return 0;
    }
    else {
      if ((a[0] - a0) % (n * (n + 1) / 2) != 0) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;








  
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define MAX 100007
#define MOD 1000000007

long long frog(long long arr[], int n){
  long long output[n+1];
  output[0] = 0;
  output[1] = abs(arr[1] - arr[0]);
  output[2] = min(abs(arr[0] - arr[2]), abs(arr[2]-arr[1]) + output[1]) ;
  for(int i=3;i<n;i++){
    output[i] = min(abs(arr[i]-arr[i-1])+output[i-1], abs(arr[i]-arr[i-2])+ output[i-2]);
  }
  return output[n-1];
}

int main(){
  int n;
  cin>>n;
  long long arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  
  cout<<frog(arr, n);
  
  return 0;
}

Measured memory_bytes: 1792
$<.map{|s,w|a,b,c,d,e,f,g,h,i=*s.chars;[[a,b,c],[d,e,f],[g,h,i],[a,d,g],[b,e,h],[c,f,i],[a,e,i],[c,e,g]].map{|x,y,z|x!=?s&&x==y&&x==z&&(puts w=x;break)};w||puts(?d)}

Measured memory_bytes: 6088
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	int A,B;
	cin >> A >> B;
	if(A==1) A=14;
	if(B==1) B=14;
	string a;
	if(A>B) a="Alice";
	else if(A<B)a="Bob";
	else a="Draw";
	cout<<a<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(){
  int N; cin>>N;
  vector<int> S(N);
  for(int i=0; i<N; i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  int A=0;
  for(int i=0; i<N-1; i++){
    A+=S.at(i);
  }
  if(A>S.at(N-1))
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3576
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();
    
    let mo = 10_usize.pow(9) + 7;
    let mut cnt = [0; 26];
    for i in 0..n {
        cnt[s[i] as usize - 'a' as usize] += 1;
    }

    let mut po: usize = 1;
    for i in 0..26 {
        if cnt[i] == 1 {
            po *= 2;
            po %= mo;
        }
        if cnt[i] > 1 {
            po *= cnt[i] + 1;
            po %= mo;
        }
    }

    po = (po + mo - 1) % mo;
    println!("{}", po);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

Measured memory_bytes: 4476
class Dice :
    def __init__(self, pane):
        self.pane = pane
    
    def roll_W(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[2]
        self.pane[2] = self.pane[5]
        self.pane[5] = self.pane[3]
        self.pane[3] = temp

    def roll_S(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[4]
        self.pane[4] = self.pane[5]
        self.pane[5] = self.pane[1]
        self.pane[1] = temp
    
dice1 = Dice(input().split())
dice2 = Dice(input().split())

flag = True

while True:
    t = dice1.pane[0]
    f = dice1.pane[1]
    if (dice2.pane[0] == f or dice2.pane[4] == f):
        dice2.roll_S()
    if (dice2.pane[0] == t and dice2.pane[1] == f):
        break
    dice2.roll_W()

for i in range(0, len(dice1.pane)):
    if (dice1.pane[i] != dice2.pane[i]):
        flag = False
        break

if (flag):
    print('Yes')
else :
    print('No')




Measured memory_bytes: 5572
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 20 10:21:00 2018
ABC077C
@author: maezawa
"""
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

bcnt = [0]*n
for i, bi in enumerate(b):
    j = bisect.bisect_left(a, bi)
    if i == 0:
        bcnt[i] = j
    else:
        bcnt[i] = bcnt[i-1] + j
cnt = 0
for i, ci in enumerate(c):
    j = bisect.bisect_left(b, ci)
    if j == 0:
        continue
    else:
        cnt += bcnt[j-1]
    #print(ci, j, bcnt[j-1], cnt)
    
print(cnt)
    

Measured memory_bytes: 24180
// Bug Hunt
import java.util.*;

public class Main {
	static String statement;
	static int pos;
	static Map<Character, Integer> sizes;
	static Map<Data, Integer> values;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		out: while (true) {
			int result = 0;
			int counter = 1;
			sizes = new HashMap<Character, Integer>();
			values = new HashMap<Data, Integer>();
			while (true) {
				statement = sc.next();
				pos = 0;
				if (statement.equals(".")) {
					if (counter != 1)
						break;
					break out;
				}
				if (!statement.contains("="))
					declaration();
				else if (!assignment()) {
					result = counter;
					break;
				}
				counter++;
			}
			System.out.println(result);
			while (!statement.equals("."))
				statement = sc.next();
		}
		sc.close();
	}

	static void declaration() {
		char array = statement.charAt(pos++);
		pos++;
		int num = number();
		sizes.put(array, num);
	}

	static boolean assignment() {
		char array = statement.charAt(pos++);
		if (!sizes.containsKey(array))
			return false;
		pos++;
		int n = -1;
		if (Character.isDigit(statement.charAt(pos)))
			n = number();
		else
			n = expression();
		if (n == -1 || n >= sizes.get(array))
			return false;
		pos++;
		Data data = new Data(array, n);
		pos++;
		int r = expression();
		if (r == -1)
			return false;
		values.put(data, r);
		return true;
	}

	static int number() {
		int result = 0;
		while (pos < statement.length()
				&& Character.isDigit(statement.charAt(pos))) {
			result *= 10;
			result += statement.charAt(pos++) - '0';
		}
		return result;
	}

	static int expression() {
		if (Character.isDigit(statement.charAt(pos)))
			return number();
		char name = statement.charAt(pos++);
		pos++;
		int n = -1;
		if (Character.isDigit(statement.charAt(pos)))
			n = number();
		else
			n = expression();
		if (n == -1)
			return -1;
		Data data = new Data(name, n);
		pos++;
		if (values.containsKey(data))
			return values.get(data);
		return -1;
	}

	static class Data {
		char name;
		int num;

		Data(char na, int nu) {
			name = na;
			num = nu;
		}

		@Override
		public boolean equals(Object anotherData) {
			return this.name == ((Data) anotherData).name
					&& this.num == ((Data) anotherData).num;
		}

		@Override
		public int hashCode() {
			return new Character(name).hashCode() + new Integer(num).hashCode();
		}
	}
}

Measured memory_bytes: 31824
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int mod=1e9L+7;
int n;
int main() {
    scanf("%d",&n);
    int matrix[n][n];
    int dp[1<<n];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i+=1){
        for(int j=0;j<n;j+=1){
            scanf("%d",&matrix[i][j]);
        }
    }
    dp[0]=1;
    for(int m=0;m<n;m+=1){
        for(int mask=0;mask<(1<<n);mask+=1){
            if(__builtin_popcount(mask)!=m+1){
                continue;
            }
            for(int w=0;w<n;w+=1){
                if(matrix[m][w]&&(mask&(1<<w))){
                    dp[mask]=(dp[mask]+dp[mask^(1<<w)])%mod;
                }
            }
        }
    }
    printf("%d",dp[(1<<n)-1]);
	return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long int n;
  cin >> n;
  long long int ans=1000;
  for(long long int i=1; i<100005; i++){
    if(n%i==0){
      long long int a = i, b = n/i;
      a = to_string(a).length();
      b = to_string(b).length();
      a = max(a, b);
      ans = min(ans, a);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();
	return ch;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	s[top+1]='\0';return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a=max(a,b);}
template<typename tp>inline void chemn(tp &a,tp b){a=min(a,b);}
cs int N=505;
int d[N][N],v[N][N];
int p[N*N],n;
queue<pii> q;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
inline void update(){
	while(q.size()){
		int x=q.front().fi,y=q.front().se;q.pop();
		for(int t=0;t<4;t++){
			int px=x+dx[t],py=y+dy[t];
			if(px<1||px>n||py<1||py>n)continue;
			if(d[px][py]>d[x][y]+v[px][py]){
				d[px][py]=d[x][y]+v[px][py];
				q.push(pii(px,py));
			}
		}
	}
}
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();int res=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)d[i][j]=min(i,min(n-i+1,min(j,n-j+1))),v[i][j]=1;
	for(int tt=1;tt<=n*n;tt++){
		int id=read(),x=(id-1)/n+1,y=id-(x-1)*n;
		res+=d[x][y]-1;v[x][y]=0;
	//	cout<<x<<" "<<y<<" "<<res<<'\n';
		d[x][y]--;q.push(pii(x,y));
		update();
	}cout<<res<<'\n';
}

Measured memory_bytes: 6532
// ABC060_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define vl vector<ll>
#define pll pair<ll, ll>
#define F first
#define S second

int main() {
    // input
    string N, M, L;
    cin >> N >> M >> L;
    
    // calculation
    if (N.back() == M.front() && M.back() == L.front()) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
    
    return 0;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

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

//--------------------------- Solve ---------------------------//

int dp1[3005][3005], dp2[3005][3005];

void solve() {
    int N, T; cin >> N >> T;
    vector<pair<int, int>> p(N);
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        p[i] = make_pair(a, b);
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= T; j++) {
            chmax(dp1[i][j], dp1[i-1][j]);
            int nj = j - p[i-1].first;
            if (nj >= 0) chmax(dp1[i][j], dp1[i-1][nj] + p[i-1].second);
        }
    }

    for (int i = N; i >= 1; i--) {
        for (int j = 0; j <= T; j++) {
            chmax(dp2[i][j], dp2[i+1][j]);
            int nj = j - p[i-1].first;
            if (nj >= 0) chmax(dp2[i][j], dp2[i+1][nj] + p[i-1].second);
        }
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < T; j++) {
            int tmp = dp1[i-1][j] + dp2[i+1][T-j-1] + p[i-1].second;
            chmax(ans, tmp);
        }
    }

    cout << ans << '\n';

}

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

    solve();

    return 0;
}

Measured memory_bytes: 74056
#include<stdio.h>
int main()
{
    int n;
    int i,j,k,l;
    scanf("%d",&n);
    int a[n],temp,max,ans,sum=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-i-1;j++)
        {
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    max=a[n-1];
    for(i=0;i<n-1;i++)
    {
        sum=sum+a[i];
    }
    ans=sum+(max/2);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define MX 20000000000000005
using namespace std;
int a[200005];
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	int n,i;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	for(i=n-1;i>-1;i-=2) cout<<a[i]<<" ";
	for(i=n%2;i<n;i+=2) cout<<a[i]<<" ";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 2944
'''
https://atcoder.jp/contests/abc079/tasks/abc079_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    H, W = map(int, input().split())
    c = [list(map(int, input().split())) for _ in range(10)]
    A = [list(map(int, input().split())) for _ in range(H)]
    N = 10
    for k in range(N):
        for i in range(N):
            for j in range(N):
                c[i][j] = min(c[i][j], c[i][k]+c[k][j])
    res = 0
    for i in A:
        for j in i:
            if j == -1:
                continue
            res += c[j][1]
    print(res)

if __name__ == '__main__':
    main()

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

int stricmp(char* ch1,char* ch2){
	int ch1_length = 0,ch2_length = 0,div;
	for(int i = 0; ch1[i] != '\0';i++) ch1_length++;
	for(int i = 0; ch2[i] != '\0';i++) ch2_length++;
	if(ch1_length != ch2_length) return -1;
	for(int i = 0; ch1[i] != '\0';i++)
	{
		div = ch1[i] -ch2[i];
		if(div != 0 && div != 32 && div != -32)
			return -1;
	}
	return 0;
}

int main(){
	char W[11],T[1001];
	int count = 0;
	scanf("%s",W);
	while(true){
		scanf("%s",T);
		if(strcmp("END_OF_TEXT",T) == 0) break;
		if(stricmp(T, W) == 0) count++;
	}
	printf("%d\n",count);
}



Measured memory_bytes: 2740
import sys

N=input()
P=map(float,  sys.stdin.readline().split() )

dp=[ [ 0 for j in range(N+1) ] for i in range(N+1) ]
dp[0][0]=1


for i in range(N):
	p=P[i]
	for j in range(i+2):
		if j==0:
			#print "dp[",i+1 , "][0]=dp[", i ,"][0]*(",1-p,")"
			dp[i+1][0]=dp[i][0]*(1-p)
		else:
			#print "dp[",i+1,"][",j,"]=dp[",i,"][",j, "]*(", 1-p,")+dp[",i," ][", j-1," ]*",p
			dp[i+1][j]=dp[i][j]*(1-p)+dp[i][j-1]*p

n=N/2+1

ans=0
for i in range(n, N+1):
	ans+=dp[-1][i]
print ans


Measured memory_bytes: 170268
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    k, x = map(int, input().split())

    for i in range(x - (k - 1), x + (k - 1) + 1):
        if abs(i) > 1000000:
            continue

        if i != x + (k - 1):
            print("{} ".format(i), end="")
        else:
            print("{}".format(i), end="")
    print()


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int maxn = 300500;

struct rc{
	bool s;
	int t, c;
	rc(bool a, int b, int c) :s(a), t(b), c(c){}
	bool operator < (const rc& a) const {
		if (t != a.t) return t < a.t;
		return s < a.s;
	}
} ;



int main(){
	int C;
	int n; sci(n); sci(C);	
	int s, t, c;
	vector<rc> r;
	lp(i, n){
		scii(s,t); sci(c);
		r.push_back({ 1, s, c });
		r.push_back({ 0, t, c });
	}
	r.push_back({ 1, 0, 0 });
	r.push_back({ 0, 0, 0 });
	sort(r.begin(), r.end());
	int ret = 0;
	set<pii> cur;
	for (auto i : r){
		if (i.s){
			if (cur.size() > 0){
				bool f = 0;
				pii be;
				for (auto j : cur) if (j.first < i.t || (j.first == i.t && j.second == i.c)){
					f = 1;
					be = j;
					if(j.first == i.t && j.second == i.c) break;
				}
				if (f) cur.erase(cur.find(be));
				else {
					ret++;
				}
			}
			else
				ret++;
		}
		else{
			cur.insert({ i.t, i.c });
		}
	}
	pri(ret);
}



Measured memory_bytes: 4852
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n,m = nm()
h = nl()

res = [[i] for i in h]

for i in range(m):
    a,b = nm()
    res[a-1].append(h[b-1])
    res[b-1].append(h[a-1])

ans = 0
for j in res:
    ma = max(j)
    if j.count(ma) == 1 and j[0] == ma:
        ans += 1

print(ans)

Measured memory_bytes: 93416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<ll,ll>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,W;cin >> n >> W;
    vi w(n), v(n);
    rep(i,n) cin >> w[i] >> v[i];

    vector<vl> dp(n+10, vl(100000+100, LINF));
    dp[0][0] = 0;
    rep(i,n){
        for(int j=0;j<=100000;++j){
            if(j-v[i]>=0) dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    rep(i,100000+100){
        if(dp[n][i] <= W) chmax(ans, i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 87296
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,j,z,x,c,v,b,n,i;
	for(i=1;i<=3;i++){
		scanf("%d %d %d %d %d %d ",&a,&s,&d,&f,&g,&h);
		j=d+s*60+a*3600;
		z=h+g*60+f*3600;
		x=z-j;
		c=x/60;
		v=x%60;
		b=c/60;
		n=c%60;
		printf("%d %d %d\n",b,n,v);
	}
	return 0;
}

Measured memory_bytes: 1036
A,B = gets.split.map(&:to_i)

max_length = 50

bit = ""
(0...max_length).each do |i|
  num = 2**(max_length-i)
  a = ((A)/num)*(num/2)
  b = [((A) % num) - (num/2), 0].max
  a_count = a+b

  c = ((B+1)/num)*(num/2)
  d = [((B+1) % num) - (num/2), 0].max
  b_count = c+d
  tmp = b_count - a_count
  if tmp.odd?
    bit << "1"
  else
    bit << "0"
  end
end

puts bit.to_i(2)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main(){

	int n;
	string a,b,c;
	int total=0;

	cin>>n;
	cin>>a;
	cin>>b;
	cin>>c;

	rep(i,n){
		if(a[i]==b[i]&&b[i]!=c[i])total++;
		if(a[i]==c[i]&&c[i]!=b[i])total++;
		if(c[i]==b[i]&&c[i]!=a[i])total++;
		if(c[i]!=b[i]&&b[i]!=a[i]&&c[i]!=a[i])total+=2;
	}
	cout<<total<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n;
	while (cin >> n) {
		if (n == 0)break;
		int a[1000] = {};
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		int mi = (int)MOD;
		for (int i = 0; i < n-1; i++) {
			mi = min(mi, a[i + 1] - a[i]);
		}
		cout << mi << endl;
	}
	return 0;
}


Measured memory_bytes: 3164
# 解説放送の方針
# 平面走査をし、各点について、左上、左下、右上、右下にある点を数え、計算する。
# 解説放送ではBITを2本使っていたが、座標圧縮の結果を利用してBIT１本で済むようにした

N = int(input())
xy = [tuple(map(int,input().split())) for _ in range(N)]

mod = 998244353

class BIT:
    '''https://tjkendev.github.io/procon-library/python/range_query/bit.html'''
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def query(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

# 平面走査のためのソート（高速化のため１次元にしてソート）
# ソート後の復元+座標圧縮用の辞書作成
# 座標圧縮: 小さいyから順に1,2,3...と値を割り振る。
xy2 = []
Y = []
for i in range(N):
  x,y = xy[i]
  Y.append(y)
  x += 10**9
  y += 10**9
  xy2.append(x<<80 | y << 40 | i)

Y = sorted(Y)
y_compress = {Y[i]:i+1 for i in range(N)}
  
xy2 = sorted(xy2)
mask = (1<<40)-1
bit=BIT(N)

# いちいち2^nを計算していると遅いのでテーブル作成
pow2 = [1]*(N+1)
for i in range(1,N+1):
  pow2[i] = pow2[i-1]*2 %mod

ans = 0
for x in xy2:
  i = x & mask
  x >>= 40
  y = x & mask
  y -= 10**9
  x >>= 40
  x -= 10**9
  
  y = y_compress[y]
  bit.add(y,1)
  '''
  今現在みている点より左上と左下にある点の個数（今の点は含まない。以下同じ）。
  BITを使って求める。
  '''
  n1 = bit.query(y-1,N)-1
  n2 = bit.query(0,y)-1 
  '''
  右上と右下。座標圧縮の結果を利用。(N-y(座標圧縮済))はある点より上にある点の総数。
  そこからn1（走査済みの点の個数)を引くことで、まだ走査していない点の個数を求めることができる。
  '''
  n3 = N-y-n1 
  n4 = y-n2-1
  
  prod14 = (pow2[n1]-1)*(pow2[n4]-1)*pow2[n2+n3] %mod
  prod23 = (pow2[n2]-1)*(pow2[n3]-1)*pow2[n1+n4] %mod
  prod1234 = (pow2[n1]-1)*(pow2[n4]-1)*(pow2[n2]-1)*(pow2[n3]-1) %mod
  ans += pow2[N-1]+prod14+prod23-prod1234
  ans %= mod
  
print(ans)

Measured memory_bytes: 198148
n,m = map(int, input().split())
Lmin = 0
Rmax = n
for i in range(m):
    L,R = map(int, input().split())
    Lmin = max(L-1, Lmin)
    Rmax = min(R, Rmax)
if Lmin < Rmax:
    ans = Rmax - Lmin
else:
    ans = 0
print(ans)

Measured memory_bytes: 44120
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=-10**18
flag=dict()
for i in range(n):
    if i in flag:
        continue
    cur=i
    accum=[]
    flag[cur]=0
    s=0
    while flag[cur]<2:
        cur=p[cur]-1
        s+=c[cur]
        accum.append(s)
        if cur not in flag:
            flag[cur]=0
        else:
            flag[cur]+=1
    l=len(accum)//2
    accum=[0]+accum
    #print(accum)
    for x in range(1,l+1):
        if accum[x+l-1]-accum[x-1]<=0 or k//l<1:
            ans=max(ans,max(accum[x:x+min(k,l)])-accum[x-1])
        else:
            a=max(accum[x:x+l-1])-accum[x-1]
            d=accum[x+l-1]-accum[x-1]
            if k%l!=0:
                b=max(accum[x:x+k%l])-accum[x-1]
                ans=max(ans,max(k//l*d,k//l*d+b,(k//l-1)*d+a))
            else:
                b=max(accum[x:x+l-1])-accum[x-1]
                ans=max(ans,max(k//l*d,(k//l-1)*d+a))
print(ans)


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

#define _fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1)
#define MAXS 100000
#define MOD 998244353
#define all(v) v.begin(),v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


int tc,n,a[100005],l[100005],r[100005];


void sol()
{

    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    l[0]=a[1];
    r[n+1]=a[n];
    for(int i=1,j=n; i<=n; i++,j--){
        l[i]=__gcd(a[i],l[i-1]);
        r[j]=__gcd(a[j],r[j+1]);
    }
    int mx=0;
    for(int i=1; i<=n; i++){
        int le=l[i-1];
        int ri=r[i+1];
        int po=__gcd(le,ri);
        if(i==1)po=ri;
        if(i==n)po=le;
        mx=max(mx,po);
    }
    cout<<mx<<endl;
}

int main()
{

    _fastIO;

    //cin>>tc;while(tc--)
    sol();

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int n,k,a[60],ans;
int main(){
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(int i=n-1;i>=0;i--){
 k--;
 if(k>=0)
 ans+=a[i];
 }
 cout<<ans;
system("pause");
return 0;
}

Measured memory_bytes: 504
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
for i in range(1,4):
    print(sum([abs(a[j]-b[j])**i for j in range(n)])**(1/i))
print(max([abs(a[i]-b[i]) for i in range(n)]))


Measured memory_bytes: 5648
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/	
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll power( ll a, ll n, ll m= 1000000007){
  ll ans = 1;
  while(n){
  if(n&1)
  {
  ans *= a;
  ans%=m;
  }
  a*=a;
  a%=m;
  n/=2;
  }
  return ans ;
} 


vector< int > prm ;
vector < bool > vsp ;

void prime ( int nn = 100000 ) {
	vsp = vector < bool > ( nn+1, 0 );
	int size_prime = nn;
	for( ll i =2; i*i < size_prime ; i++){
		
		if( vsp[i] == 1)
		continue;
		for(ll j = i*i; j < size_prime ;j+=i){
			
			vsp[j] =1;
			
		}
		
		
	}
	
	for( int i= 2; i < size_prime ; i++)
	if (vsp[i] == 0)
	prm.pb(i);
	
	
}


template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...
// never forget  to recheck your predefined function in template .. 
// already defined ::  prime , power , gcd : ( ll ).. 



vector < int  > adj[maxx];

vector < int > vis ;
void dfs (int u , int par ){
	
	vis[u] = 1;
	if(adj[u].size() == 0 )
	return ;
	for(auto it : adj[u]){
		
		if(it!= par && vis[it] == 0){
			dfs( ( int )it , u);
		}
		
	}
	
};







int Main(){
  

ll n,m;
cin>>n>>m;
for( int i=0 ; i < m;i++){
	int a,b;
	
	cin>>a>>b ;
	 a--, b-- ;
	adj[a].pb(b);
	adj[b].pb(a);
	
}

vis = vector < int > ( maxx , 0 );

int cnt =0 ; 
for ( int i =0 ; i  < n;i++){
	
	
	if(vis[i] == 0){
		
		dfs( i , -1 );
		cnt++;
	}
	
	
}

cout<<cnt-1<<endl;




return 0;

}






int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;
}


  




Measured memory_bytes: 12696
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

vector<vector<int> > calcNext(const string &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n+1, vector<int>(26, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j) res[i][j] = res[i+1][j];
        res[i][S[i]-'a'] = i;
    }
    return res;
}

void solve() {
    string s; cin >> s;
    int n = s.size();

    auto next = calcNext(s);

    vector<int> dp(n + 1, 1<<29);
    vector<pair<char, int> > rec(n + 1, {'?', n});
    dp[n] = 1;
    per(i, n) {
        rep(j, 26) {
            //a～zのうち、遷移後の同上の文字列が最短かつs辞書順最小となるものを選ぼう。
            if(next[i][j] == n) {
                if(dp[i] > 1) { //辞書順にするため
                    dp[i] = 1;
                    rec[i] = {'a' + j, n};
                }
            }
            else if(chmin(dp[i], dp[next[i][j] + 1] + 1)) {
                rec[i] = {'a' + j, next[i][j] + 1};
            }
        }
    }

    string res = "";
    int index = 0;
    while(index < n) {
        auto p = rec[index];
        res += p.first;
        index = p.second;
    }
    cout << res << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 29332
using System;

namespace _153d
{
    class Program
    {
        static void Main(string[] args)
        {
            long H = long.Parse(Console.ReadLine());
            long monster_num = 1;
            long attack_num = 0;
            while(H > 0){
                attack_num += monster_num;
                if(H<1){
                    H = 0;
                    break;
                }else{
                    H = H/2;
                    monster_num += monster_num;
                }
            }
            Console.WriteLine(attack_num);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>

#define VERTEX 10

int  N, M;
bool adj[VERTEX][VERTEX] = { false };
bool visited[VERTEX]     = { false };

long dfs(int v) {
    long ans = 0;
    bool all_visited = true;
    for (int i=0; i<N; ++i) {
        if (visited[i] == false) all_visited = false;
    }
    if (all_visited) return 1;

    for (int i=0; i<N; ++i) {
        if ( adj[v][i] && visited[i] == false ) {
            visited[i] = true;
            ans += dfs(i);
            visited[i] = false;
        }
    }
    return ans;
}

void solve() {
    long ans = 0;
    visited[0] = true;
    std::cout << dfs(0) << std::endl;
}

int main() {
    std::cin >> N >> M;
    for (int i=0; i<M; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u; --v;
        adj[u][v] = true;
        adj[v][u] = true;
    }
    solve();
    return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n;cin >> n;
    if(n<1200)cout << "ABC" << endl;
    else if(n<2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}


Measured memory_bytes: 256