akhauriyash/Code-Regression huggingface dataset:
n=int(input())
li =list(map(int,input().split()))
cnt=0
for i in range(1,n-1):
    if li[i-1]<li[i]<li[i+1]:
        cnt+=1
    elif li[i-1]>li[i]>li[i+1]:
        cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define bitCount(num)  __builtin_popcount(num)
#define pb push_back
#define ll long long
#define bye return 0;
#define f(i,a,b) for( long long i=a;i<b;i++)
#define testCases long long t;cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define newLine <<"\n"
#define all(x) (x).begin(), (x).end()
#define vll vector<long long>

int main()
{
    fast
   string s;
   cin>>s;
   int ans=0;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R') cout<<3<<endl;
    else if(s[0]=='R' && s[1]=='R' || s[1]=='R' && s[2]=='R') cout<<2<<endl;
    else if(s[0]=='R'|| s[1]=='R'|| s[2]=='R') cout<<1<<endl;
    else cout<<0<<endl;

    bye
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    string s;
    cin >> s;
    int K;
    cin >> K;
    set<string> A;
    
    rep(i, s.size()) {
        rep(j, i + 1, min(i + 6, (int)s.size() + 1)) {
            A.insert(s.substr(i, j - i));
        }
    }
    int cnt = 1;
    for(auto str: A) {
//        cout << cnt << ":";
        if(cnt == K) {
            output(str);
            break;
        }
        cnt++;
    }
    
    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();
        long ans = 1L << 60;

        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                int f = Math.max(("" + i).length(), ("" + (n / i)).length());
                ans = Math.min(ans, f);
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val k = sc.nextLong()
    println(problemagc039(s, k))
}

fun problemagc039(s: String, k: Long): Long {
    if (s.length == 1) {
        return k / 2L
    }

    val sa = s.toCharArray()
    var lastFrag = 0
    for (i in 0 until sa.size) {
        if (i == sa.size - 1) {
            if (sa[0] == sa[i]) {
                var count = 1
                val first = s[0]
                for (j in 1 until sa.size) {
                    if (first == s[j]) count++ else break
                }
                if (count % 2 == 0) {
                    break
                } else if (s.filter { s[0] == it }.length == s.length) {
                    lastFrag = (k / 2).toInt()
                    if (k % 2 != 0L) {
                        lastFrag++
                    }
                    sa[i] = '_'
                } else {
                    lastFrag = 1
                    sa[i] = '_'
                }
            }
        } else {
            if (sa[i] == sa[i + 1] && (i == 0 || sa[i] != sa[i - 1])) {
                sa[i + 1] = '_'
            }
        }
    }
//    debugLog(sa.toList(), lastFrag)

    return sa.toList().count { it == '_' }.toLong() * k - lastFrag
}

Measured memory_bytes: 36036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  int a, b, c, k;
  cin >> a >> b >> c;
  cin >> k;

  string ans = "No";
  REP(i, k) {
    if (b <= a) {
      b *= 2;
      continue;
    }
    c *= 2;
  }
  if (a < b && b < c) ans = "Yes";
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3620
using System;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var array = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

            var K = int.Parse(Console.ReadLine());
            Console.WriteLine(array[K - 1]);
        }
    }
}


Measured memory_bytes: 11092
x = input()
ls_x = x.split()

# 文字配列を整数化
# for i in range(len(ls_x)):
#     ls_x[i] = int(ls_x[i])

# 別の方法　lint_xという箱を作って，intしたものをappendしていく
lint_x = []
for i in ls_x:
    lint_x.append(int(i))

lint_x = sorted(lint_x)

