akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>

const int INF=1E8;

using namespace std;

const int MAX_W=30,MAX_H=30;

int w,h;
string S;

vector<int> G[MAX_W*MAX_H];
int d[MAX_W*MAX_H];

vector<int> out;

int bfs(){
	fill(d,d+w*h,INF);
	d[0]=0;
	queue<int> q;
	q.push(0);
	while (!q.empty()){
		int v=q.front();
		q.pop();
		for (int i=0;i<G[v].size();i++){
			if (d[G[v][i]]==INF){
				d[G[v][i]]=d[v]+1;
				q.push(G[v][i]);
			}
		}
	}
	return d[w*h-1];
}

int main(){
	do{
		cin>>w>>h;
		if (w || h){
			for (int i=0;i<h;i++){
				for (int j=0;j<w;j++){
					G[i*w+j].clear();
				}
			}
			for (int i=0;i<2*h-1;i++){
				int f;
				int v1,v2;
				if (i%2==0){
					for (int j=0;j<w-1;j++){
						cin>>f;
						if (!f){
							v1=i/2*w+j;
							v2=v1+1;
							G[v1].push_back(v2);
							G[v2].push_back(v1);
						}
					}
				}
				else{
					for (int j=0;j<w;j++){
						cin>>f;
						if (!f){
							v1=i/2*w+j;
							v2=v1+w;
							G[v1].push_back(v2);
							G[v2].push_back(v1);
						}
					}
				}
			}
			out.push_back(bfs());
		}
	}while(w || h);
	for (vector<int>::iterator ite=out.begin();ite!=out.end();ite++){
		printf("%d\n",(*ite==INF) ? 0:*ite+1);
	}
	return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll r,n;
    ll line =0;
    //std::ofstream writing_file;
    //writing_file.open("vamp_cin.txt", std::ios::out);
    while(cin>>r>>n){
    //  line++;
        if(r==0)break;
        int xl[41],xr[41],h[41];
        int hh[41][41];
        memset(hh,0,sizeof(hh));
        for(int i=0;i<n;i++){
            cin>>xl[i+20]>>xr[i+20]>>h[i+20];
            for(int j=xl[i+20];j<xr[i+20];j++){
                hh[j+20][j+21]=max(h[i+20],hh[j+20][j+21]);
            }
        }
        int minh = 1e5;
        int minx = 0;
        double ans=1e5;
        double res=1e5;
        for(int i=20-r;i<20+r;i++){
            //minh = min(h[i+20]);
/*          if(minh >= hh[i][i+1]){
                if(minh == hh[i][i+1]){
                    if(abs(20-i)<abs(minx-20)){
                        minx = i;
                    }
                }else{
                    minx = i;
                }
                minh = hh[i][i+1];
            }*/
        //  cout<<"i i+1:"<<i<<" "<<i+1<<"hh:"<<hh[i][i+1]<<endl;
            if(i<20)res = min(res,hh[i][i+1] + r - sqrt(r*r - abs(i-19)*abs(i-19)));
            else res = min(res,hh[i][i+1] + r - sqrt(r*r - abs(i-20)*abs(i-20)));
        //  cout<<"res:"<<res<<endl;
            ans = min(ans,res);
        }
        for(int i=20-r;i<20+r;i++){
        //  cout<<"i i+1:"<<i<<" "<<i+1<<"hh:"<<hh[i][i+1]<<endl;
        }
//      minh = min(hh[minx-1],min(hh[minx+1],minh));
        /*if(minh>hh[minx-1][minx]&&minh<hh[minx+1][minx+2]){
            //minh = hh[minx-1][minx];
            minx-=1;
        }else if(minh > hh[minx+1][minx+2]&&minh<hh[minx-1][minx]){
            //minh=hh[minx+1][minx+2];
            minx+=1;
        }*/
 
        if(minx<20)minx+=1;
        //if(minx>20)minx-=1;
        //cout<<"minx"<<minx<<" minh:"<<minh<<endl;
        cout<<fixed;
        cout<<setprecision(4)<<ans<<endl;
        /*writing_file<<"line:"<<line<<endl;
        writing_file<<n<<" "<<r<<endl;
        for(int i=0;i<n;i++){
            writing_file<<xl[i+20]<<" "<<xr[i+20]<<" "<<h[i+20]<<endl;
        }+*/
    //  writing_file<<fixed;
    //  writing_file<<setprecision(4)<<res<<endl;
    }
}


Measured memory_bytes: 3224
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

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

    deque<int> ans;
    REP(i,n) {
        int a; cin >> a;
        if(i%2==0) ans.push_back(a);
        else ans.push_front(a);
    }

    REP(i,n) {
        if(n%2 == 1){
            cout << ans.back() << " ";
            ans.pop_back();
        } else {
            cout << ans.front() << " ";
            ans.pop_front();
        }
    }

    cout << endl;
    
    return 0;
}

Measured memory_bytes: 2944
using System;
using System.Linq;
using static System.Console;

namespace B
{
  class Program
  {
    static void Main(string[] args)
    {
      int N = int.Parse(ReadLine());
      string[] inputs = ReadLine().Split();
      int[] L = new int[N];
      for(int i = 0; i<N; i++)
        L[i] = int.Parse(inputs[i]);

      int max = L.Max();

      int len = max;
      for(int i = 0; i<N; i++)
        len -= L[i];
      WriteLine(len < -max ? "Yes" : "No");
    }
  }
}


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

