akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.readline

N,W = map(int,readline().split())

import numpy as np
dp = np.zeros(W + 1, dtype = int)

for i in range(N):
  w,v = map(int,readline().split())
  np.maximum(dp[:-w] + v,dp[w:],out = dp[w:])

print(dp.max())

Measured memory_bytes: 30104
h, w = map(int, input().split())
a = [0] * h
for i in range(h):
    aa = list(input())
    a[i] = aa

x, y = 0, 0
px, py = 0, 0
while not (x == w-1 and y == h-1):
    if not (x == 0 and y == 0):
        if px == x and py == y:
            print('Impossible')
            exit()
    px, py = x, y
    # → を検索
    if not x+1 > w-1:
        if a[y][x+1] == '#':
            a[y][x] = '.'
            x += 1
            continue
    # ↓ を検索
    if not y+1 > h-1:
        if a[y+1][x] == '#':
            a[y][x] = '.'
            y += 1
            continue

ans = True

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            if i == h-1 and j == w-1:
                pass
            else:
                ans = False

if ans:
    print('Possible')
else:
    print('Impossible')

Measured memory_bytes: 3064
#include <stdio.h>

int main (){
	char kalimat[20];
	scanf("%[^\n]", &kalimat);
	
	for (int i=0; i < 19 ; i++){
		if(kalimat[i] == ','){
		kalimat[i] = ' ';
		}
		}
	printf("%s", kalimat);
	
	
	return 0;
}

Measured memory_bytes: 1668
package main

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

var (
	uft []int
	ch  map[int]int64
)

func find(x int) int {
	if uft[x] == x {
		return x
	}

	uft[x] = find(uft[x])
	return uft[x]
}

func union(a, b int) {
	uft[a] = uft[b]
	ch[b] += ch[a]
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, m)
	bs := make([]int, m)
	for i := 0; i < m; i++ {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		bs[i], _ = strconv.Atoi(sc.Text())
	}

	uft = make([]int, n+1)
	ch = make(map[int]int64)
	for i := range uft {
		uft[i] = i
		ch[i]++
	}

	ans := make([]int64, m)
	ans[m-1] = int64(n * (n - 1) / 2)
	for i := m - 1; i >= 1; i-- {
		ar := find(as[i])
		br := find(bs[i])

		if ar != br {
			ans[i-1] = ans[i] - ch[ar]*ch[br]
			union(ar, br)
			continue
		}
		ans[i-1] = ans[i]
	}

	for _, v := range ans {
		fmt.Println(v)
	}
}


Measured memory_bytes: 11136
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
using namespace std;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
 
