akhauriyash/Code-Regression huggingface dataset:
/*
 * Author : Sadi
 * Fri 17/07/2020
 * 18:03:35.58
 */
#include <bits/stdc++.h>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    string str;
    cin >> str;
    const int ALPHABETS = 26;
    vector<char> v(ALPHABETS);
    for(int i = 0; i < ALPHABETS; ++i) {
        v[i] = 'A' + i;
    }
    for(int i = 0; i < (int) str.size(); ++i) {
        int idx = (str[i] - 'A' + n) % ALPHABETS;
        cout << v[idx];

    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3616
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a,b in ab:
    if b <= m:
        ans += a*b
        m -= b
    else:
        ans += a*m
        m = 0
    if m == 0: break
print(ans)

Measured memory_bytes: 27348
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll n;
ll a[105];
ll dp[105];
ll ans;
int main()
{
	ll i,j,k;
	cin>>n;
	ans=1000;
	ll x,y;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	} 
	for(i=0;i<n-1;i++)
	{
		
		if(a[i]<a[i+1])
		ans=ans+(ans/a[i])*(a[i+1]-a[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/

ll k;
ll rems[10*MAX];
int main(){FAST;
cin>>k;
ll rem = 0,ans = 0;
ll stop = 7%k;
ll oof = 0;
while(1){
  ++ans;
  rem=rem*10%k;
  rem+=7;
  rem%=k;
  if(rems[rem]){
    break;
  }
  ++rems[rem];
  if(!rem){
    cout<<ans;
    return 0;
  }
}
cout<<-1;
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 11444
#include<iostream>

#include<string>

#include<algorithm>

#include<vector>

#include<iomanip>

#define _USE_MATH_DEFINES

#include<cmath>

using namespace std;

int main(){

  int m,min,max;

  while(cin >> m >> min >> max,m){

    int p[m];

    for(int i=0;i<m;i++) cin >> p[i];

    int gap=0,n=0;

    for(int i=min-1;i<max;i++){

      if(gap<=p[i]-p[i+1]){

        n=i+1;

        gap=p[i]-p[i+1];

      }

    }

  cout << n << endl;

  }

}

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

vector<vector<int>> graph;
vector<bool> isVisited;

void dfs(int a, int b, int v, int p = -1){
    if(isVisited[v]) return;
    isVisited[v] = true;
    
    for(int u: graph[v]){
        if((v == a and u == b) or(v == b and u == a) or u == p) continue;
        dfs(a,b,u,v);
    }
}

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

    int n,m;
    cin >> n >> m;
    graph.resize(n);
    isVisited.resize(n,false);
    
    vector<pair<int, int>> arr(m);
    rep(i,m) cin >> arr[i].first >> arr[i].second;
    
    rep(i,m){
        int a = arr[i].first;
        int b = arr[i].second;
        
        a--;
        b--;
        
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int cnt = 0;
    rep(i,m){
        rep(j,n) isVisited[j] = false;
        
        dfs(arr[i].first-1, arr[i].second-1, 0);
        
        bool flag = true;
        rep(k,n) if(isVisited[k] == false) flag = false;
        if(!flag) cnt++;
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
// clang-format on

void solve(std::vector<long long> A) { cout << (A[0] + A[1] + A[2] >= 22 ? "bust" : "win") << endl; }

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


Measured memory_bytes: 256
n,l = map(int,input().split())
ls = [input() for i in range(n)]
sm = sum([len(s) for s in ls])
ls.sort()
num = [0]*(sm+1)
for i in range(n):
  if i == 0:
    for j in range(len(ls[i])):
      num[j+1] = 1
  else:
    x = ls[i]
    p = ls[i-1]
    cnt = 0
    while cnt < min(len(x),len(p)):
      if x[cnt] == p[cnt]:
        cnt += 1
      else:
        break
    num[cnt+1] -= 1
    for j in range(cnt+2,len(x)+1):
      num[j] += 1
ans = 0
def d2(x):
  if x == 0:
    return 0
  cnt = 0
  while x%2 == 0:
    cnt += 1
    x //= 2
  return 2**cnt
for i in range(sm+1):
  ans ^= d2(l+1-i)*(num[i]%2)
if ans:
  print("Alice")
else:
  print("Bob")

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

public class Main {	

	private static void solve(){
		//Implement solution here.
		String S = next();
		int N = S.length();
		String front = S.substring(0, (N - 1)/2);
		String end = S.substring((N + 3) / 2 - 1, N);
		
		if(isParindome(S) && isParindome(front) && isParindome(end)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
	
	private static boolean isParindome(String s) {
		int N = s.length();
		for(int i = 0; i < N / 2; i++) {
			if(s.charAt(i) != s.charAt(N - 1 - i))return false;
		}
		return true;
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

typedef int64_t ll;
int main()
{
	int a, b;
	cin >> a >> b;
	int ans = -1;
	int pref = (a + b) / 2;
	if (abs(a - pref) == abs(b - pref)) {
		cout << pref;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+2];
        int[] c = new int[n+2];
        long tc = 0;
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            c[i] = Math.abs(a[i] - a[i-1]);
            tc += c[i];
        }
        tc += Math.abs(a[n]);
        
        for (int i = 1; i <= n; i++) {
            int c2 = Math.abs(a[i] - a[i+1]);
            int c3 = Math.abs(a[i-1] - a[i+1]);
            System.out.println(tc - c[i] - c2 + c3);
        }
    }
}


Measured memory_bytes: 68488
s = list(map(int,input()))
n = len(s)
for i in range(2**(n-1)):
    bag = []
    for j in range(n-1):
        if ((i>>j)&1):
            bag.append(s[j])
            bag.append('+')
        else:
            bag.append(s[j])
            bag.append('-')
    bag.append(s[n-1])
    bag = list(map(str,bag))
    #ss = ''.join(bag)
    #print(bag)
    total = int(bag[0])
    for m,sss in enumerate(bag):
        if(sss == '+'):
            total += int(bag[m+1])
        elif(sss == '-'):
            total -= int(bag[m+1])
    if(total==7):
        print(''.join(bag)+'=7')
        exit()

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

int main(){
  int H1,M1,H2,M2,K,wake;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  wake = (H2*60+M2) - (H1*60+M1);
  cout << wake-K << endl;
}


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

int main(){
    int n, m;
    string s;
    cin >> n >> m >> s;
    reverse(s.begin(),s.end());

    int c = 0, r = m;
    vector<int> ans;
    while(1){
        if(r == 0){
            cout << -1 << endl;
            return 0;
        }
        else if(c+r > n || s[c+r] == '1'){
            r -= 1;
        }
        else{
            c += r;
            ans.push_back(r);
            r = m;
            if(c == n) break;
        }
    }

    reverse(ans.begin(),ans.end());
    for(int i=0; i<ans.size(); i++){
        cout << ans[i];
        if(i == ans.size()-1) break;
        cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
typedef pair<ll,ll> pll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
void A() {
    int n;
    cin>>n;
    int res=max(0,(n+999)/1000*1000-n);
    cout<<res<<endl;
}
void B() {
    int n;
    cin>>n;
    unordered_map<string,int>cnt;
    cnt["AC"]=0;
    cnt["WA"]=0;
    cnt["RE"]=0;
    cnt["TLE"]=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        cnt[s]++;
    }
    cout<<"AC x "<<cnt["AC"]<<endl;
    cout<<"WA x "<<cnt["WA"]<<endl;
    cout<<"TLE x "<<cnt["TLE"]<<endl;
    cout<<"RE x "<<cnt["RE"]<<endl;
}
void C() {
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<char>> grid(h,vector<char>(w,'.'));
    int bl=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>grid[i][j];
            if(grid[i][j]=='#') bl++;
        }
    }
    int res=0;
    for(int i=0;i<(1<<h);i++){

        for(int j=0;j<(1<<w);j++){
            int cnt=bl;
            for(int x=0;x<h;x++){
                for(int y=0;y<w;y++){
                    if(grid[x][y]=='.')  continue;
                    if(i&(1<<x) || j&(1<<y)) cnt--;
                }
            }
            if(cnt==k) res++;
        }
    }
    cout<<res<<endl;
}

void D() {
    int n;
    cin>>n;
    vector<ll> a(n,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll res=0;
    int len=(n+1)/2; //使用a的前len个
    vector<ll> sum(len+1,0);
    for(int i=1;i<=len;i++){
        sum[i]=sum[i-1]+a[i-1];
        //cout<<sum[i]<<endl;
    }
    res=sum[len]-a[len-1]+sum[len]-a[0];
    if(n%2==0) res+=a[len-1];
    cout<<res<<endl;
}
void E(){

}
void F()
{

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


Measured memory_bytes: 5564
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> w(n);
    REP(i, n) cin >> w[i];

    ll ans = LINF;
    RANGE(i, 1, n-1) {
        ll s1 = accumulate(w.begin(), w.begin() + i, 0);
        ll s2 = accumulate(w.begin() + i, w.end(), 0);
        chmin(ans, abs(s1 - s2));
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//_____
#define pb emplace_back
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
#define let const auto
//_______

struct Edge {
   int  s, t, w;
   Edge(let a, let b, let c): s(a), t(b), w(c) {}
   bool operator < (const Edge &r) const { return (w < r.w); }
   bool operator > (const Edge &r) const { return (w > r.w); }
};

class UnionFind {
private:
   int par[100010];
   const size_t N;
public:
   UnionFind(int n): N(++n) {
      reps(i, 0, N) par[i] = i;
   }
   int root(int x) { return ((par[x]==x)? x : par[x] = root(par[x]) ); }
   bool same(let x, let y){ return root(x) == root(y); }
   void unite(int x, int y) {
      x = root(x), y = root(y);
      par[y] = x;
   }
};

int N;
vector <Edge> G;

int kruskal()
{
   int sum = 0;
   sort(G.begin(), G.end());
   UnionFind uf(N);

   for(let e : G) {
      if ( !uf.same(e.s, e.t) ) {
         sum += e.w;
         uf.unite(e.s, e.t);
      }
   }
   return (sum);
}

signed main()
{
   FAST();
   int m;
   cin >> N >> m;

   while (m--) {
      int a, b, w;
      cin >> a >> b >> w;
      G.pb( Edge(a,b,w) );
   }

   outl( kruskal() );

}



Measured memory_bytes: 4532
n, k = map(int, input().split())

import sys

sys.setrecursionlimit(2000)

l = [[] for i in range(n)]
e = []
for i in range(n-1):
    a, b = map(int, input().split())
    l[a-1].append(b-1)
    l[b-1].append(a-1)
    e.append([a-1, b-1])

def first_search(first, depth):
    record = 0
    for i in l[first]:
        temp = search(first, i, depth-1)
        if record < temp:
            record = temp
    return record + 1

def search(before, now, depth):
    if depth <= 0:
        return 1
    else:
        ans = 1
        for i in l[now]:
            if before != i:
                ans += search(now, i, depth-1)
        return ans

ret = 0
if k%2 == 0:
    for i in range(n):
        temp = search(-1, i, k//2)
        if temp > ret:
            ret = temp
else:           
    for i in e:
        temp = search(i[0], i[1], k//2) + search(i[1], i[0], k//2)
        if temp > ret:
            ret = temp
        

print(n-ret)

Measured memory_bytes: 4692
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    *S, = iss()
    E = ['+', '-']
    tmp = [0] * 7
    for e in E:
        tmp[0] = S[0]
        tmp[1] = e
        for e in E:
            tmp[2] = S[1]
            tmp[3] = e
            for e in E:
                tmp[4] = S[2]
                tmp[5] = e
                tmp[6] = S[3]
                ans = ''.join(map(str, tmp))
                if eval(ans) == 7:
                    print(ans + '=7')
                    exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	s := getNextString(scanner)

	n := len(s)
	ans := 0
	for i := 1; i < n; i++ {
		if s[i] != s[i-1] {
			ans++
		}
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vec A(n);
    rep(i,n) cin>>A[i];
    int ans=0;
    rep(i,n) if(ans+1==A[i]) ans++;
    if(ans==0) cout<<-1;
    else cout<<n-ans;
}

Measured memory_bytes: 4760
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 100000;
int n;
bool f;
char S[4][4];
int main()
{
    memset(S,0,sizeof(S));
    f = false;
    for (int i = 0; i < 2; i++)
        scanf("%s",S[i]);
    if( (S[0][0] != S[1][2]) || (S[0][2] != S[1][0]) || (S[0][1] != S[1][1]))
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}

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

int main() {
	string S;
	cin >> S;
	int N = S.length();
	int MIN = 1000;
	for (int i = 0; i < N - 2; i++) {
		int X = stoi(S.substr(i, 3));
		MIN = min(abs(X - 753), MIN);
	}
	cout << MIN << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define all(v) v.begin(), v.end()
  #define mod 1000000007
  //direction arrays
  int dx[8]={0,0,-1,+1,+1,-1,+1,-1};
  int dy[8]={+1,-1,0,0,+1,-1,-1,+1};
  int modexp(int x, int y)
  {
      int res = 1;
      x = (x % mod + mod) % mod;
      while(y)
      {
          if(y & 1)
              res = (res*x) % mod;
          y >>= 1;
          x = (x*x) % mod;
      }
      return res%mod; 
  }
   int gcd(int a,int b)
   { 
     if (a == 0) 
         return b; 
     return gcd(b % a, a); 
 } 
  
  int32_t main()
  { 
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
    
    IOS
    int k;
    string s;
    cin>>k;
    cin>>s;
    if(s.length()<=k)
      cout<<s;
    else
    {
      cout<<s.substr(0,k)+"...";
    }
  return 0;
}

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

int Sum(int n) {
    int ans = 0;
    while (n > 0) {
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    
    int ans = 0;
    REP(i, N + 1) {
        if (A <= Sum(i) && Sum(i) <= B) ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	long long n,ans=0,str=0,sum=0;
	cin>>n;
	vector<long long>a(n),cnt(n);

	rep(i,n){
	    cin>>a[i];
	    sum+=a[i];
	    cnt[i]=sum;
	}
	cnt.push_back(0);
	sort(cnt.begin(),cnt.end());
	for(int i=0;i<n;i++){
	    if(cnt[i]==cnt[i+1]){
	        str++;
	        ans+=str;
	    }
	    else str=0;
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


int main(){
    string s1, s2; cin >> s1 >> s2;
    string s3 = s2, s4 = s1;
    reverse(all(s3));
    reverse(all(s4));
    if(s3 == s1 && s2 == s4) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

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


int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  while (true) {
    C-=B;
    if (C<=0) {
      cout << "Yes\n";
      return 0;}
    A-=D;
    if (A<=0) {
      cout << "No\n";
      return 0;}
  }
}

Measured memory_bytes: 3632
N,Y=map(int,input().split())
Y = Y/1000
a,b,c =0,0,0
flg = True
if 10*N < Y:
  a,b,c = -1,-1,-1
#elif float(Y/10 + Y%5) > float(N):
#  a,b,c = -1,-1,-1
else:
    for n in range(int(N/5)+1):
        c = int(Y%5 + 5*n)
        for i in range(N-c+1):
            if (5*i + 5*N) == (Y + 4*c):
                flg = False
                a , b = i , (N-c-i)
                break
        if not flg:
            break
if flg:
    a,b,c = -1,-1,-1
print(a,b,c)

Measured memory_bytes: 3316
#include <stdio.h>
#include <string.h>
#define N 100000

struct Process
{
  char name[100];
  int time;
};

struct Process Q[N];
int head, tail, n;

void enqueue(struct Process);
struct Process dequeue(void);

main()
{
  int i, q, sumtime = 0, count = 0;
  struct Process u;
  scanf("%d %d", &n, &q);

  for(i = 0; i < n; i++)
    {
      scanf("%s", Q[i].name);
      scanf("%d", &Q[i].time);
    }

  head = 0;
  tail = n;
  while(count < n)
    {
      if(Q[head].time <= q)
	{
	  sumtime = sumtime + Q[head].time;
	  u = dequeue();
	  printf("%s %d\n", u.name, sumtime);
	  count++;
	}
      else
	{
	  sumtime = sumtime + q;
	  Q[head].time = Q[head].time - q;
	  u = dequeue();
	  enqueue(u);
	}
    }
  return 0;
}

void enqueue(struct Process x)
{
  Q[tail] = x;
  if(tail + 1 == N)
    {
      tail = 0;
    }
  else
    {
      tail = tail + 1;
    } 
}

struct Process dequeue(void)
{
  struct Process x;
  x = Q[head];
  if(head + 1 == N)
    {
      head = 0;
    }
  else
    {
      head = head + 1;
    }
  return x;
}

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

using namespace std;

using ll = long long;

ll dp[2][4][105];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string n;
    int K;
    cin >> n >> K;
    int m = n.size();

    dp[false][0][0] = 1;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j <= K; ++j) {
            // less?: true
            // next: 0
            dp[true][j][i + 1] += dp[true][j][i];
            for (int k = 1; k < 10; ++k) {
                if (j == K) break;
                dp[true][j + 1][i + 1] += dp[true][j][i]; 
            }

            // less?: false
            // next: 0
            dp[n[i] != '0'][j][i + 1] += dp[false][j][i];
            for (int k = 1; k <= n[i] - '0'; ++k) {
                if (j == K) break;
                dp[n[i] - '0' != k][j + 1][i + 1] += dp[false][j][i]; 
            }
        }
    }
    cout << dp[false][K][m] + dp[true][K][m] << "\n";
    return 0;
}

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

using namespace std;

typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;
    int n = s.size();
    bool palin = true;
    for(int i = 0 ; 2 * i < n ; ++i){
        if(s[i] != s[n-1-i]){
            palin = false;
        }
    }
    for(int i = 0 ; 4 * i < n ; ++i){
        if(s[i] != s[n/2 - 1 - i]){
            palin = false;
        }
    }

    if(palin){
        cout << "Yes" << endl; 
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = 0
if N < 105:
  pass
else:
  for i in range(105, N+1, 2):
    cnt = 0
    for j in range(1, N+1):
      if i % j == 0:
        cnt += 1
    if cnt == 8:
      ans += 1
      
print(ans)  



Measured memory_bytes: 2940
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	A := sc.NextInt()
	B := sc.NextInt()
	C := sc.NextInt()
	if min(A, B) < C && C < max(A, B) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func lcm(x, y int) int {
	x, y = max(x, y), min(x, y)
	if y == 0 {
		return x
	}
	return lcm(y, x%y)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<algorithm>
using namespace std;

int n,m,odd;
int a[101000];

int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a[i];
		if(a[i]&1)
		{
			odd++;
		}
	}
	if(odd>2)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	if(m==1)
	{
		if(n==1)
			cout<<1<<endl<<1<<endl<<1<<endl;
		else
			cout<<n<<endl<<2<<endl<<1<<" "<<n-1<<endl;
		return 0;
	}
	for(int i=1;i<=m;i++)
	{
		if(a[i]&1)
		{
			swap(a[1],a[i]);
			break;
		}
	}
	for(int i=2;i<=m;i++)
	{
		if(a[i]&1)
		{
			swap(a[m],a[i]);
			break;
		}
	}
	for(int i=1;i<=m;i++)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
	if(a[1]==1)
		cout<<m-1<<endl;
	else
		cout<<m<<endl<<a[1]-1<<" ";
	for(int i=2;i<m;i++)
	{
		cout<<a[i]<<" ";
	}
	cout<<a[m]+1<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	static final int n = 10;

	static final int m = 10;

	static final String INK_SIZE_SMALL = "1";

	static final String INK_SIZE_MEDIUM = "2";

	static final String INK_SIZE_LARGE = "3";

	public static void main(String[] args) throws IOException {

		int[][] paper = new int[n][m];

		BufferedReader bufferedReader = new BufferedReader(
				new InputStreamReader(System.in), 1);

		String line;
		while ((line = bufferedReader.readLine()) != null) {
			String inkSize = line.split(",")[2];
			int x = Integer.parseInt(line.split(",")[0]);
			int y = Integer.parseInt(line.split(",")[1]);

			if (INK_SIZE_SMALL.equals(inkSize)) {
				paper = smallInk(x, y, paper);
			} else if (INK_SIZE_MEDIUM.equals(inkSize)) {
				paper = mediumInk(x, y, paper);
			} else if (INK_SIZE_LARGE.equals(inkSize)) {
				paper = largeInk(x, y, paper);
			}
		}

		int colorless = 0;
		int depth = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (paper[i][j] == 0) {
					colorless++;
				}
				if (depth < paper[i][j]) {
					depth = paper[i][j];
				}
			}
		}
		System.out.println(colorless);
		System.out.println(depth);
	}

	private static int[][] smallInk(int x, int y, int[][] array) {
		if (x - 1 >= 0) {
			array[y][x - 1]++;
		}

		if (y - 1 >= 0) {
			array[y - 1][x]++;
		}
		array[y][x]++;
		if (y + 1 < n) {
			array[y + 1][x]++;
		}

		if (x + 1 < m) {
			array[y][x + 1]++;
		}
		return array;
	}

	private static int[][] mediumInk(int x, int y, int[][] array) {
		array = smallInk(x, y, array);
		if (y - 1 >= 0) {
			if (x - 1 >= 0)
				array[y - 1][x - 1]++;
			if (x + 1 < m)
				array[y - 1][x + 1]++;
		}
		if (y + 1 < n) {
			if (x - 1 >= 0)
				array[y + 1][x - 1]++;
			if (x + 1 < m)
				array[y + 1][x + 1]++;
		}

		return array;
	}

	private static int[][] largeInk(int x, int y, int[][] array) {
		array = mediumInk(x, y, array);
		if (x - 2 >= 0) {
			array[y][x - 2]++;
		}

		if (y - 2 >= 0) {
			array[y - 2][x]++;
		}
		if (y + 2 < n) {
			array[y + 2][x]++;
		}

		if (x + 2 < m) {
			array[y][x + 2]++;
		}

		return array;
	}

}

Measured memory_bytes: 17044
#include <bits/stdc++.h>
using namespace std;
long long a[100];
long long C[55][55];
void init()//排列数 
{
	 C[0][0]=1;
	 for(int i=1;i<=50;i++)
	 {
	 	C[i][0]=1;
	 	for(int j=1;j<=i;j++)
	 	   C[i][j]=C[i-1][j-1]+C[i-1][j];
	 }
}
int main()
{
	init();
	int n,A,B;
	cin>>n>>A>>B;
	for(int i=1;i<=n;i++)
	   cin>>a[i];
	sort(a+1,a+n+1);
	long long sum=0,ans=0;
	for(int i=n-A+1;i<=n;i++)
	   sum+=a[i];
    long long cot=0,tot=0;
    for(int i=n-A+1;i<=n;i++) if(a[i]==a[n-A+1]) cot++;
    for(int i=1;i<=n;i++) if(a[i]==a[n-A+1]) tot++;
    if(a[n]==a[n-A+1])//特判 
      for(int i=A;i<=B;i++)
         ans+=C[tot][i];
	else ans=C[tot][cot];
	printf("%lf\n%lld",(double)sum/A,ans);
	return 0;
} 

Measured memory_bytes: 256
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
LL dp[N + 5];
vector<LL> vec[N + 5];
LL up[N + 5];
LL MOD;

void dfs(int idx,int pre) {
	dp[idx] = 1;
	for(int i = 0;i < vec[idx].size();i++) {
		int nx = vec[idx][i];
		if(nx == pre) continue;
		dfs(nx,idx);
		dp[idx] = dp[idx] * ((dp[nx] + 1) % MOD) % MOD;
	}
}

const int BLOCK = 350;
LL block[BLOCK + 5];

void build(int a) {
	for(int i = 0;i <= BLOCK;i++) block[i] = 1;
	for(int i = 0;i < vec[a].size();i++) {
		int nx = vec[a][i];
		block[i / BLOCK] = block[i / BLOCK] * ((dp[nx] + 1) % MOD)% MOD;
	}
}

LL query(int a,int idx) {
	LL res = 1;
	for(int i = 0;i <= BLOCK;i++) {
		if(i == idx / BLOCK) {
			for(int j = i * BLOCK;j < min((int)vec[a].size(), (i + 1) * BLOCK);j++) {
				if(j == idx) continue;
				res = res * ((dp[vec[a][j]] + 1) % MOD) % MOD;
			}
		}
		else res = res * block[i] % MOD;
	}
	return res;
}

void dfs2(int idx,int pre) {
	if(idx != pre) swap(up[idx], dp[pre]);
	build(idx);
	for(int i = 0;i < vec[idx].size();i++) {
		int nx = vec[idx][i];
		if(nx == pre) continue;
		up[nx] = query(idx,i);
	}
	for(int i = 0;i < vec[idx].size();i++) {
		int nx = vec[idx][i];
		if(nx == pre) continue;
		dfs2(nx,idx);
	}
	if(idx != pre) swap(up[idx], dp[pre]);
}

void hora(int tc) {
	int n;
	cin>>n>>MOD;
	for(int i = 1;i < n;i++) {
		int x,y;
		cin>>x>>y;
		vec[x].PB(y);
		vec[y].PB(x);
	}
	dfs(1,1);
	up[1] = 0;
	dfs2(1,1);
	for(int i = 1;i <= n;i++) {
		cout<<(dp[i] * ((up[i] + 1) % MOD))% MOD<<endl;
	}
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



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

const int N = 1000010;
typedef long long ll;

ll A, B;
ll p[N], cnt, vis[N];

int main() {
	scanf("%lld%lld", &A, &B);
	ll ans = 1;
	for(int i = 2; i <= 1000000; ++i) {
		if(!vis[i]) {
			p[++cnt] = i;
		}
		for(int j = 1; j <= cnt && i * p[j] <= 1000000; ++j) {
			vis[i * p[j]] = 1;
			if(i % p[j] == 0) break;
		}
	}
	for(int i = 1; i <= cnt; ++i) {
		if(A % p[i] == 0 && B % p[i] == 0) {
			++ans;
			while(A % p[i] == 0) A /= p[i];
			while(B % p[i] == 0) B /= p[i];
		}
	}
	for(int i = 1; i <= cnt; ++i) {
		while(A % p[i] == 0) A /= p[i];
		while(B % p[i] == 0) B /= p[i];
	}
	if(A != 1 && B != 1 && A == B) ++ans;
	printf("%lld\n", ans);
}

Measured memory_bytes: 10496
flag = False

def traverable(st,sx,sy,gt,gx,gy):
    if ((gx+gy)-(sx+sy)) % 2 != (gt-st) %2:
        return False
    elif (gx+gy)-(sx+sy) > gt-st:
        return False
    else:
        return True

N = int(input())
t = [0];x = [0];y = [0]
for i in range(N):
    tt,xx,yy = [int(i) for i in input().split()]
    t.append(tt);x.append(xx);y.append(yy)

for i in range(N):
    if not(traverable(t[i],x[i],y[i],t[i+1],x[i+1],y[i+1])):
        flag = True

if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 11816
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z)                                                        \
  cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z  \
       << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair< int, int >
#define ld long double
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  int K;
  cin >> S >> K;
  int N = S.size();
  if (N == 1) {
    print(K / 2);
    return 0;
  }
  // S+=S[N-1];
  int ans = 0;

  vec< int > b;
  char cur = S[0];
  int cnt = 1;
  REPS(i, N - 1) {
    if (cur != S[i]) {
      b.pb(cnt);
      cnt = 1;
      cur = S[i];
    } else {
      cnt++;
    }
  }
  b.pb(cnt);
  // PRINTALL(b);
  int sizeb = (int)b.size();
  REP(i, sizeb) { ans += b[i] / 2; }
  //  b.pb(cnt);
  // PRINTALL(b);

  if (K == 1 || S[0] != S[N - 1]) {
    print(ans * K);
  } else {
    if (sizeb >= 2) {
      int tmp = b[0] / 2 + b[sizeb - 1] / 2;
      int val = (ans - tmp) * K + (b[0] + b[sizeb - 1]) / 2 * (K - 1) + tmp;
      // DEBUG(val);
      print(val);
    } else {
      print((N * K) / 2);
    }
  }
}

Measured memory_bytes: 256
import sys
f = sys.stdin

while True:
    n = int(f.readline())
    if n == 0:
        break
    ipqr = [map(int, f.readline().split()) for _ in range(n)]
    pl, ql, rl, cl = map(int, f.readline().split())
                        
    allow = [i for i, p, q, r in ipqr if p <= pl and q <= ql and r <= rl and p * 4 + q * 9 + r * 4 <= cl]
    

    print('\n'.join(map(str, allow)) if len(allow) else 'NA')

Measured memory_bytes: 7236
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = sorted([list(map(int, input().split())) for i in range(m)], key =lambda x:x[1])
bc.reverse()

flg = 0
cnt = 0

for i in range(n):
  if bc[flg][1] >a[i] and flg < m:
    a[i] = bc[flg][1]
    cnt +=1
    if cnt == bc[flg][0]:
      flg += 1
      cnt = 0
      if flg == m:
        break
  else:
      break

print(sum(a))

Measured memory_bytes: 33396
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main() {
    int n,k;
    cin >> n >> k;
    VI a(n);
    rep(i,n) cin >> a[i];
    VI b;
    rep(i,k) b.push_back(a[i]);

    for(int i = k ; i < n ;i++) {
        // cout << b[0] << endl;
        // cout << a[i] << endl;
        if(b[0] >= a[i]) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
        b.erase(b.begin());
        b.push_back(a[i]);
    }
}


Measured memory_bytes: 5100
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
count = 0
for i in range(N):
    A = list(map(int,input().split()))
    p = C
    for j in range(M):p+=A[j]*B[j]
    if p > 0:count += 1
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    string s;
    cin>>s;
    if (s == "Sunny") {
        cout<<"Cloudy";
    } else if (s ==  "Cloudy") {
        cout<<"Rainy";
    } else {
        cout<<"Sunny";
    }
    nextline;

    return 0;
}


Measured memory_bytes: 256
M,D = map(int,input().split(' '))
if M <= 3 or D <= 21:
  print(0)
  exit()
num = 0
for m in range(4,M+1):
  for d in range(21,D+1):
    X = str(d)
    if int(X[1]) <= 1:
      pass
    elif int(X[0]) * int(X[1]) == m:
      num += 1
print(num)
      

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;

int k;
string s;

signed main()
{
	cin>>s;
	k=s[s.size()-1]-'0';
	
	if (k==2||k==4||k==5||k==7||k==9)  cout<<"hon"<<endl;
	else if (k==0||k==1||k==6||k==8)  cout<<"pon"<<endl;
	else if (k==3)  cout<<"bon"<<endl;
	
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read() {
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
char c[100001];
int sum[100001];
main(){
    int n=read(),m=read();
    scanf("%s",c);
    for(int i=0;i<n;i++){
	if(c[i]=='C'&&c[i-1]=='A')
	    sum[i]=sum[i-2]+1;
	else
	    sum[i]=sum[i-1];
    }
    for(int i=1;i<=m;i++){
	int x=read()-1,y=read()-1;
	if(c[x]=='C'&&c[x-1]=='A')
	    cout<<sum[y]-sum[x-1]-1<<endl;
	else
	    cout<<sum[y]-sum[x-1]<<endl;
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)() //queueのclear
#define all(s) (s).begin(),(s).end()
#define vec vector
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
	if(x>y)return x;
	else return y;
}
ll min(ll x,ll y){
	if(x<y)return x;
	else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
  
  int n;cin >> n;
  vec<int> a(n);
  rep(i,n)cin >> a[i];
  vec<int> c(n),d(n);
  c[0]=a[0];
  d[n-1]=a[n-1];
  rep2(i,1,n)c[i]=gcd(a[i],c[i-1]);
  for(int i=n-2;i>=0;i--)d[i]=gcd(a[i],d[i+1]);
  ll ans=1;
  rep(i,n){
    if(i==0)ans=max(ans,d[1]);
    if(i==n-1)ans=max(ans,c[n-2]);
    ans=max(gcd(c[i-1],d[i+1]),ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4500
/*
    Flowers, wake up like the sea!
*/
#include <bits/stdc++.h>
#define PB push_back
#define FT first
#define SD second
#define MP make_pair
#define INF 0x7fffffff
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>  P;
typedef vector<int> VI;
typedef map<int,int> MII;
const int N = 18, MOD = 7+1e9;
int n, a[1<<N + 5];
P s[1<<N + 5];
int main()
{
#ifdef YUUKILP
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int S = 1 << n, _max = 0;
    for(int i = 0;i < S;i ++) cin >> a[i];
    a[S] = -1;
    s[0] = MP(0, S);
    for(int i = 1;i < S;i ++)
    {
        int x[4];
        s[i] = MP(i, S);
        for(int j = 0;j < n;j ++)
        {
            if(i & (1<<j))
            {
                int _i = i ^ (1<<j);
                x[0] = s[i].FT, x[1] = s[i].SD;
                x[2] = s[_i].FT, x[3] = s[_i].SD;
                sort(x, x + 4, [&](int _x, int _y){return a[_x] < a[_y];});
                s[i].FT = x[3], s[i].SD = (x[2] == x[3] ? x[1] : x[2]);
            }
        }
        cout << (_max = max(_max, a[s[i].FT] + a[s[i].SD])) << "\n";
    }
    return 0;
}

Measured memory_bytes: 9216