akhauriyash/Code-Regression huggingface dataset:
public class Main {

  private static void solve() {
    int n = ni();
    int[] a = na(n);
    int q = ni();

    long s = 0;
    int[] d = new int[100001];
    for (int v : a) {
      d[v]++;
      s += v;
    }

    for (int i = 0; i < q; i++) {
      int b = ni();
      int c = ni();

      int cnt = d[b];
      d[c] += cnt;
      d[b] = 0;
      s += (long) cnt * (c - b);
      System.out.println(s);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 60072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int N;string S;cin>>N>>S;
  int ans;
  REP(i,0,S.size()){
    ans =(S.at(i)-65+N)%26;
    cout<<char(ans+65);
  }
  cout<<"\n";
}


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

int main(){
    int a;
    cin >> a;
    vint A(a);
    rep(i,a) cin >> A[i];
    sort(A.begin(),A.end());
    if(A[a/2-1] != A[a/2]){
        cout << A[a/2] - A[(a/2)-1] << endl; 
    }
    else cout << 0 << endl;
    
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
  int a,b,x,a_high=0;
  scanf("%d %d",&a,&b);
  x = b - a;
  for(int i=1;i<x;i++){
    a_high += i;
  }
  printf("%d\n",a_high-a);
  return(0);
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, p;
  cin >> n >> p;
  
  int odd = 0, even = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a % 2 == 1) odd++;
    else even++;
  }
  