int main() {
	//freopen("test.txt", "r", stdin);
	FASTER;
	int n; cin>>n;
	bool ok=0;
	while(n){
		if(n%10==7) {ok=1; break;}
		n/=10;
	}
	if(ok) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <utility>
#include <queue>

#define MAX 500

using namespace std;

int tentuki(int n ,int m){
    int p;
    if (n>=m) {
        p = n - m;
    }else{
        p =0;
    }
    return p;
}


int main(){
    int n;
    vector<int> h(n,0);
    cin >> n;
    for (int i=0; i<n; i++) {
        int p;
        cin >>p ;
        h.push_back(p);
    }
    sort(h.begin(),h.end(), greater<int>());
    int stock = n;
    long long area=1;
    int huka=0;
    int flag=0;
    while (1) {
        int per;
        if (stock <= 3) {
            per = stock;
        }else{
            per = 4;
        }
        for (int i=0; i<per; i++) {
            area+=tentuki(h[flag++],huka);
        }
        huka++;
        stock-=4;
        if (stock <= 0) {
            break;
        }
    }
    cout << area << endl;
}

Measured memory_bytes: 35656
import io.StdIn.readLine

object Main extends App {
  val Array(_, a, b) = readLine.split(" ").map(_.toInt)
  val vs = readLine.split(" ").toSeq.map(_.toLong).sortBy(-_)

  case class Memo[A, B, C](f: (A, B) => C) extends ((A, B) => C) {
    private val cache = collection.mutable.Map.empty[(A, B), C]
    def apply(x: A, y: B) = cache getOrElseUpdate ((x, y), f(x, y))
  }

  val bc: Memo[Long, Long, Long] = Memo {
    case (_, 0) => 1
    case (n, k) if n == k => 1
    case (n, k) => bc(n - 1, k - 1) + bc(n - 1, k)
  }

  def solve(a: Int, b: Int, vs: Seq[Long]) = {
    val v0s = vs.takeWhile(_ == vs(0))
    val i = v0s.size

    if (vs.take(a).distinct.size > 1) {
      val i_first_ath = vs.indexOf(vs(a - 1))
      val nAth = vs.count(_ == vs(a - 1))
      bc(nAth, a - i_first_ath)
    }
    else {
      val ks = for (i <- a to b if vs.take(i).distinct.size == 1) yield i.toLong
      ks.map(k => bc(i.toLong, k)).sum
    }
  }

  def mean(xs: Seq[Long]) = 1.0 * xs.sum / xs.size

  println(if (vs.take(a).distinct.size == 1) vs(0) else mean(vs.take(a)))
  println(solve(a, b, vs))
}


Measured memory_bytes: 27300
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m,A,B;
int main()
{
    scanf("%d%d%d%d",&n,&m,&A,&B);
    for(int i=1;i<=B;i++)
    {
        for(int j=1;j<=m;j++) printf("%d",j<=A?0:1);
        puts("");
    }
    for(int i=B+1;i<=n;i++)
    {
        for(int j=1;j<=m;j++) printf("%d",j<=A?1:0);
        puts("");
    }
}


Measured memory_bytes: 1280
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;


int main() {
	int a, b, k,count=0;
	cin >> a >> b >> k;
	for (int i = 100; i >0;i--) {
		if (a%i==0&&b%i==0) {
			count++;
		}
		if (count==k) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = inint()

a = [s]
al = [s]


for i in range(1, 1000001):
    if a[i-1] % 2 == 0:
        if a[i-1]//2 not in al:
            al.append(a[i-1]//2)
            a.append(a[i-1]//2)
        else:
            print(i+1)
            break
    else:
        if a[i-1]*3+1 not in al:
            al.append(a[i-1]*3+1)
            a.append(a[i-1]*3+1)
        else:
            print(i+1)
            break


Measured memory_bytes: 62088
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

int main(){
  long n,c;
  cin>>n>>c;
  vector<long> a(n),b(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];

  vector<vector<long>> dp(n+1,vector<long>(c+1,0));
  dp[0][0] = 1;
  rep(i,n){
    vector<long> pows(c+1,0);
    for(int j=a[i]; j<=b[i]; j++){
      long p = 1;
      rep(k,c+1){
        (pows[k] += p)%=MOD;
        p = p*j%MOD;
      }
    }
    rep(j,c+1) if(dp[i][j]>0){
      for(int cc=j; cc<=c; cc++){
        (dp[i+1][cc] += dp[i][j]*pows[cc-j])%=MOD;
      }
    }
  }

  cout << dp[n][c]%MOD << endl;

  return 0;
}


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

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n;
	set <string> ms;
	string en;
	cin>>n;
	while(n--){
		cin>>en;
		ms.insert(en);
	}
	cout<<ms.size()<<endl;
	
	return 0;
}

Measured memory_bytes: 15560
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define deb(x) cout << #x << "=" << x << endl
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
int M=1e9+7,N=205001;

int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M



void solve() {
	int n,i,ans,x,s=0;
	rep(i,1,6){
		cin>>x;
		s+=x;
	}
	cout<<15-s;
}


signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}





Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint h, w;
char c[205][205];
bool b[205][205];
map<char, llint> mp;
map<llint, P> mp2;
UnionFind uf(405);

const int FACT_MAX = 15;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

int main(void)
{
	make_fact();
	
	cin >> h >> w;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> c[x][y];
		}
	}
	
	llint ans = 1;
	if(h % 2){
		string s, t;
		for(int i = 1; i <= w; i++) s += c[i][h/2+1];
		t = s;
		reverse(t.begin(), t.end());
		if(s != t) ans *= 2;
		
		for(int y = h/2+1; y < h; y++){
			for(int x = 1; x <= w; x++){
				c[x][y] = c[x][y+1];
			}
		}
		h--;
	}
	if(w % 2){
		string s, t;
		for(int i = 1; i <= h; i++) s += c[w/2+1][i];
		t = s;
		reverse(t.begin(), t.end());
		if(s != t) ans *= 2;
		
		for(int x = w/2+1; x < w; x++){
			for(int y = 1; y <= h; y++){
				c[x][y] = c[x+1][y];
			}
		}
		w--;
	}
	
	if(h >= 1 && w >= 1){
		for(int y = 1; y <= h/2; y++){
			for(int x = 1; x <= w/2; x++){
				mp.clear();
				mp[c[x][y]]++;
				mp[c[w+1-x][y]]++;
				mp[c[w+1-x][h+1-y]]++;
				mp[c[x][h+1-y]]++;
				llint mul = fact[4];
				for(auto it = mp.begin(); it != mp.end(); it++) mul /= fact[it->second];
				if(mp.size() == 4) mul /= 2, b[x][y] = true;
				ans *= mul, ans %= mod;
			}
		}
	}
	
	h /= 2, w /= 2;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			if(b[x][y]) uf.unite(x, w+y);
		}
	}
	for(int x = 1; x <= w; x++) mp2[uf.root(x)].first++;
	for(int y = 1; y <= h; y++) mp2[uf.root(y+w)].second++;
	
	llint cnt = 0;
	for(auto it = mp2.begin(); it != mp2.end(); it++){
		cnt += it->second.first + it->second.second - 1;
	}
	ans *= modpow(2, cnt), ans %= mod;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