if (lint_x[0] + lint_x[1] == lint_x[2]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
int main(void) {
    int n, i, j, temp_d;
    scanf("%d", &n);
    char s[n + 1][11], temp[11] = {'\0'};
    int p[n + 1], ans[n];
    for ( i = 1; i <= n; i++ ) {
        ans[i] = i;
        scanf("%s%d", s[i], &p[i]);
        for ( j = 1; j <= (i - 1); j++ ) {
            if ( 0 < strcmp(s[j], s[i]) ) {
                memset(temp, '\0', 11);
                memcpy(temp, s[i], 11);
                memcpy(s[i], s[j], 11);
                memcpy(s[j], temp, 11);
                temp_d = p[i];
                p[i] = p[j];
                p[j] = temp_d;
                temp_d = ans[i];
                ans[i] = ans[j];
                ans[j] = temp_d;
            }
            else if ( 0 == strcmp(s[j], s[i]) ) {
                if ( p[j] < p[i] ) {
                    memset(temp, '\0', 11);
                    memcpy(temp, s[i], 11);
                    memcpy(s[i], s[j], 11);
                    memcpy(s[j], temp, 11);
                    temp_d = p[i];
                    p[i] = p[j];
                    p[j] = temp_d;
                    temp_d = ans[i];
                    ans[i] = ans[j];
                    ans[j] = temp_d;
                }
            }
        }
    }
    for ( i = 1; i <= n; i++ ) {
        printf("%d\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];
    vl b(n);rep(i,n)cin>>b[i];

    double d1=0,d2=0,d3=0,dI=0;
    rep(i,n){
        d1+=abs(a[i]-b[i]);
        d2+=pow(abs(a[i]-b[i]),2);
        d3+=pow(abs(a[i]-b[i]),3);
        chmax(dI,(double)abs(a[i]-b[i]));
    }
    d2=pow(d2,1.0/2);
    d3=pow(d3,1.0/3);
    printf("%.7f\n",d1);
    printf("%.7f\n",d2);
    printf("%.7f\n",d3);
    printf("%.7f\n",dI);
}

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



Measured memory_bytes: 3356
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		// スペース区切りの整数の入力
      	int comp = 10001;
      	int double_times = 1;
      	int need_to_change = 0;
      	int color;
      	for(int i=0;i<N;i++){
          color = sc.nextInt();
          if(color == comp ){
            double_times++;
          }else{
            need_to_change += double_times/2;
            double_times = 1;
          }
          comp = color;
          
        }
		need_to_change += double_times/2;
		// 出力
		System.out.println(need_to_change);
	}
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<ll> VI; typedef pair<ll,ll> pii;
const int mod = (int)1e9+7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}


const ll INF = 1LL<<60;
VI cal(ll p, const VI& v){
	
	VI ans = {INF, INF};
	int ps = lower_bound(all(v), p) - v.begin();
	if(ps < sz(v)) ans[1] = v[ps];
	if(ps >0)   ans[0] = v[ps-1];
	return ans;
	
}

void sss(ll& ans, ll x ,const VI& v1, const VI& v2){

		auto r= cal(x, v1);
		if(r[1] !=INF){
			ll sm = abs(r[1] - x);
			auto r2=cal(r[1], v2);
			if(r2[1] !=INF) ans = min(ans, sm + abs(r[1] - r2[1]));
			if(r2[0] !=INF) ans = min(ans, sm + abs(r[1] - r2[0]));
		}
		if(r[0] !=INF){
			ll sm = abs(r[0] - x);
			auto r2=cal(r[0], v2);
			if(r2[1] !=INF) ans = min(ans, sm + abs(r[0] - r2[1]));
			if(r2[0] !=INF) ans = min(ans, sm + abs(r[0] - r2[0]));
		}
}



int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,q;
	cin >>a >>b >>q;
	vector<ll> s(a+2), t(b+2);
	rep(i, a) cin >>s[i+1];
	rep(i,b)  cin >>t[i+1];
	s.front() = t.front() = -1LL<<60;
	s.back() = t.back() = 1LL<<60;

	
	vector<ll> xx(q);
	rep(i, q) cin >>xx[i];
	

	rep(i, q){
		ll  ans = INF;
		sss(ans, xx[i], s, t);
		sss(ans, xx[i], t, s);
		cout << ans <<"\n";
	}
	
	
	return 0;
}



Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <regex>
#include <stack>
#include <queue>
#include <vector>
#include <iomanip>
#define MAX_N 100
#define INF 10000000

using namespace std;

string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int n,a,b,c;
string s,t;

