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

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[][] dp = new int[n][3];
        dp[0][0] = in.nextInt();
        dp[0][1] = in.nextInt();
        dp[0][2] = in.nextInt();

        for (int i = 1; i < n; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            dp[i][0] = a + Math.max(dp[i - 1][1], dp[i - 1][2]);
            dp[i][1] = b + Math.max(dp[i - 1][0], dp[i - 1][2]);
            dp[i][2] = c + Math.max(dp[i - 1][0], dp[i - 1][1]);

        }

        out.println(Math.max(Math.max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]));
        out.close();

    }


    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream i) {
            br = new BufferedReader(new InputStreamReader(i));
            st = new StringTokenizer("");
        }
        public String next() throws IOException {
            if (st.hasMoreTokens()) {
                return st.nextToken();
            }
            else
                st = new StringTokenizer(br.readLine());
            return next();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public String nextLine() throws IOException {
            if (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
                return nextLine();
            }

            String ret = "";
            while (st.hasMoreTokens()) {
                ret += st.nextToken();
            }
            return ret;
        }
        public int[] nextIntArr(int size) throws IOException {
            int[] arr = new int[size];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
        public long[] nextLongArr(int size) throws IOException {
            long[] arr = new long[size];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
        public double[] nextDoubleArr(int size) throws IOException {
            double[] arr = new double[size];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 57624
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int K;
	cin >> K;
	int Khalf = K / 2;
	if (K % 2 == 0) {
		cout << Khalf * Khalf << endl;
	}
	else {
		cout << (Khalf * Khalf) + Khalf << endl;
	}
}

Measured memory_bytes: 256
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n , m) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };
    let p: Vec<usize> = read_vec();
    let mut union = UnionFind::new(n+1);
    for _ in 0..m {
      let (a, b) = {
        let t: Vec<i64> = read_vec();
        (t[0], t[1])
      };
      union.connect(a, b);
    }

    let mut ans = 0;
    for i in (1..n+1).rev() {
      if union.connected(i as i64, p[i - 1] as i64) {
        ans += 1;
      }
    }
    println!("{}", ans);
}



pub struct UnionFind {
  // 親のノードの番号を書くのする。親だった場合は-(その集合のサイズ)
  pub parent: Vec<i64>,
}


impl UnionFind {
  // コンストラクター
  pub fn new(n: usize) -> UnionFind {
    return UnionFind {parent: vec![-1; n]};
  }

  // aがどのグループに属しているか調べる
  // 属している木のの根を返す
  pub fn root(&mut self, a: i64) -> i64 {

    if self.parent[a as usize] < 0 {
      return a;
    }
    // aに属してる集合の根にaを直接つなぐ
    let tmp = self.parent[a as usize];
    self.parent[a as usize] = self.root(tmp);

    return self.parent[a as usize];
  }

  // 自分のいるグループの頂点数を調べる
  pub fn size(&mut self, a: i64) -> i64 {
    let tmp = self.root(a) as usize;
    return -self.parent[tmp];
  }

  // aとbをくっつける
  pub fn connect(&mut self, a: i64, b: i64) -> bool {
    let mut at = self.root(a);
    let mut bt = self.root(b);

    if at == bt {
      // すでにくっついてるからくっつけない
      return false;
    }

    // 大きい方aに小さい方bをくっつける
    // 大小が逆だったらひっくり返す
    if self.size(at) < self.size(bt) {
      let temp = at;
      at = bt;
      bt = temp;
    }

    // aのサイズを更新する
    self.parent[at as usize] += self.parent[bt as usize];
    // bの親をaに更新する
    self.parent[bt as usize] = at;
    return true
  }

  pub fn equal(&self, that: UnionFind) -> bool {
    let l: usize = that.parent.len();

    if self.parent.len() != l {
      println!("{}",l);
      println!("{:?}", self.parent);
      return false;
    }

    for i in 0..l {
      if self.parent[i] != that.parent[i] {
        return false;
      }
    }
    return true;
  }

  pub fn connected(&mut self, a: i64, b: i64 ) -> bool {
    self.root(a) == self.root(b)
  }
}


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

