akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;
int table[10][10];

int check(int a, int b, int c, int d, int e){
    int ret = 0;
    ret = table[ret][a];
    ret = table[ret][b];
    ret = table[ret][c];
    ret = table[ret][d];
    ret = table[ret][e];
    return ret;
}

int f(int a, int b, int c, int d, int e){
    int ret = 0;

    // 桁を入れ替える
    for(int i = 0; i < 10; i++) if(i != a) if(check(i, b, c, d, e) == 0) return -1;
    for(int i = 0; i < 10; i++) if(i != b) if(check(a, i, c, d, e) == 0) return -1;
    for(int i = 0; i < 10; i++) if(i != c) if(check(a, b, i, d, e) == 0) return -1;
    for(int i = 0; i < 10; i++) if(i != d) if(check(a, b, c, i, e) == 0) return -1;
    for(int i = 0; i < 10; i++) if(i != e) if(check(a, b, c, d, i) == 0) return -1;

    if(a != b) if(check(b, a, c, d, e) == 0) return -1;
    if(b != c) if(check(a, c, b, d, e) == 0) return -1;
    if(c != d) if(check(a, b, d, c, e) == 0) return -1;
    if(d != e) if(check(a, b, c, e, d) == 0) return -1;
    return 0;
}

signed main(){
    
    for(int i = 0; i < 10; i++) for(int j = 0; j < 10; j++) cin >> table[i][j];

    int ans = 0;
    for(int a = 0; a < 10; a++) for(int b = 0; b < 10; b++) for(int c = 0; c < 10; c++) for(int d = 0; d < 10; d++)
    {
        int e = table[0][a];
        e = table[e][b];
        e = table[e][c];
        e = table[e][d];
        
        if(f(a, b, c, d, e) == -1) ans++;

    }
    
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 3112
#include <stdio.h>

int main(){
	int a,b;
	scanf("%d%d", &a,&b);
	printf("a ");
	if (a > b){
		printf(">");
	}
	else if (a < b){
		printf("<");
	}
	else if(a = b){
		printf("==");
	}
	printf(" b\n");

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forna(i,a,n) for(int i =a; i < n; i++)
#define fornd(i,a) for (int i = (a)-1; i >= 0; i--)
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) x.begin(), x.end()
typedef long long int unsigned lliu;
typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<vi> vvi;
typedef vector<pi> vpi;

vector<bool> checados;
vi v;

int checaCiclo(int i){
	if(checados[i])
		return i;
	checados[i]=true;
	return checaCiclo(v[i]);
}

int pasosParaElCiclo(int busca, int i){
	if(i==busca)
		return 0;
	else
		return 1 + pasosParaElCiclo(busca, v[i]);
}

int busca(int i, int k){
	if(k)
		return busca(v[i], --k);
	return i;
}

int main(){
	fastIO
	int n;
	lli k;
	cin>>n>>k;
	v.resize(n);
	checados.resize(n, false);
	forn(i, n){
		cin>>v[i];	
		v[i]--;
	}
	int initCiclo = checaCiclo(0);
	int pasosExtras = pasosParaElCiclo(initCiclo, 0);
	int tamCiclo = pasosParaElCiclo(initCiclo, v[initCiclo]);

	if(k<=pasosExtras){
		cout<<busca(0, k)+1<<endl;
		exit(0);
	}
	k-=pasosExtras;
	cout<<busca(initCiclo, k%(tamCiclo+1))+1<<endl;
	

	return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int cnt[200011];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	vector<int> vec(n);
	int cc=0;
	for(int i=0;i<n;i++) 
	{
		cin>>vec[i];
		cnt[vec[i]]++;
		if(cnt[vec[i]]==1) cc++;
	}
	sort(cnt,cnt+200007);
	ll ans=0;
	for(int i=0;i<=200006;i++)
	{
		if(cnt[i]>0&&cc>k)
		{
			ans+=cnt[i];
			cc--;
		}
	}
	cout<<ans<<'\n';
}


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

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define allpt(v) (v).begin(), (v).end()


const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

void showvec(vector<int> v)
{
    rep(i, v.size() - 1)
    {
        cout << v[i] << wsp;
    }
    cout << v[v.size() - 1] << rt;
}

class Unionfind
{
    vector<int> p;
    vector<int> q;

public:
    int find(int x);
    void unite(int x, int y);
    Unionfind(int n);
    vector<int> outputfriends();
};

Unionfind::Unionfind(int n)
{
    for (int i = 0; i < n; i++)
    {
        p.push_back(i);
    }
    q.resize(n);
    fill(q.begin(), q.end(), 1);
}
int Unionfind::find(int x)
{
    while (p[x] != x)
    {
        p[x] = p[p[x]];
        x = p[x];
    }
    return x;
}

void Unionfind::unite(int x, int y)
{
    x = Unionfind::find(x);
    y = Unionfind::find(y);
    if (x != y)
    {
        p[x] = y;
        q[x] += q[y];
        q[y] = q[x];
    }
}

vector<int> Unionfind::outputfriends()
{
    rep(i, q.size())
    {
        int j = Unionfind::find(i);
        q[i] = q[j];
    }
    rep(i, q.size()) q[i]--;
    return q;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, m, k, a, b, c, d;
    cin >> n >> m >> k;

    vector<PII> friends(m);
    Unionfind data(n);
    rep(i, m)
    {
        cin >> a >> b;
        data.unite(a - 1, b - 1);
        friends[i] = make_pair(a - 1, b - 1);
    }

    vector<int> op = data.outputfriends();

    rep(i, m)
    {
        op[friends[i].first]--;
        op[friends[i].second]--;
    }

    rep(i, k)
    {
        cin >> d >> c;
        d--, c--;
        if (data.find(d) == data.find(c))
        {
            op[c]--;
            op[d]--;
        }
    }

    showvec(op);

    return 0;
}


Measured memory_bytes: 3320
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll inf=1e18+9;

/*
ac
２人を同時に探索させる（２人のx+yは同じ）．
始点・終点以外同じ場所を通らなくても最適な経路にできる．
何故１人目を探索させてから２人目を探索させるではいけないのかまだ分からない．
*/

ll h,w,a[210][210],dp[210][210][410],b=0,dx[2]={0,1},dy[2]={1,0};

ll f(ll x1,ll x2,ll sum){//最初の経路
	if(dp[x1][x2][sum]!=-1)return dp[x1][x2][sum];
	ll y1=sum-x1,y2=sum-x2,ans=0;
	rep(i,2){
		rep(j,2){
			if(x1+dx[i]>w-1 || x2+dx[j]>w-1 || y1+dy[i]>h-1 || y2+dy[j]>h-1)continue;
			//行き先が一致しないようにする
			//この方法の都合上，最初と最後だけ場合分けが必要
			if(x1+dx[i]==x2+dx[j] && y1+dy[i]==y2+dy[j])continue;
			ans=max(ans,f(x1+dx[i],x2+dx[j],sum+1));
		}
	}
	return dp[x1][x2][sum]=ans+a[sum-x1][x1]+a[sum-x2][x2];
}

int main(void){
	cin>>h>>w;
	rep(i,h)rep(j,w)cin>>a[i][j];
	rep(i,210)rep(j,210)rep(k,410)dp[i][j][k]=-1;
	cout<<f(1,0,1)+a[0][0]+a[h-1][w-1]<<endl;//最初と最後だけどうしても同じ場所にいなくちゃいけないので，個別に足す
	return 0;
}

Measured memory_bytes: 141824
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
#define mod 1000000007
using namespace std;
using ll=long long int;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vii;
typedef pair<ll ,ll> pii;
bool cool(int a,int b,int c)
{
	if(a==b or a==c or b==c)return false;
	if((a+b>c) and (a+c>b) and (b+c>a))return true;
	return false;
}
void solve()
{
	int ans=0;
	int n;
	cin>>n;
	int arr[n];
	forn(i,n)cin>>arr[i];
	forn(i,n)
	{
		fora(j,i+1,n-1)
		{
			fora(k,j+1,n-1)
			{
				if(cool(arr[i],arr[j],arr[k]))ans++;
			}
		}
	}
	cout<<ans<<endl;
	
}

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
	solve();
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define itn int
#define gI gi
#define int long long

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int sum, cnt;

signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi(), m = n;
	while (m)
	{
		m /= 2;
		++cnt;
	}
	sum = pow(2, cnt - 1) * 2 - 1;
	cout << sum << endl;
	return 0;
}



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

