akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int mod = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int main() {
    int n, m; cin >> n >> m;
    int k[m];
    vector<int> s[m];
    rep(i, m) {
        cin >> k[i];
        rep(j, k[i]) {
            int tmp; cin >> tmp; tmp--;
            s[i].push_back(tmp);
        }
    }
    int p[m]; rep(i, m) cin >> p[i];
    int ans = 0;
    rep(i, (1 << n)) {
        int point[m]; rep(j, m) point[j] = 0;
        rep(j, n) {
            if (i & (1 << j)) {
                rep(k, m) {
                    rep(l, s[k].size()) {
                        if (s[k][l] == j) {
                            point[k]++;
                            break;
                        }
                    }
                }
            }
        }
        rep(j, m) {
            if (point[j] % 2 != p[j]) break;
            if (j == m - 1) ans++;
        }
    }
    cout << ans << endl;
    
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
typedef long long ll;
/*
    problem : http://abc058.contest.atcoder.jp/tasks/arc071_b
*/
int n, m;
const int MOD = 1e9 + 7;
ll calc(int num)
{
	VI A(num);
	REP(i, 0, num) cin >> A[i];

	ll res = 0;
	REP(i, 1, num){
		res += (1ull * (A[i]-A[i-1]) * i) % MOD * (num-i);
		res %= MOD;
	}

	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> m;


	ll sumX = calc(n), sumY = calc(m);
	
	cout << (sumX * sumY) % MOD << endl;

	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
int n,i,a[2][100005],ans=0,mx=0,mx2=0,x,b[100005];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&b[i]);
	for(i=1;i<=n;i+=2)a[0][b[i]]++;
	for(i=2;i<=n;i+=2)a[1][b[i]]++;
	for(i=0;i<=100000;i++)
	{
		ans=max(ans,max(a[0][i]+mx2,a[1][i]+mx));
		mx=max(mx,a[0][i]);
		mx2=max(mx2,a[1][i]);
	}
	printf("%d\n",n-ans);
	return 0;
} 

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();

		int[] b = new int[m];

		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < m; j++) {
				int a = sc.nextInt();
				sum += a * b[j];
			}
			if (sum + c > 0) {
				ans++;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 22356
mod=10**9+7
x=[0]+[0]
for i in range(1,2*10**5+10):
  x.append((x[-1]+i)%mod)

ans=0


n,k=map(int,input().split())


for i in range(k,n+2):
  ans+=(i*(n+n+1-i)//2)-x[i]+1
  ans%=mod
  
print(ans)


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

int main() {
  int h, w; cin >> h >> w;
  vector<string> c(h+1);
  rep(i,h) {
    cin >> c[i+1];
  }
  rep(i,h*2+1) {
    if (i==0) continue;
    rep(j,w) {
      cout << c[(i+1)/2][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int memo[100010];
int n, l;

int solve(vector<int> &a, int idx){
  if(memo[idx] != 0) return memo[idx];

  if(idx == 0){
    if(a[idx] > a[idx+1]){
      memo[idx] = l - a[idx];
    }else{
      memo[idx] = l - a[idx] + solve(a, idx+1);
    }
  }else if(idx == n-1){
    if(a[idx] > a[idx-1]){
      memo[idx] = l - a[idx];
    }else{
      memo[idx] = l - a[idx] + solve(a, idx-1);
    }
  }else{
    memo[idx] = l - a[idx];
    if(a[idx] < a[idx+1]){
      memo[idx] = max(memo[idx], l - a[idx] + solve(a, idx+1));
    }
    if(a[idx]  < a[idx-1]){
      memo[idx] = max(memo[idx], l - a[idx] + solve(a, idx-1));
    }
  }
  return memo[idx];
}

int main(){
  
  cin >> n >> l;

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

  REP(i,n){
    solve(a, i);
  }

  int ans = 0;
  REP(i,n){
    ans = max(ans, memo[i]);
  }

  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void test_case()
{   
	int n;
    cin >> n;
 
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
 
    sort(a.rbegin(), a.rend());
 
    int count = 0;
    for (int i = 0; i < n - 2; ++i) {
        for (int j = i + 1; j < n - 1; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if (a[i] < a[j] + a[k] && a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
                    ++count;
                }
            }
        }
    }
 
    cout << count;
}

int main()
{
	test_case();
	return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	int a,b;
	Scanner scan=new Scanner(System.in);
	a=scan.nextInt();
	b=scan.nextInt();
	if(a<b)
	    System.out.println("a < b");
	else if(a>b)
	    System.out.println("a > b");
	else
	    System.out.println("a == b");
    }
}

Measured memory_bytes: 17160
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

template <class T> class RangeSumQuery {
    vector<T> bit_sum; int size;
public:
    RangeSumQuery(int n):size(n+1),bit_sum(n+10,0){}
    void add(int i, T x){
        while(i<=size){
            bit_sum[i]+=x;
            i+=i&-i;
        }
    }
    T acc(int i){
        T ret=0;
        while(i>0) {
            ret+=bit_sum[i];
            i-=i&-i;
        }
        return ret;
    }
    T getsum(int x, int y) {
        T rem = (x==0?0:acc(x-1));
        return acc(y)-rem;
    }
};


int main(){
    
    int n,q;
    cin>>n>>q;
    
    RangeSumQuery<int> inst(100010);
    
    REP(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0){
            inst.add(x,y);
        }else{
            cout<<inst.getsum(x,y)<<endl;
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 3088
import java.util.*;
 
public class Main{
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int count = 0;
    int que = 0;
    int num = Integer.parseInt(in.nextLine());
    for(int i = 0; i < num; i++) {
      que <<= 5;
      que += Integer.parseInt(in.next());
      if (i > 1) {
        int a = (que >> 10) & 31;
        int b = (que >> 5) & 31;
        int c = que & 31;
        if ((a - b) * (c - b) < 0) {
          count++;
        }
      }
    }
    in.close();
    System.out.println(count);
  }
}

Measured memory_bytes: 23764
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))

cnt = 0
flg = True

while flg == True:
    for i in range(len(a)):
        if a[i] % 2 == 1:
            flg = False
        a[i] /= 2

    if flg:
        cnt += 1 

print(cnt)


Measured memory_bytes: 9172
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int a[] = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		
		int chtimes = 0;
		boolean flag = true;
		while(flag) {
			flag = false;
			for(int j = n-1; j >= 1; j--) {
				if(a[j] < a[j-1]) {
					flag = true;
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					chtimes++;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			if(i != 0) System.out.print(" ");
			System.out.print(a[i]);
		}
		System.out.println("\n" + chtimes);
	}
}


Measured memory_bytes: 26020
#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(){
    int h, w, in;
    cin >> h >> w;
    vector<vector<int>> c(10, vector<int>(10));
    vector<int> m(10);
    rep(i, 10) m.at(i) = 100000;
    rep(i, 10) rep(j, 10){
        cin >> c.at(i).at(j);
    }
    vector<int> s(10);
    rep(i, 10) s.at(i) = i;
    do {
        int cos = 0;
        int it = 0;
        rep(i, 10){
            if(s.at(i) == 1){ it = i; break;}
            cos += c.at(s.at(i)).at(s.at(i+1));
        }
        if(m.at(s.at(0)) > cos) m.at(s.at(0)) = cos;
    } while(next_permutation(s.begin(), s.end()));
    ll ans = 0;
    rep(i, h*w){
        cin >> in;
        if(in != -1){
            ans += m.at(in);
        }
    } 
    cout << ans << endl;
    return 0;
}

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

#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long int
 
using namespace std;
void make_XOR(int A[], int n) 
{ 
    int XOR = 0; 
    for (int i = 0; i < n; i++) 
        XOR ^= A[i]; 
  
    for (int i = 0; i < n; i++) 
        A[i] = XOR ^ A[i]; 
} 
	     
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int  a[n];
	for(int i=0;i<n;i++)
	{
	     cin>>a[i];
	}
	make_XOR(a,n);
	for(int i=0;i<n;i++)
	{
	     cout<<a[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 4368
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])

const ans = _ => {
  const arr = Array(n)
    .fill(0)
    .map((_, i) => i + 1)

  const exps = arr.filter(num => {
    if (num === 1) {
      return true
    }

    for (let i = 2; i < num; i++) {
      for (let j = 2; i ** j <= num; j++) {
        const pow = i ** j
        if (pow === num) {
          return true
        }
      }
    }
    return false
  })

  return Math.max(...exps)
}

console.log(ans())


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

int main(){
  int N;
  cin>>N;
  vector<string> S(N);
  
  for (int i=0; i<N; i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  S.erase(unique(S.begin(),S.end()),S.end());
  cout<<S.size()<<endl;
}

Measured memory_bytes: 9532
eval"N,K,*A="+`dd`.split*?,
S=->a{a.reduce:+}
s,*l=S[A]
1.upto(3e4){|i|s% i<1&&l<<i<<s/i}
p l.select{|d|a=A.map{|a|a%d}.sort
S[a[0..-S[a]/d-1]]<=K}.max

Measured memory_bytes: 9860
#include<bits/stdc++.h>
#define ll  long long int
#define loop(i,a,b) for(i=a;i<b;i++)
#define mod 100000007
#define INF 1000000000000
#define pb push_back
#define lim 500001
using namespace std;

char opposite(char x)
{
	if(x=='0')
		return '1';
	else
		return '0';
}

ll power(ll x,ll y)
{
	ll res=1;

	while(y){
		if(y%2)
			res=(res*x)%mod;
		x=(x*x)%mod;
	}

	return res;
}
int main()
{
	ll i,n,k;

	cin>>n>>k;
	ll a[n+1];


	loop(i,1,n+1) cin>>a[i];

	vector<ll> vis(n+1,0),ans;

	ans.pb(1);
	vis[1]=1;
	ll curr=a[1];

	while(!vis[curr])
	{
	    vis[curr]=1;
		ans.pb(curr);
		curr=a[curr];
	}
	ll len=ans.size();
	
	loop(i,0,len)
	if(ans[i]==curr)
	break;
	
    if((k+1)<=len)
    {
        cout<<ans[k]<<endl;
        return 0;
    }
    k-=i;

    cout<<ans[k%(len-i)+i]<<endl;
    
	return 0;}



Measured memory_bytes: 8480
#!/usr/bin/env python3
from itertools import chain
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, x: "List[int]", y: "List[int]", c: "List[str]"):
    imos = [[0] * (2 * K) for _ in range(2 * K)]

    def sq(x1: int, y1: int, x2: int, y2: int):
        x1 %= 2 * K
        x2 %= 2 * K
        y1 %= 2 * K
        y2 %= 2 * K
        if x1 > x2:
            imos[y1][0] += 1
            imos[y2][0] -= 1
            if y1 > y2:
                imos[0][0] += 1
        if y1 > y2:
            imos[0][x1] += 1
            imos[0][x2] -= 1
        imos[y1][x1] += 1
        imos[y1][x2] -= 1
        imos[y2][x1] -= 1
        imos[y2][x2] += 1

    for xi, yi, ci in zip(x, y, c):
        if ci == "B":
            bx = xi + 1
            by = yi + 1
        else:
            bx = xi - K + 1
            by = yi + 1
        sq(bx, by, bx + K, by + K)
        sq(bx + K, by + K, bx, by)

    # print(imos, file=sys.stderr)

    for i in range(2 * K):
        for j in range(1, 2 * K):
            imos[i][j] += imos[i][j - 1]

    for j in range(2 * K):
        for i in range(1, 2 * K):
            imos[i][j] += imos[i - 1][j]

    # print(imos, file=sys.stderr)
    print(max(chain(*imos)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    c = [str()] * (N)  # type: "List[str]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = next(tokens)
    solve(N, K, x, y, c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 92124
import itertools
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
p = 0
q = 0
c = 0
for e in itertools.permutations([k+1 for k in range(N)], N):
    c += 1
    if e == P:
        p = c
    if e == Q:
        q = c
    if p*q > 0:
        break
print(abs(p-q))


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

using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    string s;
    cin >> s;
    int cnt = 0;
    int maxi = 0;
    int n = s.size();
    for(int i=0; i<n; i++){
        if(s[i]=='R'){
            cnt+=1;
            maxi = max(cnt,maxi);
        } 
        else cnt = 0;
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 3624
N = int(input())
A = list(map(int, input().split()))
count = 0
sumabs = 0
minabs = 10 ** 10
for i in range(N):
    if A[i] < 0:
        count += 1
    sumabs += abs(A[i])
    minabs = min(minabs, abs(A[i]))

if count % 2 == 0:
    print(sumabs)
else:
    print(sumabs-2*minabs)

Measured memory_bytes: 14224
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let mut ps = vec![true; 100_001];
    ps[0] = false;
    ps[1] = false;
    for i in 2..100_001 {
        if ps[i] {
            let mut j = i*2;
            while j <= 100_000 {
                ps[j] = false;
                j += i;
            }
        }
    }
    let mut ns = vec![0; 100_001];
    for i in 0..100_001 {
        if i != 0 { ns[i] += ns[i-1]; }
        if i%2 == 1 && ps[i] && ps[(i+1)/2] { ns[i] += 1; }
    }

    let q = get!(usize);
    for _ in 0..q {
        let (l, r) = get!(usize, usize);
        println!("{}", ns[r] - ns[l-1]);
    }
}

Measured memory_bytes: 2476
#include <bits/stdc++.h> 
using namespace std;
int main(){
    int h,w,m = 0;
    cin >> h >> w;
    bool g[h][w];
    vector<int> row[h];
    vector<int> col[w];
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            char z; cin >> z;
            g[i][j] = (z == '#');
            if(z == '#'){
                row[i].push_back(j);
                col[j].push_back(i);
            }
        }
    }
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(!g[i][j]){
                int t1 = 0,t2 = 0;
                int x1,x2,y1,y2;
                int ix = lower_bound(row[i].begin(), row[i].end(), j) - row[i].begin();
                if(ix == row[i].size()) x2 = w - 1;
                else x2 = row[i][ix] - 1;

                if(ix == 0) x1 = 0;
                else x1 = row[i][ix - 1] + 1;

                int iy = lower_bound(col[j].begin(), col[j].end(), i) - col[j].begin();
                if(iy == col[j].size()) y2 = h - 1;
                else y2 = col[j][iy] - 1;

                if(iy == 0) y1 = 0;
                else y1 = col[j][iy - 1] + 1;

                m = max(m, (y2 - y1) + (x2 - x1) + 1);
            }
        }
    }
    cout << m << endl;

}

Measured memory_bytes: 38272
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.size(); 
  int flag = 0;
  rep(i,n){
    if(i%2==0){
      if(s[i]=='L'){
        flag = 1;
        break;
      }
    }else{
      if(s[i]=='R'){
        flag = 1;
        break;
      }
    }
  }
  if(flag==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

struct vector2D
{
	double x, y;

	vector2D(double x, double y)
	{
		this->x = x;
		this->y = y;
	}
};

vector2D vec(double ax, double ay, double bx, double by)
{
	return vector2D(bx - ax, by - ay);
}

double outer(vector2D a, vector2D b)
{
	return a.x * b.y - a.y * b.x;
}

int main()
{
	vector<double> x(3);
	vector<double> y(3);
	double xp, yp;
	for (;cin >> x.at(0) >> y.at(0) >> x.at(1) >> y.at(1) >> x.at(2) >> y.at(2) >> xp >> yp;)
	{
		vector2D ab = vec(x.at(1), y.at(1), x.at(0), y.at(0));
		vector2D bc = vec(x.at(2), y.at(2), x.at(1), y.at(1));
		vector2D ca = vec(x.at(0), y.at(0), x.at(2), y.at(2));

		vector2D ap = vec(xp, yp, x.at(0), y.at(0));
		vector2D bp = vec(xp, yp, x.at(1), y.at(1));
		vector2D cp = vec(xp, yp, x.at(2), y.at(2));


		if ((outer(ab, bp) >= 0 && outer(bc, cp) >= 0 && outer(ca, ap) >= 0) || (outer(ab, bp) <= 0 && outer(bc, cp) <= 0 && outer(ca, ap) <= 0))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}


Measured memory_bytes: 3212
#include <iostream>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int i;
  for (i = 0; n > 1; i++) {
    n = n / 2;
  }
  for (; i > 0; i--) {
    n = n * 2;
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f)
{
  if (rest == 0)
  {
    f(indexes);
  }
  else
  {
    if (s < 0)
      return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f)
{
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int n, m, q;

ll a[100] = {};
ll b[100] = {};
ll c[100] = {};
ll d[100] = {};
ll ans = 0;

void dfs(vector<int> vec)
{
  ll last = vec[vec.size() - 1];
  if (vec.size() == n)
  {
    // rep(i, vec.size())
    // {
    //   cout << vec[i] << ",";
    // }
    // cout << endl;
    ll tmp = 0;
    rep(i, q)
    {
      if (vec[b[i] - 1] - vec[a[i] - 1] == c[i])
      {
        tmp += d[i];
      }
    }
    // cout << tmp << endl;
    ans = max(ans, tmp);
    return;
  }

  if (last == m)
  {
    vec.push_back(m);
    dfs(vec);
  }
  else
  {
    for (ll i = last; i <= m; i++)
    {
      vector<int> vec_a;
      vec_a = vec;
      vec_a.push_back(i);
      dfs(vec_a);
    }
  }
  return;
}

int main()
{

  cin >> n >> m >> q;

  rep(i, q)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  vector<int> vec;
  vec.push_back(1);
  dfs(vec);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> d(N); rep(i,N) std::cin >> d[i];

  ll sum = 0;
  for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) sum += (d[i]*d[j]);
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	int N, R;
	cin >> N >> R;

	if (N >= 10) {
		cout << R << endl;
	}
	else {
		cout << R + 100 * (10 - N) << endl;
	}
}

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

using namespace std;
const int N = 1e5 + 5;

int n;
struct edge { int to, len; };
vector<edge> G[N];

long long ans;
int tmp;
int maxp[N], siz[N];
int centr;

void solve(int x, int f) {
    siz[x] = 1, maxp[x] = 0;
    for (auto y : G[x]) {
        if (y.to == f) continue;
        solve(y.to, x);
        ans += y.len * 2ll * min(siz[y.to], n - siz[y.to]);
        siz[x] += siz[y.to];
        maxp[x] = max(maxp[x], siz[y.to]);
    }
    maxp[x] = max(maxp[x], n - siz[x]);
    if (maxp[x] < maxp[centr]) centr = x;
}

signed main() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v, w; cin >> u >> v >> w;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }

    maxp[centr = 0] = 2e9;
    solve(1, 0);
    tmp = 2e9;
    for (auto i : G[centr]) {
        int x = i.to, w = i.len;
        if (maxp[centr] == maxp[x]) {
            printf("%lld\n", ans - w);
            return 0;
        }
        tmp = min(tmp, w);
    }
 //   printf("%d %d %d\n", ans, tmp, centr);
    printf("%lld\n", ans - tmp);
    return 0;
}

Measured memory_bytes: 16452
package main

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

type point struct {
	x, y, h int
}

func main() {
	n := getInt()
	ps := make([]point, n)
	for i := range ps {
		ps[i].x = getInt()
		ps[i].y = getInt()
		ps[i].h = getInt()
	}

	var ans point
	for cx := 0; cx <= 100; cx++ {
		for cy := 0; cy <= 100; cy++ {
			tmpH := -1
			ok := true
			for _, p := range ps {
				if p.h == 0 {
					continue
				} else {
					if tmpH == -1 {
						tmpH = p.h + abs(p.x-cx) + abs(p.y-cy)
					} else if tmpH != p.h+abs(p.x-cx)+abs(p.y-cy) {
						ok = false
						break
					}
				}
			}
			if !ok {
				continue
			}
			for _, p := range ps {
				if p.h == 0 {
					if tmpH-abs(p.x-cx)-abs(p.y-cy) > 0 {
						ok = false
						break
					}
				}
			}

			if ok {
				ans = point{x: cx, y: cy, h: tmpH}
			}
		}
	}

	fmt.Println(ans.x, ans.y, ans.h)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int n,k,q,max=0;
	scanf("%d%d%d",&n,&k,&q);
	int a[n],b[n];
	for(int i=1;i<=n;i++){
		a[i]=k;
		b[i]=0;
	}
	int c;
	for(int i=1;i<=q;i++){
		scanf("%d",&c);
		b[c]++;
	}

	for(int i=1;i<=n;i++){
		if(a[i]-(q-b[i])<=0)printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();

    int countMax = 0 ;

    for(int i = 1;i < S.length()  ; i ++){
      int count = 0 ;
      int[] frontChar = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      int[] backChar  = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      String front = S.substring(0,i );
      String back  = S.substring(i  );
      for(int j = 0 ;j < front.length(); j++){
        if(frontChar[ (int) front.charAt(j)  - 97 ] == 0 ) {
          frontChar[ (int) front.charAt(j)  - 97 ] ++ ;
        }
      }
      for(int j = 0 ;j < back.length(); j++){
        if(backChar[ (int) back.charAt(j)  - 97 ] == 0 ) {
          backChar[ (int) back.charAt(j)  - 97 ] ++ ;
        }
      }
      for(int k = 0 ; k < 26 ; k ++){
        if(frontChar[k]  == 1 && backChar[k] == 1){
          count ++ ;
        }
      }
      if(countMax < count ){
        countMax = count ;
      }
    }

    System.out.println( countMax );
  }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int cnt=0;
    for(int i=0; i<n-2; i++){
        if((p[i] < p[i+1] && p[i+1] < p[i+2]) || (p[i] > p[i+1] && p[i+1] > p[i+2])){
            cnt++;
        }
    }
    cout <<cnt <<endl;
}

Measured memory_bytes: 256
N=int(input())
for i in range(N):
    sides=list(map(int,input().split()))
##    print(sides)
    sortsides=sorted(sides)
    if sortsides[2]**2==sortsides[0]**2+sortsides[1]**2:
        print("YES")
    else:
        print("NO")



Measured memory_bytes: 5596
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a=[0 for i in range(n)]
for i in range(n):
    a[i] = list(map(int,input().split()))
    
cnt=0

for i in range(n):
    sum=0
    for j in range(m):
        sum+=b[j]*a[i][j]
    sum+=c
    if(sum>0):
        cnt+=1
        
    
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long 

main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    int dp[n+1];
    dp[1]=0;

    for(int i=2;i<=n;i++){
        dp[i]=1e18;
        for(int j=i-1;j>=max(1ll,i-k);j--){
            dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
        }
    }

    cout<<dp[n];

    return 0;
}

Measured memory_bytes: 1792
A = []
for i in range(3):
  A.append(list(map(int,input().split())))
N = int(input())
b = []
for i in range(N):
  b.append(int(input()))
if A[0][0] in b and A[0][1] in b and A[0][2] in b:
  print("Yes")
elif A[1][0] in b and A[1][1] in b and A[1][2] in b:
  print("Yes")
elif A[2][0] in b and A[2][1] in b and A[2][2] in b:
  print("Yes")
elif A[0][0] in b and A[1][0] in b and A[2][0] in b:
   print("Yes")
elif A[0][1] in b and A[1][1] in b and A[2][1] in b:
  print("Yes")
elif A[0][2] in b and A[1][2] in b and A[2][2] in b:
  print("Yes")
elif A[0][0] in b and A[1][1] in b and A[2][2] in b:
  print("Yes")
elif A[0][2] in b and A[1][1] in b and A[2][0] in b:
  print("Yes")
else:
  print("No")
  
  
  

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

using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long double a, b, h, m, ans;
	const double PI = 3.141592653589793238463;
	cin >> a >> b >> h >> m;

	/*cout << h * 360 / 12 + m *PI/ 2 / 180 << endl;
	cout << m * 360 / 60<<endl;
*/
	h = h *360 * atan(1) * 4 / 12 / 180 + m * atan(1) * 4 / 2 / 180;
	m = m *360 * atan(1) * 4 / 60 / 180;

	/*cout << h << endl;
	cout << cos(h) << endl;
	cout << sin(h) << endl;
	cout << m << endl;
	cout << cos(m) << endl;
	cout << sin(m) << endl;*/

	ans = sqrt(pow(a*cos(h) - b*cos(m), 2) + pow(a*sin(h) - b*sin(m), 2));
	cout << setprecision(15) << ans << endl;

}



Measured memory_bytes: 4164
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
#define MAX_N 200000
int par[MAX_N];
void init(){
	for(int i = 0; i < MAX_N; i++) par[i] = i;
}

int root(int i){
	if(par[i] == i) return i;
	par[i] = root(par[i]);
	return par[i];
}

bool isSameRoot(int i,int j){
	i = root(i), j = root(j);
	return i == j;
}

void unite(int i,int j){
	i = root(i);
	j = root(j);
	if( i == j) return;
	par[i] = j;
}

int main()
{
	init();
	int N,M;
	cin>>N>>M;
	for(int i = 0; i < M; i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		unite(a,b);
	}
	vector<int> population(N,0);
	int maxPopulation = 0;
	for(int i = 0; i < N; i++){
		population[root(i)]++;
	}
	for(int i = 0; i < N; i++){
		maxPopulation = max(maxPopulation,population[i]);
	}
	cout<<maxPopulation<<endl;
	return 0;
}



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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

ll ndigit(ll n)
{
    ll c = 0;
    while(n > 0) {
        n /= 10;
        ++c;
    }
    return c;
}



int main()
{
    ll N, M;
    cin >> N >> M;
    ll s, c;
    vec D(5, -1);
    bool f = true;
    REP(i,0,M) {
        cin >> s >> c;
        --s;
        if(D[s] != c && D[s] != -1) f = false;
        else D[s] = c;
    }

    ll num = -1;
    if(N == 1) {
        REP(i,1,5) if(D[i] != -1) f = false;
        if(f) num = (D[0] == -1 ? 0 : D[0]);
    }
    if(N == 2) {
        REP(i,2,5) if(D[i] != -1) f = false;
        if(f) {
            if(D[0] != 0) 
                num = (D[0] == -1 ? 1 : D[0]) * 10 + (D[1] == -1 ? 0 : D[1]);
        }
    }
    if(N == 3) {
        REP(i,3,5) if(D[i] != -1) f = false;
        if(f) {
            if(D[0] != 0) 
                num = (D[0] == -1 ? 1 : D[0]) * 100 + (D[1] == -1 ? 0 : D[1]) * 10 + (D[2] == -1 ? 0 : D[2]);
        }
    }
    PR(num);

    return 0;
}

/*



*/

Measured memory_bytes: 256
n, q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
ac_count = [0, 0]

(1...n).each do |i|
    if s[i-1] + s[i] == "AC" then
        ac_count << ac_count[i] + 1
    else
        ac_count << ac_count[i]
    end
end

q.times do
    left, right = gets.chomp.split(" ").map(&:to_i)
    puts ac_count[right] - ac_count[left]
end

Measured memory_bytes: 3452
#include<stdio.h>
#include<stdlib.h>
#define N 100000000
#define command 7
#define limit 12
char math[N];
int getChar(char);
int Key(char[]);
int main(){
    int i,n,ans;
    char str[limit],com[command];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s %s",com,str);
        ans=Key(str);
        if (com[0] == 'i'){
            math[ans] = 1;
        } else {
            math[ans]== 1 ? printf("yes\n") : printf("no\n");
        }
    }
}
int Key(char str[]){
    int i=0, k = 0, ans = 1;
    while ('\0'!=str[i]){
        k+=ans*(getChar(str[i]));
        ans*= 5;
        i++;
    }
    return k;
}
int getChar(char ch){
    switch(ch){
        case 'A':
            return 1;
            break;
        case 'C':
            return 2;
            break;
        case 'G':
            return 3;
            break;
        case 'T':
            return 4;
            break;
    }
    return 0;
}