int main(){
	string S;
	cin >> S;
	int N=S.size();
	for(int i=N-2;i>0;i-=2){
		bool flag=true;
		for(int j=0;j<i/2;j++)if(S[j]!=S[j+i/2])flag=false;
		if(flag){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
	int a;
	cin >> a;
	cout << a + a * a + a * a * a;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}
 
int main() {
  ll n ,t ; 
  cin>>n>>t;
  

  vector<ll>vec(n);
  rep(i,n) cin>>vec[i];
  ll sum=t;
  ll time=0;
  rep(i,n-1){
    time=vec[i]+t;
    sum+=t;
    if(vec[i+1]<time){
      sum-=time-vec[i+1];
    }
  }
  cout<<sum<<endl;
  
}
  



Measured memory_bytes: 1792
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)] # a_0...a_(M-1)

def f(x):
    a, b = 1, 1
    if x == 0:
        return a
    elif x == 1:
        return b
    else:
        for i in range(x-1):
            a, b = b, a + b
        return b
"""
# 再帰だとTLEとかREとかになるよ
def f(x): # フィボナッチ数列
    if x == 0:
        return(1)
    elif x == 1:
        return(1)
    else:
        return(f(x-1) + f(x-2))
"""

ans = 0
MOD = 10**9 + 7

if M == 0:
    ans += f(N) % MOD
    print(ans)
else:
    ans += f((a[0]-1) - 0) % MOD # 0段目からa_0-1段目に上る(その後a_0段目を飛ばしてa_0+1段目に上る)
    for i in range(1, M): # iは1からM-1
        stair = (a[i] - 1) - (a[i-1] + 1) # 登る段数
        if stair >= 0:
            ans *= f(stair) % MOD # a_(i-1)+1段目からa_i-1段目に上る(その後a_i段目を飛ばしてa_i+1段目に上る)
        else:
            ans = 0
            break
    ans *= f(N - (a[M-1] + 1)) % MOD # a_M-1段目からN段目に上る
    print(ans % MOD)


Measured memory_bytes: 7076
k,n = input().split()

k,n = int(k), int(n)
lt = [int(x) for x in input().split()]
lt2 = lt.copy()
lt3 = lt2 + [i+k for i in lt]

mini = 1000000000000000

i=0
while i+n-1 < len(lt3):
    mini = min(mini, lt3[i+n-1] - lt3[i])
    i+=1
print(mini)


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

int main(){
	int n,i,ans;
	cin  >> n >> i;
	ans=n-i+1;
	cout << ans << endl;
}
    

Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = LLONG_MAX, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

ll arr[300][300];
bool flag[300][300];
typedef pair<ll, Pa> edge;

vector<Pa> to[301];
vector<edge> edges;
bool need[300][300];

int main() {
    cin >> N;
    rep(i, N){
        rep(j, N){
            cin >> arr[i][j];
            need[i][j] = true;
        }
    }
    ll ans = 0;
    for (int k = 0; k < N; k++)      // 経由する頂点
        for (int i = 0; i < N; i++)    // 開始頂点
            for (int j = 0; j < N; j++)  // 終端
                if(arr[i][j] > arr[i][k] + arr[k][j]){
                    cout << -1;
                    return 0;
                }else{
                    if(arr[i][j] == arr[i][k] + arr[k][j] && i != j && i != k && j != k){
                        need[i][j] = false;
                        need[j][i] = false;
                    }
                }

    rep(i, N){
        rep(j, N){
            if(need[i][j]) ans += arr[i][j];
        }
    }
    cout << ans/2;
}


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

