akhauriyash/Code-Regression huggingface dataset:
from collections import deque

def check(line):
    Q = deque([])
    for s in line:
        if s in ['(', '[']:
            Q.append(s)
        elif s in [')', ']']:
            if len(Q) == 0:
                return 0
            p = Q.pop()
            if s == ')' and p != '(':
                return 0
            elif s == ']' and p != '[':
                return 0
            else:
                continue
    else:
        if len(Q) != 0:
            return 0
        else:
            return 1



ans = []
while 1:
    line = input()
    if line == '.': break
    ans += ['yes' if check(line) else 'no']

print('\n'.join(ans))
        
            


Measured memory_bytes: 6012
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("oxo");
            //900
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("ooo");
            //1000
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("xxx");
            //700
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];

        Console.WriteLine(700 + S.Count(A => A == 'o') * 100);
    }
}


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

int main() {
	int h,w; cin>>h>>w;
  	vector<vector<char>> c(h,vector<char>(w));
  	vector<vector<int>> data(h,vector<int>(w));
  	
  	for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
       	cin>>c.at(i).at(j);
        if(c.at(i).at(j)=='#'){
        	if(i-1>=0 && j-1>=0) {data.at(i-1).at(j-1)++;}
  			if(j-1>=0)          {data.at(i).at(j-1)++;}
  			if(i+1<h && j-1>=0) {data.at(i+1).at(j-1)++;}
  			if(i-1>=0)          {data.at(i-1).at(j)++;}
    		if(i+1<h)          {data.at(i+1).at(j)++;}
  			if(i-1>=0 && j+1<w) {data.at(i-1).at(j+1)++;}
  			if(j+1<w)          {data.at(i).at(j+1)++;}
  			if(i+1<h && j+1<w) {data.at(i+1).at(j+1)++;}
        }
      }    
    }
  	
  	for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(c.at(i).at(j)=='#'){
        	cout<<c.at(i).at(j);
        }else{
        	cout<<data.at(i).at(j);
        }
    	
      }    
      cout<<endl;
    }
}
  	

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

struct Node
{
    public int Num, N;
    public Node(int num, int n)
    {
        Num = num;
        N = n;
    }
}

struct W
{
    public int X, Y, D;
    public W(int x, int y, int d)
    {
        X = x;
        Y = y;
        D = d;
    }
}

public class UnionFind
{
    private int[] Par;
    private int[] Rank;

    public UnionFind(int n)
    {
        Par = (new int[n]).Select((i, index) => index).ToArray();
        Rank = new int[n];
    }

    public int Root(int a)
    {
        if (Par[a] == a) return a;
        else return Root(Par[a]);
    }

    public bool Same(int a, int b)
    {
        return Root(a) == Root(b);
    }

    public bool Union(int a, int b)
    {
        a = Root(a);
        b = Root(b);
        if (a != b)
        {
            if (Rank[a] < Rank[b])
            {
                Par[a] = b;
            }
            else
            {
                Par[b] = a;
                if (Rank[a] == Rank[b])
                {
                    Rank[a]++;
                }
            }
            return true;
        }
        else
        {
            return false;
        }
    }
}

class Magatro
{
    private int X, A, B;
    public void Solve()
    {
        var line = Console.ReadLine().Split(' ');
        X = int.Parse(line[0]);
        A = int.Parse(line[1]);
        B = int.Parse(line[2]);
        if (B - A > X)
        {
            Console.WriteLine("dangerous");
        }
        else if (B - A <= X&&B>A)
        {
            Console.WriteLine("safe");
        }
        else
        {
            Console.WriteLine("delicious");
        }
    }
}


Measured memory_bytes: 13140
use std::io::{self, BufRead};