void solve(){
	int sum=n,x=0;
	for (int i = 0; sum >=0; i++) {
		if (sum>=0 && sum % 4 == 0) {
			x = 1;
		}
		sum -= 7;
	}
	if (x == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main() {
	cin >> n;
	solve();
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::*;
use std::cmp::*;

fn main() {
    input! {
        n: u128
    }

    if n % 2 == 1{
        println!("0");
        exit();
    }

    let ten: f64 = 10.0;
    let max_times = (ten.log(5.0) * 18.0).ceil() as u32;
    let mut res = 0u128;
    for i in 1..max_times{
        res += n / (2 * 5u128.pow(i));
    }
    println!("{}",res);
}

fn exit(){
    std::process::exit(0);
}

Measured memory_bytes: 2552
main = do
  li <- getLine
  let [a,b,c] = map read $ words li
  li <- getLine
  let k = read li
  putStrLn $ if compute a b c k then "Yes" else "No"

compute :: Int -> Int -> Int -> Int -> Bool
compute a b c k
  | a < b && b < c = True
  | k == 0 = False
  | a < b  = compute a b (c*2) (pred k)
  | True   = compute a (b*2) c (pred k)


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
int main() {

  int A,B;
  string op;
  cin >> A >> op >> B;
  
  if (op == "+") {
    cout << A + B << endl;
  }
  else if (op == "-") {
    cout << A - B << endl;
  }
}
  

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a.at(i);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 1 && a.at(i) % 2 == 1) {
      ans++;
    }
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 3628
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 200, INF = 1e9;
int N;
int A[MAX_N];

int main() {
  cin >> N;
  rep(i, N) cin >> A[i];

  int ans = INF;

  rep(i, N) {
    int t = 0;
    while(A[i]%2 == 0) {
      ++t;
      A[i] /= 2;
    }
    ans = min(ans, t);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
import java.util.*;

class Main
{
    public  static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int y = sc.nextInt();
        int x = sc.nextInt();
        
        if (x % 2 != 0 || x < 2 * y || x > 4 * y) {
            System.out.println("No");
            return;
        }
        
        System.out.println("Yes");
        
    }
}

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

int X[5];

int main(){
  rep(i, 3) cin >> X[i];
  cout << X[2] << " " << X[0] << " " << X[1] << endl;;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0;i <n;i++){
        int l,r;
        cin >> l >> r;
        int sa = abs(r - l + 1);
        ans += sa;
    }
    
    cout << ans;
    
}


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

int main() {
  int n,k;
  int ans = 0;

  cin >> n >> k;
  vector<int> l(n);
  
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }
  
  sort(l.begin(),l.end(),greater<int>());
  
  for(int j = 0; j < k; j++){
    ans += l[j];
  }
  cout << ans << endl;
  
  return 0;
  }

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import time
t1=time.time()
def LI():return list(map(int,input().split()))
n,k=LI()
a=LI()

for _ in range(k):
    tab=[0]*(n)
    for i in range(n):
        q=a[i]
        if 0<=i-q:
            tab[i-q]+=1
        else:
            tab[0]+=1
        if i+q+1<=n-1:
            tab[i+q+1]-=1
        else:
            pass
    b=[tab[0]]
    for i in range(n-1):
        b.append(tab[i+1]+b[-1])
    if a==b:
        print(*a)
        exit()
    a=b[:]
    if time.time()-t1>1.5:
        print(*a)
        exit()
print(*a)


Measured memory_bytes: 178908
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    n, A, B, C = map(int, input().split())
    bumb = []
    for _ in range(n):
        bumb.append(int(input()))

    min_cost = 100000000
    for i in range(1<<n):
        for j in range(1<<n):
            if i & j:
                continue
            for k in range(1<<n):
                if i & k or j & k:
                    continue
                a = 0
                b = 0
                c = 0
                a_cost = 0
                b_cost = 0
                c_cost = 0
                for idx in range(n):
                    if i & 1<<idx:
                        a_cost += 10 if a != 0 else 0
                        a += bumb[idx]
                    if j & 1<<idx:
                        b_cost += 10 if b != 0 else 0
                        b += bumb[idx]
                    if k & 1<<idx:
                        c_cost += 10 if c != 0 else 0
                        c += bumb[idx]
                if a == 0 or b == 0 or c == 0:
                    continue
                m = abs(a - A) + abs(b - B) + abs(c - C) + a_cost + b_cost + c_cost
                min_cost = min(min_cost, m)
    print(min_cost)
main()


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

int main()
{
  int N;
  int a[100010]={0};
  int ans=0;
  cin>>N;
  for(int i=0; i<N; i++){
    cin>>a[i];
    int c =a[i];
    ans=ans^c;
  }
  if(ans==0)cout<<"Yes"<<endl;
  if(ans!=0)cout<<"No"<<endl;
}


Measured memory_bytes: 640
n,h=gets.split.map(&:to_i)
m=0
swords=n.times.map{
  a,b=gets.split.map(&:to_i)
  m=a if m<a
  [a,b]
}
swords.sort_by!{|a,b|10**9*b+a}.reverse!
puts n.times.map{|i|
  a,b=swords[i]
  h-=b
  ret=i+1
  ret+=(h+m-1)/m if h>0
  ret
}.min

Measured memory_bytes: 12664
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    vi a(n);
    map<int,int> x;
    forn(i,n){
        cin>>a[i];
        x[a[i]]++;
        x[a[i]+1]++;
        if(a[i]>0){
            x[a[i]-1]++;
        }
    }
    int maxi = INT_MIN;
    for(auto i:x)   maxi = max(maxi, i.se);
    cout<<maxi<<endl;
    
    /*
    sort(all(a));

    int cnt=1, max_cnt=1, i=0, j=1;
    while(i<n && j<n)
    {
        if(a[j]-a[i]<=2)
        {
            j++;
            cnt++;
        }
        else
        {
            max_cnt = max(max_cnt, cnt);
            i++;
            cnt--;
        }
    }
    max_cnt = max(max_cnt, cnt);
    cout<<max_cnt<<endl;
    */
    return 0;
}



Measured memory_bytes: 8236
#include "bits/stdc++.h"
using namespace std;