int main(){
    ll N,K,Q; cin >> N >> K >> Q;
    vector<ll> A(N+1,K-Q);
    rep(i,0,Q){
        ll a;
        cin >> a;
        a--;
        A[a]++;
    }
    rep(i,0,N){
        if(A[i]>0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

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

using namespace std;

const double INF = 4e9;

int main(){
  double xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  
  int N;
  cin >> N;
  
  vector<double> x(N + 2), y(N + 2), r(N + 2);
  
  x[0] = xs, y[0] = ys, r[0] = 0;
  x[N + 1] = xt, y[N + 1] = yt, r[N + 1] = 0;
  
  for(int i = 1; i <= N; i++){
    cin >> x[i] >> y[i] >> r[i];
  }
  
  vector<vector<pair<double, int>>> to(N + 2);
  
  for(int i = 0; i <= N + 1; i++){
    for(int j = 0; j <= N + 1; j++){
      double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
      d -= r[i] + r[j];
      d = max(d, 0.0);
      
      to[i].push_back(make_pair(d, j));
      to[j].push_back(make_pair(d, i));
    }
  }
  
  vector<double> exposed(N + 2, INF);
  vector<bool> used(N + 2, false);
  priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
  
  exposed[0] = 0;
  pq.push(make_pair(0.0, 0));
  
  while(!pq.empty()){
    auto cur = pq.top();
    pq.pop();
    
    if(used[cur.second]) continue;
    used[cur.second] = true;
    
    for(auto next : to[cur.second]){
      if(cur.first + next.first < exposed[next.second]){
        exposed[next.second] = cur.first + next.first;
        pq.push(make_pair(exposed[next.second], next.second));
      }
    }
  }
  
  cout << fixed << setprecision(10) << exposed[N + 1] << endl;
  
  return 0;
}

Measured memory_bytes: 37744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

bool check(const vector<int> &d)
{
    int n = d.size();
    vector<bool> vis(n);
    vis[0] = true;
    queue<int> que;
    que.push(0);
    while(!que.empty())
    {
        int v = que.front();
        que.pop();
        for(int i=d[v]; i>0; --i)
        {
            int nx = min(n-1,v+i);
            if(vis[nx]) break;

            que.push(nx);
            vis[nx] = true;
        }
    }
    return vis[n-1];
}

int main()
{
    int n;
    cin >>n;
    vector<int> d(n);
    rep(i,n)
    {
        cin >>d[i];
        d[i]/=10;
    }

    string ans = "yes";
    if(!check(d)) ans = "no";

    reverse(all(d));
    if(!check(d)) ans = "no";

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4920
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long X, long long N, std::vector<long long> p){
    if(N == 0) {cout<<X<<endl; return;}
    set<ll> SX(ALL(p)); 
    map<ll, ll> R;
    for(ll i = 101; i >= 0; i--){
        if(!SX.count(i)){
            R[abs(i - X)] = i;
        }
    }
    cout<<R.begin()->second<<endl;
}
int main(){
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


Measured memory_bytes: 3688
n, m = map(int, input().split())

import numpy as np

food_list = np.zeros(m)

for j in range(n):
    tmp_list = list(map(int, input().split()))
    #k= tmp_list[0]
    for i in tmp_list[1:]:
        food_list[i-1] += 1
    
ans = 0
for k in range(m):
    if food_list[k] == n:
        ans += 1

print(ans)


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

using namespace std;

const unsigned long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    // check even number of nodes?

    // proof: suppose we've got one that appears an odd amount of times, that means an odd number of paths must've come past the node
    //          but what if some node has been covered by other queries? then they must have been odd as well, or there needs to be another node that help fixes in order to be YES
    //          this means that for YES to happen, it must be even

    int n, a, b, m; cin >> n >> m;
    bitset<100005> c;

    for(int i = 0; i < m; ++i){
        cin >> a >> b;
        c[a] = c[a] ^ 1; c[b] = c[b] ^ 1;
    }

    for(int i = 0; i < n; ++i){
        if(c[i]){
            cout << "NO\n";
            return 0;
        }
    }

    cout << "YES\n";

    return 0;

}


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

#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
typedef long long ll;
using namespace std;
const int MAX = 0x7ffffff;
int t;

void slove()
{
	int n , m , k;
	cin >> n >> m >> k;
	vector<ll> a(n + 1) , b(m + 1),suma(n + 1) , sumb(m + 1);
	for(int i = 1;i <= n;i ++)cin >> a[i];
	for(int i = 1;i <= m;i ++)cin >> b[i];
	for(int i = 1;i <= n;i ++)
		suma[i] = suma[i-1] + a[i];
	for(int i = 1;i <= m;i ++)
		sumb[i] = sumb[i-1] + b[i];
	ll ans = 0 , j = m;
	for(int i = 0;i <= n;i ++)
	{
		if(suma[i] > k)break;
		while(sumb[j] > k - suma[i])
			j--;
		ans = max(ans , i + j);
	}
	cout << ans << endl;
}
int main()
{
	SIS;
	slove();
}

Measured memory_bytes: 9516
import java.util.*;

public class Main {

    /* static BitSet bset;
    static int MAX = 10000001;  
    public static void sieve() {
    bset = new BitSet(MAX);
    bset.set(2); //list.add(2);
    for (int j = 3; j < MAX; j+=2) bset.set(j);      
    int sqrt = (int) Math.sqrt(MAX);           
    for (int i = 3; i < sqrt; i+=2)
      if (bset.get(i)) {
        for (int j = i*i; j < MAX; j+=2*i) bset.clear(j);
        //list.add(i);
      }
     */
    //static BitSet bs;
    static int M = 1000001;
    static boolean[] k = new boolean[M];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder st = new StringBuilder();
        k[2] = true;
        for (int i = 3; i < M; i++) {
            int c = 0;
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    c++;
                    break;
                }
            }
            if (c == 0) {
                k[i] = true;
            }
        }
        while (in.hasNextInt()) {
            int p = in.nextInt();
            int x = 0;
            for (int i = 2; i <= p; i++) {
                if (k[i] == true) {
                    x++;
                }
            }
            System.out.println(x);
        }
    }
}