fn main(){
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let n: usize = lines.next().unwrap().unwrap().parse().unwrap();

    let mut honest: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut dishonest: Vec<Vec<usize>> = vec![Vec::new(); n];
    for i in 0..n {
        let a: usize = lines.next().unwrap().unwrap().parse().unwrap();
        for _ in 0..a {
            let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
            let (x, y) = (xs[0] - 1, xs[1]);
            if y == 0 {
                dishonest[i].push(x);
            } else {
                honest[i].push(x);
            }
        }
    }

    let mut ans = 0;

    for i in 0..((2 as u32).pow(n as u32)){
        let mut ok = true;
        for j in 0..n {
            // print!("i & (1<<j) = {}, ", i & (1<<j));
            // print!("i = {}, ", i);
            // print!("j = {}, ", j);
            // println!("1<<j = {}", 1<<j);
            if i & (1<<j) != 0 {
                let p1 = honest[j].iter().all(|&h| i & (1 << h) != 0);
                let p2 = dishonest[j].iter().all(|&d| i & (1 << d) == 0);
                if !p1 || !p2 {
                    ok = false;
                    break;
                }
            }
        }
        if ok {
            let tmp = (0..n).filter(|&k| i & (1 << k) != 0).count();
            if ans < tmp {
                ans = tmp;
            }
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
import math

N = int(input())
x = [0] * N
y = [0] * N
z = [True] * N
for i in range(N):
    x[i],y[i] = map(int,input().split())
D = 0

def distance(a,b,d):
    global D
    if a.count(True) == 0:
        D += d
        return
    for i in range(N):
        if a[i] == True:
            a[i] = False
            dd = math.sqrt((x[i] - x[b]) ** 2 + (y[i] - y[b]) ** 2)
            d += dd
            distance(a,i,d)
            a[i] = True
            d -= dd

for i in range(N):
    z[i] = False
    d = 0
    distance(z,i,d)
    z[i] = True

print (D / math.factorial(N))

Measured memory_bytes: 43740
n, m, k = (map(int, input().split()))
a = list(map(int, input().split()))
f = lambda x:1 if x<k else 0
f2 = lambda x:1 if x>k else 0
y = list(map(f, a))
z = list(map(f2, a))
print(min(sum(y), sum(z)))


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int n, a[999], i;
    int j, temp;
    scanf("%d",&n);

    if(n<=100)

    {
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);

        }
        for (i=0,j=n-1; i<n/2;i++,j--)
        {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
        for(i=0;i<n-1;i++)
        {
            printf("%d ",a[i]);
        }
        printf("%d\n",a[n-1]);
    }

    return 0;
}



Measured memory_bytes: 2104
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
 
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
 
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
 
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
 
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
 
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

              

int main(){
  int N,M;
  cin >> N >> M;
  vector<P> p;
  vector<P> g;
  rep(i,N){
    int a,b;cin >> a >> b;
    p.push_back(make_pair(a,b));
  }
  rep(i,M){
    int a,b;cin >> a >> b;
    g.push_back(make_pair(a,b));
  }

  rep(i,N){
    int a=p[i].first,b=p[i].second;
    int ans = inf;
    int idx = 0;
    rep(j,M){
      int x = g[j].first,y=g[j].second;
      int d = abs(a-x) + abs(b-y);
      // cout << x << y << endl;
      if(ans > d){
	idx = j;
	ans = d;
      }
    }
    cout << idx+1 << endl;
    
  }
  
  return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int X, Y, Z;
	cin >> X >> Y >> Z;
	cout << (X - Z) / (Y + Z) << endl;

	return 0;
}

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

int main(int argc, char **argv)
{
	ll n, m;
	cin >> n >> m;
	vector<ll> l(m), r(m);

	for (ll i = 0;i < m; ++i)
		cin >> l[i] >> r[i];

	ll MAX = 100010;
	vector<ll> table(MAX, 0);
	for (ll i = 0; i < m; ++i)
	{
		++table[l[i]];
		--table[++r[i]];
	}

	for (ll i = 0; i < MAX-1; ++i)
	{
		table[i+1] += table[i];
	}

	ll c{0};
	for (ll i= 0; i < MAX; ++i)
	{
		if (table[i] == m) ++c;
	}

	std::cout << c << std::endl;
	
}


Measured memory_bytes: 2560
A, B, C, X = [int(input()) for i in range(4)]
num = 0
for j in range(A+1):
    for k in range(B+1):
        for m in range(C+1):
            if 500 * j + 100 * k + 50 * m == X:
                num += 1
print("{}".format(num))


Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long llong;

int f(int n){
	if(n %2 == 0) return n / 2;
	return 3 * n + 1;
}

int main() {
	int s, a[1000010];
	bool is_exists[1000010];

	for (int i = 0; i < 1000010; ++i) {
		is_exists[i] = false;
	}

	cin >> s;
	a[1] = s;
	is_exists[s] = true;

	for (int n = 2; n <= 1000001; ++n) {
		a[n] = f(a[n-1]);

		if(is_exists[a[n]]){
			cout << n << endl;
			return 0;
		}else{
			is_exists[a[n]] = true;
		}
	}

	cout << 99 << endl;
	return 0;
}


Measured memory_bytes: 3072
N = input().split('/')
year = int(N[0])
mon  = int(N[1])
day  = int(N[2])

if year < 2019:
    ans = "Heisei"
elif (year == 2019) and (mon < 5):
    ans = "Heisei"
else:
   ans = 'TBD'
   
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
using namespace std;

int n,a[105];

int main(){
    scanf("%d",&n);
    int count=0;
    for(int i=1;i<=n;i++) {
        scanf("%d", &a[i]);
        if((i&1)&&(a[i]&1))
            count++;
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
  int n;
  scanf("%d",&n);
  int temp=n/111;
  if(n%111==0)
  	printf("%d",n);
  else
  {
    temp++;
    n=temp*111;
      printf("%d",n);
  }
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end())

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using vstr = std::vector<std::string>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

int dp[5005][5005];

void Main() {
    int n;
    string s;
    cin >> n >> s;
    for(int i = n - 1; i >= 0; --i) {
        for (int j = n - 1; j >= 0; --j) {
            if (s[i] != s[j])dp[i][j] = 0;
            else dp[i][j] = dp[i + 1][j + 1] + 1;
        }
    }
    int ans = 0;
    rep(i, n)rep(j, n) {
        if (i >= j)continue;
        int now = min(dp[i][j], j - i);
        ans = max(ans, now);
    }
    cout << ans << endl;
}

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



Measured memory_bytes: 98048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		// ???????????°??\???
		String game_times = input.readLine();

		int game_num = Integer.parseInt(game_times);

		// ????????¨???????????????
		int taro_point = 0;

		// ????????¨?????±?????????
		int hanako_point = 0;

		// ??????????????°????????????????????°?????°?????????
		for (int match_spot = 0; match_spot < game_num; match_spot++) {

			String two_person_card = input.readLine();

			// ???????????§?????????????????????????????±????????\???
			String[] cards_array = two_person_card.split(" ");

			String taro_card = cards_array[0];

			String hanako_card = cards_array[1];

			// ????????????????????¨??±?????????????????????????????????????????????????????????????´¢
			if (taro_card.compareToIgnoreCase(hanako_card) > 0) {

				taro_point += 3;

			} else if (taro_card.compareToIgnoreCase(hanako_card) < 0) {

				hanako_point += 3;

				// ??????????????????
			} else {

				taro_point += 1;

				hanako_point += 1;
			}
		}

		System.out.println(taro_point + " " + hanako_point);

	}

}