long long int main(){
    int n,i,a,y,z;
    long long x;
    x=0;
    y=-1000000;
    z=1000000;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        x+=a;
        if(y<a){
            y=a;
        }else{
            
        }
        if(z>a){
            z=a;
        }else{
            
        }
    }
    printf("%d %d %lld\n",z,y,x);
    return 0;
}


Measured memory_bytes: 2104
N, M = gets.split.map(&:to_i)
edges = Array.new(N+1){{}}
companies = Array.new(N+1){{}}
M.times do
    p, q, c = gets.split.map(&:to_i)
    edges[p][c] ||= []
    edges[p][c].push(q)
    edges[q][c] ||= []
    edges[q][c].push(p)
    companies[p][c] = true
    companies[q][c] = true
end
visited = {}
dist = {}
deque = edges[1].keys.map{|c| c*(N+1) + 1}
deque.each do |code|
    dist[code] = 1
end
while deque.length > 0
    a = deque.shift
    ca = a / (N+1)
    na = a % (N+1)
    edges[na][ca].each do |nb|
        if nb == N
            puts dist[a]
            exit
        end
        b = ca * (N+1) + nb
        if !dist[b] || dist[b] > dist[a]
            dist[b] = dist[a]
            deque.unshift(b)
        end
    end
    unless visited[na]
        companies[na].each do |c, _|
            aa = c * (N+1) + na
            if !dist[aa] || dist[aa] > dist[a] + 1
                dist[aa] = dist[a] + 1
                deque.push(aa)
            end
        end
        visited[na] = true
    end
end
puts -1

