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

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int main() {
	char abcd[5];
	scanf("%s", abcd);
	int a, b, c, d;
	a = abcd[0] - '0';
	b = abcd[1] - '0';
	c = abcd[2] - '0';
	d = abcd[3] - '0';

	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int ans;
				if (i) ans = a+b;
				else ans = a-b;

				if (j) ans = ans+c;
				else ans = ans-c;

				if (k) ans = ans+d;
				else ans = ans-d;

				if (ans == 7) {
					char s[3];
					s[0] = i?'+':'-';
					s[1] = j?'+':'-';
					s[2] = k?'+':'-';
					printf("%d%c%d%c%d%c%d=7\n",a,s[0],b,s[1],c,s[2],d);
					return 0;
				}
			}
		}
	}
}


Measured memory_bytes: 256
from bisect import *
n = 1
max_v = 0
v_map = [0.0] * 500
while max_v < 200:
    h = 5 * n - 5
    t = (h / 4.9)**0.5
    v_map[n - 1] = 9.8 * t
    #print(n,h,t,v_map[n-1])
    max_v = max(v_map)
    n += 1

while True:
    try:
        x = float(input())
        print(bisect(v_map, x) + 1)
    except EOFError:
        break



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

int v[105];

int dp[100005];

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&v[i]);
    }
    dp[0] = 0;
    for(int i = 1; i <= k; i++)
    {
        set<int>s;
        for(int j = 0 ; j < n; j++)
        {
            if(i - v[j] >= 0)
            s.insert(dp[i - v[j]]);
        }
        int mex = 0;
        while(s.count(mex))
            mex++;
        dp[i] = mex;
    }
    printf("%s\n", dp[k] ? "First" : "Second");
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

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

unsigned GetDigit(ull num) {
    return log10(num);
}

void nextPernutationPrint(const vector<int>& v) {
    for_each(v.begin(), v.end(), [](int x) { cout << x << " "; });
    cout << endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> T(N), P(N), Q(N);

    rep(i, N) {
        T[i] = i + 1;
    }
    rep(i, N) {
        cin >> P[i];
    }
    rep(i, N) {
        cin >> Q[i];
    }

    int cnt = 1, pValue = 0, qValue = 0;
    do {
        bool pFlag = true, qFlag = true;
        for (int i = 0; i < N; i++) {
            if (T[i] != P[i]) {
                pFlag = false;
            }
            if (T[i] != Q[i]) {
                qFlag = false;
            }
        }
        if (pFlag) {
            pValue = cnt;
        }

        if (qFlag) {
            qValue = cnt;
        }

        cnt++;
    } while (next_permutation(T.begin(), T.end()));

    cout << abs(pValue - qValue) << endl;
}