Measured memory_bytes: 25760
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D; ll C;
//***********//
int main() {
	ll X, Y, Z;
	cin >> X >> Y >> Z;

	cout << Z << " "<<X <<" "<< Y;
}

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

using namespace std;

const int CMax = 100002;

int A, B;
long long sum;

int main() {
    scanf("%d", &A);
    scanf("%d", &B);


    printf("%d\n", (A * B) - A - B + 1);
}


Measured memory_bytes: 256
/*input
sippxu
*/

#include <bits/stdc++.h>
#define MOD 998244353
 
using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5])
    cout << "Yes";
    else
    cout << "No";    



    return 0;
}


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

int main(){
  int n,t;cin>>n>>t;
  int Min=INT_MAX;
  for(int i=0;i<n;i++){
    int c,tt;cin>>c>>tt;
    if(tt<=t){
      Min=min(Min,c);
    }
  }
  if(Min==INT_MAX){
    puts("TLE");
  }
  else{
    cout<<Min<<endl;
  }
}

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

int hist[14+1];
int group[4+1];
int cont;

bool fourofakind() { return group[4] == 1; }
bool fullhouse() { return (group[2] == 1 && group[3] == 1); }
bool straight() { return cont == 5; }
bool threeofakind() { return group[3] == 1; }
bool twopair() { return group[2] == 2; }
bool onepair() { return group[2] == 1; }