Measured memory_bytes: 27544
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20, mod = 1e9 + 7;
int n, s, d, w[N], cnt[N], fc[N], ifc[N], r[N];
bool mark[N];
vector<int> gr[N], c[N], mm;
pair<int, int> mn = {mod, mod}, smn = {mod, mod};
long long ans = 1;
long long power(long long a, long long b) {
	if (!b)
		return 1;
	long long rtr = power(a, b / 2) % mod;
	if (b % 2)
		return rtr * rtr % mod * a % mod;
	return rtr * rtr % mod;
}
void getFC() {
	fc[0] = ifc[0] = 1;
	for (int i = 1; i < N - 5; i++) {
		fc[i] = 1ll * fc[i - 1] * i % mod;
		ifc[i] = 1ll * ifc[i - 1] * power(i, mod - 2) % mod;
	}
	return;
}
void dfs(int v) {
	mm.push_back(v);
	mark[v] = 1;
	for (auto u : gr[v])
		if (!mark[u])
			dfs(u);
	return;
}
int main() {
	getFC();
	cin >> n >> s >> d;
	for (int i = 0; i < n; i++) {
		cin >> r[i] >> w[i];
		r[i]--;
		c[r[i]].push_back(i);
		mn = min(mn, {w[i], i});
	}
	for (int i = 0; i < n; i++) 
		sort(c[i].begin(), c[i].end(), [] (int x, int y) { return (w[x] < w[y]); });
	for (int i = 0; i < n; i++)
		if (r[i] != r[mn.second])
			smn = min(smn, {w[i], i});
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < c[i].size(); j++) {
			if (w[c[i][j]] + w[c[i][0]] <= s) {
				gr[c[i][0]].push_back(c[i][j]);
				gr[c[i][j]].push_back(c[i][0]);
			}
			int u = c[i][j], v = mn.second;
			if (i != r[v]) {
				if (w[u] + w[v] <= d) {
					gr[u].push_back(v);
					gr[v].push_back(u);
				}
			}
			else {
				if (smn.first + w[u] <= d) {
					gr[u].push_back(smn.second);
					gr[smn.second].push_back(u);
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (!mark[i]) {
			dfs(i);
			long long rtr = 1ll * fc[(int) mm.size()] % mod;
			for (auto u : mm) {
				rtr = 1ll * rtr * fc[cnt[r[u]]] % mod;
				cnt[r[u]]++;
				rtr = 1ll * rtr * ifc[cnt[r[u]]] % mod;
			}
			for (auto u : mm)
				cnt[r[u]] = 0;
			mm.clear();
			ans = 1ll * (ans * rtr) % mod;
		}
	}
	cout << (ans + mod) % mod;
	return 0;
}


Measured memory_bytes: 25204
// Problem : A - Duplex Printing
// Contest : AtCoder - AtCoder Beginner Contest 157
// URL : https://atcoder.jp/contests/abc157/tasks/abc157_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#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;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    cin>>n;
    cout<<(n+1)/2;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i = 0; i < N; i++) cin >> h[i];
    ll cost[N];
    for(int i = 0; i < N; i++) cost[i] = INF;
    cost[0] = 0;
    for(int i = 0; i < N; i++){
        if(i + 1 < N) cost[i+1] = min(cost[i+1],cost[i]+abs(h[i] - h[i+1]));
        if(i + 2 < N) cost[i+2] = min(cost[i+2],cost[i]+abs(h[i] - h[i+2]));
    }
    cout << cost[N-1] << endl;
    return 0;
}