// Shortcut

#define int long long
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << ' ';
#define PrintVl(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << endl;
#define PrintA(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << ' ';
#define PrintAl(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a));
#define mmset(a) memset(a, 0x3f, sizeof(a));
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, inf = 1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b;
    cin >> a >> b;
    if (a >= 13) cout << b;
    else if (a >= 6) cout << b/2;
    else cout << 0;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        foreach (int n in Input().OrderByDescending(x => x).Take(3))
        {
            Console.WriteLine(n);
        }
    }

    static IEnumerable<int> Input()
    {
        for (int i = 0; i < 10; i++)
        {
            yield return int.Parse(Console.ReadLine());
        }
    }
}


Measured memory_bytes: 18456
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
 
		int count = 0;
 
		for (int i = 0; i < s.length() / 2; i++) {
			if (!(s.charAt(i) == s.charAt(s.length() - 1 - i))) {
				count++;
			}
 
		}
		System.out.println(count);
	}
}

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

int main() {
  int N, K; cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> dp(100001, 0);
  for (int i = 1; i <= K; i++) {
    for (int j = 0; j < N; j++) {
      if (i - A.at(j) >= 0 && dp.at(i-A.at(j)) == 0) dp.at(i) = 1;
    }
  }
  if (dp.at(K)) cout << "First" << endl;
  else cout << "Second" << endl;
}

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

int main(){
    string s;
    cin >>s;
    rep(i,s.size()) s[i]='x';
    cout << s <<endl;
    return 0;
}

Measured memory_bytes: 256
Imports System.Collections.Generic

Module Module1
    Sub Main()
        Dim N = Integer.Parse(Console.ReadLine())
        Dim d As Integer
        Dim d1 As New List(Of Integer)
        For i As Integer = 1 To N
            d = Integer.Parse(Console.ReadLine())
            If Not d1.Contains(d) Then d1.Add(d)
        Next
        Console.WriteLine(d1.Count)
    End Sub
