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

int main() {
  int N;
  cin >> N;
  
  
  for(int i=1; i<10; i++){
    for(int j=1; j<10; j++){
      int A=i*j;
      if(N==A){
        cout << "Yes" << endl;
        return 0;
      }
      else {
        continue;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
X = list(map(int, input().split()))
X.sort()
diss=[0]*(M-1)
allDistance = abs(X[0])
for i in range(1,M):
    allDistance += X[i]
    diss[i-1] = abs(X[i]-X[i-1])
diss.sort(reverse=True)
print(sum(diss[N-1:]))

Measured memory_bytes: 85528
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  int a[n],b[m];
  int d=9999,e=-9999;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]>e)e=a[i];
  }
  for(int i=0;i<m;i++){
    cin >> b[i];
    if(b[i]<d)d=b[i];
  }
  for(int i=e+1;i<=d;i++){
    if(x<i&&i<=y){
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
}


Measured memory_bytes: 256
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n, m;
    cin >> n >> m;
    vector adjs(n, vector<int>());
    rep(i, m)
    {
        int s, t;
        cin >> s >> t;
        --s;
        --t;
        adjs[s].push_back(t);
    }

    vector<int> ts(n, -1), tsinv(n, -1);
    {
        int i = 0;
        auto dfs = fix([&](auto self, int s) -> void {
            if (tsinv[s] >= 0)
            {
                return;
            }

            for (auto t : adjs[s])
            {
                self(t);
            }

            ts[i] = s;
            tsinv[s] = i;
            ++i;
            return;
        });

        rep(s, n)
        {
            dfs(s);
        }
    }

    vector dp(n, 0);
    int ans = -1;
    rep(i, n)
    {
        int s = ts[i];
        for (auto t : adjs[s])
        {
            int j = tsinv[t];
            chmax(dp[i], dp[j] + 1);
        }

        chmax(ans, dp[i]);
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 14388
/*
 * Author       : YangDavid
 * Created Time : 2020.07.14 21:13:35
 * 可以证明网格图距离平方是 D 的点连边，形成的图一定是二分图。
 * 问题转化为给出两个 4N^2 个点的二分图，求一个大小为 N^2、在两个图中都是独立集的点。
 * 可以将点按两次染色的颜色分类（实际上是个“四分图”），取“四分图”最大的那个分量就行了。
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 391000;
vector<int> G[2][MAXN], box[4];
vector<pii> vecs[2];
int col[2][MAXN], n, D[2], *ccol;

void dfs(int v, int c, int o) {
    ccol[v] = c;
    for(auto g : G[o][v]) {
        if(ccol[g] == -1) dfs(g, c^1, o);
        else assert(ccol[g] != ccol[v]);
    }
}

int main() {
    memset(col, -1, sizeof col);
    map<int, int> sqrs;
    for(int i = 0; i < 500; ++i) sqrs[i*i] = i;

    scanf("%d%d%d", &n, &D[0], &D[1]);
    int n2 = n * 2;
    for(int o = 0; o < 2; ++o) {
        for(int i = -500; i <= 500; ++i) if(sqrs.count(D[o] - i * i)) {
            int res = sqrs[D[o] - i * i];
            vecs[o].emplace_back(i, res);
            if(res) vecs[o].emplace_back(i, -res);
        }
        for(int i = 0; i < n2; ++i)
            for(int j = 0; j < n2; ++j) {
                for(auto t : vecs[o]) {
                    int ni = i + t.first, nj = j + t.second;
                    if(min(ni, nj) >= 0 && max(ni, nj) < n2) {
                        G[o][i*n2+j].push_back(ni*n2+nj);
                        G[o][ni*n2+nj].push_back(i*n2+j);
                    }
                }
            }
        ccol = col[o];
        for(int i = 0; i < n2*n2; ++i) if(ccol[i] == -1)
            dfs(i, 0, o);
    }
    for(int i = 0; i < n2*n2; ++i) {
        int m = col[0][i] + col[1][i] * 2;
        box[m].push_back(i);
        if((int)box[m].size() == n*n) {
            for(auto g : box[m])
                printf("%d %d\n", g/n2, g%n2);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 182104
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    a, b, c = sorted(Input())
    k = int(input())

    for i in range(k):
        c *= 2
    print(a+b+c)


main()

Measured memory_bytes: 8932
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

func main() {
	n := readInt()
	h := make([]int, n)
	for i := range h {
		h[i] = readInt()
	}

	pre := math.MaxInt64
	for i := range h {
		if h[n-1-i] > pre {
			h[n-1-i]--
		}
		if h[n-1-i] > pre {
			fmt.Println("No")
			return
		}
		pre = h[n-1-i]
	}

	fmt.Println("Yes")
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int P,Q,R; cin >> P >> Q >> R;

    cout << P+Q+R-max({P,Q,R}) << endl;

    return 0;

}

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

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let input_max = 100_000;
    let mut is_primes = [true; 100_000 + 10];
    let mut like2017 = [false; 100_000 + 10];
    let mut accum_sum = [0; 100_000 + 10];
    let mut primes = Vec::new();

    is_primes[0] = false;
    is_primes[1] = false;

    //前処理--------------------------
    //エラトステネスの篩で素数を列挙
    for i in 2..=input_max {
        if is_primes[i] {
            primes.push(i);
            for j in (2 * i..input_max + 1).step_by(i) {
                is_primes[j] = false;
            }
        }
    }

    // 2017に似た数をチェックし累積和にする
    for i in 2..=input_max {
        if is_primes[i] && is_primes[(i + 1) / 2] {
            like2017[i] = true;
            accum_sum[i] = accum_sum[i - 1] + 1;
        } else {
            accum_sum[i] = accum_sum[i - 1];
        }
    }

    //クエリ処理（入力を受ける）--------
    let q: usize = read();
    for _ in 0..q {
        let l: usize = read();
        let r: usize = read();

        println!("{}", accum_sum[r] - accum_sum[l - 1]);
    }

    /*
    for i in 0..17{
        println!("like2017:{}",like2017[i]);
        println!("accum_sum:{}",accum_sum[i]);
    }
    */
}


Measured memory_bytes: 2728
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a,b;
    char op;
    cin>>a>>op>>b;
    while(op!='?')
    {
        int c;
        if(op=='+') c=a+b;
        if(op=='-') c=a-b;
        if(op=='*') c=a*b;
        if(op=='/') c=a/b;
        cout<<c<<endl;
        cin>>a>>op>>b;
    }
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
#define INF 1000000
using namespace std;
typedef pair<int,int> P;
P pt[100000];
P xs;

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

P update(P r,int x){
	return P(min(r.first,x),max(r.second,x));
}

bool solve(int n,int D){
	int i;
	vector<int> ry;
	P yr[2]={P(INF,-INF),P(INF,-INF)};
	for(i=0;i<n;i++){
		int x=pt[i].first;
		int y=pt[i].second;
		if(x>xs.first+D&&x<xs.second-D)return false;
		else if(x>xs.first+D)yr[1]=update(yr[1],y);
		else if(x<xs.second-D)yr[0]=update(yr[0],y);
		else ry.push_back(y);
	}
	sort(ry.begin(),ry.end());
	P yrt[2]={yr[0],yr[1]};
	int p=0;
	while(p<ry.size()&&ry[p]<=yrt[0].first+D)yrt[0]=update(yrt[0],ry[p++]);
	for(;p<ry.size();p++)yrt[1]=update(yrt[1],ry[p]);
	if(yrt[0].second-yrt[0].first<=D&&yrt[1].second-yrt[1].first<=D)return true;
	yrt[0]=yr[0];
	yrt[1]=yr[1];
	p=0;
	while(p<ry.size()&&ry[p]<=yrt[1].first+D)yrt[1]=update(yrt[1],ry[p++]);
	for(;p<ry.size();p++)yrt[0]=update(yrt[0],ry[p]);
	if(yrt[0].second-yrt[0].first<=D&&yrt[1].second-yrt[1].first<=D)return true;
	return false;
}

int main(){
	int n,i;
	scanf("%d",&n);
	xs=P(INF,-INF);
	for(i=0;i<n;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		int a=x+y;
		int b=x-y;
		pt[i]=P(a,b);
		xs=update(xs,a);
	}
	int l=0,r=INF;
	while(r-l>1){
		int mid=(l+r)/2;
		if(solve(n,mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 2444
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,ans=0;
int par[100010];
vector <pair <pii,int> > v[2];
vector <pair <int,pii> > con;

inline int getval(pair <pii,int> a,pair <pii,int> b)
{
	return min(abs(a.fi.fi-b.fi.fi),abs(a.fi.se-b.fi.se));
}

int FIND(int pos)//dsu
{
	if(par[pos]!=pos) par[pos]=FIND(par[pos]);
	return par[pos];
}

inline void UNION(int pos1,int pos2)
{
	par[FIND(pos1)]=FIND(pos2);
}

int main()
{ 
	cin>>n;
	rep(i,100005) par[i]=i;
	rep(i,n)
	{
		LL x,y;
		scanf("%I64d%I64d",&x,&y);
		v[0].pb({{x,y},i});
		v[1].pb({{y,x},i});
	}
	sort(v[0].begin(),v[0].end());
	sort(v[1].begin(),v[1].end());
	repn(i,n-1)
	{
		con.pb({getval(v[0][i-1],v[0][i]),{v[0][i-1].se,v[0][i].se}});
		con.pb({getval(v[1][i-1],v[1][i]),{v[1][i-1].se,v[1][i].se}});
	}
	sort(con.begin(),con.end());
	rep(i,con.size())
	{
		if(FIND(con[i].se.fi)==FIND(con[i].se.se)) continue;
		UNION(con[i].se.fi,con[i].se.se);
		ans+=con[i].fi;
	}
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 14372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
 
/*int g(int a,int b){
  int r=a%b;
  if(r<1)return b;
  g(b,r);
}*/
int main(){
  int k;
  cin>>k;
  int ans=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        ans +=gcd(gcd(i,j),l);
      }
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int sum = accumulate(A.begin(), A.end(), 0);
  int select = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] * 4 * M < sum) continue;
    select++;
  }

  if (select >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 384
N=int(input())
D=[int(i) for i in input().split()]
ans=1
mod=998244353
M=max(D)+1
X=[0 for i in range(M)]
for i in range(N):
    X[D[i]]+=1
if X[0]!=1:
    print(0)
    exit()
if D[0]!=0:
    print(0)
    exit()
if N==1:
    print(1)
    exit()
if N==2:
    if D[0]==0 and D[1]==1:
        print(1)
    else:
        print(0)
    exit()
#print(X)
for i in range(1,M-1):
    #print(X[i],X[i+1])
    ans=ans*pow(X[i],X[i+1],mod)
    ans%=mod
print(ans)


Measured memory_bytes: 14396
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
        rep(i,n) cin>>p.at(i);
    vector<vector<int>> dp(n+1,vector<int>(k+1,inf));
    dp[0][0]=0;
    rep(i,n){
        rep(j,k+1){
            if(dp[i][j]==inf) continue;
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            if(j<k){
                dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+p[i]);
            }
        }
    }
    cout<<dp[n][k]<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 6984
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<list>
#include<stack>
#include<sstream>
#define lli long long int
#define h 1000000007
#define s 10000
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lowepr_bound
#define mp make_pair
#define pi 3.14159
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL) ;
  lli n, fact=1,i, fact2=1,ans,fact3=1;
  cin>>n;
  for(i=1;i<=n;i++) 
  fact=((fact%h)*10)%h;
  for(i=1;i<=n;i++) 
  fact2=((fact2%h)*8)%h;
  for(i=1;i<=n;i++) 
  fact3=((fact3%h)*9)%h;
  ans=(fact-(fact3+fact3-fact2))%h;
  if(ans<0){ans+=h;} 
  cout<<ans<<endl;
  return 0;
} 


Measured memory_bytes: 3688
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<cstdio>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn=1e9+7;
typedef long long ll;
#define INF 0x3f3f3f3f
#define IO ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
ll a[100007];
int id=0;
int mark3,mark5,mark7;
void dfs(ll num)
{
    if(num>maxn) return;
    mark3=0,mark5=0,mark7=0;
    ll countt=num;
    while(countt>0)
    {
        if(countt%10==3)
            mark3=1;
        else if(countt%10==5)
            mark5=1;
        else if(countt%10==7)
            mark7=1;
        countt/=10;
    }
    if(mark3&&mark5&&mark7)
        a[id++]=num;
    dfs(num*10+3);
    dfs(num*10+5);
    dfs(num*10+7);
}
int main()
{
    IO;
    dfs(3);
    dfs(5);
    dfs(7);
//    cout<<id<<endl;
    sort(a,a+id);
    ll t;
    cin>>t;
    int res=0;
    for(int i=0;i<id;i++)
    {
        if(a[i]<=t)
            res++;
        else break;
    }
    cout<<res<<endl;
//    for(int i=0;i<id;i++)
//        cout<<a[i]<<endl;
    return 0;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
//int nm[10001][10001] = {0};
 
map<pair<int,int>,int> nm;
 
int b[10000];
 
int main() {
    int n,m;
 
    cin >> n >> m;
 
    while(1){
        int s,t,e;
        scanf(" %d %d %d",&s,&t,&e);
        if( (s+t+e) == 0) break;
        //nm[s][t] = e;
        nm[make_pair(s,t)] = e;
    }
 
    int l;
 
    cin >> l;
 
    pair<int,int> tmp;
 
    while(l--) {
 
        long c[10001] = {0};
 
        for(int i=1;i<=m;i++){
            scanf(" %d",&b[i]);
        }
 
        int i, j;
        for (i = 1; i <= n; i++) {
            /*for (j = 0; j < m; j++) {
                c[i] = c[i] + nm[i][j+1] * b[j];
            }*/
        }
        for(map<pair<int,int>,int>::iterator itr = nm.begin(); itr != nm.end(); ++itr) {
            tmp = itr->first;
            c[tmp.first] += b[tmp.second] * itr->second;
            //cout << "I'm hungry " << c[tmp.first] << " " << tmp.first << " " << tmp.second << endl;
        }
 
 
        for(int i=1;i<=n;i++){
            //cout << c[i];
            printf("%d",c[i]);
            if(i!=n) printf(" ");//cout <<  ' ';
        }
        printf("\n");
 
    }
    return 0;
}

Measured memory_bytes: 6468
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

string s, t;
int k, n, len;
long long ans;

int fun()
{
	int cnt = 1, cur = 1, retval = 0;
	while (cur < n) {
		if (s[cur] != s[cur - 1]) {
			retval += cnt / 2;
			cnt = 1;
		}
		else
			cnt++;
		cur++;
	}
	retval += cnt / 2;
	return retval;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s >> k;
	n = s.length();
	len++;
	while (len < n && s[len] == s[len - 1]) len++;
	if (len == n) {
		ans = (n * 1LL * k) / 2;
	}
	else if (s[0] == s[n - 1]) {
		ans = fun();
		t = s.substr(len, n - len) + s.substr(0, len);
		s = t;
		ans += fun() * 1LL * (k - 1);
	}
	else {
		ans = fun() * 1LL * k;
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc145/tasks/abc145_e
//E - All-you-can-eat
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 max_n=3000+10;
// const int max_t=3000+10;
// ll dp[max_n][max_t];
#if 0

int MIN = I64_MAX;
const int MAX = 1000000;

void solve()
{

  int N,T;
  cin>>N>>T;

  vector<pair<int,int> > data(N,pair<int,int>(0,0));

  for (int i = 0; i < N; i++)
  { 
    int A,B;
    cin>>A>>B;
    data[i].first = A;
    data[i].second = B;
  }
  
  sort(data.begin(),data.end());

  

  vector<vector<int> > DP (N + 1,vector<int>(T, 0 ));
  
   for (int i = 1; i <= N; i++)
  {
    for (int j = 0; j < T; j++)
    {
      if(j - data[i-1].first < 0)
      {
        DP[i][j] = DP[i-1][j];
        continue;
      }
      DP[i][j] =max(DP[i-1][j],DP[i-1][j-data[i-1].first] + data[i-1].second);
    }  
  }
  int ANS = 0;
  
  for (int i = 0; i < N ; i++)
  {
    ANS = max(ANS,DP[i][T-1] + data[i].second);
  }

  cout<<ANS;
  
  return;  
}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

#endif
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    //std::ifstream in("./input.txt"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N, T; cin>>N>>T;    
    vector<vector<ll>> dp(N+3,vector<ll>(T+2,0));

    vector<pair<ll,ll>> abn(N+1); //time,value
    FOR(i,1,N+1){
        auto& ab=abn.at(i);
        cin>>ab.first>>ab.second;
    }

    sort(abn.begin()+1,abn.end());
    // sort(abn.begin()+1,abn.end(),[](const auto& a,const auto& b){
    //     if(a.second==b.second) return (a.first<b.first);
    //     return (a.second<b.second);
    // });
    //(*(abn.end()-1)).second=1; //最後は1でいけるとする

    for(ll i=1; i<N;++i){
        auto ti=abn.at(i).first;
        auto vi=abn.at(i).second;
        for(ll t=0;t<T; ++t){
            if (t-ti>=0) {
                dp[i][t]=max(dp[i-1][t-ti]+vi, dp[i-1][t]);
            }else{
                dp[i][t]=dp[i-1][t];
            }
        }
        // if(i==N){//最後は0でいけるとする
        //     dp[i][T]=max(dp[i-1][T-1]+vi,dp[i][T]);
        // }
    }

    ll ans=0;
    FOR(i,1,N+1){
        ans=max(dp[i-1][T-1]+abn.at(i).second, ans);
    }
    cout<<ans<<endl;

    return 0;
}

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

int w, h;
int field[55][55];

void dfs(int sh, int sw){
    for(int dx = -1; dx <= 1; dx++){
        for(int dy = -1; dy <= 1; dy++){
            int nh = sh + dx, nw = sw + dy;
            if(nh < 0 || h <= nh || nw < 0 || w <= nw) continue;
            if(field[nh][nw] == 0) continue;
            field[nh][nw] = 0;
            dfs(nh, nw);
        }
    }
}

void solve(){
    int cnt = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(field[i][j] == 0) continue;
            field[i][j] = 0;
            dfs(i,j);
            cnt++;
        }
    }

    cout << cnt << endl;
}

int main(){
    while(cin >> w >> h){
        if(h == 0 || w == 0) break;
        rep(i,h)rep(j,w) cin >> field[i][j];
        solve();
    }
}


Measured memory_bytes: 3308
from heapq import heappop, heappush
N, M = map(int, input().split())
link = {(i, j) : [] for i in range(1, N+1) for j in range(3)}
for _ in range(M):
    u, v = map(int, input().split())
    link[(u, 0)].append((v, 1))
    link[(u, 1)].append((v, 2))
    link[(u, 2)].append((v, 0))
S, T = map(int, input().split())

''' dijkstra '''
INF = 10 ** 9
vstd = {(i, j): False for i in range(1, N+1) for j in range(3)}
dist = {(i, j): INF for i in range(1, N+1) for j in range(3)}  # distance
# prev = {i: -1 for i in range(1, N+1)}  # for extract min cost path
pq = []
# initialize
dist[(S, 0)] = 0
heappush(pq, (0, (S, 0)))
while pq:
    _, u = heappop(pq)
    vstd[u] = True
    for v in link[u]:
        if vstd[v]:
            continue
        if dist[u] + 1 < dist[v]:
            dist[v] = dist[u] + 1
            # prev[v] = u
            heappush(pq, (dist[v], v))


print(dist[(T, 0)] // 3 if dist[(T, 0)] % 3 == 0 else -1)


Measured memory_bytes: 148860
import sys
sys.setrecursionlimit(10**7)
n = int(input())

def rec(s, mx, l):
    if l >= n:
        print("".join([chr(ord("a") + x) for x in s]))
        return
    for x in range(mx+2):
        rec(s+[x], max(mx, x), l+1)

rec([0], 0, 1)


Measured memory_bytes: 4340
#include <stdio.h>
#include <stdlib.h>

typedef struct tuple{
    int num;
    int index;
}tuple;
tuple B[2*100000];

int compare_int(const void *a, const void *b)
{
    return (*(tuple*)a).num - (*(tuple*)b).num;
}
int abs(int a){ return ( a<0)? -a:a;}
int main(void){
    // Your code here!
    long long N;
    scanf("%lld",&N);
    
    for(int i = 0; i < N; i++){
        scanf("%d", &(B[i].num));
        B[i].num -= 1+i;
        B[i].index = i;
    }
    
    qsort(B, N, sizeof(tuple), compare_int);
    
    int b = B[N/2].num;
    
    int candidates[] = {0,0,0};
    candidates[0] = N/2-1;
    candidates[1] = N/2;
    candidates[2] = N/2+1;
    
    long long min = 10000000000000000LL;
    for(int i = 0; i < 3; i++){
        int b = B[candidates[i]].num;
        long long sum = 0;
        for(int j = 0; j < N; j++){
            sum += abs(B[j].num-b);
        }
        if(min > sum) min = sum;
    }
    
    /* An-n = b*/
    long long  ans = min;
    printf("%lld\n",ans);
}


Measured memory_bytes: 3324
// She is Pretty pretty!
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int N = 1e6+100;
int n , k , a[N], dp[N];
int boyi(int x){
    if(dp[x]) return dp[x];
    int fl = 0;
    for(int i = 0 ; i < n; i++){
        if(a[i] <= x && boyi(x - a[i]) == -1){
            fl = 1;
        }
    }
    return dp[x] =  (fl ? 1 : -1);
}
int main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    dp[0] = -1;
    puts(boyi(k) == 1? "First":"Second");
    return 0;
}

Measured memory_bytes: 7424
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Element> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int h = sc.nextInt();
            list.add(new Element(x, y, h));
        }
        sc.close();

        // 高度の降順でソート
        Collections.sort(list, (e1, e2) -> e2.h - e1.h);
//        System.out.println(list);

        // Cx, Cy は全組み合わせ 101 x 101 ≒ 10,000通りを全通り検証可能
        // 1)高度hiが != 0 の場合でHを求める。そのHが他の条件を満たすことを確認する
        // 2)すべてのhiが 0 の場合、hiはHの単調増加関数であるため、H=1で検証する

        // list.get(0).h != 0
        for (int cx = 0; cx <= 100; cx++) {
            for (int cy = 0; cy <= 100; cy++) {
                Element e = list.get(0);
                int hCandidate = e.h + Math.abs(e.x - cx) + Math.abs(e.y - cy);
                boolean isOk = true;
                for (int i = 1; i < n; i++) {
                    Element ei = list.get(i);
                    int hi = evaluate(hCandidate, ei.x, ei.y, cx, cy);
                    if (hi != ei.h) {
                        isOk = false;
                        break;
                    }
                }
                if (isOk) {
                    System.out.println(cx + " " + cy + " " + hCandidate);
                    System.exit(0);
                }
            }
        }
    }

    static int evaluate(int hCandidate, int x, int y, int cx, int cy) {
        return Math.max(hCandidate - Math.abs(x - cx) - Math.abs(y - cy), 0);
    }

    static class Element {
        int x;
        int y;
        int h;

        Element(int x, int y, int h) {
            this.x = x;
            this.y = y;
            this.h = h;
        }

        @Override
        public String toString() {
            return "(x=" + x + ", y=" + y + ", h=" + h + ")";
        }
    }

}