Measured memory_bytes: 4416
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static long[] primes = new long[1001];
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            for (var i = 1; i <= N; ++i)
                primefactorize(i);
            var ans = 1L;
            for (var i = 2; i <= N; ++i)
                ans = (ans * (primes[i] + 1)) % Mod;
            // 1 + その他 - 0
            WriteLine((1 + ans - 1) % Mod);

            //Out.Flush();
        }
        static void primefactorize(long n)
        {
            for (long i = 2; i * i <= n; ++i)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                    {
                        ++primes[i];
                        n /= i;
                    }
                }
            }
            if (n != 1) ++primes[n];
        }
    }
}


Measured memory_bytes: 11348
(let ((s (read-line))
      (k (read))
      (flg t)
      (l 0)
      (temp #\0))
  (loop for i across s
        while flg do (if (equal i #\1) (incf l) (progn (setf flg nil)
                                                     (setf temp i))))
  (princ (if (<= k l) 1 temp)))


Measured memory_bytes: 12136
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class t,class u>
ostream& operator << (ostream& os,pair<t,u> p){
	return os << p.fi << ',' << p.sec;
}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
template<class T>
void input(vector<T>& vec,int n){
	vec.resize(n);
	for(int i=0;i<n;i++){
		cin >> vec[i];
	}
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
int N;
int main(){
	cin >> N;
	if(__builtin_popcount(N)==1){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	cout << 1 << ' ' << 2 << endl;
	cout << 2 << ' ' << 3+N << endl;
	cout << 3+N << ' ' << 1+N << endl;
	cout << 1+N << ' ' << 2+N << endl;
	cout << 2+N << ' ' << 3 << endl;
	for(int i=4;i<N;i+=2){
		cout << i+N << ' ' << i+1 << endl;
		cout << i+N << ' ' << 1+N << endl;
		cout << 1+N << ' ' << i+1+N << endl;
		cout << i+1+N << ' ' << i << endl;
	}
	if(N%2==1)return 0;
	int K = N&(-N);
	K++;
	int J = N^K;
	K--;
	cout << N << ' ' << J+N << endl;
	cout << N+N << ' ' << K+N << endl;
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n;cin>>n;
    string s;
    while(true){
        ll k=n%26;
        if(k==0){
            s='z'+s;
            n=(n-26)/26;
        }else{
            s=(char)('a'+k-1)+s;
            n=(n-k)/26;
        }
        if(n==0){
            break;
        }
    }
    cout<<s<<endl;
    
    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <array>
#include <numeric>
#include <algorithm>
#include <set>
#include <deque>
using namespace std;
using ll = long long;
constexpr double INF{ 1e9 };
constexpr int MAGIC_PRIME{ 1000000000 + 7 };
constexpr array<int, 4> dy{ -1, 1, 0, 0 };
constexpr array<int, 4> dx{ 0, 0, -1, 1 };
constexpr int div_ru(int a, int b)
{
    return (a - b + 1) / b;
}
ll pow_mod(ll b, ll e, ll m)
{ // https://atcoder.jp/contests/atc002/tasks/atc002_b
    ll r = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            r = (r * b) % m;
        b = (b * b) % m;
    }
    return r;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;

    int count = 0;

    while (!(a % 2) && !(b % 2) && !(c % 2)) {
        const int spl_a = a / 2;
        const int spl_b = b / 2;
        const int spl_c = c / 2;

        a = spl_b + spl_c;
        b = spl_c + spl_a;
        c = spl_a + spl_b;
        count++;

        if (a == b && b == c) {
            count = -1;
            break;
        }
    }

    cout << count << endl;

}
// vector<vector<int>> mm(h, vector<int>(w, -1));


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

int cnts[100005];

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

  int n;
  cin >> n;

  int ub = n-1;
  int lb = 0;

  cout << 0 << endl;

  string s1;
  cin >> s1;

  if(s1 == "Vacant") {
    return 0;
  }

  while(ub - lb > 1) {
    int next = (ub + lb) / 2;
    cout << next << endl;
    string s;
    cin >> s;
    if(s == "Vacant") {
      return 0;
    }
    if ((next % 2 == 0) == (s1 == s)) {
      lb = next;
    } else {
      ub = next;
    }
  }

  cout << ub << endl;
  cin >> s1;
}

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

int main(){
    char s[4];
    for (int i=0; i<4; ++i) cin >> s[i];
    char a[3];
    int A=s[0]-'0';
    int B=s[1]-'0';
    int C=s[2]-'0';
    int D=s[3]-'0';
    if(A+B+C+D==7) {
        a[0]='+';
        a[1]='+';
        a[2]='+';
    }
    else if(A+B-C-D==7) {
        a[0]='+';
        a[1]='-';
        a[2]='-';
    }
    else if(A+B+C-D==7) {
        a[0]='+';
        a[1]='+';
        a[2]='-';
    }
    else if(A+B-C+D==7) {
        a[0]='+';
        a[1]='-';
        a[2]='+';
}
    else if(A-B+C+D==7) {
        a[0]='-';
        a[1]='+';
        a[2]='+';
}
    else if(A-B-C-D==7) {
        a[0]='-';
        a[1]='-';
        a[2]='-';
}
    else if(A-B+C-D==7) {
        a[0]='-';
        a[1]='+';
        a[2]='-';
}
    else if(A-B-C+D==7) {
        a[0]='-';
        a[1]='-';
        a[2]='+';
}
    cout <<A<<a[0]<<B<<a[1]<<C<<a[2]<<D<<"=7"<<  endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	ll x; cin>>x;
	for(ll a=-1000; a<=1000; a++){
		for(ll b=-1000; b<=1000; b++){
			if(pow(a,5)-pow(b,5)==x) return cout<<a SP b<<endl,0;
		}
	}

	return 0;
}


Measured memory_bytes: 4028
#include<stdio.h>
#define _CRT_SECURE_NO_WARNINGS

int w, h, x, y, r;

int main() {
	scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);

	

	if (x > (w - r)) {
		printf("No\n");
		return 0;
	}
	else if (x < r) {
		printf("No\n");
		return 0;
	}
	else if (y > (h-r)) {
		printf("No\n");
		return 0;
	}
	else if (y < r) {
		printf("No\n");
		return 0;
	}
	else printf("Yes\n");

	return 0;

}

Measured memory_bytes: 580
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    if sum(a) == x:
        print(N)
        return
    for i in range(N):
        x -= a[i]
        if x < 0:
            break
    ans = i
    print(ans)

if __name__ == "__main__":
    main()


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int H,W,h,w;cin>>H>>W>>h>>w;
  cout<<(H-h)*(W-w)<<endl;

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int LCS(string X,string Y){
    int cnt=-1;
    int c[1001][1001];
    int m=X.size();
    int n=Y.size();
    X=' '+X;
    Y=' '+Y;
    for(int i=1;i<=m;i++){
        c[i][0]=0;
    }
    for(int j=0;j<=n;j++){
        c[0][j]=0;
    }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(X[i]==Y[j]){
                c[i][j]=c[i-1][j-1]+1;
            }
            else{
                c[i][j]=max(c[i][j-1],c[i-1][j]);
            }
            cnt=max(cnt,c[i][j]);
        }
    }
    return cnt;
}
int main(){
    int n;
    string X,Y;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>X>>Y;
        cout<<LCS(X,Y)<<endl;
    }
    return 0;
}