int main() {
	int k;
	while (scanf("%d", &k) == 1) {
		for (int i = 1; i <= 14; i++) hist[i] = 0;
		for (int i = 0; i <= 4; i++) group[i] = 0;
		cont = 0;
		for (int i = 0; i < 5; i++, scanf(",%d", &k)) {
			hist[k]++;
			if (k == 1) hist[14]++;
		}
		for (int i = 1; i <= 13; i++)
			group[hist[i]]++;
		int c = 0;
		for (int i = 1; i <= 14; i++) {
			if (hist[i] == 1) {
				c++;
				if (c > cont) cont = c;
			} else
				c = 0;
		}

		if (fourofakind()) cout << "four card";
		else if (fullhouse()) cout << "full house";
		else if (straight()) cout << "straight";
		else if (threeofakind()) cout << "three card";
		else if (twopair()) cout << "two pair";
		else if (onepair()) cout << "one pair";
		else cout << "null";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N,X = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
ans = 10**18
w = Array.new(N+1,0)
for i in 0..N-1
  w[i+1] = w[i]+x[i]
end
for i in 1..N
  ret = X*(N+i)
  ret += (w[N]-w[N-i])*5
  for j in 2..(N-1)/i
    ret += (w[N-i*(j-1)]-w[N-i*j])*(2*j+1)
  end
  ret += (w[N-i*((N-1)/i)]-w[0])*(2*((N+i-1)/i)+1)
  ans = ret if ret < ans
end
puts ans

Measured memory_bytes: 22804
ans=0
N=int(input())
l=list(input())
for i in range(1,N):
   tmp1=set(l[0:i])
   tmp2=set(l[i:])
   tmp3=[]
   tmp3.append(list(tmp1))
   tmp3.append(list(tmp2))
   tmp3=sum(tmp3,[])
   tmp3=set(tmp3)
   ans=max(ans,-len(tmp3)+len(tmp2)+len(tmp1))
print(ans)

Measured memory_bytes: 9188
//g++  5.4.0

#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;

int main()
{
    int n,k; cin >> n >> k;
    vector<vector<long long> > first(2100,vector<long long>(2100,0));
    vector<vector<long long> > second(2100,vector<long long>(2100,0));
    
    for (int i = 0; i <= k-1; i++) 
    { 
        for (int j = 0; j <= i; j++) 
        { 
            if (j == 0 || j == i) 
                first[i][j] = 1; 
            else
                first[i][j] = (first[i - 1][j - 1] + first[i - 1][j])%mod; 
        } 
    }
    
    
    for (int i = 0; i <= n-k+1; i++) 
    { 
        for (int j = 0; j <= i; j++) 
        { 
            if (j == 0 || j == i) 
                second[i][j] = 1; 
            else
                second[i][j] = (second[i - 1][j - 1] + second[i - 1][j])%mod; 
        } 
    }
    
    for(int i = 1; i <= k; ++i){
        long long tmp = ((first[k-1][i-1])*(second[n-k+1][i]))%mod;
        cout << tmp << "\n";
    }
}

Measured memory_bytes: 69376
N=int(input())
p=list(map(int,input().split()))

count=0
flag=0
for i in range(N):
  if flag:
    flag=0
    continue
  if p[i]==i+1:
    count += 1
    if i < N-1 and p[i+1]==i+2:flag=1
      
print(count)

Measured memory_bytes: 20552
/* https://www.youtube.com/watch?v=dQw4w9WgXcQ hello. -bedirhan */
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string f,s;
    cin >> f >> s;
    s.pop_back();
    if(f==s){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
}


Measured memory_bytes: 3588
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    ll n,l;
    cin >> n >> l;
    ll a[n];
    inrep(n,a);


    rep(i,0,n-1){
	if(a[i] + a[i+1] >= l){
	    P("Possible");
	    rep(j,1,i+1)P(j);
	    rrep(j,n,i+2)P(j);
	    P(i+1);
	    ret 0;
	}
    }
    P("Impossible");
   
    return  0;
}


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

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

	if (a <= 0 && b >= 0) {
		cout << "Zero" << endl;
	}
	else if (b < 0) {
		if ((b - a) % 2 == 0) {
			cout << "Negative" << endl;
		}
		else {
			cout << "Positive" << endl;
		}
	}
	else {
		cout << "Positive" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int mod = 1e9 + 7;

signed main(){
   IOS;
   int n, k;
   cin >> n >> k;
   vector<int> b1(n), b2(2*n);
   for(auto &x : b1) cin >> x;
   for(int i = 0; i < 2*n; i++) {
      b2[i] = b1[i%n];
   }
   int a = 0, b = 0;
   for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
         if(i < j and b1[i] > b1[j]) a++;
      }
   }
   for(int i = 0; i < 2*n; i++) {
      for(int j = 0; j < 2*n; j++) {
         if(i < j and b2[i] > b2[j]) b++;
      }
   }
   cout << (k*a + ((b-2*a)*(((k*(k-1))/2)%mod))%mod)%mod << "\n";
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s; cin >> s;
    int len = s.length();

    if(s[0] == s[len-1]){
        if(len % 2 == 0){
            cout << "First" << endl;
        }
        else cout << "Second" << endl;
    }
    else{
        if(len % 2 == 0){
            cout << "Second" << endl;
        }
        else cout << "First" << endl;
    }

}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int bi_search(int a[], int start, int end, int q){
    if(end-start==1){
        if(a[start]==q) return start;
        else if(a[end]==q) return end;
        else return -1;
    }
    int mid = (start+end)/2;
    if(a[mid]==q) 
        return mid;
    else if(a[mid]>q) 
        return bi_search(a, start, mid, q);
    else 
        return bi_search(a, mid, end, q); 
}

