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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    int n, m;
    cin>>n>>m;
    vvi adj(n);
    for(int i=0; i<m; i++) {
        int u, v;
        cin>>u>>v;
        u--, v--;
        adj[u].PB(v);
    }
    vi a;
    vi marked(n);
    function<void(int) > dfs = [&](int u)
    {
        marked[u] = 1;
        for(int v : adj[u]) {
            if(marked[v]) continue;
            dfs(v);
        }
        a.PB(u);
    };
    for(int i=0; i<n; i++) {
        if(!marked[i]) {
            dfs(i);
        }
    }
    vi dp(n);
    int ans = 0;
    for(int i=0; i<n; i++) {
        int node = a[i];
        for(int to : adj[node]) {
            dp[node] = max(dp[node], 1 + dp[to]);
        }
        ans = max(ans, dp[node]);
    }
    cout << ans << "\n";
    return 0;
}



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

int main() {
  int a, b ,c, k, count;
  cin >> a >> b >> c >> k;
  count = a;
  if (k<=a)
    cout << k <<endl;
  else{
    if (k>=a+b){
      for(int j=0; j<(k-a-b); j++){
        count--;
      }
      cout << count << endl;
    }
    else
      cout << a << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vector<double> p(n);
    rep(i, n) cin >> p[i];
    rep(i, n) {
        p[i] = (p[i]+1)/2;
    }
    vector<double> psum(n+1, 0);
    rep(i, n) psum[i+1] = psum[i]+p[i];
    double ans = 0;
    rep(i, n-k+1) {
        chmax(ans, psum[k+i] - psum[i]);
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 5005;

int a[MAX_N];
ll sm[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    rep(i,n){
        cin >> a[i];
    }
    sort(a, a+n, greater<int>());
    rrep(i,n){
        sm[i] = sm[i+1] + a[i];
    }
    int ans = 0;
    bitset<MAX_N> dp;
    dp[0] = true;
    rep(i,n){
        if(K+a[i]-sm[i] > 0){
            bool flag = true;
            srep(j,max(0LL, K-sm[i]),K+a[i]-sm[i]){
                if(dp[j]) flag = false;
            }
            ans += flag;
        }
        dp |= (dp << a[i]);
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
#define BUF (1000)
#define ll long long 

int n;
vector<int> a;

int main(void){
	cin >> n;
	for(int i=0;i<n;i++){
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

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

	int k;
	int mx = 0;
	int ans;
	for( int i=0;i<n-1;i++){
		int tmp = min(a[n-1]-a[i],a[i]);
		if(mx<tmp){
			mx = tmp;
			ans = i;
		}
	}

	cout << a[n-1] << " " << a[ans] << endl;	
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define int long long
#define INF 1e+18
using namespace std;

struct person{ int h,p; };

int dp[2][5010],*now = dp[0],*nxt = dp[1];

signed main(){
	int n;
	vector<person> vec;
	cin >> n;
	for(int i = 0;i < n;i++){
		int h,p;
		cin >> h >> p;
		vec.push_back({h,p});
	}
	for(int i = 0;i <= n + 1;i++) now[i] = INF;
	now[0] = 0;
	sort(vec.begin(),vec.end(),[](const person p1,const person p2){ return p1.p + p1.h < p2.p + p2.h; });
	for(int i = 0;i < n;i++){
		for(int j = 0;j <= n + 1;j++) nxt[j] = INF;
		for(int j = 0;j <= i;j++){
			nxt[j] = min(nxt[j],now[j]);
			if(now[j] <= vec[i].h) nxt[j + 1] = min(nxt[j + 1],now[j] + vec[i].p);
		}
		swap(now,nxt);
	}
	for(int i = 0;i <= n + 1;i++){
		if(now[i] == INF){
			cout << i - 1 << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,k,t=1;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        if(2*t<t+k) t*=2;
        else t+=k;
    }
    cout << t;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
  for (int i = 0; i < h; i++) {
    cout << '#' << s[i] << '#' << endl;
  }
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
  return 0;
}

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

int main(void){
  int N, ans;
  cin >> N;
  vector<int> h(N);
  ans=0;
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  
  for (int i=0; i<N; i++){
  	while(h[i] != 0){
      for (int j=i; j<N;j++){
        if (h[j] == 0) break;
         h[j] -=1;
      }
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
const Main = (input) => {
  const Sarr = input.trim()

  var count = 0
  var tmp = ''
  var current = ''
  var resultArr = []

  for (var j = 0; j < Sarr.length; j++) {
    current += Sarr[j]

    if (current === tmp) continue

    tmp = current
    resultArr.push(current)

    current = ''
    count += 1
  }

  var result = resultArr.length

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)


void func(long long N){
    long long ans = N/2 + N%2;
    cout << ans << endl;
}

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

    long long N;
    scanf("%lld",&N);
    func(N);
    return 0;
}


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

#define INF INT_MAX

using namespace std;

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

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

    int A,B,C;
    cin >> A >> B >> C;
    
    int ab,bc,ac;
    ab = abs(A+B);
    bc = abs(C+B);
    ac = abs(A+C);

    int ans;
    if(ab > bc){
        if(bc > ac){
            ans = ac;
        }else{
            ans = bc;
        }
    }else{
        if(ab > ac){
            ans = ac;
        }else{
            ans = ab;
        }
    }
    
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <algorithm>      //sort,二分探索,など
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <iterator>       //集合演算(積集合,和集合,差集合など)
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;


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

	int n, ts;
    cin >> n >> ts;
    string name;
    int time;
	queue<pair<string, int>> q;
    for(int i = 0; i < n; ++i){
        cin >> name >> time;
        q.emplace(make_pair(name, time));
    }
    int time_stamp = 0;
    pair<string, int> tmp;
    while(!q.empty()){
        if(q.front().second <= ts){
            time_stamp += q.front().second;
            cout << q.front().first << " " << time_stamp << "\n";
            q.pop();
        }else{
            q.front().second -= ts;
            time_stamp += ts;
            tmp = q.front();
            q.pop();
            q.push(tmp);
        }
    }
        
	return 0;
}


Measured memory_bytes: 6332
#include<stdio.h>

int main(){
	int N/*人数*/, D/*日数*/, X/*残量*/;
	scanf("%d", &N);
	scanf("%d %d", &D, &X);
	
//	printf("%d %d %d\n", N, D, X);
	
	int A[N], i;
	
	for(i=0; i<N; i++){
//		printf("\ni=%d\n", i);
		scanf("%d", &A[i]);
//		printf("%d  %d\n", i, A[i]);
	}
	
	int B[N];
	for(i=0; i<N; i++){
		int day=1, j=0;
		do{
			day += A[i];
			j++;
		}while(day<=D);
		B[i] = j;
	}
	
	for(i=0; i<N; i++)	X += B[i];
	
	printf("%d", X);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
ll nCr(ll n, ll r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}

int main() {
	ll n, m;
	cin >> n >> m;
	if (n > 1) {
		n = nCr(n, 2);
	}
	else {
		n = 0;
	}
	if (m > 1) {
	m = nCr(m, 2);
	}
	else {
		m = 0;
	}
	//cout << n << " " << m << endl;
	cout << n + m << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    int l[110];
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    int cnt = 0;
    for (int i = 0; i < n - 2; i++)
    {
        for (int j = i + 1; j < n - 1; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (l[i] != l[j] && l[i] != l[k] && l[j] != l[k])
                {
                    if (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[k] + l[j] > l[i])
                    {
                        cnt++;
                    }
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef short int sh;

const int inf=0x3f3f3f3f;
const int MAX=1e2+10;
const int mod=1e9+7;

struct STR
{
    char str[MAX];
    bool operator< (const STR&p) const;
}s[MAX];
bool STR::operator< (const STR&p) const
{
    for(int i=0;str[i];i++)
    {
        if(str[i]<p.str[i])
            return true;
        else if(str[i]>p.str[i])
            return false;
    }
    return false;
}

int main()
{
    int n,l;
    while(scanf("%d%d",&n,&l)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%s",s[i].str);
        sort(s,s+n);
        for(int i=0;i<n;i++)
            printf("%s",s[i].str);
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 3228
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int cost[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

    int N;
    cin >> N;
    ll ret = 0;
    for (int i = 0; i < N; i++)
    {
        ll a;
        cin >> a;
        ret = gcd(a, ret);
    }
    cout<<ret<<endl;
    
/*
    int N, M;
    cin >> N >> M;
    vector<int> use(10, 0);
    while (M--)
    {
        int a;
        cin >> a;
        use[a] = 1;
    }
    vector<string> dp(N + 1);
    vector<int> dig(N + 1, -1);
    dp[0] = "";
    dig[0] = 0;
    for (int i = 0; i <= N; i++)
    {
        if (dig[i] == -1)
            continue;
        for (int j = 9; j >= 1; j--)
        {
            if (!use[j])
                continue;
            int next = i + cost[j];
            if (next > N)
                continue;
            if (dig[next] > dig[i] + 1)
                continue;
            if (dig[next] == -1 || dig[next] < dig[i] + 1)
            {
                dp[next] = dp[i] + (char)('0' + j);
                dig[next] = dp[next].size();
            }
            else
            {
                dp[next] = max(dp[next], dp[i] + (char)('0' + j));
            }
        }
    }
    cout << dp[N] << endl;
*/
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String moto=sc.next();
		if(moto.length()>1) {
			int aa=Integer.parseInt(moto.charAt(0)+"");
			int keta=moto.length()-1;

			int sonomama=0;

			for(int i=0; i<moto.length(); i++) {
				sonomama+=Integer.parseInt(moto.charAt(i)+"");
			}
			System.out.println(Math.max(keta*9+aa-1,sonomama));
		}
		else if(moto.length()==1) {
			System.out.println(moto);
		}
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt();
		int[] a=new int[N];
		int i,alice=0,bob=0;
		for(i=0;i<N;i++) {
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		for(i=N-1;i>=0;i--) {
			if(N%2==0) {
				if(i%2!=0)alice+=a[i];
				else bob+=a[i];
			}else {
				if(i%2==0)alice+=a[i];
				else bob+=a[i];
			}
		}
		System.out.println(alice-bob);
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <map>

using namespace std;

const int MOD = 1e9 + 7;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, int> cnt;
    for(auto c: s){
        cnt[c]++;
    }

    long long ans = 1; 
    for(auto t: cnt){
        ans = (ans * (t.second+1)) % MOD;
    }

    cout << ans - 1 << endl;

    return 0;
}
       


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;

int main(void){
    int n, s;
    cin >> n >> s;
    VI a(n);
    REP(i,n) a[i] = in();
    ll ans = 0;
    VL dp(s + 1);
    dp[0] = 1;
    REP(i,n){
        if (a[i] <= s) ans = (ans + (n - i) * dp[s - a[i]]) % mod;
        FORR(j,s,a[i]){
            dp[j] = (dp[j] + dp[j - a[i]]) % mod;
        }
        dp[0]++;
    }
    cout << ans << endl;
    return 0;
}


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


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans;
    if (a-b > c) {
        ans = 0;
    } else {
        ans = c - (a - b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N;
int A[1000005];
int B[1000005];

priority_queue<pair<int,int>> s;

int main() {
    ios_base::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> A[i];
    for(int i = 0; i < N; i++) {
        cin >> B[i];
        if(A[i] != B[i]) s.push({B[i], i});
    }
    long long ans = 0;
    while(!s.empty()) {
        int pos = s.top().second;
        s.pop();

        int nxt = max(B[(pos - 1 + N) % N] , max(B[(pos + 1) % N], A[pos]));
        int neg = B[(pos - 1 + N) % N] + B[(pos + 1) % N];
        int diff = max(1, (B[pos] - nxt) / neg);
        ans += diff;
        B[pos] -= diff * neg;
        if(B[pos] < A[pos]) {
            cout << -1;
            return 0;
        } else if(B[pos] != A[pos]) {
            s.push({B[pos], pos});
        }
    }

    for(int i = 0; i < N; i++)
        if(A[i] != B[i]) {
            cout << -1;
            return 0;
        }

    cout << ans;
}


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

int main(){
int X,Y;
int ans=0;


    cin>>X>>Y;;

if(Y%2!=0){
    cout<<"No"<<endl;
}else if(4*X>=Y && 2*X<=Y){
cout<<"Yes"<<endl;

}else{
    cout<<"No"<<endl;
}


    return 0;
    
}

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

int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  
  int ans = 0;
  for(int i = 0; i <= a; i++){
    for(int j = 0; j <= b; j++){
      for(int k = 0; k <= c; k++){
        if(500 * i + 100 * j + 50 * k == x){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100
#define INFTY 1000000000
#define white 0
#define gray 1
#define brack 2

int A[MAX][MAX],p[MAX];

void prim(int);

int main(){
  int n,i,e,j,sum;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      A[i][j] = (e==-1) ? INFTY:e;
    }
  }
  prim(n);

  sum=0;
  for(i=0;i<n;i++){
    if(p[i] != -1) sum += A[i][p[i]];
  }
  printf("%d\n",sum);

  return 0;
  
}

void prim(int n){
  int u,d[MAX],color[MAX],mincost,i,v,j;

  for(j=0;j<n;j++){

  color[j] = white;
  d[j] = INFTY;
  }

  d[0] = 0;
  p[0] = -1;

  while(1){
    mincost = INFTY;
    for(i=0;i<=n-1;i++){
      if(color[i] != brack && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == INFTY) break;

    color[u] = brack;

    for(v=0;v<=n-1;v++){
      if(color[v] != brack &&A[u][v] != INFTY){
	if(A[u][v] < d[v]){
	  d[v] = A[u][v];
	  p[v] = u;
	  color[v] = gray;
	}
      }
    }
  }
}

      
    
  



Measured memory_bytes: 2048
#include <stdio.h>
#include <stdlib.h>
#define MN 100000
int n,l,a[MN+5],b;
int main(){
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(b=1;b<=n-1;b++)
		if(a[b]+a[b+1]>=l)break;
	if(b==n) puts("Impossible"),exit(0);
	puts("Possible");
	for(int i=1;i<b;i++)
		printf("%d\n",i);
	for(int i=n-1;i>b;i--)
		printf("%d\n",i);
	printf("%d\n",b);
}

Measured memory_bytes: 1152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC129_b solver = new ABC129_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC129_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int arr[] = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = in.nextInt();
            }
            int diff = 999;
            for (int T = 0; T < N; T++) {
                int left = 0;
                int right = 0;
                for (int i = 0; i < N; i++) {
                    if (i <= T) {
                        left += arr[i];
                    } else {
                        right += arr[i];
                    }
                }
                if (diff > (Math.abs(left - right))) {
                    diff = (Math.abs(left - right));
                }
            }
            out.println(diff);

        }

    }
}



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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  int a[3];
  int temp=0;
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  
  if(a[0]&&a[1]&&!a[2]||!a[0]&&!a[1]&&a[2]) printf("Open\n");
  else printf("Close\n");
  
  return (0);
}



Measured memory_bytes: 3168
max = gets.to_i
songs = []
for num in 0...max do
 songs.push(gets.split)
end
x = gets.chomp

sleep_num = 0

for i in 0...max do
  if songs[i][0] == x then
    sleep_num = i+1
  end
end

time = 0

for num in sleep_num...max do
  time += songs[num][1].to_i
end

print time

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int x,n;
  cin>>x>>n;
  map<long long int,bool> hoge;
  for(long long int i=0; i<n; i++){
    long long int a;
    cin>>a;
    hoge[a]=true;
  }

  long long int ans;
  long long int sa=999999999999;
  for(long long int i=0; i<=101; i++){
    if(hoge.count(i)==true){
      continue;
    }

    if(abs(x-i)<sa){
      sa=abs(x-i);
      ans=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;


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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int ans=1;
    int cnt = 0;
    while(ans != 2){
        int x = ans-1;
        ans = a[x];
        a[x] = 1;
        cnt++;
        if(ans == 1) break;
    }
    if(ans == 2) cout << cnt << endl;
    else cout << -1 << endl;
    cout << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.*; 

public class Main { 

	static int MAX = 1000001; 
	static int factor[]; 

	// function to generate all prime 
	// factors of numbers from 1 to 10^6 
	static void generatePrimeFactors() 
	{ 
		factor[1] = 1; 

		// Initializes all the positions with 
		// their value. 
		for (int i = 2; i < MAX; i++) 
			factor[i] = i; 

		// Initializes all multiples of 2 with 2 
		for (int i = 4; i < MAX; i += 2) 
			factor[i] = 2; 

		// A modified version of Sieve of 
		// Eratosthenes to store the 
		// smallest prime factor that 
		// divides every number. 
		for (int i = 3; i * i < MAX; i++) { 
			// check if it has no prime factor. 
			if (factor[i] == i) { 
				// Initializes of j starting from i*i 
				for (int j = i * i; j < MAX; j += i) { 
					// if it has no prime factor 
					// before, then stores the 
					// smallest prime divisor 
					if (factor[j] == j) 
						factor[j] = i; 
				} 
			} 
		} 
	} 

	// function to calculate number of factors 
	static int calculateNoOFactors(int n) 
	{ 
		if (n == 1) 
			return 1; 

		int ans = 1; 

		// stores the smallest prime number 
		// that divides n 
		int dup = factor[n]; 

		// stores the count of number of times 
		// a prime number divides n. 
		int c = 1; 

		// reduces to the next number after prime 
		// factorization of n 
		int j = n / factor[n]; 

		// false when prime factorization is done 
		while (j != 1) { 
			// if the same prime number is dividing n, 
			// then we increase the count 
			if (factor[j] == dup) 
				c += 1; 

			/* if its a new prime factor that is 
			factorizing n, then we again set c=1 
			and change dup to the new prime factor, 
			and apply the formula explained 
			above. */
			else { 
				dup = factor[j]; 
				ans = ans * (c + 1); 
				c = 1; 
			} 

			// prime factorizes a number 
			j = j / factor[j]; 
		} 

		// for the last prime factor 
		ans = ans * (c + 1); 

		return ans; 
	} 

	/* Driver program to test above function */
	public static void main(String[] args) 
	{ 
		// array to store prime factors 
		factor = new int[MAX]; 
		factor[0] = 0; 

		// generate prime factors of number 
		// upto 10^6 
		generatePrimeFactors(); 
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
		int res=0;
		for (int i = 1; i < n; i++) 
			res+=calculateNoOFactors(i);
      	System.out.println(res);
        sc.close();
	} 
} 

// This code is contributed by Arnav Kr. Mandal. 



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n; cin >> n;
	vector<int> a(n), b(n);
	
	rep(i, n) {
		cin >> a[i];
		b[i] = a[i] - i - 1;
	}
	sort(b.begin(), b.end());
	int med = b[b.size() / 2];
	
	ll ans = 0;
	rep (i, n) ans += abs(a[i] - (med + i + 1));
	cout << ans << endl;
}



Measured memory_bytes: 1792
n, m = map(int, input().split())
h = list(map(int, input().split()))

tmp = []
ans = [0]*n
for i in range(m):
    a, b = map(int, input().split())
    tmp.append([a, b])

    if h[a-1] == h[b-1]:
        ans[a-1] = -1
        ans[b-1] = -1
    else:
        if h[a-1] > h[b-1]:
            ans[b-1] = -1
        else:
            ans[a-1] = -1

ans_ = ans.count(0)
print(ans_)






Measured memory_bytes: 92276
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x); cout<<#x<<"="<<x<<endl;
#define debug2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long
using namespace std;
const long long mod=1e9+7;


long long inverseMod(long long x,long long mod);
long long nCr(long long n,long long r,long long mod){
    //when r is lesser and is greater
    long long res=1;
    if(r>n-r)r=n-r;
    long long div=1;
    for(long long  i=0;i<r;i++){
        res=(res*(n-i))%mod;
    }

    for(long long i=1;i<=r;i++){
        div=(div*i)%mod;
    }
    return (res*inverseMod(div,mod))%mod;
}


long long power(long long x,long long n,long long mod){
//(x^n)%mod
long long result=1;

    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

long long inverseMod(long long x,long long mod){

return power(x,mod-2,mod);
}


int arr[15][15];
int32_t main(){

    fast
    int n,m,x;
    int price[15];
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        cin>>price[i];
        for(int j=0;j<m;j++){
            cin>>arr[i][j];
        }
    }
    int isPoss[15];
    int mini=INT_MAX;
    for(int i=0;i<(1<<n);i++){
        memset(isPoss,0,sizeof isPoss);
        int cost=0;
        for(int j=0;j<n;j++){
            if((i&(1<<j))!=0){
                for(int k=0;k<m;k++){
                    isPoss[k]+=arr[j][k];
                }
                //watch(j);
                cost+=price[j];
            }
        }
        bool b=true;
        for(int j=0;j<m;j++){
            if(isPoss[j]<x)b=false;
        }
        if(b){
            mini=min(cost,mini);
        }
    }
    if(mini==INT_MAX){
        cout<<-1;
    }
    else{
        cout<<mini;
    }




    return 0;
}



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

#define fi freopen("i.txt", "r", stdin)
#define fo freopen("o.txt", "w", stdout)
#define SIO ios_base :: sync_with_stdio(false); cin.tie(0)
#define fs first
#define sc second
#define cn(a) cin >> a
#define cn2(a, b) cin >> a >> b
#define cn3(a, b, c) cin >> a >> b >> c
#define cn4(a, b, c, d) cin >> a >> b >> c >> d
#define sf(a) scanf("%d", &a)
#define sf2(a, b) scanf("%d %d", &a, &b)
#define sf3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sf4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define sfl(a) scanf("%lld", &a)
#define sfl2(a, b) scanf("%lld %lld", &a, &b)
#define sfl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define sfl4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define pnl() putchar('\n')
#define fli(i, a, b, c) for(int i = a; i < b; i += c)
#define flie(i, a, b, c) for(int i = a; i <= b; i += c)
#define fls(i, a, b) for(int i = a; i < b; i++)
#define flse(i, a, b) for(int i = a; i <= b; i++)
#define fl(i, n) fls(i, 0, n)
#define fle(i, n) flse(i, 1, n)
#define ll long long
#define ld long double
#define vi vector <int>
#define vll vector <ll>
#define ii pair <int, int>
#define pll pair <ll, ll>
#define iii pair <int, pair <int, int> >
#define lll pair <ll, pair <ll, ll> >
#define vii vector <ii>
#define vpll vector <pll>
#define vlll vector <lll>
#define pb push_back
#define ins insert
#define fr front
#define mp make_pair
#define PI acos(-1.0)
#define INF 10000000
#define LINF 1000000000000
#define piiii pair <ii, ii>
#define sq(a) a * a
#define MOD 1000000007
#define all(x) x.begin(), x.end()
#define gc() getchar()
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define matrixCh vector <vector <char> >
#define matrixInt vector <vector <int> >

int main()
{
    ll arr[3];
    cin >> arr[0] >> arr[1] >> arr[2];
    
    if((arr[0] & 1) || (arr[1] & 1) || (arr[2] & 1))
    {
        cout << 0 << endl;
        return 0;
    }

    if(arr[0] == arr[1] && arr[1] == arr[2] && arr[0] == arr[2])
    {
        cout << -1 << endl;
        return 0;
    }

//    sort(arr, arr + 3);
    ll p = arr[2], s = 0;

    while(true)
    {
        ll x = (arr[1] + arr[2]) / 2LL;
        ll y = (arr[0] + arr[2]) / 2LL;
        ll z = (arr[0] + arr[1]) / 2LL;
        arr[0] = x, arr[1] = y, arr[2] = z;
        ++s;

        if((arr[0] & 1) || (arr[1] & 1) || (arr[2] & 1))
        {
            cout << s << endl;
            return 0;
        }
        
        if(arr[0] == arr[1] && arr[1] == arr[2])
        {
            cout << -1 << endl;
            return 0;
        }

        if(s == 100000)
        {
            cout << -1 << endl;
            return 0;
        }
    }

    return 0;
}

//int main()
//{
//    int a, b, c, i = 0;
//    cin >> a >> b >> c;
//
//    while(!(a & 1) && !(b & 1) && !(c & 1))
//    {
//        int x = (b + c) >> 1;
//        int y = (a + c) >> 1;
//        int z = (a + b) >> 1;
//        a = x, b = y, c = z, i++;
//
//        if(i == 100000)
//        {
//            cout << -1 << endl;
//            return 0;
//        }
//    }
//
//    cout << i << endl;
//    return 0;
//}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int n,dp[100001],a[12]={1,6,36,216,1296,7776,46656,9,81,729,6561,59049};
int main(){
	sort(a,a+12);
	cin>>n;
	for(int i=0;i<=n;i++)dp[i]=i;
	for(int i=1;i<=n;i++){
		for(int j=0;j<12;j++){
			if(i-a[j]>=0){
				dp[i]=min(dp[i],dp[i-a[j]]+1);
			}
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 640
N, Q = map(int, input().split())
S = input()
T = [0]*(N+1)

for i in range(1, N):
    T[i+1] = T[i] + (1 if S[i-1:i+1]=='AC' else 0)
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(T[r] - T[l])
print(*ans, sep='\n')

Measured memory_bytes: 15028
#include <iostream>
using namespace std;
int main()
{
    int x,y;
    cin >> x >> y;

    int tsuru = 4 * x - y;
    int kame = y - 2 * x;

    if (tsuru >= 0 && tsuru % 2 == 0) {
        if (kame >= 0 && kame % 2 == 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        cout << "No" << endl;
    }

    return 0;

}




Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main() 
{
	int n,m,a;
	cin>>n>>m;
	int sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>a;
		sum+=a;
	}
	if(sum<=n)
	{
		cout<<n-sum<<endl;
	}
	else
		cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
using namespace std;
int main() {
	string a, b;
	ll n, N;
	cin >> n >> a >> b;
	N = n;
	for (int i = 0; i < n; i++) {
		if (a.substr(i, n - i) == b.substr(0, n - i)) break;
		N++;
	}
	cout << N << endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>


int IsPrime(int);

int p[1000001] = {0};

int main()
{
	int i, j, n, count, buf[1000] = {0};
	for(i=2; i<=1000000; i++)
		p[i] = 1;
	j = 0;
	for(i=0; i<=1000; i++){
		if(IsPrime(i) == 1){
			buf[j] = i;
			j++;
		}
	}
	for(i=0; i<168; i++){
		for(j=2*buf[i]; j<=1000000; j+=buf[i])
			p[j] = 0;
	}

	while(scanf("%d", &n) != EOF){
		i = n-1;
		while(1){
			if(p[i] == 1){
				printf("%d", i);
				break;
			}
			i--;
		}
		printf(" ");
		i = n+1;
		while(1){
			if(p[i] == 1){
				printf("%d", i);
				break;
			}
			i++;
		}
		printf("\n");
	}

	return 0;
}


int IsPrime(int n)
{
    int i;
 
    if(n < 2)
        return 0;
    else if(n == 2)
        return 1;
 
    if(n % 2 == 0)
        return 0;
 
	for(i = 3; i * i <= n; i += 2){
         if(n % i == 0)
            return 0;
	}
    return 1;
}

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

#include <iostream>
#define fastio                              ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fastio;
    long long n, d, sum = 0, x;
    cin >> n >> d;
    for(long long i = 0; i < d; i++){
        cin >> x;
        sum += x;
    }
    if(n < sum) cout << -1;
    else cout << n-sum;
}

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

#define MAXN 30

int main(){
	string s;
	cin>>s;
	int arr[MAXN]={0};
	for(int i=0;i<s.size();i++){
		arr[s[i]-97]++;
	}
	int flag=0;
	for(int i=0;i<26;i++){
		if(arr[i]>1){
			flag=1;
		}
	}
	if(flag==1){
		cout<<"no";
	}else{
		cout<<"yes";
	}
	return 0;
}

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

bool indexWise(vector<ll>&a,vector<ll>&b){
	return a[1]<b[1];
}

void update(vector<int>&v,int val,int pos){
	while(pos<v.size()){
		v[pos]+=val;
		pos+=(pos&(-pos));
	}
}

ll query(vector<int>&v,int pos){
	ll ans=0;
	while(pos>0){
		ans+=v[pos];
		pos-=(pos&(-pos));
	}
	return ans;
}

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

 vector<int> BIT(500005);
 //last_bit->last index
 vector<int> last_bit(500005,-1);
 int qry=0;
 vector<vector<ll>> sol(q);
 for(int i=0;i<n;i++){
 	if(last_bit[v[i]]!=-1){
 		update(BIT,-1,last_bit[v[i]]+1);
	}
	last_bit[v[i]]=i;
	update(BIT,1,i+1);
	//cout<<i<<endl;
	while(qry<q && Q[qry][0]==i){
		//cout<<i<<endl;
		sol[qry]={query(BIT,Q[qry][0]+1)-query(BIT,Q[qry][1]),Q[qry][2]};
		qry++;
	}
 }
 sort(sol.begin(),sol.end(),indexWise);
 for(int i=0;i<q;i++){
 	cout<<sol[i][0]<<endl;
 }
 return 0;
}



Measured memory_bytes: 66312
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;
const int MOD=1000000007;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }

int n;
int a[MAXN];

int nxt[MAXN];
int lst[MAXN];
int dp[MAXN+1];

int solve() {
	memset(lst,-1,sizeof(lst));
	REP(i,n) nxt[i]=-1;
	REP(i,n) { if(lst[a[i]]!=-1) nxt[lst[a[i]]]=i; lst[a[i]]=i; }

	dp[n]=1;
	for(int i=n-1;i>=0;--i) {
		dp[i]=dp[i+1];
		if(nxt[i]!=-1&&nxt[i]!=i+1) inc(dp[i],dp[nxt[i]]);
	}
	return dp[0];
}

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]),--a[i];
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<cmath>
#include<unordered_map>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#include<iomanip>
#include<string>
#include<map>
#define PI 3.14159265
#define mod 998244353  
#define mod1 1e9 + 7  
using namespace std;

 
void func(){
    int n , k;
    cin >> n >> k;
    int arr[n];
    for(int i = 0 ; i < n ; ++i) cin >> arr[i];
    bool dp[k + 1];
    dp[0] = 0;

    for(int i = 1 ; i <= k ; ++i){
        dp[i] = 0;
        for(int j = 0 ; j < n ; ++j){
            if(arr[j] <= i){
                if(dp[i - arr[j]] == 0){
                    dp[i] = 1;
                    break;
                }
            }
        }
      //  cout << dp[i] << " ";
    }

    if(dp[k] == 1){
        cout << "First\n";
        return;
    }
    else{
        cout << "Second\n";
    }
    
}

int main(){
    int t = 1 , cnt = 0 ;
   // cin >> t;
    
    while(t--){
        
        func();
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pa = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//
ll lcm(ll a, ll b) {
    ll aa = a, bb = b;
    ll r = a % b;
    while (r != 0) {
        a = b, b = r;
        r = a % b;
    }
    return aa * bb / b;
}
int main() {
    init();
    ll N, M;
    cin >> N >> M;
    vl a(N);
    rep(i, N) {
        ll tmp;
        cin >> tmp;
        a[i] = tmp / 2;
    }
    ll v = 1;
    rep(i, N) {
        v = lcm(v, a[i]);
        if (v > M) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, N) {
        if (v / a[i] % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    
    
    cout << (M / v + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>

using namespace std;

int main()
{
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	
	int ans = min(abs(a1 - a2), abs(a1 - a3));
	ans += abs(a2 - a3);

	int t = min(abs(a2 - a1), abs(a2 - a3));
    t += abs(a1 - a3);
    
    if(ans > t)
      ans = t;
    
    t = min(abs(a3 - a1), abs(a3 - a2));
    t += abs(a1 - a2);
  
    if(ans > t)
      ans = t;
  
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int n,an=0,bn=0,abn=0,on=0;
  char s[3];
  while(scanf("%d,%s",&n,s)!=-1){
    if(strcmp(s,"A")==0)
      an++;
    else if(strcmp(s,"B")==0)
      bn++;
    else if(strcmp(s,"AB")==0)
      abn++;
    else if(strcmp(s,"O")==0)
      on++;
  }
  printf("%d\n%d\n%d\n%d\n",an,bn,abn,on);
  return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif

struct UnionFind {
    vector<int> data;

    UnionFind(int size) : data(size, -1) {}

    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }

    bool findSet(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    int size(int x) {
        return -data[root(x)];
    }
};

void solve(ll N, vector<ll> x, vector<ll> y) {
    vector<pair<ll, ll> > ps;
    for (int i = 0; i < N; i++) ps.push_back({x[i], y[i]});
    sort(ps.begin(), ps.end());
    ps.erase(unique(ps.begin(), ps.end()), ps.end());
    N = ps.size();
    map<pair<ll, ll>, int> conv;
    for (int i = 0; i < N; i++) conv[ps[i]] = i;
    vector<pair<ll, pair<int, int> > > es;
    {
        sort(ps.begin(), ps.end(), [&](pair<ll, ll> a, pair<ll, ll> b) { return a.first < b.first; });
        for (int i = 0; i + 1 < ps.size(); i++)
            es.push_back({ps[i + 1].first - ps[i].first, {conv[ps[i]], conv[ps[i + 1]]}});
    }
    {
        sort(ps.begin(), ps.end(), [&](pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; });
        for (int i = 0; i + 1 < ps.size(); i++)
            es.push_back({ps[i + 1].second - ps[i].second, {conv[ps[i]], conv[ps[i + 1]]}});
    }
    sort(es.begin(), es.end());
    UnionFind uf(N);
    long long ans = 0;
    for (auto &e : es) {
        ans += uf.unionSet(e.second.first, e.second.second) * e.first;
    }
    cout << ans << endl;

}


void main_(istream &cin) {
    ll N;
    cin >> N;
    vector<ll> y(N - 1 + 1);
    vector<ll> x(N - 1 + 1);
    for (int i = 0; i <= N - 1; i++) {
        cin >> x[i];
        cin >> y[i];
    }
    solve(N, x, y);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 17392
//1_3_C
#include <stdio.h>
#define True 1

int main(void)
{
	int x, y;
	while(True){
		scanf("%d %d", &x, &y);
		if(x == 0 && y == 0){
			break;
		}

		if(x <= y){
			printf("%d %d\n", x, y);
		}else{
			printf("%d %d\n", y, x);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 123456789012


int main(){
    ll i,j;
    ll n,k,q;
    cin>>n>>k>>q;
    ll s[n+1];
    for(i=1;i<=n;i++){
        s[i]=k-q;
    }
    for(i=0;i<q;i++){
        ll a;
        cin>>a;
        s[a]++;
    }

    for(i=1;i<=n;i++){
        if(s[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    
    return 0;
}

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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  cout << (A.back() - A.front()) << endl;
}

Measured memory_bytes: 256