bool hantei(vector<int> j,vector<vector<int>> &A){
  sort(j.begin(),j.end());
  for(vector<int> &i:A)
    if(i==j)
      return true;
  return false;
}

int main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int>> A(M,vector<int>(2));
  for(vector<int> &i:A){
    int j,k;
    cin>>j>>k;
    i={j-1,k-1};
    sort(i.begin(),i.end());
  }
  vector<int> v={};
  for(int i=1;i<N;i++)
    v.push_back(i);
  int k=0;
  do{
    if(!hantei({0,v.at(0)},A))
      continue;
    bool bo=false;
    for(int i=0;i<N-2;i++)
      if(!hantei({v.at(i),v.at(i+1)},A)){
        bo=true;
        break;
      }
    if(bo)
      continue;
    k++;
  }while (next_permutation(v.begin(), v.end()));
  cout<<k<<endl;
}

Measured memory_bytes: 256
N, M = list(map(int,input().rstrip().split()))
Amin = 1
Amax = N
for i in range(M):
    L, R = list(map(int,input().rstrip().split()))
    Amin = max(Amin,L)
    Amax = min(Amax,R)
    if Amin>Amax:
        print(0)
        break
else:
    print(Amax-Amin+1)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int N,K;
	cin>>N>>K;
	cout<<(N-2)/(K-1)+1<<endl;
}


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



// string ans = "aaaaaaaaaa";
string mapping = "abcdefghij";
int str[] = {0,1,2,3,4,5,6,7,8,9};
int ans[] = {0,0,0,0,0,0,0,0,0,0};

vector<int> v;
int N;
vector<int> vec;
set<char> s;
        
void find(int pos){
    if(pos == N){
        for(int i=0;i<N;i++){
            if(i==0){
                v.push_back(ans[i]);
                s.insert(ans[i]);
            }
            else{
                if(ans[i] > v[v.size()-1]){
                    if(ans[i]-v[v.size()-1]>1){
                        return;
                    }
                    else{
                        v.push_back(ans[i]);
                        s.insert(ans[i]);
                    }
                }
                else{
                    if(s.count(ans[i])==0){
                        cout<<"set not \n";
                        for(int i=0;i<N;i++)
                            cout<<mapping[ans[i]];
                        cout<<"\n";
                        return;
                    }
                }
            }
        }
        for(int i=0;i<N;i++)
            cout<<mapping[ans[i]];
        cout<<"\n";
        return;
    }
    for(int i=0;i<pos+1;i++){  
        ans[pos] = str[i];
        find(pos+1);
    }
}
int main(){
    cin>>N;
    find(0);
}

Measured memory_bytes: 67296
#include <iostream>
using namespace std;
int main() {
    int h, n;
    cin >> h >> n;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        h -= a;
    }
    if (h <= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in); 
		int n = in.nextInt(); 
		int[] arr = new int[n]; 
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt(); 
		}
		System.out.println(computeMaxProfit2(arr, n)); 
	}

	private static int computeMaxProfit(int[] arr, int n) {
		int maxProfit = -999999999; 
		for(int i = 0; i < n-1; i++) {
			for (int j = i+1; j<n; j++) {
				if(arr[j] - arr[i] > maxProfit)
					maxProfit = arr[j] - arr[i]; 
			}
		}
		return maxProfit; 
		
	}
	private static int computeMaxProfit2(int[] arr, int n) {
		int maxProfit = -999999999; 
		int min = arr[0];

		for (int i = 1; i < n; i++) {
			maxProfit = Math.max(maxProfit, arr[i] - min);
			min = Math.min(min, arr[i]);
		}
		return maxProfit;
	}

}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, m;
char s[505][505];
bool R[505][505], B[505][505];

int main(){
	scanf("%d %d", &n, &m);
	FI(i, 1, n){
		scanf(" %s", s[i] + 1);
		FI(j, 1, m) if(s[i][j] == '#') R[i][j] = B[i][j] = true;
	}
	FI(i, 1, m) R[1][i] = B[n][i] = true;
	FI(j, 1, m) if(j & 1){
		FI(i, 2, n - 1) R[i][j] = true;
	} else{
		FI(i, 2, n - 1) B[i][j] = true;
	}
	FI(i, 1, n) FI(j, 1, m){
		if(R[i][j]) printf("#");
		else printf(".");
		if(j == m) printf("\n");
	}
	printf("\n");
	FI(i, 1, n) FI(j, 1, m){
		if(B[i][j]) printf("#");
		else printf(".");
		if(j == m) printf("\n");
	}
	return 0;
}


Measured memory_bytes: 1536
import kotlin.math.PI

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main() {
    val s = readLn()
    print(if (s == "ABC") "ARC" else "ABC")
}


Measured memory_bytes: 34400
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int r;
        cin >> r;
        cout << 3 * r * r << '\n';
    }
}