Measured memory_bytes: 26964
#include <stdio.h>
int main(){
	int N=0;
	int K=0;
	scanf("%d %d", &N, &K);
	if(K<=100&&1<=N){
		bool ac=(N+1)/2>=K;
		if(ac){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define CLR(a)              memset(a, 0, sizeof(a))
#define SET(a, x)           memset(a, x, sizeof(a))
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for (int i=0; i<n; i++)
#define FOR1(i, n)          for (int i=1; i<=n; i++)
#define ROF(i, n)           for (int i=n-1; i>=0; i--)
#define ROF1(i, n)          for (int i=n; i>=1; i--)
#define LOOP(i, x, n)       for (int i=x; i<=n; i++)
#define READ(x)             freopen(x, "r", stdin);
#define WRITE(x)            freopen(x, "w", stdout);
#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI                  acos(-1.0)
#define pb                  push_back
#define mp                  make_pair
#define fi                  first
#define se                  second
#define all(v)              v.begin(), v.end()

using namespace std;

typedef long long              ll;
typedef unsigned long long     ull;
typedef vector<int>            vi;
typedef pair<int, int>         pii;
typedef pair<string, int>      psi;
typedef pair<char, int>        pci;

const double eps = 1e-9;

int fx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int fy[] = {0, 0, -1, 1, -1, 1, -1, 1};

int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};

int main()
{
    string s; cin >> s;
    deque < char > q;
    for (char x : s)
        q.pb(x);

    int dir = 1;
    int Q; cin >> Q;
    while(Q--){
        int d; cin >> d;
        if (d == 1) dir *= -1;
        else{
            int f; cin >> f;
            char c; cin >> c;
            if (f == 1){
                if (dir == 1) q.push_front(c);
                else q.push_back(c);
            }
            else{
                if (dir == 1) q.push_back(c);
                else q.push_front(c);
            }
        }
    }
    if (dir == 1){
        while(!q.empty()){
            cout << q.front();
            q.pop_front();
        }
    }
    else{
        while(!q.empty()){
            cout << q.back();
            q.pop_back();
        }
    }
    cout << endl;
    return 0;
}




Measured memory_bytes: 896
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var abhm = Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
            var h = (abhm[2] + (abhm[3] / 60.0)) * 30.0;
            var m = abhm[3] * 6.0;
            var angle = Math.Abs(h - m) * Math.PI / 180.0;
            var tmp = (abhm[0] * abhm[0]) + (abhm[1] * abhm[1]) - (2.0 * abhm[0] * abhm[1] * Math.Cos(angle));
            Console.WriteLine(Math.Sqrt(tmp));
        }
    }
}


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