Measured memory_bytes: 7076
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

class NoNeed
{
private:
	int n, k;
	int sum;
	vector<vector<bool> > l_dp;
	vector<vector<bool> > r_dp;
	vector<int> a;
public:
	NoNeed(){
		cin >> n >> k;
		a.resize(n);
		sum = 0;
		for (int i = 0; i < n; ++i)
		{
			cin >> a[i];
			sum += a[i];
		}
		l_dp = vector<vector<bool> >(n, vector<bool>(k+1, false));
		r_dp = vector<vector<bool> >(n, vector<bool>(k+1, false));
	}

	bool is_valid(int med){
		if(a[med] >= k){
			return true;
		}

		for (int i = k - a[med]; i < k; ++i)
		{
			if(med == 0){
				if(r_dp[1][i]) return true;
				continue;
			}

			if(med == n-1){
				if(l_dp[n-2][i]) return true;
				continue;
			}

			for (int j = 0; j <= i; ++j)
			{
				if(l_dp[med-1][j] && r_dp[med+1][i-j]){
					return  true;
				}
			}
		}
		return false;
	}

	void set_dp(){
		l_dp[0][0] = true;
		if(a[0] <= k) l_dp[0][a[0]] = true; 
		for (int i = 1; i < n; ++i)
		{
			for (int j = 0; j <= k; ++j)
			{
				if(l_dp[i-1][j] || (j - a[i] >= 0 && l_dp[i-1][j - a[i]]) ){
					l_dp[i][j] = true;
				}
			}
		}
		r_dp[n-1][0] = true;
		if(a[n-1] <= k) r_dp[n-1][a[n-1]] = true;
		for (int i = n-2; i >= 0; --i)
		{
			for (int j = 0; j <= k; ++j)
			{
				if(r_dp[i+1][j] || (j -  a[i] >= 0 && r_dp[i+1][j - a[i]]) ){
					r_dp[i][j] = true;
				}
			}
		}

	}