int main(){
    int a[100005];
    int q[50005];
    int data_num;
    scanf("%d", &data_num);
    for(int i=0; i<data_num; i++){
        scanf("%d", &a[i]);
    }
    int query_num;
    scanf("%d", &query_num);
    for(int i=0; i<query_num; i++){
        scanf("%d", &q[i]);
    }
    
    /*int q;
    scanf("%d", &q);
    printf("%d\n",bi_search(a,0,data_num-1,q));*/
    
    int find = 0;
    for(int i=0; i<query_num; i++){
        if(bi_search(a, 0, data_num-1, q[i])!=-1)
            find++;
    }
    printf("%d\n", find);
}



Measured memory_bytes: 2312
#include <iostream>
#include <algorithm>

typedef std::pair<int,int> Activity;

bool compare(const Activity& a, const Activity& b) { return a.second < b.second; }

int main()
{
	int n; std::cin >> n;
	
	Activity* acts = new Activity[n];
	for (int i=0; i<n; i++) {
		std::cin >> acts[i].first >> acts[i].second;
	}

	std::sort(acts, acts + n, compare);
	
	
	int count = 0;
	int start = 0;
	for (int i=0; i<n; i++) {
		// std::cout << acts[i].first << " " << acts[i].second;
		if (start < acts[i].first) {
			// std::cout << " * "; 
			count++;
			start = acts[i].second;
		}
		// std::cout << std::endl;
	}
	
	std::cout << count << std::endl;
	
	delete[] acts;
	
	return 0;
}



Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
///////////////////////////////////////////////////////////////////////////////////////////////////////
const int maxn=3e3+10;
pair<int,int>dp[maxn][maxn];
string s;
string t;
char c[maxn];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>s;
	cin>>t;
	for(int i=1;i<=s.size();i++){
		for(int j=1;j<=t.size();j++){
			if(s[i-1]==t[j-1]){
				if(dp[i-1][j-1].second+1>=max(dp[i][j-1].second,dp[i-1][j].second)){
					dp[i][j]={1,dp[i-1][j-1].second+1};
				}
				else{
					if(dp[i][j-1].second>=dp[i-1][j].second){
						dp[i][j]={2,dp[i][j-1].second};
					}
					else{
						dp[i][j]={3,dp[i-1][j].second};
					}
				}
			}
			else{
					if(dp[i][j-1].second>=dp[i-1][j].second){
						dp[i][j]={2,dp[i][j-1].second};
					}
					else{
						dp[i][j]={3,dp[i-1][j].second};
					}
				}
			//	cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
	}
	int cnt=0;
	int i=s.size();
	int j=t.size();
	while(i!=0&&j!=0){
	    if(dp[i][j].first==1){
	        c[cnt]=s[i-1];
	        i--;
	        j--;
	        cnt++;
	    }
	    else if(dp[i][j].first==2){
	        j--;
	    }
	    else{
	        i--;
	    }
	}
	for(int i=cnt-1;i>=0;i--){
	    cout<<c[i];
	}
	return 0;
	
}