Measured memory_bytes: 3728
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	cin >> s;
	map<char, int> m;
	for(int i = 0; i < 4; i++){
		if(m.find(s[i]) == m.end()) m[s[i]] = 1;
		else m[s[i]]++;
	}
	if(m.size() == 2 && (*m.begin()).second == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main(){
int a,b,k;
cin>>a>>b>>k;
if(a+b <= k){
    cout<<"0"<<" "<<"0";
}
else {if(a <= k){
    cout<<"0"<<" "<<b-(k-a);
}
        else{
            cout<<a-k<<" "<<b;
        }
    return 0;}
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define loopj(n) for(int j=0;j<n;j++)
#define loopi(a,b,k) for(int i=a;i<b;i=i+k)
#define  deb(x) cout<<#x<<"  "<<x<<endl
#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main()
{
	double d,s,t;
	cin>>d>>t>>s;
	double t2=d/s;
	if(t2<=t)
	cout<<"Yes";
	else
	cout<<"No";
	
}

Measured memory_bytes: 3720
import sys

#+++++
		
def main():
	dd=[0]*100200
	a = int(input())
	cc=[100,101,102,103,104,105]
	dd[0]=1
	for i in range(a+1):
		if i == a:
			return dd[i]
		if dd[i] == 1:
			for c in cc:
				dd[i+c] = 1
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3828
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	a := readInt()
	b := readInt()
	t := readInt()

	var ans int
	for i := a; i <= t; i += a {
		ans += b
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
n, k = map(int, input().split())
a = list(map(int, input().split()))

t1 = 0
for i in range(n):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            t1 += 1

t2 = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            t2 += 1

ans = t1 * k + t2 * k * (k - 1) // 2

print(ans % (10 ** 9 + 7))


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<int> G[100000];
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u].emplace_back(v);
	}
	int s,t; scanf("%d%d",&s,&t); s--; t--;

	int d[100000][3];
	rep(u,n) rep(k,3) d[u][k]=INF;
	d[s][0]=0;
	priority_queue<tuple<int,int,int>> Q;
	Q.emplace(0,s,0);
	while(!Q.empty()){
		auto a=Q.top(); Q.pop();
		int d0=-get<0>(a),u=get<1>(a),k=get<2>(a);
		if(d0>d[u][k]) continue;

		if(u==t && k==0){ printf("%d\n",d0/3); return 0; }

		for(int v:G[u]){
			if(d[v][(k+1)%3]>d0+1){
				d[v][(k+1)%3]=d0+1;
				Q.emplace(-d[v][(k+1)%3],v,(k+1)%3);
			}
		}
	}

	puts("-1");

	return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >>N;
  	string s;
  	int num;
  	list<int> v;
  for(int i=0;i<N;i++){
  	
  	cin >>s;
  	  if(s[0]=='i'){
		cin >>num;
        v.push_front(num);
      }
  	  else if(s[6]=='F'){
         v.pop_front();
      }  
      else if(s[6]=='L'){  
         v.pop_back();
      }  
      else{
      	cin >>num;
      	for(list<int>::iterator it =v.begin();it!=v.end();it++){
      		if(*it==num){
            	v.erase(it); break;
            }
      	}
      }
  }//i forno   
  int m=0;
   for(list<int>::iterator it =v.begin();it!=v.end();it++){
     if(m!=0){cout <<' ';}
   		cout <<(*it);  	m++;
   }
	cout <<endl;
	
  	
  
}


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

int main(){
  	int A1,A2,A3;
  	cin >> A1 >> A2 >> A3;
  
  	int sum = A1 + A2 + A3;
  
  	if(sum >= 22){
      cout << "bust" << endl;
    }else{
      cout << "win" << endl;
    }
  
  
	return 0;  
}


Measured memory_bytes: 256
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))
count = 0
for i in range(1, N):
    if a_list[i-1] == a_list[i]:
        a_list[i] = -1
        count += 1
ans = count
print(ans)


Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>

int roundup(int x){
		double x1 = (double)x / 10.0;
		int x3 = (int)(ceil(x1) * 10);
		return x3;
}

int min1(int x[5]){
		int min = 10;
		int min_index = -1;
		int i;
		for(i = 0; i < 5; i++) {
				if(x[i]%10 < min && x[i]%10 != 0){
						min_index = i;
						min = x[i] % 10;
				}
		}
		return min_index;
}