int main() {

	int N, K;
	cin >> N >> K;

	vector<int> A(N);

	for (int i = 0;i < N;i++) {
		cin >> A.at(i);
	}

	set<int> var;

	for (int i = 0;i < N;i++) {
		var.insert(A.at(i));
	}

	vector<int> value(N+1);

	for (int i = 0;i < N;i++) {
		value.at(A.at(i))++;
	}

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

	int size = var.size();
	int ans = 0;
	for (int i = 0;i < value.size();i++) {
		if (size <= K) {
			break;
		}
		if (value.at(i) != 0) {
			size--;
			ans += value.at(i);
		}
	}

	cout << ans;

}


Measured memory_bytes: 11136
#include <cmath>

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int a;
int b;

void solve() {
  cin >> a >> b;

  int all = ((a + b - 1) * (a + b)) / 2;

  cout << all - a * b << '\n';
}

int main() {
  int t = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  t = 5;
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  while (t--)
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
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; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

int main()
{
	int N;
	cin >> N;
	int a[N];
	ll sum = 0;
	ll ans;
	for(int i = 0; i < N; i++) cin >> a[i],sum += a[i];
	if(N == 2)
	{
		cout << abs(a[0] - a[1]) << endl;
		return(0);
	}
	ll x,y;
	x = a[0];
	y = sum - a[0];
	ans = abs(x - y);
	for(int i = 1; i < N - 1; i++)
	{
		x += a[i];
		y -= a[i];
		ans = min(ans,abs(x - y));
	}
	cout << ans << endl;

}

Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S=next();
		long ans=0;
		for(int i=0;i<S.length();i++){
			ans+=Integer.valueOf(S.substring(i,i+1));
		}
		if(ans%9==0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
	public static long lmod(long i, long j) {
	     return (i%j)<0?(i%j)+0+(j<0?-j:j):(i%j+0);
	 }
	static boolean isOK(int index,int key,int[]a){
		if (a[index]>=key) return true;
	    else return false;
	}
	static int binary_search(int key,int[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}



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

int main() {
	// your code goes here
    string a, b;
    cin >> a >> b;
    int c, d;
    cin >> c >> d;
    string e;
    cin >> e;
    if(e == a){
        c--;
    }
    if(e == b)
    {
        d--;
    }
    cout << c << ' ' << d << endl;
	return 0;
}



Measured memory_bytes: 256
import sys
from pprint import pprint

def solve(n):
    c = [[0 for i in range(10)] for j in range(10)]
    for i in range(1, n+1):
        str_i = str(i)
        len_i = len(str_i)
        c[int(str_i[len_i-1])][int(str_i[0])] += 1
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += c[i][j] * c[j][i]
        
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    solve(n)

Measured memory_bytes: 40428
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}


void solve(long long K){
    ll sum=0;
    for (long long i = 1; i <= K; i++) {
        for (long long j = 1; j <= K; j++) {
            for (long long k = 1; k <= K; k++) {
                sum+=gcd(gcd(i,j),k);
            }
        }
    }
    cout << sum << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3764
answer = []

while True:
    inp = input()
    if inp == "-":
        break

    m = int(input())
    for i in range(m):
        h = int(input())
        shuffle = inp[h:] + inp[:h]
        inp = shuffle
    answer.append(shuffle)

[print(answer[i]) for i in range(len(answer))]


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, k, t, u, v, l;
  cin >> n >> k >> t >> u >> v >> l;
  map<int, bool> mp;
  for(int i=0;i<n;++i) {
    int tmp; cin >> tmp;
    mp[tmp] = true;
  }
  double tmpu = 1.0 / u, tmpv = 1.0 / v;
  int cnt = 0;
  double time = 0.0;
  double ans = 0.0;
  for(int i=0;i<l;++i) {
    if(cnt > 0 && time < eps) {
      time = t;
      cnt--;
    }
    if(mp[i] && (time < eps || cnt == k)) {
      time = t;
    } else if(mp[i]) {
      cnt ++;
    }
    if(time > eps) {
      ans += tmpv;
      time -= tmpv;
    } else {
      ans += tmpu;
      time -= tmpu;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3740
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long int
#define MO 1000000007

struct hoge{
  int p,A;
};

int ll_cmp(const void* a,const void* b){
  if ((*(ll*)a)>(*(ll*)b)) return -1;
  if ((*(ll*)a)<(*(ll*)b)) return 1;
  return 0;
}

ll a[2020][2];
ll dp[2020][2020];

ll max(ll a,ll b){
  if(a>b) return a;
  return b;
}

int main(){
  ll n;
  scanf("%lld",&n);
  for(int i=0;i<n;i++){
     scanf("%lld",&a[i][0]);
     a[i][1] = i+1;}
  
  ll ans=0;
  qsort(a,n,sizeof(ll)*2,ll_cmp);
  /*
  for(int i=0;i<n;i++){
    printf("%lld %lld\n",a[i][0],a[i][1]);}
  */
  dp[0][0] = 0;
  for(int y=1;y<=n;y++){
    dp[0][y] = dp[0][y-1]+a[y-1][0]*(n-y+1-a[y-1][1]);}
  for(int x=1;x<=n;x++){
    dp[x][0] = dp[x-1][0]+a[x-1][0]*(a[x-1][1]-x);
    for(int y=1;x+y<=n;y++){
      dp[x][y] = max(dp[x-1][y]+a[x+y-1][0]*(a[x+y-1][1]-x),dp[x][y-1]+a[x+y-1][0]*(n-y+1-a[x+y-1][1]));
    }}
  /*
  for(int i=0;i<=n;i++){
    for(int j=0;i+j<=n;j++){
      printf("%lld ",dp[i][j]);}
    printf("\n");}
  */
  int i=n,j=0;
  while(i>=0 && j>=0){
    if(ans<dp[i][j]) ans=dp[i][j];
    i--; j++;}
  
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 24448
from itertools import*
g=[(c>'<',len(list(m)))for c,m in groupby(input())]
n=len(g)
a=b=0
for i,(c,m)in enumerate(g):
  a+=m*~-m//2+max(m,b)*c+m*(c^1)*(i>n-2)
  b=m
print(a)

Measured memory_bytes: 22308
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
#include<iterator>
#include<functional>
#include<string.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp = boost::multiprecision;
long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}
int main(){
 int n; cin>>n;
 int h,w;
 cin>>h>>w;
 cout<<(n-h+1)*(n-w+1)<<endl;

  }


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

using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;

#define rep(i,a,b) for(int i =(a);i<(int)(b);i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

typedef long long ll;

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

    int n ;cin>>n; 
    vector<int> arr; 
    map<int, int> mp; 

    rep(i, 0, n){
        int x; cin>>x; 
        mp[x]++;
        if(mp[x]>1){
            continue;
        }
        else arr.push_back(x);
    }

    sort(all(arr));

    // for(auto x: arr){
    //     cout<<x<<" ";
    // }cout<<endl;


    int ans = 0;
    rep(i, 0, sz(arr)-2){
        rep(j, i+1, sz(arr)-1){
            rep(k,j+1,sz(arr)){
                if(arr[i]+arr[j]> arr[k]){
                    // DEBUG(i); 
                    // DEBUG(j);
                    // DEBUG(k);
                    int val= (mp[arr[i]]*mp[arr[j]]*mp[arr[k]]);
                    ans+= val;
                    // DEBUG(val);
                }

            }
        }

    }

    

    cout<<ans<<endl;


    return 0 ;
}



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

int main(){
  int N;
  cin >> N;
  int a[N];
  for (int i=0;i<N;i++){
    cin>>a[i];
  }
  int count=0;
  int temp=0;
  for (int i=0;i<N-1;i++){
    if(a[i]==i+1){
      temp=a[i];
      a[i]=a[i+1];
      a[i+1]=temp;
      count++;
    }
  }
  if(a[N-1]==N){
    count++;
  }
  cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
 	int x = 1;
	int y = 1;
 	
	while(true){
		scanf("%d %d", &x, &y);
		
		if(x == 0 && y == 0)
			break;
		
		if(x <= y){
			printf("%d %d\n",x, y);
		}
		else{
			printf("%d %d\n",y, x);
		}
	}
	return 0;
   
}

Measured memory_bytes: 2596
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, i, j, k;
	int y;
	scanf("%d%d", &n, &y);
	y/=1000;
	for(i=0; i<=n; i++){
		for(j=n-i; j>=0; j--){
			k=n-i-j;
			int Y=i*10+j*5+k;
			if(Y==y){
				printf("%d %d %d\n", i, j, k);
				return 0;
			}
		}
	}
	puts("-1 -1 -1");
}


Measured memory_bytes: 128
def fib(n):
    a, b = 1, 1
    for i in range(n):
        a, b = b, a + b
    return b


nm = input().split()
n = ["o"] * (int(nm[0])+1)
for i in range(int(nm[1])):
    this_index = int(input())
    n[this_index] = "x"
n_str = "".join(n)
if "xx" in n_str:
    print(0)
    exit()

n_list = n_str.split("x")
res = 1
for i in n_list:
    res *= fib(len(i)-2)
print(res % 1000000007)


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 3e5;
const ll INF = 1e9;
int l[N], r[N];

struct SegmentTree {
	ll t[4 * N], add[4 * N];

	void change(int v, ll val) {
    val = min(val, INF);
		t[v] = val;
		add[v] = val;
	}

	void push(int v, int tl, int tm, int tr) {
    if (add[v] != 0) {
      change(v * 2, add[v]);
  		change(v * 2 + 1, add[v] + tm + 1 - tl);
      add[v] = 0;
    }
	}

  ll get(int v, int tl, int tr, int pos) {
		if (tl == tr) {
			return t[v];
		}
		int tm = (tl + tr) >> 1;
    push(v, tl, tm, tr);
    if (pos <= tm)
      return get(v * 2, tl, tm, pos);
    else
      return get(v * 2 + 1, tm + 1, tr, pos);
	}

	void update(int v, int tl, int tr, int l, int r, ll val, int myl, int myr) {
		if (l > r) {
			return;
		}
		if (tl == l && tr == r) {
			change(v, val + (tl - myl));
			return;
		}
		int tm = (tl + tr) >> 1;
    push(v, tl, tm, tr);
		update(v * 2, tl, tm, l, min(r, tm), val, myl, myr);
		update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val, myl, myr);
		t[v] = min(t[v * 2], t[v * 2 + 1]);
	}
} st;

void solve() {
  int n, m; cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    st.update(1, 1, m, l[i], r[i], INF, l[i], r[i]);
    if (1 <= l[i] - 1) {
      ll v = st.get(1, 1, m, l[i] - 1);
      st.update(1, 1, m, l[i], r[i], v + 1, l[i], r[i]);
    }
    ll v = st.t[1];
    if (v != INF)
      cout << i + v << "\n";
    else
      cout << "-1\n";
  }
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


Measured memory_bytes: 13376
#include <stdio.h>

int main (){
	int h1,m1,h2,m2,k;
	scanf ("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
	
	int h=(h2-h1)*60;
	int m=m2-m1;
	int total=h+m-k;
	
	printf ("%d",total);
	
	return 0;
}

Measured memory_bytes: 2140
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
for i in range(N-1):
  n = a[i]+a[i+1]
  if n > x:
    ans += n-x
    if n-x > a[i+1]:
      a[i], a[i+1] = a[i]-(n-x-a[i+1]), 0
    else:
      a[i+1] -= (n-x)
print(ans)

Measured memory_bytes: 20084
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=998244353;
int main()
{
	ll i,j,k,m,n,t;
	cin>>n>>k;
	vector<pair<ll,ll>> v;
	for(i=0;i<k;i++)
	{
		ll  k1;
		cin>>j>>k1;
		v.push_back({j,k1});
	}
	ll ar[n],p[n];
	memset(ar,0,sizeof(ar));
	memset(p,0,sizeof(p));
	ar[0]=1;
	p[0]=1;
	for(i=1;i<n;i++)
	{
		for(auto x:v)
		{
			ll l=i-x.second;
			ll r=i-x.first;
			if(l<0 and r<0) continue;
			if(l<=0)
			ar[i]+=p[r];
			else
			{
				ll q=p[r]-p[l-1];
				if(q<0)
				q+=mod;
				else q%=mod;
				ar[i]+=q;
			}
			ar[i]%=mod;
		}
		p[i]=(p[i-1]+ar[i]%mod)%mod;
	}
	cout<<ar[n-1];
}

Measured memory_bytes: 6748
q = int(input())
info = [list(map(int,input().split())) for i in range(q)]

def prime_table(n):
  list = [True for _ in range(n + 1)]
  i = 2
  while i * i <= n:
    if list[i]:
      j = i + i
      while j <= n:
        list[j] = False
        j += i
    i += 1

  table = [i for i in range(n + 1) if list[i] and i >= 2]
  return table

li = prime_table(10**5)

isPrime = [False]*(10**5+1)
for i in li:
  isPrime[i] = True

isLikeNum = [0]*(10**5+1)
for i in range(1,10**5+1,2):
  if isPrime[i] and isPrime[(i+1)//2]:
    isLikeNum[i] = 1

ruiseki = [0]*(10**5+1)
for i in range(1,10**5+1):
  ruiseki[i] = ruiseki[i-1] + isLikeNum[i]
#print(ruiseki)

for i in range(q):
  print(ruiseki[info[i][1]]-ruiseki[info[i][0]-1])

Measured memory_bytes: 33132
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int r, w, c, n, ans;
    while (cin >> r >> w >> c >> n, r) {
        ans = (c * w - r) / n;
        if (ans <= 0) {
            cout << 0 << endl;
        } else if ((c * w - r) % n) {
            ans++;
            cout << ans << endl;
        } else {
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;

double L;

int main() {
	cin >> L;
	printf("%.12lf\n", 1.0 * L * L * L / 27.0);
	return 0;
}

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

int main(){
	
	int n,m,d ;
	int map[410][410] ;
	int dx[] = {-1,0,1,0} ;
	int dy[] = {0,1,0,-1} ;
	
	while( cin >> n , n ){
		for( int i=0 ; i<410 ; i++ )
			for( int j=0 ; j<410 ; j++ )
				map[i][j] = -1 ;
		
		int HL[2] = {200,200} ;
		int WL[2] = {200,200} ;
		int cnt = 1 ;
		map[200][200] = 0 ;
		
		for( int i=1 ; i<n ; i++ ){
			cin >> m >> d ;
			int p = cnt ;
			for( int j=HL[0] ; j<=HL[1] ; j++ ){
				for( int k=WL[0] ; k<=WL[1] ; k++ ){
					if( map[j][k] == m ){
						map[j+dy[d]][k+dx[d]] = cnt ;
						HL[0] = min( HL[0] , j+dy[d] ) ;
						HL[1] = max( HL[1] , j+dy[d] ) ;
						WL[0] = min( WL[0] , k+dx[d] ) ;
						WL[1] = max( WL[1] , k+dx[d] ) ;
						cnt++ ;
						break ;
					}
				}
				if( p != cnt ) break ;
			}
		}
		
		cout << WL[1]-WL[0]+1 << " " <<  HL[1]-HL[0]+1 << endl ;
	}
	
return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl

int main() {
  int n,m,x; cin >> n >> m >> x;
  int l, r; l=0; r=0;
  rep(i, m) {
    int tmp;
    cin >> tmp;

    if (tmp < x) {
      l++;
    } else {
      r++;
    }
  }
  p(min({l,r}));
}

Measured memory_bytes: 256
using System;
using System.IO;

class Solve{
    static void Main(string[] args){
        var H = long.Parse(Console.ReadLine());
        var index = 1;
        while (H > 1){
            H /= 2;
            index++;}
        var answer = Math.Pow(2, index) - 1;
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27864
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int N;
	cin >> N;
	int mod = N % 10;
	if (mod == 2 || mod == 4 || mod == 5 || mod == 7 || mod == 9)
		cout << "hon";
	else if (mod == 0 || mod == 1 || mod == 6 || mod == 8)
		cout << "pon";
	else
		cout << "bon";
	return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

P1 dat[2][600005];
class Segment{
private:
    
    P1 Min(P1 a,P1 b){
        if(a.first<=b.first)return a;
        else return b;
    }
    
public :
    
    int n;
    int ed;
    void init(int n_,int ed_){
        n=1;
        ed=ed_;
        while(n<n_)n*=2;
        for(int i=0;i<2*n-1;++i)dat[ed][i]=P1(INF,INF);
    }
    
    void update(int k,P1 a){
        k+=n-1;
        dat[ed][k]=a;
        while(k>0){
            k=(k-1)/2;
            dat[ed][k]=Min(dat[ed][k*2+1],dat[ed][k*2+2]);
        }
    }
    
    P1 query(int a,int b,int k,int l,int r){
        if(a<=l&&r<=b)return dat[ed][k];
        if(r<=a||b<=l)return P1(INF,INF);
        else {
            P1 vl=query(a,b,k*2+1,l,(l+r)/2);
            P1 vr=query(a,b,k*2+2,(l+r)/2,r);
            return Min(vl,vr);
        }
    }
    
};

int N;
vector<int> p,q;
priority_queue<P2,vector<P2>,greater<P2> > minInterval;
Segment seg[2];

void divideInterval(P1 id,int i,int j){
    P1 tmp = id;
    minInterval.push(P2(seg[tmp.first%2].query(tmp.first,i,0,0,seg[tmp.first%2].n).first,P1(tmp.first,i)));
    minInterval.push(P2(seg[(i+1)%2].query(i+1,j,0,0,seg[(i+1)%2].n).first,P1(i+1,j)));
    minInterval.push(P2(seg[(j+1)%2].query(j+1,tmp.second,0,0,seg[(j+1)%2].n).first,P1(j+1,tmp.second)));
}

signed main(){
    cin>>N;
    seg[0].init(N,0);
    seg[1].init(N,1);
    for(int i=0;i<N;++i){
        int x;
        cin>>x;
        p.PB(x);
        seg[i%2].update(i,P1(x,i));
    }
    minInterval.push(P2(seg[0].query(0,N,0,0,seg[0].n).first,P1(0,N)));
    while(q.size()!=N){
        P2 nextInterval = minInterval.top();
        int l = nextInterval.second.first,r = nextInterval.second.second;
        minInterval.pop();
        P1 i,j;
        i = seg[l%2].query(l,r,0,0,seg[l%2].n);
        j = seg[!(l%2)].query(i.second+1,r,0,0,seg[!(l%2)].n);
        q.PB(i.first);
        q.PB(j.first);
        divideInterval(nextInterval.second,i.second,j.second);
    }
    for(int i=0;i<q.size()-1;++i)cout<<q[i]<<" ";
    cout<<q[q.size()-1]<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n,m;cin>>n>>m;
    cout<<n-m+1<<endl;
}

Measured memory_bytes: 3540
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static long Solve(int N, long[] A)
        {
            var dict = new Dictionary<long, int>();
            foreach (long a in A)
            {
                if (!dict.ContainsKey(a)) { dict[a] = 0; }
                ++dict[a];
            }
            var X = dict.Where(pair => pair.Value >= 2).OrderByDescending(pair => pair.Key);
            if (X.Count() == 0) { return 0; }
            var x = X.First();
            dict[x.Key] -= 2;
            var Y = dict.Where(pair => pair.Value >= 2).OrderByDescending(pair => pair.Key);
            if (Y.Count() == 0) { return 0; }
            var y = Y.First();
            return x.Key * y.Key;
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            long[] A = ReadLongs();
            Console.WriteLine(Solve(N, A));
        }
    }
}


Measured memory_bytes: 30176
#include <iostream>

using namespace std;

int input1; 
int input2;
int input3;

int main() {
    cin >> input1 >> input2 >> input3;
    int cost_by_train = input1 * input2;
    int cost_by_taxi = input3;

    if (cost_by_train<cost_by_taxi){
        cout << cost_by_train;
    }
    else{
        cout << cost_by_taxi;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
#include <tuple>
#include <map>
using namespace std;

typedef unsigned long long ull;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

int DX[9] = {0, 1, 2, 0, 1, 2, 0, 1, 2}; 
int DY[9] = {0, 0, 0, 1, 1, 1, 2, 2, 2}; 

map<tuple<int, int>, bool> grid;

ull h, w, n;

bool invalid(int x, int y) {
  if (x < 0 || x >= w || y < 0 || y >= h) return true;
  return false;
}

int num_black(int x, int y) {
  int ret = 0;
  for (int i = 0; i < 9; ++i) { 
    int nx = x+DX[i];
    int ny = y+DY[i];
    if (invalid(nx, ny)) {
      return -2;
    }
    tuple<int, int> np = make_tuple(nx, ny);
    if (grid.find(np) == grid.end()) continue;
    bool used = grid[np];
    if (used) return -1;
    ++ret;
  }
  return ret;
}

int main() {
  cin >> h >> w >> n;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    tuple<int, int> pos = make_tuple(b, a);
    grid[pos] = false;
  }
  vector<ull> ans(10);
  for (auto it : grid) {
    int x, y;
    tie(x, y) = it.first;
    int id = it.second;
    for (int dx = -2; dx <= 0; ++dx) { 
      for (int dy = -2; dy <= 0; ++dy) { 
        int nx = x+dx;
        int ny = y+dy;
        if (invalid(nx, ny)) continue;
        int nb = num_black(nx,ny);
        // cout << "(" << x << " " << y << ")(" << nx << " " << ny << ")" << nb << endl;
        if (nb < 0) continue;
        ++ans[nb];
      }
    }
    grid[make_tuple(x, y)] = true;
  }
  ull block = 0;
  for (int i = 1; i <= 9; ++i) {
    block += ans[i];
  }
  ans[0] = (h-2)*(w-2) - block;
  cout << ans << endl;
}



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

using namespace std;


int main() {
    int num[101]={0},count=0,n;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        int numm;
        cin>>numm;
        if(num[numm]==0){num[numm]=1;count++;}
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));

int main() {
	int n;
	cin >> n;
	auto a = mat(int, 2, n, 0);
	int m = 2;
	rep(i, m)rep(j, n) cin >> a[i][j];

	vector<int>cs1(n + 1, 0), cs2(n, 0);
	cs1[n] = 0;
	cs1[n - 1] = a[0][n - 1] + a[1][n - 1];
	cs2[n - 1] = a[1][n - 1];
	for (int i = n - 1; i >= 1; i--) {
		cs1[i - 1] += cs1[i] + a[0][i - 1];
		cs2[i - 1] += cs2[i] + a[1][i - 1];
	}
	ll ma = 0;
	ll sum = 0;
	rep(i, n) {
		sum += a[0][i];
		ma = max({ ma, sum + cs2[i], sum + cs1[i + 1] });
	}
	cout << ma << endl;
	return 0;
}





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

	using namespace std;
	using ll=long long int;
	int n,k;
	int d[10];

	int main(){
		scanf("%d %d",&n,&k);
		for(int i=0;i<10;i++) d[i]=1;
		for(int i=0;i<k;i++) {
			int k;
			scanf("%d",&k);
			d[k]=0;
		}
		while(true){
			int k=n;
			while(k>0){
			 if(!d[k%10])break;
			 k/=10;
			}
			if(k==0) break;
			n++;
		}
		printf("%d",n);
		return 0;
	}

Measured memory_bytes: 256