Measured memory_bytes: 119932
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int N = 2e5+5;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
int n,k;
ll a[N],ans=1;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	for(int i=1;i<=n;i++)
	a[i]=i,a[i]+=a[i-1];
}
int main()
{
	cin>>n>>k;init();
	if(k>n)cout<<1;
	else
	{
		for(int i=k;i<=n;i++)
		{
			ans+=a[n]-a[n-i]-a[i-1]+1;
			ans=ans%mod;
		}
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 5148
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    l=list(map(int,input().split()))
    l.sort()
    YESNO(l[0]==l[1]==5 and l[2]==7)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <iostream>

using namespace std;

int main(){
  long long int h, n=1, ans=0;

  cin>> h;

  while(1){
    if(h>1){
      h/=2;
      ans+=n;
      n*=2;
    }else{
      ans+=n;
      break;
    }
  }

  cout<< ans <<endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		int ans = 0;
		Collections.sort(list);

		for(int i = 0; i < K; i++) {
			ans += list.get(i);
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 38216
#include<stdio.h>
int main(void)
{
	char s[4];
	int i,a;
	scanf("%s",s);
	a=700;
	for(i=0;i<=2;i++){
		if(s[i]=='o'){
			a=a+100;
		}
	}
	printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

char oomozi(char x)
{
	string a = "abcdefghijklmnopqrstuvwxyz";
	string A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (int i = 0; i < 26; i++)
	{
		if (x == a.at(i))
		{
			return A.at(i);
			break;
		}
	}
}

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

	cout << oomozi(a.at(0)) << oomozi(b.at(0)) << oomozi(c.at(0)) << endl;
	
}

Measured memory_bytes: 256
x(X):-current_input(I),read_string(I,' \n','',_,X).
n(N):-x(X),number_string(N,X).
ns(0,[]):-!.
ns(I,[N|A]):-n(N),I1 is I-1,ns(I1,A).
s(0):- writeln("No"),!.
s(N):- 7 is N mod 10,writeln("Yes"),!.
s(N):- N1 is N div 10,s(N1).
main:-
        n(N),s(N).


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

int main() {
	int a,b,c,d,ans=0,mx=0;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d)ans=1;
	else if(abs(a-b)<=d&&abs(b-c)<=d)ans=1;
	if(ans)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;    

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

int sh[100010];
int N;
int dp[100010];

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i = 0; i<N; i++) {
        cin >> sh[i];
    }
    for (int i = 1; i<N; i++) {
        int case1 = abs(sh[i]-sh[i-1])+dp[i-1];
        int case2 = numeric_limits<int>::max();
        if (i>1) {
            case2 = abs(sh[i]-sh[i-2])+dp[i-2];
        }
        dp[i] = min(case1, case2);
    }
    cout << dp[N-1] << endl;
    return 0;
}





Measured memory_bytes: 1024
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define endl '\n'


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        int x, y, z;
        in >> x;
        y = x / 500;
        z = x % 500;
        out << 1000*y + 5*(z/5) << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

string s, t;

int main() {
	string s, t;
	cin >> s >> t;
	
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3856
#include<iostream>
using namespace std;
int main(){
	string S;
	cin >> S;
	size_t size = S.length();
	int ans=0;
	if(size%2==0){
		for(int i=0; i<size/2;i++){
			if(S[i]!=S[size-1-i]){
				ans++;
			}
		}
	} else {
		for(int i=0;i<size/2;i++){
			if(S[i]!=S[size-1-i]){
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){	
	int n;
	string s; 
	cin >> n >> s;
	int ans = 1;
	
	for(int i = 0;i < n-1;++i)
		ans += s[i] != s[i+1];
	
	cout << ans;
}	


Measured memory_bytes: 3680
a,b = map(int, open(0).read().split())

i = int(a/0.08-1e-8)
while 1:
    if int(i*0.08)==a and int(i*0.1)==b:
        print(i)
        break
    if int(i*0.08)>a:
        print(-1)
        break
    i += 1

Measured memory_bytes: 61916
N = int(input())
A = [int(input()) for i in range(N)]
if A[0]:
    print(-1)
    exit()

ans = 0
for a,b in zip(A,A[1:]):
    if b-a > 1:
        print(-1)
        exit()
    if b==0: continue
    if b-a == 1:
        ans += 1
    else:
        ans += b
print(ans)

Measured memory_bytes: 12584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int a[30];
int b[3];

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%d", a+i);
	int ans = 0;
	REP(i, n-2){
		REP(j, 3) b[j]=a[i+j];
		sort(b, b+3);
		if(a[i+1] == b[1]) ans++;
	}
	printf("%d\n", ans);
}


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, k, a, b;
  in2(n, k);
  vector<ll> c(n), h(n, 9999999999999);
  rep(i, n)
    in(c[i]);
  h[0] = 0;
  rep(i, n){
    rep(j, k){
      b = max(0ll, i - j - 1);
      h[i] = min(h[i], h[b] + abs(c[i] - c[b]));
    }
  }
  out(h[n - 1]);
  memi;
}

Measured memory_bytes: 1920
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main() {
    string s;
    std::cin >> s;
    string result = "";
    for (int i = 0; i < s.length(); i++) {
        if(s[i]!='B'){
            result = result + s[i];
        }else{
            if(result.length()!=0){
                result = result.substr(0,result.length()-1);
            }
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 256
/**
 * 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 ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DAnythingGoesToZero {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      string s; cin >> s;
      vector<int> f(n+1);
      for(int i=1; i<=n; i++) {
        int p = __builtin_popcount(i);
        f[i] = 1 + f[i%p];
      }

      int cnt = 0;
      rep(i, n) {
        if (s[i] == '1') {
          cnt++;
        }
      }

      vector<int> mod(3);
      mod[0] = max(1, cnt-1);
      mod[1] = max(1, cnt);
      mod[2] = cnt+1;

      vector<vector<int>> beki(n+1, vector<int>(3));
      rep(i, 3) {
        beki[0][i] = 1%mod[i];
      }

      for(int i=0; i<n; i++) {
        rep(j, 3) {
          beki[i+1][j] = beki[i][j]*2%mod[j];
        }
      }

      vector<int> x(3);
      for(int i=0; i<n; i++) {
        if (s[i] == '1') {
          rep(j, 3) {
            x[j] += beki[n-1-i][j];
            x[j] %= mod[j];
          }
        }
      }

      for(int i=0; i<n; i++) {
        int j = 1;
        int now = 0;
        if (s[i] == '0') {
          j = 2;
          now = x[j] + beki[n-1-i][j];
          now %= mod[j];
        } else {
          j = 0;
          now = x[j] - beki[n-1-i][j] + mod[j];
          now %= mod[j];
          if (cnt == 1) {
            cout << 0 << '\n';
            continue;
          }
        }
        cout << 1+f[now] << '\n';
      }





    }
};

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

Measured memory_bytes: 15272
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

struct node
{
    int idx, p;
    bool operator<(const node &c)
    {
        return p < c.p;
    }
};

node x[200000];

int main()
{
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        x[i].idx = i + 1;
        scanf("%d", &(x[i].p));
    }

    sort(x, x + N);
    for (int i = 0; i < N; i++)
    {
        printf("%d ", x[i].idx);
    }
    printf("\n");
}

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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n,l[100010],r[100010];
ll ans = 0;

ll calc(){
	sort(l,l+n);
	sort(r,r+n);
	int p1 = n-1,p2 = 0;
	int cp = 0;
	ll ans = 0;
	bool run =1;
	while(run){
		run = 0;
		if(p1>=0 && l[p1]>cp){
			ans+=l[p1]-cp;
			cp = l[p1];
			p1--;
			run = 1;
		}
		if(p2<n && r[p2]<cp){
			ans+=cp-r[p2];
			cp = r[p2];
			p2++;
			run = 1;
		}
	}
	ans+=abs(cp);
	return ans;
}

int main() {
	read(n);
	for(int i=0;i<n;i++){
		read(l[i]);
		read(r[i]);
	}
	ans = calc();
	for(int i=0;i<n;i++){
		l[i]*=-1;r[i]*=-1;
	}
	swap(l,r);
	ans = max(ans,calc());
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

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

template<typename T>
constexpr T divide_ceil(T a, T b)
{
	T remainder = a % b;
	return remainder == 0 ? a / b : (a + (b - remainder)) / b;
}

int main()
{
	ll H, W;
	cin >> H >> W;

	ll S[3];
	ll ans = numeric_limits<int>::max();
	for(int i = 1; i <= H-1; ++i)
	{
		S[0] = W * i;
		ll restH = H - i;
		{
			S[1] = (restH / 2) * W;
			S[2] = divide_ceil(restH, static_cast<ll>(2)) * W;

			ll minS = min({ S[0], S[1], S[2] });
			ll maxS = max({ S[0], S[1], S[2] });

			ans = min(ans, maxS - minS);
		}

		{
			S[1] = restH * (W / 2);
			S[2] = restH * divide_ceil(W, static_cast<ll>(2));

			ll minS = min({ S[0], S[1], S[2] });
			ll maxS = max({ S[0], S[1], S[2] });

			ans = min(ans, maxS - minS);
		}
	}

	for (int i = 1; i <= W-1; ++i)
	{
		S[0] = H * i;
		ll restW = W - i;
		{
			S[1] = (restW / 2) * H;
			S[2] = divide_ceil(restW, static_cast<ll>(2)) * H;

			ll minS = min({ S[0], S[1], S[2] });
			ll maxS = max({ S[0], S[1], S[2] });

			ans = min(ans, maxS - minS);
		}

		{
			S[1] = restW * (H / 2);
			S[2] = restW * divide_ceil(H, static_cast<ll>(2));

			ll minS = min({ S[0], S[1], S[2] });
			ll maxS = max({ S[0], S[1], S[2] });

			ans = min(ans, maxS - minS);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#pragma comment(linker,"/STACK:102400000,102400000")
#define inf 0x3f3f3f3f
#define mem(x,t) memset(x,t,sizeof(x));
#define maxm 100000
typedef long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int cost,n;
    cin>>cost>>n;
    int c[maxm],t[maxm];
    for(int i=1;i<=n;i++)
        cin>>c[i];
    for(int i=0;i<maxm;i++)
    {
        t[i]=inf;
    }
    t[0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=c[i];j<=cost;j++)
        {
            t[j]=min(t[j],t[j-c[i]]+1);
        }
    }
    cout<<t[cost]<<endl;
    return 0;
}



Measured memory_bytes: 3516
#include <iostream>
#include <list>
using namespace std;
int main() {
	list<int> lst;
	string tmp;
	int key;
	int n; cin >> n;
	while (n--) {
		 cin >> tmp;
		if (tmp.size() < 7) {
			if (tmp[0] == 'i'){
				cin >> key; lst.push_front(key);
		}
			else{
				 cin >> key;
				list<int>::iterator itr = lst.begin();
				while ( itr != lst.end()) {
					if (key == *itr) {
						lst.erase(itr);
						break;
					}
					itr++;
				}
			}
		}else if (tmp[6] == 'F') lst.pop_front();
		else lst.pop_back();
	}
	list<int>::iterator itr = lst.begin();
	for (int i = 0; itr != lst.end(); itr++, i++) {
		if (i) cout << ' ';
		cout << *itr;
	}
	cout << endl;
}


Measured memory_bytes: 34364
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const ll MAX = 1000001;
struct Query { 
	ll l, r, idx; 
};
bool cmp(Query x, Query y) { 
	return x.r < y.r; 
}
void update(ll idx, ll val, ll bit[], ll n) { 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
}
ll query(ll idx, ll bit[], ll n) { 
	ll sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(ll arr[], ll n, Query queries[], ll q) {
	ll bit[n+1]; 
	memset(bit, 0, sizeof(bit));
	ll last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit));
	ll ans[q]; 
	ll query_counter = 0; 
	for (ll i=0; i<n; i++) 
	{
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n);
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n);
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	}
	for (ll i=0; i<q; i++) 
		cout << ans[i] << endl; 
}
int main()  { 
	ll n, q;
	cin >> n >> q;
	ll a[n];
	for (ll& x : a)
		cin >> x;
	Query queries[q]; 
	for(ll i=0; i<q; i++) {
		cin >> queries[i].l >> queries[i].r;
		queries[i].l--;
		queries[i].r--;
		queries[i].idx = i; 
	}
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 34960
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

int main()
{
	int x, max = 0;
	cin >> x;
	for (int i = 1; i <= x; i++) {
		for (int j = 2; j <= x + 1; j++) {
			if (pow(i, j) > max && pow(i, j) <= x) {
				max = pow(i, j);
			}
		}
	}
	cout << max << endl;
}

Measured memory_bytes: 384
from collections import defaultdict
N, K = map(int, input().split())
A = [(int(c)%K)-1 for c in input().split()]
B = [0]
for c in A:
  B += [B[-1]+c]
dic = defaultdict(int)
ldic = defaultdict(int)
for i in range(min(K,N+1)):
  c = B[i]
  dic[c%K] += 1
ans = 0
#print(dic)
for i in range(1,N+1):
  x = B[i-1]
  ldic[x%K] += 1
  ans += dic[x%K]-ldic[x%K]
  if K+i-1<=N:
    dic[B[K+i-1]%K] += 1
  """
  print('###############')
  print(i,x, ans)
  print(dic)
  print(ldic)
  """
print(ans)


Measured memory_bytes: 71048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()

int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<ll> ac(n, 0), wa(n, 0);
  ll ans_ac = 0;
  ll ans_wa = 0;
  rep(i, 0, m) {
    ll ptmp; string stmp;
    cin >> ptmp >> stmp;
    if (stmp == "WA" && ac[ptmp-1] == 0) {
      wa[ptmp-1] += 1;
      //ans_wa += 1;
    } else if (stmp == "AC" && ac[ptmp-1] == 0) {
      ac[ptmp-1] = 1;
      ans_ac += 1;
      ans_wa += wa[ptmp-1];
    }
  }
  
  cout << ans_ac << " " << ans_wa << endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {
	static List<List<Hen>> list;
	static boolean[] visit;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		Hen[] arr = new Hen[m];
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			Hen h = new Hen();
			h.a = Integer.parseInt(sa[0]) - 1;
			h.b = Integer.parseInt(sa[1]) - 1;
			list.get(h.a).add(h);
			list.get(h.b).add(h);
			arr[i] = h;
		}
		br.close();

		if (m % 2 == 1) {
			System.out.println(-1);
			return;
		}

		visit = new boolean[n];
		dfs(0, -1);

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < m; i++) {
			pw.println(++arr[i].c + " " + ++arr[i].d);
		}
		pw.flush();
	}

	static void dfs(int x, int p) {
		visit[x] = true;
		for (Hen h : list.get(x)) {
			int ch = h.a;
			if (ch == x) {
				ch = h.b;
			}
			if (!visit[ch] && ch != p) {
				dfs(ch, x);
			}
		}

		int cnt = 0;
		List<Hen> work = new ArrayList<>();
		for (Hen h : list.get(x)) {
			if (h.d == -1) {
				work.add(h);
			} else {
				if (h.c == x) {
					cnt++;
				}
			}
		}

		for (Hen h : work) {
			int ch = h.a;
			if (ch == x) {
				ch = h.b;
			}
			h.c = x;
			h.d = ch;
		}
		if (cnt % 2 != work.size() % 2) {
			Hen h = work.get(0);
			int tmp = h.c;
			h.c = h.d;
			h.d = tmp;
		}
	}

	static class Hen {
		int a, b, c, d = -1;
	}
}


Measured memory_bytes: 86864
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    string s;
    cin >> s;
    int n = s.length();
    int lb = 1, ub = n + 1;
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        bool ok = true;
        for(int i = n - mid; i + 1 < mid; ++i){
            if(s[i] != s[i + 1]){
                ok = false;
                break;
            }
        }
        if(ok)  lb = mid;
        else    ub = mid;
    }
    cout << lb << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  cin >> N;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; };
  ;
}
void solve() {
  bool ans = true;
  each(x, va) {
    if (x % 2 == 0) {
      if (x % 3 == 0 || (x % 5 == 0)) {
        continue;
      } else {
        ans = false;
        break;
      }
    }
  }
  cout << (ans ? "APPROVED" : "DENIED") << endl;
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();
        if(a-k>=0){
            a = a-k;
            System.out.println(a + " " + b);
        }
        else{
            k = k-a;
            a = 0;
            if(b-k>=0){
                b=b-k;
                System.out.println(a + " " + b);
            }
            else{
                System.out.println(0 + " " + 0);
            }
        }
    }
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> p(N); rep(i, N) cin >> p[i];
  vector<ll> q(N); rep(i, N) cin >> q[i];
  ll np[12];
  rep(i, N) np[i] = i + 1;
  ll ans = 0;
  ll oc = 0;
  ll po, qo;
  do {

    bool ok = true;
    rep(i, N) {
      if(p[i] != np[i]) ok = false;
    }
    if(ok) po = oc;
    ok = true;
    rep(i, N) {
      if(q[i] != np[i]) ok = false;
    }
    if(ok) qo = oc;
    oc++;
  } while(next_permutation(np, np + N));
  ans = abs(po - qo);
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3668
str = list(input())
q = int(input())

temp = []
for i in range(q):
    comm = input().split()

    if comm[0] == "replace":
        temp = list(comm[3])
        for i in range(0,int(comm[2])-int(comm[1])+1):
            str[int(comm[1])+i]=temp[i]
        temp.clear()
    elif comm[0] == "reverse":
        for i in reversed(range(int(comm[1]), int(comm[2])+1)):
            temp.append(str[i])
        for i in range(0, int(comm[2])-int(comm[1])+1):
            str[i+int(comm[1])] = temp[i]
        temp.clear()
    else:
        for i in range(int(comm[1]), int(comm[2])+1):
            temp.append(str[i])
        print(''.join(temp))
        temp.clear()


Measured memory_bytes: 5628
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define X first
#define Y second
#define sz(v) (int)v.size()
using ord = tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update>;
 
void solve();
 
main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef ONPC
	freopen("in.txt", "r", stdin);
#endif
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}



void solve() {
	int n;
	string s, t, out = "";
	cin >> n >> s >> t;
	for (int i = 0; i < n; ++i) {
		out += s[i];
		out += t[i];
	}
	cout << out;	
}


Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var n,m,i,j int
  var a []int
  fmt.Scan(&n)
  a = make([]int,n)
  for i=0;i<n;i++ {
    fmt.Scan(&a[i])
  }
  m = 0
  i = 0
  j = 0
  for {
    if a[j] == a[i] {
      j++
      if j == n {
        m += (j-i)/2
        break
      }
    } else {
      m += (j-i)/2
      i = j
    }
  }
  fmt.Println(m)
}

Measured memory_bytes: 512
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


k = I()
a, b = LI()
for i in range(a, b + 1):
    if i % k == 0:
        print('OK')
        break
else:
    print('NG')


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

int main()
{
	int N,sum = 0,M = 0;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		sum += a;
		M = max(M,a);
	}

	sum -= M / 2;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int A = 101;
const int B = 220;
const int INF = 19191919;

int f[B][B]={};
int dp[B][B][6];

struct State{
    int x,y,t;
};

int main()
{
    int sx,sy,gx,gy,lx,ly,n;
    cin >>sx >>sy >>gx >>gy;
    cin >>n;
    while(n--)
    {
        int x,y;
        cin >>x >>y;
        f[x+A][y+A] = 1;
    }
    cin >>lx >>ly;

    #define IN(x,y) (-lx<=x && x<=lx && -ly<=y && y<=ly)
    int dx[7]={0,1,1,0,-1,-1,0}, dy[7]={1,0,-1,-1,-1,0,0};

    rep(i,B)rep(j,B)rep(k,6) dp[i][j][k]=INF;
    dp[sx+A][sy+A][0]=0;
    queue<State> que;
    que.push({sx,sy,0});
    while(!que.empty())
    {
        State s = que.front();
        que.pop();
        int o = abs(s.x*s.y*s.t)%6;

        int nx = s.x+dx[o];
        int ny = s.y+dy[o];
        if(o%3!=0) ny += abs(s.x)%2;
        int nt = (s.t+1)%6;

        if(IN(nx,ny) && !f[nx+A][ny+A] && dp[nx+A][ny+A][nt]>dp[s.x+A][s.y+A][s.t])
        {
            dp[nx+A][ny+A][nt] = dp[s.x+A][s.y+A][s.t];
            que.push({nx,ny,nt});
        }

        rep(i,7)
        {
            nx = s.x+dx[i];
            ny = s.y+dy[i];
            if(i%3!=0) ny += abs(s.x)%2;
            if(IN(nx,ny) && !f[nx+A][ny+A] && dp[nx+A][ny+A][nt]>dp[s.x+A][s.y+A][s.t]+1)
            {
                dp[nx+A][ny+A][nt]=dp[s.x+A][s.y+A][s.t]+1;
                que.push({nx,ny,nt});
            }
        }
    }

    int ans = INF;
    rep(i,6) ans = min(ans, dp[gx+A][gy+A][i]);
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

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

int main() {
    int sx, sy, tx, ty; 
    cin >> sx >> sy >> tx >> ty;
    const int dx = tx - sx, dy = ty - sy;

    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy+1, 'U') << string(dx+1, 'R') << 'D';
    cout << 'R' << string(dy+1, 'D') << string(dx+1, 'L') << 'U';
    cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
#include <stdint.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)
 

int main()
{
    
    char c;
    cin>>c;

    char ans;

    ll num = c;
    num+=1;

    ans = num;
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MM 1000000000
int a1[1000],b1[1000],c1[1001][1001];
int main(void)
{
	int a,b,c=0,d=0,e=0,i,j,k;
	scanf("%d %d",&a,&b);
	for(i=0;i<=b;i++){
		for(j=0;j<a+1;j++){
			c1[i][j]=MM;
		}
	}
	for(i=0;i<a;i++){
		scanf("%d",&a1[i]);
	}
	for(i=0;i<b;i++){
		scanf("%d",&b1[i]);
	}
	/* for(i=b;i>=0;i--){
		for(j=0;j<a+1;j++){
			printf(".%d.",c1[i][j]);
		}
		printf("\n");
	}
	*/
	c1[0][0]=0;
	for(i=0;i<b;i++){
		for(j=0;j<a+1;j++){
			if(c1[i][j]!=MM){
				if(c1[i+1][j]>=c1[i][j]){
					c1[i+1][j]=c1[i][j];
				}
				if(j!=a+1){
					d=a1[j]*b1[i];
					if(c1[i+1][j+1]>=c1[i][j]+d){
						c1[i+1][j+1]=c1[i][j]+d;
					}
				}
			}
		}
	}
	/*for(i=b;i>=0;i--){
		for(j=0;j<a+1;j++){
			printf(".%d.",c1[i][j]);
		}
		printf("\n");
	}*/
	for(i=0;i<a+1;i++){
		if(MM>=c1[b][i]){
			e=c1[b][i];
		}
	}
	printf("%d\n",e);
	return 0;
}


Measured memory_bytes: 6636
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int a = -1, b;
  FOR(i,0,N) {
    int A, B; cin >> A >> B;
    if(A >= a) {
      b = B;
      a = A;
    }
  }
  cout << a + b << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll   long long int  
#define pb push_back
const int M=1e9 + 7;
using namespace std;
int N=1000000+1;
int main() {
   
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int W;cin>>W;
    ll* w=new ll[n+1];
    ll* v=new ll[n+1];
    for(int i=1;i<=n;i++)
    {
    	cin>>w[i]>>v[i];
	}
    ll** dp=new ll*[2];
    dp[0]=new ll[W+1];
    dp[1]=new ll[W+1];
    for(int i=0;i<=W;i++)
    {
    	dp[0][i]=0;
	}
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=W;j++)
		{   
		    if(j==0)
		    {
		    	dp[flag][j]=0;
		    	continue;
			}
			if(j>=w[i])
			{
				dp[flag^1][j]=max(v[i]+dp[flag][j-w[i]],dp[flag][j]);
			}else{
				dp[flag^1][j]=dp[flag][j];
			}
		}
		flag=flag^1;
	}
	cout<<dp[flag][W]<<endl;
	return 0;
}










Measured memory_bytes: 1792