Measured memory_bytes: 31488
#include<stdio.h>
int main(){
	int sx, sy, tx, ty;
	scanf("%d %d %d %d", &sx,&sy,&tx,&ty);
	for(int i=0; i<tx-sx; i++){
		printf("R");
	}
	for(int i=0; i<ty-sy; i++){
		printf("U");
	}
	for(int i=0; i<tx-sx; i++){
		printf("L");
	}
	for(int i=0; i<ty-sy; i++){
		printf("D");
	}
	printf("D");
	for(int i=0; i<tx-sx+1; i++){
		printf("R");
	}
	for(int i=0; i<ty-sy+1; i++){
		printf("U");
	}
	printf("LU");
	for(int i=0; i<tx-sx+1; i++){
		printf("L");
	}
	for(int i=0; i<ty-sy+1; i++){
		printf("D");
	}
	printf("R");
}

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



int main(){
  int n,m;
  cin >> n >> m;
  cout << n*(n-1)/2 + m*(m-1)/2 << endl;
  }

Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
// xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>//変数.substr(どこから,いくつ)
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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; }

int main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  vll cnt(n); rep(i,n) cnt[a[i]-1]++;
  ll sum = 0;
  rep(i,n) sum += cnt[i]*(cnt[i]-1)/2;
  rep(i,n){
    ll ans = sum;
    ans -= cnt[a[i]-1]*(cnt[a[i]-1]-1)/2;
    ans += (cnt[a[i]-1]-1)*(cnt[a[i]-1]-2)/2;
    cout << ans << " \n";
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 5120
//**************************
//*** author  :  Alex Hu **
//************************

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n,m;
vi graph[100010];
int ans[100010],in[100010];
queue<int> q;

int main()
{
	cin>>n>>m;
	rept(i,1,n+m)
	{
		int x,y;
		cin>>x>>y;
		graph[x].pb(y);
		in[y]++;
	}
	rept(i,1,n+1)
	{
		if (!in[i])
		{
			q.push(i);
			break;
		}
	}
	while (!q.empty())
	{
		int cnt=q.front();
		q.pop();
		for (auto y:graph[cnt])
		{
			in[y]--;
			if (!in[y])
			{
				q.push(y);
				ans[y]=cnt;
			}
		}
	}
	rept(i,1,n+1) cout<<ans[i]<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    bool answerable = false;
    for (int i = 1; i <= 9; i++) {
        if ((n%i == 0) && 1 <= (n/i) && (n/i) <= 9) 
            answerable = true;            
    }
    if (answerable) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int n;
    cin>>n;
    map<string,int> mp;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        mp[s]++;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        string t;
        cin>>t;
        mp[t]--;
    }
    int ma=0;
    for(auto i:mp) ma=max(ma,i.second);
    cout << ma <<endl;
    
}


Measured memory_bytes: 256
s = input()
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
i = 0

for i in range (0,int(len(s)),2):
  if s[i] not in odd:
    print("No")
    exit()
    
for i in range (1, int(len(s)), 2):
  if s[i] not in even:
    print("No")
    exit()  

print("Yes")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nm = Input.ar;
        var coin = Input.ar;
        var dp = new long[nm[1] + 1, nm[0] + 1];
        for (var i = 0; i <= nm[1]; i++)
            for (var j = 0; j <= nm[0]; j++)
                dp[i, j] = long.MaxValue / 2;
        dp[0, 0] = 0;
        for (var i = 1; i <= nm[1]; i++)
            for (var j = 0; j <= nm[0]; j++)
                if (j - coin[i - 1] >= 0)
                    dp[i, j] = Min(dp[i - 1, j], dp[i, j - coin[i - 1]] + 1);
                else dp[i, j] = dp[i - 1, j];
        WriteLine(dp[nm[1], nm[0]]);
    } 
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}



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


void solve(std::string AtCoder, std::string s, std::string Contest){
	cout << "A" << s[0] << "C" << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string AtCoder;
    std::cin >> AtCoder;
    std::string s;
    std::cin >> s;
    std::string Contest;
    std::cin >> Contest;
    solve(AtCoder, s, Contest);
    return 0;
}


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

using namespace std;