	void exec(){
		sort(a.begin(), a.end());
		// if(sum < k){
		// 	cout << n << endl;
		// 	return;
		// }

		set_dp();
		int left = 0;
		int right = n-1;
		while(left < right){
			int med = (left + right) / 2;
			if(is_valid(med)){
				right = med;
			}else{
				left = med + 1;
			}
		}
		if(is_valid(n-1) == false){
			cout << n << endl;
			return;
		}
		cout << right << endl;
		// for (int i = 0; i < n; ++i)
		// {
		// 	if(is_valid(i)){
		// 		cout << i << endl;
		// 		return;
		// 	}
		// }
		// cout << n << endl;


	}
};


int main(){
	NoNeed nn = NoNeed();
	nn.exec();
}

Measured memory_bytes: 6912
let nk = stdin.ReadLine().Split() |> Array.map int64
let k = nk.[1]
let a = stdin.ReadLine().Split() |> Array.map int64 |> Array.toList

let rec f ls acc =
 match ls with
 | [] -> acc
 | hd :: tl -> let count = (tl |> List.map (fun x -> if x < hd then 1 else 0) |> List.sum)
               f tl (acc + count)

let syokou = (f a 0 |> int64)
let nikou = (f (a @ a) 0 |> int64)

let g(x)= x % 1000000007L
let h(x,y)= g(g(x) - g(y) + 1000000007L)
let i(x,y) = g(g(x) * g(y))
let kk = if k % 2L = 0L then g(g(k / 2L) * g(k + 1L)) else g(g(k) * g((k + 1L) / 2L))

g(i(h(nikou,i(syokou,2L)),kk) + i(h(i(syokou,3L),nikou),k))
|>stdout.WriteLine

Measured memory_bytes: 34960
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	string S;
	cin>>S;
	ll N=S.length();
	string S1=S.substr(0,(N-1)/2);
	string S2=S.substr((N-1)/2+1,(N-1)/2);
	string SR=S;
	reverse(SR.begin(),SR.end());
	string S1R=S1;
	reverse(S1R.begin(),S1R.end());
	string S2R=S2;
	reverse(S2R.begin(),S2R.end());
	if(S==SR && S1==S1R && S2==S2R)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	

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


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(int argc,char** argv){
    int n;
    scanf("%d",&n);
    int a[10000],b[10000],index=0;
    int m=n;
    if(n%2==0)m++;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(i+j!=m){
                a[index]=i;
                b[index++]=j;
            }
        }
    }
    printf("%d\n",index);
    for(int i=0;i<index;i++){
        printf("%d %d\n",a[i],b[i]);
    }
    return 0;
}




Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function bfsPath(e::Array{Array{Int,1}},p)
	n=length(e)
	v=-ones(Int,n)
	v[p]=0
	c=1
	s=Int[]
	for i in 1:length(e[p])
		push!(s,e[p][i])
		v[e[p][i]]=1
		c+=1
	end
	bef=0
	j=p
	while !isempty(s)&&c<n
		j=shift!(s)
		for i in 1:length(e[j])
			if v[e[j][i]]<0
				push!(s,e[j][i])
				v[e[j][i]]=v[j]+1
				c+=1
			end
		end
	end
	v
end

function main()
	n = readline() |> parseInt
	e = [Int[] for i in 1:n]
	for i in 1:n-1
		a,b = readline() |> split |> parseMap
		push!(e[a],b)
		push!(e[b],a)
	end
	f = bfsPath(e,1)
	u = indmax(f)
	g = bfsPath(e,u)
	d = maximum(g)
	println(d%3==1?"Second":"First")
end
main()


