akhauriyash/Code-Regression huggingface dataset:
dices, k = list(map(int, input().split()))
p = list(map(int, input().split()))

p_shift = p[k:] + [0] * k

con_p = [0] * dices
sum_first_k = sum(p[0:k])

con_p[0] = sum_first_k

for i in range(dices-k):
    con_p[i+1] = con_p[i] + p_shift[i] - p[i]

max_expectation = (k + max(con_p))/2.
print(max_expectation)


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

int main(){
    int n; cin >> n;
    vector<int> vec;
    for (int i=0;i<n;i++) {
        int a;
        cin >> a;
        vec.push_back(a);
    }
    sort(vec.begin(),vec.end(),greater<int>());
    int alice = 0;
    int bob = 0;
    for (int i=0;i<n;i++){
        if (i%2 ==0) alice += vec[i];
        else bob += vec[i];
    }
    cout << alice-bob << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define ALL(a) (a).begin(),(a).end()

int main(){
  ll X,Y,A,B,C; cin>>X>>Y>>A>>B>>C;
  ll p[A]; CINA(p,A); sort(p,p+A,greater<ll>());
  ll q[B]; CINA(q,B); sort(q,q+B,greater<ll>());
  ll r[C]; CINA(r,C); sort(r,r+C,greater<ll>());
  
  vector<ll> v;
  REP(i,X){ v.push_back(p[i]); }
  REP(i,Y){ v.push_back(q[i]); }
  REP(i,C){ v.push_back(r[i]); }
  sort(ALL(v),greater<ll>());
  
  ll ans = 0;
  REP(i,X+Y){ ans += v.at(i); }
  cout << ans <<"\n";
}

Measured memory_bytes: 8816
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <functional>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(x) begin(x), end(x)
using namespace std;

int solve(int n, vector<int> const & a, vector<int> const & b) {
    int sum_a = accumulate(whole(a), 0, bit_xor<int>());
    {
        map<int, int> cnt;
        for (int a_i : a) {
            cnt[a_i] += 1;
        }
        cnt[sum_a] += 1;
        for (int b_i : b) {
            if (cnt.count(b_i)) {
                cnt[b_i] -= 1;
                if (cnt[b_i] == 0) {
                    cnt.erase(b_i);
                }
            }
        }
        assert (not cnt.empty());
        if (cnt.size() >= 2 or cnt.begin()->second >= 2) {
            return -1;  // impossible
        }
    }
    int mismatch = 0;
    int component = 0; {
        map<int, set<int> > g;
        repeat (i, n) {
            if (a[i] != b[i]) {
                mismatch += 1;
                g[b[i]].insert(a[i]);
            }
        }
        set<int> used;
        function<void (int)> go = [&](int a_i) {
            used.insert(a_i);
            for (int a_j : g[a_i]) if (not used.count(a_j)) {
                go(a_j);
            }
        };
        component += 1;
        if (g.count(sum_a)) {
            go(sum_a);
        }
        repeat (i, n) if (not used.count(a[i])) {
            if (g.count(a[i])) {
                component += 1;
                go(a[i]);
            }
        }
    }
    return mismatch + (component - 1);
}

int main() {
    int n; scanf("%d", &n);
    vector<int> a(n); repeat (i, n) scanf("%d", &a[i]);
    vector<int> b(n); repeat (i, n) scanf("%d", &b[i]);
    int result = solve(n, a, b);
    printf("%d\n", result);
    return 0;
}


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

const int INF = 1'000'000'000;

using Weight=int;
using P=pair<Weight, int>;
struct Edge { int to; Weight cost; };

bool BellmanFord(const vector<vector<Edge>>& graph, vector<Weight>& dist, int s) {
	int V = graph.size();
	dist.assign(V, INF); dist[s] = 0;
	for (int i = 0; i < V; i++)
		for (int v = 0; v < V; v++)
			for (auto e : graph[v]) {
				if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
					if (i == V - 1)return true;
				}
			}
	return false;
}

int main() {
	int v, e, r;
	cin >> v >> e >> r;
	vector<vector<Edge>> g(v);
	for (int i = 0; i < e; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		g[s].push_back({ t,d });
	}

	vector<int> d;
	bool flag = BellmanFord(g, d, r);

	if (flag) {
		puts("NEGATIVE CYCLE");
	}
	else {
		for (auto aa : d) {
			if (aa == INF)puts("INF");
			else cout << aa << endl;
		}
	}
}