int main() {
  string S;
  std::cin >> S;
  bool i = S[0] == 'R';
  bool j = S[1] == 'R';
  bool k = S[2] == 'R';
  if (i and j and k){
    cout << 3 << endl;
  }
  else if ((i and j)or(j and k)){
    cout << 2 << endl;
  }
  else if (i or j or k){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem2544 : Older Resarch Bldg. No.7 **/
int main()
{
	int N, Q;
	cin>>N>>Q;
	
	string ans = "kogakubu10gokan";
	
	rep(i, N) {
		int a; string s;
		cin>>a>>s;
		if (Q<a) {
			cout << ans << endl;
			return 0;
		} else {
			ans = s;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 1208
N, M = gets.split.map(&:to_i)
edges = readlines.map { |l| l.split.map(&:to_i) }

dp = Array.new(N) { Array.new(N, 0) }

(0..N-1).each do |i|
  (0..N-1).each do |j|
    dp[i][j] = (i == j) ? 0 : Float::INFINITY
  end
end

edges.each do |a, b, c|
  dp[a-1][b-1] = [dp[a-1][b-1], c].min
  dp[b-1][a-1] = [dp[b-1][a-1], c].min
end

(0..N-1).each do |k|
  (0..N-1).each do |i|
    (0..N-1).each do |j|
      dp[i][j] = [dp[i][j], dp[i][k] + dp[k][j]].min
    end
  end
end

ans = M
edges.each do |a, b, c|
  shortest = false
  (0..N-1).each do |j|
    shortest = true if dp[j][a-1] + c == dp[j][b-1]
  end
  ans -= 1 if shortest
end
p ans


Measured memory_bytes: 2172
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
	int i,n,ans=0,k,x,y;
	cin>>n>>k>>x>>y;
	for(i=1;i<=n;i++){
		if(i<=k) ans+=x;
		else ans+=y;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int a[2000][2000] = {};

void f(int x, int y, int p, int q) {
    cerr << x _ y _ p _ q << endl;
    int mx = (p + x) / 2, my = (q + y) / 2;
    a[mx][my] = 1;
    if (abs(p - x) <= 1 || abs(q - y) <= 1) return;
    f(x, y, mx - 1, my - 1);
    f(x, my + 1, mx - 1, q);
    f(mx + 1, y, p, my - 1);
    f(mx + 1, my + 1, p, q);
}


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

    f(0, 0, (1 << n) - 2, (1 << m) - 2);
    for (int i = 0; i < (1 << n) - 1; i++) {
        for (int j = 0; j < (1 << m) - 1; j++) {
            cout << a[i][j];
        }
        cout << endl;
    }

}


Measured memory_bytes: 9472
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int k = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        
        int[] a = new int[n];
        a[0] = Integer.parseInt(sc.next());
        int max = 0;
        for(int i = 1; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
            if(a[i] - a[i-1] > max) max = a[i] - a[i-1];
        }
        if((a[0] + k - a[n-1]) > max) max = a[0] + k - a[n-1];
        
        System.out.println(k - max);
    }
}

Measured memory_bytes: 51248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		String T = scanner.next();
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		String U = scanner.next();

//		System.out.println(S);

//		System.out.println(U.equals(S)?A-1:B-1);
		if (U.equals(S)) {
			System.out.println(A-1);
			System.out.println(B);
		} else if (U.equals(T)){
			System.out.println(A);
			System.out.println(B-1);
		}

	}

}

Measured memory_bytes: 35632
#include<iostream>
#include<vector>
#include<string>
#include<set>
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		vector<string>c(a);
		set<string>s;
		for (int d = 0; d < a; d++)cin >> c[d];
		switch (b) {
		case 2:
			for (int e = 0; e < a; e++) {
				for (int f = 0; f < a; f++) {
					if (e != f)s.insert(c[e] + c[f]);
				}
			}break;
		case 3:
			for (int e = 0; e < a; e++) {
				for (int f = 0; f < a; f++) {
					for (int g = 0; g < a; g++) {
						if (e != f&&f != g&&g != e)s.insert(c[e] + c[f] + c[g]);
					}
				}
			}break;
		case 4:for (int e = 0; e < a; e++) {
			for (int f = 0; f < a; f++) {
				for (int g =0; g < a; g++) {
					for (int h = 0; h < a; h++) {
						if (e != f&&f != g&&g != h&&h != e&&e != g&&f != h)s.insert(c[e] + c[f] + c[g] + c[h]);
					}
				}
			}
		}break;
		}
		cout << s.size() << endl;
	}
}

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

using namespace std;

int main(){
  int sum, n; cin >> sum >> n;
  int res = 0;
  for(int i = 0; i < n; i++){
    int x; cin >> x;
    res += x;
  }
  if(res >= sum) cout << "Yes\n";
  else cout << "No\n";
  
  return 0;
}

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

