akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int l = 1, r = n;
  for (int i = 0; i < m; ++i) {
    int nl, nr;
    scanf("%d%d", &nl, &nr);
    l = max(l, nl);
    r = min(r, nr);
    if (l > r) {
      puts("0");
      return 0;
    }
  }
  printf("%d\n", r - l + 1);
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(ll i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
typedef long long ll;

const ll MOD = 1000000007;
const int MAX = 1024;


bool prime[MAX];
ll dividetimes[MAX];

void solve(void){
    //prime_table
    rep(MAX, i) prime[i] = true;
    prime[0] = prime[1] = false;
    Rep(2, MAX, i) {
        if (prime[i]) {
            for (int k = 2; i * k <= MAX; k++){
                prime[i*k] = false;
            }
        }
    }
    int N;
    scanf("%d\n", &N);
    Rep(2, N, n){
        Rep(2, n, d) {
            ll t = n;
            if (prime[d]) {
                while(t%d==0){
                    dividetimes[d]++;
                    t /= d;
                }
            }
        }
    }
    ll ans = 1LL;
    Rep(2, N, n){
        ans *= (dividetimes[n]+1)%MOD;
        ans %= MOD;
    }
    printf("%lld\n", ans);
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	set<int> s;
	rep(i,n){
		int a;cin >> a;
		if(s.count(a) == 0) s.insert(a);
		else s.erase(a);
	}
	cout << s.size() << endl;
}


Measured memory_bytes: 4992
h, w = map(int,input().split())
aList = []
for i in range(h):
  aList.append(list(input()))
for i in range(h-1,-1,-1):
  if aList[i].count('#') == 0:
    aList.pop(i)

aList = list(zip(*aList))
for i in range(w-1,-1,-1):
  if aList[i].count('#') == 0:
    aList.pop(i)

aList = list(zip(*aList))

for i in aList:
  print(''.join(i))


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    string s;cin >> s;
    int n = s.size();
    int l, r;
    for(int i=0;i<n;i++){
        if(s[i] == 'A'){
            l = i;
            break;
        }
    }
    for(int i=n-1;i>=0;i--){
        if(s[i] == 'Z'){
            r = i;
            break;
        }
    }

    cout << r-l+1 << endl;
    return 0;
}


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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define sz(x) (int)x.size()

int main(){
    fastio;
    set<int> letras[1005];
    string total, wanted;
    cin >> total >> wanted;
    for(int i=0; i<sz(total); i++){
        letras[(int)total[i]].insert(i+1);
    }
    ll resp=0;
    int pos=-1;
    for(int i=0; i<sz(wanted); i++){
        int letra=(int)wanted[i];
        if(sz(letras[letra])==0){
            cout << -1 << endl;
            return 0;
        }
        set<int>::iterator it=letras[letra].upper_bound(pos);
        if(it==letras[letra].end()){
            resp+=(sz(total)-pos)+*letras[letra].begin();
            pos=*letras[letra].begin();
        }else{
            resp+=*it-pos;
            pos=*it;
        }
    }
    cout << resp-1 << endl;
    return 0;
}

Measured memory_bytes: 5200
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        """[l, r)
        """
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret


@mt
def slv(N, K, P):
    min_st = SegmentTree(P, min, INF)
    max_st = SegmentTree(P, max, -1)

    a = []
    for i in range(N-K):
        min_p = min_st.query(i, i+K+1)
        max_p = max_st.query(i, i+K+1)
        if P[i] == min_p and P[i+K] == max_p:
            a.append((i, i+K))

    j = 0
    ss = []
    for i in range(N-1):
        if P[i] < P[i+1]:
            pass
        else:
            if i - j + 1 >= K:
                ss.append((j, i+1))
            j = i + 1
    i += 1
    if i - j + 1 >= K:
        ss.append((j, i+1))

    ans = N - K + 1
    if ss:
        ans -= sum(s[1]-s[0] - K + 1 for s in ss) - 1

    ss.reverse()
    for l, r in a:
        while ss and ss[-1][1] <= l:
            ss.pop()
        if ss:
            if ss[-1][0] <= l and r < ss[-1][1]:
                pass
            else:
                ans -= 1
        else:
            ans -= 1

    return ans


def main():
    N, K = read_int_n()
    P = read_int_n()
    print(slv(N, K, P))


if __name__ == '__main__':
    main()


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

using namespace std;

#define AC return 0

typedef long long ll;