  vector<vector<ll>> c(102, vector<ll>(102));
  for (int i = 0; i <= 100; i++) c[0][i] = 1;
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
  }
  
  ll ans = 0;
  if (p == 0) {
    for (int i = 0; i <= odd; i += 2) {
      ans += pow(2, even) * c[odd][i];
    }
  }
  else {
    for (int i = 1; i <= odd; i += 2) {
      ans += pow(2, even) * c[odd][i];
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll a, b;
    cin >> a >> b;
    cout << ((a * b % 2) ? "Odd" : "Even") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define nl '\n'
#define fillar(x) for(int i=0;i<x;i++)cin>>ar[i]
#define qquery int query;cin>>query;while(query--)
#define benfero freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
vector<int> adj[100005];
int dp[100005];
int dfs(int node){
	if(adj[node].size()==0) return 0;
	if(dp[node]!=-1) return dp[node];
	int t=0;
	for(int j=0;j<adj[node].size();j++){
		t=max(t,dfs(adj[node][j]));
	}
	return dp[node]=t+1;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//benfero
	int n,m,i;
	cin>>n>>m;
	memset(dp,-1,sizeof(dp));
	for(i=0;i<m;i++){
		int a,b;
		cin >>a>>b;
		adj[a].pb(b);
	}
	int ans=0;
	for(i=1;i<=n;i++){
		dfs(i);
	}
	for(int i=1;i<=n;i++){
		ans=max(ans,dp[i]);
	}
	cout<<ans;
}


Measured memory_bytes: 8192
open System
open System.Collections.Generic;

let N =stdin.ReadLine()|>int
let B= stdin.ReadLine().Split()|> Array.map int
[<EntryPoint>]
let sf argv = 
    let fn i = if i=0 then B.[0] elif i=N-1 then B.[N-2] else min B.[i] B.[i-1]
    let mutable ans = 0
    for i in [0..N-1] do 
        ans <- ans + fn i
    printfn "%d" ans
    0


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

int main() {
    int N,L;
    cin >> N >> L;
    vector<string> S(N);

    rep(i,N)
        cin >> S.at(i);
    sort(S.begin(), S.end());

    rep(i,N)
        cout << S.at(i);
    cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
  while ( u != NIL && k != u->key ) {
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while ( x != NIL ) {
    y = x;
    if ( z->key < x->key )
      x = x->left;
    else
      x = x->right;
  }

  if ( y == NIL ) {
    root = z;
  } else {
    if ( z->key < y->key )
      y->left = z;
    else
      y->right = z;
  }
}

void inorder(Node *u) {
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    cin >> com;
    if ( com[0] == 'f' ) {
      scanf("%d", &x);
      Node *t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com == "insert" ) {
      scanf("%d", &x);
      insert(x);
    } else if ( com == "print" ) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 15816
#include <bits/stdc++.h> 
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
        	
const int ppr = 257;
const ll INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e6 + 123;
const ld pi = acos(-1.0);
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
 
main() {             	
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
 
//	srand(time(NULL));

//	speed;

	int n;
	string s, t;
	cin >> n >> s >> t;
	for(int i = 0; i < s.size(); i++)
		cout << s[i] << t[i];
        
    return 0;                                        
}

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

long long dp[51][51][50*51];

int main(){
    int N,A; cin >> N >> A;
    int x[N];
    for(int i=0;i<N;i++){
        cin >> x[i];
    }
    memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=51*50;k>=0;k--){
                if(k-x[i]>=0){
                    dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
                }
                dp[i+1][j][k]+=dp[i][j][k];
            }
        }
    }
    long long ans=0;
    for(int i=1;i<=N;i++){
        ans+=dp[N][i][A*i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 52096
#include <iostream>
using namespace std;
int main(){
  string n;cin>>n;
  long long k;cin>>k;
  for(int i = 0; n.size() > i; i++){
    if(n[i]!='1'){
      cout << n[i] << endl;
      return 0;
    }
    if(k-1==i){
      cout << 1 << endl;
      return 0;
    }
  }
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        ans += 2 * min(x, k - x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
// ここから開始
int main(){
  int r;
  cin>>r;
  cout<<r*r<<endl;
  return 0;
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 078_arc_b / Link: https://abc067.contest.atcoder.jp/tasks/arc078_b?lang=en  ----- */
/* ------問題------

フェネックとすぬけくんがボードゲームで遊んでいます。
このボードゲームには 1 番から N 番までの番号がついた N 個のマスと、マスどうしをつなぐ N−1 本の道が存在しています。 ai 番のマスと bi 番のマスは i 番目の道を介して隣り合っています。どの 2 つのマスも隣接するマスをいくつか辿って必ず辿り着くことが可能です。すなわち、グラフ理論の言葉を用いると、マスと道から構成されるグラフは木です。
はじめに 1 番のマスは黒く、N 番のマスは白く塗られています。その他のマスはまだ色が塗られていません。 先手のフェネックと後手のすぬけくんは残りのマスに交互に色を塗ります。 自分の手番において、2 人はそれぞれ以下のような行動を行います。
フェネック：黒く 塗られたマスに隣接したマスであって、色が塗られていないマスを 1 つ選んで 黒く 塗る。
すぬけくん：白く 塗られたマスに隣接したマスであって、色が塗られていないマスを 1 つ選んで 白く 塗る。
手番のプレイヤーがマスに色を塗ることができなかったとき、敗者となります。フェネックとすぬけくんが最適に行動したとき勝者はどちらか判定してください。

-----問題ここまで----- */
/* -----解説等-----

与えられるグラフは木なので、ガンガン遠くに行って良い。
お互いの反対側には到達できないので考えるのは境界の位置だけで良い。
これは0,N-1の中心の位置であるが、木なのでこれは一点しか無い。また先攻が少し有利なので中心的な場所も先攻の場所となる。
したがって木上の距離を記録しこれを比較すれば良い。

----解説ここまで---- */

LL N;

LL ans = 0LL;
void dfs(int v, int p, int d, VVI& G, VI& dist) {
	dist[v] = d;
	FOR(i, 0, SZ(G[v])) {
		int nx = G[v][i];
		if (nx != p) {
			dfs(nx, v, d + 1, G, dist);
		}
	}
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N;
	VVI G(N);
	FOR(i, 0, N - 1) {
		int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}
	VI distF(N, -1);
	VI distS(N, -1);
	dfs(0, -1, 0, G, distF);
	dfs(N-1, -1, 0, G, distS);
	int Fcnt = 0;
	FOR(i, 0, N) {
		if (distF[i] <= distS[i])Fcnt++;
	}

	if (Fcnt > N - Fcnt) {
		cout << "Fennec" << endl;
	}
	else cout << "Snuke" << endl;

	return 0;
}


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

#define FOR(type, i, a, b) for (type i = (a); i < (b); ++i)

const char BLACK = '#';
const char WHITE = '.';

int dx4[]={1, 0,-1, 0};
int dy4[]={0, 1, 0,-1};

char table[1000][1000];

int main(void) {
  int H, W; cin >> H >> W;
  vector<pair<int, int> > bl;
  FOR(int, h, 0, H) FOR(int, w, 0, W) {
    char a; cin >> a; table[h][w] = a;
    if (a == BLACK) bl.push_back(make_pair(h, w));
  }

  int a = 0;
  while (1) {
    int flag = 1;
    vector<pair<int, int> > bl2;
    for (pair<int, int> b : bl) {
      int h = b.first;
      int w = b.second;
      FOR(int, i, 0, 4) if (0 <= h+dy4[i] && h+dy4[i] < H && 0 <= w+dx4[i] && w+dx4[i] < W) {
        if (table[h+dy4[i]][w+dx4[i]] == WHITE) {
          flag = 0;
          bl2.push_back(make_pair(h+dy4[i], w+dx4[i]));
          table[h+dy4[i]][w+dx4[i]] = BLACK;
        }
      }
    }

    if (flag) break;
    else {
      a++;
      bl = bl2;
    }
  }
  cout << a << endl;

  return 0;
}


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

const int maxn = 1e3 + 20;
int vis[maxn],n;
double x[maxn],y[maxn],r[maxn],dist[maxn],mp[maxn][maxn];

void SPFA(int s)
{
    queue<int>q;
    for(int i = 1;i <= n;i++) dist[i] = 1e10;
    memset(vis,0,sizeof(vis));
    while(!q.empty()) q.pop();
    dist[s] = 0;
    vis[s] = 1;
    q.push(s);

    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        vis[v] = 0;
        for(int i = 1;i <= n;i++)
        {
            if(dist[i] > dist[v] + mp[v][i])
            {
                dist[i] = dist[v] + mp[v][i];
                if(!vis[i])
                {
                    vis[i] = 1;
                    q.push(i);
                }
            }
        }
    }
}

int main()
{
    while(scanf("%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2]) != EOF)
    {
        scanf("%d",&n);
        n += 2;
        r[1] = r[2] = 0;
        mp[1][2] = mp[2][1] = sqrt((x[1] - x[2]) * (x[1] - x[2]) + (y[1] - y[2]) * (y[1] - y[2]));
        for(int i = 3;i <= n;i++)
        {
            scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
        }
        for(int i = 1;i <= n;i++)
        {
            for(int j = 1;j <= n;j++)
            {
                mp[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
                mp[i][j] -= r[i] + r[j];
                if(mp[i][j] < 0)
                {
                    mp[i][j] = 0;
                }
            }
        }
        SPFA(1);
        printf("%.10f\n",dist[2]);
    }
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  int n; cin >> n;
  int a; cin >> a;
  REP(i, n-1) {
    int b; cin >> b;
    a = __gcd(a, b);
  }
  cout << a << endl;

}
























Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void){
  long long int n;
  long long int max=0;
  long long int next=0;
  long long int a[20005000];
  long long int ans;
  long long int i;
 
  scanf("%lld",&n);
  for (i=0; i<n; i++){
    scanf("%lld", &a[i]);
    if(max<=a[i]){
      next=max;
      max=a[i];
    }else if(next<a[i]){
      next=a[i];
    }
  }
  
  for(i=0; i<n; i++){
    ans=max;
    if(ans==a[i]){
      ans=next;
    }
    printf("%lld\n",ans);
  }
    
  
  return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, r, p, h, k;
string s, t;

ll node[4000000];
ll fours[4000000];
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> s;
	if(s.length()==3) reverse(all(s));
	cout << s;

}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 237980
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <string>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

void count_head_tail_char(int num, string s) {
  }

int main(void){
  int N;
  int counter = 0;
  cin >> N;

  string s[N];
  int b_str_a = 0;
  int b_str_ = 0;
  int _str_a = 0;

  for (int i = 0; i < N; i++) {
    cin >> s[i];
    int len = s[i].length() - 1;

    for (int j = 0; j < len+1; j++) {
      char tmp = s[i][j-1];
      char cur = s[i][j];

      if (tmp == 'A' && cur == 'B') counter ++;
    }

    if (s[i][0] == 'B' && s[i][len] == 'A') b_str_a ++;
    else if (s[i][0] == 'B') b_str_ ++;
    else if (s[i][len] == 'A') _str_a ++;
  }

  if (b_str_a > 0) {
    counter += (b_str_a - 1);
  }

  if (_str_a > 0 && b_str_a > 0) {
    counter ++;
    _str_a --;
  }

  if (b_str_ > 0 && b_str_a > 0) {
    counter ++;
    b_str_ --;
  }

  counter += min(_str_a, b_str_);

  cout << counter << '\n';
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int calc(string x,string y){
  set<char> stx;
  set<char> sty;
  rep(i,x.size()){
    stx.insert(x.at(i));
  }
  rep(i,y.size()){
    sty.insert(y.at(i));
  }
  string s;
  set_intersection(stx.begin(), stx.end(),sty.begin(), sty.end(), back_inserter(s));
  return s.size();
}
int main() {
  cout << fixed << setprecision(10);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i = 1; i<=n-1; i++){
    string x = s.substr(0,i);
    string y = s.substr(i);
    ans = max(ans,calc(x,y));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main ()
{
	int N,i,t,c=0;
	scanf("%d",&N);
	
	for(i=1;i<=N;i++)
	{
		t=N%i;
		if(t==0&&N/i<10&&i<10)
		{
			printf("Yes\n");
			c=1;
			break;
		}

		
	}
	if(c==0)
		{
			printf("No\n");
		}

	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
n,a,b = map(int, input().split())
x = [int(i) for i in input().split()]

ret = 0
for i in range(n-1):
    if (x[i+1]-x[i])*a>=b:
        ret += b
    else:
        ret += (x[i+1]-x[i])*a
print(ret)


Measured memory_bytes: 14224
import java.io.*;
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        for (int i = 1; i <= n; i++) {
            int x = i;
            if (x % 3 == 0) {
                System.out.printf(" %d", i);
                continue;
            }
            while (x > 0) {
                boolean endFlag = false;
                if (x % 10 == 3) {
                    System.out.printf(" %d", i);
                    endFlag = true;
                }
                if (endFlag) break;
                x /= 10;
            }
        }
    	System.out.printf("\n");           
    }
}


Measured memory_bytes: 37700
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define ll long long

using namespace std;


int main() {
  char x; string s;
  cin >> s; x = s[0];

  cout << char(x + 1) << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>

using namespace std;

int main(){
    int n,z,w;
    cin >> n >> z >> w;
    int card[2000];
    for(int i = 0; i < n; i++){
        cin >> card[i];
    }
    if(n==1){
        cout << abs(card[n-1] - w) << endl;
    }else{
        cout << max(abs(card[n-2] - card[n-1]), abs(card[n-1] - w)) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define rrep(i,s,e) for(int (i) = (s);(i) >= (e);(i)--)

int a[505][505];
vector<int> px;
vector<int> py;
vector<int> mx;
vector<int> my;

signed main() {
  int h,w;cin>>h>>w;

  if(h==1&&w==1)
  {
    cout << 0 << endl;
    return 0;
  }
  rep(i,0,h-1)rep(j,0,w-1)cin>>a[i][j];

  rep(i,0,h-1)rep(j,0,w-1)
  {
    if(i==h-1 && j==w-1) break;

    if(a[i][j]%2)
    {
      px.push_back(i);
      py.push_back(j);
      
      if(j!=w-1)
      {
        mx.push_back(i);
        my.push_back(j+1);
        a[i][j+1]++;
      }
      else
      {
        mx.push_back(i+1);
        my.push_back(j);
        a[i+1][j]++;
      }
    }
  }
  if(mx.empty())
  {
    cout << 0 << endl;
    return 0;
  }
  cout << mx.size() << endl;
  rep(i,0,mx.size()-1) cout << px[i]+1 << " " << py[i]+1 <<" "<<mx[i]+1<<" "<<my[i]+1<<endl;
  
}


Measured memory_bytes: 8148
#include<iostream>
using namespace std;
#define MAX 100000
 
int parent(int i){ return i/2;}
 
int left(int i){ return 2*i;}
 
int right(int i){ return 2*i+1;}
 
int main(){
  int H,i,A[MAX+1];//1をはじめに考える
 
  cin>>H;
  for(int i=1;i<=H;i++){
    cin>>A[i];
  }
 
  for(int i=1;i<=H;i++){
    cout<<"node "<<i<<": key = "<<A[i]<<", ";
    if(parent(i)>=1) cout<<"parent key = "<< A[parent(i)]<<", ";
    if(left(i)<=H) cout<<"left key = "<< A[left(i)]<<", ";
    if(right(i)<=H) cout<<"right key = "<< A[right(i)]<<", ";
    cout<<endl;
  }
  return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int A = a * b;
    int B = c * d;

    if(A >= B ){
        cout << A << endl;
    }else{
        cout << B << endl;
    }
    return 0;
}

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


public class C
{
	public static void Main()
	{
		string SP = Console.ReadLine();
		string T = Console.ReadLine();

		int start = -1;
		for(int i = 0; i <= SP.Length - T.Length; i++)
		{
			bool isMatch = true;
			for(int j = 0; j < T.Length; j++)
			{
				if((SP[i + j] != '?') && (SP[i + j] != T[j]))
				{
					isMatch = false;
					break;
				}
			}
			if(isMatch)
				start = i;
		}

		StringBuilder sb = new StringBuilder();
		if(start == -1)
		{
			sb.Append("UNRESTORABLE");
		}
		else
		{
			for(int i = 0; i < start; i++)
				sb.Append((SP[i] == '?') ? 'a' : SP[i]);
			sb.Append(T);
			for(int i = start + T.Length; i < SP.Length; i++)
				sb.Append((SP[i] == '?') ? 'a' : SP[i]);
		}
		Console.WriteLine(sb);
	}
}





Measured memory_bytes: 13140
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program
{


    static void Main(string[] args)
    {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

        //int val = int.Parse(Console.ReadLine());
        //int[] vals = parseAry(Console.ReadLine().Split(cs));
        //string str = Console.ReadLine();
        //string[] strs = Console.ReadLine().Split(cs);

        //string res="";
        //int res = 0; ;
        //int t = int.Parse(Console.ReadLine());
        //string str = Console.ReadLine();
        //int[] vals = parseAry(Console.ReadLine().Split(cs));
        //int n = int.Parse(Console.ReadLine());
		//string res="";
		int res = 0;
		string str = Console.ReadLine();

		int now=0;
		int ia = 0;
		int ib = 0;
		string flg="0";
		for ( int i = 0; i < str.Length; i++ ) {
			if ( flg == "0" ) { flg = "1"; } else { flg = "0"; }
			if ( str[i] != flg[0] ) { ia++; } else { ib++; }
		}



			Console.WriteLine(Math.Min(ia,ib));


        return;
    }

    //　String[]  ----->  int[]
    static int[] parseAry(string[] str)
    {
        int[] nums = new int[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
        return nums;
    }
    //　String[]  ----->  long[]
    static long[] parseAryL(string[] str)
    {
        long[] nums = new long[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); }
        return nums;
    }

    //文字列を1文字ずつString[]に入れる
    static string[] strAry(String str)
    {
        string[] re = new string[str.Length];
        for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
        return re;
    }

}


Measured memory_bytes: 13280
# include <bits/stdc++.h>
  using namespace std;
# define res(a,b,c) for (int64 a=b ; a<c ; a++)
# define ress(a,b)  for (auto a = b.begin() ; a!=b.end() ; a++) 
# define all(con) con.begin() , con.end()
# define INF (int)1e9  
# define MOD 1000000007
# define pb push_back   
# define mp make_pair
# define f first
# define s second   
# define MAX numeric_limits<int>::max() 
# define MIN numeric_limits<int64>::min()
# define mymin -1000000000000000001
# define mymax 1000000000000000001
# define watch(x) cout<<(#x)<<" is "<<(x)<<endl
# define in(x) cin>>(x)
# define inn(x,y) cin>>(x)>>(y)  
# define out(x) cout<<(x)<<"\n"  
# define outt(x,y) cout<<(x)<<" "<<(y)<<"\n"  
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int64> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int64,int64> pi; 
bool doubleSame(double a, double b)
{ const double eps = 1e-15; return ( abs(a-b)<= eps*abs(a) ); }

int main()
{
	int a,b;
	cin>>a>>b;

	int ans = -1;
	for(int i = (10*b) ; i<=(10*b+9) ; i++)
	{
		if(floor(i*(0.08))==a)
		{
			ans = i;
			break;
		}
	}
	cout<<ans<<"\n";
}


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

int main() {
	char a[15], b[15], c[15];
	int alast, blast;
	alast = blast = 0;
	cin >> a >> b >> c;
	while (a[alast] != '\0') alast++;
	while (b[blast] != '\0') blast++;
	if (a[alast - 1] == b[0] && b[blast - 1] == c[0]) cout << "YES";
	else cout << "NO";
	return 0;
}


Measured memory_bytes: 256
O = input()
E = input()

for i in range(len(E)-1):
    print(O[i]+E[i],end='')
if len(O) == len(E):
    print(O[len(O)-1]+E[len(E)-1])
else:
    print(O[len(O)-2]+E[len(E)-1]+O[len(O)-1])


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> G[5000];
ll A[5000];
int num[5000];
ll dp[5000][5000][2]; //[頂点][何本の辺をきるか][全て正か]
ll dp2[5000][2];
void dfs(int v, int p) {
	num[v] = 1;
	for (int to : G[v]) {
		if (to == p) continue;
		dfs(to, v);
		num[v] += num[to];
	}
	for (int i = 0; i < num[v]; i++) dp2[i][0] = dp2[i][1] = INF;
	dp2[0][0] = A[v];
	if (A[v] > 0) dp2[0][1] = A[v];
	int sum = 1;
	for (int to : G[v]) {
		if (to == p) continue;
		for (int i = sum - 1; i >= 0; i--) {
			ll x = dp2[i][0], y = dp2[i][1];
			dp2[i][0] = dp2[i][1] = INF;
			for (int j = 0; j < num[to]; j++) {
				dp2[i + j][0] = min(dp2[i + j][0], x + dp[to][j][0]);
				if (dp[to][j][0] < 0 || dp[to][j][1] < INF) dp2[i + j + 1][0] = min(dp2[i + j + 1][0], x);
				if (A[v] > 0) {
					dp2[i + j][1] = min(dp2[i + j][1], y + dp[to][j][1]);
					if (dp[to][j][0] < 0 || dp[to][j][1] < INF) dp2[i + j + 1][1] = min(dp2[i + j + 1][1], y);
				}
			}
		}
		sum += num[to];
	}
	for (int i = 0; i < num[v]; i++) {
		dp[v][i][0] = dp2[i][0];
		dp[v][i][1] = dp2[i][1];
	}
}
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i + 1 < N; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0, -1);
	for (int i = 0; i < num[0]; i++) {
		if (dp[0][i][0] < 0 || dp[0][i][1] < INF) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 390016
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#define REL
#endif
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

//#pragma GCC optimize("Ofast")
//#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);
//mt19937_64 gen(41);


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------//
	string s;
	cin >> s;
	if (s.size() != 6) {
		cout << "No";
		return 0;
	}
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes";
	else
		cout << "No";
	//----------------------------------------------//

	return 0;
}




Measured memory_bytes: 256
N, K = map(int, input().split())
H = [int(input()) for i in range(N)]
h = sorted(H)
A=[0]*(N-K+1)
ans=0
for i in range(N-K+1):
    A[i] =h[i+K-1]-h[i]
ans=min(A)
print(ans)

Measured memory_bytes: 11800
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return (ans.x+m)%m;
}
int fact[N];
void calfac(int n ){
fact[0] = 1;
for(int i = 1 ; i <= n+2; i++){
 fact[i] = (((fact[i-1]%mod)*(i%mod))%mod + mod)%mod;
}
 }
int calc(int n , int r){
 if(r > n)return 0;
 if(r == n)return 1;
 int ans = 1;
 ans = ((ans%mod)*(fact[n])%mod + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[n-r] , mod)%mod) + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[r] , mod)%mod) + mod)%mod;
 return (ans+mod)%mod;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a , b , c,d;
cin>>a>>b>>c>>d;
int turn = 1;
while(true){
 if(turn == 1 && b >= c){
  cout<<"Yes"<<endl;
  break;
 }
 else if(turn == 1){
    c-=b;
    turn = turn^3;
    continue;
 }
 if(turn == 2 && d >= a){
  cout<<"No"<<endl;
  break;
 }
 else if(turn == 2){
     a-=d;
     turn = turn^3;
     continue;
 }
}
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 1;
int n, m, i, j, k, z;
long a[MAXN], b[MAXN];
signed main()
{
    ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	scanf("%d %d %d", &n, &m, &k);
	for (i = 1; i <= n; ++i)
		scanf("%d", &a[i]), a[i] += a[i - 1];
	for (i = 1; i <= m; ++i)
		scanf("%d", &b[i]), b[i] += b[i - 1];
	z = 0, i = 0, j = m;
	while (a[i] <= k && i <= n)
	{
		while (b[j] > k - a[i])
			--j;
		if (i + j > z)
			z = i + j;
		++i;
	}
	printf("%d", z);
}

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

const int N = 220;

int n, l, s, a[N];
int mini = N * N, val;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> l;
	for (int i = 0; i < n; i++) {
		a[i] = i + l;
		if(fabs(a[i]) < mini)
			mini = fabs(a[i]), val = a[i];
		s += a[i];
	}
	cout << s - val;
	return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    v = list(map(int, input().rstrip('\n').split()))
    v.sort()
    t = 0
    for i in range(n):
        if i != 0:
            t = (t + v[i]) / 2
        else:
            t += v[i]
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
h, w = map(int, input().split())
n = int(input())
a = [int(i) for i in input().split()]
k = 1
r = a[0]
for i in range(h):
  tmp = []
  for j in range(w):
    if r==0:
      r = a[k]
      k += 1
    tmp.append(k)
    r -= 1
  if i%2==1:
    tmp = tmp[::-1]
  print(*tmp)

Measured memory_bytes: 3700
int_n, int_m, int_x = map(int, input().split())

int_a_ar = list(map(int, input().split()))


to_start = len([x for x in int_a_ar if x < int_x])

to_end = len([x for x in int_a_ar if x > int_x])


cost = to_start if to_start < to_end else to_end

print(cost)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    ll mx[n][n];
    ll mn[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n-i;j++){
            if(i==0){
                mx[j][j+i]=a[j];
                mn[j][j+i]=-a[j];
            }
            else{
                ll t1 = mn[j+1][j+i]+a[j];
                ll t2 = mn[j][j+i-1]+a[j+i];
                ll t3 = mx[j+1][j+i]-a[j];
                ll t4 = mx[j][j+i-1]-a[j+i];
                mx[j][j+i] = t1>t2?t1:t2;
                mn[j][j+i] = t3<t4?t3:t4;
            }
            //cout<<mn[j][j+i]<<" "<<mx[j][i+j]<<"  ";
        }
        //cout<<endl;
    }
    cout<<mx[0][n-1]<<endl;
    return 0;
}


Measured memory_bytes: 140032
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	for(int i=0;; i++){
		int s = x-i;
		int b = x+i;
		bool flag1 = true;
		bool flag2 = true;
		for(const auto& x : p){
			if(s == x) flag1 = false;
			if(b == x) flag2 = false;
		}
		if(flag1){
			cout << s << endl;
			return 0;
		}
		if(flag2){
			cout << b << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[] A = new int[N];
        final int[] counts = new int[N + 1];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            counts[A[i]] += 1;
        }

        long total = 0;
        for (int i = 1; i <= N; i++) {
            int n = counts[i];
            total += choose2(n);
        }

        for (int i = 0; i < N; i++) {
            int n = counts[A[i]];
            System.out.println(total - (n - 1));
        }        
    }

    private static long choose2(long n) {
        return n * (n - 1) / 2;
    }
}


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

int main() {
	int n;
	scanf("%d", &n);
	int arr[n];
	vector<pair<int, int> > v;
	for (int i=0; i<n; i++) {
		scanf("%d", &arr[i]);
		v.push_back({arr[i], i});
	}
	sort(v.begin(), v.end());
	int ans[n];
	for (int i=0; i<n; i++) {
		if (i<n/2) ans[v[i].second]=v[n/2].first;
		else ans[v[i].second]=v[n/2-1].first;
	}
	for (int i=0; i<n; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 5488
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(n);++i)

template<class T>void z_algorithm(T &s, vector<int> &ans) {
  ans.resize(s.size(), 0);
  for(int i = 1, j = 0; i < s.size(); i++) {
    if (i + ans[i - j] < j + ans[j]) {
      ans[i] = ans[i - j];
    } else {
      int k = max(0, j + ans[j] - i);
      while (i + k < s.size() && s[k] == s[i + k]) ++k;
      ans[i] = k;
      j = i;
    }
  }
  ans[0] = (int)s.size();
}

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

  int A[N], B[N];
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];

  vi diff;
  rep(i, N) diff.push_back(B[i%N] ^ B[(i+1)%N]);
  diff.push_back(-1);
  rep(i, 2*N) diff.push_back(A[i%N] ^ A[(i+1)%N]);

  vi res;
  z_algorithm(diff, res);

  rep(i, N) {
    if (res[N+1+i] == N)
      cout << i << " " << (A[i] ^ B[0]) << endl;
  }
  return 0;
}


Measured memory_bytes: 11500
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste
// #include "UnionFind.h"

signed main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<int>> dp(H + 1, vector<int>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int k = 0; k < (1LL << (W - 1)); ++k) {
                bool check = true;
                for (int l = 0; l < W - 2; ++l) {
                    if ((k & (1LL << l)) && (k & (1LL << (l + 1)))) {check = false; break;}
                }
                if (!check) continue;

                if ((j >= 1) && (k & (1LL << (j - 1)))) {
                    dp[i + 1][j - 1] += dp[i][j];
                    dp[i + 1][j - 1] %= MOD;
                } else if ((j <= W - 2) && (k & (1LL << j))) {
                    dp[i + 1][j + 1] += dp[i][j];
                    dp[i + 1][j + 1] %= MOD;
                } else {
                    dp[i + 1][j] += dp[i][j];
                    dp[i + 1][j] %= MOD;
                }
            }
        }
    }
    cout << dp[H][K - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double INF = 100000;
int main(){
  cout << fixed << setprecision(4);
  while (1){
    int D, E;
    cin >> D >> E;
    if (D == 0 && E == 0){
      break;
    }
    double ans = INF;
    for (int i = 0; i <= D; i++){
      ans = min(ans, abs(sqrt(i * i + (D - i) * (D - i)) - E));
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3228
m = [int(i) for i in input().split()]
for i in range(len(m)):
    if(m[0]>m[1]):
        m[0],m[1] = m[1],m[0]
    elif(m[1]>m[2]):
        m[1],m[2] = m[2],m[1]
print("{0} {1} {2}".format(m[0],m[1],m[2]))


Measured memory_bytes: 5604
def resolve():
    A,B, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = min(a) + min(b)
    for i in range(m):
        x, y, c = map(int, input().split())
        ans = min(ans, a[x - 1] + b[y - 1] - c)
    print(max(ans, 0))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 18612
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-04-26 20:09:24
 * @LastEditTime: 2020-04-26 20:10:55
 * @FilePath: \VSC\C++\Practice\AC abc164 C.cpp
 */
#include<bits/stdc++.h>
using namespace std;

int n;
set<string> st;
signed main(){
    string s;
    scanf("%d",&n);
    register int i;

    for(i=1;i<=n;++i){
        cin>>s;
        st.insert(s);
    }

    printf("%d\n",st.size());
    return 0;
}

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

int main(){
  ull x,y;
  cin >> x >> y;
  ull n = x;
  ull ans = 0;
  while( n <= y ){
    n *= 2;
    ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  bool flag = true;
  int ret = 0;
  while (flag) {
    flag = false;
    for (int i = N-1; 1 <= i; i--) {
      if (A[i] < A[i-1]) {
        swap(A[i], A[i-1]);
        flag = true;
        ret++;
      }
    }
  }
  cout << A[0];
  for (int i = 1; i < N; i++) cout << ' ' << A[i];
  cout << endl;
  cout << ret << endl;
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <math.h>

#define SQ(x) ((x) * (x))

int main(void)
{
    int s;
    int i;
    double x1, x2, x3;
    double y1, y2, y3;
    double a, b, c, d, e, f;
    double l, m, n;
    
    scanf("%d", &s);
    for (i = 0; i < s; i++){
        scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
        
        a = (x1 - x2);
        b = (y1 - y2);
        c = -1 * (SQ(x1) - SQ(x2) + SQ(y1) - SQ(y2));
        d = (x1 - x3);
        e = (y1 - y3);
        f = -1 * (SQ(x1) - SQ(x3) + SQ(y1) - SQ(y3));
        
        l = (c * e - b * f) / (e * a - b * d);
        m = (d * c - a * f) / (d * b - e * a);
        
        n = -1 * (SQ(x1) + SQ(y1) + l * x1 + m * y1);
        
        printf("%.3f %.3f %.3f\n", l / -2.0, m / -2.0, sqrt(SQ(l) + SQ(m) - 4 * n) / 2.0);
    }
    
    return (0);
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}


ll N;

int main(int argc, char **argv)
{
	cin >> N;
	auto dp = make_vec<ll>(N+1, 4, 4, 4);
	dp[0][0][0][0] = 1;

	REP(n, N)REP(a, 4)REP(b, 4)REP(c, 4)REP(d, 4)
	{
		if (b == 1 && c == 2 && d == 3) continue;
		if (b == 1 && c == 3 && d == 2) continue;
		if (b == 2 && c == 1 && d == 3) continue;
		if (a == 1 && b == 2 && d == 3) continue;
		if (a == 1 && c == 2 && d == 3) continue;
		(dp[n+1][b][c][d] += dp[n][a][b][c]) %= MOD;
	}

	ll res{0};
	REP(a, 4)REP(b, 4)REP(c, 4)
		(res += dp[N][a][b][c]) %= MOD;
	std::cout << res << std::endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#define int long long

signed main(){
	int N, M;
	scanf("%lld%lld", &N, &M);
	if(2 * N > M){
		printf("%lld\n", M / 2);
	}
	else{
		printf("%lld\n", N + (M - 2 * N) / 4);
	}
	return 0;
}

Measured memory_bytes: 128