int main(){
	int N; cin>>N;
	int ans = 0;
	for(int n=1; n<=N; n+=2){

		int c = 0;
		if(n == 1) c++;
		else{
			for(int i=1; i*i<n; ++i)
				if(n%i == 0) c++;
			c *= 2;
		}

		if(c == 8) ans++;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
A = list(map(int,input()))
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

ops =''
for n in range(8):
	b = Base_10_to_n(n,2).rjust(3,'0')
	s = A[0]
	for i in range(3):
		if b[i] == '0':
			s -= A[i+1]
		else:
			s += A[i+1]

	if s == 7:
		ops = b
		break

ans = []
for i in range(3):
	ans.append(str(A[i]))
	if ops[i] == '0':
		ans.append('-')
	else:
		ans.append('+')

ans.append(str(A[3])+'=7')

print(''.join(ans))

Measured memory_bytes: 3064
N = int(input())
arr = map(int,input().split())

divisible_by_2 = 0
divisible_by_4 = 0
others = 0

for i in arr:
    if i % 4 == 0:
        divisible_by_4 += 1
    elif i % 2 == 0:
        divisible_by_2 += 1
    else:
        others += 1

if others > divisible_by_4:
    if divisible_by_2 == 0 and others == divisible_by_4 + 1:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")


Measured memory_bytes: 11224
# -*- coding: utf-8 -*-
tset = [0] * 27
while 1:
 try:
  str = raw_input().lower()
  a = ord('a')
  for c in str:
   tset[ord(c)-a if c.islower() else 26] += 1
 except EOFError:
  for c in xrange(26):
   print "{0} : {1}".format(chr(a+c), tset[c])
  break

Measured memory_bytes: 6452
h,w=map(int,input().split())
arr=[]
for i in range(h):
    arrx=list(map(int,input().split()))
    arr.append(arrx)

count=0
arry=[]
for i in range(h):
    for j in range(w):
        if(arr[i][j]%2!=0):
            flag=0
            if(j>0 and arr[i][j-1]%2!=0):
                arr[i][j]-=1
                arr[i][j-1]+=1
                count+=1
                arry.append((j+1,i+1,j,i+1))
                flag=1
            elif(j<w-1 and arr[i][j+1]%2!=0):
                arr[i][j]-=1
                arr[i][j+1]+=1
                count+=1
                arry.append((j+1,i+1,j+2,i+1))
                flag=1
            elif(i>0 and arr[i-1][j]%2!=0):
                arr[i][j]-=1
                arr[i-1][j]+=1
                count+=1
                arry.append((j+1,i+1,j+1,i))
                flag=1

            elif(i<h-1 and arr[i+1][j]%2!=0):
                arr[i][j]-=1
                arr[i+1][j]+=1
                count+=1
                arry.append((j+1,i+1,j+1,i+2))
                flag=1
            if(flag==0):
                if(j<w-1):
                    arr[i][j]-=1
                    arr[i][j+1]+=1
                    count+=1
                    arry.append((j+1,i+1,j+2,i+1))
                elif(i<h-1):
                    arr[i][j]-=1
                    arr[i+1][j]+=1
                    count+=1
                    arry.append((j+1,i+1,j+1,i+2))
print(count)
for i in range(len(arry)):
    print(arry[i][1],arry[i][0],arry[i][3],arry[i][2])


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

link = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    link[u - 1].append((v - 1, w))
    link[v - 1].append((u - 1, w))

d = [-1] * N
d[0] = 0
q = [0]
while q:
  i = q.pop(0)
  for n, w in link[i]:
    if d[n] == -1:
      d[n] = d[i] + w
      q.append(n)

for i in d:
  print(i % 2)

Measured memory_bytes: 42796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    pair<int,int> T=make_pair(0,N);
    cout<<0<<endl;
    string s; cin>>s;
    if(s=="Vacant") return 0;

    map<int,string> mp;
    mp[0]=s;
    mp[N]=s;

    rep(i,0,19){
        int q=(T.second-T.first)/2+T.first;
        cout<<q<<endl;
        string s; cin>>s;
        if(s=="Vacant") return 0;

        mp[q]=s;
        if((q-T.first)%2){
            if(s==mp[T.first]) T.second=q;
            else T.first=q;
        }else{
            if(s!=mp[T.first]) T.second=q;
            else T.first=q;
        }
    }
}

Measured memory_bytes: 852
#include<iostream>
#include<stdio.h>
#include<queue>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
#define INF 10000000
string ch[20];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int w,h,node;
int vd[20][20],u[11][11],px[11],py[11];
int t[11][11];
int dp[2048][11];
int compute(int,int);
void solve();
int main(){
  while(cin>>w>>h&&w){
    node=1;
    for(int i=0;i<h;i++){
      cin>>ch[i];
      for(int j=0;j<w;j++){
	if(ch[i][j]=='*'){
	  px[node]=j;
	  py[node++]=i;
	}else if(ch[i][j]=='o'){
	  px[0]=j;
	  py[0]=i;
	}
      }
    }
   
    for(int i=0;i<11;i++)for(int j=0;j<11;j++)t[i][j]=INF;
    for(int i=0;i<node-1;i++)
      for(int j=i+1;j<node;j++)
	t[i][j]=t[j][i]=compute(i,j);
    /*
    for(int i=0;i<node;i++){
      for(int j=0;j<node;j++){
	if(t[i][j]==INF){
	  printf("%2d ",-1);
	}else{
	  printf("%2d ",t[i][j]);
	}
      }
      cout<<endl;
    }
    */
    solve();
    
  }
}
int compute(int a,int b){
  for(int i=0;i<20;i++)for(int j=0;j<20;j++)vd[i][j]=0;
  queue<int>qx,qy,qz;
  int x,y,z,ny,nx;
  qx.push(px[a]);qy.push(py[a]),qz.push(0);
  vd[py[a]][px[a]]=1;
  while(!qx.empty()){
    x=qx.front();qx.pop();
    y=qy.front();qy.pop();
    z=qz.front();qz.pop();
    if(x==px[b]&&y==py[b])return z;
    for(int i=0;i<4;i++){
      ny=y+dy[i];
      nx=x+dx[i];
      if(ny<0||nx<0||ny>=h||nx>=w){
	continue;
      }
      
      if(ch[ny][nx]=='x')continue;
      if(!vd[ny][nx]){
	qy.push(ny);
	qx.push(nx);
	qz.push(z+1);
	vd[ny][nx]=1;
      }
    }
  }
  return INF;
}

int rec(int S,int v){
  if(dp[S][v]>=0){
    return dp[S][v];
  }
  if(S==(1<<node)-1){
    return dp[S][v]=0;
  }
  int res = INF;
  for(int u=0;u<node;u++){
    
    if(!(S>>u&1)){
      res=min(res,rec(S|(1<<u),u)+t[v][u]);
    }
    
  }
  return dp[S][v]=res;
}
void solve(){
  for(int i=0;i<2048;i++)
    for(int j=0;j<11;j++)
      dp[i][j]=-1;
  int out=rec(1,0);
  if(out!=INF)cout<<out<<endl;
  else cout<<-1<<endl;
}

Measured memory_bytes: 1312
md=10**9+7
s=input()
dp=[[0]*4 for _ in range(3)]
for c in s:
    if c=="A":dp[0][0]=(dp[0][0]+1)%md
    if c=="B":
        for j in range(2):dp[1][j]=(dp[1][j]+dp[0][j])%md
    if c=="C":
        for j in range(3):dp[2][j]=(dp[2][j]+dp[1][j])%md
    if c=="?":
        for j in range(3):dp[2][j+1]=(dp[2][j+1]+dp[1][j])%md
        for j in range(2):dp[1][j+1]=(dp[1][j+1]+dp[0][j])%md
        dp[0][1] = (dp[0][1] + 1) % md
ans=0
q=s.count("?")
for j in range(4):
    if q-j<0:break
    ans+=dp[2][j]*pow(3,q-j,md)
    ans%=md
print(ans)


Measured memory_bytes: 3316
import java.io.IOException;
import java.util.*;

class Point {
	double x;
	double y;
	Point(double x, double y) {
		this.x = x;
		this.y = y;
	}

	public double getX() {
		return x;
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}
}

class Vec {
	Point a;
	Point b;
	Vec(Point a, Point b) {
		this.a = a;
		this.b = b;
	}
}

class MathUtil {
	/**
	 * ??????????±??????????
	 *     Q
	 *  ???/
	 *   /
	 *  C -------- P
	 *
	 * @param p
	 * @param c
	 * @param q
	 * @return >0: ???????????? <0:???????????? 0:Q,C,P????????´???????????????
	 */
	public static double outProd(Point c, Point p, Point q) {
		return (p.getX() - c.getX()) * (q.getY() - c.getY()) - (p.getY() - c.getY()) * (q.getX() - c.getX());
	}

	public static boolean isZero(long EPS, double val) {
		return Math.abs(val) <= EPS;
	}
}

/**
 */
class Main {
	final static int N = 10;

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			String[] strArr = in.nextLine().split(",");
			double[] intArr = new double[strArr.length];
			for(int i=0;i<intArr.length;i++) {
				intArr[i] = Double.parseDouble(strArr[i]);
			}
			List<Point> points = new ArrayList<>();
			for(int i=0;i<intArr.length;i+=2) {
				double a = intArr[i];
				double b = intArr[i+1];
				points.add(new Point(a, b));
			}
			solve(points);
		}
	}

	public static void solve(List<Point> pts) {
		double prev = 0;
		int n =pts.size();
		for(int i=0;i<pts.size();i++) {
			double ret = MathUtil.outProd(pts.get(i%n), pts.get((i+1)%n), pts.get((i+2)%n));
			if(MathUtil.isZero((long)(1e-9), ret)) {
				continue;
			}
			if(ret * prev < 0) {
				System.out.println("NO");
				return;
			}
			prev = ret;
		}
		System.out.println("YES");
	}
}