Measured memory_bytes: 6860
#!/usr/bin/env python3
a = int(input())#500y
b = int(input())#100y
c = int(input())#50y
x = int(input())

ans = 0

for i in range(a + 1):
    for j in range(b + 1):
        d = (x - (i * 500) - (j * 100)) // 50

        if d >= 0 and d <= c:
            ans += 1
print(ans)


Measured memory_bytes: 9132
from heapq import heappush, heapreplace

def main():
    INF = 10 ** 9 + 5

    N, K, *TD = map(int, open(0).read().split())

    E = [[-INF] for _ in range(N)]
    for t, d in zip(*[iter(TD)] * 2):
        E[t - 1].append(d)

    for e in E:
        e.sort(reverse=True)
    E.sort(key=lambda x: -x[0])

    cur = 0
    Q = []
    for ei in E[:K]:
        cur += ei[0]
        for eij in ei[1:]:
            heappush(Q, -eij)

    for ei in E[K:]:
        for eij in ei:
            heappush(Q, -eij)

    res = cur + K * K
    for x in reversed(range(1, K)):
        v, w = E[x][0], -Q[0]
        if v < w:
            heapreplace(Q, -v)
            cur += w - v

        res = max(res, cur + x * x)

    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 34812
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  string s;
  int q;
  cin >> s >> q;
  
  int cnt=0;
  while(q--){
    int type; cin >> type;
    if(type==1){
      cnt++;
    } else {
      int fb;  cin >> fb;
      if(fb==1){
        if(cnt%2==0){string c;cin>>c; s.insert(0,c); } else {char c;cin>>c; s.push_back(c); }
      } else {
        if(cnt%2==1){string c;cin>>c; s.insert(0,c); } else {char c;cin>>c; s.push_back(c); }
      }
    }
  }
  
  if(cnt%2==1){ reverse(s.begin(),s.end()); }
  cout << s << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