End Module


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

#define FOR(i, n) for(i = 0; i < n; ++i)
typedef vector <int> vi;
typedef pair<int, int> iPair;
const int MOD = 1e9+7;

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

    int t = 1;
    int i,j;
    // cin>>t;
    
    while(t--)
    {
        int h, w;
        cin >> h >> w;

        char arr[h][w];
        FOR(i, h)
            FOR(j, w) 
                cin >> arr[i][j];

        int dp[h][w];
        dp[0][0] = 1;
        for(int i = 1; i < w; ++i)
        {
            if(arr[0][i] != '#') dp[0][i] = dp[0][i-1];
            else dp[0][i] = 0;
        }
        for(int i = 1; i < h; ++i)
        {
            if(arr[i][0] != '#') dp[i][0] = dp[i-1][0];
            else dp[i][0] = 0;
        }


        for(int i = 1; i < h; ++i)
        {
            for(int j = 1; j < w; ++j)
            {
                if(arr[i][j] == '#') dp[i][j] = 0;
                else
                {
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;                    
                }
            }
        }


        cout<<dp[h-1][w-1]<<endl;

            //     FOR(i, h){
            // FOR(j, w) 
            //     cout<< dp[i][j]<<" ";
            //     cout<<endl;
            //     }
    }

	return 0;
}


Measured memory_bytes: 9088
N = int(input())
S = [input() for i in range(N)]
from collections import Counter
ctr = Counter(S)
n = ctr.most_common()[0][1]

cands = []
for k in ctr.keys():
    if ctr[k] == n:
        cands.append(k)
cands.sort()
print(*cands, sep='\n')

Measured memory_bytes: 45072
//Atcoder 177A
#include <bits/stdc++.h>
#define endl "\n"
#define int long long 

using namespace std;

int32_t main(){
	int k;
	cin >> k;
	int seven=7;
	for(int i=1;i<=k;i++){
		if(seven%k==0){
			cout << i << endl;
			return 0;
		}
		seven=seven%k;
		seven=seven*10+7;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3600
a, b = map(int, input().split())

a_l = []
b_l = []
for i in range(b):
    a_l.append(str(a))
for i in range(a):
    b_l.append(str(b))

a_b = ''.join(a_l)
b_a = ''.join(b_l)

lst = sorted([a_b, b_a])
print(lst[0])


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

#define MAX_LOG_N 21

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<vector<int>> hotels(2, vector<int>(N));
  REP(i, N) cin >> hotels[0][i];
  REP(i, N) hotels[1][i] = hotels[0][N-1] - hotels[0][N-1-i];

  int L, Q; cin >> L >> Q;
  vector<int> A(Q), B(Q); REP(i, Q) cin >> A[i] >> B[i], A[i]--, B[i]--;
  vector<vector<int>> next_hotel(2, vector<int>(N));

  //REP(k, 2) REP(i, N) cout << hotels[k][i] << (i == N-1 ? '\n' : ' ');
  REP(k, 2) REP(i, N) {
    next_hotel[k][i] = upper_bound(ALL(hotels[k]), hotels[k][i] + L) - hotels[k].begin() - 1;
  }

  // doubling
  vector<vector<vector<int>>> doubling(2, vector<vector<int>>(MAX_LOG_N, vector<int>(N, -1)));
  REP(k, 2) REP(i, N) doubling[k][0][i] = next_hotel[k][i];
  REP(k, 2) REP(i, MAX_LOG_N-1) REP(j, N) doubling[k][i+1][j] = doubling[k][i][j] < 0 ? -1 : doubling[k][i][doubling[k][i][j]];

  /*
  REP(k, 2) {
    REP(i, MAX_LOG_N) REP(j, N) cout << doubling[k][i][j] << (j == N-1 ? '\n' : ' ');
    cout << endl;
  } //*/

  REP(q, Q) {
    int k = A[q] > B[q], a = A[q], b = B[q];
    if (a > b) {
      a = N-1 - a;
      b = N-1 - b;
    }
    //cout << a << ' ' << b << endl;
    assert(a < b);

    int low = 0, high = 1e6;
    while (low + 1 < high) {
      int mid = (low + high) >> 1, now = a;
      for (int i = MAX_LOG_N-1; i >= 0; i--) if (mid >> i & 1) now = doubling[k][i][now];
      //cout << low << ',' << high << ':' << mid<< ':' << now << endl;
      (now >= b ? high : low) = mid;
    }
    cout << high << endl;
  }

  return 0;
}


Measured memory_bytes: 28152
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    cout << 3*n*n << "\n";
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h> 
int main(){
  int n,min=10000000,max=-10000000,sum=0,i;
  int *array;
  scanf("%d",&n);
  array=(int*)malloc(n*sizeof(int));

  for(i=0;i<n;i++){
    scanf("%d",&array[i]);
 }
 for(i=n-1;i>=0;i--){
   printf("%d",array[i]);
   if(i!=0)
   printf("%s"," ");
 }
 printf("\n");
    return 0;
}

Measured memory_bytes: 600
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		
		for(int i=0;i<N;i++){
			A[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(A);
		
		int min_A=A[0];	//Aの中で一番小さい値
		int min_A2=A[1];
		
		 List<Integer> list = new ArrayList<Integer>();

		    for (int i = 1; i * i <= min_A; i++) {  
		        if (min_A % i == 0) {
		            list.add(i);         
		            if (i != min_A / i) {
		                list.add(min_A / i);  
		            }
		        }
		    }
		    for (int i = 1; i * i <= min_A2; i++) {  
		        if (min_A2 % i == 0) {
		            list.add(i);         
		            if (i != min_A2 / i) {
		                list.add(min_A2 / i);  
		            }
		        }
		    }

		
		
		int ans = 1;
	
		for(Iterator<Integer> it = list.iterator(); it.hasNext();){
			int num = it.next();
			boolean flag=false;
			boolean flag_ans=true;
			for(int i=0; i<N;i++){
				if(A[i]%num != 0){
					if(flag){
						flag_ans = false;
						continue;
					}
					flag = true;
				}
			}
			if(flag_ans && ans<num)ans = num;
		
		}
		



		System.out.println(ans);
		
		
		sc.close();
	}
	
}


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
using V = vector<int>;
using Vll = vector<ll>;
using Vstr = vector<string>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;
}
*/

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

  int N;
  cin >> N;
  V P(N),Q(N);
  REP(i,N) cin >> P[i];
  REP(i,N) cin >> Q[i];

  int perm[] = {1, 2, 3, 4, 5, 6, 7, 8};
  int a, b, perm_count = 0;

  do {
    perm_count++;
    bool is_p = true, is_q = true;
    REP(i,N) {
      if (perm[i] != P[i]) is_p = false;
      if (perm[i] != Q[i]) is_q = false;
    }
    if (is_p) a = perm_count;
    if (is_q) b = perm_count;
  } while(next_permutation(perm, perm+N));

  cout << abs(a-b) << endl;
}



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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    string s,t;
    cin >> s >> t;
    int ans = INF;
    REP(i,s.size()-t.size()+1){
        int cnt = 0;
        REP(j,t.size()) if(s[i+j]!=t[j]) cnt++;
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int n,m;
    cin >> n >> m;
    int fast=0,last=1000000;
    int l,r;
    rep(i,m)
    {
        cin >> l >> r;
        fast=max(fast,l);
        last=min(last,r);
    }
    int ans;
    if(fast>last)ans=0;
    else ans=last-fast+1;
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
//        string[] input = ReadLine().Split(' ');
        int kazu = int.Parse(ReadLine());
        string[] suji = ReadLine().Split(' ');
//        int max = int.Parse(input[1]);
        int[] suuji = new int[kazu];
        for(int i=0;i<kazu;i++){
            suuji[i] = int.Parse(suji[i]);
        }
        for(int i=0;i<kazu*2;i++){
            for(int j=0;j<kazu-1;j++){
                if(suuji[j] < suuji[j+1]){
                    int temp = suuji[j];
                    suuji[j] = suuji[j+1];
                    suuji[j+1] = temp;
                }
            }
        }
        
        int a=0,b=0;
        for(int i=0;i<kazu;i++){
            if(i%2 == 0){
                a += suuji[i];
            }else{
                b += suuji[i];
            }
        }
        WriteLine(a-b);
    }
}

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