Measured memory_bytes: 25884
fn c() {
    input! {
        n: usize,
        a: [u32; n]
    }

    let mut ans = 0_u64;
    let mut check = a[0];

    for v in a.iter() {
        if *v > check {
            check = *v;
        }
        else if *v < check {
            ans += (check - *v) as u64;
        }
    }

    println!("{}", ans);
}

use proconio::{input, marker::Chars};

fn main() {
    c();
}

Measured memory_bytes: 4816
// A. 

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int a, b;
	cin >> a >> b;
	cout << ((a <= 8 && b <= 8) ? "Yay!" : ":(") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <unordered_map>
#include <cmath>
#include <set>
#include <queue>
using namespace std;

int main(){
    string s;
    cin >> s;
    s = '0' + s;
    int n = s.size();
    int arr[n];
    for(int i = 0; i < n; i++){
        arr[i] = s[i] - '0';
    }
    int ans[n][2];
    ans[n-1][0] = arr[n-1];
    ans[n-1][1] = 10 - arr[n-1];
    for(int i = n-2; i >= 0; i--){
        for(int c = 0; c < 2; c++){
            int d = c ? 9 - arr[i] : arr[i];
            ans[i][c] = min(
                ans[i+1][c],
                ans[i+1][!c] + 1
            ) + d;
        }
    }
    cout << ans[0][0] << '\n';
}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

X,Y,Z,K=MAP()
A=LIST()
B=LIST()
C=LIST()

AB=[]
for i in range(X):
    for j in range(Y):
        AB.append(A[i]+B[j])
AB.sort(reverse=True)
AB=AB[:3000]

ABC=[]
for i in range(len(AB)):
    for j in range(Z):
        ABC.append(AB[i]+C[j])
ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n;
int ans = MAX_N;
int main() {
    scanf("%d",&n);
    vector<int>a(n);
    rep(i,0,n) cin >> a[i];

    rep(i,0,n){
        int cnt = 0;
        while(1){
            if(a[i]%2 == 0){
                cnt++;
                a[i] /= 2;
            }
            else{
                break;
            }
        }
        ans = min(cnt,ans);
    }
    pout(ans);
    return 0;
}

Measured memory_bytes: 256
n,t=gets.chomp.split(" ").map(&:to_i)
ns=gets.chomp.split(" ").map(&:to_i)

result = 0
now = 0
ns.each do |num|
  if now >= num then
    result = result + t - (now - num)
  else
    result = result + t
  end
  now = num + t