class CompareFirst{ public:
    bool operator()(P n1, P n2) {
        return n1.first > n2.first; //>:昇順　pairのfirst同士を比較する
        // return n1.first < n2.first; // 降順
    }
};

void Main() {
    ll N; cin >> N;

    // 拡張priority queue (llを２つ格納，１つ目でソート)
    priority_queue<P, vector<P>, CompareFirst> cd; // blue側はxの小さい方から取り出す
    set<P> ab;
    rep(i, N){ll a, b; cin >> a >> b; ab.insert(make_pair(a, b));}
    rep(i, N){ll c, d; cin >> c >> d; cd.push(make_pair(c, d));}

    // ただの貪欲探索
    // 青のx座標が最も小さいものと，ペアになれるもののうち最もy座標が大きいものとペアにする
    ll cnt = 0;
    while(cd.size() > 0){
        P q = cd.top(); cd.pop();
        ll tmp_y = -INF; P tmp_P;
        for (P a: ab){
            if (a.first < q.first){
                if (a.second < q.second && a.second > tmp_y){tmp_y = a.second; tmp_P = a;}
            }
        }
        if (tmp_y > -INF){cnt++; ab.erase(tmp_P);}
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll n,m;
    cin>>n>>m;
    vector <int> a(m);
    ll sum=0;
    rep(i,m)
    cin>>a[i],sum+=a[i];
    if (sum>n)
        cout<<-1;
    else
        cout<<n-sum;





}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){
  string t,p;
  cin >> t;
  cin >> p;
  vector<int> ve;
  int k=0;
  for(int i=0;i<t.size();i++){
    if(t[i]==p[k]){
      ve.push_back(i);
      //   cout << i << endl;
      k++;
    }
  }
  ve.push_back(t.size());
  if(k!=p.size()){
    cout << "no" << endl;
    return 0;
  }
  for(int i=0;i<ve.size()-1;i++){
    for(int j=ve[i]+1;j<ve[i+1];j++){
      if(t[ve[i]]==t[j]){
	cout << "no" << endl;
	return 0;
      }
    }

  }
  cout << "yes" << endl;
  return 0;
}

