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

typedef struct Node {
  Node *left, *right;
  int data;
} Node;

Node* base;

void Node_init() {
  base = new Node();
  base->left  = base;
  base->right = base;
  return;
}

void Node_push(int x) {
  Node *node = new Node();
  node->data = x;
  node->right = base;
  node->left  = base->left;
  node->right->left = node;
  node->left->right = node;
  return;
}

int Node_top(void) {
  if( base->left != nullptr ) {
    return base->left->data;
  }
  return 0;
}

void Node_pop(void) {
  Node *node = base->left;
  node->right->left = node->left;
  node->left->right = node->right;
  delete node;
  return;
}
  
int main() {  

  std::string str;

  Node_init();

  while( std::cin >> str ) {
    if( str[0] == '+' ) {
      int right = Node_top(); Node_pop();
      int left  = Node_top(); Node_pop();
      Node_push(left + right);
    }
    else if( str[0] == '-' ) {
      int right = Node_top(); Node_pop();
      int left  = Node_top(); Node_pop();
      Node_push(left - right);
    }
    else if( str[0] == '*' ) {
      int right = Node_top(); Node_pop();
      int left  = Node_top(); Node_pop();
      Node_push(left * right);
    }
    else {
      Node_push( stoi(str) );
    }
  }

  std::cout << Node_top() << std::endl;

  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N;
  cin >>N;
  vector<int> L(N);
  rep(i,N) cin>>L[i];
  sort(L.begin(),L.end());
  int sum=0;
  rep(i,N-1){
    sum += L[i];
  }
  if(sum>L[N-1]) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    string a;
    cin>>a;
    int n=a.length();
    int ans=0;
    int temp=0;
    for (int i=0;i<n;i++)
    {

        if (a[i]=='A'||a[i]=='C'||a[i]=='G'||a[i]=='T')
        {
            temp++;
            ans=max(ans, temp);
        }
        else
        {
            temp=0;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3560
r,c  = map(int, input().split())
tbl = []
tblS = [0 for i in range(c+1)]
for i in range(r):
    tbl.append(input())
    tmpL = tbl[i].split()
    tmpL = [int(j) for j in tmpL]
    print(tbl[i] ,sum(tmpL))
    
    for j in range(c):
        tblS[j] += int(tbl[i].split()[j])
    
    tblS[c] += sum(tmpL)

print(*tblS)


Measured memory_bytes: 5624
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = sum(A)
for i in range(N-1):
    C = A[i]-B[i]
    A[i] = C
    if A[i] < 0:
        A[i] = 0
        A[i+1] = A[i+1] - (-(C))
        if A[i+1] < 0:
            A[i+1] = 0

D = A[-2] - B[-1]    
A[-2] = D

if A[-2] < 0:
        A[-2] = 0
        A[-1] = A[-1] - (-D)
        if A[-1] < 0:
            A[-1] = 0
Y = sum(A)
print(X-Y)

Measured memory_bytes: 18752
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve(){
    int N;
    ll C;
    cin >> N >> C;
    vector<pair<ll, ll>> sushi(N);
    for (int i=0; i<N; i++) {
        cin >> sushi.at(i).first >> sushi.at(i).second;
    }
    vector<ll> forw(N+1), rev(N+1), disForw(N+1), disRev(N+1);
    for (int i=1; i<N+1; i++) {
        forw.at(i) = sushi.at(i-1).second;
        rev.at(i) = sushi.at(N-i).second;
        disForw.at(i) = sushi.at(i-1).first;
        disRev.at(i) = C - sushi.at(N-i).first;
    }
    for (int i=1; i<N+1; i++) {
        forw.at(i) += forw.at(i-1);
        rev.at(i) += rev.at(i-1);
    }
    for (int i=1; i<N+1; i++) {
        forw.at(i) -= disForw.at(i);
        rev.at(i) -= disRev.at(i);
    }
    for (int i=1; i<N+1; i++) {
        if (chmax(forw.at(i), forw.at(i-1))) disForw.at(i) = disForw.at(i-1);
        if (chmax(rev.at(i), rev.at(i-1))) disRev.at(i) = disRev.at(i-1);
    }
    ll ans = -LINF;
    for (int i=0; i<N+1; i++) {
        if (i == N) {
            chmax(ans, forw.at(i));
        } else if (i == 0) {
            chmax(ans, rev.at(N));
        } else {
            chmax(ans, forw.at(i) + rev.at(N-i) - min(disForw.at(i), disRev.at(N-i)));
        }
    }

    cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<int,bool> Pair;

int main(){

  int N;
  string S;
  bool flg = true;

  cin >> N;
  cin >> S;

  if((N%2) == 0){
    
    for(int i = 0; i < N/2; ++i){
      
      if(S[i] != S[(N/2)+i]){

        flg = false;

      }

    }

  }
  else{

    flg = false;

  }

  if(flg) cout << "Yes" << endl;
  else    cout << "No"  << endl;
  
  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

bool test(const vector<string> &vs, int r, int c, int s){
	int rc = 0, cc = 0, sc = 0;
	for(int i = 0; i < vs.size(); ++i){
		int depth = 0, j = 0;
		for(; j < vs[i].size() && vs[i][j] == '.'; ++j){ ++depth; }
		if(depth != r * rc + c * cc + s * sc){ return false; }
		for(; j < vs[i].size(); ++j){
			switch(vs[i][j]){
				case '(': ++rc; break;
				case ')': --rc; break;
				case '{': ++cc; break;
				case '}': --cc; break;
				case '[': ++sc; break;
				case ']': --sc; break;
			}
		}
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int p, q;
		cin >> p >> q;
		if(p == 0 && q == 0){ break; }
		vector<string> x(p), y(q);
		for(int i = 0; i < p; ++i){ cin >> x[i]; }
		for(int i = 0; i < q; ++i){ cin >> y[i]; }
		vector<int> r, c, s;
		for(int i = 1; i <= 20; ++i){
			for(int j = 1; j <= 20; ++j){
				for(int k = 1; k <= 20; ++k){
					if(test(x, i, j, k)){
						r.push_back(i);
						c.push_back(j);
						s.push_back(k);
					}
				}
			}
		}
		int rc = 0, cc = 0, sc = 0;
		for(int i = 0; i < q; ++i){
			if(i != 0){ cout << " "; }
			int depth = -1;
			for(int j = 0; j < r.size(); ++j){
				const int t = rc * r[j] + cc * c[j] + sc * s[j];
				if(j == 0){ depth = t; }
				if(depth != t){ depth = -1; }
			}
			cout << depth;
			for(int j = 0; j < y[i].size(); ++j){
				switch(y[i][j]){
					case '(': ++rc; break;
					case ')': --rc; break;
					case '{': ++cc; break;
					case '}': --cc; break;
					case '[': ++sc; break;
					case ']': --sc; break;
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1364
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

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

   if(n==1 && m==1) cout<<1;
   else if(n==1) cout<<max(m-2,0);
   else if(m==1) cout<<max(n-2,0);
   else cout<<(ll)(n-2)*(m-2);
   
   
   
   return 0;
}


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

struct edge {Int to, cost;};
typedef pair<Int, Int> P;

const Int INF = 1e18;

Int N, S, M;
vector<vector<edge>> G(130000);
vector<Int> d(130000, INF);

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    d[s] = 0;
    que.push(P(0,s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        Int v = p.second;
        if (d[v] < p.first) continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }

}


int main(){
    cin >> N >> M >> S;
    if (S > 2500) S = 2500;

    vector<int> U(M),V(M);
    vector<Int> A(M),B(M);
    rep(i,M) {
        cin >> U[i] >> V[i] >> A[i] >> B[i];
    }
    vector<Int> C(N),D(N);
    rep(i,N) {
        cin >> C[i] >> D[i];
    }
    vector<int> C2(N);
    rep(i,N) {
        if (C[i] > 2500) C2[i] = 2500;
        else C2[i] = C[i];
    }

    

    rep(i,M) {
        for(int s = A[i]; s <= 2500; s++) {
            edge e;
            e.to = (V[i] - 1) * 2600 + s - A[i];
            e.cost = B[i];
            G[(U[i] - 1) * 2600 + s].push_back(e);
        }
        for(int s = A[i]; s <= 2500; s++) {
            edge e;
            e.to = (U[i] - 1) * 2600 + s - A[i];
            e.cost = B[i];
            G[(V[i] - 1) * 2600 + s].push_back(e);
        }
    }
    rep(t,N) {
        rep(s,2501) {
            edge e;
            e.to = t * 2600 + min(2500,s + C2[t]);
            e.cost = D[t];
            G[t * 2600 + s].push_back(e);
        }
    }

    dijkstra(S);

    rep1(i,N-1){
        Int ans = INF;
        rep(j,2501){
            ans = min(ans, d[i*2600+j]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 23756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int main() {
	string s;
	cin >> s;
	int a, b;
	a = b = 0;
	for (char c : s) {
		if (c == 'A') a++;
		else b++;
	}
	cout << (a*b > 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

N, M = tuple(int(n) for n in input().split())

str_list = ['0' for n in range(N)]
str_state = [0 for n in range(N)] #0 if digit unchanged, 1 if changed

#print(str_list)
#print(str_state)


for i in range(M):
    si, ci = tuple(int(n) for n in input().split())
    #print('si: %d, ci: %d' % (si, ci))
    ci = str(ci)
    if str_state[si - 1] == 0:
        str_list[si - 1] = ci
        str_state[si - 1] = 1
        #print(str_list)
        #print(str_state)
    elif str_list[si - 1] != ci:
        print(-1)
        sys.exit(0)
    #else:
    #    pass

for i in range(len(str_list)):
    if str_list[i] != '0':
        break
    else:
        if i == len(str_list) - 1:
            break
        if str_state[i] == 0:
            str_list[i] = '1'
            break

num = str(int(''.join(str_list)))
if len(num) == N:
    print(num)
else:
    print(-1)


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

int main(){
    int n,q,b,c;
    ll ans;
    cin>>n;
    vector<ll>k(MX);
    rep(i,n) {
        int a;
        cin>>a;
        k[a]++;
    }
    ans = 0;
    rep(i,MX) ans += i*k[i];
    cin>>q;
    rep(i,q){
        cin>>b>>c;
        ans -= b*k[b];
        ans -= c*k[c];
        k[c] += k[b];
        k[b] = 0;
        ans += c*k[c];
        cout<<ans<<endl;
    }
}

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

int main(){
  vector<int> is_p(100005, 1);
  is_p[0] = is_p[1] = 0;
  for(int i=2;i<100005;i++){
    if(is_p[i])for(int j=2;i*j<100005;j++){
      is_p[i*j] = 0; 
    }
  }
  vector<int> is_q(100005, 0);
  for(int i=3;i<100005;i+=2){
    is_q[i] = is_p[i] & is_p[(i+1)/2]; 
  }
  for(int i=0;i<100004;i++){
    is_q[i+1] += is_q[i]; 
  }
  int Q;
  cin >> Q;
  for(int i=0;i<Q;i++){
    int l, r;
    cin >> l >> r;
    cout << is_q[r] - is_q[l-1] << endl;
  }
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			D();
		}

		public static void D()
		{
			Scanner cin = new Scanner();
			long x = cin.NextLong();
			long y = cin.NextLong();
			long z = cin.NextLong();
			long k = cin.NextLong();

			long[] ai = new long[x];
			long[] bi = new long[y];
			long[] ci = new long[z];
			for (int i = 0; i < x; ++i) {
				ai[i] = cin.NextLong();
			}

			for (int i = 0; i < y; ++i) {
				bi[i] = cin.NextLong();
			}

			for (int i = 0; i < z; ++i) {
				ci[i] = cin.NextLong();
			}

			long count = 0;
			long w = x * y;
			long[] ww = new long[w];
			for (int i = 0; i < x; ++i) {
				for (int j = 0; j < y; ++j) {
					ww[count] = ai[i] + bi[j];
					++count;
				}
			}

			Array.Sort(ww);
			count = 0;
			long vc = Math.Min(3000, Math.Min(w, k));
			long[] vv = new long[vc * z];
			for (int i = 0; i < vc; ++i) {
				for (int j = 0; j < z; ++j) {
					vv[count] = ww[ww.Length - 1 - i] + ci[j];
					++count;
				}
			}

			Array.Sort(vv);
			for (int n = 0; n < k; ++n) {
				Console.WriteLine(vv[vv.Length - 1 - n]);
			}

			/*
			ci = ci.OrderByDescending(i => i).ToArray();

			int wc = 0;
			int zc = 0;
			for (int n = 0; n < k; ++n) {
				long value = ww[wc] + ci[zc];
				Console.WriteLine(value);

				if (wc < w - 1 && zc < z - 1) {
					if (ww[wc] - ww[wc + 1] > ci[zc] - ci[zc + 1]) {
						++zc;
					} else {
						++wc;
					}
				} else if (wc < w - 1) {
					++wc;
				} else if (zc < z - 1) {
					++zc;
				}
			}
			*/
		}

		
	}

	public class Scanner
	{
		string[] s;
		int i;

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

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}


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

const int MOD = 1000000007;

int main (){
    int r;  cin>> r ;
    cout << r*r << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t = 0;
        for(int i=0;i<3000;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            if(x==0&&y==0) break;
            if(x<=y){
                System.out.println(x+" "+y);
            }else{
                t = x;
                x = y;
                y = t;
                System.out.println(x+" "+y);
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 36360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

bool card[15];  // trueなら先手が所有
int fl, fr, sl, sr, dp[2][15][15];  // dp=[l,r]のカードが置かれているときの勝敗

bool rec(bool turn, int l, int r){
    if(turn && l <= sl && r >= sr){
        return false;
    }
    if(!turn && l <= fl && r >= fr){
        return false;
    }
    if(dp[turn][l][r]>0){
        return dp[turn][l][r] == 1;
    }
    
    int res = -1;
    if(l>1 && card[l-1]==turn){
        if(!rec(!turn, l-1, r)) res = 1;
        else res = max(res, 0);
    }
    if(r<13 && card[r+1]==turn){
        if(!rec(!turn, l, r+1)) res = 1;
        else res = max(res, 0);
    }
    if(res == -1){
        if(!rec(!turn, l, r)) res = 1;
        else res = 0;
    }
    
    dp[turn][l][r] = res;
    return res == 1;
}

int main() {
    int n;
    cin >> n;
    REP(i,n){
        fill(card,card+15,false);
        REP(j,2)REP(k,15)fill(dp[j][k],dp[j][k]+15,-1);
        REP(j,6){
            int f;
            cin >> f;
            card[f] = true;
        }
        fl = fr = sl = sr = -1;  // 手持ちの中の最大最小
        REP(i,13){
            if(i+1==7)continue;
            if(card[i+1]){
                if(fl == -1) fl = i+1;
                fr = max(fr, i+1);
            }
            else{
                if(sl == -1) sl = i+1;
                sr = max(sr, i+1);
            }
        }
        cout << (rec(true,7,7)?"yes":"no") << endl;
    }
    return 0;
}



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

int main(void)
{
   char a[11], b[11], c[11];

   scanf("%s%s%s",a,b,c);

   if((a[strlen(a)-1] == b[0])&&(b[strlen(b)-1] == c[0]))
      printf("YES\n");

   else
      printf("NO\n");

   return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

map<ll, ll> factors;
void solveFactors(ll a) {
    for(int i = 2; i <= sqrt(a); i++) {
        while(a % i == 0) {
            factors[i]++;
            a /= i;
        }
        if(a == 1) break;
    }
    if(a != 1) factors[a]++;
}

int main() {
    ll n, p;
    cin >> n >> p;
    ll ans = 1;
    solveFactors(p);

    for(auto x : factors) {
        if(x.second >= n) {
            ans *= pow(x.first, (x.second / n));
        }
    }
    cout << ans << endl;

    return 0;
}

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

ll gcd(ll a,ll b){
  ll r=1;
  if(a>b) swap(a,b);
  while(r!=0){
    r=b%a;
    b=a;
    a=r;
  }
  return b;
}

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for(ll i=2;i*i<=n;i++){
    if(n%i)continue;
    res.emplace_back(i,0);
    while(n%i==0){
      n /= i;
      res.back().second++;
    }
  }
  if(n != 1) res.emplace_back(n,1);
  return res;
}

int main() {
  ll a,b;
  cin >> a >> b;
  b = gcd(a,b);
  auto f = factorize(b);
  int ans = f.size() + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

ll  dp[330][330];

int main(){
    int n, k; cin >> n >> k;
    int m = n-k;

    vector<int> h(n); rep(i,n) cin >> h[i];
    h.insert(h.begin(),0);
    rep(i,n+1) rep(j,n+1) dp[i][j] = 1002003004005006007ll;
    dp[0][0] = 0;

    for(int i=1; i<=n; i++){
        rep(j,m){
            ll now = 1002003004005006007ll;

            rep(k,i){
                chmin(now, dp[k][j] + max(0, h[i] - h[k]));
            }

            dp[i][j+1] = now;
        }
    }

    ll ans = 1002003004005006007ll;

    rep(i,n+1) ans = min(ans, dp[i][m]);

    dunk(ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))

#if 0
//No.4
int main()
{
	INT A, B, N;

	return 0;
}
#endif

#if 1
//No.3
int sub(INT A[10], INT idx, INT start, INT N, INT M, INT Q, INT abcd[50][4])
{
	INT ret = 0;

	//ラスト
	if (idx == N) {
		for (int i = 0; i < Q; ++i) {
			INT bi = abcd[i][1] - 1;
			INT ai = abcd[i][0] - 1;
			if (A[bi] - A[ai] == abcd[i][2]) {
				ret += abcd[i][3];
			}
		}

		//for (int i = 0; i < N; ++i) {
		//	cout << A[i] << ", ";
		//}
		//cout << ": " << ret << endl;
	}
	else {
		for (int i = start; i <= M; ++i) {
			A[idx] = i;
			INT score = sub(A, idx + 1, i, N, M, Q, abcd);
			if (score > ret) { 
				ret = score;
				//cout << "****updated!****" << endl;
			}
		}
	}

	return ret;
}

int main()
{
	INT N, M, Q;
	INT abcd[50][4];
	INT A[10];

	cin >> N >> M >> Q;
	for (int i = 0; i < Q; ++i) {
		cin >> abcd[i][0] >> abcd[i][1] >> abcd[i][2] >> abcd[i][3];
	}

	INT ret = sub(A, 0, 1, N, M, Q, abcd);
	cout << ret;

	return 0;
}
#endif


Measured memory_bytes: 3596
#include<stdio.h>
int get(int a,int b){
  int r;
  r=a%b;
  if(r==0){
    return b;
  }else{
    return get(b,r);
  }
}
int gcd(int a,int b,int c){
  return get(get(a,b),c);
}
int main(void){
  int K,a,b,c,sum=0;
  scanf("%d",&K);
  for(a=1;a<=K;a++){
    for(b=1;b<=K;b++){
      for(c=1;c<=K;c++){
        sum+=gcd(a,b,c);
      }
    }
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 1736
/* Generated by cf-tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (win, osx, linux)
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            ioyhhhhhhyoi    
#define next          sdNNNmNNNNNNNmds. 
#define y0          -hNNNNy_yNNNNNN_lNh-
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy--:smNNNms
#define tm          .+oooooosyysooooo+- 
#define read               :yhy/        
#define rank              :mNmo         
#define index              ... 
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, 1, 3) {
        ans += s[i - 1] == t[i - 1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
        "sort"
)

var t int

func main() {
        var n int
        fmt.Scan(&n)
        a := make([]int, n)
        for i := range a {
                fmt.Scan(&a[i])
        }
        sort.Ints(a)
        t = a[n-1]
        sort.Sort(sortInterface(a))
        fmt.Println(t, a[0])
}

func abs(n int) int {
        if n < 0 {
                return -n
        }
        return n
}

type sortInterface []int

func (s sortInterface) Len() int           { return len(s) }
func (s sortInterface) Less(i, j int) bool { return abs(t-2*s[i]) < abs(t-2*s[j]) }
func (s sortInterface) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

Measured memory_bytes: 5504
#include<stdio.h>
int main(void)
{
    int in[11]={0};
    while(scanf("%d,",&in[0])!=EOF)
    {
        int i,j,train1,train2;
        int all=0,train;
        double time,kyori;
        all=in[0];
        for(i=1;i<10;i++)
        {
            scanf("%d,",&in[i]);
            all+=in[i];
        }
        scanf("%d,%d",&train1,&train2);
        train=train1+train2;
        time=(double)all/(double)train;
        kyori=time*train1;
        for(i=0;i<10;i++)
        {
            kyori-=in[i];
            if(kyori<0)
            {
                i++;
                printf("%d\n",i);break;
            }
            else if(kyori==0)
            {
                i++;
                printf("%d\n",i);break;
            }
        }

    }
    return 0;
}

Measured memory_bytes: 596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::HashSet;

fn main() {
    input!{
        n: usize,
        a: [usize; n],
        b: [usize; n]
    }
    let mut ab: Vec<_> = a.iter().cloned().zip(b.iter().cloned()).collect();
    ab.sort_by_key(|x| x.1);
    let mut a2: Vec<_> = ab.iter().map(|x| x.0).enumerate().collect();
    let b2: Vec<_> = ab.iter().map(|x| x.1).collect();
    a2.sort_by_key(|x| x.1);
    if a2.iter().map(|x| x.1).zip(b2.iter().cloned()).any(|(x, y)| x > y) {
        println!("No");
        return;
    }
    let mut set = HashSet::new();
    set.insert(0);
    let mut i = a2[0].0;
    while set.insert(i) {
        i = a2[i].0;
    }
    if set.len() < n {
        println!("Yes");
        return;
    }
    for i in 0..n - 1 {
        if b2[i] >= a2[i + 1].1 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 16636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>

using namespace std;

#define int long long
#define ll long long
#define double long double
#define pii pair<int, int>
#define vec vector
#define u_map unordered_map
#define u_set unordered_set
#define str string
#define all(el) el.begin(), el.end()
#define allr(el) el.rbegin(), el.rend()
#define sz(el) (int)el.size()
#define f first
#define s second
#define pb push_back
#define in insert
#define mp make_pair
#define endl "\n"
#define forn(i, n) for (int i = 0; i < n; ++i)

inline int maxi(int &a, int b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(int &a, int b) { if (b < a) { a = b; return 1; } return 0; }

inline int maxi(double &a, double b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(double &a, double b) { if (b < a) { a = b; return 1; } return 0; }

const int maxN = 1e5 + 100;

vec<int> g[maxN];
int used[maxN];

void dfs(int v) {
    used[v] = 1;
    for (int to : g[v]) {
        if (!used[to]) {
            dfs(to);
        }
    }
}

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g[a].pb(b);
        g[b].pb(a);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            dfs(i);
            ans++;
        }
    }

    cout << ans;

    return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  
  
  int ans = 0;
  if(N>1 && M>1){
    ans = M * (M-1) / 2 + N * (N-1) / 2;
  }
  else if(N>1){
    ans = N * (N-1) / 2;
  }
  else if(M > 1){
    ans = M * (M-1) / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n, m, l; cin >> n >> m >> l;
	vl k(n); REP(i, n) cin >> k[i];
	vl s(m); REP(i, m) cin >> s[i];

	vl sum(m + 1); sum[0] = 0;
	REP(i, m) sum[i + 1] = sum[i] + s[i];

	sort(ALL(k));
	vvl dp(2, vl((n - 1) * 2 + 1, TEN(13)));
	dp[0][n - 1] = 0;
	ll ans = TEN(13);
	FOR(i, 1, n) {
		REP(j, (n - 1) * 2 + 1) dp[i % 2][j] = TEN(13);
		REP(j, (n - 1) * 2 + 1) {
			ll j_zero = j - (n - 1);
			ll times = abs(j_zero);
			if (times >= i || dp[(i - 1) % 2][j] == TEN(13)) continue;
			if (i == n - 1) {
				MINC(
					ans,
					dp[(i - 1) % 2][j]
					+ (sum[k[i]] - sum[k[i - 1 - times] - 1]) / l
					+ (sum[k[i]] - sum[k[i - 1] - 1]) / l
				);
			} else {
				MINC(
					dp[i % 2][(n - 1) + (j_zero <= 0 ? 1 : -1)],
					dp[(i - 1) % 2][j] + (sum[k[i]] - sum[k[i - 1 - times] - 1]) / l
				); // ???
				MINC(
					dp[i % 2][j + (j_zero <= 0 ? -1 : 1)],
					dp[(i - 1) % 2][j] + (sum[k[i]] - sum[k[i - 1] - 1]) / l
				); // ??£?¶?
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
int a[10005],n,f,j=0;
int main() {  
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) 	
		while(a[i]%2==0) 
		{
			a[i]/=2;
			j++;
		}
	cout<<j;
   	return 0; 
}

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

vector<int> to[200005];
vector<int> ans;

void dfs(int node, int parent = -1){
    for(auto v : to[node]){
      if (v == parent){
            continue;
        }
        ans.at(v) += ans.at(node);
        dfs(v, node);
    }
}

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

    for (int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;

        a--;
        b--;

        to[a].push_back(b);
        to[b].push_back(a);
    }

  
    ans.resize(n);
    for (int i = 0; i < q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        ans.at(p) += x;
    }

    dfs(0);

    for(int i = 0; i < n; i++){
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 26624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long x = Long.parseLong(br.readLine());

		int time = 0;
		int position = 0;
		while (position < x) {
			time++;
			position = (time * (time + 1)) / 2;
		}
		System.out.println(time);
	}
}


Measured memory_bytes: 32396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cerr << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl

struct UnionFind{
    vector<int> par,r;

    //はじめに全てが根であるとしておく
    UnionFind(int N):par(N),r(N,1){iota(par.begin(),par.end(),0);}

    int root(int x){//根に当たるまで再帰で探す
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool same(int x,int y){//つながっているかどうか判定
        return par[x] == par[y];
    }

    int size(int x){ //根の大きさを判定する
        return r[root(x)];
    }

    void unite(int x, int y){//根が同じでなかったらつなげる
        x = root(x), y = root(y);
        if(x == y) return;
        if(r[x] < r[y]) swap(x,y); //値を小さいほうを根にする
        r[x] += r[y];
        par[y] = x;
        return;
    }
};

int main() {
    int N,M;cin >> N >> M;
    int X[M],Y[M],Z[M];
    UnionFind UF(N);
    REP(i,M){
        cin >> X[i] >> Y[i] >> Z[i];
      	--X[i];--Y[i];
        UF.unite(X[i],Y[i]);
    }
    vector<int> ans;
    REP(i,N){
        ans.pb(UF.root(i));
    }
    sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end());
    cout << ans.size() << endl;
}

Measured memory_bytes: 2812
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define ld long double
#define eps 1e-9
#define maxp 100000000000000000000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
void solve(){
	ld a,b;
	in2(a,b);
	ld ans=a*b;
	ll fans=ans;
	cout<<fans<<'\n';
}	
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	clock_t t1=clock();
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
	clock_t t2=clock();
	cerr<<"Time elapsed:- "<<(double)(t2-t1)/CLOCKS_PER_SEC<<'\n';
}	

Measured memory_bytes: 3812
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

long long x, y, z, k;
long long a[1005], b[1005], c[1005];
vector<long long> d, e;

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%lld%lld%lld%lld", &x, &y, &z, &k);
    for(long long i = 1; i <= x; i++) scanf("%lld", &a[i]);
    for(long long i = 1; i <= y; i++) scanf("%lld", &b[i]);
    for(long long i = 1; i <= z; i++) scanf("%lld", &c[i]);
    for(long long i = 1; i <= x; i++) for(long long j = 1; j <= y; j++) d.push_back(a[i] + b[j]);
    sort(d.begin(), d.end(), greater<long long>());
    for(long long i = 0; i < min((long long)d.size(), k); i++) for(long long j = 1; j <= z; j++) e.push_back(d[i] + c[j]);
    sort(e.begin(), e.end(), greater<long long>());
    for(long long i = 0; i < k; i++) printf("%lld\n", e[i]);
    return 0;
}


Measured memory_bytes: 43236
n = int(input())
pn = [0 for _ in  range(n)]
for i in range(n):
  p = int(input())
  pn[p-1] = i + 1

k = 1
tmpk = 1
for i in range(1, n):
  if pn[i-1] < pn[i]:
    tmpk += 1
  else:
    k = k if k > tmpk else tmpk
    tmpk = 1

k = k if k > tmpk else tmpk
print(n - k)


Measured memory_bytes: 11048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> P;

const int N=1005;
const ll INF=1e18;
int n,m;
vector<P> adj;
vector<int> nxt[N],rev[N];
ll c[N][N],d[N],dp[N];
vector<int> topo;
bool neg[N];

void neg_cycle(){
	for(int i=1;i<=n;++i)
		d[i]=INF;
	d[1]=0;
	for(int i=0;i<n-1;++i){
		for(auto it:adj){
			int u=it.first;
			int v=it.second;
			if(d[u]==INF) continue;
			if(d[u]+c[u][v]<d[v]) 
				d[v]=d[u]+c[u][v];
		}
	}
	for(int i=0;i<n-1;++i){
		for(auto it:adj){
			int u=it.first;
			int v=it.second;
			if(d[u]==INF) continue;
			if(d[u]+c[u][v]<d[v]){
				d[v]=d[u]+c[u][v];
				neg[v]=true;
			}
			neg[v]|=neg[u];
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;++i){
		int u,v;
		ll w;
		cin>>u>>v>>w;
		c[u][v]=-w;
		adj.emplace_back(u,v);
	}
	neg_cycle();
	if(neg[n]) cout<<"inf\n";
	else cout<<-d[n]<<'\n';
}




Measured memory_bytes: 8880
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++) {
		if (ch == '\\')S1.push(i);
		else if (ch == '/'&&S1.size() > 0) {
			int j = S1.top();
			S1.pop();
			sum += i - j;
			int a = i - j;
			while (S2.size() > 0 && S2.top().first > j) {
				a += S2.top().second;
				S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}
	vector<int> ans;
	int t = 0;
	while (S2.size() > 0) {
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		t += ans[i];
		cout << ans[i];
	}
	cout << endl;
	return 0;
}




Measured memory_bytes: 3240
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define mod 1000000007
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi 3.1415926535897932384626433832795
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define lo lower_bound
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
void cp()
{
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); 
    #ifndef ONLINE_JUDGE  
    freopen("input.txt", "r", stdin);  
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    //cp();
    //w(x)
        def(a,n);
        ll k=1;
            ll ans=0;
            re(i,n)
            {
                if(k==a[i])
                k++;
                else
                {
                    ans++;
                }
            }
            if(ans==n)
            cout<<"-1\n";
            else
            cout<<ans<<endl;
    return 0;
}

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

int N, ans[2];
bool found, blocked[100005];
vector<int> route;
vector<int> adjlist[100005];

void dfs(int x, int p) {
	route.push_back(x);
	if (x == N - 1) {
		found = 1;
		return;
	}
	for (int i = 0; i < adjlist[x].size(); i++) {
		if (adjlist[x][i] != p) {
			dfs(adjlist[x][i], x);
			if (found) return;
		}
	}
	route.pop_back();
}

void dfs2(int x, int p, int c) {
	ans[c]++;
	for (int i = 0; i < adjlist[x].size(); i++) {
		if (adjlist[x][i] != p && !blocked[adjlist[x][i]]) {
			dfs2(adjlist[x][i], x, c);
		}
	}
}

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	dfs(0, -1);
	for (int i = 0; i < route.size(); i++) blocked[route[i]] = 1;
	int a = route.size() - route.size() / 2;
	for (int i = 0; i < route.size(); i++) {
		if (i < a) dfs2(route[i], -1, 0);
		else dfs2(route[i], -1, 1);
	}
	if (ans[0] > ans[1]) printf("Fennec\n");
	else printf("Snuke\n");
	//printf("%d %d\n", ans[0], ans[1]);
}


Measured memory_bytes: 11000
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<assert.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 1e6+10, M = 1e6+10;

int main() {
	ll a, b, c, d;
	cin>>a>>b>>c>>d;
	ll ans = -INF;
	ans = max(ans, a * c);
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
vector<ll>v;
ll dp[100005][4];
int main(){
    ll n;
    cin>>n;
    vector<ll>a,b,c;
    for(ll i=0;i<n;i++){
        ll s1,s2,s3;
        cin>>s1>>s2>>s3;
        a.push_back(s1);
        b.push_back(s2);
        c.push_back(s3);
    }
    dp[0][1]=a[0];
    dp[0][2]=b[0];
    dp[0][3]=c[0];
    for(ll i=1;i<n;i++){
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+c[i];

    }
    cout<<max(dp[n-1][1],max(dp[n-1][2],dp[n-1][3]))<<endl;
    return 0;

    }


Measured memory_bytes: 5984
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N = Scanner.int()
    S = Scanner.int_cols_list(N)
    S.sort(reverse = True)
    ans = sum(S)
    i = 0
    if ans % 10 == 0:
        n = [x for x in S if x % 10 != 0]
        if n == []:
            ans = 0
        else:
            ans -= min(n)
    print(ans)
    return

if __name__ == "__main__":
    main()


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

const int inf = 1001001001;

struct segtree {
  vector<pair<int, int>> dat;
  static const int N = 1 << 18;

  segtree() : dat(2 * N, make_pair(inf, -1)){}

  void init(vector<int> &v) {
    for (int i = 0; i < v.size(); ++i) {
      dat[i + N - 1] = make_pair(v[i], i);
    }
    for (int i = N - 2; i >= 0; --i) {
      dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]);
    }
  }

  pair<int, int> get_min(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return pair<int, int>(inf, -1);
    if (a <= l && r <= b) return dat[k];

    return min(
      get_min(a, b, 2 * k + 1, l, (l + r) / 2),
      get_min(a, b, 2 * k + 2, (l + r) / 2, r)
    );
  }

  pair<int, int> get_min(int a, int b) {
    return get_min(a, b, 0, 0, N);
  }
};

struct data {
  pair<int, int> p;
  int k;
  data(pair<int, int> p, int k) : p(p), k(k) {}
};

bool operator<(const data& a, const data& b) {
  return a.p > b.p;
}

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

  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }

  vector<int> u, v;
  for (int i = 0; i < n; ++i) {
    if (i & 1) {
      u.push_back(p[i]);
      v.push_back(inf);
    } else {
      u.push_back(inf);
      v.push_back(p[i]);
    }
  }

  segtree even, odd;
  odd.init(u);
  even.init(v);

  int idx = 0;
  vector<vector<int>> G(n);
  vector<pair<int, int>> val(n);

  function<void(int, int)> solve = [&](int l, int r) {
    int x, y;
    x = (l & 1 ? odd : even).get_min(l, r).second;
    y = (l & 1 ? even : odd).get_min(x, r).second;

    int v = idx;
    idx++;

    val[v] = make_pair(p[x], p[y]);
    if (l != x) {
      G[v].push_back(idx);
      solve(l, x);
    }
    if (x + 1 != y) {
      G[v].push_back(idx);
      solve(x + 1, y);
    }
    if (y + 1 != r) {
      G[v].push_back(idx);
      solve(y + 1, r);
    }
  };

  solve(0, n);

  vector<int> ans;

  priority_queue<data> que;
  que.push(data(val[0], 0));
  while (!que.empty()) {
    pair<int, int> p = que.top().p;
    int k = que.top().k;
    que.pop();

    ans.push_back(p.first);
    ans.push_back(p.second);

    for (auto e : G[k]) {
      que.push(data(val[e], e));
    }
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << (i + 1 == n ? "\n" : " ");
  }
}


Measured memory_bytes: 50412
def myAnswer(N:int,A:list) ->int:
   if((2 in A) == False):return -1
   graph = {}
   for n,a in enumerate(A):
      graph[n] = a - 1
   i = 0
   counter = 0
   while True:
      if(graph[i] == "-"):
         return -1
      if(graph[i] == 1):
         counter += 1
         break
      tmp = graph[i]
      graph[i] = "-"
      i = tmp
      counter += 1
   return counter




def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = [int(input()) for _ in range(N)]
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 22568