akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	NAB := sc.nextInts()
	N := NAB[0]
	A := NAB[1]
	B := NAB[2]

	times := N / (A + B)
	tmpBlue := times * A

	redis := N % (A + B)
	var tmpBlue2 int
	if redis >= A {
		tmpBlue2 = A
	} else {
		tmpBlue2 = redis
	}
	fmt.Println(tmpBlue + tmpBlue2)
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


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

def solve():
    N = int(input())
    Xs = list(map(int, input().split()))

    avg1 = sum(Xs)//N
    avg2 = avg1+1

    ans1 = 0
    ans2 = 0
    for x in Xs:
        ans1 += (x-avg1)**2
        ans2 += (x-avg2)**2
    print(min(ans1, ans2))


if __name__ == "__main__":
    solve()


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

using namespace std;

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

  int n;
  string s;
  cin >> n >> s;

  int res = 0;
  vector<int> count(26, 0);
  for (auto &ss : s) count[ss-'a']++;
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    set<char> hash;
    for (int j = 0; j < i; ++j) {
      if (hash.find(s[j]) != hash.end()) 
        continue;
      hash.insert(s[j]);
      if (count[s[j]-'a'] > 0) 
        ++cnt;
    }
    count[s[i]-'a']--;
    if (cnt > res) 
      res = cnt;
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){


    string S;
    int N;
    
    cin >> N;
    cin >> S;

    char target;

    int tar;
    for( int si = 0 ; si <S.length() ; si++ ){
        tar = (int)S[si];
        tar = ( (tar+N-65) % 26 );
        printf("%c",'A'+tar);

    }
    


}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

vint seg;
int n, q, n0;

// segment tree
// let n = 5
// A = [1,2,3,4,5]
// then the seg tree looks like:
//        15
//    10,     5
//  3,  7,  5,  0
// 1,2,3,4,5,0,0,0
// with indices
//          1
//    2,          3
//  4,   5,    6,    7
// 8,9,10,11,12,13,14,15
// thus, you can go one layer up by dividing by 2 (floor)
// update is easy since you just update the bottom and move up
// accumulation is also easy:
// for [l,r), we will look at l and r separately.
// l: if (l%2 == 1), then you look at seg[l] and l++.
// after, l/=2 to go up a layer
// this means you are at the level of detail that has the best scale always
// since you need to look at that layer and no shallower (since info from seg[l-1] will be in seg[l/2])
// r: if (r%2 == 1), then look at seg[r-1] and r--.
// after, r/=2 to go up a layer.
// similar to l, if r is odd, then r/=2 will include information from seg[r].
// we don't want this since we are querying r exclusive.
// once l >= r we've accumulated everything we need.

void add(int i, int x)
{
    int k = i + n;
    seg[k] += x;
    while (k)
    {
        k /= 2;
        if (!k)
            break;
        seg[k] = seg[k * 2] + seg[k * 2 + 1];
    }
}

// s inclusive t exclusive
int getSum(int s, int t)
{
    int l = s + n,
        r = t + n;
    ll sum = 0;
    while (l < r)
    {
        if (l % 2)
        {
            sum += seg[l];
            l++;
        }
        l /= 2;
        if (r % 2)
        {
            sum += seg[r - 1];
            r--;
        }
        r /= 2;
    }
    return sum;
}

int main()
{
    cin >> n >> q;
    int size = 1 << (int)(log2(n) + 1);
    seg = vint(2 * size + 1, 0);

    rep(i, q)
    {
        int com, x, y;
        cin >> com >> x >> y;
        if (com)
        {
            int ans = getSum(x, y + 1);
            cout << ans << "\n";
        }
        else
        {
            add(x, y);
        }
    }

    return 0;
}


Measured memory_bytes: 4084
from heapq import heappush, heappop
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
x = sum(A)
ls = []
for i in range(1, int(x**0.5)+1):
  if x%i==0:
    ls += [i]
    if i != x//i:
      ls += [x//i]
ls.sort(reverse=True)
for i in ls:
  B =[]
  for j in A:
    heappush(B, -1*(j%i))
  y = sum(B)
  while y<0:
    u = heappop(B)
    u += i
    heappush(B,u)
    y += i
  m = 0
  for j in B:
    if j>0:
      m += j
  if m>K:
    continue
  else:
    print(i)
    break

Measured memory_bytes: 48604
#include<iostream>
#include<string>
using namespace std;
int main()
{

	while (1) {
		string s;
		int m;

		cin >> s;
		if (s.size() == 1 && s[0] == '-') break;
		cin >> m;
		
		int ch;

		for (int i = 0; i < m; i++) {
			cin >> ch;

			string s1 = s.substr(0, ch);
			string s2 = s.substr(ch, s.size());

			s = s2 + s1;
		}
		cout << s <<endl;
	}
	return 0;
}


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


int main(){
	int a,l,r,iwa=0;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>l;
		cin>>r;
		iwa+=(r-l+1);
	}
	cout<<iwa<<endl;
}


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