Measured memory_bytes: 70784
#include<iostream>
using namespace std;
int main()
{
	int n,i=1,j=0;
	cin>>n;
	if(n<=81)
	{
		for(i=1;i<=9;i++)
		{
			if(n%i==0&&n/i<10)
			j++;
		}
		if(j>0)
		cout<<"Yes";
		else
		cout<<"No";
    }
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(float, input().split()))
dp = [[0] * (N + 1) for i in range(N + 1)]
dp[0][0] = 1.0
for i in range(1, N + 1):
    for j in range(N):
        if j < N:
            dp[i][j + 1] += dp[i - 1][j] * P[i - 1]
        dp[i][j] += dp[i - 1][j] * (1 - P[i - 1])

num = 0
for i in range(N // 2 + 1, N + 1):
    num += dp[N][i]

print(num)


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

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

using ll=long long;
const int Nmax=3010;
string S,T; 
ll dp[Nmax][Nmax];
const ll INF=1LL<<60;


int main(){
  cin >> S >> T;
  for (int i=0;i<S.size();i++){
    for (int j=0;j<T.size();j++){
      if (S[i]==T[j]) dp[i+1][j+1]=dp[i][j]+1;
      dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
      dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
    }
  }
  string X;
  int i=S.size();
  int j=T.size();
  while(i>0 && j>0){
    if (dp[i][j]==dp[i][j-1]) j--;
    if (dp[i][j]==dp[i-1][j]) i--;
    if (dp[i][j]!=dp[i][j-1] && dp[i][j]!=dp[i-1][j]){
      X+=T[j-1];
      i--; j--;
    }
  }
  reverse(X.begin(),X.end());
  cout << X << endl;
      
  
}

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

int main(){
    int n,m,i,j;
    cin>>n>>m;
    vector<int>C(m);
    vector<vector<int>> dp(m,vector<int>(n+1));
    for(i=0;i<m;i++)cin>>C[i];
    sort(C.begin(),C.end());

    for(i=0;i<m;i++){
        if(i==0)for(j=0;j<=n;j++)dp[i][j]=j;
        if(i>0)for(j=0;j<=n;j++){
            if(j-C[i]<0)dp[i][j]=dp[i-1][j];
            if(j-C[i]>=0)dp[i][j]=min(dp[i-1][j],dp[i][j-C[i]]+1);
        }
    }

    cout<<dp[m-1][n]<<endl;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	cout << ((b % a == 0) ? a + b : b - a) << endl;

}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)