end

puts result


Measured memory_bytes: 17924
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
ll a, b;
double bb;

int main(){
	IOS
	int store;
	cin >> a >> bb;
	string c=to_string(bb);
	string isib1, isib2;
	int d=c.size();
	for(int i=0;i<d;i++){
		store=i;
		if(c[i]=='.'){
			break;
		}
		isib1=isib1+c[i];
	}
	for(int i=store+1;i<d;i++){
		isib2=isib2+c[i];
		if(isib2.size()==2){
			break;
		}
	}
	ll b1=stoi(isib1);
	ll b2=stoi(isib2);
	b1=b1*100+b2;
	cout << a*b1/100 << '\n';
	//cout << isib1 << " " << isib2 << '\n';
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define MAX (ll)(1e5 + 5)
ll dp[MAX];

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

    ll n;
    cin >> n;
    ll h[n];
    for (int i = 0; i < n; i++)
        cin >> h[i];

    dp[0] = 0;
    dp[1] = llabs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
        dp[i] = min(dp[i - 2] + llabs(h[i] - h[i - 2]), dp[i - 1] + llabs(h[i] - h[i - 1]));
    cout << dp[n - 1] << "\n";    
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
    int n, a[100000], count = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int k = a[0];
    for(int i = 1; i < n; i++){
        if(k == 2){
            cout << i << endl;
            return 0;
        }
        k = a[k-1];
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int maxn=1e3+5;
const ll inf=0x3f3f3f3f;
const ll mod=998244353;

char mp[maxn][maxn];

int sum[maxn][maxn];

int arr[maxn];
vector<int> v;
int n,m,k;

int calc(int i,int j,int col){
	int sum=0;
	for(int x=i;x<=j;x++){
		sum+=mp[x][col]-'0';
	}
	return sum;
}

int check(){
	for(int i=1;i<v.size();i++){
		arr[i]=0;
	}
	int flg=0;int ans=0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<v.size();j++){
			arr[j]+=calc(v[j-1]+1,v[j],i);
//			printf("%d %d %d\n",i,arr[j],k);
			if(arr[j]>k){
				flg=1;
				ans++;
				break;
			}
		}
		if(flg){
			flg=0;
			for(int j=1;j<v.size();j++){
				if(calc(v[j-1]+1,v[j],i)>k) return inf;
				arr[j]=calc(v[j-1]+1,v[j],i);
			}
		}
	}
//	printf("%d %d\n",v.size(),ans);
	return ans;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%s",mp[i]+1);
	}	
	int N=1<<(n-1);
	int ans=inf;
	for(int i=0;i<N;i++){
		int tmp=0;
		v.pb(0);
		for(int j=0;j<=n-2;j++){
			if(i&(1<<j)) v.pb(j+1);
		}
		v.pb(n);
		ans=min(ans,(int)v.size()-2+check());
		v.clear();
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>
#include<stdlib.h>
int asc(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int i;
	int h[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &h[i]);
	qsort(h, n, sizeof(int), asc);
	int ans = 1000000009;
	for (i = 0; i <= n - k; i++)
		if (ans > h[i + k - 1] - h[i])
			ans = h[i + k - 1] - h[i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 892
from fractions import gcd
import functools
import sys

n=int(input())
a = [int(i) for i in input().split()]

left_gcd = [a[0]]
for i in range(1,len(a)):
  left_gcd.append(gcd(left_gcd[-1],a[i]))
#print(left_gcd)
  
right_gcd = [a[-1]]
for i in range(len(a)-1)[::-1]:
  right_gcd.append(gcd(right_gcd[-1],a[i]))
right_gcd = right_gcd[::-1]
#print(right_gcd)

each_gcd = [right_gcd[1]]
for i in range(1,len(a)-1):
  each_gcd.append(gcd(left_gcd[i-1],right_gcd[i+1]))
each_gcd.append(left_gcd[-2])

#print(each_gcd)
print(max(each_gcd))
             

Measured memory_bytes: 16124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
constexpr double PI=3.14159265358979323846;
constexpr int INF = INT_MAX/2;

int main() {
	int N, M;
	cin >> N >> M;
	if (M%2 == 1) {
		std::cout << "No" << '\n';
	} else if (N*2 > M) {
		std::cout << "No" << '\n';
	} else if (N*4 < M) {
		std::cout << "No" << '\n';
	} else {
		std::cout << "Yes" << '\n';
	}
}


Measured memory_bytes: 3616
N = int(input())
S = input()

count = 0
for i in range(10):
  idx = S.find(str(i))
  if idx == -1 or idx >= N-2:
    continue
  for j in range(10):
    idx2 = S.find(str(j), idx+1)
    # print(('!', idx, idx2))
    if idx2 == -1 or idx2 >= N-1:
      continue
    set1 = set()
    for k in range(idx2+1, N):
      if S[k] not in set1:
        set1.add(S[k])
        if len(set1) >= 10:
          # print((i, j, 10))
          count += 10
          break
    else:
      # print((i, j, len(set1)))
      count += len(set1)

print(count)


Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

class Point{
public:
	double x,y;

	Point(double x = 0,double y = 0):x(x),y(y){}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}
};

typedef Point Vector;
typedef vector<Point> Polygon;

int num_point,Q;

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
	return a.x*b.x + a.y*b.y;
}

Point calc_minus(Point a,Point b){
	Point ret;

	ret.x = a.x-b.x;
	ret.y = a.y-b.y;

	return ret;
}

/*
 * IN 2
 * ON 1
 * OUT 0
 *
 */
int contains(Polygon g,Point p){
	int n = g.size();
	bool x = false;
	for(int i = 0; i < n; i++){
		Point a = g[i]-p,b = g[(i+1)%n]-p;
		if(abs(cross(a,b)) < EPS && dot(a,b) < EPS)return 1;
		if(a.y > b.y)swap(a,b);
		if(a.y < EPS && EPS < b.y && cross(a,b) > EPS) x = !x;
	}
	return (x ? 2:0);
}

int main(){

	scanf("%d",&num_point);
	Polygon g;

	double x,y;
	for(int loop = 0; loop < num_point; loop++){
		scanf("%lf %lf",&x,&y);
		g.push_back(Point(x,y));
	}

	scanf("%d",&Q);

	for(int loop = 0; loop < Q; loop++){
		scanf("%lf %lf",&x,&y);
		printf("%d\n",contains(g,Point(x,y)));
	}

	return 0;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
P calc(int a, int b) {
  int res = a + b;
  int cnt = 1;
  while(res > 9) {
    cnt++;
    res = res%10 + res/10;
  }
  return {res, cnt};
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  vector<P> v = {{0, 1}, {2, 1}, {4, 1}, {6, 1}, {8, 1}, {1, 2}, {3, 2}, {5, 2}, {7, 2}, {9, 2}};
  int m; cin >> m;
  vector<ll> d(m), c(m);
  vector<pair<ll, ll>> p(m);
  for(int i=0;i<m;++i) {
    cin >> p[i].first >> p[i].second;
  }
  ll ans = 0;
  vector<pair<ll, ll>> nxtp;
  bool upd = true;
  while(upd) {
    upd = false;
    for(int i=0;i<(int)(p.size());++i) {
      ll tmp = v[p[i].first].second * (p[i].second / 2);
      ans += tmp;
      if(tmp > 0) upd = true;
      if(p[i].second > 1) nxtp.emplace_back(make_pair(v[p[i].first].first, p[i].second / 2));
      if(p[i].second % 2) {
        nxtp.emplace_back(make_pair(p[i].first, 1ll));
      }
    }
    p = nxtp;
    nxtp.clear();
  }
  if((int)(p.size()) == 1) {
    cout << ans << endl;
    return 0;
  }
  int now = p[0].first;
  for(int i=1;i<(int)(p.size());++i) {
    P res = calc(now, p[i].first);
    ans += res.second;
    now = res.first;
  }
  cout << ans << endl;
}


Measured memory_bytes: 158136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long X;
  cin >> X;
  int k=0;
  if(X<=3){
      cout << X << endl;
  }
  else{
  while(k!=1){
    if(X%2==0){
    }
    else{
        for(int j=3;j<X;j=j+2){
            if(X%j==0){
                k=0;
                break;
            }
            else{
                k=1;
            }
        }  
    }
    X++;
  }
  cout << X-1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

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

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const ll inf = 1e18 ; 
const int MxN = 300005; 
const ll mod = 1e9+7 ; 
const int MOD = 998244353 ; 

ll nCr(ll n,ll r){
	ll res=1;
	if(r>n) return 0;
	if(r>n-r) r=n-r;
	for(ll i=0;i<r;i++) {
		res*=(n-i);
		res/=(i+1);
	}
	return res;
}
ll power(ll a , ll n)
{
	ll res = 1;
	while(n)
	{
		if(n & 1)
			res = (res * a) % MOD;
		n >>= 1;
		a = (a * a) % MOD;
	}
	return res%MOD;
}



vt<pii> dir =  {{-1,0} , {1, 0} , {0,-1} , {0,1}} ; 

// ==========Start Here==============
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 
	int n , z , w ; 
	cin >> n >> z >> w ; 
	vt<int> a(n) ; 
	rep(i,0,n) cin >> a[i] ; 
	if(n==1) {
		cout << abs(a[0]-w) ; 
	} else {
		cout << max(abs(a[n-1]-a[n-2]) , abs(a[n-1]-w)) ; 
	}

	cerr <<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<" ms\n";
	return 0 ; 
}


Measured memory_bytes: 3848
func readIntArray() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

let N = Int(readLine()!)!
var A = readIntArray()
A.sort()

var multiple = Array.init(repeating: false, count: A.last! + 1)
var count: [Int:Int] = [:]

A.forEach({ i in
    if count[i] == nil && !multiple[i] {
        var j = 2
        while i * j <= A.last! {
            multiple[i * j] = true
            j += 1
        }
    }
    count[i] = (count[i] ?? 0) + 1
})

print(A.filter({count[$0] == 1 && !multiple[$0]}).count)


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

int A[202];

int main() {
    
    int N;
    cin >> N;
    
    for(int i=1; i<=2*N; i++)
        cin >> A[i];
    
    sort(A+1, A+1+2*N);
    
    int ans = 0;
    
    for(int i=1; i<=2*N; i+= 2)
        ans += A[i];
    
    cout << ans << endl;
    
	return 0;
}


Measured memory_bytes: 256