Measured memory_bytes: 169280
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    ll c = 0;
    FOR(i, 1, N + 1) {
        if (i % 3 != 0 && i% 5 != 0) c += i;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3624
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    if b%a == 0:
        print(a+b)
    else:
        print(b-a)
    return

#B
def B():
    n,m = LI()
    d = defaultdict(int)
    for i in range(n):
        l = LI()
        for j in range(1,len(l)):
            d[l[j]] += 1
    ans = 0
    for i in d.values():
        if i == n:
            ans += 1
    print(ans)
    return

#C
def C():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a,a)
    n = I()
    a = LI()
    g = a[0]
    for i in range(1,n):
        g = gcd(g,a[i])
    print(g)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 59248
#include<iostream>
using namespace std;
int n,fl=-1,now=7;
int main()
{
     int i;
     cin>>n;
     for(i=1;i<=1000000;i++)
     {
         now=now*10%(9*n);
         if(now==7)
         {
             fl=i;
             break;
         }
     }
     cout<<fl;
     system("pause");
}
             


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

void func(long long a, long long b, long long c){

    set<lli> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);

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

}

int main(){
    // cout << fixed << setprecision(5);

    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    func(a, b, c);
    return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main(){
string s;
cin>>s;
if(s=="Sunny")
    cout<<"Cloudy";
if(s=="Cloudy")
    cout<<"Rainy";
if(s=="Rainy")
    cout<<"Sunny";
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, vs, n, m) vector<vector<T>> vs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]

using namespace std;
using ll = long long;

int main(void){
    Cin(int, x);
    Cin(int, y);
    Cin(int, z);
    Cout((x-z)/(y+z));
}


Measured memory_bytes: 256
N = int(input())
# N = 1000000

def fizzbuzz_sum(N):
    ans = 0
    for i in range(1, N+1):
        if i % 3 == 0:
            continue
        elif i % 5 == 0:
            continue
        elif i % 15 == 0:
            continue
        else:
            ans += i
    return ans

print(fizzbuzz_sum(N))

Measured memory_bytes: 9112
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
//素数列挙
#define P 60000
vl primes;
ll primenum[P];
bool bprime[P*30];
ll searchprime(ll max){//発見した素因数の個数を返す
  bprime[1]=false;
  for(ll i=2;i<=max;i++){
    bprime[i]=true;
  }
  ll nowprimes=1;
  primes.pb(2);
  for(ll i=4;i<max*30;i+=2){
    bprime[i]=false;
  }

  for(ll i=3;i<max/2;i+=2){
    if(bprime[i]==true){
      //primes[nowprimes]=i;
      primes.pb(i);
      nowprimes++;
      for(ll j=2;i*j<=max*30;j++){
        bprime[i*j]=false;
      }
    }
  }
  return nowprimes;
}
ll nn;
void primenum_factorization(ll n){//primesで素因数分解の結果をprimenumに格納
  rep(i,P){
    primenum[i]=0;
  }
  for(int i=0;primes[i]<=n;i++){
    ll pren = n;
    while(1){
      if(pren%primes[i]==0){
        primenum[i]++;
        pren/=primes[i];
      }else{
        break;
      }
    }
  }
  return;
}

int flag=0;
int n;
deque<ll> search(deque<ll> list,int nowp){
  int f=0;
  if(list.size()>=5){
    for(int i1=0;i1<list.size()-4 && f==0;i1++){
        for(int i2=i1+1;i2<list.size()-3 && f==0;i2++){
          for(int i3=i2+1;i3<list.size()-2 && f==0;i3++){
            for(int i4=i3+1;i4<list.size()-1 && f==0;i4++){
              for(int i5=i4+1;i5<list.size() && f==0;i5++){
                if(bprime[list[i1]+list[i2]+list[i3]+list[i4]+list[i5]]==false){
                  continue;
                }else{
                  f=1;
                  break;
                }
              }
            }
          }
        }
      }
  }
  if(f==1){
    return {};
  }
  if(list.size()==n){
    flag=1;
    return list;
  }else{
    while(nowp<primes.size()){
      list.pb(primes[nowp]);
      deque<ll> tmp=search(list,nowp+1);
      if(tmp.size()!=0){
        return tmp;
      }
      list.pop_back();
      nowp++;
    }
    return {};
  }
}
int main(void){
  cin>>n;
  ll max1=searchprime(60000);
  //deque<ll> list=search({},0);
  int now=0;
  int nowp=0;
  while(now<n){
    if(primes[nowp]%5==1){
      cout<<primes[nowp]<<" ";
      now++;
    }
    nowp++;
  }
  return 0;
}

Measured memory_bytes: 2048