stack<int> st1;
stack<pair<int, int> > st2;

int main() {
	char ch;
	int ans = 0;
	for (int i = 0; cin >> ch; ++i) {
		if (ch == '\\') st1.push(i);
		else if (ch == '/' && st1.size()){
			int j = st1.top();
			st1.pop();
			int num = i - j;
			ans += num;
			while (st2.size() && st2.top().first > j) {
				num += st2.top().second;
				st2.pop();
			}
			st2.push(make_pair(j, num));
		}
	}
	vector<int> outt;
	while (st2.size()) {
		outt.push_back(st2.top().second);
		st2.pop();
	}
	printf("%d\n%d", ans, outt.size());
	for (int i = outt.size() - 1; ~i; --i) {
		printf(" %d", outt[i]);
	}
	printf("\n");
	AC;
}


Measured memory_bytes: 3332
#include<cstdio>

int StLn(char *s); //my strlen
void StrStr(char *p, char *circle);

int main() {
  char s[101], p[101] = { '0' }, circle[201] = { '0' };

  scanf("%s %s", s, p);
  sprintf(circle, "%s%s", s, s);
  //printf("circle = %s\n", circle);
  StrStr(p, circle);
  return 0;
}

int StLn(char *s) {
  int c = 0;
  for (int i = 0; s[i] != '\0'; i++) {
    c++;
  }
//printf ("c=%d\n",c);
  return c; //return 0に注意
}

void StrStr(char *p/*探す文字列*/, char *circle/*この文字列の中から探す*/) {
  for (int i = 0; i < StLn(circle); i++) {//探す対象の全域を探索する
    int j = 0;

    for (j = 0; ( j < StLn(p) && p[j] == circle[i + j] ); j++);
    //条件合わないとj==StLn(p)にならず終わる

    if (j == StLn(p)) {
    //一致した時
      printf("Yes\n");
       return;
    }  
    
  }
  printf("No\n");

}


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