int main(){
	int N,C;
	cin >> N >> C;
	vector< vector< int >  > D = vector< vector< int >  >(C,vector< int > (C,0));
	vector< vector< int >  > grid = vector< vector< int >  >(N,vector< int > (N,0));
	
	for(int i = 0; i < C; i++)
	{
		
		for(int j = 0; j < C; j++)
		{
			cin >> D[i][j];
		}
		
	}
	
	for(int i = 0; i < N; i++)
	{
		
		for(int j = 0; j < N; j++)
		{
			cin >> grid[i][j];
		}
		
	}
	vector< vector< int >  > cnt = vector< vector< int >  >(3,vector< int > (C,0));

	
	for(int i = 0; i < N; i++)
	{
		
		for(int j = 0; j < N; j++)
		{
			cnt[(i+j)%3][grid[i][j]-1] ++;
		}
		
	}
	
	int minv= INT_MAX;
	for(int i = 0; i < C; i++)
	{
		
		for(int j = 0; j < C; j++)
		{
			
			for(int k = 0; k < C; k++)
			{
				if(i==j || j==k || i==k){
					continue;
				}else{
					int sum =0;
					for(int l=0;l<C;l++) sum += cnt[0][l] * D[l][i];
					for(int l=0;l<C;l++) sum += cnt[1][l] * D[l][j];
					for(int l=0;l<C;l++) sum += cnt[2][l] * D[l][k];
					minv = min(minv, sum);
					
				}
			}
			
		}
		
	}

	cout << minv << endl;
	return 0;

}



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