int main ()
{
	int a,b,c;  cin>>a>>b>>c;
	
	int m=b-a;
	int n=c-b;
	
	if(m==n){
		cout<<"YES"<<endl;
	}
	else 
	cout<<"NO"<<endl;
	


}



Measured memory_bytes: 3600
N = int(input())
S = [input() for _ in range(N)]

def solve(N, S):
    cs1 = [tuple(x) for x in S]
    cs2 = list(zip(*cs1))
    r = 0
    for d in range(N):
        if cs1 == cs2:
            r += 1
        cs1 = cs1[-1:] + cs1[:-1]
        cs2 = [row[-1:] + row[:-1] for row in cs2]
    return r * N

print(solve(N, S))


Measured memory_bytes: 5332
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        String s = sc.next();
        System.out.println((s.equals("AAA") || s.equals("BBB")) ? "No" : "Yes");
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
            return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23124
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[][] a=new int[n][m];
		int[] b=new int[m],c=new int[n];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				a[i][j]=sc.nextInt();
			}
		}
		for(int i=0;i<m;i++){
			b[i]=sc.nextInt();
		}
		for(int i=0;i<n;i++){
			c[i]=0;
			for(int j=0;j<m;j++){
				c[i]+=a[i][j]*b[j];
			}
			System.out.println(c[i]);
		}
	}
}