Measured memory_bytes: 3156
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    static boolean simulate( final int start, final int hit, final int[][] map ) {
	int current = start;
	for ( int i = 0; i < map.length; i++ ) {
	    if ( map[ i ][ current - 1 ] == 1 ) {
		current--;
	    } else if( map[ i ][ current ] == 1 ) {
		current++;
	    }
	}
	return current == hit;
    }
    
    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    final int n = Integer.parseInt( stdin.nextLine() );
	    if ( n == 0 ) {
		break;
	    }
	    final int m = Integer.parseInt( stdin.nextLine() );
	    final int hit = Integer.parseInt( stdin.nextLine() );
	    final int d = Integer.parseInt( stdin.nextLine() );

	    int[][] map = new int[ d ][ n + 1 ];
	    for ( int i = 0; i < d; ++i ){
		final String input = stdin.nextLine();
		for ( int k = 1; k <= n - 1; k++ ) {
		    map[ i ][ k ] = input.charAt( k - 1 ) - '0';
		}
	    }

	    if ( simulate( m, hit, map ) ){
		System.out.println( 0 );
	    } else {
		solveAdd( map, m, hit, n, d );
	    }	    
	}	
    }

    static void solveAdd ( final int[][] map, final int m, final int hit, final int n, final int d ) {
	for ( int i = 0; i < d; i++ ) {
	    for ( int j = 1; j <= n - 1; j++ ) {
		if ( map[ i ][ j ] == 0 && map[ i ][ j - 1 ] == 0 && map[ i ][ j + 1 ] == 0 ) {
		    map[ i ][ j ] = 1;
		    if ( simulate( m, hit, map ) ) {
			System.out.printf( "%d %d\n", ( i + 1 ), j );
			//printMap( map );
			return;
		    }
		    map[ i ][ j ] = 0;
		}
	    }
	}
	System.out.println( 1 );
    }

    static void printMap( int[][] map ) {
	for ( int[] array : map ) {
	    System.err.println( Arrays.toString( array ) );
	}
    }    
}

Measured memory_bytes: 23024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
	return 0;
}

void Main(){
	int h,w,m; cin >> h >> w >> m;
	vector<int> row(h,0), col(w,0);
	map<pair<int,int>, bool> exist;
	Rep(m){
		int x,y; cin >> x >> y;
		x--; y--;
		exist[make_pair(x,y)] = true;
		row[x]++;
		col[y]++;
	}
	int mx = 0;
	int dx = 0;
	rep(i, h){
		if(row[i] > mx){
			mx = row[i];
			dx = i;
		}
	}
	int my = 0;
	int dy = 0;
	rep(i, w){
		if(col[i] - exist[make_pair(dx, i)] > my){
			my = col[i] - exist[make_pair(dx, i)];
			dy = i;
		}
	}
	int ans = mx + my;

	mx = 0;
	my = 0;
	dx = 0;
	dy = 0;
	rep(i,w){
		if(col[i] > my){
			my = col[i];
			dy = i;
		}
	}
	rep(i, h){
		if(row[i] - exist[make_pair(i, dy)] > mx){
			mx = row[i] - exist[make_pair(i, dy)];
			dx = i;
		}
	}
	ans = max(ans, mx + my);
	cout << ans << endl;
}


Measured memory_bytes: 61804
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let a: i64 = sc.cin();
    let b: i64 = sc.cin();
    let xs: Vec<i64> = (0..n).map(|_| sc.cin()).collect();
    put!((1..n).map(|i| min!((xs[i] - xs[i-1]) * a, b)).sum::<i64>());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 11768
#include <iostream>
using namespace std;
int main(void){
    int r[4][3][10] = {{}};
    int n,b,f,o,v;
    cin>>n;
    for(int i = 0;i < n;i++){
        cin>>b>>f>>o>>v;
        r[b-1][f-1][o-1]+=v;
    }
    for(int i = 0;i < 4;i++){
          for(int j = 0;j < 3;j++){
           for(int m = 0;m < 10;m++){
               cout<<" ";
               cout<<r[i][j][m];
           }
           cout<<endl;
    }
    if(i<3)cout<<"####################"<<endl;
    }
}



Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <numeric>

using namespace std;

int main(void)
{
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0;i < n;i++) cin >> d[i];
    int size = d.size();

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

    cout << d[size/2] - d[size/2 - 1] << endl; 
    
    return 0;
}


