akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define FTEST int testcase;fin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
#define plii pair<ll,pii>
#define no {cout<<"no"<<endl;return;}
#define yes {cout<<"yes"<<endl;}
#define rep(i,N) for(int i=0;i<N;i++)
const int maxn=3e5;
const int mod=998244353;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ull power(ull a,ll b){
    ull ans=1;
    while(b){
        if(b&1) ans=ans*a;
        b/=2;
        a=a*a;
    }
    return(ans);
}
int arr[maxn+1];
ll dp[maxn+1];
int sizes[maxn+1];
int root(int i){
    while(i!=arr[i]){
        arr[i]=arr[arr[i]];
        i=arr[i];
    }
    return(i);
}
void link(int i,int j){
    i=root(i);j=root(j);
    if(i==j) return;
    if(sizes[i]>sizes[j]) swap(i,j);
    sizes[j]+=sizes[i];
    arr[i]=j;

}
void solve(){
    int n,m,a,b;cin>>n>>m;
    for(int i=1;i<=n;i++){
        arr[i]=i;
        sizes[i]=1;
    }
    while(m--){
        cin>>a>>b;
        link(a,b);
    }
    int maxx=1;
    for(int i=1;i<=n;i++){
        if(i==arr[i]) maxx=max(maxx,sizes[i]);
    }
    cout<<maxx;
    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}
/*
2
3 3
2500 2500 2520
10 -5 -20
10 15 20
-15 17 13
2 3
2125 2098
-20 10 -10
10 10 -20
*/
/*
1
3 3
2500 2500 2520
10 -5 -20
10 15 20
-15 17 13

*/


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

int main()
{
	int N;
	int val;

	cin >> N >> val;

	for ( int i = 0; i < N - 1; i++ ) {
		int v;
		cin >> v;
		val = __gcd(val, v);
	}

	cout << val << endl;

	return ( 0 );
}


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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

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

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< int > A(N);
  cin >> A;

  int ret = 0;
  for(int i = 1; i < N; i++) {
    ret += A[i - 1] < A[i];
  }
  cout << ret << endl;


}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,K;
ll mo;
ll po[202][20202];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

const int CN=401;
ll C[CN][CN];