int main(){
    string s;
    cin>>s;
    int a,z;
    int t=s.size();
    for(int i=0;i<s.size();i++){
        if(s.at(t-1-i)=='A'){
            a=t-i;
            }
        if(s.at(i)=='Z'){
            z=i;
            }
        }
    cout<<z-a+2<<endl;
}


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

int H,W;
short fid[110][110] = {0};
short dp[110][110][110][110] = {0};
int x,y;

short sum(int y1,int x1,int y2,int x2)
{
    if(y1 > y2 || x1 > x2)return 0;
    return fid[y1 - 1][x1 - 1] - fid[y1 - 1][x2] - fid[y2][x1 - 1] + fid[y2][x2];
}

int main()
{
    scanf("%d%d",&H,&W);
    for(int i = 1; i <= H; i++)for(int j = 1; j <= W; j++)
    {
        char c;
        scanf(" %c",&c);
        if(c == 'o')fid[i][j] = 1;
        if(c == 'E')x = j,y = i;
    }

    for(int i = 1; i <= H; i++)for(int j = 1; j <= W; j++)fid[i][j] += fid[i - 1][j];
    for(int i = 1; i <= H; i++)for(int j = 1; j <= W; j++)fid[i][j] += fid[i][j - 1];

    for(int i = 0; i < y; i++)
    {
        for(int j = 0; j <= H - y; j++)
        {
            for(int k = 0; k < x; k++)
            {
                for(int l = 0; l <= W - x; l++)
                {
                    if(i + j + k + l == 0)continue;
                    if(i)
                    {
                        dp[i][j][k][l] = max(dp[i][j][k][l],
                        (short)(dp[i - 1][j][k][l] + sum(max(y - i,j + 1),max(x - k,l + 1),y - i,min(x + l,W - k))));
                    }
                    if(j)
                    {
                        dp[i][j][k][l] = max(dp[i][j][k][l],
                        (short)(dp[i][j - 1][k][l] + sum(y + j,max(x - k,l + 1),min(y + j,H - i),min(x + l,W - k))));
                    }
                    if(k)
                    {
                        dp[i][j][k][l] = max(dp[i][j][k][l],
                        (short)(dp[i][j][k - 1][l] + sum(max(y - i,j + 1),max(x - k,l + 1),min(y + j,H - i),x - k)));
                    }
                    if(l)
                    {
                        dp[i][j][k][l] = max(dp[i][j][k][l],
                        (short)(dp[i][j][k][l - 1] + sum(max(y - i,j + 1),x + l,min(y + j,H - i),min(x + l,W - k))));
                    }
                }
            }
        }
    }
    printf("%d\n",dp[y - 1][H - y][x - 1][W - x]);
    return 0;
}


Measured memory_bytes: 203136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n;
  cin >> n;
  if (n % 2 != 0) {
    cout << 0 << endl;
  } else {
    ll ans = 0;
    ll t = 5;
    while (t < n) {
      ans += n / (t*2);
      t *= 5;
    }

    cout << ans << endl;
  }
}

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

#define INF 0
#define SIZE 105

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

int c[SIZE];
bool loop[SIZE],tloop[SIZE];

bool relax_lim(int u, int v, int w, int l)
{
	int up=c[u]+w;
	if(up < l) up=l;
	if(c[v]>=up)
	{
		c[v]=up;
		return true;
	}
	
	return false;
}

class Edge
{
public:
	int s,d,c;
	Edge(){}
	Edge(int s,int d,int c)
	:s(s),d(d),c(c)
	{}
};

