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

inline void solve(){
    int x;
    cin >> x;
    cout << 1 - x << endl;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif

    //int t;
    //cin >> t;
    //while(t--)
    solve();

    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>

using namespace std;

int main(void){
    string S;
    cin >> S;
    int n;
    n = S.size();
    int flag = 0;
    if(n%2 == 1){
        flag = 10;
    }
    for(int i=0; i<n; i++){
        if(i%2 == 0){
            if(S[i] == 'h'){
                flag += 1;
            }
        }else{
            if(S[i] == 'i'){
                flag += 1;
            }
        }

    }
    if(flag == n){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    long H=s.nextLong();
    long cnt=0;
    long plus=1;
    for(;;){
    if(H==1) break;
    H/=2;
    cnt+=plus;
    plus*=2;
    }
    System.out.println(cnt+plus);
  }  
}

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

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXS 510

int n;

int main(){
	
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	
	VVL dp(n,VL(n,LONG_LONG_MAX));
	VVL pref(n,VL(n));
	VVI tab(n,VI(n));
	
	FOR(i,0,n-1){
		FOR(j,0,n-1){
			if(i==j)
				continue;
			cin>>tab[i][j];
		}
	}
	
	FOR(dl,1,n){
		REP(i,n){
			int j=dl+i;
			if(j>=n)
				break;
			if(dl==1){
				pref[i][j]=tab[i][j];
				pref[j][i]=tab[j][i];
			}
			else{
				pref[i][j]=pref[i][j-1]+pref[i+1][j]-pref[i+1][j-1]+tab[i][j];
				pref[j][i]=pref[j-1][i]+pref[j][i+1]-pref[j-1][i+1]+tab[j][i];
			}
		}
	}
	
	REP(i,n){
		if(i==0){
			FOR(j,0,n-1)
				dp[0][j]=min(dp[0][j],pref[0][j]);
		}
		else{
			FOR(j,i,n-1)
				REP(k,i)
					dp[i][j]=min(dp[i][j],dp[k][i-1]+pref[i][j]+pref[j][0]-pref[j][k]-pref[i-1][0]+pref[i-1][k]);
		}
	}
	
	LL wyn=LONG_LONG_MAX;
	REP(i,n)
		wyn=min(wyn,dp[i][n-1]);
	cout<<wyn;
	
	return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 1e2 + 5;

int n, a[N];

void code() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    sort(a, a + n);

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (a[i] == a[j] or a[j] == a[k] or a[i] == a[k]) continue;
                if (a[i] + a[j] > a[k] and a[j] + a[k] > a[i] and a[i] + a[k] > a[j]) cnt++;
            }
        }
    }

    cout << cnt << "\n";
}

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

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}

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

#define fastIO      ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define asc(s)      sort(s.begin(), s.end())
#define des(s)      sort(s.rbegin(), s.rend())
#define pb(x)       push_back(x)
#define mp(x, y)    make_pair(x, y)
#define all(v)      v.begin(), v.end()
#define rev(v)      reverse(v.begin(), v.end())
#define lower(s)    transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s)    transform(s.begin(), s.end(), s.begin(), ::toupper);
#define MOD         1000000007
#define PI          3.14159265358979

typedef long long ll;

template <typename TH>
void _dbg(const char *sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; }
template <typename TH, typename... TA>
void _dbg(const char *sdbg, TH h, TA... t)
{
    while (*sdbg != ',')
    {
        cerr << *sdbg++;
    }
    cerr << "=" << h << ",";
    _dbg(sdbg + 1, t...);
}

#ifndef ONLINE_JUDGE
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug
#endif

template <class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template <class T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string> beg(buf), end;
    vector<string> list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiouAEIOU";
    if (find(s.begin(), s.end(), c) != s.end())     return true;
    return false;
}

vector <ll> sieve(ll n)
{
    vector<bool> prime(n + 1, true);
    prime[0] = prime[1] = 0;

    for (int i = 2; i * i <= n; i++)
    {
        if (prime[i])
            for (int j = i * i; j <= n; j += i)
            {
                prime[j] = 0;
            }
    }

    vector <ll> p;

    for(int i=2; i<=prime.size();i++)
        if(prime[i])
            p.pb(i);
    
    return p;        
}

bool isprime(int n)
{
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
            return false;
    }

    return true && (n!=1);
}

int ncr(ll n, ll r) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 

    C[0] = 1; 

    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            // nCj = (n-1)Cj + (n-1)C(j-1); 
            C[j] = (C[j] + C[j-1])%MOD; 
    } 

    return C[r]; 
}

bool special(string s)
{
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == ' ')
            continue;
        
        if(s[i] == '#')
            return true;
        
        else
            return false;
    }
    return false;
}

vector <ll> ans;

bool cmp(string &a, string &b)
{
    return (a.size() < b.size() )|| (a.size() == b.size() && a < b);
}

void solve()
{
    int a,b,c;
    cin >> a >> b >> c;

    swap(a,b);
    swap(a,c);

    cout << a << ' ' << b << ' ' << c;
}

