akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[26];
        while(sc.hasNextLine()) {
            char[] c = sc.nextLine().toCharArray();
            for (int i = 0, l = c.length; i < l; ++i) {
                char _c = c[i];
                if (97 <= _c && _c <= 122) ++a[_c - 'a'];
                else if (65 <= _c && _c <= 90) ++a[_c - 'A'];
            }
        }
        for (int i = 0; i < 26; ++i) System.out.printf("%c : %d\n", 'a' + i, a[i]);
    }

}

Measured memory_bytes: 26088
#include<stdio.h>

int main(void){
	int x, a, b, xa, xb;	/*xa,xbは距離*/
	do{
		scanf("%d%d%d", &x, &a, &b);
	}while(x < 1 || x > 1000 || a < 1 || a > 1000 || b < 1 || b > 1000 || x == a || a == b || b == x);

	xa = a - x;
	if (xa < 0)	xa *= -1;
	xb = b - x;
	if (xb < 0)	xb *= -1;

	if (xa < xb)	printf("A\n");
	else	printf("B\n");

	return 0;
}

Measured memory_bytes: 128
#ABC088-B
n = int(input())
a = list(map(int,input().split()))
alice = []
bob = []
a.sort(reverse=True)
for i in range(n):
    if i % 2 == 0:
        alice.append(a[i])
    else:
        bob.append(a[i])
        
print(sum(alice) - sum(bob))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    string N; cin >> N;
    if(N[0]=='7'||N[1]=='7'||N[2]=='7'){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define N 100005
using namespace std;
typedef long long ll;
typedef vector <int> vec;
typedef pair <int,int> Pair;
vec g[N];
bool vis[N];
vec path;
int n,m;
void Init()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
}
void dfs(int k)
{
	for(int i=0;i<g[k].size();i++)
	{
		if(!vis[g[k][i]])
		{
			vis[g[k][i]]=true;
			path.push_back(g[k][i]);
			dfs(g[k][i]);
			return;
		}
	}
}
void Solve()
{
	dfs(1);
	reverse(path.begin(),path.end());
	dfs(g[1][0]);
	reverse(path.begin(),path.end());
}
void Print()
{
	printf("%d\n",path.size());
	for(int i=0;i<path.size();i++)
	{
		printf("%d ",path[i]);
	}
	puts("");
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
	Init();
	Solve();
	Print();
	return 0;
}


Measured memory_bytes: 6904
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mp make_pair
#define all(a) (a).begin(), (a).end()

int main(){
    int n;
    cin >> n;
    ll su =0;
    vector<ll> d(n),c(n);
    ll ans = -1;
    rip(i,n,0){
        cin >> d[i] >> c[i];
        ans += c[i];
        su += d[i] * c[i];
    }
    ans += (su + 8)/9 -1;
    cout << ans << endl;
}

Measured memory_bytes: 3328
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    int n ; 
    cin >> n ;
    map<ll,ll> m ; 
    for(int i=0;i<n;i++){
    	ll x ; 
    	cin >> x ; 
    	m[-x]++;
    }
    ll area = 0 ; 
    ll first = 0 ;
    for(auto &p : m){
    	if ( p.second < 2 ) continue ; 
    	if ( p.second >= 4 ) area = max(area, p.first * p.first );
    	area = max(area,p.first*first);
    	first = p.first ; 
    }
    cout << area << endl;
    return 0 ;
}


Measured memory_bytes: 6528
n,x=map(int,input().split())
A=[0]*51
B=[0]*51
A[0]=1
B[0]=1
i=1
while i<=50:
  A[i]=A[i-1]*2+3
  B[i]=B[i-1]*2+1
  i=i+1
#print(A)
#print(A[50])
#print(B[50])
ans=0
if n>=2:
  for i in range(n-1,0,-1):
    #print(i)
    if x==1 or x==0:
      break
    elif 1<x and x<=1+A[i]:
      x=x-1
    elif x==2+A[i]:
      ans=ans+B[i]+1
      break
    elif 2+A[i]<x and x<A[i+1]:
      ans=ans+B[i]+1
      x=x-A[i]-2
    else:
      ans=ans+2*B[i]+1
      break
    if i==1:
      if x==2:
        ans=ans+1
      elif x==3:
        ans=ans+2
      elif x==4 or x==5:
        ans=ans+3
  print(ans)
else:
  if x==1:
    print(0)
  elif x==2:
    print(1)
  elif x==3:
    print(2)
  elif x==4:
    print(3)
  elif x==5:
    print(3)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <array>

using namespace std;

int main()
{
  array<int, 3> num;
  cin >> num[0] >> num[1] >> num[2];

  sort(num.begin(), num.end());
  if(num[0] == 5 && num[1] == 5 && num[2] == 7){
	cout << "YES" << endl;
  } else {
	cout << "NO" << endl;
  }	
}


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

using namespace std;

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

int main(){
	ll n;
	cin >> n;
	vector<char> v;
	
	while(n>0){
		n--;
		char c;
		
		c = 'a' + (n % 26);
		v.push_back(c);
		n/=26;
	}
	for(int i=v.size()-1;i>=0;i--){
		cout << v[i];
	}
	cout << endl;
		
	return 0;
}