bool bellman_ford(vector<Edge>& g, int N, int s,int d,int MHP)
{
	REP(i,N) 
	{
		c[i]=(loop[i]?-MHP:c[i]);
	}
	
	memset(tloop,0,sizeof(tloop));
	
	c[s]=-MHP;
	
	REP(i,N-1) REP(j,g.size())
	{
		
		if(g[j].s==d) continue;
		if(g[j].d==d) continue;
		if(c[g[j].s]>=INF) continue;
		
		
		relax_lim(g[j].s,g[j].d,-g[j].c,-MHP);
	}
	bool ret=true;
	REP(j,g.size())
	{
		if(g[j].s==d) continue;
		if(g[j].d==d) continue;
		if(c[g[j].s]>=INF) continue;
		
		if(relax_lim(g[j].s,g[j].d,-g[j].c,-MHP)) 
		{
			if(-g[j].c < 0)
			{
				tloop[g[j].d]=1;
			}
		}
	}
	
	
	for(int i=0; i<N; i++)
	{
		if(tloop[i]!=loop[i])
		{
			ret=false;
			loop[i]=tloop[i];
		}
	}
	
	return ret;
}

int calc(vector<Edge>& g, int N, int s, int d, int MHP)
{
	REP(i,N) c[i]=(loop[i]?-MHP:INF);
	
	c[s]=-MHP;
	
	REP(i,N-1) REP(j,g.size())
	{
		if(g[j].s==d) continue;
		if(loop[g[j].d]) continue;
		if(c[g[j].s]>=INF) continue;
		relax_lim(g[j].s,g[j].d,-g[j].c,-MHP);
	}
	
	return -c[d];
}

int main()
{
	int N,M,C=1;
	while(cin >> N >> M, (N||M))
	{
		memset(c,0,sizeof(c));
		memset(loop,0,sizeof(loop));
		
		vector<Edge> g(M);
		for(int i=0; i<M; i++)
		{
			int s,d,c;
			cin >> s >> d >> c;
			g[i]=Edge(s,d,c);
		}
		
		int S,D,H;
		cin >> S >> D >> H;
		
		while(!bellman_ford(g,N,S,D,H));
		
		int ret=calc(g,N,S,D,H);
		
		cout << "Case " << C++ << ": ";
		if(ret<=INF) cout << "GAME OVER" << endl;
		else cout << ret << endl;
	}
}

Measured memory_bytes: 928
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
//#include <bits/stdc++.h>//atcoderでsqrtを使うときに必要
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

void solve() {
	ll n,res;
	res = 0;
	cin >> n;

	if (n >= 500) {
		res += n / 500 * 1000;
		n = n % 500;
	}

	if (n >= 5) {
		res += n / 5 * 5;
		n = n % 5;
	}

	ce(res);
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	char a[N + 1];
  char b[N+1];
	f(i, N+1){
a[i] = 0;
      b[i]=0;
    }
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%s", a);
	scanf("%s", b);
	f(i,3){
if(a[i]==b[i])ans++;
	}

	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <map>

const int N = 100001;

using LL = long long;

int m;
LL a[N];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("E.in", "r", stdin);
#endif
    scanf("%d%d", a, &m);
    for (int i = 1; i <= m; ++ i) {
        scanf("%lld", a + i);
    }
    std::map<LL, LL> cnt;
    cnt[a[m]] = 1;
    for (int i = m - 1; i >= 0; -- i) {
        auto it = cnt.upper_bound(a[i]);
        while (it != cnt.end()) {
            auto len = it->first;
            cnt[a[i]] += it->second * (len / a[i]);
            if (len % a[i]) {
                cnt[len % a[i]] += it->second;
            }
            auto backup = it;
            it ++;
            cnt.erase(backup);
        }
    }
    LL res = 0;
    for (auto it : cnt) {
        res += it.second;
    }
    auto it = cnt.begin();
    for (int i = 1; i <= a[0]; ++ i) {
        while (it != cnt.end() && it->first < i) {
            res -= it->second;
            it ++;
        }
        printf("%lld\n", res);
    }
}



Measured memory_bytes: 8576
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll cnt[200005];
int main(){
	ll n; cin >> n;
	for (ll i = 0; i < n - 1; i++){
		ll ip; cin >> ip; cnt[ip]++;
	}
	for (ll i = 1; i <= n; i++) cout << cnt[i] << endl;
}