ll A[101][101][101];
ll B[101][101][101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K>>mo;
	
	FOR(i,201) {
		po[i][0]=1;
		FOR(j,20101) po[i][j+1]=po[i][j]*i%mo;
	}
	
	FOR(i,CN) for(j=0;j<=i;j++) C[i][j]=(j==0||j==i)?1:(C[i-1][j-1]+C[i-1][j])%mo;
	
	A[0][0][0]=1;
	for(k=1;k<=K;k++) {
		FOR(y,H+1) FOR(x,W+1) if(A[k-1][y][x]) {
			ll pat=(po[k][W-x]+mo-po[k-1][W-x])%mo;
			ll v=1;
			for(int len=0;y+len<=H;len++) {
				(B[k-1][y+len][x]+=A[k-1][y][x]*C[H-y][len]%mo*v%mo*po[K+1-k][len*x])%=mo;
				v=v*pat%mo;
			}
		}
		FOR(y,H+1) FOR(x,W+1) if(B[k-1][y][x]) {
			ll pat=(po[K+1-k][y]+mo-po[K-k][y])%mo;
			ll v=1;
			for(int len=0;x+len<=W;len++) {
				(A[k][y][x+len]+=B[k-1][y][x]*C[W-x][len]%mo*v%mo*po[k][len*(H-y)])%=mo;
				v=v*pat%mo;
			}
		}
	}
	
	cout<<A[K][H][W]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 49408
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > vp;
int main(){
	int n,i,a;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a;
		vp.push_back(make_pair(a,i));
	}
	sort(vp.begin(),vp.end());
	for(i=0;i<n;i++)
	{
		cout<<vp[i].second<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1780
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main(void) {
	char str[101];
	scanf("%s", str);
	printf("%c%d%c\n", str[0], (int)strlen(str) - 2, str[strlen(str)-1]);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> under(n);
  for(int i = 0;i < n;i++)under[i] = pow(10,18);
  vector<ll> de(n);
  for(int i = 0;i < n;i++)de[i] = -1;
  
  vector<ll> t(n);
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> t[i];
  for(int i = 0;i < n;i++)cin >> a[i];
  
  for(int i = 0;i < n;i++){
    if(i == 0){
      de[i] = t[i];
    }
    else if(t[i] > t[i - 1]){
      de[i] = t[i];
    }
    else{
      under[i] = t[i];
    }
  }
  for(int i = n - 1;i >= 0;i--){
    if(i == n - 1){
      if((de[i] != a[i] && de[i] != -1) || (a[i] > under[i])){
        cout << 0 << endl;
        return 0;
      }
      de[i] = a[i];
    }
    else if(a[i] > a[i + 1]){
      if((de[i] != a[i] && de[i] != -1) || (a[i] > under[i])){
        cout << 0 << endl;
        return 0;
      }
      de[i] = a[i];
    }
    else{
      if(de[i] > a[i]){
        cout << 0 << endl;
        return 0;
      }
      under[i] = min(under[i],a[i]);
    }
  }
  ll res = 1;
  ll mod = pow(10,9) + 7;
  for(int i = 0;i < n;i++){
    if(de[i] == -1){
      res *= under[i],res %= mod;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 6368
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;

 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();
    int[] ss = new int[n];
    for(int i = 0; i < n; i++){
      ss[i] = sc.nextInt();
    }
    int m = sc.nextInt();
    int[] ts = new int[m];
    for(int i = 0; i < m; i++){
      ts[i] = sc.nextInt();
    }

    int ans = 0;
    for(int i = 0; i < m; i++){
      int target = ts[i];
      int left = 0;
      int right = n-1;
      while(true){
        int center = (left + right) / 2;
        if(ss[center] == target){
          ans++;
          break;
        }
        if(right == left){break;}
        if(ss[center] < target){
          left = center + 1;
        }else{
          right = center;
        }
      }
    }
    System.out.println(ans);
  }
 
  
// LinkedList<Integer>[] setsu = new LinkedList[n];
// for(int i = 0; i < n; i++){
//   setsu[i] = new LinkedList<Integer>();
// } 

 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;

      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }

      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

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

	int n;
	cin >> n;

	for ( int i = 1 ; i < 10 ; i++ ){
		int d = n / i;
		if ( d > 0 && d < 10 && d * i == n ){
			cout << "Yes" << "\n";
			return 0;
		}
	}
	cout << "No" << "\n";
	return 0;
}


Measured memory_bytes: 256
N = int(input())
t = []
x = []
y =[]
for i in range(N):
    data = input().split()
    data = [int(n) for n in data]
    t.append(data[0])
    x.append(data[1])
    y.append(data[2])

t_now = 0
x_now = 0
y_now = 0

flag_able = True
for i in range(N):
    t_sub = t[i] - t_now
    x_sub = abs(x[i] - x_now)
    y_sub = abs(y[i] - y_now)
    step_needed = x_sub + y_sub
    if(step_needed > t_sub):
        flag_able = False
    else:
        if((t_sub - step_needed)%2 == 1):
            flag_able = False
        else:
            flag_able = True
    if(flag_able == False):
        break

if(flag_able == True):
    print('Yes')
else:
    print('No')


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

int main(void) 
{
  int dp[1001][1001];  // [takara][weight]
  int wei[1001];       // [takara]
  int val[1001];       // [takara]
  int i, w;
  int n, tw;
  int datcnt;
  char c;

  cin >> tw;
  for(datcnt = 1; tw != 0; datcnt++){
    cin >> n;
    for(i = 1; i <= n; i++){
      cin >> val[i];
      cin >> c;
      cin >> wei[i]; 
    }

    // initArrayDP
    for(i = 0; i <= n; i++) {
      for(w = 0; w <= tw; w++) {
	dp[i][w] = 0;
      }
    }
    //cout << "--map";
    for(i = 1; i <= n; i++) {
      for(w = 1; w <= tw; w++) {
	int tem = w - wei[i];
	if(tem < 0) {
	  dp[i][w] = dp[i-1][w];
	} else {
	  dp[i][w] = max(dp[i-1][w], dp[i-1][tem] + val[i]);
	}
      }
    }

    //for(i = 1; i <= n; i++) {
    //  for(w = 1; w <= tw; w++) {
    //	printf("%5d", dp[i][w]);
    //  }
    //  printf("\n");
    //}

    
    // [takara]の最終列から価値最大かつ、そのなかで重さ最初を探す。
    int maxval  = INT_MIN;
    int lastwei = INT_MAX;

    for(w = 0; w <= tw; w++)
      maxval = max(dp[n][w], maxval);

    for(w = tw; w >= 0; w--)
      if(dp[n][w] == maxval) lastwei = min(lastwei, w);

    cout << "Case " << datcnt << ":" << endl;
    cout << maxval << endl << lastwei << endl;
    
    cin >> tw;
  }
  return 0;
}

Measured memory_bytes: 5080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  string s,t;
  cin>>s>>t;
  ll mini=INF;
  for(ll i=0;i<=sz(s)-sz(t);i++){
      ll count=0;
      for(ll j=0;j<sz(t);j++){
          if(s[i+j]==t[j]){
              count++;
          }
      }
      chmin(mini,sz(t)-count);
  }
  print(mini);
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main() {
  int S;
  cin >> S;
  int h = S / 3600;
  S %= 3600;
  int m = S / 60;
  int s = S % 60;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  
  int t[n],x[n],y[n];
  rep(i,n) cin >> t[i] >> x[i] >> y[i];
  
  rep(i,n)
  {
    if(t[i] % 2 != (x[i] + y[i]) % 2) 
    {
      cout << "No" << endl;
      return 0;
    }
  }
  
  if(t[0] < x[0] + y[0])
  {
    cout << "No" << endl;
    return 0;
  }
  for(int i = 1; i < n; i++)
  {
    if( (t[i] - t[i-1]) < abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]) ) 
    {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 4720
import math
n, m = map(int, input().split())
mod = 10**9+7
if abs(n-m) >= 2:
  print(0)
elif n == m:
  print((math.factorial(n)*math.factorial(m)*2)%mod)
else:
  print((math.factorial(n)*math.factorial(m))%mod)

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

using namespace std;

int main(){
  string s; cin >> s;
  if(s[5]=='0' && (s[6]=='1' || s[6]=='2' || s[6]=='3' ||s[6]=='4')){
    cout << "Heisei" << endl;
  }
  else{
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    int a;cin >> a; 
    cout << a + a * a  + a * a * a << endl;
    return 0;
}


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

s = []
k = []
for i in range(m):
    ks = list(map(int, input().split()))
    k.append(ks[0])
    s.append(ks[1:])

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


def check_switch(ss):
    for i in range(m):
        sum_switch = 0
        for j in range(k[i]):
            sum_switch += ss[s[i][j] - 1]
        if sum_switch % 2 != p[i]:
            return 0
    return 1


def check(switches, l):
    if l == n:
        return check_switch(switches)
    return check(switches+[0], l + 1) + check(switches+[1], l + 1)


print(check([], 0))


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

int main() {
    int n;
    cin >> n;
    vector<string> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        sort(v[i].begin(), v[i].end());
    }

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

    long long ans = 0;
    long long cnt = 1;
    for (int i = 0; i < n; i++) {
        if (i == n - 1) {
            ans += cnt * (cnt - 1) / 2;
        }
        else if (v[i] == v[i + 1]) {
            cnt++;
        }
        else if (v[i] != v[i + 1]) {
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long lint; typedef pair<int, int> ii;
// const int MOD = 1'000'000'007, MOD2 = 1'000'000'009;
const int INF = 0x3f3f3f3f; const lint BINF = 0x3f3f3f3f3f3f3f3fLL;

struct STNode{
	int lo, hi, mn, lz;
	STNode *lchi, *rchi;

	STNode(int l, int r, int *v) : lo(l), hi(r), lz(-INF), lchi(nullptr), rchi(nullptr) {
		if(lo == hi){
			mn = v[lo];
		}else{
			int mi = (lo + hi) >> 1;
			lchi = new STNode(lo, mi, v); rchi = new STNode(mi+1, hi, v);
			mn = max(lchi->mn, rchi->mn);
		}
	}

	void update(int x) {
		mn = max(mn, x);
		lz = max(lz, x);
	}

	void pushdown() {
		if (lz != -INF) {
			if (rchi) rchi->update(lz);
			if (lchi) lchi->update(lz);
			lz = -INF;
		}
	}

	int query(int l, int r){
		pushdown();
		if(l > r) return -INF;
		if(l == lo && r == hi)
			return mn;
		int mi = (lo + hi) >> 1;
		if(r <= mi)
			return lchi->query(l, r);
		else if (l > mi)
			return rchi->query(l, r);
		else{
			int resl = lchi->query(l, mi);
			int resr = rchi->query(mi+1, r);
			return max(resl, resr);
		}
	}

	void set(int l, int r, int v) {
		if (l == lo && r == hi) {
			update(v);
		} else {
			pushdown();
			int mi = (lo + hi) >> 1;
			if (r <= mi)
				lchi->set(l, r, v);
			else if (l > mi)
				rchi->set(l, r, v);
			else {
				set(l, mi, v);
				set(mi + 1, r, v);
			}
			mn = max(lchi->mn, rchi->mn);
		}
	}

	~STNode(){
		if(lo != hi){
			delete lchi; delete rchi;
		}
	}
};

int n, a[200005], x[200005];
int p[200005];
STNode *teui;

int bullshxt(int lo, int hi, int t) {
	while (lo < hi) {
		int mi = (lo + hi) >> 1;
		if (teui->query(mi, mi) < t)
			hi = mi;
		else
			lo = mi + 1;
	}
	return lo;
}

int solve(){
	cin >> n;
	for (int i=0;i<n;i++) cin >> a[i], a[i] -= i;
	for (int i=0;i<n;i++) if (a[i] > 0 || a[i] < -i) return cout << -1 << endl, 0;
	for (int i=0;i+1<n;i++) if (a[i] < a[i+1]) return cout << -1 << endl, 0;
	// for (int i=0;i<n;i++) cerr << a[i] << " \n"[i==n-1];
	for (int i=0;i<n;i++) x[i] = -i;
	teui = new STNode(0, n-1, x);
	lint ans = 0;
	for (int i=n-1;i>=0;i--) {
		// cerr << "diuuuuuu0u8auiygsaehksdvhilil" << endl;
		// for (int i=0;i<n;i++) cerr << teui->query(i, i) << " \n"[i==n-1];
		if (a[i] == teui->query(i, i)) continue;
		int fi = bullshxt(0, i+1, a[i]); fi--;
		// cerr << fi << endl;
		if (fi == i || fi < 0 || teui->query(fi, fi) != a[i]) return cout << -1 << endl, 0;
		teui->set(fi, i, a[i]);
		ans += i - fi;
	}
	cout << ans << endl;
	delete teui;
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	// int t; cin >> t; while(t--)
	solve();
	// cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}


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

#define MAXN 100010
#define ll long long
#define mod 1000000007

using namespace std;

int n, r;

int a[MAXN];

int main() {
	cin >> n >> r;
	if (n >= 10) cout << r << endl;
	else {
		cout << r + 100 * (10 - n) << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int Maxn=2005;
const int Maxval=2005;
const int Maxsum=Maxn*Maxval;
const int Maxl=Maxsum/64+1;
int a[Maxn];
uint64_t b[Maxl];
int sum;
int main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	b[0]=1;
	rep(i,n){
		int dj=a[i]/64,dk=a[i]%64;
		if(dk){
			for(int j=Maxl-1;j>=0;j--){
				uint64_t high=b[j]>>(64-dk),low=b[j]<<dk;
				b[j+dj]|=low;b[j+dj+1]|=high;
			}
		}else{
			for(int j=Maxl-1;j>=0;j--){
				b[j+dj]|=b[j];
			}
		}
	}
	for(int i=(sum+1)/2;i<Maxsum;i++){
		if((b[i/64]>>(i%64))&1){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

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

int main() {
    int A, B, C; cin >> A >> B >> C;
    
    if (A == B) {
        if (A != C && B != C) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        if (B == C && A != C) {
            cout << "Yes" << endl;
        }
        else if (A == C && B != C) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

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

int N;
string s;
int dp[100005];
int h[100005];

int main(){
    cin >> N;
    int h_in;
    rep(i,N){
        cin >> h_in;
        h[i+1] = h_in;
    }
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for(int i=3; i<=N; ++i){
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[N];
	return 0;
}

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

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

  int h[N];
  for (int i = 0; i < N; i++) cin >> h[i];

  int counter = 0;
  for (int i = 0; i < N; i++) {
    if (h[i] >= K) counter++;
  }

  cout << counter << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
	int n, s, sum;
	while (!cin.eof())
	{
		cin >> n;
		if (n == 0) break;
		int max = 0, min = 500;
		for (int i = 0; i < n; i++)
		{
			sum = 0;
			for (int j = 0; j < 5; j++)
			{
				cin >> s;
				sum += s;
			}
			if (max < sum) max = sum;
			if (min > sum) min = sum;
		}
		cout << max << " " << min << endl;
	}
	return 0;
}

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

int main() {
  int  S , s1 ,s2 , s3;
  cin >> S ;

   s1= S / 100 % 2;
   s2= S / 10 % 2;
   s3= S % 2;

  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    double n;
    cin >> n;
    cout << fixed << setprecision(10) << n * 2 * acos(-1) << '\n';
}


Measured memory_bytes: 3800
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

struct Magic {
  int p, d, t;
  Magic() {}
  Magic(int _p, int _d, int _t): p(_p), d(_d), t(_t) {}
  bool operator<(const Magic &m) const { return p < m.p; }
};

/* global variables */

Magic mgs[MAX_N + 1];
int dp[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int l, n;
  cin >> l >> n;

  for (int i = 0; i < n; i++)
    cin >> mgs[i].p >> mgs[i].d >> mgs[i].t;
  sort(mgs, mgs + n);
  mgs[n] = Magic(l, 0, 0);

  for (int i = 0; i <= n; i++) dp[i] = mgs[i].p;

  for (int i = 0; i < n; i++) {
    //printf("dp[%d]=%d\n", i, dp[i]);

    int x = mgs[i].p + mgs[i].d;
    int y = dp[i] + mgs[i].t;

    for (int j = i + 1; j <= n; j++)
      if (mgs[j].p >= x) {
	int dpj = y + mgs[j].p - x;
	if (dp[j] > dpj) dp[j] = dpj;
      }
  }

  printf("%d\n", dp[n]);
  return 0;
}


Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////


int main() {

	int N, M;
	cin >> N >> M;
	vector<vector<int>> S(M,vector<int>(0));
	rep(i, M) {
		int k,s;
		cin >> k;
		rep(j, k) {
			cin >> s;
			S[i].push_back(s);
		}
	}
	vector<int> P(M);
	rep(i, M) {
		cin >> P[i];
	}

	long long ans = 0;
	for (int i = 0; i < 1 << N; i++) {
		bool all = true;
		for (int j = 0; j < M; j++) {
			int swn = 0;
			for (int k:S[j]) {
				if (1 << (k - 1)&i)swn++;				
			}
			if (swn % 2 != P[j]) { all = false; break; }
		}
		if (all)ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n,x; cin >> n >> x;
    int d[n],l[n];
    int i;
    d[0] = 0;
    for(i = 0; i < n; i++){
        cin >> l[i];
    }

    for(i = 1; i <= n; i++){
        d[i] = d[i-1] + l[i-1];
    }
    i = 0;
    while(d[i] <= x){ i++; }
    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,root=-1,dp[100010];
bool used[100010];
vector<int>G[100010];
void dfs(int x){
    used[x]=true;
    int cnt_zero=0;
    for(int i:G[x]){
        if(!used[i]){
            dfs(i);
            dp[x]+=dp[i];
            if(dp[i]==0)cnt_zero++;
        }
    }
    dp[x]+=max(0ll,cnt_zero-1);
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        G[a].pb(b);
        G[b].pb(a);
    }
    rep(i,n){
        if(G[i].size()>=3){
            root=i;
            break;
        }
    }
    if(root==-1){
        cout<<1<<endl;
        return 0;
    }
    dfs(root);
    cout<<dp[root]<<endl;
    return 0;
}

Measured memory_bytes: 13460
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=lambda x: x[0])

dp = [[0] * (n+1) for i in range(t)]
ans = 0
for time in range(1, t):
    for i in range(n):
        if ab[i][0] <= time:
            if dp[time][i] < (ab[i][1] + dp[time - ab[i][0]][i]):
                dp[time][i+1] = (ab[i][1] + dp[ time - ab[i][0] ][i])
            else:
                dp[time][i+1] = dp[time][i]
        else:
            dp[time][i+1] = dp[time][i]
        if i < n-1:
            ans = max(ans, dp[time][i+1] + ab[i+1][1])

print(ans)


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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	string s;
	bool flag[1000]={false};
	cin >> s;
	REP(i,s.length()){
		if(flag[s[i]] == true){
			cout << "no";
			return 0;
		}
		else flag[s[i]] = true;
	}
	cout << "yes";
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())

const int mod = 998244353;
const int maxn = 3e5 + 5;

int n;
string s;
vector<int> a[3];
map<pair<int, int>, vector<pair<int, int> > > mm;
int vs[maxn];

int find1() {
	int found = -1;
	for (int i = 0; i < 3; i++) {
		if (!~found || a[i].back() > a[found].back()) {
			found = i;
		}
	}
	return found;
}

int find2() {
	int found = -1;
	for (int i = 0; i < 3; i++) {
		if (!~found || a[i].back() < a[found].back()) {
			found = i;
		}
	}
	return found;
}

int main() {
//	freopen("inp.txt", "r", stdin);
	cin >> n;
	
	cin >> s;
	
	for (int i = 0; i < sz(s); i++) {
		if (s[i] == 'R') {
			a[0].pb(i);
		} else if (s[i] == 'G') {
			a[1].pb(i);
		} else {
			a[2].pb(i);
		}
	}
	
	for (int i = n - 1; i >= 0; i--) {
		int hi = find1();
		int lo = find2();
		vs[a[hi].back()] = 2;
		vs[a[lo].back()] = 0;
		for (int j = 0; j < 3; j++) {
			if (hi != j && lo != j) {
				vs[a[j].back()] = 1;
			}
			a[j].pop_back();
		}
	}
	
	long long ans = 1;
	int has[4];
	has[0] = n, has[1] = 0, has[2] = 0;
	for (int i = 0; i < 3 * n; i++) {
		ans = ans * (has[vs[i]]) % mod;
//		cout << i << ' ' << has[vs[i]] << endl;
		has[vs[i]]--;
		has[vs[i] + 1]++;
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 3324
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n, b, cnt = 1;
	vi v;
	cin >> n;
	rep(i, n) {
		cin >> b;
		v.pb(b);
	}
	sort(v.begin(), v.end());
	REP(i, 0, n - 1) {
		if (v[i] != v[i + 1]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	string s;
	bool f = 0;
	cin >> a >> b >> s;
	for (int i = 0; i < a; i++)if (s[i] == '-')f = 1;
	if (s[a] != '-')f = 1;
	for (int i = a + 1; i < a + b + 1; i++)if (s[i] == '-')f = 1;
	if (f)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
n, t = map(int, input().split())
list_CT = [ list(map(int,input().split(" "))) for i in range(n)]

ans = []

for i in range(n):
    l = list_CT[i]
    if l[1] <= t:
        ans.append(l[0])
if len(ans) == 0:
    print("TLE")
else:
    print(min(ans))

Measured memory_bytes: 3060
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

int h, w;
vector<vector<char>> s;
vector<vector<int>> dist;

const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

void solve() {
	cin >> h >> w;
    s.assign(h, vector<char>(w));
    dist.assign(h, vector<int>(w, inf));
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    -- sx, -- sy, -- gx, -- gy;
    rep(i, h) {
        rep(j, w) {
            cin >> s[i][j];
        }
    }
    deque<P> deq;
    deq.push_front(P{sx, sy});
    dist[sx][sy] = 0;
    while(!deq.empty()) {
        P p = deq.front(); deq.pop_front();
        rep(k, 4) {
            int nx = p.fr + dx[k], ny = p.sc + dy[k];
            if(0 <= nx and nx < h and 0 <= ny and ny < w and s[nx][ny] == '.' and chmin(dist[nx][ny], dist[p.fr][p.sc])) {
                deq.push_front(P{nx, ny});
            }
        }
        for(int dx = -2; dx <= 2; ++ dx) for(int dy = -2; dy <= 2; ++ dy) {
            int nx = p.fr + dx, ny = p.sc + dy;
            if(0 <= nx and nx < h and 0 <= ny and ny < w and s[nx][ny] == '.' and chmin(dist[nx][ny], dist[p.fr][p.sc] + 1)) {
                deq.push_back(P{nx, ny});
            }
        }
    }
    if(dist[gx][gy] == inf) dist[gx][gy] = -1;
    cout << dist[gx][gy] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 8644
r,c,kk = map(int, input().split())

a = [[0 for j in range(c)] for i in range(r)]
dp1 = [[0 for j in range(c+1)] for i in range(r+1)]
dp2 = [[0 for j in range(c+1)] for i in range(r+1)]
dp3 = [[0 for j in range(c+1)] for i in range(r+1)]
dp4 = [[0 for j in range(c+1)] for i in range(r+1)]

for i in range(kk):
  b,cc,d = map(int, input().split())
  b -= 1
  cc -= 1
  a[b][cc] = d

for i in range(r):
  for j in range(c):
    dp4[i][j] = max(dp4[i][j],dp3[i][j]+a[i][j])
    dp3[i][j] = max(dp3[i][j],dp2[i][j]+a[i][j])
    dp2[i][j] = max(dp2[i][j],dp1[i][j]+a[i][j])
    dp1[i][j+1] = max(dp1[i][j+1],dp1[i][j])
    dp2[i][j+1] = max(dp2[i][j+1],dp2[i][j])
    dp3[i][j+1] = max(dp3[i][j+1],dp3[i][j])
    dp4[i][j+1] = max(dp4[i][j+1],dp4[i][j])
    dp1[i+1][j] = max(dp1[i+1][j],dp1[i][j],dp2[i][j],dp3[i][j],dp4[i][j])
ans=  0
ans = max(dp1[r-1][c-1],dp2[r-1][c-1],dp3[r-1][c-1],dp4[r-1][c-1])
print (ans)

Measured memory_bytes: 472636
using System;
using System.Linq;

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

        var ans = "Yes";
        var t = 0;
        var x = 0;
        var y = 0;
        for (int i = 0; i < N; i++)
        {
            var inputs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var dt = inputs[0] - t;
            var dx = Math.Abs(inputs[1] - x);
            var dy = Math.Abs(inputs[2] - y);

            if (dx + dy > dt)
            {
                ans = "No";
            }

            if (dt % 2 != (dx + dy) % 2)
            {
                ans = "No";
            }

            t = inputs[0];
            x = inputs[1];
            y = inputs[2];
        }

        Console.WriteLine(ans);
    }
}

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

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


ll gcd (ll a, ll b){ return b == 0? a : gcd(b, a % b); }

void solve(long long N, std::vector<long long> A){
    ll ans = A[0];
    for(ll i=1; i< N; i++){
        ans = gcd(A[i], ans);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

void addcard(char[],char[],char[],int[],int,int,int,int*);

int main(void) {
	char cards[10*6000];
	char nowcard[10];
	char cardkouho[3*10];
	int cardmaisuu;
	int sentakumaisuu;
	int cardnokori[10];
	int i;
	int result;
	while(1) {
		scanf("%d",&cardmaisuu);
		scanf("%d",&sentakumaisuu);
		if(cardmaisuu==0 && sentakumaisuu==0)break;
		for(i=0;i<cardmaisuu;i++) {
			scanf("%s",&cardkouho[3*i]);
		}
		for(i=0;i<cardmaisuu;i++) {
			cardnokori[i]=1;
		}
		for(i=0;i<60000;i++) {
			cards[i]=0;
		}
		for(i=0;i<10;i++) {
			nowcard[i]=0;
		}
		result=0;
		addcard(cards,nowcard,cardkouho,
			cardnokori,1,sentakumaisuu,cardmaisuu,&result);
		printf("%d\n",result);
	}
	return 0;
}

void addcard(char cards[],char nowcard[],
	char cardkouho[],int cardnokori[],
	int nowmaime,int max,int cardkouhomaisuu,
	int* cardmaisuu) {
	int i;
	int ii;
	int ng;
	int cardlen;
	for(i=0;i<cardkouhomaisuu;i++) {
		if(cardnokori[i]==1) {
			cardnokori[i]=0;
			cardlen=strlen(nowcard);
			strcat(nowcard,&cardkouho[3*i]);
			if(nowmaime<max) {
				addcard(cards,nowcard,cardkouho,
					cardnokori,nowmaime+1,max,
					cardkouhomaisuu,cardmaisuu);
			} else {
				ng=0;
				for(ii=0;ii<(*cardmaisuu);ii++) {
					if(strcmp(nowcard,&cards[10*ii])==0) {
						ng=1;
						break;
					}
				}
				if(ng==0) {
					strcpy(&cards[10*(*cardmaisuu)],nowcard);
					(*cardmaisuu)++;
				}
			}
			nowcard[cardlen]=0;
			cardnokori[i]=1;
		}
	}
}

Measured memory_bytes: 0
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t=sc.next();
    t=t+t;
    System.out.println(t.contains(s)?"Yes":"No");
  }
}

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

using namespace std;

using ll = long long;

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

    ll n;
    cin >> n;
    vector<ll> a(3 * n);
    for (int i = 0; i < 3 * n; ++i) cin >> a[i];

    // n <= k < 2 * n
    vector<ll> score(n + 1);

    ll sum = 0;
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    for (int i = 0; i < n; ++i) {
        sum += a[i];
        que1.push(a[i]);
    }
    score[0] = sum;

    ll sum2 = 0;
    for (int i = 1; i <= n; ++i) {
        que1.push(a[n + i - 1]);
        sum += a[n + i - 1];
        sum2 += que1.top(); que1.pop();
        score[i] = sum - sum2;
    }

    sum = 0;
    priority_queue<ll> que2;
    for (int i = 0; i < n; ++i) {
        sum += a[3 * n - i - 1];
        que2.push(a[3 * n - i - 1]);
    }
    score[n] -= sum;

    ll sum3 = 0;
    for (int i = n - 1; 0 <= i; --i) {
        que2.push(a[n + i]);
        sum += a[n + i];
        sum3 += que2.top(); que2.pop();
        score[i] -= sum - sum3;
    }

    cout << *max_element(score.begin(), score.end()) << endl;

    return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

bool need(int index,int N,int K,const vector<ll>& a){
    vector<bool> e(K+1,false);
    e[0] = true;
    for(int i=0;i<N;i++){
        if(i==index) continue;
        for(int j=K;j>=0;j--){
            if(e[j] and j+a[i]<=K) e[j+a[i]]=true;
        }
    }
    for(int i=max<ll>(0,K-a[index]);i<K;i++) if(e[i]) return true;
    return false;
}

int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    sort(all(a));

    if(need(0,N,K,a)){
        cout << 0 << endl;
        return 0;
    }
    if(!need(N-1,N,K,a)){
        cout << N << endl;
        return 0;
    }

    int l,r;    // l : NG , r : OK
    l = -1;     // NG
    r = N-1;    // OK
    while(r-l>1){
        int mid=(l+r)/2;
        bool ret = need(mid,N,K,a);
        if(ret){
            r = mid;
        }else{
            l = mid;
        }
    }
    cout << l+1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=32e4;

char s[N];

int main(){
	ios::sync_with_stdio(0);
	cin>>s;
	int n=strlen(s);
	int c1=0,c2=0;
	for(int i=n/2+1;i<n;i++){
		if(s[i]==s[i-1])c1++;
		else break;
	}
	for(int i=(n-1)/2-1;i>=0;i--){
		if(s[i]==s[i+1])c2++;
		else break;
	}
	if(n%2==0 && s[n/2]!=s[n/2-1])c1=-1;
	//cout<<c1<<' '<<c2<<'\n';
	cout<<n/2+min(c1,c2)+1;
	return 0;
}


Measured memory_bytes: 384
unittest
{
	assert( [ "6", "1 2 3 4 5 6" ].parse.expand.solve == 1 );
	assert( [ "2", "10 -10" ].parse.expand.solve == 20 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto x = as[ 0 ];
	auto y = as[ 1 .. $ ].sum;
	auto d = ( x - y ).abs;
	foreach( a; as[ 1 .. $ - 1 ] )
	{
		x += a;
		y -= a;
		d = min( d, ( x - y ).abs );
	}
	return d;
}


Measured memory_bytes: 11392
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

const int mod=1e9+7;
#define ll long long

ll dp[110][21];


int main(){
	int n;
	string s;
	cin>>n>>s;
	if(s.size()%2!=0){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<n/2;i++){
		int j=i+n/2;
		if(s[i]!=s[j]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
'use strict';
(function(stdin) {
  var line = stdin.split('\n');
  var param = line[0].split(' ').map(Number);
  var result = (function(width,height,x,y,r) {
    return {true:'No',false:'Yes'}[[
        y + r > height
        ,y - r < 0
        ,x - r < 0
        ,x + r > width
    ].some(function(v){
        return v;
    })];
  }(
    param[0],param[1],param[2],param[3],param[4]
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

const long long inf = (long long)1e18;

long long n, ans = inf;

long long gcd(long long x, long long y) {
	if (x < y) swap(x, y);
	while (y) {
		long long r = x % y;
		x = y, y = r;
	}
	return x;
}

int main() {
	scanf("%lld", &n);
	n <<= 1;
	ans = min(ans, n - 1);
	for (int i = 1; 1ll * i * i <= n; i++) {
		if (n % i == 0) {
			long long x = i, y = n / i;
			if (gcd(x, y) > 1) continue;
			long long m = inv_mod(x, y);
			if (x * m > 1) ans = min(ans, x * m - 1);
			m = inv_mod(y, x);
			if (y * m > 1) ans = min(ans, y * m - 1);
		}
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 3832