int main()
{
    fastIO
    // #ifndef ONLINE_JUDGE
    //     freopen("in.txt", "rt", stdin);
    //     freopen("out.txt", "wt", stdout);
    // #endif


    int t = 1;
    // cin >> t;

    for(int i=1;i<=t;i++)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll N;
    cin>>N;
    ll A[N],B[N-1];
    rep(0,i,N-1)cin>>B[i];
    A[0]=B[0];
    A[N-1]=B[N-2];
    rep(0,i,N-2){
        A[i+1]=min(B[i],B[i+1]);
    }
    ll ans=0;
    rep(0,i,N)ans+=A[i];
    cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    string S;
    cin >> S;
    if(S=="ABC")
       cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
}

Measured memory_bytes: 3544
H, W = map(int, input().split())
s = []
s.append(["."]*(W+2))
for _ in range(H):
    string = input()
    string = "." + string + "."
    s.append(list(string))
s.append(["."]*(W+2))
ans = True
for row in range(1, H+1):
    for col in range(1, W+1):
        if s[row][col] == "#":
            is_ok = False
            for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                if s[row+dh][col+dw] == "#":
                    is_ok = True
                    break
            if not is_ok:
                ans = False
                break
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 65896
import math

N, M = map(int, raw_input().split())
a = []
for i in range(N+M):
    a.append(map(int, raw_input().split()))

b=[]

def mhtn(a,b,c,d):
    return 

for i in range(N):
    best=4*10e8
    num=0
    for j in range(M):
        x=math.fabs(a[i][0]-a[N+j][0])+math.fabs(a[i][1]-a[N+j][1])
        
        if(best>x):
            best=x
            num=j+1
    b.append(num)

for i in b:
    print i

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