Measured memory_bytes: 5152
#include<iostream>
using namespace std;
int main(){
    while(1){
        int Daikin = 0;
        int Book[9] = {0};
        cin >> Daikin;
        if(Daikin == 0){
            break;
        }
        for(int i = 0;i < 9;i++){
            cin >> Book[i];
            Daikin-=Book[i];
        }
        cout << Daikin << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=1e5+500;
const ll inf=1e9+800;
const ll mod=1e9+7;

ll x[maxn];

ll b[maxn];
ll c[maxn];

ll a[maxn];
ll p[maxn];
ll ans[maxn];
bool vis[maxn];
vector<ll> vec;

void dfs(ll a){
	vis[a]=1;
	vec.pb(a);
	if(vis[p[a]])return ;
	dfs(p[a]);
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>x[i];
	}
	ll m,k,firs;
	firs=x[1];
	cin>>m>>k;
	for(ll i=0;i<m;i++){
		cin>>a[i];
	}
	for(ll i=1;i<n;i++){
		b[i]=x[i+1]-x[i];
		p[i]=i;
	}

	for(ll i=0;i<m;i++){
		swap(p[a[i]],p[a[i]-1]);
	}
	for(ll i=1;i<n;i++){
		if(!vis[i]){
			vec.clear();
			dfs(i);
			ll m=vec.size();
			for(ll j=0;j<m;j++){
				c[vec[j]]=b[vec[(j+k)%m]];
			}
		}
	}

	ans[1]=firs;
	for(ll i=2;i<=n;i++){
		ans[i]=ans[i-1]+c[i-1];
	}
	for(ll i=1;i<=n;i++){
		cout<<ans[i]<<'\n';
	}
}




















Measured memory_bytes: 10100
N,M = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
mark = [-1]*N
INF = float('inf')
dist = [-1] * N

mark[0] = 0
from collections import deque
q = deque()
q.append((0,0))

while q:
    v,pv = q.popleft()
    # print(v,pv)
    if dist[v] == -1: # hajimete
        dist[v] = dist[pv] + 1
        mark[v] = pv
        for nv in G[v]:
            q.append((nv,v))
    # print(dist)
    # print(mark)

print('Yes')
for i in range(1,N):
    print(mark[i] + 1)





Measured memory_bytes: 107964
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ll long long
const int maxi=2000000000;
const int maxq=1000000000;
const ll mod=1000000007LL;
#define f(i,a,b) for(ll  i=(a); i<(b);++i)
/*
unsigned int countSetBits(unsigned int n)
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
*/

/*
const int maxx=9000000;
void SieveOfEratosthenes(vector<int> &primes){
    bool IsPrime[maxx+1];
    memset(IsPrime, true, sizeof(IsPrime));
    for(int p=2;p*p<=maxx ;p++){
        if(IsPrime[p]){
            for(int i=p*p;i<maxx ;i+=p) IsPrime[i]=false;
        }
    }
    f(p,2,maxx +1){
        if(IsPrime[p]) primes.push_back(p);
    }
    }
*/
//int b[100];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*ll n,sum=0;
    cin>>n;
    ll a[n];
    f(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll x;
    cin>>x;
    while(x--){
        ll c,d;
        cin>>c>>d;
        f(i,0,n){
        if(a[i]==c){
            a[i]=d;
            sum=sum+d-c;
        }

        } cout<<sum<<endl;
    } */

    ll a;
    cin>>a;
    string s;
    while(a){
        a--;
        s+='a'+(a%26);
        a/=26;
    }
    reverse(s.begin(),s.end());
    cout<<s;
    return 0;
}




Measured memory_bytes: 3624
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7




def main():
    # r = int(input())
    # print(r*r)
    n = int(input())
    s = input()
    if n % 2 == 1:
        print("No")
        exit()
    for i in range(n//2):
        if s[i] != s[i + n//2]:
            print("No")
            exit()
    print("Yes")
        




            
            
            
            
            
        


if __name__ == '__main__':
    main()


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

int main(){
    int a,b,c; cin >> a >> b >> c;
    int sum = a + b + c;
    int ideal = sum;
    int parity = sum%2;
    while(ideal%3 != 0 || ideal/3 < max(a,max(b,c)) || ideal%2 != parity) ++ideal;
    cout << (ideal-sum)/2 << endl; return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#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<double,double>pdd;
#define int ll
signed main(){
    int n,a,b;cin>>n>>a>>b;
    if(a>b)return puts("0")*0;
    if(n==1&&a!=b)return puts("0")*0;
    cout<<b*(n-1)+a-(a*(n-1)+b)+1<<endl;
}

Measured memory_bytes: 256
let ($) f x = f x

type pos = {x:int; y:int}

exception No_more_candidate

let load () =
  let n = int_of_string (read_line ()) in
  let positions = Array.make n {x = 0; y = 0} in
  for i = 0 to (n - 1) do
    positions.(i) <-
      Scanf.sscanf (read_line ()) "%d %d" (fun x y -> {x=x; y=y})
  done;
  positions

let closest_dist positions =
  let len = Array.length positions in
  let closest_result = ref max_int in
  let closest_length = ref max_int in
  for i = 0 to (len - 1) do
    let pos = positions.(i) in
    try (
      for j = i + 1 to (len - 1) do
        let another_pos = positions.(j) in
        if another_pos.x - pos.x < !closest_length then (
          let result =
            (another_pos.x - pos.x) * (another_pos.x - pos.x) +
            (another_pos.y - pos.y) * (another_pos.y - pos.y) in
          if result < !closest_result then (
            closest_result := result;
            closest_length := int_of_float (sqrt $ float_of_int result)
          )
        )
        else
          raise No_more_candidate
      done
    ) with No_more_candidate -> ();
  done;
  !closest_result

let work_for_strip = Array.make 500000 {x=0; y=0}

let rec traverse positions =
  let len = Array.length positions in
  if len <= 1 then
    max_int
  else
    let mid = len / 2 in
    let mid_pos = positions.(mid) in
    let left_side = Array.sub positions 0 mid in
    let right_side = Array.sub positions (mid + 1) (len - (mid + 1)) in
    let dl = traverse left_side in
    let dr = traverse right_side in
    let d_both = min dl dr in
    let idx_of_strip = ref 0 in
    ignore (try (
      for i = 0 to (len - 1) do
        let pos = positions.(i) in
        if abs $ pos.x - mid_pos.x < d_both then (
          work_for_strip.(!idx_of_strip) <- pos;
          idx_of_strip := !idx_of_strip + 1;
        )
        else (
          if pos.x > mid_pos.x then
            raise No_more_candidate
        )
      done
    ) with No_more_candidate -> ());
    let d_strip = closest_dist $ Array.sub work_for_strip 0 (!idx_of_strip - 1) in
    min d_both d_strip

let () =
  let positions = load () in
  Array.sort (fun a b -> a.x - b.x) positions;
  print_int $ traverse positions;
  print_newline ()




Measured memory_bytes: 57432
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int L,R;
int dp[61][2][2][2];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>L>>R;
    dp[60][0][0][0]=1;
    for(int i=59;i>=0;i--){
        rep(j,2){
            rep(k,2){
                rep(l,2){
                    //from:dp[i+1][j][k][l]
                        
                    //0,0
                    if(k||!((L>>i)&1)){
                        dp[i][j][k][l||((R>>i)&1)]+=dp[i+1][j][k][l];
                        dp[i][j][k][l||((R>>i)&1)]%=mod;
                    }
                    //1,1
                    if(l||((R>>i)&1)){
                        dp[i][1][k||!((L>>i)&1)][l]+=dp[i+1][j][k][l];
                        dp[i][1][k||!((L>>i)&1)][l]%=mod;
                    }
                    //1,0
                    if(j==0)continue;
                    if( (l||((R>>i)&1)) && (k||!((L>>i)&1))){
                        dp[i][j][k][l]+=dp[i+1][j][k][l];
                        dp[i][j][k][l]%=mod;
                    }
                }
            }
        }
    }
    int ans=0;
    rep(i,2){
        rep(j,2){
            rep(k,2){
                ans+=dp[0][i][j][k];
                ans%=mod;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3660
//package  com.company;


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int x=sc.nextInt();
        int t=sc.nextInt();
        sc.close();
        int ans=n/x;
        if(n%x>0)ans++;
        System.out.println(ans*t);
        
    }
}

Measured memory_bytes: 27076
#include <bits/stdc++.h>
using namespace std;
string s,t;
bool eq(char a,char b){
	if(a>='A'&&a<='Z')a=a-'A'+'a';
	if(b>='A'&&b<='Z')b=b-'A'+'a';
	return a==b;
}
bool ok(){
	if(t.length()!=s.length())return 0;
	for(int i=0;i<=(int)(t.length()-s.length());i++){
		bool ok=1;
		for(int j=0;j<s.length();j++)
			if(!eq(s[j],t[i+j]))ok=0;
		if(ok)return 1;
	}
	return 0;
}
int main(){
	cin>>s;int k=0;
	while(1){
		cin>>t;if(t=="END_OF_TEXT")break;
		if(ok())k++;
	}cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 3196
#include<stdio.h>
#define MAX 1000
#define NIL -1

struct Node
{
	int parent, left, right;	
};

Node T[MAX];
int n;

void PreOrderTraverse(int u)
{
	if(u == NIL)
		return;
	printf(" %d", u);
	PreOrderTraverse(T[u].left);
	PreOrderTraverse(T[u].right);
}

void InOrderTraverse(int u)
{
	if(u == NIL)
		return;
	InOrderTraverse(T[u].left);
	printf(" %d", u);
	InOrderTraverse(T[u].right);
}

void PastOrderTraverse(int u)
{
	if(u == NIL)
		return;
	PastOrderTraverse(T[u].left);
	PastOrderTraverse(T[u].right);
	printf(" %d", u);
}
int main()
{
	int v, l, r, root;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		T[i].parent = NIL;
	for(int i = 0; i < n; i++)
	{
		scanf("%d%d%d", &v, &l, &r);
		T[v].left = l;
		T[v].right = r;
		if(l != NIL)
			T[l].parent = v;
		if(r != NIL)
			T[r].parent = v;
	}
	
	for(int i = 0; i < n; i++)
	{
		if(T[i].parent == NIL)
			root = i;	
	}
	printf("Preorder\n");
	PreOrderTraverse(root);
	putchar('\n');
	printf("Inorder\n");
	InOrderTraverse(root);
	putchar('\n');
	printf("Postorder\n");
	PastOrderTraverse(root);
	putchar('\n');
	
	return 0;
}



Measured memory_bytes: 2760
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <complex>
using namespace std;


int main() {
	int N, K;
	int A[200000];

	cin >> N >> K;
	map <int, int> mp;
	for (int n = 0; n < N; n++) {
		cin >> A[n];
		mp[A[n]]++;
	}

	int keep = 0;
	int i=0;
	int key_size = mp.size();

	vector<int> vec(key_size);

	
	for (auto m : mp) {
		vec[i] = m.second;
		i++;
	}
	sort(vec.rbegin(), vec.rend());
	K = min(K, key_size);
	for (int k = 0; k < K; k++) {
		keep += vec[k];
	}
	
		
	cout << N - keep << endl;
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

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

void solve_133A(){
    int n, a, b;
    cin >> n >> a >> b;

    int ans = a * n > b ? b : a * n;
    cout << ans << endl;
}

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

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextLong()
    val v = sc.nextLong()
    val b = sc.nextLong()
    val w = sc.nextLong()
    val t = sc.nextLong()
    println(problem2020b(a, v, b, w, t))
}

fun problem2020b(A: Long, V: Long, B: Long, W: Long, t: Long): String {
    val diff = Math.abs(A - B)
    val speed = V - W
    if (speed <= 0) return "NO"
    if(t * speed >= diff) return "YES"
    return "NO"
}


Measured memory_bytes: 36396
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: i64 = 1000000007;

fn main() {
    let n: usize = read();
    let s1: String = read();
    let s2: String = read();

    let sc1: Vec<char> = s1.chars().collect();
    let sc2: Vec<char> = s2.chars().collect();

    let mut a: Vec<i64> = vec![];

    let mut ci = 0;
    while ci < n {
        if sc1[ci] == sc2[ci] {
            a.push(1);
            ci += 1;
            continue;
        } else {
            a.push(2);
            ci += 2;
            continue;
        }
    }
    // println!("{:?}", a);

    let mut ans = 0;
    if a[0] == 1 {
        ans = 3;
    } else {
        ans = 6;
    }

    for i in 1..a.len() {
        // println!("ans{}", ans);
        let ai = a[i];
        let aip = a[i - 1];
        if ai == 1 && aip == 1 {
            ans *= 2;
        }
        if ai == 2 && aip == 2 {
            ans *= 3;
        }
        if ai == 2 && aip == 1 {
            ans *= 2;
        }
        ans %= MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, K, count;
  cin >> A >> B >> K;
  count = 0;
  
  for (int i = 100; i > 0; i--) {
    if (A % i == 0 && B % i == 0)
      count++;
    
    if (count == K) {
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
function main(input) {
    var nums = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));

    var count = 0;
    while(nums.every((n) => (n % 2) === 0)) {
        count++;
        nums = nums.map((n) => n / 2);
    }

    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

typedef long long int ll;
#define push_back pb
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;

int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	if(b < 0)return 0;
	int re = 1;
	while(b){
		if(b&1){
			re = mul(re, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return re;
}
int const N = 100000 + 5;
int fact[N], inverse[N];
void FAC(){
 	fact[0] = 1;
	for(int x = 1; x< N; x++){
		fact[x] = mul(fact[x-1], x);
	}
	inverse[N-1] = power(fact[N-1], mod -2);
	for(int x = N-2; x>= 0; x--){
		inverse[x] = mul(x + 1, inverse[x+1]);
	}

 }

int ncr(int a, int b){
	if(a < b)return 0;
	return mul(fact[a], mul(inverse[a-b], inverse[b]));
}

/******************************************************/
void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for(int x =0; x<s.length()-2; x++){
		if(s[x] == 'A' && s[x+1] == 'B' && s[x+2] == 'C')ans++;
	}
	cout << ans;
}


/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
int m,n,sum=1;
string s;
int main(){
	cin>>n>>m;
	cin>>s;
	for (int i=0;i<s.length()-1;i++)if (s[i]!=s[i+1])sum++;
	sum=max(1,sum-m*2);
	cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <algorithm>   //sort,二分探索,など
#include <bitset>      //固定長bit集合
#include <chrono>      //実行時間計測
#include <cmath>       //pow,logなど
#include <complex>     //複素数
#include <deque>       //両端アクセスのキュー
#include <functional>  //sortのgreater
#include <iomanip>     //setprecision(浮動小数点の出力の誤差)
#include <iostream>    //入出力
#include <iterator>    //集合演算(積集合,和集合,差集合など)
#include <map>         //map(辞書)
#include <numeric>     //iota(整数列の生成),gcdとlcm,accumulate
#include <queue>       //キュー
#include <set>         //集合（順序保持）
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair
#include <vector>  //可変長配列
using namespace std;
typedef long long ll;
typedef long double ld;

#define REP(i, n) for (int i = 0; i < ll(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < ll(b); i++)
#define FORD(i, a, b) for (int i = a; i > ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく
const long long INF = 1e12;
const int MOD = 1e9 + 7;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define Umap unordered_map
#define Uset unordered_set
#define int long long
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
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;
}

signed main() {

    int x, y;
    cin >> x >> y;

    bool can = false;
    REP(i, x + 1) {
        if (i * 2 + (x - i) * 4 == y) {
            can = true;
        }
    }
    if (can) {
        print("Yes");
    } else {
        print("No");
    }
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int k = 10001,N = 2000001;
int main(){
  int n;
  cin >> n;
  vector < int > A(N),B(N),C(k,0);
  for(int i = 1 ; i <= n ; i++ ) cin >> A[i];
  for(int j = 1 ; j <= n ; j++ ){
    C[A[j]] = C[A[j]] + 1;
  }
  for(int i = 1 ; i <= k ; i++ ){
    C[i] = C[i] + C[i-1];
  }
  for(int j = n ; j >= 1 ; j-- ){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]] - 1;
  }
  for(int i = 1 ; i <= n ; i++ ){
    cout << ( i == 1 ? "" : " " ) << B[i];
  }
  cout << endl;
}

Measured memory_bytes: 16856
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  lint n, m;
  cin >> n >> m;
  vector<int> a(m);
  REP(i,m) cin >> a[i];

  lint sum = 0;
  REP(i,m){
    sum += a[i];
  }
  lint res;
  if(sum > n) res = -1;
  else res = n-sum;

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 3696
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		//テストの成績を格納するリストを宣言
		List<String> grades = new ArrayList<String>();

		while(true){
			//各テストの変数を宣言と値を入力
			int point_middle = scan.nextInt();
			int point_end_term = scan.nextInt();
			int reTest = scan.nextInt();
			//中間と期末の合計点
			int point_total = point_middle + point_end_term;

			if(point_middle == -1 && point_end_term == -1 &&reTest == -1){
				break;
			}

			if(point_middle == -1 || point_end_term == -1){
				grades.add("F");
			}else if(80 <= point_total){
				grades.add("A");
			}else if(65 <= point_total && point_total < 80 ){
				grades.add("B");
			}else if(50 <= point_total && point_total < 65 || 50<=reTest){
				grades.add("C");
			}else if(30 <= point_total && point_total < 50){
				grades.add("D");
			}else if(point_total < 30){
				grades.add("F");
			}
		}

		//拡張for文でリストの成績を出力
		for(String grade : grades){
			System.out.println(grade);
		}
		scan.close();
	}
}



Measured memory_bytes: 26308
using System;

namespace consoleapp01
{
    class foo
    {
        static void Main()
        {
            int A, B;
            string[] st = Console.ReadLine().Split(' ');
            A = int.Parse(st[0]);
            B = int.Parse(st[1]);

            if (A >= 13)
                Console.WriteLine(B);
            
            else if (A <= 12 && A >= 6)
                Console.WriteLine(B / 2);

            else if (A <= 5)
                Console.WriteLine("0");
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
 using namespace std;
 
 int main(){
 long long a, b, k;
 cin >> a >> b >> k;
 
 if(k <= a){
 cout << a - k << ' ' << b <<endl;
 }else if(k <= a+b){
 cout << 0 << ' ' << b - (k-a) <<endl;
 }else{
 cout << 0 << ' ' << 0 <<endl;
 }
 }

Measured memory_bytes: 256
import copy
char = list(map(chr, range(ord('a'), ord('z')+1)))
target = list(input())
ans = float("inf")
for c in char:
  s = copy.deepcopy(target)
  tmpans = 0
  while True:
    flag = True
    for si in s:
      if si != s[0]:
        flag = False
    if flag==True:
      break
    for i in range(len(s)-1):
      if s[i] == c or s[i+1] == c:
        s[i] = c
    s.pop()
    tmpans += 1
  if ans > tmpans:
    ans = tmpans
print(ans)
     



Measured memory_bytes: 75092
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	long long a, b, x;
	cin >> a >> b >> x;
	long long fb = b/x+1, fa;
	if(a!=0)
		fa = (a-1)/x+1;
	else
		fa = 0;
	cout << fb-fa << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		m: usize,
	}

	// 試行回数の期待値は2^m
	// 1回の試行にかかる時間は、1900m＋100(N-M)

	println!("{}", (1900*m + 100*(n-m))*2usize.pow(m as u32));
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int, int>;

int main() {
  int K, S, C=0;
  cin >> K >> S;
  for (int x=0; x<=min(K, S); x++) {
    for (int y=0; y<=min(K, S); y++) {
      if (S-(x+y)>=0 && S-(x+y)<=K) {
        C++;
      }
    }
  }
  cout << C << endl;
}

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

int main() {
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  ll sum;
  if(A+B<=2*C){
      cout << X*A + Y*B;
      return 0;
    }
  else{
    int sa = max(X,Y)-min(X,Y);
    sum += 2*C*min(X,Y);
    int a;
    if(X>Y){
      if(sa*A >= sa*2*C) sum += sa*2*C;
      else sum += sa*A;
    }
    else{
      if(sa*B >= sa*2*C) sum += sa*2*C;
      else sum += sa*B;
    }
  }
  cout << sum;
}

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

int main(){
	stack<long> st;
	string s;
	while (cin >> s){
		if (s == "+" || s == "-" || s == "*"){
			long a = st.top();
			st.pop();
			long b = st.top();
			st.pop();
			if (s == "+") st.push(b + a);
			else if (s == "-") st.push(b - a);
			else st.push(b * a);
		}
		else {
			stringstream ss;
			long a;
			ss << s;
			ss >> a;
			st.push(a);
		}
	}
	cout << st.top() << endl;
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N;
  cin >> N;
  vll P(N);
  rep(i, N) {
    cin >> P[i];
  }

  ll m = INF;
  ll ans = 0;
  rep(i, N) {
    if (m > P[i]) {
      m = P[i];
      ans++;
    }
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        int[] A = in.ii(N);
        HashSet<Integer> hs = new HashSet<>(100000);
        boolean flag = true;
        for(int i = 0; i < N; i++){
            flag = hs.add(A[i]);
            if (!flag) {
                break;
            }
        }
        out.println(flag ? "YES" : "NO");
    }


    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        int i() {
            return Integer.parseInt(s());
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            int i = 0;
            String s = s();
            for (int j = 0; j < a.length; j++) {
                boolean minus = s.charAt(i) == '-';
                i += minus ? 1 : 0;
                int k = 0;
                while (true) {
                    try {
                        int h = s.charAt(i++) - '0';
                        if (h < 0 || 9 < h) break;
                        k = 10 * k + h;
                    } catch (Exception e) { break; }
                }
                a[j] = minus ? -k : k;
            }
            return a;
        }
    }
}


Measured memory_bytes: 60036