using PAIR = pair<string, pair<ll, ll>>;

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

    ll N;
    cin >> N;

    vector<PAIR> p;
    rep (i, N) {
        string S;
        ll P;
        cin >> S >> P;
        p.push_back(make_pair(S, make_pair(-P, i+1)));
    }

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

    rep (i, N) {
        cout << p[i].second.second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

#define STR_MAX 500000
// 524288
#define NUM_MAX (1<<19)
#define BUF_SIZE (STR_MAX+100)
#define QUERY_MAX 20000
#define LOWER_NUM 26

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_intch(int *a, char *ch) {
    return scanf("%d %c", a, ch);
}

int get_int2(int *a, int *b) {
    return scanf("%d %d", a, b);
}

// include '\n'
int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

enum type {
    COMMAND_UPDATE = 1,
    COMMAND_GET
};

// assume that 'a' - 'z'
char get_pos(char ch) {
    return ch - 'a';
}

void update(int *seg, int num, int idx, int bit) {
    int node = num + idx;
    seg[node] = bit;
    while((node = node/2)) {
        seg[node] = seg[node*2] | seg[node*2+1];
    }
#ifdef DEBUG
    int i;
    for(i = num; i < 2*num; i++) {
        printf(" %d", seg[i]);
    }
    putchar('\n');
#endif
    return;
}

struct range {
    int start;
    int end;
};

int is_overlap(struct range r1, struct range r2) {
    return r1.end >= r2.start && r2.end >= r1.start;
}

int is_contain(struct range this, struct range in) {
    return in.start <= this.start && in.end >= this.end;
}

int get_pat(int *seg, struct range r, int node, struct range nr) {
    if(!is_overlap(r, nr)) return 0;
    if(is_contain(nr, r)) {
        return seg[node];
    }
    // otherwise
    struct range left = {nr.start, (nr.start+nr.end)/2};
    struct range right = {left.end+1, nr.end};
    return get_pat(seg, r, node*2, left) | get_pat(seg, r, node*2+1, right);
}

int main(void) {
    int _num = get_int();
    int num = 1;
    while(_num >= num) num *= 2;
    static char str[BUF_SIZE];
    get_str(str, _num);

    int queries = get_int();
    static int seg[NUM_MAX*2];
    static int ans[QUERY_MAX];
    int aidx = 0;
    int i;
    // initialization
    for(i = 0; i < _num; i++) {
        int idx = get_pos(str[i]);
        update(seg, num, i, (1<<idx));
    }

    struct range whole = {0, num-1};
    for(i = 0; i < queries; i++) {
        int type = get_int();
        switch(type) {
            case COMMAND_UPDATE:
                {
                    int idx; char newch;
                    get_intch(&idx, &newch);
                    idx--;
                    int pos = get_pos(newch);
                    update(seg, num, idx, (1<<pos));
                }
                break;
            case COMMAND_GET:
                {
                    int start, end;
                    get_int2(&start, &end);
                    start--; end--;
                    struct range r = {start, end};
                    int pat = get_pat(seg, r, 1, whole);
                    ans[aidx++] = __builtin_popcount(pat);
                }
                break;
            default:
                break;
        }
    }
    for(i = 0; i < aidx; i++) {
        printf("%d\n", ans[i]);
    }
}

Measured memory_bytes: 4736
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    std::string s;
    std::cin >> s;
    vec<usize> ckd(26);
    for (char c: s) {
        usize i = c - 'a';
        if (std::exchange(ckd.at(i), true)) {
            std::cout << "no" << '\n';
            return 0;
        }
    }
    std::cout << "yes" << '\n';
}


Measured memory_bytes: 256
n,m=map(int, input().split())

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
        
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

for _ in range(m):
    a,b=map(int,input().split())
    unite(a-1,b-1)
ans=0
for i in range(n):
    if size(i)>ans:
        ans=size(i)