int main()
{
	while (true) {
		int N, Q;
		cin >> N >> Q;

		if (N == 0 && Q == 0) {
			break;
		}

		int day[120] = { 0 };
		int ans = 0;
		int num = 0;

		for (int i = 0; i < N; i++) {
			int M;
			cin >> M;

			for (int j = 0; j < M; j++) {
				int temp;
				cin >> temp;
				day[temp]++;
			}
		}

		for (int i = 1; i < 120; i++) {
			if (day[i] >= Q) {
				if (day[i] > num) {
					ans = i;
					num = day[i];
				}
			}
		}

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

Measured memory_bytes: 1160
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int SG(int a,int k) {
    int x=a/k,b=a%k;
    return b?SG(a-((b+x)/(x+1))*(x+1),k):x;
}

int main() {
	int n,a,k,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d%d",&a,&k),ans^=SG(a,k);
	return puts(ans?"Takahashi":"Aoki"),0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int N, c=0, ns;
string n, s;
cin>>N>>n;
ns = n.length();
while (N--){
string s;
cin>>s;
if ([&](){
for (int i=0;i<s.length();++i)
if(s[i] == n[0])
for(int p=1;;++p){
if(i+p*(ns-1)>= s.length())break;
for(int h=1;h<ns;h++)
if(s[i+p*h]!=n[h])break;
else if (h==ns-1)return true;
}
return false;
}()
)c++;
}
cout << c << endl;
}

Measured memory_bytes: 1208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
//#include <stdio.h>

using namespace std;

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

    int N;
    int M;
    int C;

    cin >> N >> M >> C;

    int count = 0;
    int kekka;

    vector<int> B(M);

    for(int i = 0; i < M; i++)
    {
        cin >> B[i];
    }

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < M; j++)
        {
            int a;
            cin >> a;
            kekka += a * B[j];
        }
        kekka += C;

        if(kekka > 0)
        {
            count++;
        }

        kekka = 0;
    }

    cout << count;
}

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

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

    int l[60];
    for(int i=0; i<N; i++){
        cin >> l[i];
    }
    sort(l, l+N, greater<int>()); // 破壊的に降順ソート
    int sum = 0;
    for(int i=0; i<K; i++){
        sum += l[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007LL;

int main(void) {
    int N, K;
    deque<ll> D;
    cin >> N >> K;
    for (int i=0;i<N;i++) {
        ll v;
        cin >> v;
        D.push_back(v);
    }
    vector<ll> H;
    ll ans = 0;
    for (int l=1;l<=min(K,N);l++) {
        H.push_back(D[l-1]);
        vector<ll> T(H);
        for (int r=1;r<=min(K,N)-l;r++) {
            T.push_back(D[N-r]);
            vector<ll> U(T);
            sort(U.begin(), U.end());
            reverse(U.begin(), U.end());
            for (int del=0;del<(K-l-r);del++) {
                if (U.back() < 0) U.pop_back();
                else break;
            }
            ans = max(ans,accumulate(U.begin(), U.end(), 0LL));
#ifdef DEBUG
            cout << "l: " << l << ", r: " << r << ", del: " << K-l-r << ",ans: " << ans << endl;
#endif
        }
        vector<ll> X(H);
        sort(X.begin(), X.end());
        reverse(X.begin(), X.end());
        for (int del=0;del<(K-l);del++) {
            if (X.back() < 0) X.pop_back();
            else break;
        }
        ans = max(ans,accumulate(X.begin(), X.end(), 0LL));
#ifdef DEBUG
        cout << "l: " << l << ", del: " << K-l << ",ans: " << ans << endl;
#endif
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
char s[MAXN];

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    scanf("%s", s);
    int len = strlen(s), ans = 0, gp = 1;
    for (int i = 1; i < len; i++) {
        if (s[i] == s[i - 1]) {
           ans++;
        } else {
           gp++;
        }
    }
    //printf("ans = %d gp = %d\n", ans, gp);
    while (gp > 2 && K) {
          ans += 2;
          gp -= 2;
          K--;
    }
    if (K && gp > 1) ans++;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20)
#define ll long long
#define endl '\n'
//       Author
//        ::
//    (  NOBODY  )
//   No Copyright .....You can copy and paste it without my permission...................................
// !!!!!!!!!!!!!!!
#define pb push_back
#define N 300009
int a[N],b[N],c[N];
ll val[N],wt[N];
ll dp[109][100009];
ll weight,bag,item;
int main()
{
    FAST_IO;
    cin>>item>>weight;
    for(int i=1;i<=item;i++)cin>>wt[i]>>val[i];
    for(int i=0;i<=item;i++)
    {
       for(int w=0;w<=weight;w++)
       {
          if(w==0||i==0)dp[i][w]=0;
          else if(wt[i]<=w)dp[i][w]=max(val[i]+dp[i-1][w-wt[i]],dp[i-1][w]);
          else dp[i][w]=dp[i-1][w];
       }
    }
    cout<<dp[item][weight];
    return 0;
}


Measured memory_bytes: 84224
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 998244353


int d[30][30];
int c[500][500];
int x[3][30];

int main() {
	int n, nc;
	scanf("%d%d", &n, &nc);
	REP(i, nc)REP(j, nc)scanf("%d", &d[i][j]);
	REP(i,n)REP(j,n)scanf("%d", &c[i][j]);
	REP(i, n)REP(j, n)c[i][j]--;
	REP(i, n)REP(j, n)REP(k, nc)x[(i + j) % 3][k] += d[c[i][j]][k];
	int ans = 1e9;
	REP(i, nc) {
		REP(j, nc) {
			if (i == j)continue;
			REP(k, nc) {
				if (k == i || k == j)continue;
				ans = min(ans, x[0][i] + x[1][j] + x[2][k]);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define LL long long
#define lowbit(x) ((x)&-(x))
using namespace std;

const int N = 200009;
const int MOD = 1000000007;

int n, np[N], arr[N];
struct Data{
	int x, v; 
	inline bool operator < (const Data &D) const {
		return x < D.x || (x == D.x && v < D.v);
	}
}d[N], seg[N];

inline int read() {
	char c = getchar(); int ret = 0, f = 1;
	for (; c < '0' || c > '9'; f = c == '-'? -1: 1, c = getchar());
	for (; '0' <= c && c <= '9'; ret = ret * 10 + c - '0', c = getchar());
	return ret * f;
}

inline bool cmpv(int aa, int bb) {
	return d[aa].v < d[bb].v;
}

class Fenwick_Tree{
	int sum[N], uve, cur = 1;
public:
	inline void modify(int p, int x) {
		uve = (uve + x) % MOD;
		sum[p] = (sum[p] + x) % MOD;
	}	
	inline int query(int p) {
		while (cur < p) {
			++cur;
			sum[cur] = (sum[cur] + sum[cur - 1]) % MOD;
		}
		return ((uve - sum[p - 1]) + MOD) % MOD;
	}
}BIT;

int main() {
	//freopen("11input.in", "r", stdin);
	//freopen("infection.out", "w", stdout);
	n = read();
	for (int i = 1; i <= n; i++) {
		d[i].x = read();
		d[i].v = read();
		arr[i] = i;
	}
	sort(d + 1, d + 1 + n);
	sort(arr + 1, arr + 1 + n, cmpv);
	for (int i = 1; i <= n; i++) {
		np[arr[i]] = i;
	}
	/*for (int i = 1; i <= n; i++) {
		printf("%d ", np[i]);
	}
	puts("");*/
	for (int i = 1, cur = 0; i <= n; ++i) {
		seg[i].x = cur = max(cur, np[i]);
	}
	for (int i = n, cur = n + 1; i; --i) {
		seg[i].v = cur = min(cur, np[i]);
	}
	/*for (int i = 1; i <= n; i++) {
		printf("%d %d\n", seg[i].v, seg[i].x);
	}*/
	sort(seg + 1, seg + 1 + n);
	BIT.modify(1, 1);
	for (int i = 1; i <= n; i++) {
		//cout<<seg[i].v<<' '<<seg[i].x<<endl;
		int tmp = BIT.query(seg[i].v);
		//cout<<tmp<<endl;
		BIT.modify(seg[i].x + 1, tmp);
	}
	printf("%d\n", BIT.query(n + 1));
	return 0;
}

Measured memory_bytes: 5884
#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define F first
#define S second
#define var auto
using namespace std;
typedef long long ll;
const int Max = 5e3 + 50;
const int Mod = 1e9 + 7;

int A[Max];
int X[Max] , Y[Max];

ll cnt[Max];
ll inv[Max][Max];
ll nrm[Max][Max];
ll lstedit[Max][Max];
ll _2pw[Max];
ll pw(int b)
{
	return _2pw[b];
}

ll getInv(int i , int j , int q)
{
	if(i > j)
		swap(i , j);
	return inv[i][j] * pw(q - lstedit[i][j] - 1) % Mod;
}

ll getNrm(int i , int j , int q)
{
	if(i > j)
		swap(i , j);
	return nrm[i][j] * pw(q - lstedit[i][j] - 1) % Mod;
}



int main()
{
	int n , q;cin >> n >> q;
	_2pw[0] = 1;
	for(int i = 1; i <= q + 1;i++)
		_2pw[i] = _2pw[i - 1] * 2 % Mod;

	for(int i = 1; i <= n ; i++)
		cin >> A[i];

	for(int i = 1; i <= q ; i++)
	{
		cin >> X[i] >> Y[i];
		if(X[i] > Y[i])
			swap(X[i] , Y[i]);
	}

	for(int i = 1; i <= q; i++)
	{
		for(int j = X[i] + 1; j <= Y[i];j++)
			cnt[i] += (A[X[i]] > A[j]);
		for(int j = Y[i] - 1; j >= X[i];j--)
			cnt[i] += (A[j] > A[Y[i]]);
	}

	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n ; j++)
			if(A[i] > A[j])
			{
				inv[i][j]++;
				inv[j][i]++;
			}
			else if(A[i] < A[j])
			{
				nrm[i][j]++;
				nrm[j][i]++;
			}

	ll _2k = 1;
	for(int i = 1; i <= q; i++ , _2k = _2k * 2 % Mod)
	{
		for(int j = 1; j <= n; j++)
		{
			if(j == X[i] || j == Y[i])
				continue;
			else
			{
				ll invX = getInv(j , X[i] , i);
				ll invY = getInv(j , Y[i] , i);
				ll nrmX = getNrm(j , X[i] , i);
				ll nrmY = getNrm(j , Y[i] , i);
				
				if(j < X[i] || j > Y[i])
				{
					inv[j][X[i]] = inv[X[i]][j] = inv[j][Y[i]] = inv[Y[i]][j] = (invX + invY) % Mod;
					nrm[j][X[i]] = nrm[X[i]][j] = nrm[j][Y[i]] = nrm[Y[i]][j] = (nrmX + nrmY) % Mod;
				}
				else
				{
					inv[j][X[i]] = inv[X[i]][j] = (invX + nrmY) % Mod;
					inv[j][Y[i]] = inv[Y[i]][j] = (invY + nrmX) % Mod;
					nrm[j][X[i]] = nrm[X[i]][j] = (nrmX + invY) % Mod;
					nrm[j][Y[i]] = nrm[Y[i]][j] = (nrmY + invX) % Mod;
				}

				lstedit[j][X[i]] = lstedit[X[i]][j] =
				   lstedit[j][Y[i]] = lstedit[Y[i]][j] = i;
			}
		}

		ll invxy = getInv(X[i] , Y[i] , i);
		ll nrmxy = getNrm(X[i] , Y[i] , i);
		inv[X[i]][Y[i]] = inv[Y[i]][X[i]] = (invxy + nrmxy) % Mod;
		nrm[X[i]][Y[i]] = nrm[Y[i]][X[i]] = (invxy + nrmxy) % Mod;
		lstedit[X[i]][Y[i]] = lstedit[Y[i]][X[i]] = i;
	}

	/*cout << "\n**\n";
	for(int j = 1; j <= n ; j++)
	{
		for(int k = 1; k <= n ; k++)
			cout << getReal(j , k , q + 1) << " ";
		cout << '\n';
	}*/

	ll ANS = 0;
	for(int i = 1; i <= n ; i++)
	{
		for(int j = i + 1; j <= n ; j++)
			ANS = (ANS + getInv(i,j, q + 1)) % Mod;
	}
	cout << '\n' << ANS << '\n';
}



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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
    int n, x;
    cin >> n >> x;
    V<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    Rep(i,n-1) {
        if(a[i] + a[i-1] > x) {
            int d = a[i] + a[i-1] - x;
            ans += d;
            if(a[i-1] <= x) a[i] -= d;
            else a[i] = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ln(a) cout << (a) << endl
#define debug(a, n) rep(hoge, n) printf("%lld%c", a[hoge], hoge == (n) - 1? '\n' : ' ');
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1e9
#define LINF 1e18

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

signed main() {
    int n, m;
    cin >> n >> m;
    bool* ac = new bool[n];
    fill(ac, ac + n, false);
    int* miss = new int[n];
    fill(miss, miss + n, 0);
    int ans = 0;
    int num = 0;
    rep(i, m) {
        int p;
        string s;
        cin >> p >> s;
        if(ac[p]) continue;
        if(s == "AC") {
            ans += miss[p];
            num++;
            ac[p] = true;
        }else {
            miss[p]++;
        }
    }

    printf("%d %d\n", num, ans);
}


Measured memory_bytes: 768
from sys import stdin

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()

left = 0
right = pow(10, 9)

for line in inp:
    l, r = map(int, line.strip().split())
    left = max(left, l)
    right = min(right, r)

ans = 0
ans = max(ans, right - left + 1)

print ans

Measured memory_bytes: 47340
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    ll n,m;
    cin >> n >> m;
    vector<pair<ll,ll> > a(n);
    rep(i,n){
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(),a.end());
    ll res=0, cnt=0;    
    int i=0;
    for(i=0;cnt<m;i++){
        cnt+=a[i].second;
        res+=a[i].first*a[i].second;
    }
    i--;
    if(cnt>m){
        res -= a[i].first*(cnt-m);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
n=int(input());arr = list(map(int,input().split()))
from collections import Counter
cnt = Counter(arr)
total = 0
for i in cnt:
  total += (cnt[i]**2 - cnt[i])//2
for i in arr:
  print(total-(cnt[i]**2-cnt[i])//2 + (cnt[i]-1)*(cnt[i]-2)//2)

Measured memory_bytes: 24748
import queue

K = int(input())
q = queue.Queue()
for i in range(1, 10):
    q.put(i)
ans = 1
for _ in range(K):
    ans = q.get()
    if ans % 10 != 0:
        q.put(ans * 10 + ans % 10 - 1)
    q.put(ans * 10 + ans % 10)
    if ans % 10 != 9:
        q.put(ans * 10 + ans % 10 + 1)

print(ans)

Measured memory_bytes: 57428
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

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

    double X = N / 1.08;
    int X_floor = (int)(floor(X));
    int X_ceil  = (int)(ceil(X));

    int N_floor = (int)(floor(X_floor * 1.08));
    int N_ceil = (int)(floor(X_ceil * 1.08));

    if (N_floor == N)
        cout << X_floor << endl;
    else if (N_ceil == N)
        cout << X_ceil << endl;
    else
        cout << ":(" << endl;

    return 0;
}

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

using namespace std;

int main(){
	int n,m;
	long long k;
	cin >> n >> m >> k;
	
	vector<long long> a(n);
	vector<long long> b(m);
	
	//i=0,1,2...の時の合計時間が入る
	vector<long long> sumA(n+1,0);
	vector<long long> sumB(m+1,0);
	
	for(int i = 0; i < n; i++){
		cin >> a.at(i);
	}
	for(int i = 0; i < m; i++){
		cin >> b.at(i);
	}
	
	long long sum_min_A = 0;
	for(int i = 1; i <= n; i++){
		sum_min_A += a.at(i-1);
		sumA.at(i) = sum_min_A;
	}
	
	long long sum_min_B = 0;
	for(int i = 1; i <= m; i++){
		sum_min_B += b.at(i-1);
		sumB.at(i) = sum_min_B;
	}
	
	int best = m;
	vector<int> counts;
	int max = 0;
	for(int i = 0; i < n+1; i++){
		for(int j = best; j >= 0; j--){
			if(sumA.at(i) + sumB.at(j) <= k){
				best = j;
				counts.push_back(i+j);
				if(max < i+j) max = i+j;
				break;
			}
		}
	}
	/*
	int max = 0;
	for(int i = 0; i < counts.size(); i++){
		if(max < counts.at(i)) max = counts.at(i);
	}
	*/
	cout << max << endl;
	
}

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

using namespace std;

typedef long long ll;

ll N, M;
ll MOD = 1000000007;
ll dp[300 + 10][300 + 10][300 + 10];
//dp[i][j][k] := i回目の移動(1-idx)を終えて、まだ連結されてない町がj個あり、k個の長さから成る最初の連結成分を持つ場合の数

int main() {

	cin >> N >> M;
	
	dp[0][N - 1][1] = 1;
	for (int i = 0; i <= M; i++) {
		for (ll j = 0; j <= N - 1; j++) {
			for (ll k = 1; k <= N; k++) {
				if (j - 1 >= 0) {
					dp[i + 1][j - 1][k] += (dp[i][j][k] * j % MOD);
					dp[i + 1][j - 1][k] %= MOD;
				}
				if (N - j - k >= 0) {
					dp[i + 1][j][k] += dp[i][j][k] * (N - j - k) % MOD;
					dp[i + 1][j][k] %= MOD;
				}
				dp[i + 1][j][N - j] += (dp[i][j][k] * k % MOD);
				dp[i + 1][j][N - j] %= MOD;
			}
		}
	}

	cout << dp[M][0][N] << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool ans = false;
  for(int a = 0; a <= 100; ++a){
    for(int b = 0; b <= 100; ++b){
      
      if(ans) break;
      int total = 4*a + 7*b;
      if(total == N) ans = true;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
    int a;scanf("%d", &a);
    vector < vector <double> > dp(3005, vector<double>(3005, 0));
    dp[0][0] = 1;
    double ret = 0;
    for(int coin = 1; coin <= a; coin++){
        double p ;
        scanf("%lf", &p);
        for(int j = 0; j <= coin; j++){
            if(j)dp[coin][j] += dp[coin - 1][j - 1] * p;
            dp[coin][j] += dp[coin - 1][j] * (1 - p);
            if(coin == a && j > a - j)ret += dp[coin][j];
            }
    }
    printf("%.12f", ret);
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    sort(a, a + N, greater<int>());

    int suma = 0;
    int sumb = 0;

    for(int i = 0; i < N; i++){
        if(i%2 == 0) suma += a[i];
        else sumb += a[i];
    }

    cout << suma - sumb << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  if ((n - n / 100) % 10 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
def solve1(n, lst):
    alice, bob = 0, 0

    #print(" i |a[i]|Alice|Bob")
    # print("------------------")

    for i in range(n):
        if i % 2 == 0:
            alice += lst[i]
        else:
            bob += lst[i]
        # print(f"{i:3d}|{a[i]:3d}|{alice:5d}|{bob:5d}")

    return alice - bob


n = int(input())
a = list(map(int, input().split(" ")))
a.sort(reverse=True)
print(solve1(n, a))


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef ll _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int n;
ll w;

const int MAXN = 100;
const ll MAXV = 1000*MAXN+5;
ll dp[MAXV];

int main() {
    cin>>n>>w;

    fill(dp,dp+MAXV,1e9 + 5);
    dp[0] = 0;

    REP(i,n){
        ll a,b;
        cin>>a>>b;
        FORR(j,0,MAXV-b){
            if(dp[j] != -1)
                chmin(dp[j+b], dp[j]+a);
        }
    }

    ll ans = 0;

    REP(i,MAXV){
        if(dp[i] <= w)
            chmax(ans,i);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n,x,t;
	cin >> n >> x >> t;
	int time = n/x;
	int amari = n%x;
	if(amari == 0) cout << time*t << endl;
	else cout << (time+1)*t << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int arr[101] = {0};

int main()
{
	int a, b, c, tmp;
	cin >> a >> b >> c;
	tmp=a;
	a=b;
	b=tmp;
	tmp=a;
	a=c;
	c=tmp;
	cout << a << ' ' << b << ' ' << c;
}



Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] W = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            int w = scan.nextInt();
            W[i] = w;
            sum += w;
        }
        int answer = Integer.MAX_VALUE;
        for (int t = 1; t <= N; t++) {
            int sum1 = 0;
            int sum2 = 0;
            for (int i = 1; i <= N; i++) {
                if (i <= t) {
                    sum1 += W[i-1];
                } else {
                    sum2 += W[i-1];
                }
            }
            answer = Math.min(answer, Math.abs(sum1 - sum2));
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 22228
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    string str;
    cin >> str;

    int ans = 0;
    for(int j=0; j<16; j++){
        if(str[j] == 'o'){
	    ans++;
	}
	else if(str[j] == '\0'){
	    break;
	}
    }

    int res;
    res = (int)str.length();

    if(ans + 15 - res >= 8){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S, N;
    cin >> S >> N;
    int x=0;
    while (x<S.length()){
        string A;
        A+=S.at(S.length()-1);
        A+=S.substr(0, S.length()-1);
        if (S==N){
            cout << "Yes" << endl;
            return 0;
        }
        S=A;
        x++;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#if ENABLE_DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const int INF = 100000000;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> checkpoints(R);
  REP(i, R) {
    int x;
    cin >> x;
    checkpoints[i] = x - 1;
  }
  vector<vector<int>> dist(N, vector<int>(N, INF));
  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    dist[a][b] = dist[b][a] = c;
  }
  REP(k, N) REP(i, N) REP(j, N) {
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  }

  // REP(i, R) REP(j, i) { DEBUG(j, i, dist[checkpoints[i]][checkpoints[j]]); }
  const int L = 1 << R;
  vector<vector<int>> dp(L, vector<int>(R, INF));

  auto solve = [&](auto rec, int unvisited, int cur) -> i64 {
    if (!unvisited) return 0LL;
    if (dp[unvisited][cur] != INF) return dp[unvisited][cur];
    const int cc = checkpoints[cur];
    i64 res = INF;
    REP(i, R) {
      if (unvisited & (1 << i)) {
        int nxt = checkpoints[i];
        int state = unvisited & ~(1 << i);
        res = min(res, dist[cc][nxt] + rec(rec, state, i));
      }
    }
    dp[unvisited][cur] = res;
    return res;
  };
  i64 ans = INF;
  REP(i, R) {
    int state = (L - 1) & ~(1 << i);
    ans = min(ans, solve(solve, state, i));
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3820
a,b,c,d,e,f=map(int,input().split())
able_water=[]
for na in range(1+f//(a*100)):
  for nb in range(1+(f-na*a*100)//(b*100)):
    water=na*a*100+nb*b*100
    if water and water<=f:
      able_water.append(water)
able_water.sort()
import bisect
ans=[0,0,0]
max_s=(f*e+100-1)//100
for nd in range(1+max_s//d):
  for nc in range(1+(max_s-nd*d)//c):
    sugger=nc*c+nd*d
    min_water=(sugger*100+e-1)//e
    if min_water+sugger>f:continue
    idx=bisect.bisect_left(able_water,min_water)
    if idx <len(able_water) and able_water[idx]+sugger<=f:
      if ans[0]<=(100*sugger/(able_water[idx]+sugger)):
        ans=[100*sugger/(able_water[idx]+sugger),able_water[idx]+sugger,sugger]
print(ans[1],ans[2])

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

const int N = 110;

int n, m;
int a[N];

int main() {
	cin >> n >> m;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] * 4 * m >= sum) cnt++;
	}
	
	if (cnt >= m) cout << "Yes\n";
	else cout << "No\n";
	 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	string s;
	cin>>s;
	int j=0;
	char ans[20];
	REP(i,s.size()){
		if(s[i]=='0'){
			ans[j]='0';
			j++;
		}
		else if(s[i]=='1'){
			ans[j]='1';
			j++;
		}
		else if(j!=0)
			j--;
	}
	REP(i,j){
		cout<<ans[i];
	}
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
  
  
def factorial(n):
  if n==1:
    return 1
  else:
    return n * factorial(n-1)
  
num_p=0
num_q=0
for i in range(n-1):
  sort_p = sorted(p[i:],reverse=True)
  index_p = sort_p.index(p[i])
  mp=n-(index_p+1)
  num_p += mp*factorial(n-(i+1))
  
  
  sort_q = sorted(q[i:],reverse=True)
  index_q = sort_q.index(q[i])
  mq = n-(index_q+1)
  num_q += mq*factorial(n-(i+1))
  
print(abs(num_p-num_q))

Measured memory_bytes: 3064
import collections
n=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(n//2):
    A.append(v[2*i])
    B.append(v[2*i+1])
    
a=collections.Counter(A)
b=collections.Counter(B)
aa=a.most_common()
bb=b.most_common()


if len(a)==len(b)==1 and aa[0][0]!=bb[0][0]:
    print(0)
elif len(a)==len(b)==1 and aa[0][0]==bb[0][0]:
    print(n//2)
else:
    if aa[0][0]!=bb[0][0]:
        count=n-aa[0][1]-bb[0][1]
        print(count)
    else:
        print(min(
            n-aa[0][1]-bb[1][1],
            n-aa[1][1]-bb[0][1]
        ))
    


Measured memory_bytes: 23776
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> D(N, vector<int>(N, 1e9));
    for (int i = 0; i < M; i++) {
        int A, B; cin >> A >> B; A--, B--;
        D[A][B] = 1;
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
            }
        }
    }
    int start = -1, len = 1e9;
    for (int i = 0; i < N; i++) {
        if (D[i][i] < len) {
            start = i, len = D[i][i];
        }
    }
    if (start == -1) {
        cout << -1 << '\n';
    } else {
        cout << len << '\n';
        int node = start;
        do {
            cout << node + 1 << '\n';
            for (int j = 0; j < N; j++) {
                if (D[node][j] == 1 && D[j][start] == len - 1) {
                    node = j;
                    break;
                }
            }
        } while (--len);
    }
    return 0;
}


Measured memory_bytes: 6272
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Deque;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int ans = in.nextInt();
            Deque<Integer> q = new ArrayDeque<Integer>();
            for (int i = 1; i < n; i++) {
                q.add(in.nextInt());
            }

            while (q.size() > 0) {
                int a = q.poll();
                int d = a % ans;
                if (d > 0 && ans > d) {
                    q.add(ans);
                    ans = d;
                }
            }

            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

    }
}



Measured memory_bytes: 25172
from itertools import product
N, A, B, C = map( int, input().split())
L = [ int( input()) for _ in range(N)]
T = [-A, -B, -C]
ans = 10**4
for V in product( range(4), repeat = N):
    ANS = [-A,-B,-C]
    mp = 0
    for i in range(N):
        if V[i] == 3:
            continue
        if ANS[V[i]] > T[V[i]]:
            mp += 10
        ANS[V[i]] += L[i]
    if ANS[0] == -A or ANS[1] == -B or ANS[2] == -C:
            continue
    ans = min( ans, sum( list( map( abs, ANS))) + mp)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
int vis[102];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   /// https://ideone.com/Fd5s8n
   int n,k;
   cin>>n>>k;
   for(int i=1;i<=n;i++)
    vis[i]=1;
   while(k--){
        int d;
        cin>>d;
        while(d--){
            int x;
            cin>>x;
            vis[x]++;
        }

   }
   int ans =0;
   for(int i=1;i<=n;i++){
    if(vis[i]<2)
        ans++;
   }
   cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3612
N, X, Y = map(int, input().split())
scores = [0] * N

for i in range(1, N):
    for j in range(i+1, N+1):
        if (i <= X and j <= X) or (i >= Y and j >= Y):
            d = j - i
        elif X < i < Y and X < j < Y:
            d = min([j - i, i - X + Y - j + 1])
        elif i <= X and X < j < Y:
            d = X - i + min([j - X, Y - j + 1])
        elif X < i < Y and  Y <= j:
            d = min([i - X + 1, Y - i]) + j - Y
        elif i <= X and Y <= j:
            d = X - i + j - Y + 1
        else:
            print("undefined pattern {}, {}".format(X, Y))

        scores[d] += 1
for score in scores[1:]:
    print(score)

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
    int A,B,C,D,X,Y,N,L,M,P,Q;
    cin>>N;
    int foo[1005];
    double sum = 0;
    for(int i=0;i<N;i++){
        cin>>foo[i];
        sum+=(double)1/foo[i];
    }
    cout<<std::scientific<<(double)1/sum<<endl;
}

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

const ll INF = 1001001001;
const ll mod = 1000000007;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> ans(100002);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        for(int j = -1; j <= 1; j++){
            if(a[i] + j < 0) continue;
            ans[a[i] + j]++;
        }
    }
    cout << *max_element(ans.begin(), ans.end()) << endl;
}

Measured memory_bytes: 4056
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s;cin >> s;
    bool ok = false;
    rep(i,s.size()){
        if(s[i] == '7')ok = true;
    }
    YES(ok);
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main()
{
    ll i,j;
    ll n, c;
    cin >> n >> c;
    vector<vector<ll>> d(c,vector<ll>(c));
    vector<vector<ll>> color(n,vector<ll>(n));
    for(i = 0;i < c;++i){
        rep(j,c){
            cin >> d.at(i).at(j);
        }
    }
    for(i = 0;i < n;++i){
        rep(j,n){
            ll e;
            cin >> e;
            --e;
            color.at(i).at(j) = e;
        }
    }
    vector<pair<ll,ll>> tmp1(c);
    ll k;
    for(k = 0;k < c;++k){
        ll tmp = 0;
        for(i = 0;i < n;++i){
            for(j = (3*n + 3-i)%3;j < n;j += 3){
                tmp += d.at(color.at(i).at(j)).at(k);
            }
        }
        tmp1.at(k) = make_pair(tmp, k);
    }
    vector<pair<ll,ll>> tmp2(c);
    for(k = 0;k < c;++k){
        ll tmp = 0;
        for(i = 0;i < n;++i){
            for(j = (3*n + 3-i+1)%3;j < n;j += 3){
                tmp += d.at(color.at(i).at(j)).at(k);
            }
        }
        tmp2.at(k) = make_pair(tmp, k);
    }
    vector<pair<ll,ll>> tmp3(c);
    for(k = 0;k < c;++k){
        ll tmp = 0;
        for(i = 0;i < n;++i){
            for(j = (3*n + 3-i+2)%3;j < n;j += 3){
                tmp += d.at(color.at(i).at(j)).at(k);
            }
        }
        tmp3.at(k) = make_pair(tmp, k);
    }
    sort(all(tmp1));
    sort(all(tmp2));
    sort(all(tmp3));
    vector<ll> ans;
    for(i = 0;i < 3;++i){
        rep(j,3){
            rep(k,3){
                if(tmp1.at(i).second == tmp2.at(j).second || tmp2.at(j).second == tmp3.at(k).second || tmp3.at(k).second == tmp1.at(i).second){
                    continue;
                }else{
                    ans.push_back(tmp1.at(i).first + tmp2.at(j).first + tmp3.at(k).first);
                }
            }
        }
    }
    sort(all(ans));
    cout << ans.front() << endl;
    return 0;
}

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

    for k in range(K):
        imos = [0] * (N+1)
        for i in range(N):
            imos[min(N,i+A[i]+1)] -= 1
            imos[max(0,i-A[i])] += 1
        
        A[0] = imos[0]
        all_N = True
        for i in range(1,N):
            A[i] = A[i-1] + imos[i]
            if A[i] != N:
                all_N = False
        
        if all_N:
            break

    print(*A)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 137516
s = input()

def result(s):
    count = 0
    max = 0
    if s == 'RRR':
        max = 3
        return max
    elif s == 'SSR':
        max = 1
        return max
    elif s == 'SRR':
        max = 2
        return max
    elif s == "RSR":
        max = 1
        return max
    for i in s:
        if i == 'R':
            count += 1
        else:
            if max < count:
                max = count
            count = 0
    return max
    

print(result(s))
        

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int x = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256