int main(void){
		int x[5];
		int i;

		for(int j=0; j<5; j++) {
				scanf("%d", &x[j]);
		}

		int min_index = min1(x);
		
		int y[5] = {0};
		int sum = 0;


		if(min_index != -1) {
			for(i=0; i<5; i++) {
					if(i != min_index) {
						   sum	+= roundup(x[i]);
					}
			}
		sum+= x[min_index];
		}

		else{
			for(i=0; i<5; i++) {
					sum += x[i];
			}
		}

		printf("%d", sum);
		return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>

using namespace std;

long long int gcd(long long int a, long long int b){
  long long int temp;
  if(a<b){ 
    temp = a;
    a = b;
    b = temp; 
  }
  if(b<1) return -1;
  if(a%b==0) return b;
  return gcd(b,a%b);
}

int main(int argc, char* argv[]){
  int n;
  cin >> n;
  long long int x[100002]={};
  cin >> x[0];
  for(int i=1;i<=n;i++){
    cin >> x[i];
  }
  sort(x,x+n+1);

  long long int ans = x[1]- x[0];
  for(int i=2;i<=n;i++){
    if(x[i]-x[i-1]==0)continue;
    ans = gcd(ans, abs(x[i]-x[i-1]));
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  char S[110];
  char T[110];

  rep(i,N){
    cin >> S[i];
  }
  rep(i,N){
    cin >> T[i];
  }

  rep(i,N){
    cout << S[i] << T[i];
  }
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		String S = input.next();
		char cur = S.charAt(0);
		int ans = 0;
		for (int i = 1; i < S.length(); i++) {
			if (S.charAt(i)!=cur) {
				ans++;
				cur=S.charAt(i);
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 25556
#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> Ai;
  
  rep(i,N){
    int tmpAi = 0;
    cin >> tmpAi;
    Ai.push_back(tmpAi);
  }
  
  double ans = 0;
  rep(i,N){
  	ans += 1.0 / Ai.at(i);
  }
  
  cout << fixed;
  cout << setprecision(10) << 1.0 / ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<complex>
#define EPS 1e-10
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQP(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
using namespace std;

typedef complex<double> P;

double dot(P a,P b){return real(conj(a)*b);}
double cross(P a,P b){return imag(conj(a)*b);}
double area(P a,P b,P c){return abs(cross(b-a,c-a)/2);}
bool para(P a1,P a2,P b1,P b2){return abs(cross(a1-a2,b1-b2))<EPS;}
bool is_cp(P a1,P a2,P b1,P b2){
  if(cross(a2-a1,b1-a1) * cross(a2-a1,b2-a1) < EPS)
    if(cross(b2-b1,a1-b1) * cross(b2-b1,a2-b1) < EPS)return true;
  return false;
}
P seg_cp(P a1,P a2,P b1,P b2){
  b2-=b1;
  double d = abs(cross(b2,a1-b1));
  return a1 + (a2-a1)*d/( d + abs(cross(b2,a2-b1)) );
}

int main(){
  P p11,p12,p21,p22,p31,p32;
  for(;;){
    cin >> p11.real() >> p11.imag() >> p12.real() >> p12.imag();
    if(!abs(p11) && !abs(p12))break;
    cin >> p21.real() >> p21.imag() >> p22.real() >> p22.imag();
    cin >> p31.real() >> p31.imag() >> p32.real() >> p32.imag();

    if(para(p11,p12,p21,p22) || para(p21,p22,p31,p32) || para(p31,p32,p11,p12))
      cout << "kyo\n";
    else if(!is_cp(p11,p12,p21,p22) || !is_cp(p21,p22,p31,p32) || !is_cp(p31,p32,p11,p12))
      cout << "kyo\n";
    else{
      P cp1 = seg_cp(p11,p12,p21,p22);
      P cp2 = seg_cp(p21,p22,p31,p32);
      P cp3 = seg_cp(p31,p32,p11,p12);
      if(EQP(cp1,cp2))cout << "kyo\n";
      else{
	double s = area(cp1,cp2,cp3);
	if(s+EPS>1900000)cout << "dai-kichi\n";
	else if(s+EPS>1e6)cout << "chu-kichi\n";
	else if(s+EPS>1e5)cout << "kichi\n";
	else cout << "syo-kichi\n";
      }
    }
    
  }
}

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

using namespace std;

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

template<typename T>
using pq_gt = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using pq_lt = priority_queue<T, vector<T>, less<T>>;

#define se second
#define fi first
#define pb push_back

int main() {
    ios::sync_with_stdio(false);
    string str;
    cin>>str;
    cout<<str.substr(0, str.size()-8)<<endl;
}

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

namespace ABC049C
{
    class Program
    {
        static string skipKeywords(string s, string[] keywords)
        {
            while (true)
            {
                bool matched = false;

                foreach (var keyword in keywords)
                {
                    matched = s.StartsWith(keyword);
                    if (matched)
                    {
                        s = s.Substring(keyword.Length);
                        break;
                    }
                }

                if (!matched)
                {
                    break;
                }
            }

            return s;
        }

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var keywords = new string[] { "dream", "dreamer", "erase", "eraser" };

            // 末尾一致を探したいので、逆転する
            s = string.Concat(s.Reverse());
            keywords = keywords.Select(x => string.Concat(x.Reverse())).ToArray();

            var t = skipKeywords(s, keywords);

            Console.WriteLine((t.Length == 0) ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 34060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, m; cin >> n >> m;
    vector<VI> g(n);
    VI in(n);
    FOR(i, 0, n - 1 + m) {
        int a, b; cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        ++in[b];
    }

    VI ans(n);
    queue<int> bfs;
    FOR(i, 0, n)if (in[i] == 0) {
        bfs.push(i);
        ans[i] = 0;
    }
    while (!bfs.empty()) {
        int now = bfs.front();
        bfs.pop();
        each(to, g[now]) {
            --in[to];
            if (in[to] == 0) {
                bfs.push(to);
                ans[to] = now + 1;
            }
        }
    }

    FOR(i, 0, n)cout << ans[i] << "\n";
}

Measured memory_bytes: 7040
flag = False
cli = [0] * 1001
sen = set()
kon = set()

while True:
    try:
        c, d = map(int, input().split(","))
    except:
        if flag:
            break
        flag = True
        continue

    if flag:
        kon.add(c)
    else:
        sen.add(c)
    cli[c] += 1

for i in range(1,1001):
    if i in sen and i in kon:
        print(i,cli[i])

Measured memory_bytes: 7512
#include <bits/stdc++.h>
using namespace std;
long long n,m,x,p[13],c[13],a[13][13],ktra=0,ans=1e9;
void check()
{
    long long sum[100000],res=0;

    for (int i=1;i<=m;i++) sum[i]=0;

    for (int i=1;i<=n;i++)
    if (p[i])
    {
        for (int j=1;j<=m;j++) sum[j]+=a[i][j];
    }

    for (int i=1;i<=m;i++) 
    if (sum[i]<x) return;

    //out<<p[1]<<" "<<p[2]<<" "<<p[3]<<endl;
    
    for (int i=1;i<=n;i++)
    if (p[i]) res+=c[i];
    ans=min(res,ans);
}
void solve(int k)
{
    if (k==n+1) 
    { check(); return;}

    for (int j=0;j<=1;j++)
    {
        p[k]=j;
        //cout<<k<<endl;
        solve(k+1);

    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m>>x;

    for (int i=1;i<=n;i++)
    {
        cin>>c[i];
        for (int j=1;j<=m;j++) cin>>a[i][j];
    }
    solve(1);
    
    if (ans==1e9) cout<<-1;
    else
    cout<<ans;
}    




Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int[] A = new int[M];
		for(int i = 0; i < M; i ++) {
			A[i] = stdIn.nextInt();
		}
		for(int i = 0; i < A.length; i ++) {
			N -= A[i];
		}
		if(0 <= N) {
			System.out.println(N);
		}else {
			System.out.println("-1");
		}
	}
}

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

int main()
{
    int n, a, b, res1=0, res2=0, res3=0, res=0, res4=0, res5=0, sum = 0;
    cin >> n >> a >> b;
    for(int i=1; i<=n; i++)
    {
        res1 = i % 10;
        res2 = (i/10)%10;
        res3 = (i/100)%10;
        res4 = (i/1000)%10;
        res5 = (i/10000)%10;
        res = res1+res2+res3+res4+res5;
        if(((res >= a) && (res <= b))) sum += i;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;




signed main(){
  int x, y;
  cin >> x >> y;
  if(x*y < 0){
    cout << llabs(-x-y)+1 << endl;
  }else{
    if(x <= y){cout << y-x << endl;return 0;}
    if(x == 0 or y == 0){cout << llabs(x-y)+1 << endl;return 0;}
    cout << llabs(x-y)+2 << endl;
  }
	return 0;
}








Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W,K;
  cin >> H >> W >> K;
  combination c(H*W);
  mint ans = 0;
  for(int i=1; i<W; i++){
    ans += c(H*W-2,K-2) * H*H * i * (W-i);
  }
  for(int i=1; i<H; i++){
    ans += c(H*W-2,K-2) * W*W * i * (H-i);
  }
  cout << ans.x << "\n";
  return 0;
}

Measured memory_bytes: 6352
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;
int main() {
   int N;
   cin>>N;
   vector<int>T(N);
   for(int i=0;i<N;i++){cin>>T[i];}
   int M;
   cin>>M;
   vector<int>P(M);
   vector<int>X(M);
   for(int i=0;i<M;i++){
      cin>>P[i]>>X[i];
   }

   for(int i=0;i<M;i++){
    int ans=0;
     for(int j=0;j<N;j++){
      if(j+1==P[i]){ans+=X[i];continue;}
       ans+=T[j];
      }
      cout<<ans<<endl;
   }
return 0;}

Measured memory_bytes: 256
#include<stdio.h>
main()
{
  int   A,B;
  do
  {
   scanf("%d%d",&A,&B);
  }while(A<1||A>9||B<1||B>9);
  if((A+B)<10)
  printf("%d",A+B);
  if((A+B)>9)
  printf("error");
}

Measured memory_bytes: 128
<?php
list($n) = ints();
list($k) = ints();
$x = ints();
$ans = 0;
for ($i = 0; $i < $n; ++$i) $ans += 2 * min($k - $x[$i], $x[$i]);
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4604
#include<cstdio>
#include<algorithm>
int main(){
	int n;
	scanf("%d",&n);
	long long int a[n]={};
	long long int b[n]={};
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		b[i]=a[i];
	}
	std::sort(b,b+n);
	long long int c[n/2+1];
	long long int d[n/2+1];
	for(int i=1;i<n;i+=2){
		c[i/2]=a[i];
		d[i/2]=b[i];
	}
	std::sort(c,c+n/2);
	int ans=0;
	int l=0;
	int m=0;
	c[n/2]=10000000000;
	d[n/2]=10000000000;
	while(l!=n/2||m!=n/2){
		if(c[l]==d[m]){
			l++;
			m++;
		}else if(c[l]<d[m]){
			l++;
			ans++;
		}else{
			m++;
		}
	}
	printf("%d\n",ans);
	return 0;
}
	

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


def Base_10_to_n(X, n):
    if (int(X / n)):
        return Base_10_to_n(int(X / n), n) + str(X % n)
    return str(X % n)


a = Base_10_to_n(n, k)
print(len(a))


Measured memory_bytes: 2940
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i > M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}

template<class T>
T getbit(T i) {
	return 1LL << i;
}
template<class T>
T POW(T n, T m) {
	T res = 1;
	rep(i, 0, m) {
		res *= n;
	}
	return res;
}

ll power(ll x, ll y,ll mod) {
	if (y == 0)return 1;
	if (y == 1)return x % mod;
	if (y % 2 == 0)return POW(power(x, y / 2, mod), 2LL) % mod;
	return ((POW(power(x, y / 2, mod), 2LL) % mod)*(x%mod))%mod;
}
ll div(ll a,ll  b, ll mod) {
	return (a* power(b, mod - 2,mod))%mod;
}

//#define TRANSFORM(v,w,func) decltype(v) w ; transform((v).begin(),(v).end(),back_inserter(w),func);

using namespace std;

ll MOD_NUM = POW(10LL, 9LL) + 7;

int main() {
	vll A(3);
	rep(i,0,3) cin >> A[i];
	sort(all(A));
	ll res = A[2] * 10 + A[1] + A[0];


	cout << res;
		


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxV = 90010;
const int maxN = 1e5+10;
const int MOD = 1e9+7;
const ll INF = 1000000000000000010LL;


int a[maxN];
int b[maxN];
int c[maxN];
char s[maxN]; 

int main() {
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int x = (a[i]+a[j]);
			int pos = lower_bound(a+1+j,a+1+n,x)-(a+j+1);
			ans += (ll)max(pos,0); 
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll sqrt(ll x) {
	ll left = 0, right = x;
	rep(i, 100) {
		ll mid = (left + right) >> 1;
		if (mid*mid <= x)	left = mid;
		else	right = mid;
	}
	return left;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	printf("Case #%d: ", x)
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vector<string> s(n);
	rep(i, n)	cin >> s[i];
	// 一度(A,B)が見つかれば(A+1,B+1)も絶対揃う。
	// よって、A=0で解を求めていけばよさそう?
	// (a,b)=(1,2)と(3,5)で成立するとき、(0,1)と(0,2)でも成立するはず。
	int ret = 0;
	rep(b, n) {
		string tmp = s[0];	s.erase(s.begin());
		s.push_back(tmp);
		// check
		bool ok = true;
		rep(i, n)	rep(j, n) {
			if (s[i][j] != s[j][i]) {
				ok = false;
			}
		}
		if (ok) {
			ret++;
		}
	}
	cout << ret*n << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct
{
	int a;
	int b;
} abc086a_t;

int product (const abc086a_t * given_data)
{
	return (* given_data).a * (* given_data).b;
}

bool isProdEven (const abc086a_t * given_data)
{
	return ( ( product(given_data) % 2 ) == 0 );
}

void ABC086A (const abc086a_t * given_data)
{
	if ( isProdEven(given_data) ) printf( "Even\n" );
	else                          printf( "Odd\n"  );
}

int main (void)
{
	// variables for `main`
	abc086a_t given_data;
	int       retval_scanf;

	// STEP.01
	// read out the given data
	retval_scanf = scanf("%d %d", &given_data.a, &given_data.b);

	// STEP.02
	// calculate & output the answer
	ABC086A(& given_data);

	// STEP.END
	return EXIT_SUCCESS;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int N = 1e5+5;
const dd eps = 1e-8;
const ll mod = 1e9+7;
int n,a[N],ans,sum,ans2;
int main(){
  // freopen("input.txt","r",stdin);
  cin>>n;
  for(int i = 1;i <= n;i++) cin>>a[i],sum+=a[i];
  sum /= n;
  for(int i = 1;i <= n;i++) ans+=(a[i]-sum)*(a[i]-sum);
  sum++;
  for(int i = 1;i <= n;i++) ans2+=(a[i]-sum)*(a[i]-sum);  
  cout<<min(ans,ans2)<<endl;
  return 0;
}


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


int main(){
  string s;
  cin >>s;
  rep(i,s.size())s[i]='x';
  cout <<s<<endl;

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
max_L = 1
min_R = 100000
for _ in range(M):
	L, R = map(int, input().split())
	if max_L < L:
		max_L = L
	if R < min_R:
		min_R = R
if min_R - max_L + 1 < 0:
	print(0)
else:
	print(min_R - max_L + 1)

Measured memory_bytes: 40556
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int sx,sy,tx,ty;
//8c:1a:bf:89:66:b6
struct threeElements{
int _1st,_2nd,_3rd;
};
vector<vector<int>>adj(10);
ll v[200009];
ll n;
ll solve(int x)
{
    ll ans=0,sum=x;
    for(int i=2;i<=n;i++)
    {
        ll u=v[i]+sum;
        if(sum<0)
        {
            if(u<=0)
            {
                ans+=abs(u)+1;
                u=1;
            }
        }else
        {
            if(u>=0)
            {
                ans+=u+1;
                u=-1;
            }
        }
        sum=u;
    }
    return ans;
}
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
   //18:52
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        v[i]=x;
    }
    if(v[1]==0)
    {
        cout<<min(solve(1),solve(-1))+1;
    }else
    {
        ll ans2,ans1=solve(v[1]);
        if(v[1]>0)
        {
            ans2=solve(-1)+v[1]+1;
        }else
        {
            ans2=solve(1)+abs(v[1])+1;
        }
        cout<<min(ans1,ans2);
    }

}


Measured memory_bytes: 4428
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, i; cin >> n >> i;
  cout << n - i + 1 << '\n';
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::cmp;

fn solve(s: Vec<i32>) -> u32 {
    let mut minimum = 100;
    for i in s {
        for j in 1..31 {
            if i % 2i32.pow(j) != 0 {
                minimum = cmp::min(minimum, j - 1);
                break;
            }
        }
    }
    minimum
}

fn main() {
    input!{
        N: i32,
        A: [i32; N],
    }
    println!("{}", solve(A))
}


Measured memory_bytes: 4352
n = int(input())
s = input()

ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n):
    for j in range(i+1, n):
        k = j + (j - i)
        if k < n:
            if s[i] != s[j]:
                if s[i] != s[k]:
                    if s[j] != s[k]:
                        ans -= 1

print(ans)


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

using namespace std;
int main()
{
    string word, s;
    cin>>word;
    int n;
    int a, b;
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>s;
        if(s=="print")
        {
            cin>>a>>b;
            for(int e=a; e<=b; ++e)
                cout<<word[e];
            cout<<"\n";
        }
        else if(s=="replace")
        {
            cin>>a>>b>>s;
            int counter=0;
            for(int e=a; e<=b; ++e)
            {
                word[e]=s[counter];
                counter++;
            }
        }
        else
        {
            cin>>a>>b;
            while(a<b)
            {
                int temp=word[a];
                word[a]=word[b];
                word[b]=temp;
                a++;
                b--;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3224
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int long long
#define setout(n,x) setw(n) << setfill(x)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;
vector<int> a;
vector<int> dp;
int n;

int Binary_Search(int x){
    int low = -1;
    int high = n;
    while(high - low > 1){
        int mid = (high + low) / 2;
        if(a[mid] <= x) low = mid;
        else high = mid;
    }
    return low;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(all(a));
    dp.resize(n+1);
    reps(i,n){
        dp[i] = dp[i-1] + a[i-1];
    }
    int cnt = 0;
    rep(i,n){
        int x = dp[i+1];
        int tmp = i;
        while(true){
            int p = Binary_Search(x * 2);
            if(p >= n-1){
                ++cnt;
                break;
            }
            if(p <= tmp){
                break;
            }
            tmp = p;
            x = dp[tmp+1];
        }
    }
    cout << cnt << '\n';
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>

int main(void)
{
  int n;
  
  const int minVal = 0;
  const int maxVal = 9;
  
  while (std::cin >> n) {
    int count = 0;
    for (int a = minVal; a <= maxVal; a++) {
      for (int b = minVal; b <= maxVal; b++) {
        for (int c = minVal; c <= maxVal; c++) {
          for (int d = minVal; d <= maxVal; d++) {
            if (a + b + c + d == n) {
              count++;
            }
          }
        }
      }
    }
    std::cout << count << std::endl;
  }
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int min(int a,int b){return a>b?b:a;}
long int n;
long int fun(long int a[],long int n)
{
    long int dp[100000],i,p,q;
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    return dp[n-1];
}
int main()
{
    long int i,a[100000];
    scanf("%ld",&n);
    for(i=0;i<n;i++)
    {scanf("%ld",&a[i]);}
    printf("%ld",fun(a,n));
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 1e5+10;

int N;
ll A[MAX];

ll solve() {
    ll ret = 1;
    REP (i, N) if (A[i] == 0) return 0;
    REP (i, N) {
        ll a = A[i];
        if (ret > 1000000000 && a > 1000000000) return -1;
        ret *= a;
        if (ret < 0) return -1;
    }
    if (ret > 1000000000000000000ll) return -1;
    return ret;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

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

#define ll unsigned long long
#define inf 1e18
#define mod 1e9+7
#define w(x) int x; cin >> x; while(x--)
#define sp(x, y) fixed << setprecision(y) << x;
#define pb push_back


const int maxn = 1e6;
const ll mx = 1e18;

vector<ll> arr;
int n;
void solve() {
    cin >> n;
    arr.resize(n);
    for (auto &it: arr) {
        cin >> it;
        if (it == 0) {
            cout << 0 << '\n';
            return;
        }
    }
    ll mul = 1;
    for (int i = 0; i < n; i++) {
        if (mul > mx / arr[i]) {
            cout << -1 << '\n';
            return;
        }
        mul *= arr[i];
    }
    cout << mul << '\n';
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
    return 0;
}



Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
#define sz int(1e5+1)
int main()
{
    string s1, s2;

    cin>>s1>>s2;
    s1='0'+s1;
    s2='0'+s2;
    int n=s1.size(), m=s2.size();
    
    vector < vector<int> > dp(n+1,vector<int>(m+1,0));

    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(s1[i]==s2[j]){
                dp[i][j]=1+dp[i-1][j-1];
            }else{
                dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
            }
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    int y=n-1,x=m-1;
    string s = "";
    while(dp[y][x]){
        int mxx = max(dp[y-1][x-1], max(dp[y-1][x], dp[y][x-1]));
        if(mxx!=dp[y][x]){
            s=s1[y]+s;
            y--, x--;
        }else{
            if(dp[y-1][x]==dp[y][x])
                y--;
            else if (dp[y-1][x-1]==dp[y][x]){
                y--, x--;
            }else{
                x--;
            }
        }
    }

    cout<<s<<endl;
    return 0;
}

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

using namespace std;

int main(){
  long long n, a[200009];
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(long long i=0;i<n;i++){
    if(a[i]>i){
      cout << -1 <<  endl;
      return 0;
    }
  }
  long long prev=a[n-1];
  long long top=a[n-1];
  long long ans=0;
  long long top_idx = n-1;
  for(long long i=n-2;i>=0;i--){
    if(a[i]<top-(top_idx-i)){
      cout << -1 << endl;
      return 0;
    }
    else if(a[i]>prev-1){
      ans += top;
      top = a[i];
      top_idx = i;
    }
    prev = a[i];
  }
  ans += top;
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;

namespace output{
    void __(short x){cout<<x;}
    void __(unsigned x){cout<<x;}
    void __(int x){cout<<x;}
    void __(long long x){cout<<x;}
    void __(unsigned long long x){cout<<x;}
    void __(double x){cout<<x;}
    void __(long double x){cout<<x;}
    void __(char x){cout<<x;}
    void __(const char*x){cout<<x;}
    void __(const string&x){cout<<x;}
    void __(bool x){cout<<(x?"true":"false");}
    template<class S,class T>
    void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
    template<class T>
    void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class S,class T>
    void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    void pr(){cout<<"\n";}
    template<class S,class... T>
    void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}

using namespace output;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,char> pic;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;

#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)

ll n, a, b;

int main(){
    scanf("%lld%lld%lld",&n,&a,&b);
    if(a%2==b%2) printf("%lld\n",(b-a)/2);
    else printf("%lld\n",min(n-b,a-1)+(b-a+1)/2);
    return 0;
}


Measured memory_bytes: 256