print(ans)

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    ll N;
    ll ans = 0;
    cin >> N;
    if(N%2 == 1||N==0) cout << 0 << endl;
    else{
        N /= 2;
        ll i = 1;
        while(pow(5,i) <=  N){
            ll x = pow(5,i);
            ans += N / x;
            i++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    int n;
    ll ans = 0;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    for(int i = 0; i < n-2; i++){
        for(int j = i+1; j < n-1; j++){
            int sum = l[i] + l[j];
            int idx = distance(l.begin(), lower_bound(l.begin(), l.end(), sum));
            idx -= (j+1);
            ans += idx;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template<long long mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((mod + x) % mod) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    mint& operator+=(const mint &a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint &a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint &a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint& operator/=(const mint &a) {
        long long n = mod - 2;
        mint<mod> u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

int main() {
    constexpr int MOD = 1e9 + 7;
    int n; cin >> n;
    vector<int> near(2 * 1e5, -1);
    vector<mint<MOD>> dp(n + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        int c; cin >> c; c--;
        if (near[c] == -1 || near[c] == i) {
            dp[i + 1] = dp[i];
        }
        else {
            dp[i + 1] = dp[i] + dp[near[c]];
        }
        near[c] = i + 1;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
        template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
    };

    inp inp1; // input one
}

int main() {

    ll n, m;
    cin >> n >> m;
    vector<ll> a = inp(m);

    ll sum = 0LL;
    rep(i, m) sum += a[i];

    if (sum > n) {
        Cout(-1);
        return 0;
    }

    Cout(n - sum);

    return 0;
}


Measured memory_bytes: 3704
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
ll dp[501][501];
ll find(vector<ll>&v,vector<ll>&sum,ll l,ll r){
	// cout<<l<<" "<<r<<endl;
	if(l==r){
		// cout<<l<<" "<<r<<" "<<v[l]<<endl;
		dp[l][r]=0;
		return 0;
	}
	ll &ans=dp[l][r];
	if(ans!=-1) return ans;
	ans=LLONG_MAX;
	for(int i=l;i<r;i++){
		ll pre1=(l==0)?sum[i]:sum[i]-sum[l-1];
		ll pre2=(sum[r]-sum[i]);
		// cout<<pre1<<" "<<pre2<<endl;
		ans=min(ans,find(v,sum,l,i)+find(v,sum,i+1,r)+pre1+pre2);
	}
	// cout<<l<<" "<<r<<" "<<ans<<endl;
	return ans;
}
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n;
		cin>>n;
		vector<ll>v(n),sum(n,0);
		for(int i=0;i<n;i++){
			cin>>v[i];
			sum[i]=(i>0?sum[i-1]:0)+v[i];
			// cout<<sum[i]<<endl;
		}
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				dp[i][j]=-1;
			}
		}

		cout<<find(v,sum,0,n-1)<<endl;
		// for(int i=0;i<=n;i++){
		// 	for(int j=0;j<=n;j++){
		// 		cout<<dp[i][j]<<" ";
		// 	}
		// 	cout<<endl;
		// }
	}
}

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

using ll = long long int;

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> d(n);
    for(int i=0;i<n-1;i++){
        cin >> d[i+1];
        d[i+1] += d[i];
    }
    ll ans = 0;
    for(int i=0,idx=0;i<m;i++){
        int a;
        cin >> a;
        ans += abs(d[idx+a]-d[idx]);
        ans %= 100000;
        idx += a;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int a,b,c;cin>>a>>b>>c;int flag=-1;
	for(int i=1;i<=1000;i++){
		if(i*a>=b&&i*a<=c){flag=1;break;
		}
	}
	if(flag==-1)cout<<"NG"<<"\n";
	else cout<<"OK"<<"\n";
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<long long> T(N);
    for(int i=0; i<N; i++) cin >> T[i];
    long long ans = 1;
    long long g;
    for(int i=0; i<N; i++) {
        g = gcd(ans, T[i]);
        ans *= T[i] / g;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a;
   string b;
   cin>>a>>b;
   int count=0;
   for(int i=0;i<a-2;i++)
   {
       if(b.substr(i,3)=="ABC")
        count++;
   }
   cout<<count<<endl;
}

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

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

	int	n;
	int	sum;

	cin >> n;
	vector<int>	B(n - 1);
	rep(i, n - 1)
		cin >> B.at(i);
	sum = B.at(0) + B.at(n - 2);
	rep(i, n - 2)
		sum += min(B.at(i), B.at(i + 1));
	cout << sum << endl;
}


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

int N, M;

void Main(){
    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            if(i != j){
                count++;
            }
        }
    }
    for (int i = 0; i < M; i++) {
        for (int j = i; j < M; j++) {
            if(i != j){
                count++;
            }
        }
    }
    cout << count << endl;
}

int main() {
    cin >> N >> M ;
    Main();
    return 0;
}

Measured memory_bytes: 256