Measured memory_bytes: 6052
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	string a,b;
	cin>>n;
	cin>>a>>b;
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<b[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
lisS = [list(map(ord, list(input()))) for _ in range(N)]
arS = np.array(lisS)
arExt = np.tile(arS, [2,2])[:-1,:-1]

cnt = 0
for i in range(N):
    ar = arExt[i:i+N, 0:N]
    cnt += N * (ar == ar.T).all()

print(cnt)



Measured memory_bytes: 18108
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d,e, H, W;
long long A[2005][2005] = {};
long long B[2005][2005] = {};
long long C[200005] = {};
bool f, ff;
string S[2005];
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/



bool fs[2005][2005] = {};

int main() {


	cin >> H >> W;

	for (int i = 0; i < H; i++) {
		cin >> S[i];
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				fs[i][j] = true;
			}
		}
	}

	a = 0;

	b = 0;
	f = false;

	for (int i = 0; i < H; i++) {
		b = 0;
		a = 0;
		f = false;
		for (int j = 0; j < W; j++) {
			
			if (fs[i][j] == true) {
				
				if (f == true) {
					for (int v = b; v < j; v++) {
						A[i][v] = a;
					}
				}

				a = 0;
				b = j;
				f = false;

			}
			else {
				a++;
				if (f == false) {
					f = true;
					b = j;
				}
			}

		}

		if (f == true) {

			for (int v = b; v < W; v++) {
				A[i][v] = a;
			}
		}

	}
	a = 0;
	f = false;
	b = 0;
	

	for (int j = 0; j < W; j++) {
		b = 0;
		a = 0;
		f = false;
		for (int i = 0; i < H; i++) {

			if (fs[i][j] == true) {

				if (f == true) {
					for (int v = b; v < i; v++) {
						B[v][j] = a;
					}
				}

				a = 0;
				b = j;
				f = false;

			}
			else {
				a++;
				if (f == false) {
					f = true;
					b = i;
				}
			}

		}

		if (f == true) {
			for (int v = b; v < H; v++) {
				B[v][j] = a;
			}
		}
	}

	c = 0;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (c < A[i][j] + B[i][j] - 1) {
				c = A[i][j] + B[i][j] - 1;
			}
		}
	}



	cout << c << endl;
	
	return 0;

}