Measured memory_bytes: 3628
/*
17D8101013F 森田　匡博
ID:key4 使用言語:C
*/

#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

struct node {
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key) {
}

void init() {
  nil = malloc(sizeof(struct node));
  nil->next = nil; //最初の次を初期化
  nil->prev = nil; //最初の前を初期化
}

void printList() {
  NodePointer cur = nil->next;
  int isf = 1;
  while(1) {
    if(cur == nil) {
      break; //一番最後になったらbreak
    }
    if(isf == 0) {
      printf(" ");
    }
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t) {
  NodePointer pre = t->prev, nex = t->next;
  pre->next = nex;
  nex->prev = pre;
  free(t);
}

void deleteFirst() {
  NodePointer t = nil->next;
  if(t == nil) {
    return;
  }
  deleteNode(t);
}

void deleteLast() {
  NodePointer t = nil->prev;
  nil->prev = t->prev;
  deleteNode(t);
}

void delete(int key) {
  NodePointer t = nil->next;
  while(1) {
    if(t == nil) {
      break;
    }
    if(t->key == (unsigned int)key) {
      deleteNode(t);
      break;
    }
    t = t->next;
  }
}

void insert(int key) {
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->prev = nil;
  x->next = nil->next;
  x->next->prev = x;
  nil->next = x;
  if(nil->prev == nil) {
    nil->prev = x;
  }
}
  

int main()
{
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for(i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if(com[0] == 'i') {
      insert(key);
      np++;
      size++;
    }
    else if(com[0] == 'd') {
      if(strlen(com) > 6) {
	if(com[6] == 'F') {
	  deleteFirst();
	}
	else if(com[6] == 'L') {
	  deleteLast();
	}
      }
      else{
	delete(key);
	nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32944
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 5e2 + 5;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};

int n;
int a[MAXN][MAXN], f[MAXN][MAXN];

void dfs(int x,int y)
{
	for(int k=0; k<4; ++k)
	{
		int xx=x+dx[k], yy=y+dy[k];
		if(xx<1||xx>n || yy<1||yy>n) continue;
		if(f[xx][yy] > f[x][y] + a[xx][yy])
			f[xx][yy] = f[x][y] + a[xx][yy],
			dfs(xx,yy);
	}
}

int main(void)
{
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j)
			a[i][j] = 1,
			f[i][j] = min(min(i,j), min(n-i+1,n-j+1));
	
	int tot = n*n, ans=0;
	for(int i=1; i<=tot; ++i)
	{
		int p;
		scanf("%d",&p);
		int x = (p-1)/n + 1;
		int y = (p-1)%n + 1;
		
		a[x][y]=0;
		--f[x][y];
		dfs(x,y);
		
		ans += f[x][y];
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 23032
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 500
using namespace std;

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

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

multiset< int > graph[MAX_N];

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

  int n, m, q;
  cin >> n >> m >> q;
  int l[m], r[m];
  for(int i = 0; i < m; i++){
    cin >> l[i] >> r[i];
    --l[i]; --r[i];
  }
  int p1[q], p2[q];
  for(int i = 0; i < q; i++){
    cin >> p1[i] >> p2[i];
    --p1[i];  --p2[i];
  }

  for(int i = 0; i < m; i++){
    graph[l[i]].insert(r[i]);
  }

  int dp[MAX_N][MAX_N];
  for(int i = 0; i < MAX_N; i++){
    fill(dp[i], dp[i] + MAX_N, 0);
  }

  for(int i = 0; i < n; i++){
    dp[i][i] = graph[i].count(i);
  }

  for(int d = 1; d < n; d++){
    for(int i = 0; i + d < n; i++){
      int j = i + d;
      dp[i][j] = dp[i + 1][j] +
        distance(graph[i].begin(),
            graph[i].upper_bound(j));
    }
  }

  string buf;
  for(int i = 0; i < q; i++){
    buf += to_string(dp[p1[i]][p2[i]]) + "\n";
  }

  cout << buf;

  return 0;
}


Measured memory_bytes: 14456
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
#include <thread>
#include <chrono>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vl ans(N);
    rep(i, N){
        ll a; cin >> a; a--;
        ans[a] = i+1;
    }
    rep(i, N) cout << ans[i] << " ";
    cout << endstr;
    return 0;
}


Measured memory_bytes: 1664
/**
 *	Author: houtaru
 *	Create: 27.05.2018 20:27:46
 */

#include <bits/stdc++.h>
using namespace std;

const int maxn = 3e5 + 10;

int n;
char s[maxn];
int f[maxn][2];

int main() {
    while (~scanf("%d", &n)) {
        scanf("%s", s);
        memset(f, 0, sizeof f);
        for (int i = 1; i <= n; ++i) {
            if (i) f[i][0] += f[i - 1][0], f[i][1] += f[i - 1][1];
            f[i][s[i - 1] == 'W']++;
        }
        int answer = 1e9 + 7;
        for (int i = 1; i <= n; ++i) {
            answer = min(answer, f[i - 1][1] + f[n][0] - f[i][0]);
        }
        cout << answer << "\n";
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N*3+1);
    rep(i, N*3) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    ll ans=0, cnt=0;
    rep(i, N*3-cnt) {
        ans += a[++i];
        ++cnt;
    }
    cout << ans << endl;
}


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

using namespace std;

inline int read()
{
	int f = 1,x = 0;
	char ch;
	do
	{
		ch = getchar();
		if(ch == '-') f = -1;
	}while(ch < '0'||ch > '9');
	do
	{
		x = (x<<3) + (x<<1) + ch - '0';
		ch = getchar();
	}while(ch >= '0'&&ch <= '9');
	return f*x;
} 

const int MAXN = 2000 + 10;

int n,k;
int u[MAXN],v[MAXN];
vector<int>G[MAXN];
int dep[MAXN];
int ans,cnt;

inline void dfs(int x,int f)
{
	for(int i=0;i<G[x].size();i++)
	{
		int v = G[x][i];
		if(v == f) continue;
		dep[v] = dep[x] + 1;
		dfs(v,x);
	}
}

int main()
{
	n = read(),k = read();ans = 1<<30;
	for(int i=1;i<n;i++)
	{
		int a = read(),b = read();
		G[a].push_back(b);
		G[b].push_back(a);
		u[i] = a;v[i] = b;
	}
	if(k&1)
	{
		for(int i=1;i<n;i++)
		{
			memset(dep,0,sizeof(dep));
		    cnt = 0;
			dfs(u[i],v[i]);
			dfs(v[i],u[i]);
			for(int j=1;j<=n;j++) if(dep[j]>(k-1)/2) cnt++;	
			ans = min(ans ,cnt);
		}

	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			cnt = 0;
			memset(dep,0,sizeof(dep));
			dfs(i,0);
			for(int j=1;j<=n;j++)
			{
				if(dep[j]>(k/2)) cnt++;
			} 
			ans = min(ans , cnt);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

using R = long double;
constexpr R pi = acos((R)-1), eps = 1e-10;

int sgn(R a) { return (a > eps) - (a < -eps); }
int sgn(R a, R b) { return sgn(a - b); }
using P = complex<R>;
istream& operator>>(istream& i, P& p) { R x, y; i >> x >> y; p = P(x, y); return i; }
ostream& operator<<(ostream& o, P p) { return o << fixed << setprecision(15) << real(p) << ' ' << imag(p); }
bool cmp(P p, P q) { return 2 * sgn(real(p), real(q)) + sgn(imag(p), imag(q)) < 0; }
bool eql(P p, P q) { return !cmp(p, q) and !cmp(q, p); }
R dot(P p, P q) { return real(conj(p) * q); }
R crs(P p, P q) { return imag(conj(p) * q); }
// -2: back, -1: cw, 0: on, 1: ccw, 2: front
int ccw(P p, P q) {
  int s = sgn(crs(p, q));
  if (s) return s;
  if (dot(p, q) < 0) return -2;
  if (dot(p, q - p) > 0) return 2;
  return 0;
}
int ccw(P o, P p, P q) { return ccw(p - o, q - o); }
struct L {
  P s, t;
  P vec() const { return t - s; }
  R abs() const { return std::abs(vec()); }
  R arg() const { return std::arg(vec()); }
};
int ccw(L s, P p) { return ccw(s.s, s.t, p); }

P proj(P p, L l) {
  P e = l.vec() / l.abs();
  return l.s + dot(p - l.s, e) * e;
}
P refl(P p, L l) { return (R)2 * proj(p, l) - p; }
R distPP(P p, P q) { return abs(q - p); }
R distPL(P p, L l) { return distPP(p, proj(p, l)); }
R distPS(P p, L s) {
  P q = proj(p, s);
  if (!ccw(s, q)) return distPP(p, q);
  return min(distPP(p, s.s), distPP(p, s.t));
}
R distLL(L l, L m) {
  if (sgn(crs(l.vec(), m.vec()))) return 0;
  return distPL(l.s, m);
}
R distLS(L l, L s) {
  if (ccw(l, s.s) * ccw(l, s.t) != 1) return 0;
  return min(distPL(s.s, l), distPL(s.t, l));
}
R distSS(L s, L t) {
  if (ccw(s, t.s) * ccw(s, t.t) <= 0 and ccw(t, s.s) * ccw(t, s.t) <= 0) return 0;
  return min({distPS(s.s, t), distPS(s.t, t), distPS(t.s, s), distPS(t.t, s)});
}
P intxn(L l, L m) {
  assert(sgn(crs(l.vec(), m.vec())));
  return l.s + crs(m.s - l.s, m.vec()) / crs(l.vec(), m.vec()) * l.vec();
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  R r, th; cin >> r >> th, th *= pi / 180;
  V<P> p(n); for (auto&& e : p) cin >> e;
  VV< V<> > ks(20, VV<>(20));
  VV<R> d(20, V<R>(20));
  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (j != i) {
    for (int k = 0; k < n; ++k) if (k != j) {
      L s{p[i], p[j]}, t{p[j], p[k]};
      R ph = fmod(3 * pi + t.arg() - s.arg(), 2 * pi) - pi;
      if (sgn(abs(ph), th) <= 0) ks[i][j].push_back(k);
    }
    d[i][j] = distPP(p[i], p[j]);
  }
  VV<R> dp(20, V<R>(20, 1e10));
  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (j != i) {
    dp[i][j] = d[i][j];
  }
  int res = 0;
  for (int s = 0; s <= 1e4; ++s) {
    VV<R> ndp(20, V<R>(20, 1e10));
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (j != i) {
      if (!i and sgn(dp[i][j], r) <= 0) res = s + 1;
      for (int k : ks[i][j]) {
        ndp[i][j] = min(ndp[i][j], d[i][j] + dp[j][k]);
      }
    }
    swap(dp, ndp);
  }
  cout << res << '\n';
}


Measured memory_bytes: 3416
#include <bits/stdc++.h>
#define sort stable_sort
using namespace std; 

const long long INF=1LL << 62; 
 
int _;

int n,k,p[100050],c[100050],cnt;
long long ans=-INF,n_maxn,t_maxn,sum,maxn;
bool vis[100050];

inline void init()
{
	sum=0;
	maxn=-INF;
}

long long dfs(int x)
{
	if(vis[x])
		return 0;
	cnt++;
	vis[x]=true;
	sum=dfs(p[x]);
	vis[x]=false;
	return sum+c[x];
}
 
void rdfs(int x,int depth)
{
	if(vis[x] || depth == 0)
		return;
	vis[x]=true;
	sum += c[x];
	maxn=max(maxn,sum);
	rdfs(p[x],depth-1);
	vis[x]=false;
	return;
}
 
int main()
{	
	//for(scanf("%d",&_);_;_--)	
	scanf("%d%d",&n,&k);
	for(int i=1;i <= n;i++)
		scanf("%d",p+i);
	for(int i=1;i <= n;i++)
		scanf("%d",c+i);
	for(int i=1;i <= n;i++)
	{
		cnt=sum=0;
		long long x=dfs(i),t=k%cnt;
		init();
		rdfs(p[i],n);
		n_maxn=maxn;
		init();
		rdfs(p[i],t);
		t_maxn=maxn;
		if(x <= 0)
			ans=max(n_maxn,ans);
		else
			ans=max(max(x*(k/cnt)+t_maxn,x*(k/cnt-1)+n_maxn),ans); 
	} 
	printf("%lld\n",ans); 
	return 0;
}               


Measured memory_bytes: 3976
#include<stdio.h>

int main(){

int a,b,c,k,m,n;

scanf("%d""%d""%d""%d",&a,&b,&c,&k);

if(a >= k){
  printf("%d\n",k);
}else if(a < k){
  m = k - a;
  if(b >= m){
    printf("%d\n",a);
  }else if(b < m){
  n = m - b;
  printf("%d\n",a-n);
  }
}

return 0;
}

Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class76
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            long[] st = new long[N];
            long[] ed = new long[N];
            for(int i = 0; i < N; i++)
            {
                var XL = Console.ReadLine().Split().Select(long.Parse).ToArray();
                st[i] = XL[0] - XL[1];
                ed[i] = XL[0] + XL[1];
            }
            Array.Sort(ed, st);
            long l = long.MinValue;
            int count = 0;

            for(int i = 0; i < N; i++)
            {
                if (l <= st[i])
                {
                    count++;
                    l = ed[i];
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

int main() {
  int n;
vector<int> q,p,r;

for(int i=2;i<=300000;i++) 
if(i%7==1 || i%7==6) p.push_back(i);

while(1){
  cin>>n;
  if(n==1) break;
  
  for(int i=0;i<p.size();i++) if(n%p[i]==0) q.push_back(p[i]);
  
  for(int i=0;i<q.size();i++)
  for(int j=0;j<p.size();j++){
  if(q[i]%p[j]!=0 && j==p.size()-
  1) r.push_back(q[i]);
else if(q[i]!=p[j] && q[i]%p[j]==0)break;
}
cout<<n<<":";
for (int i=0;i<r.size();i++) cout<<" "<<r[i];
cout<<endl;
q.clear(),r.clear();
}
return 0;
}

Measured memory_bytes: 1592
#include <stdio.h>

int main() {
  int red_ball, green_ball, blue_ball, number, count = 0, i, j, temp_red, temp_green;
  scanf("%d %d %d %d", &red_ball, &green_ball, &blue_ball, &number);
  for(i = 0; (i * red_ball) <= number; i++) {
    temp_red = i * red_ball;
    for(j = 0; (temp_red + (j * green_ball)) <= number; j++) {
      temp_green = j * green_ball;
      if((number - (temp_red + temp_green)) % blue_ball == 0) {
        count++;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
mod = 10**9+7
from collections import defaultdict
dp = defaultdict(lambda:defaultdict(lambda:0))
def possible(last4):
    if 'AGC' in last4:
        return False
    for i in range(3):
        s = list(last4)
        s[i],s[i+1] = s[i+1],s[i]
        if 'AGC' in ''.join(s):
            return False
    return True
S = []
for s1 in 'AGCT':
    for s2 in 'AGCT':
        for s3 in 'AGCT':
            s = s1+s2+s3
            S.append(s)
for s in S:
    if s not in ['AGC','GAC','ACG']:
        dp[3][s] = 1

for n in range(3,N+3):
    for last in 'AGCT':
        for last3 in S:
            last4 = last3+last
            if possible(last4):
                dp[n+1][last4[1:]] += dp[n][last3]
                dp[n+1][last4[1:]] %= mod
print(dp[N+3]['TTT'])

Measured memory_bytes: 4200
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        a: i64, b: i64, c: i64,
        k: i64,
    }
    let mut t = 0;
    let mut b = b;
    let mut c = c;
    while a >= b {
        b *= 2;
        t += 1;
    }
    while b >= c {
        c *= 2;
        t += 1;
    }
    puts!("{}\n", if t <= k { "Yes" } else { "No" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 2276
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long int 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define from(i,n)       for(int i=0;i<(int)n;i++)
#define from_j(i,j,n)   for(int i=j;i<(int)n;i++)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
 
int32_t main()
{
    c_p_c();
    int n; cin>>n;
    int arr[n]; from(i,n)cin>>arr[i];
    int cost[n]; cost[0]=0; cost[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++){
        cost[i] = min(cost[i-1]+abs(arr[i]-arr[i-1]),cost[i-2]+abs(arr[i]-arr[i-2])); 
    }
    cout<<cost[n-1];
    return 0;
}

Measured memory_bytes: 1792
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,k,S=get_i
ans=[]
N.times do|i|
  if k>0
      ans.push(S)
  else
      if S==10**9
          ans.push(1)
      else
          ans.push(S+1)
      end
  end
  k-=1
end
puts ans.join(" ")

Measured memory_bytes: 4860
s=gets.chomp

if s=='SSS'
  p 0
elsif s=='SSR'
  p 1
elsif s=='SRS'
  p 1
elsif s=='SRR'
  p 2
elsif s=='RSS'
  p 1
elsif s=='RSR'
  p 1
elsif s=='RRS'
  p 2
elsif s=='RRR'
  p 3
end

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

int main( int argc, char *argv[] )
{
char c;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

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

	return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int W, H, x, y, r;
		
		W = scan.nextInt();
		H = scan.nextInt();
		x = scan.nextInt();
		y = scan.nextInt();
		r = scan.nextInt();
		
		if((y + r) <= H && (x + r) <= W && (y - r) >= 0 && (x - r) >= 0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	
	}

}

Measured memory_bytes: 26256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int r[8];
int c[8];
string grid[8];
bool can_use[8][8][8];

bool f(int depth){
  /*
  cout << depth << endl;
  for(int i = 0; i < 8; i++){
    cout << grid[i] << endl;
  } */
  if(depth == 0){
    return true;
  }
  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 8; j++){
      can_use[depth][i][j] = true;
    }
  }
  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 8; j++){
      if(grid[i][j] == 'Q'){
        for(int k = 0; i + k < 8; k++){
          can_use[depth][i + k][j] = false;
        }
        for(int k = 0; i - k >= 0; k++){
          can_use[depth][i - k][j] = false;
        }
        for(int k = 0; j + k < 8; k++){
          can_use[depth][i][j + k] = false;
        }
        for(int k = 0; j - k >= 0; k++){
          can_use[depth][i][j - k] = false;
        }
        for(int k = 0; (i + k < 8 && j + k < 8); k++){
          can_use[depth][i + k][j + k] = false;
        }
        for(int k = 0; (i + k < 8 && j - k >= 0); k++){
          can_use[depth][i + k][j - k] = false;
        }
        for(int k = 0; (i - k >= 0 && j + k < 8); k++){
          can_use[depth][i - k][j + k] = false;
        }
        for(int k = 0; (i - k >= 0 && j - k >= 0); k++){
          can_use[depth][i - k][j - k] = false;
        }
      }
    }
  }

  /*
  cout << depth << endl;
  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 8; j++){
      cout << can_use[depth][i][j];
    }
    cout << endl;
  }
  */

  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 8; j++){
      if(can_use[depth][i][j]){
        grid[i][j] = 'Q';
        if(f(depth - 1)){
          return true;
        }
        grid[i][j] = '.';
      }
    }
  }
  return false;
}
int main(void){
  int k;
  cin >> k;
  for(int i = 0; i < k; i++){
    cin >> r[i] >> c[i];
  }

  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 8; j++){
      grid[i].push_back('.');
    }
  }
  for(int i = 0; i < k; i++){
    grid[r[i]][c[i]] = 'Q';
  }
  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 8; j++){
      for(int k = 0; k < 8; k++){
        can_use[i][j][k] = true;
      }
    }
  }

  f(8 - k);
  for(int i = 0; i < 8; i++){
    cout << grid[i] << endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;


string s, t;
int dp[3010][3010];

int f(int i, int j)
{
    if (i == s.size() || j == t.size()) return 0;
    int &ret = dp[i][j];
    if (~ret) return ret;
    if (s[i] == t[j])
        ret = f(i+1, j+1) + 1;
    ret = max(ret, f(i+1, j));
    ret = max(ret, f(i, j+1));
    return ret;
}
void print(int i, int j)
{
    if (i == s.size() || j == t.size()) return ;
    if (s[i] == t[j] && f(i+1, j+1) + 1 == dp[i][j])
    {
        cout << s[i] ;
        print(i+1, j+1);
        return;
    }
    if (f(i+1, j) == dp[i][j])
    {
        print(i+1, j);
        return;
    }
    print(i, j+1);
}
int main()
{
    memset(dp, -1, sizeof dp);

    cin >> s >> t;

    f(0, 0);
    print(0, 0);
    cout << "\n";

    return 0;
}


Measured memory_bytes: 36096
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
W=[0]*N
ans = 1
for i in range(N):
    W[i] = input()
    if ans == 1 and i != 0 and W[i-1][-1] != W[i][0]:
        ans = 0

if ans == 1 and len(set(W)) != N:
    ans = 0

yn(ans)


Measured memory_bytes: 3064
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N,M = map(int,readline().split())
k = 2**N
dp = [INF]*k 
dp[0] = 0

for i in range(M):
    a,b = map(int,readline().split())
    c = list(map(int,readline().split()))
    d = sum(1<<(ci-1) for ci in c)
    dpnew = dp[:]
    for j in range(k):
        dpnew[j|d] = min(dp[j]+a,dpnew[j|d])
    dp = dpnew

print(dp[2**N-1] if dp[2**N-1] != INF else -1)




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

using namespace std;

int main(){
    int N,M;
    vector<int> HH,WW;
    while(cin >>N>>M,N|M){
        int H[N+1]; H[0]=0;
        for(int i=1;i<=N;i++){
            cin >> H[i];
            H[i]+=H[i-1];
        }
        HH.clear();
        for(int i=0;i<=N;i++){
            for(int j=i+1;j<=N;j++){
                HH.push_back(H[j]-H[i]);
            }
        }
        int W[M+1]; W[0]=0;
        for(int i=1;i<=M;i++){
            cin >> W[i];
            W[i]+=W[i-1];
        }
        WW.clear();
        for(int i=0;i<=M;i++){
            for(int j=i+1;j<=M;j++){
                WW.push_back(W[j]-W[i]);
            }
        }
        sort(HH.begin(),HH.end());
        sort(WW.begin(),WW.end());
        int c=0;
        for(auto&h:HH){
            auto lo=lower_bound(WW.begin(),WW.end(),h);
            auto up=upper_bound(WW.begin(),WW.end(),h);
            for(auto i=lo;i!=up;++i){
                if(h==*i)c++;
            }
        }
        cout << c << endl;
    }
}

Measured memory_bytes: 15724
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto n = readln.chomp.to!int;
    int[][] G;
    G.length = n;
    foreach (i; 0..n) {
        auto ukv = readln.split.to!(int[]);
        if (ukv[1] > 0) foreach (j; ukv[2..$]) G[i] ~= j-1;
    }

    auto ds = new int[](n);
    auto fs = new int[](n);
    int go(int i, int t) {
        ds[i] = t;
        foreach (j; G[i]) if (ds[j] == 0) t = go(j, t+1);
        fs[i] = t+1;
        return t+1;
    }
    int t = 1;
    foreach (i; 0..n) if (ds[i] == 0) t = go(i, t) + 1;
    foreach (i; 0..n) {
        writefln("%d %d %d", i+1, ds[i], fs[i]);
    }
}


Measured memory_bytes: 2504
import Data.Complex
import Control.Applicative
import Data.List.Split
import Text.Printf
main ::IO()
main = do
  v <- map (map read . splitOn ",") . lines <$> getContents
  mapM_ ((\x->putStrLn $ printf "%.5f" (fst x) ++ " " ++ printf "%.5f" (snd x)) . solve ) v

solve :: [Double] -> (Double,Double)
solve (x1:y1:x2:y2:xq:yq:_)
  | x1==x2 = (2*x1-xq, yq)       -- parallel to y axis
  | otherwise = (realPart zq,imagPart zq)   
  where
    m  = (y2-y1)/(x2-x1)             -- y = mx + n
    n  = (x2*y1-x1*y2)/(x2-x1)
    d  = (yq - m*xq - n) / sqrt(1+m^2) --signed distant from Q to P1-p2
    zv = m :+ (-1)                  -- vector perpendicular to P1-P2
    ze = zv / (magnitude zv :+ 0)   -- make it a unit one
    zq = (xq :+ yq) + 2*ze*(d :+ 0) -- twice the distant from Q

Measured memory_bytes: 4532
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
	int N,K;
	scanf("%d%d",&N,&K);
	int x[2][50],y[2][50],z[2][50];
	vector<int> dx,dy,dz;
	for(int i=0;i<N;i++){
		scanf("%d%d%d%d%d%d",&x[0][i],&y[0][i],&z[0][i],&x[1][i],&y[1][i],&z[1][i]);
		dx.push_back(x[0][i]); dx.push_back(x[1][i]);
		dy.push_back(y[0][i]); dy.push_back(y[1][i]);
		dz.push_back(z[0][i]); dz.push_back(z[1][i]);
	}
	sort(dx.begin(),dx.end());sort(dy.begin(),dy.end());sort(dz.begin(),dz.end());
	dx.erase(unique(dx.begin(),dx.end()),dx.end());
	dy.erase(unique(dy.begin(),dy.end()),dy.end());
	dz.erase(unique(dz.begin(),dz.end()),dz.end());
	int d[dx.size()-1][dy.size()-1][dz.size()-1];
	for(int i=0;i<dx.size()-1;i++) for(int j=0;j<dy.size()-1;j++) for(int k=0;k<dz.size()-1;k++) d[i][j][k]=0;
	for(int s=0;s<N;s++) for(int i=0;i<dx.size()-1;i++) for(int j=0;j<dy.size()-1;j++) for(int k=0;k<dz.size()-1;k++)
		if(x[0][s]<=dx[i]&&dx[i+1]<=x[1][s]) if(y[0][s]<=dy[j]&&dy[j+1]<=y[1][s]) if(z[0][s]<=dz[k]&&dz[k+1]<=z[1][s])
			d[i][j][k]++;
	ll res=0;
	for(int i=0;i<dx.size()-1;i++) for(int j=0;j<dy.size()-1;j++) for(int k=0;k<dz.size()-1;k++)
		if(d[i][j][k]>=K) res+=(ll)(dx[i+1]-dx[i])*(dy[j+1]-dy[j])*(dz[k+1]-dz[k]);
	printf("%lld\n",res);
}

Measured memory_bytes: 5004
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 12:04:27 2020

@author: shinba
"""

n,k = map(int,input().split())

ans = 0

for i in range(1,n+1):
    cnt = 0
    while i < k:
        i *= 2
        cnt += 1
    ans += (0.5)**cnt/n

print(ans)

Measured memory_bytes: 2940
def read():
    return int(input())

def reads():
    return list(map(int, input().split()))

n,m = reads()
a = []
r = []
for i in range(n):
    a.append(reads())
for i in range(n):
    for j in range(1,a[i][0]+1):
        r.append(a[i][j])
ans = 0
for i in set(r):
    if r.count(i) == n:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){

int n;

int x;

int num;

int min=1000001;

int max=-1000001;

long total=0;




scanf("%d",&n);

for(x=0;x<n;x++){

scanf("%d",&num);

if(min>num)min=num;

if(max<num)max=num;

total+=num;

}

printf("%d %d %ld\n",min,max,total);

return 0;

}

Measured memory_bytes: 600
using System;

namespace ARC070
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());

            for (var i = 1;; i++)
            {
                if (i * (i + 1) / 2 >= X)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>
#include<cstdint>
#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int gcd(int a,int b){
    int r;
    if(a<b) swap(a,b);
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int atcoder(){
    int n,ans=0;
    cin>>n;
    Vi a(n),b(n),c(n);
    REP(i,0,n) cin>>a[i];
    REP(i,0,n){
        if(i==0){b[i]=a[i];continue;}
        b[i]=gcd(b[i-1],a[i]);
    }
    for(int i=n-1; i>=0; i--){
        if(i==n-1){c[i]=a[i];continue;}
        c[i]=gcd(c[i+1],a[i]);
    }
    REP(i,1,n-1){
        int tmp=gcd(b[i-1],c[i+1]);
        chmax(ans,tmp);
    }
    chmax(ans,b[n-2]);
    chmax(ans,c[1]);
    cout<<ans<<ENT;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  int B[100];
  cin >> N;
  REP(i, N - 1) { cin >> B[i]; }

  int ans = B[0];
  for (int i = 1; i < N - 1; ++i) {
    ans += min(B[i], B[i - 1]);
  }
  ans += B[N - 2];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n){
		cin>>a[i];
	}
	ll ans=0;
	map<ll,ll> mp;
	mp[0+a[0]]++;
	FOR(j,1,n){
		ans+=mp[j-a[j]];
		mp[j+a[j]]++;
	}
	cout<<ans<<endl;
}

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

int main() {
  string S;
  cin >> S;
  int count = 0;
  if ( S.at(0) == S.at(1) ) {
    count++;
  }
  if (S.at(0) == S.at(2) ) {
    count++;
  }
  if (S.at(0) == S.at(3) ) {
    count++;
  }
  if (S.at(1) == S.at(2) ) {
    count++;
  }
  if (S.at(1) == S.at(3) ) {
    count++;
  }
  if (S.at(2) == S.at(3) ) {
    count++;
  }
  if ( count == 2 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
def matrixMultiplication(n, m, l, A, B):
	result = list()
	for i in range(n):
		temp = list()
		for j in range(l):
			temp2 = list()
			for k in range(m):
				temp2.append(A[i][k] * B[k][j])
			temp.append(sum(temp2))
		result.append(temp)
	return result

nml = [int(x) for x in input().split()]
A = list()
for i in range(nml[0]):
	A.append([int(x) for x in input().split()])
B = list()
for i in range(nml[1]):
	B.append([int(x) for x in input().split()])

C = matrixMultiplication(nml[0], nml[1], nml[2], A, B)
for i in range(len(C)):
	for j in range(len(C[i])):
		print(C[i][j], end=' ' if j < len(C[i]) - 1 else '\n')


Measured memory_bytes: 6984
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

X, A = l_inpl()

if X < A:
    print("0")
else:
    print("10")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()

vector<double> x, y, z, r;

double getdist(int a, int b) {
	double dx = x[a] - x[b];
    double dy = y[a] - y[b];
    double dz = z[a] - z[b];
	double d = sqrt(dx * dx + dy * dy + dz * dz);
	return max(d - (r[a] + r[b]), 0.);
}

double prim(int n) {
    using P = pair<double, int>;
    
    double res = 0.;
    vector<bool> used(n, false);
    // P -> first : コスト, second : 行先
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0., 0);
    // コストが小さい順に出しいく
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        if(used[p.second]){
            continue;
        }
        int pos = p.second;
        used[pos] = true;
        res += p.first;
        for(int i = 0; i < n; ++i){
            if(!used[i] && i != pos){
                que.emplace(getdist(pos, i), i);
            }
        }
    }
    return res;
}

signed main() {

    int n;
    while(true){
        cin >> n;
        if(n == 0){
            break;
        }
        x.resize(n); 
        y.resize(n);
        z.resize(n);
        r.resize(n);
        rep(i, n){
            cin >> x[i] >> y[i] >> z[i] >> r[i];
        }
        cout << fixed << setprecision(3) << prim(n) << endl;
    }
    return 0;
}



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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
    int a[5];
    rep(i,5){
        cin>>a[i];
        if(a[i]==0)cout<<i+1<<endl;
    }
	return 0;
}

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

row_1 = list(map(int, input().split()))
row_2 = list(map(int, input().split()))

row_1_cumsum = [0] + [sum(row_1[:i + 1]) for i in range(N)]
row_2_cumsum = [0] + [sum(row_2[:i + 1]) for i in range(N)]

v_list = []
r2_max = row_2_cumsum[-1]

for i in range(1, N+1):
    v_list.append(row_1_cumsum[i] - row_2_cumsum[i-1] + r2_max)

print(max(v_list))


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

using namespace std;

int nr, N, D1, D2, cod[609][609], x[609 * 609], y[609 * 609], c[2][609 * 609], sqr[609 * 609];
vector < int > v[2][609 * 609], h[4];

void add (int line, int i, int j)
{
    v[line][i].push_back (j);
    v[line][j].push_back (i);
}

void dfs (int lin, int nod, int col)
{
    if (c[lin][nod] != 0)
        return ;
    c[lin][nod] = col;
    for (auto it : v[lin][nod])
        dfs (lin, it, 3 - col);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d", &N, &D1, &D2);
for (int i=0; i<2 * N; i++)
    sqr[i * i] = i + 1;
vector < pair < int, int > > dlt[2];
for (int dx=0; dx<2 * N; dx++)
{
    if (dx * dx <= D1 && sqr[D1 - dx * dx] > 0)
    {
        int dy = sqr[D1 - dx * dx] - 1;
        dlt[0].push_back ({dx, dy});
    }
    if (dx * dx <= D2 && sqr[D2 - dx * dx] > 0)
    {
        int dy = sqr[D2 - dx * dx] - 1;
        dlt[1].push_back ({dx, dy});
    }
}
for (int i=0; i<2 * N; i++)
    for (int j=0; j<2 * N; j++)
        cod[i][j] = ++nr,
        x[nr] = i, y[nr] = j;
for (int i=0; i<2 * N; i++)
    for (int j=0; j<2 * N; j++)
    {
        for (int k=0; k<2; k++)
            for (auto d : dlt[k])
            {
                if (i >= d.first && j >= d.second)
                    add (k, cod[i][j], cod[i - d.first][j - d.second]);
                if (i >= d.first && j + d.second < 2 * N)
                    add (k, cod[i][j], cod[i - d.first][j + d.second]);
            }
    }
for (int i=0; i<2; i++)
    for (int j=1; j<=nr; j++)
        if (c[i][j] == 0)
            dfs (i, j, 1);
for (int i=1; i<=nr; i++)
    h[(c[0][i] - 1) * 2 + c[1][i] - 1].push_back (i);
int lin = -1;
for (int i=0; i<4; i++)
    if (h[i].size () >= N * N)
        lin = i;
int sz = 0;
for (auto it : h[lin])
    if (++sz <= N * N)
        printf ("%d %d\n", x[it], y[it]);
return 0;
}


Measured memory_bytes: 121528