int main(){
    unsigned long int l, r;
    int temp = 2019, k;
    cin >> l >> r;
    for(unsigned long int i = l; i<r; i++){
        for(unsigned long int j = i+1; j<r+1; j++){
            k = (i*j)%2019;
            if(k < temp){
                temp = k;
            }
            if(k==0){
                temp = k;
                break;
            }
        }
        if(!temp){
            break;
        }
    }
    cout << temp << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
const ll inf =1000000007;

void solve(){
    ll s,w;
    cin >> s >> w;
    if(s<=w) cout << "unsafe" << endl;
    else cout <<"safe" << endl;
}

int main(){
    solve();
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

int main() {
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
        // Code Starts...
        ll n;
        cin>>n;
        vector<ll > v(n);
        for (int i=0;i<n;i++)
            cin>>v[i];
        vector<ll > dp(n,inf); // it stores the min cost incurred so far...
        dp[0] = 0; // cost at stone 1 is 0...
        dp[1] = abs(v[1] - v[0]);
        for (int i=2;i<n;i++)
        {
            dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
        }
        cout<<dp[n-1]<<endl;
        // Code Ends...
        return 0;
}


Measured memory_bytes: 1792
/*
 * sto Qingyu orz
 * 感谢真神sqy无私的教诲。膜时队者处处阿克，只因大师sqy在他背后。不膜大师者违背了真神的旨意，真神必将降下天谴,
 * 使其天天爆零
 * 我不由自主地膜拜真神sqy。
 * Author: RainAir
 * Time: 2019-10-17 07:32:01
 */
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define U unsigned
#define P std::pair
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 700+5;
int mp[MAXN][MAXN];
int n,m;
bool vis[MAXN];
int col[MAXN];
int a[MAXN],b[MAXN],tot;
int f[MAXN][MAXN];
//std::vector<int> pt;
bool flag = true;

inline void dfs(int v){
 //   pt.pb(v);
    FOR(x,1,n){
        if(!mp[v][x]) continue;
        if(!vis[x]){
            vis[x] = true;
            col[x] = 3-col[v];dfs(x);
        }
        else if(col[v] == col[x]) flag = false;
    }
}

int main(){
    scanf("%d%d",&n,&m);
    FOR(i,1,n) FOR(j,1,n) mp[i][j] = (i != j);
    FOR(i,1,m){
        int u,v;scanf("%d%d",&u,&v);
        mp[u][v] = mp[v][u] = 0;
    }
    FOR(i,1,n){
        if(!vis[i]){
            CLR(col,0);
            col[i] = 1;dfs(i);
            if(!flag){
                puts("-1");
                return 0;
            }
            int cnt1 = 0,cnt2 = 0;
            FOR(i,1,n){
                if(col[i] == 1) ++cnt1;
                else if(col[i] == 2) ++cnt2;
            }
            a[++tot] = cnt1;b[tot] = cnt2;
        }
    }
    f[0][0] = 1;
//    DEBUG(a[tot]);DEBUG(b[tot]);
    FOR(i,1,tot){
        ROF(j,n,0){
            ROF(k,n,0){
                if(j >= a[i] && k >= b[i]) f[j][k] |= f[j-a[i]][k-b[i]];
                if(j >= b[i] && k >= a[i]) f[j][k] |= f[j-b[i]][k-a[i]];
            }
        }
    }
    int ans = 1e9;
    FOR(i,0,n){
        if(f[i][n-i]) ans = std::min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
    }
    printf("%d\n",ans);
    return 0;
}


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

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    while((cnt < c) && (b >= a))
    {
        cnt++;
        b -= a;
    }

    cout << cnt << endl;

    return 0;
}

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

using namespace std;

template< typename T = int >
T Hungarian(vector< vector< T > > &A)
{
  const T infty = numeric_limits< T >::max();
  const int N = (int) A.size() - 1;
  const int M = (int) A[0].size() - 1;
  vector< int > P(M + 1), way(M + 1);
  vector< T > U(N + 1, 0), V(M + 1, 0), minV;
  vector< bool > used;

  for(int i = 1; i <= N; i++) {
    P[0] = i;
    minV.assign(M + 1, infty);
    used.assign(M + 1, false);
    int j0 = 0;
    while(P[j0] != 0) {
      int i0 = P[j0], j1 = 0;
      used[j0] = true;
      T delta = infty;
      for(int j = 1; j <= M; j++) {
        if(used[j]) continue;
        T curr = A[i0][j] - U[i0] - V[j];
        if(curr < minV[j]) minV[j] = curr, way[j] = j0;
        if(minV[j] < delta) delta = minV[j], j1 = j;
      }
      for(int j = 0; j <= M; j++) {
        if(used[j]) U[P[j]] += delta, V[j] -= delta;
        else minV[j] -= delta;
      }
      j0 = j1;
    }
    do {
      P[j0] = P[way[j0]];
      j0 = way[j0];
    } while(j0 != 0);
  }
  return (-V[0]);
}

const int LIM = (int) 1e7;
bool prime[LIM + 1];

int main()
{
  prime[0] = prime[1] = true;
  for(int i = 2; i * i <= LIM; i++) {
    if(!prime[i]) {
      for(int j = i + i; j <= LIM; j += i) {
        prime[j] = true;
      }
    }
  }

  int N;
  cin >> N;
  vector< int > vs;
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if(vs.empty() || vs.back() + 1 != x) {
      vs.emplace_back(x - 1);
      vs.emplace_back(x);
    } else {
      ++vs.back();
    }
  }

  vector< int > latte, malta;
  for(auto &p : vs) {
    if(p & 1) latte.emplace_back(p);
    else malta.emplace_back(p);
  }

  int ret = 0;

  if(!latte.empty() && !malta.empty()) {
    if(latte.size() > malta.size()) swap(latte, malta);
    vector< vector< int > > g(latte.size() + 1, vector< int >(malta.size() + 1, 0));
    for(int i = 0; i < latte.size(); i++) {
      for(int j = 0; j < malta.size(); j++) {
        if(!prime[abs(latte[i] - malta[j])]) {
          g[i + 1][j + 1] = -1;
        }
      }
    }
    ret = -Hungarian(g);
  }

  int beet1 = latte.size() - ret;
  int beet2 = malta.size() - ret;
  ret += beet1 / 2 * 2;
  ret += beet2 / 2 * 2;
  ret += beet1 % 2 * 3;
  cout << ret << endl;
}