Measured memory_bytes: 72576
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <tuple>
using namespace std;

using ii = pair < int, int >;
using lint = long long;
using ti = tuple < int, int, int >;

int main() {
	//freopen("in.txt", "r", stdin);
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	int t = -1;
	for(int i=0;i<100*n;i++) {
		if(i&1) {//borys
			if(b==n) {
				if(a==n-1) {
					t = 0;
					break;
				}
				else {
					b = b-1;
				}
			}
			else {
				if(b-1==a) {
					b = b+1;
				}
				else {
					b = b-1;
				}
			}
		}
		else {
			if(a==1) {
				if(b==2) {
					t = 1;
					break;
				}
				else {
					a = a+1;
				}
			}
			else {
				if(a+1==b) {
					a = a-1;
				}
				else {
					a = a+1;
				}
			}
		}
	}
	if(t==0) {
		puts("Alice");
	}
	else if(t==1){
		puts("Borys");
	}
	else {
		puts("Draw");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main(){
    int X;
    cin>>X;
  int A,B;
  A = X/500;
    int sum=0;
    sum += 1000*A;
    X %= 500;
    sum += 5*(X/5);
    cout<<sum<<endl;
}

Measured memory_bytes: 256
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll l(n), r(n);
    REP(i, n) cin >> l[i] >> r[i];

    ll min_r = *min_element(ALL(r)), max_l = *max_element(ALL(l));
    ll ans = 0;
    V< P<ll, ll> > p(n);
    REP(i, n) p[i] = make_pair(min_r - l[i] + 1, r[i] - max_l + 1);
    sort(ALL(p));
    
    ll m2 = HIGHINF;
    REP(i, n-1) {
        chmin(m2, p[i].second);
        chmax(ans, p[i + 1].first + m2);
    }
    REP(i, n) {
        ll cur = r[i] - l[i] + 1;
        cur += max(0LL, min_r - max_l + 1);
        ans = max(ans, cur);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) (x-'0')
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return (t*t);
    else
        return (t*t*x);
}

bool prime(int x)
{
    if(x < 2) return false;
        for(int i=2; i<= sqrt(x); i++) {
            if ((x%i) == 0) return false;
        }
    return true;
}

bool cmp(const pair<int , int> &a , const pair<int , int> &b){
    return (a.first < b.first);
}


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



int main()
{
    weewoo;
    ll n,r;
    cin >> n >> r;
    if(n>=10)
        return cout << r << endl,0;
    ll ans = r + (100*(10-n));

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


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

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

using namespace std;

int main(){
  int n,x;cin>>n>>x;
  int minx = 1000;
  int sum = 0;
  rep(i,n){
    int t;cin>>t;
    minx=min(t,minx);
    sum+=t;
  }
  
  cout<<(x-sum)/minx+n;

  return 0;
}

Measured memory_bytes: 764