Measured memory_bytes: 40468
#B-Friendly Rabbits
num = int(input())
str = input()
Li = list(map(int,str.split(' ')))
CoupleNum = 0
for pointer in range(len(Li)):
	ai = Li[pointer]
	if (ai > pointer+1):
		if (Li[ai-1]==pointer+1):
			CoupleNum += 1
print(CoupleNum)


Measured memory_bytes: 14584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		while(scan.hasNext()) {
			int H = scan.nextInt(), W = scan.nextInt();
			if(H == 0 && W == 0) {
				break;
			}else {
				for(int i = 0 ; i < H ; i++) {
					for(int j = 0 ; j < W ; j++) {
						if(( i + j ) % 2 == 0) {
							System.out.print("#");
						}else {
							System.out.print(".");
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		}
		scan.close();
	}

}



Measured memory_bytes: 34752
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector< vector<bool> > done;

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

    int H, W;
    cin >> H >> W;
    done.resize(H, vector<bool>(W, false));

    string s;
    queue< pair<int, int> > q;
    rep (i, H)
    {
        cin >> s;
        rep (j, W)
        {
            if (s[j] == '#')
            {
                q.push(make_pair(i, j));
                done[i][j] = true;
            }
        }
    }

    int ans = 0;
    while (!q.empty())
    {
        ++ans;
        int s = q.size();
        rep (i, s)
        {
            int xx = q.front().first;
            int yy = q.front().second;
            q.pop();
            if (xx + 1 < H && !done[xx + 1][yy]) { done[xx + 1][yy] = true; q.push(make_pair(xx + 1, yy)); }
            if (xx - 1 >= 0 && !done[xx  - 1][yy]) { done[xx - 1][yy] = true; q.push(make_pair(xx - 1, yy)); }
            if (yy + 1 < W && !done[xx][yy + 1]) { done[xx][yy + 1] = true; q.push(make_pair(xx, yy + 1)); }
            if (yy - 1 >= 0 && !done[xx][yy - 1]) { done[xx][yy - 1] = true; q.push(make_pair(xx, yy - 1)); }
        }
    }
    cout << ans - 1 << "\n";
    return 0;
}



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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

const ll LLINF = 4e+18 + 10;

using pint = pair<int,int>;

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> x(N),y(N);
    vector<pint> xy(N);
    REP(i,N) {
        cin >> x[i] >> y[i];
        xy[i] = pint(x[i],y[i]);
    }
    
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    
    
    ll ans = LLINF;
    for ( int xl = 0; xl < N; ++xl){
        for ( int xr = xl; xr < N; ++xr){
            for ( int yl = 0; yl < N; ++yl){
                for ( int yr = yl; yr < N; ++yr){
                    ll dx = x[xr] - x[xl], dy = y[yr] - y[yl];
                    ll S = dx * dy;
                    
                    int count = 0;
                    for ( auto a: xy){
                        int X = a.first, Y = a.second;
                        if ( X >= x[xl] and X <= x[xr] and Y >= y[yl] and Y <= y[yr] ) ++ count;
                    }
                    //cout << xl << " " << xr << " " << yl << " " << yr << " " << count << endl;
                    if ( count >= K ) {
                        chmin( ans, S);
                    }
                    
                }
            }
        }
    }
    
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
  int n;
  int s=0;
  scanf("%d",&n);
  int p[n];
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  for(int j=0;j<n-2;j++){
    if((p[j+1]<p[j])&&(p[j+1]>p[j+2]))s=s+1;
    else if((p[j+1]>p[j])&&(p[j+1]<p[j+2]))s=s+1;
  }
  printf("%d\n",s);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n;
long double a[100001];
int main(){cin>>n;
	int i;
	long long s=1;
	for(i=1;i<=n;++i){cin>>a[i];
	if(a[i]==0){cout<<0;
	return 0;	
	}
	}
	for(i=1;i<=n;++i){
		if(s>(long double)1e18/a[i]){cout<<-1;
		return 0;
		}
		s*=a[i];
	}
	cout<<s;
	return 0;
} 

Measured memory_bytes: 5252
n=gets.to_i
a=gets.split.map(&:to_i)
m=a.delete(a.max)
l=0
lm=1/0.0
a.each do |aa|
  ab=(aa-m/2.0).abs
  if ab<lm
    lm=ab
    l=aa
  end
end
puts [m,l].join(" ")


Measured memory_bytes: 8452
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;

    int ret[n] = {};
    for(int i=1;i<=n;++i)
    {
        for(int j=i+1;j<=n;++j)
        {
            int tmp = j-i;
            tmp = min(tmp, abs(i-x) + abs(j-y) + 1);
            tmp = min(tmp, abs(i-y) + abs(j-x) + 1);
            ret[tmp]++;
        }
    }

    for(int i=1;i<=n-1;++i)
    {
        cout << ret[i] << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(N-1):
    if p[i] == i+1:
        a = p[i]
        b = p[i+1]
        p[i] = b
        p[i+1] = a
        count += 1
if p[N-1] == N:
    count += 1
print(count)


Measured memory_bytes: 14008
from fractions import gcd

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

rs, ls = [0], [0]
for i in range(n-1):
  rs.append(gcd(rs[i], a[i]))
  ls.append(gcd(ls[i], a[-i-1]))

print(max(gcd(r, l) for r, l in zip(rs, ls[::-1])))

Measured memory_bytes: 16112
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
int main(){
  ll n,ans=0;cin>>n;
  vector<ll> a(n),b(n),c(n);
  rep(i,n) cin>>a[i];rep(i,n) cin>>b[i];rep(i,n) cin>>c[i];
  sort(ALL(a));sort(ALL(b));sort(ALL(c));
  rep(i,n){
    ans+=(lower_bound(ALL(a),b[i])-a.begin())*(c.end()-upper_bound(ALL(c),b[i]));
  }
  cout<<ans<<endl;
}


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

using namespace std;

int main(){
    int n;
    string s,ans;

    cin >> n >> s;

    for(int i = 0;i < n;i++){
        if(s[i] != s[i+1]){
            ans += s[i];
        }
    }

    cout << ans.size() << endl;

    return 0;
}

Measured memory_bytes: 512
buttons = input().split()
a = int(buttons[0])
b = int(buttons[1])
count = 0

if a > b:
    count += a
    a -= 1
elif b > a:
    count += b
    b -= 1
elif a == b:
    count += a
    a -= 1
        
if a > b:
    count += a
    a -= 1
elif b > a:
    count += b
    b -= 1
elif a == b:
    count += a
    a -= 1
print(count)


Measured memory_bytes: 3064
n = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(n-1,i,-1):
        if A[j-1]>A[j]:
            A[j-1],A[j]=A[j],A[j-1]
            ans+=1

print(*A)
print(ans)



Measured memory_bytes: 5604
# include<iostream>

using namespace std;
int main() {
	int a[10000];
	int an = 0;
	for (;     ;)
	{
		cin >> a[an];
		if (a[an] == 0) {
			break;
		}
		an++;
	}
	for (int i = 0; i < an; i++) {
		cout << "Case " << i + 1 << ": " << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;


int main(void) {
    long long int h ,w;
    cin >> h >> w;
    
    if (h == 1 || w == 1) {
        cout << 1 ;
        return 0;
    }
    
    if(h % 2 == 0){
        cout << (h / 2) * w;
        return 0;
    }else{
        if(w % 2 == 0){
            cout << h * (w / 2);
            return 0;
        }else{
            cout << h * (w / 2) + int(round(h/2.0));
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >>W >>H >>x >>y >>r;
    if(0 <= x-r && x+r <= W && 0 <= y-r && y+r <= H) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
vector<LL>dp;
vector<vector<LL>>a;
int main(){
	cin>>n;
	a.resize(n,vector<LL>(n));
	dp.resize(1<<n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	for(int i=1;i<1<<n;i++)
		for(int j=0;j<n-1;j++)if(1<<j&i)
			for(int k=j+1;k<n;k++)if(1<<k&i)
				dp[i]+=a[j][k];
	for(int i=1;i<1<<n;i++)
		for(int j=(i-1)&i;j;j=(j-1)&i)
			dp[i]=max(dp[i],dp[j]+dp[i^j]);
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}


Measured memory_bytes: 768
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find((v).begin(), (v).end(), i) != (v).end())
#define ERASE(v,i) (v).erase(remove((v).begin(),(v).end(),i),(v).end())
#define me (*this)

//repetition
//------------------------------------------
#define rep(i,s) for(int i=0; i<(int)(s); i++)

//constant
//--------------------------------------------
const int INF = 100000000;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLEAR(a) memset((a), 0 ,sizeof(a))

//debug
#define debug(x)  cerr << #x << " = " << (x) << endl

bool prime[10001];

void makePrimeList() {
	rep(i, 10001)
		prime[i] = true;
	prime[0] = prime[1] = false;
	for(int i = 2; i * i <= 10000; i++)
		if(prime[i])
			for(int j = 2; i * j <= 10000; j++)
				prime[i * j] = false;
}

int main() {
	makePrimeList();
	static int n;
	while(cin >> n) {
		vint ary(n);
		for(int i = 1; i <= n; i++)
			ary[i - 1] = i;
		vint rary = ary;
		reverse(all(rary));
		int ans = 0;
		rep(i,n) {
			if(prime[ary[i]] == true && prime[rary[i]] == true)
				ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
    long g;
    if(c>=d){
      g = gcd(c,d);
    }else{
      g = gcd(d,c);
    }
    long l = (c/g)*(d/g)*g;
    long cnt1 = b/c-(a+c-1)/c;
    long cnt2 = b/d-(a+d-1)/d;
    long cnt3 = b/l-(a+l-1)/l;
    if(cnt1<0){
      cnt1 = 0;
    }else{
      cnt1++;
    }
    if(cnt2<0){
      cnt2 = 0;
    }else{
      cnt2++;
    }
    if(cnt3<0){
      cnt3 = 0;
    }else{
      cnt3++;
    }
    
    System.out.println(b-a+1-(cnt1+cnt2-cnt3));
    System.out.flush();
  }
  
  public static long gcd(long a,long b){
    if(b==0){
      return a;
    }else{
      return gcd(b,a%b);
    }
  }
}

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

int main(){
  int a, b, sum=0;
  string n;
  cin >> a >> b;
  
  for(int i=a; i <= b; i++){
    n = to_string(i);
    if((n[0] == n[4]) && (n[1] == n[3])) sum++;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3668
def Solve(graph):
    one = 0
    two = 0
    for i in graph:
        if len(graph[i]) == 1:
            one += 1
        elif len(graph[i]) == 2:
            two += 1

    if one == two:
        return 'YES'
    return 'NO'
        

def main():
    graph = {}
    for i in range(1,5):
        graph[i] = []
        
    a1,b1 = map(int,input().split())
    a2,b2 = map(int,input().split())
    a3,b3 = map(int,input().split())

    graph[a1].append(b1)
    graph[b1].append(a1)
    graph[a2].append(b2)
    graph[b2].append(a2)
    graph[a3].append(b3)
    graph[b3].append(a3)

    print (Solve(graph))

main()


Measured memory_bytes: 3064