Measured memory_bytes: 10112
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;

int main() {
	cpp_int n, k;
	cin >> n >> k;
	vector<cpp_int> h;
	for (int i = 0; i < n; ++i) {
		cpp_int e;
		cin >> e;
		h.push_back(e);
	}

	sort(h.begin(), h.end());

	for (int i = 0; i < k; ++i) {
		h.pop_back();
		if (h.empty()) {
			cout << 0 << endl;
			return 0;
		}
	}

	cpp_int sum = 0;
	for (auto e : h) {
		sum += e;
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 10220
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int M = 5e5 + 10;
const int mod = 1e9 + 7;

int n;
struct par {
	int w, id;
}a[M];

inline bool cmp(par a, par b) {
	return a.w < b.w;
}

int main() {
	int ans = 0;
	cin >> n;
	for (int i=1; i<=n; ++i) scanf("%d", &a[i].w), a[i].id = i;
	sort(a+1, a+n+1, cmp);
	for (int i=1; i<=n; ++i) ans += ((a[i].id & 1) != (i & 1));
	cout << ans/2 << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <map>
#include <set>
#define SIZE 200005
#define INF 1000000000
#define PI 3.1415926535897932384626

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

int dp[SIZE];
int n;

double solve(vector <P> vx,int x1,int x2,int y1,int y2)
{
	vector <P> vec;
	for(int i=0;i<n;i++)
	{
		int x=vx[i].first,y=vx[i].second;
		if(min(x1,x2)<=x&&x<=max(x1,x2)&&min(y1,y2)<=y&&y<=max(y1,y2))
		{
			vec.push_back(P(x,y));
		}
	}
	double ret=100.0*(ll) (abs(x1-x2)+abs(y1-y2));
	if(x1>x2)
	{
		swap(x1,x2);
		swap(y1,y2);
	}
	if(y1>y2)
	{
		for(int i=0;i<vec.size();i++) vec[i].second*=-1;
		y1*=-1,y2*=-1;
	}
	int sz=vec.size()+1;
	for(int i=0;i<sz;i++) dp[i]=INF;
	dp[0]=-INF;
	sort(vec.begin(),vec.end());
	double mn=20.0-5.0*PI;
	double add=10.0*PI-20.0;
	for(int i=0;i<vec.size();i++)
	{
		int y=vec[i].second;
		int pos=lower_bound(dp,dp+sz,y)-dp;
		dp[pos]=y;
	}
	int len=0;
	for(int i=0;i<sz;i++) if(dp[i]<INF) len=i;
	ret-=len*mn;
	if(len==min(x2-x1,y2-y1)+1) ret+=mn+add;
	return ret;
}
int main()
{
	int x1,x2,y1,y2;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	scanf("%d",&n);
	vector <P> vx;
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		vx.push_back(P(x,y));
	}
	double ret=solve(vx,x1,x2,y1,y2);
	printf("%.12f\n",ret);
	return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int N=100005;
int n,a[N],ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	ans=1;
	for (int i=0;i<n;i++) 
	  ans=(ll)ans*__gcd(i,a[i+1])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
K, N = map(int, input().split())
A = list(map(int, input().split()))

# tmp1 = A[-1] - A[0]
# tmp2 = A[-1] - (20 - A[0] - A[-1])
# tmp2 = A[-1] - A[1]

# print(min(tmp1, tmp2))
# # print(A[-1]-A[0])

# ans = []
ans = -1
for i in range(N):
    # 右方向
    tmp = A[-1] - A[i]
    if i != 0:
        tmp += K - A[-1] + A[i-1]
    
    if ans == -1:
        ans = tmp
    elif ans > tmp:
        ans = tmp
print(ans)


Measured memory_bytes: 26420
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n+1],c[n];
    for(int i=0;i<n;++i) cin>>a[i];
    for(int i=1;i<=n;++i) cin>>b[i];
    for(int i=1;i<n;++i) cin>>c[i];
    int sum=0;
    for(int i=0;i<n;++i)
    {
        sum+=b[a[i]];
        if(i && (a[i-1]==a[i]-1)) sum+=c[a[i-1]];
    }
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 410
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> new_data_set; 

ll a[MAX];
pii dp[MAX][MAX];
pii f(ll start,ll end,ll n){
	if(start==end) return mp(0,a[start]);
	if(dp[start][end].fi!=-1) return dp[start][end];
	ll ans=1e18;
	ll sum=0;
	Foe(i,start,end-1){
		pii sum1 = f(start,i,n);
		pii sum2 = f(i+1,end,n);
		ll c = sum1.fi+sum2.fi+(sum1.se+sum2.se);
		if(c<ans){
			ans=c;
			sum=sum1.se+sum2.se;
		}
	}
	dp[start][end]=mp(ans,sum);
	return mp(ans,sum);
}

int main(){
	ios_base::sync_with_stdio(false);
	For(i,0,MAX) For(j,0,MAX) dp[i][j]=mp(-1,-1);
	ll n;cin>>n;
	For(i,0,n) cin>>a[i];
	pii ans = f(0,n-1,n);
	cout<<ans.fi<<endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
vector<int> F[100001];
int bel=0;
vector<int> belong[100001];
map<int,int> p;
bool visited[100001];
void dfs(int now,int c){
    int cn=0;
    if(!visited[now]){
        visited[now]=true;
        belong[c].push_back(now);
        p[now]=c;
        //keyは人、値は所属番号
        for(int j=0;j<F[now].size();j++){
            int child = F[now][j];
            if(!visited[child]){
                dfs(child,c);
                cn++;
            }
        }
        if(cn==0){
            bel++;
            //もう回り切った＝＞所属しているグループを変える
        }
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n),x(m),y(m);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    rep(i,m){
        cin>>x[i]>>y[i];
        x[i]--,y[i]--;
        F[x[i]].push_back(y[i]);
        F[y[i]].push_back(x[i]);
    }
    rep(i,n){
        visited[i]=false;
    }
    rep(i,n){
        dfs(i,bel);
    }
    int ans=0;
    rep(i,bel){
        set<int> s;
       // cout<<i<<"個目のグループ所属 ";
        rep(j,belong[i].size()){
            //cout<<belong[i][j]<<" ";
            s.insert(belong[i][j]);
        }
        rep(j,belong[i].size()){
            if(s.count(a[belong[i][j]]))ans++;
        }
        //cout<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 26212
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    double n, k;
    cin >> n >> k;
    double res = 0;

    int v;
    for (int i = 1; i <= n; i++) {
        v = i;
        for(double j = 0;; j++) {
            if (v >= k) {
                res += (double)(1/n) * powl(2, -1 * j);
                break;
            }
            v *= 2;
        }
    }
    printf("%.16lf", res);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (2000005)
#define rhl (1000000007)

using namespace std;

int fac[N],ifac[N],inv[N],X1,X2,X3,X4,X5,X6,Y1,Y2,Y3,Y4,Y5,Y6,ans;

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
  return q*x;
}

il int C(RG int n,RG int m){
  if (n<m) return 0;
  return 1LL*fac[n]*ifac[m]%rhl*ifac[n-m]%rhl;
}

il int calc(RG int l1,RG int r1,RG int l2,RG int r2){
  return (1LL*C(r1+r2+2,r1+1)-C(r1+l2+1,r1+1)-C(l1+r2+1,l1)+C(l1+l2,l1)+rhl+rhl)%rhl;
}

int main(){
  X1=gi(),X2=gi(),X3=gi(),X4=gi(),X5=gi(),X6=gi();
  Y1=gi(),Y2=gi(),Y3=gi(),Y4=gi(),Y5=gi(),Y6=gi();
  fac[0]=ifac[0]=1;
  for (RG int i=1;i<N;++i){
    inv[i]=i==1 ? 1 : 1LL*(rhl-rhl/i)*inv[rhl%i]%rhl;
    fac[i]=1LL*fac[i-1]*i%rhl,ifac[i]=1LL*ifac[i-1]*inv[i]%rhl;
  }
  for (RG int i=Y3;i<=Y4;++i){
    ans=(1LL*calc(X3-X2-1,X3-X1-1,i-Y2,i-Y1)*calc(X5-X3,X6-X3,Y5-i,Y6-i)%rhl*(rhl+rhl-X3-i)+ans)%rhl;
    ans=(1LL*calc(X4-X2,X4-X1,i-Y2,i-Y1)*calc(X5-X4-1,X6-X4-1,Y5-i,Y6-i)%rhl*(X4+i+1)+ans)%rhl;
  }
  for (RG int i=X3;i<=X4;++i){
    ans=(1LL*calc(i-X2,i-X1,Y3-Y2-1,Y3-Y1-1)*calc(X5-i,X6-i,Y5-Y3,Y6-Y3)%rhl*(rhl+rhl-Y3-i)+ans)%rhl;
    ans=(1LL*calc(i-X2,i-X1,Y4-Y2,Y4-Y1)*calc(X5-i,X6-i,Y5-Y4-1,Y6-Y4-1)%rhl*(Y4+i+1)+ans)%rhl;
  }
  cout<<(ans%rhl+rhl)%rhl; return 0;
}


Measured memory_bytes: 23680
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
int n;
vector<int> e[114514];
lli a[114514];

void bye()
{
    cout << "NO" << endl;
    exit(0);
}
lli dfs(lli cur, lli par)
{
    lli sum = 0;
    bool flag = false;
    lli ma = 0;
    for (auto to : e[cur]) {
        if (to == par)
            continue;
        flag = true;
        lli tmp = dfs(to, cur);
        ma = max(tmp, ma);
        sum += tmp;
    }
    if (!flag) {
        //cout << "CUR: " << cur + 1 << ' ' << " x:" << ' ' << 0 << " y: " << a[cur] << endl;

        return a[cur];
    }
    if (ma > a[cur]) {
        bye();
    }

    lli x = sum - a[cur];
    if (x < 0)
        bye();
    lli y = 2LL * a[cur] - sum;
    if (y < 0)
        bye();
    //cout << "CUR: " << cur + 1 << ' ' << "x:" << ' ' << x << "y: " << y << endl;
    if (par == -1) {
        if (y == 0)
            cout << "YES" << endl;
        else
            bye();
        exit(0);
    }
    return y;
}
int main()
{
    lli n;
    cin >> n;
    rep(i, n) cin >> a[i];
    lli b, c;

    rep(i, n - 1)
    {
        cin >> b >> c;
        b--, c--;
        e[b].push_back(c);
        e[c].push_back(b);
    }
    if (n == 2) {
        if (a[0] != a[1])
            cout << "NO" << endl;
        else
            cout << "YES" << endl;
        return 0;
    }
    lli root = 0;
    rep(i, n) if (e[i].size() >= 2) root = i;
    dfs(root, -1);
}


Measured memory_bytes: 12544
import math

tol = 10 ** -9

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


def calc_exponent(k, i):
    tmp = math.log2(k / i)
    tmp2 = int(tmp)
    return tmp2 if 10 ** -10 > abs(tmp - tmp2) else tmp2 + 1


if n < k:
    ans = 0
    for i in range(1, n+1):
        ans += 0.5 ** calc_exponent(k, i)
    print(ans / n)
else:
    ans = 0
    for i in range(1, k):
        ans += 0.5 ** calc_exponent(k, i)
    ans = (n - k + 1) / n + ans / n
    print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, i;
  cin >> N >> i;

  cout << N + 1 - i << endl;
  
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N), H(N,0);
   for (int i = 0; i < N; i++) {
     cin >> vec.at(i);
   }
   for (int j = 0; j < M; j++) {
     int A = 0, B = 0;
     cin >> A >> B;
     int a = A - 1;
     int b = B - 1;
     if (vec.at(a) == vec.at(b)){
       H.at(a) ++;
       H.at(b) ++;
     }
       else if (vec.at(a) > vec.at(b))
         H.at(b) ++;
       else
         H.at(a) ++;
   }
  int x = 0;
   for (int i = 0; i < N; i++) {
     if (H.at(i) == 0)
       x ++;
   }
  cout << x << endl;
}

Measured memory_bytes: 4052
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		sc.nextLine();
		String[] str=new String[N];
		str=sc.nextLine().split("");
		int cntE=0,cntW=0,cnt=3000000;
		for(int i=0;i<str.length;i++){
			if(str[i].equals("E"))cntE=cntE+1;
			if(str[i].equals("W"))cntW=cntW+1;
		}
		int leftE=0,leftW=0;
		for(int i=0;i<str.length;i++){
			if(str[i].equals("E"))leftE=leftE+1;
			if(cnt>(leftW+cntE-leftE))cnt=(leftW+cntE-leftE);
			if(str[i].equals("W"))leftW=leftW+1;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 53008
import Data.Set (Set, (\\), intersection, elems, null, size, fromList)
import qualified Data.Set as S

main :: IO ()
main = interact $ unlines . map (show' . uncurry surrounding_area) . read' . lines
 where
  read' ("0 0":_) = []
  read' (wh:xs) = ((w,h),(black,white)) : read' xs'
   where
    [w,h] = map read (words wh)
    (m,xs') = splitAt h xs
    black = fromList [(x,y) | x<-[1..w], y<-[1..h], m!!(y-1)!!(x-1)=='B']
    white = fromList [(x,y) | x<-[1..w], y<-[1..h], m!!(y-1)!!(x-1)=='W']
  show' (b,w) = show b ++ " " ++ show w

type Grid = Set (Int,Int)

wasteland :: Int -> Int -> Grid
wasteland x y = fromList [(w,h) | w<-[1..x], h<-[1..y]]

surrounding_area :: (Int,Int) -> (Grid,Grid) -> (Int,Int)
surrounding_area (w,h) (black,white) = (nb,nw)
 where
  nb = if S.null black then 0 else untouched (wasteland w h \\ black) white
  nw = if S.null white then 0 else untouched (wasteland w h \\ white) black

untouched :: Grid -> Grid -> Int
untouched gw gp = size $ gw \\ (untilFix (survey gw) gp)

survey :: Grid -> Grid -> Grid
survey gw = intersection gw . expand

expand :: Grid -> Grid
expand = fromList . concatMap neighbor . elems

neighbor :: (Int,Int) -> [(Int,Int)]
neighbor (x,y) = [(x,y),(x-1,y),(x+1,y),(x,y-1),(x,y+1)]

untilFix :: Eq a => (a -> a) -> a -> a
untilFix f x = if f x == x then x else untilFix f (f x)

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

int main() {
    map<int, bool> mp;
    int s;
    cin >> s;
    mp[s] = true;
    int a = s;
    int cnt = 1;
    while (cnt++) {
        if (a % 2 == 0) {
            a /= 2;
        } else {
            a = a * 3 + 1;
        }
        if (mp[a]) break;
        mp[a] = true;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256