Measured memory_bytes: 640
H, W = map(int, input().split())
field = [list(input()) for i in range(H)]

dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            num = 0
            for k in range(8):
                ni = i + dx[k]
                nj = j + dy[k]
                if ni < 0 or ni >= H or nj < 0 or nj >= W:
                    continue
                if field[ni][nj] == '#':
                     num += 1
            field[i][j] = str(num)

for i in range(H):
    for j in range(W):
        print(field[i][j], end='')
    print()


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

using pii = std::pair <int, int>;
const int N = 100010;
using ll = long long;

pii p[N];

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    int cnt = 0;
    if (n % 2 == 1){
        int left = n / 2, right = n - left;
        for (int i = 0; i < left; ++ i){
            p[cnt ++] = {right + i, right + i + left};
        }
        for (int i = 0; i < right; ++ i){
            p[cnt ++] = {i, i + right + left + left};
        }
    }
    else{
        int left = n / 2;
        for (int i = 0; i < left; ++ i){
            p[cnt ++] = {left + i, left + i + left};
            p[cnt ++] = {i, i + left * 3};
        }
    }
    std::sort(p, p + cnt, [](const pii &p1, const pii &p2){ return p1.first + p1.second < p2.first + p2.second;});
    for (int i = 0; i < cnt; ++ i){
        if ((ll) p[i].first + p[i].second + 2 * k > (ll) k + 2 * cnt + i){
            puts("-1");
            return 0;
        }
    }
    for (int i = 0; i < cnt; ++ i){
        printf("%lld %lld %lld\n", (ll) p[i].first + k,  (ll) p[i].second + k, (ll) k + 2 * cnt + i);
    }
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    ll ans = 0;

    unordered_map<string, ll> mp;
    rep(i,n){
        sort(ALL(s[i]));
        mp[s[i]]++;
    }

    for(auto t : mp){
        ll u = t.second;
        ans += (u*(u-1))/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17700
import math
N,D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        s = 0
        for k in range(D):
            s += (X[i][k] - X[j][k])**2
        if math.sqrt(s).is_integer():
            ans +=1
print(ans)

Measured memory_bytes: 9124
n = int(input())

l = list(map(int,input().split()))

k = 1

if 0 in l:
    print(0)
    exit()

for i in l:
    k = k*i
    if k > 10**18 :
        print(-1)
        exit()

if k > 10**18:
    print(-1)
else:
    print(k)

Measured memory_bytes: 21792
/**
 * @Author:      G_bg
 * @DateTime:    2019-08-10 20:16:03
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn = 1e5+10;
vector<int> v[maxn];
multiset<int> s;
int main(int argc, const char *argv[]) {
    ios::sync_with_stdio(0);cin.tie(0);
    int n,m;cin >> n >> m;
    for(int i = 1;i <= n;++i) {
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    int sum = 0;
    for(int i = 1;i <= m;++i){
        for(int j = 0;j < v[i].size();++j)
            s.insert(v[i][j]);
        if(s.size()){
            auto xx = s.end();
            sum += *--xx;
            s.erase(xx);
        }
    }
    cout << sum << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 7808
import collections
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
col_A = collections.Counter(A)
lis_col_A=[]
for key,val in col_A.items():
    lis_col_A.append([key,val])
slcA = sorted(lis_col_A,key = lambda x:-x[1])
sumA = 0
for i in range(K,len(slcA)):
    sumA += slcA[i][1]
print(sumA)
    

Measured memory_bytes: 47820
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int cnt = 0;
    rep(i,n){
        if(i == v[v[i]-1] - 1){
            cnt++;
        }
    }
    cout << cnt/2 << endl;
    return 0;
}

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

n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]

for i in range(n, 100000):
    f = True
    for si in str(i):
        if int(si) in d:
            f = False
    if f:
        print(i)
        break


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
// using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define ers erase
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

void Main() {
    ll X, K, D;
    cin >> X >> K >> D;

    X = abs(X);
    ll a = 0;
    ll d = abs(X/D);
    if (d > K) {
        a = X - K*D;
    } else {
        ll r = X%D;
        K -= d;
        if (K%2 == 0) {
            a = r;
        } else {
            a = min(abs(r-D), abs(r+D));
        }
    }

    cout << a << endl;
}

int main() {
    Main();
    // MainB();
    return 0;
}


Measured memory_bytes: 3628
def solve(L):
    for i in range(m):
        cnt = 0
        for j in range(1, s[i][0]+1):
            if L[s[i][j] - 1] == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            return 0
    else:
        return 1

n, m = map(int, input().split())
*s, p = [list(map(int, input().split())) for _ in range(m+1)]
ans = 0
for i in range(2 ** n):
    L = [0] * n
    for j in range(n):
        if ((i >> j) & 1) == 1:
            L[j] = 1
    ans += solve(L)
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

#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)

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

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

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

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


int dx[5] = {1, 0, -1, 0};
int dy[5] = {0, 1, 0, -1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N; cin >> N;
    vector<int> A(N);
    vector<int> B(N-1);

    rep(i,N-1){
        cin >> B[i];
    }

    A[0]=B[0];
    A[N-1]=B[N-2];
    for(int i=0; i<N-2; i++){
        if(B[i]<=B[i+1]){
            A[i+1]=B[i];
        }else{
            A[i+1]=B[i+1];
        }
    }
    lli ans=0LL;
    rep(i,N){
        ans+=A[i];
    }


    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <limits>
#include <cmath>
#include <typeinfo>
 
 
using namespace std; 

// ||    

// upper to lower = + 32;
// lower to upper = - 32;

int firstDigit(int n) 
{ 
    while (n >= 10)  
        n /= 10;  
    return n; 
}
int lastDigit(int n) 
{ 
    return (n % 10); 
} 
void sortString(string &str) 
{ 
   sort(str.begin(), str.end());
}
void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
} 
void bubbleSort(string s, int o, int n)
{  
    for(int i = 1; i <= n; i++) {
    	for(int j = 1; j <= n; j++)  {
       		if (s[o] < s[j]) {
       			swap(s[o], s[j]); 

       		}  
    	}
    }      
 
} 
bool allCharactersSame(string s) 
{ 
	int n = s.length();
    for (int i = 1; i < n; i++) 
        if (s[i] != s[0]) 
            return false; 
  
    return true; 
}
int factorial(int n) 
{ 
    return (n==1 || n==0) ? 1: n * factorial(n - 1);  
}

int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2;
        if (arr[mid] == x) 
            return mid;
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x);  
        return binarySearch(arr, mid + 1, r, x); 
    }
    return -1; 
} 
 
int main() { 
	int n = 0;
	cin >> n;
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	int e = 0;
	for(int i = 0; i < n; i++) {
		if(cnt == 0) {
			cout << s[i];
			cnt = 1;
		}
		if(cnt == 1) {
			cout << t[e];
			cnt = 0;
		}
		e++;
	}
 	cout << endl;

    return 0; 
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import deque

N, time = [int(n) for n in input().split()]

dq = deque()

for n in range(N):
    inp = input().split()
    dq.append([inp[0], int(inp[1])])

now = 0    
while len(dq):
    name, task = dq.popleft()
    if task > time:
        task -= time
        now += time
        dq.append([name, task])
    else:
        now += task
        print("{} {}".format(name, now))
    

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

int main()
{
    int n;

    cin >> n;
    vector<int> a(n);                                             // 各要素は個数
    vector<vector<int>> x(n, vector<int>()), y(n, vector<int>()); // 各要素はa[j]個の人の番号

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

        x[i].resize(a[i]);
        y[i].resize(a[i]);

        //x,yのヴェクタ
        for (int j = 0; j < a[i]; j++)
        {
            cin >> x[i][j] >> y[i][j];
        }
    }

    // 全探索の最大数
    int t = 1;
    for (int i = 0; i < n; i++)
    {
        t *= 2;
    }

    // メイン
    int maxAnswer = 0;

    // 全bit探索
    for (int i = 0; i < t; i++)
    {
        // 正直者と不親切な人をbitに変換
        vector<int> bitv(n, 0);

        // iを変えないためにkを導入
        int k = i;

        for (int j = 0; j < n; j++)
        {
            // 0か1を入れる
            //cout << k ;
            bitv[j] = k % 2;
            k = k / 2;
        }
        // ここまで切り出せそう？

        //answerの値の設定
        int answer = 0;
        for (int j = 0; j < n; j++)
        {
            if (bitv[j] == 1)
            {
                answer += 1;
            }
        }

        int frag;
        frag = 1;

        // 矛盾の確認
        for (int j = 0; j < n; j++) // 一回しか回ってない
        {
            // j番目が1ならx[j]にあるa[j]個の真偽を確認
            if (bitv[j] == 1)
            {
                for (int k = 0; k < x[j].size(); k++)
                {
                    if (bitv[x[j][k] - 1] != y[j][k])
                    {
                        frag = 0;
                        break;
                    }
                }
            }
            // frag==0なら矛盾してるのでbreak
            if (frag == 0)
            {
                break;
            }
        }

        // frag==1で大きくなっているなら値を更新
        if (answer > maxAnswer && frag == 1)
        {
            maxAnswer = answer;
        }
    }
    cout << maxAnswer << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N, K;
    string S;

    vector<int> len;

    void input() {
        cin >> N >> K;
        cin >> S;
        int l = 0, r = 0;
        while (l < S.size()) {
            while (r < S.size() && S[l] == S[r]) {
                r++;
            }
            len.push_back(r - l);
            l = r;
        }
        if (S[0] == '0') len.insert(len.begin(), 0);
        if (S.back() == '0') len.push_back(0);
    }

    void solve() {
        input();

        int l = 0;
        int r = l + 2 * K + 1;
        if (r > len.size()) {
            int ans = accumulate(all(len), 0);
            cout << ans << endl;
            return;
        }

        int sum = 0;
        for (int i = l; i < r; ++i) {
            sum += len[i];
        }
        int ans = sum;
        while (r < len.size()) {
            sum -= len[l];
            sum += len[r];
            l++;
            r++;
            if (l % 2 == 0) {
                chmax(ans, sum);
            }
        }
        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
using namespace std;
int main() {
	int a,b;
	string ans="";
	cin >>a>> b ;

	char as[10];
	char bs[10];
	sprintf(as,"%d",a);
	sprintf(bs,"%d",b);
	if(a>=b){
		rep(i,a){
			ans+=bs;
		}
	}
	else{
		rep(i,b){
			ans+=as;
		}
	}
	cout << ans <<endl;
	return 0;
}


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

typedef vector<long long> vec;
typedef vector<vec> mat;

mat times(mat& a,mat& b){
  long long n = a.size(), m = a[0].size(), l = b[0].size();
  mat ans(n,vec(l,0));
  for(int i=0; i<n; i++){
    for(int j=0; j<l; j++){

      for(int k=0; k<m; k++){
	ans[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  return ans;
}

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

  mat a(n,vec(m)), b(m,vec(l));

  for(int i=0; i<n; i++)
    for(int j=0; j<m; j++)  cin >> a[i][j];
  for(int i=0; i<m; i++)
    for(int j=0; j<l; j++)  cin >> b[i][j];

  mat ans = times(a,b);

  for(int i=0; i<n; i++){
    for(int j=0; j<l; j++){
      cout << ans[i][j];
      if(j!=l-1)cout << " ";
      else cout << endl;
    }
  }

}

Measured memory_bytes: 1416
#include <iostream>
using namespace std;
int p[100005];
int main(void){
    int N; cin>>N;
    for(int i=0;i<N;i++)cin>>p[i];
    int ans=0;
    for(int i=0;i<N;i++)if(p[i]==i+1){ans++;i++;}
    cout<<ans<<endl;
}

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

int main()
{
    int a,b;
    cin >> a >> b;
    if(a<=16 && b<=16 && (a+b)<=16){
        if(a==b || a==(b+1) || b==(a+1)){
            cout << "Yay!" << endl;
        }
        else{
            cout << ":(" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
	int a, b, n;
	while(scanf("%d %d", &a, &b) != EOF){
		if(a <= b){
			n = a;
			a = b;
			b = n;
		}
		if(a % b == 0) n = b;
		while(a % b != 0){
			if(a % b == 0){
				n = b;
				break;
			}
			a = a % b;
			n = a;
			a = b;
			b = n;
		}
		printf("%d\n", n);
	}
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

using pii=pair<int,int>;

pii normalize(string s){
	int n=s.size();
	string res="";
	rep(i,n){
		if(s[i]==')' &&  !res.empty() && res.back()=='(')
			res.pop_back();
		else
			res+=s[i];
	}
	pii ret=make_pair(0,0);
	for(auto &c:res){
		if(c==')')
			ret.first++;
		else
			ret.second++;
	}
	return ret;
}

vector<pii> ll,rr;

int main(void){
	int n;
	cin >> n;
	rep(i,n){
		string s;
		cin >> s;
		pii cur=normalize(s);
		int r=cur.first,l=cur.second;
		if(r<=l)
			ll.push_back(make_pair(r,l));
		else
			rr.push_back(make_pair(l,r));
	}

	bool ok=true;
	int ld=0,rd=0;
	sort(_all(ll)),sort(_all(rr));

	for(auto &it:ll){
		if(ld-it.first<0) ok=false;
		ld+=it.second-it.first;
	}

	for(auto &it:rr){
		if(rd-it.first<0) ok=false;
		rd+=it.second-it.first;
	}

	if(ok&&ld==rd)
		puts("Yes");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	int a, b;

	std::cin >> a >> b;

	if (a + b == 3) {
		std::cout << 3 << std::endl;
	}
	else if (a + b == 4) {
		std::cout << 2 << std::endl;
	}
	else {
		std::cout << 1 << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
void rev(char *s) {
	int l = strlen(s), i;
	for (i = 0; i<l / 2; i++) {
		char t = s[i];
		s[i] = s[l - 1 - i];
		s[l - 1 - i] = t;
	}
}
char T[4][8] = { "dream","dreamer","erase","eraser" };
int main() {
	int i , c=0, l;
	char s[100001];
	for (i = 0; i<4; i++)rev(T[i]);
	scanf("%s",& s);
	l = strlen(s);
	rev(s);
	for (; c<l;) {
		int k = -1;
		for (i = 0; i<4; i++) {
			if (!strncmp(s + c, T[i], strlen(T[i]))) {
				k = strlen(T[i]);
				break;
			}
		}
		if (k<0) {
			puts("NO");
			return 0;
		}
		c += k;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 256
N,L = map(int,input().split())
Strings = list()
for i in range(N):
    Strings.append(input())

ansString=""
for i in range(len(Strings)):
    for j in range(len(Strings)-1,i,-1):
        if Strings[j] < Strings[j-1]:
            Strings[j], Strings[j-1] = Strings[j-1], Strings[j]
            
for k in Strings:
    ansString += k
    
print(ansString)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,cnt;
int a[105],b[105];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	forn(i,3)
	{
		cin>>a[i]>>b[i];
		if(a[i]==b[i])cnt++;
	}
	if(cnt>=3)
	{
		cout<<"Yes";
		return 0;
	}
	for(int i=3;i<n;i++)
	{
		cin>>a[i]>>b[i];
		if(a[i]==b[i])cnt++;
		if(a[i-3]==b[i-3])cnt--;
		if(cnt>=3)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 3648
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var nods = Sarray();
            for (var i = N / 2; 0 < i; --i)
                maxHeapify(nods, (int)i);
            WriteLine(" " + string.Join(" ", nods));
        }
        static void maxHeapify(long[] A, int i)
        {
            var H = A.Length;
            var l = left(i);
            var r = right(i);
            var largest = 0;
            if (l <= H &&  A[i - 1]< A[l - 1])
            { largest = l; }
            else
            { largest = i; }
            if (r <= H && A[largest - 1] < A[r - 1])
            { largest = r; }
            if (largest != i)
            {
                var t = A[i-1];
                A[i-1] = A[largest-1];
                A[largest-1] = t;
                maxHeapify(A, largest);
            }
        }
        static int left(int l) => l * 2;
        static int right(int r) => r * 2 + 1;
    }
}


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

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = double;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

const int MAXN = 10000000;
int primes[MAXN], cnt;
map<int, int> factors;
void sieve(int *primes, int n, int &cnt)
{
    cnt = 0;
    memset(primes, 1, n * sizeof(int));

    for (int i = 2; i < n; i++)
    {
        if (primes[i]) primes[cnt++] = i;
        for (int j = 0; j < cnt && i * primes[j] < n; j++)
        {
            primes[i * primes[j]] = 0;
            if (i % primes[j] == 0) break;
        }
    }
}

void findDivisor(int n)
{
    for (int i = 0; i < cnt; i++)
    {
        if (primes[i] * primes[i] > n) break;
        while (n % primes[i] == 0)
        {
            n /= primes[i];
            factors[primes[i]]++;
        }
    }

    if (n > 1) factors[n]++;
    
    for(auto f : factors){
        for (int i = 0; i < f.second; i++) {
            cout << " " << f.first;
        }
    }

}


int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    sieve(primes, MAXN - 1, cnt);
    cout << n << ":";
    findDivisor(n);
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 42292
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm> 
#include<queue>
using namespace std;
const int maxn=810;
const int inf=0x3fffffff;
struct node
{
	int first,second,cnt;
	node(){
		
	}
	node(int first,int second,int cnt):first(first),second(second),cnt(cnt){
		
	}
};
int dist[maxn][maxn],sx,sy,w,h,k;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
char gra[maxn][maxn];
int bfs()
{
	dist[sx][sy]=0;
	queue<node>q;
	q.push(node(sx,sy,0));
	while(!q.empty())
	{
		node p=q.front();
		q.pop();
		if(p.first==1||p.second==1||p.second==w||p.first==h)	return 1;
		if(dist[p.first][p.second]==k)
				continue;
		for(int i=0;i<4;i++)
		{
			int tx=p.first+dx[i];
			int ty=p.second+dy[i];
			if(tx<1||tx>h||ty<1||ty>w||gra[tx][ty]=='#'||dist[tx][ty]!=-1)	continue;
			dist[tx][ty]=p.cnt+1;
			q.push(node(tx,ty,p.cnt+1));
		}
	}
	return 0;
}
int main()
{
	while(scanf("%d%d%d",&h,&w,&k)!=EOF)
	{
		for(int i=1;i<=h;i++)
		{
			char s[maxn];
			scanf("%s",&s[1]);
			for(int j=1;j<=w;j++)
			{
				gra[i][j]=s[j];
				if(s[j]=='S')
				{
					sx=i;
					sy=j;
				}
			}
		}
		int ans=inf;
		memset(dist,-1,sizeof(dist));
		if(sx==1||sy==1||sx==h||sy==w)
		{
			printf("0\n");
			continue;
		}
		int f=bfs();
		if(f==1)
		{
			printf("1\n");
			continue;
		}
		for(int i=1;i<=h;i++)
		{
			for(int j=1;j<=w;j++)
			{
				if(dist[i][j]==-1)	continue;
				int d=min(min(i-1,h-i),min(j-1,w-j));
				ans=min(ans,(d+k-1)/k+1);
			}
		}
		printf("%d\n",ans); 
	}
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

ull M = 1e18;
vector<ll> a;

signed main() {
  ull n, x = 1;
  cin >> n;
  a.resize(n);
  rep(i, n) {
    ull x;
    cin >> x;
    a[i] = x;
  }
  sort(begin(a), end(a));

  rep(i, n) {
    ull y = x * a[i];
    if (y > M || (x != 0 && y / x != a[i]) || (a[i] !=  0 && y / a[i] != x)) {
      cout << -1 << endl;
      return 0;
    }
    x = y;
  }
  cout << x << endl;
  return 0;
}


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

using namespace std;

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

	long long sum = 0;

	int takeA = min(k, a);

	k -= takeA;

	sum += takeA;

	if (k == 0) {
		cout << sum;
		return 0;
	}

	int takeB = min(b, k);

	k -= takeB;


	if (k == 0) {
		cout << sum;
		return 0;
	}

	int takeC = min(c, k);

	k -= takeC;
	sum -= takeC;

	cout << sum;
}

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

int sum (int x){
return (x*(x+1))/2;
}
int main(){
	
	
	int n,m; cin>>n>>m;
	cout<<sum(n-1)+sum(m-1)<<"\n";
	
	
	
}

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

const int N=2e+5+50;
long long int m1,m2;
pair<long long int,long long int> inp[N];
int n;

int main()
{
	cin>>n;
	m1=-1e+10;
	m2=1e+10;
	for(int i=1;i<=n;i++)
	{
		cin>>inp[i].first>>inp[i].second;
		m1=max(m1,inp[i].first+inp[i].second);
		m2=min(m2,inp[i].first+inp[i].second);
	}
	long long int ans=m1-m2;
	m1=-1e+10;
	m2=1e+10;
	for(int i=1;i<=n;i++)
	{
		//cin>>inp[i].first>>inp[i].second;
		m1=max(m1,inp[i].first-inp[i].second);
		m2=min(m2,inp[i].first-inp[i].second);
	}
	ans=max(ans,m1-m2);
	cout<<ans;

}



Measured memory_bytes: 6736
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
const int N = 200001;
int n,m,k;
ll a[N],b[N],val;
vector<ll>v;
int main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        scanf("%lld",&val);
        a[i]=a[i-1]+val;
    }
    
    for(int i=1;i<=m;i++){
        scanf("%lld",&val);
        b[i]=b[i-1]+val;
    }
    ll mx=0;
    for(int i=0;i<=n;i++){
        if(a[i]>k)
            break;
        ll at=upper_bound(b,b+m+1,k-a[i])-b;
        mx=max(mx,i+at-1);
    }
    cout<<mx;
    
}



Measured memory_bytes: 6336
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	string S; 
	cin >> S; 
	if(S.size() == 2){
		cout << S << endl; 
	}
	else if(S.size() == 3){
		cout << S.at(2) << S.at(1) << S.at(0) << endl; 
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m,x;
    cin>>n>>m;
    while (m--)
    {
        cin>>x;
        n-=x;
    }
    cout<<max(-1,n);
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
int main(){
	int n,m=0;
	std::cin>>n;
	int o=0;
	std::vector<int> vec(3);
	std::vector<int> vec2(n);
	int d=0;
	while(n>m){
		std::string str;
		std::cin>>str;
		if(str=="HIT"){
			if(vec[2]==1)vec2[d]+=1,vec[2]=0;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HOMERUN"){
			for(int i=0;i<3;i++){
				if(vec[i]==1)vec2[d]+=1;
				vec[i]=0;
			}
			vec2[d]+=1;
		}

		if(str=="OUT")o++;
		if(o==3){
			m++,o=0,d++;
			for(int i=0;i<3;i++){
				vec[i]=0;
			}
		}
	}
	for(int i=0;i<n;i++){
		std::cout<<vec2[i]<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N;

int main() {
  cin >> N;
  vector<int> P(N+1);
  for (int i=1; i<N+1; i++) {
    cin >> P.at(i);
  }
  int ans = 0;
  for (int i=1; i<N; i++) {
    if (P.at(i) == i) {
      int tmp = P.at(i);
      P.at(i) = P.at(i+1);
      P.at(i+1) = tmp;
      ans++;
    }
  }
  if (P.at(N)==N) {
    ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll st = 1, sa = 1;
    rep (i, n) {
        int t, a;
        cin >> t >> a;
        ll n = max((st + t - 1) / t, (sa + a - 1) / a);
        st = (ll)n * t;
        sa = (ll)n * a;
    }
    cout << st + sa << endl;

    return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;

    if (s.size() < 3) {
        cout << 0 << endl;
        return 0;
    }

    int count = 1, flag = 0;
    for (int i=0; i<s.size(); i++) {
        if (s[i] == 'R')
            flag = 1;

        if (s[i] == 'R' && s[i+1] == 'R')
            count++;
    }
    if (flag == 0)
        cout << 0;
    else
        cout << count;
    cout << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int getMin(int h, int m){
	return (60*h)+m;
}
long double getShortRad(int m){
	return (m * PI) / 360.0;
}
long double getLongRad(int m){
	return (m%60 * 6 * PI) / 180.0;
}

int main(void)
{
	
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	int minute = getMin(h, m);
	long double subx = (cosl(getShortRad(minute))*a) - (cosl(getLongRad(minute))*b);
	long double suby = (sinl(getShortRad(minute))*a - sinl(getLongRad(minute))*b);
	
	printf("%.20Lf", sqrtl(powl(subx, 2) + powl(suby, 2)));
	
	
	return 0;
	
}

Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n, m;
	cin >> n >> m;
	veci v(n);
	rep(i, n) cin >> v[i];
	n -= m;
	ll ans = 1;
	while (n > 0)
	{
		n -= m - 1;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3772
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class ACantWaitForHoliday {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      string s; cin >> s;
      if (s == "SUN") {
        cout << 7 << endl;
      } else if (s == "MON") {
        cout << 6 << endl;
      } else if (s == "TUE") {
        cout << 5 << endl;
      } else if (s == "WED") {
        cout << 4 << endl;
      } else if (s == "THU") {
        cout << 3 << endl;
      } else if (s == "FRI") {
        cout << 2 << endl;
      } else {
        cout << 1 << endl;
      }
    }
};

signed main() {
  ACantWaitForHoliday solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
z;t[99],k,i;char s[99];f(int*x){z=*x-*1[&x];}main(n){for(;scanf("%d",&n),z=n*=2;){for(;i=z;t[--z]=*s,t[--z]=i)for(scanf(" %[^\n]",s),k=n;k-=2;)i+=s[k]&2?30:s[k]&1?0:999;for(qsort(t,n/2,8,f);n--;)puts(t+n--);}}

Measured memory_bytes: 0