int main() {
	long long n;cin>>n;
	vector<long long> a(3*n);
	priority_queue<long long,vector<long long>,greater<long long>> q;
	priority_queue<long long,vector<long long>,less<long long>> q2;
	for(int i=0;i<3*n;i++){
		cin>>a[i];
	}
	long long sum=0;
	for(int i=0;i<n;i++){
		q.push(a[i]);
		sum+=a[i];
	}
//	vector<long long> sl(n),sr(n);
//	sl[0]=a[0];
//	for(int i=1;i<n;i++){
//		sl[i]=sl[i-1]+a[i];
//	}
//	sr[n-1]=a[n-1];
//	for(int i=n-2;i>=0;i--){
//		sr[i]=sr[i+1]+a[i];
//	}
	vector<long long> sl(3*n,0);
	sl[n-1]=sum;
	for(int i=n;i<2*n;i++){
		sum+=a[i];
		q.push(a[i]);
		long long temp=q.top();
		q.pop();
		sum-=temp;
		sl[i]=sum;
	}
	sum=0;
	for(int i=3*n-1;i>=2*n;i--){
		q2.push(a[i]);
		sum+=a[i];
	}
	vector<long long> sr(3*n,0);
	sr[2*n]=sum;
	for(int i=2*n-1;i>=n;i--){
		sum+=a[i];
		q2.push(a[i]);
		long long temp=q2.top();
		q2.pop();
		sum-=temp;

		sr[i]=sum;
	}
	long long ans=-1;
	for(int i=0;i<15;i++)ans*=10;
	for(int i=n-1;i<2*n;i++){
		long long temp=sl[i]-sr[i+1];
		if(temp>ans)ans=temp;
	}
//	for(int i=0;i<3*n;i++){
//		cout<<sr[i];
//	}
//	cout<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8948
var
	A,B,C,K:Longint;
begin
	read(A,B,C,K);
	while A>=B do begin
		dec(K);
		B:=B*2;
	end;
	while B>=C do begin
		dec(K);
		C:=C*2;
	end;
	if K<0 then writeln('No')else writeln('Yes');
end.


Measured memory_bytes: 1388
'use strict';
(function(stdin) {
  var lines  = stdin.toString().split('\n');
  var param = lines[0].split(' ').map(Number);
  var result = (function(a,b) {
    return [
        ~~(a / b)
        ,(a % b)
        ,(a / b).toFixed(5)
    ].join(' ');
  }(param[0],param[1]
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15896
import math

def main():
    A, B, K = map(int, input().split())
    
    c_list = []
    
    for i in range(1, min(A, B)+1):
        if A%i==0 and B%i==0:
            c_list.append(i)
    c_list.reverse()
    print(c_list[K-1])
main()

Measured memory_bytes: 2940
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    num, a, b = map(int, input().split())
    data = list(input())

    for i in range(num):
        if data[i] == 'a':
            if a > 0:
                a -= 1
                print('Yes')
            elif b > 0:
                b -= 1
                print('Yes')
            else:
                print('No')
        elif data[i] == 'b':
            if b > 0:
                b -= 1
                print('Yes')
            else:
                print('No')
        else:
            print('No')




if __name__ == '__main__':
    main()



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


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int[,] s = new int[3, 3];
            int[] A = new int[3];
            for (int i = 0; i < 3; i++)
            {
                int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
                //配列作成
                for (int j = 0; j < 3; j++)
                {
                    s[i, j] = tmp[j];
                }
                //同時にaも求める
                A[i] = tmp.Min();

            }
            string ans = "No";
            if (s[0,0] - A[0] == s[1, 0] - A[1] && s[1, 0] - A[1] == s[2, 0] - A[2])
            {
                if (s[0, 1] - A[0] == s[1, 1] - A[1] && s[1, 1] - A[1] == s[2, 1] - A[2])
                {
                    if (s[0, 2] - A[0] == s[1, 2] - A[1] && s[1, 2] - A[1] == s[2, 2] - A[2])
                    {
                        ans = "Yes";
                    }
                }
            }

            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String ans = "";
        for(char c: str.toCharArray()) {
            if(c == '1') ans += '9';
            else if(c == '9') ans += '1';
            else ans += c;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 3e5 + 1;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s; cin >> s;
    int n = s.size();
    int l = -1, r = n;
    while (r - l > 1) {
        int md = (l + r) / 2;
        bool gd = 0;
        for (char ch = 'a'; ch <= 'z'; ch++) {
            int ck = 0; gd = 1;
            for (int i = n - 1; i >= 0; i--) {
                if (s[i] == ch)
                    ck = 0;
                else
                    ++ck;
                if (ck > md) {
                    gd = 0;
                    break;
                }
            }
            if (gd) break;
        }
        if (gd) r = md;
        else l = md;
    }
    cout << r;
    return 0;
}


Measured memory_bytes: 256
import sys
import copy
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
b = [0]
for i in range(N):
    b.append(A[i])
b.append(0)

sumb= 0
for i in range(1,len(b)):
    sumb += abs(b[i]-b[i-1])

for j in range(1,N+1):
    sumc = sumb
    sumc = sumc - abs(b[j+1]-b[j])-abs(b[j]-b[j-1])+abs(b[j+1]-b[j-1])
    print(sumc)



Measured memory_bytes: 20516
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;


int main() {

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

	int n, k;

	cin >> n >> k;

	if ((n + 1 )/ 2 >= k) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;

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

struct edge {int to, cost;}; // 辺
vector<edge> graph[MAX]; // 隣接リスト
bool visited[MAX]; // 訪問状況
int mark[MAX]; // 洞窟の道標

int n, m; // 変数

void bfs(int start) {
    queue<int> q;
    q.push(start);
    visited[start] = true;
    while (not q.empty()) {
        int cur = q.front();
        q.pop();
        for (edge e : graph[cur]) {
            if (visited[e.to]) continue;
            q.push(e.to);
            visited[e.to] = true;
            mark[e.to] = cur;
        }
    }
}

int main() {
// input
    cin >> n;
    cin >> m;
    rep(i, m) {
        int a, b;
        cin >> a;
        cin >> b;
        graph[a].push_back({b, 0});
        graph[b].push_back({a, 0});
    }
// solve
    bfs(1);
// output
    cout << "Yes" << "\n";
    rep(i, n+1) {
        if (i > 1) cout << mark[i] << "\n";
    }
}

Measured memory_bytes: 33664
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using Graph = vector<vector<int> >;
Graph G;

void dfs(int v, vector<bool> &seen, int &res) {
    bool end = true;
    rep(i,seen.size()) if(!seen[i] && i!=v) end = false;
    if (end) {
        ++res;
        return;
    }

    seen[v] = true;
    for (auto nv : G[v]) {
        if (seen[nv]) continue;
        dfs(nv, seen, res);
    }
    seen[v] = false;
}

int main() {
    int N, M; cin >> N >> M;
    G.assign(N, vector<int>());
    rep (i,M) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<bool> seen(N, false);
    int res = 0;
    dfs(0, seen, res);
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		sc.close();

		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += l + i;
		}

		if (l <= 0) {
			if (l + n - 1 < 0) {
				System.out.println(sum - (l + n - 1));
			} else {
				System.out.println(sum);
			}
		} else {
			System.out.println(sum - l);
		}
	}
}


Measured memory_bytes: 23764
n, m = gets.split.map(&:to_i)
abs = n.times.map { gets.split.map(&:to_i) }.sort!

ans = 0

abs.each do |a, b|
  if b > m
    ans += a * m
    m = 0
  else
    ans += a * b
    m -= b
  end

  break if m <= 0
end

puts ans


Measured memory_bytes: 10488
i;k;t;main(n){
        
        
        int c[501],f[500],s[500];
        for(scanf("%d",&n);k<n-1;k++)scanf("%d%d%d",&c[k],&s[k],&f[k]);
        
        for(;i<n-1;i++){
            t=0;
            for(int j=i;j<n-1;j++){
                if(t<=s[j]){
                    t=s[j]+c[j];
                }else{
                    t=s[j]+(int)ceil( ((double)t-(double)s[j])/(double)f[j] )*f[j]+c[j];
                    
                }
            }
            printf("%d\n",t);
        }
        printf("0");
    }

Measured memory_bytes: 1696
MODC = 1000000007

n = gets.strip.to_i
z = 0
st = Hash.new{|hash, key| hash[key] = [0,0]}
n.times do
  a,b = gets.strip.split.map(&:to_i)
  if b == 0
    if a == 0
      z += 1
    else
      st[0r][1] += 1
    end
  else
    rr = Rational(a,b)
    if rr >= 0 then st[rr][0] += 1
    else st[-1/rr][1] += 1
    end
  end
end
ans = 1
st.each do |key, val|
  ans *= 2.pow(val[0], MODC) + 2.pow(val[1], MODC) - 1
  ans %= MODC
end
ans += z - 1
ans %= MODC
p ans


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

int main(void)
{
  int n;
  cin >> n;
  double sum = 0;
  while(n--)
  {
    double x;
    cin >> x;
  	sum += ((double)1 / x);
  }
  sum = (double)1 / sum;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>

#include <map>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;



int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   map<int, int> freq;
   int N;
   cin >> N;
   REP(i, N) {
      int d;
      cin >> d;
      ++freq[d];
   }

   int M;
   cin >> M;
   REP(j, M) {
      int t;
      cin >> t;
      if (freq[t] == 0) {
         cout << "NO\n";
         return 0;
      }
      --freq[t];
   }

   cout << "YES\n";

   return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 998244353;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long double a;
  long double b;
  cin >> a >> b;
  long double ans = a * b;
  int x = ans;
  cout << x;
}

Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string Sd,T,S;
int slen,tlen;

int main(){
    cin>>Sd>>T;
    slen=Sd.size();
    tlen=T.size();
    
    vector<int> v;
    for(int i=0;i<slen-tlen+1;i++){
        int j=0;
        for(;j<tlen;j++){
           if(Sd[i+j]!='?' && Sd[i+j]!=T[j]) break;
        }
        if(j==tlen) v.push_back(i);
    }

    if(v.empty()){
        cout<<"UNRESTORABLE"<<endl;
    }else{
        int l=v.back();
        for(int i=0;i<l;i++){
            if(Sd[i]=='?'){
                cout<<'a';
            }else{
                cout<<Sd[i];
            }
        }
        cout<<T;
        for(int i=l+tlen;i<slen;i++){
            if(Sd[i]=='?'){
                cout<<'a';
            }else{
                cout<<Sd[i];
            }
        }
        cout<<endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b) cout << c << endl;
    else if(a == c) cout << b << endl;
    else if(b == c) cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;

#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll modinv(ll n)    { ll ans=powm(n,mod-2); return ans; }
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}


int main()
{
	fast
	ll n,x;
	cin>>n>>x;

	for(ll i=x-n+1;i<=x+n-1;i++)
		cout<<i<<" ";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
int n,m;
int xx[10]={1,0,-1,0},yy[10]={0,1,0,-1};
int x[20],y[20];
char a[1100][1100];
int b[1100][1100];
bool d[1100][1100];
int bfs(int f,int e)
{
	memset(b,0,sizeof(b));
	memset(d,false,sizeof(d));
	queue<p> q;
	q.push(p(x[f],y[f]));
	b[x[f]][y[f]]=0;
	d[x[f]][y[f]]=true;
	while(q.size())
	{
		p k=q.front();
		if(k.first==x[e]&&k.second==y[e])
		{
			return b[x[e]][y[e]];
		}
		q.pop();
		for(int i=0;i<4;i++)
		{
			int nx=k.first+xx[i];
			int ny=k.second+yy[i];
			if(!d[nx][ny]&&nx>=0&&nx<n&&ny>=0&&ny<m&&a[nx][ny]!='X')
			{
				q.push(p(nx,ny));
				b[nx][ny]=b[k.first][k.second]+1;
				d[nx][ny]=true;
			}
		}
	}
}
int main()
{
	int s;
	while(scanf("%d%d%d",&n,&m,&s)!=EOF)
	{
		getchar();
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				scanf("%c",&a[i][j]);
				if(a[i][j]=='S')
				{
					x[0]=i;
					y[0]=j;
					a[i][j]=i;
				}
				else if(a[i][j]>='1'&&a[i][j]<='9')
				{
					x[a[i][j]-'0']=i;
					y[a[i][j]-'0']=j;
					a[i][j]='.';
				}
			}
			getchar();
		}
		ll ss=0;
		for(int i=0;i<s;i++)
		{
			ss+=bfs(i,i+1);
		}
		cout<<ss<<endl;
	}
	return 0;
}
 


Measured memory_bytes: 10200
void main() {
	auto N = ri;
	auto V = readAs!(int[]);
	auto C = readAs!(int[]);
	int res = 0;
	foreach(i; 0..N) {
		if(V[i] - C[i] > 0) res += V[i] - C[i];
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/17/20 20:48:52
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll modpow(ll x, ll p) {
  ll u = x;
  ll t = 1;
  constexpr ll mod = 1e9+7;
  while (p) {
    if (p&1)
      (t *= u) %= mod;
    (u *= u) %= mod;
    p>>=1;
  }
  return t;
}

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

  int n; cin>>n;
  vector<int> A(n); for (auto& a:A) cin>>a;
  vector<int> cnt(n+1);
  for (auto a:A)
    cnt[a]++;
  bool ok = true;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (i%2==1) {
        ok &= cnt[i]==2;
      } else {
        ok &= cnt[i] == 0;
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i == 0) {
        ok &= cnt[i] == 1;
      } else if (i%2==0) {
        ok &= cnt[i]==2;
      } else {
        ok &= cnt[i] == 0;
      }
    }
  }
  if (!ok) {
    cout << 0 << endl;
  } else {
    ll ans = modpow(2, n/2);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
using namespace std;

int main() {
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		double x1, y1, x2, y2, x3, y3, x4, y4;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		double x5 = x2 - x1, y5 = y2 - y1, x6 = x4 - x3, y6 = y4 - y3;
		if (x5 == 0 && x6 == 0 || y5 == 0 && y6 == 0) {
			puts("YES");
		}
		else if (x5 == 0 || x6 == 0 || y5 == 0 || y6 == 0) {
			puts("NO");
		}
		else {
			if (abs(x6 / y6 - x5 / y5) <= 0.0000001)puts("YES");
			else puts("NO");
		}
	}
}

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

int main() {
	vector<int> v;
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		int h, m;
		cin >> h >> m;
		v.push_back(h*60+m);
	}

	int k;
	cin >> k;
	for ( int i = 0; i < k; i++ ) {
		int h, m;
		cin >> h >> m;
		v.push_back(h*60+m);
	}

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

	int pre = -1;
	for ( int i = 0; i < n+k; i++ ) {
		if ( pre == v[i] ) continue;
		if ( i ) cout << " ";
		cout << v[i]/60 << ':';
		printf("%02d", v[i]%60);
		pre = v[i];
	}
	cout << endl;
	
}


						



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

int main() {
  int N,d0,d1,d2,d3;
  cin >> N ;
  
  d3 = N / 1000;
  d2 = (N - d3*1000) / 100;
  d1 = (N - d3*1000 - d2*100) / 10;
  d0 = N % 10;
    
  if( d3 == d2 && d2 == d1
    ||d2 == d1 && d1 == d0
    )
  {cout << "Yes"<<endl;}
  
  else cout << "No" << endl;
      
}

Measured memory_bytes: 256
import math
S = input()
a = [0]*len(S)
lenprev = len(S)
idx=0
while len(S)>0:
  S = S.lstrip("R")
  c = lenprev-len(S)
  idx += c
  a[idx-1] += math.ceil(c/2)
  a[idx+1-1] += c//2
  lenprev=len(S)
  
  S=S.lstrip("L")
  c=lenprev-len(S)
  a[idx] += math.ceil(c/2)
  a[idx-1] += c//2
  idx+=c
  lenprev=len(S)
print(*a)
  

Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;
    
    return 0;
}

Measured memory_bytes: 3540
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;

/// Info.
///****************************************************************************************************************************************///
/// author                : BAHAA El-DEEN OSAMA .
/// Problem name          : K - Minor Change
/// Method                : brute force
/// Online judge          : vjudge(Contest)
/// Date                  : 8/6/2020
///****************************************************************************************************************************************///



string s1,s2;
int cnt=0;

int main()
{
    cin>>s1>>s2;
    for(int i=0;i<s1.length();++i)
    {
        if(s1[i]!=s2[i])
        {
            ++cnt;
        }
    }
    cout <<cnt<<endl;




return 0;
}


Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 1e9 + 7;

char s[100005];
long long dp[100005][13];

int main() {
    int n, d;
    cin >> n >> d;
    int ans = (int)ceil((double)n / (double)((d * 2) +1));
    cout << ans;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <iostream>
typedef long long ll;
using namespace std;
const int maxn=300100;
int ai[maxn];
int n;

bool check(int l,int r){
    int minx=n+10,maxx=0;
    for(int i=l;i<=r;i++){
        minx=min(minx,ai[i]);
        maxx=max(maxx,ai[i]);
    }
    if(minx<l||maxx>r) return true;
    int x1=0,x2=0;
    for(int i=l;i<=r;i++){
        if(ai[i]!=i){
            if(ai[i]>i){
                if(x1<ai[i]) x1=ai[i];
                else return true;
            }else{
                if(x2<ai[i]) x2=ai[i];
                else return true;
            }
        }
    }
    return false;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&ai[i]);
    for(int i=1;i<=n;i++){
        if(ai[i]!=i){
            int x;
            for(x=i;ai[x+1]==x+1&&ai[x+2]!=x+2;){
                x+=2;
            }
            x=min(x,n);
            //cout<<i<<"   "<<x<<endl;
            if(check(i,x)) return puts("No"),0;
            i=x;
        }
    }
    puts("Yes");
    return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cout << fixed << setprecision(6);
	ld l;
	cin >> l;
	cout << pow(l/3, 3) << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

//Earth Invasion Diary of Miyabi-sensei
public class Main{

	int f(int n){
		return n<=1?0:(n%3==0?f(n/3):f(n/3+1))+1;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		System.out.println(f(sc.nextInt()));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

const ll A = 1000005;




int main(){
  ll n;cin >> n;
  vector<ll> a(n);
  vector<ll> c(A);
  rep(i,n){
    cin >> a.at(i);
    c.at(a.at(i))++;
  }
  bool pairwise = true;
  for(ll i=2;i<A;++i){
    ll cnt = 0;
    for(ll j=i;j<A;j+=i)
      cnt += c.at(j);
    if( cnt > 1 ) pairwise = false;
  }

  if( pairwise ){
    cout << "pairwise coprime" << endl;
    return 0;
  }

  ll g = 0;
  rep(i,n) g = __gcd(g,a.at(i));
  if( g == 1 )
    cout << "setwise coprime" << endl;
  else
    cout << "not coprime" << endl;
  return 0;
}

Measured memory_bytes: 18780
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define fast       ios_base::sync_with_stdio(false); cin.tie(NULL);

int main (){
    ll n,m,count=0;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll x;
        cin>>x;
        count=count+x;
    }
    ll y= n-count;
    if(y<0){
        cout<<-1<<"\n";
    }
    else{
        cout<<y<<"\n";
    }
}

Measured memory_bytes: 3596
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};

struct Scanner<R: Read> {
    reader: R,
    buffer: String,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader, buffer: String::new() }
    }

    // fn line(&mut self) -> String {
    //     self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
    //         .skip_while(|&c| c == '\n' || c == '\r')
    //         .take_while(|&c| !(c == '\n' || c == '\r'))
    //         .collect::<String>();
    //     self.buffer.clone()
    // }

    fn read_buffer(&mut self) {
        self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        self.read_buffer();
        if self.buffer.is_empty() {
            None
        } else {
            self.buffer.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            // writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn counting_sort(a: &Vec<usize>) -> Vec<usize> {
    let mut cnt = vec![0; 10001];
    for &x in a.iter() {
        cnt[x] += 1;
    }
    for i in 1..cnt.len() {
        cnt[i] += cnt[i-1];
    }
    let mut res = vec![0; a.len()];
    for &x in a.iter().rev() {
        res[cnt[x] - 1] = x;
        cnt[x] -= 1;
    }
    res
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n: usize = sc.read();
        let a = sc.vec(n);
        let b = counting_sort(&a);
        println!("{}", b.iter().join(" "))
    }
}



Measured memory_bytes: 113536
#  --*-coding:utf-8-*--

def f(str):
    numOfX = 0
    numOfXs = []
    letters = []
    
    for c in str:
        if c == 'x':
            numOfX += 1
        else:
            letters.append(c)
            numOfXs.append(numOfX)
            numOfX = 0
            
    numOfXs.append(numOfX)

    for i in range(len(letters)//2):
        if letters[i] != letters[-i-1]:
            return -1

    a = 0
    for i in range(len(numOfXs)//2):
        a += abs(numOfXs[i] - numOfXs[-i-1])
            
    return a

def test():
    assert f('xabxa') == 2
    assert f('ab') == -1
    assert f('a') == 0
    assert f('oxxx') == 3


def main():
    str = input()
    print(f(str))

if __name__ == '__main__':
    main()



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

int a[200005];
int b[200005];

int main()
{
    int i, j, n, v, ck=0, sum=0;

    cin>>n;

    for(i=0; i<n-1; i++){
        cin>>a[i];
        v = a[i];
        b[v]++;
    }

    for(i=1; i<=n; i++)
    {
        cout<<b[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b;
  cin >> a >> b;
  if(a<=8 && b<=8) cout << "Yay!" <<endl;
  else cout << ":(" <<endl;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int n;
    cin >> n;
    int x = digsum(n);

    if(n%x==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N){
        cin >> a[i];
    }

    int count = 1;
    bool fail = false;
    int ans;
    rep(i,N){
        if(a[i] == count){
            count++;
            fail = true;
        }
    }
    ans = a.size() + 1 - count;
    if(!fail) ans = -1;

    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

int main()
{
  string S;
  cin>>S;
  vector<int64_t> s(S.size());
  for (int i = 0; i < S.size(); ++i)
  {
    s[i]=(S[i]-'0');
  }
  
  int64_t ans=0;
  for (int i = 0; i < (1<<s.size()-1); ++i)
  {
    std::vector<int64_t> tmp;
    int64_t cnt=s[0];
    for (int j = 0; j < s.size()-1; ++j)
    {
      if((i>>j)&1==1){
        tmp.emplace_back(cnt);
        cnt=s[j+1];
      }
      else {
        cnt*=10;
        cnt+=s[j+1];
      }
    }
    tmp.emplace_back(cnt);
    ans+=accumulate(tmp.begin(), tmp.end(),0L);
  }

  cout<<ans;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        int A = int.Parse(s[1]);
        int B = int.Parse(s[2]);
        Console.WriteLine(Math.Min(N * A, B));
    }
}


Measured memory_bytes: 11092
import itertools


n, m, q = map(int, input().split())
queries = [list(map(int, input().split())) for _ in range(q)]
ans = 0

nums = list(range(1, m+1))
seqs = list(itertools.combinations_with_replacement(nums, n))

for seq in seqs:
    point = 0
    for query in queries:
        a, b, c, d = query
        if seq[b-1] - seq[a-1] == c:
            point += d
    if point > ans:
        ans = point

print(ans)


Measured memory_bytes: 21600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<vector>
#include<string>
#define reep(a,s,d) for(int a=d;a<s;a++)
#define rep(a,s) reep(a,s,0)
using namespace std;
struct edge{
    int to,cost,tick;
    edge(int to,int cost,int tick):to(to),cost(cost),tick(tick){}
    edge(){}
};
bool operator<(const edge &a,const edge &b){
    return a.cost>b.cost;
}
int main(){
    int c,n,m,s,d;
    while(cin>>c>>n>>m>>s>>d,c){
        vector<edge> G[128];
        rep(i,m){
            int a,b,c;
            cin>>a>>b>>c;
            G[--a].push_back(edge(--b,c,0));
            G[b].push_back(edge(a,c,0));
        }
        bool vis[16][128];
        memset(vis,false,sizeof(vis));
        priority_queue<edge> Q;
        Q.push(edge(s-1,0,0));
        int ret=-1;
        while(!Q.empty()){
            edge n=Q.top();Q.pop();
            if(vis[n.tick][n.to])continue;
            vis[n.tick][n.to]=true;
            if(n.to==d-1){
                ret=n.cost;
                break;
            }
            rep(i,G[n.to].size()){
                Q.push(edge(G[n.to][i].to,n.cost+G[n.to][i].cost,n.tick));
                if(n.tick<c){
                    Q.push(edge(G[n.to][i].to,n.cost+G[n.to][i].cost/2,n.tick+1));
                }
            }
        }
        cout<<ret<<endl;
    }
}

Measured memory_bytes: 1316
#include<iostream>
#include<functional>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
using namespace std;

int main()
{
    string s;
    cin>>s;
    char p=s[0];
    int count=0;
    for(int i=1;i<s.length();i++)
    {
        if(p!=s[i])
        {
            count++;
        }
        p=s[i];
    }
    cout<<count;
}

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

int main(){
  long s,c,kekka = 0;
  cin >> s >> c;
  if(2*s < c){
    c -= 2*s;
    kekka = s + c/4;
  }
  else{
    kekka = c/2;
  }
  cout << kekka << endl;
} 

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

using namespace std;

static long long ans = 0;

static vector<bool> renew_used (vector<bool> used, int n) {
    if ( n == 3 ) {
        used.at(0) = true;
        return used;
    }
    else if ( n == 5 ) {
        used.at(1) = true;
        return used;
    }
    else if ( n == 7 ) {
        used.at(2) = true;
        return used;
    }
    assert(false);
    return used;
}

static bool is_all_used (vector<bool> &used) {
    return used.at(0) && used.at(1) && used.at(2);
}

static void calc_n_753 (long long N, long long n, vector<bool> used) {
    if ( n > N )
        return;
    if ( is_all_used(used) ) {
        ans++;
    }
    for ( int i = 3; i <= 7; i += 2 ) {
        calc_n_753(N, 10 * n + i, renew_used(used, i));
    }
    return;
}

int main (void) {
    long long N;
    cin >> N;

    vector<bool> used(3, false);

    for ( int i = 3; i <= 7; i += 2 ) {
        calc_n_753(N, i, renew_used(used, i));
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

ll modexp(ll x, ll n)
{
    if(n==0)
        return 1LL;
    if(n%2==0)
    {
        ll y = modexp(x,n/2)%mod;
        return (y*y)%mod;
    }
    return (x*modexp(x,n-1)%mod)%mod;
}

ll powr(ll x, ll n)
{
    ll ans = 1;
    for(int i=1;i<=n;i++)
        ans=ans*x;
    return ans;
}

int main()
{
    int n,k,q;
    si(n),si(k),si(q);
    int a[n];
    for(int i=0;i<n;i++)
        a[i] = 0;
    for(int i=0;i<q;i++)
    {
        int x;
        si(x);
        a[x-1]++;
    }
    for(int i=0;i<n;i++)
    {
        a[i] = k - (q-a[i]); 
        if(a[i]<=0)
            pf("No\n");
        else
            pf("Yes\n");
    }

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

    int N;
    cin >> N;
    string S;
    cin >> S;
    int l_sum = 0, r_sum = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '(') {
            l_sum++;
        }
        else if (l_sum > 0)
            l_sum--;
        else r_sum++;
    }


    if (r_sum > 0) {
        string temp(r_sum , '(');
        S = temp + S;
    }
    if (l_sum > 0) {
        string temp(l_sum , ')');
        S += temp;
    }
    
    cout << S << '\n';

}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 123456789123456789;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<long long> S(N + 1);
	for (int i = 0; i < N; ++i) {
		S[i + 1] = S[i] + A[i];
	}
	vector<vector<long long> > dp(N + 1);
	dp[1] = vector<long long>(N, 0);
	for (int i = 2; i <= N; ++i) {
		dp[i] = vector<long long>(N - i + 1, inf);
		for (int j = 0; j <= N - i; ++j) {
			for (int k = j + 1; k < j + i; ++k) {
				dp[i][j] = min(dp[i][j], dp[k - j][j] + dp[i - (k - j)][k] + S[j + i] - S[j]);
			}
		}
	}
	cout << dp[N][0] << '\n';
	return 0;
}

Measured memory_bytes: 896