akhauriyash/Code-Regression huggingface dataset:
h,w,d=map(int,input().split())
l=[[] for t in range(h*w)]
for i in range(h):
  ll=list(map(int,input().split()))
  for j in range(w):
    l[ll[j]-1]=[i,j]
    
r=[[0] for dd in range(d)]
for dd in range(d):
  if dd==0:
    k=d
  else:
    k=dd
  while k+d<=h*w:
    r[dd].append(r[dd][-1]+abs(l[k+d-1][0]-l[k-1][0])+abs(l[k+d-1][1]-l[k-1][1]))
    k+=d

    
q=int(input())
for qq in range(q):
  a,b=map(int,input().split())
  if a%d==0:
    p=d
  else:
    p=a%d
  aa=(a-p)//d
  bb=(b-p)//d
  ans=r[a%d][bb]-r[a%d][aa]
  print(ans)

Measured memory_bytes: 25160
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  string s = in;
  cout << (s.substr(0, size(s) - sizeof("FESTIVAL") + 1)) << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll n, k;
    cin >> n >> k;
    vll p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    ll ans = 0;
    rep(i,k) ans += p[i];
    cout << ans << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
int n;
int a[105],b[105];
bool x,y;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        if(a[i]==b[i]){
            if(x){
                if(y){
                    cout<<"Yes"<<endl;
                    return 0;
                }else{
                    y=true;
                }
            }else{
                x=true;
            }
        }else{
            x=false;
            y=false;
        }
    }
    cout<<"No"<<endl;
    
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll a, b;
    cin >> a >> b;
    if (a <= 0 && 0 <= b) {
        cout << "Zero" << endl;
        return 0;
    } else if (b < 0) {
        ll minus_num;
        minus_num = b - a + 1;
        if (minus_num % 2 == 0) {
            cout << "Positive\n";
        } else {
            cout << "Negative\n";
        }
    } else {
        cout << "Positive\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    ll ans=0;
    ll count=0;
    if(a[0]!=0){
            cout<<-1<<"\n";
            return 0;
        }
    for(int i=1;i<n;i++){
        if(a[i]-a[i-1]>1||a[i]>i){
            cout<<-1<<"\n";
            return 0;
        }
        if(a[i]-a[i-1]==1){
            ans++;
        }
        else{
            ans+=a[i];
        }
    }
    cout << ans << "\n";
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


int main() {
    int n, k; cin >> n >> k;
    V<ll> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    ll ans = 1LL << 60;
    for(int bit = 0; bit < (1 << n); bit++){
        if(bit % 2 == 0 || __builtin_popcount(bit) != k) continue;
        ll s = v[0] - 1, sum = 0;
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)){
                if(v[i] <= s){
                    s++;
                    sum += s - v[i];
                }else{
                    s = v[i];
                }
            }else{
                s = max(s, v[i]);
            }
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3576
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int MOD = 1e9 + 7, N = 2e5 + 7;

int binpow(int x, int d) {
    int ans = 1;
    while (d) {
        if (d & 1)
            ans = ans * x % MOD;
        x = x * x % MOD;
        d >>= 1;
    }
    return ans;
}

int f[N] = { 1 }, add[N];

void solve() {
    loop1(i, N - 1) {
        f[i] = f[i - 1] * i % MOD;
        add[i] = (add[i - 1] + i * (i + 1)) % MOD;
    }
    int n, m, k, ans = 0;
    cin >> n >> m >> k;
    loop(i, n)
        loop(j, m) {
            int d = abs(i - j), mn = min(i, j);
            int cur = (add[mn] + (d * (mn + 1) + d * (d - 1) / 2) * (mn + 1) + (mn == 0 ? 0 : mn * (mn + 1) / 2 % MOD * max(i, j) + mn * (mn + 1) / 2 % MOD * mn - add[mn - 1] + MOD)) * 2 % MOD;
            cur = (cur - (i * (i + 1) / 2 + j * (j + 1) / 2) % MOD + MOD) % MOD;
            ans = (ans + cur) % MOD;
        }
    cout << ans * f[n * m - 2] % MOD * binpow(f[k - 2], MOD - 2) % MOD * binpow(f[n * m - k], MOD - 2) % MOD;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int point[N][3];
  int dep[3] = {0,0,0};
  int now[3] = {0,0,0};
  int distance[2];


  rep(i,N) cin >> point[i][0] >> point[i][1] >> point [i][2] ;
  bool flag = false;

  rep(i,N){
    distance[0] = abs(point[i][1]-now[1]);
    distance[1] = abs(point[i][2]-now[2]);

    if((point[i][0]-now[0]-(distance[0]+distance[1]))%2 != 0) break;
    if((point[i][0]-now[0]-(distance[0]+distance[1])) < 0) break;
    //if(now[1]==point[i][1] && point[i][2]==now[2] && point[i][0]-now[0] < 4)break;
    now[0]=point[i][0];
    now[1]=point[i][1];
    now[2]=point[i][2];
    if(i==N-1)flag = true;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
typedef long long ll;
#define mod 998244353
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
int A[410],B[410],f[410][410][410],fact[410],ifact[410];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),SA=0,S=0;
	for(int i=1;i<=n;++i)SA+=A[i]=gi(),S+=B[i]=gi();
	fact[0]=1;for(int i=1;i<=S;++i)fact[i]=1ll*fact[i-1]*i%mod;
	ifact[S]=pow(fact[S],mod-2);for(int i=S;i;--i)ifact[i-1]=1ll*ifact[i]*i%mod;
	auto add=[&](int&a,int b){a=a+b>=mod?a+b-mod:a+b;};
	f[1][0][0]=mod-1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=SA;++j)
			for(int k=0;k<=S;++k){
				if(!f[i][j][k])continue;
				add(f[i+1][j][k],f[i][j][k]);
				for(int l=0,x=1;l<B[i];++l,x=1ll*x*A[i]%mod)
					add(f[i+1][j+A[i]][k+l],mod-1ll*f[i][j][k]*x%mod*ifact[l]%mod);
			}
	int ans=0;
	for(int i=0;i<=SA;++i)
		for(int j=0;j<=S;++j)
			add(ans,1ll*f[n+1][i][j]*pow(i,mod-j-2)%mod*fact[j]%mod*SA%mod);
	printf("%d\n",ans);
	return 0;
}


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

const int N = 200020;
const int INF = (1LL << 31) - 1;

struct BIT {
    int N;
    vector<int> dat;
    void init(int _N){
        N = _N;
        dat = vector<int>(N+1,0);
    }
    void add(int k,int val){
        k++;
        while (k <= N){
            dat[k] += val;
            k += k&-k;
        }
    }
    int getsum(int k){
        k++;
        int ret = 0;
        while (k){
            ret += dat[k];
            k -= k&-k;
        }
        return ret;
    }
};

/* 
class BIT{
    public:
    //[1,i]
    int n;
    vi bit;
    // int bit[MAZ_N+1];
    BIT(int size){
        n=size;
        bit=vi(n+1);
    }
    int query(int i){//sum
        int s=0;
        while(i>0){
            s+=bit[i];
            i-=i&-i;
        }
        return s;
    }
    void add(int i,int x){
        while(i<=n){
            bit[i]+=x;
            i+=i&-i;
        }
    }
};
*/



int main(){
    int n,q; cin >> n >> q;
    BIT bit;
    bit.init(n);
    for(int i = 0; i < q; i++){
        int t,x,y; cin >> t >> x >> y;
        if (t == 1){
            cout << bit.getsum(y-1) - bit.getsum(x-2) << endl;;
        } else {
            bit.add(x-1,y);
        }
    }
    return 0;
}



Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1e9 + 7;

int main()
{
  string a;
  cin >> a;
  int f[100100][2] = {0};
  f[0][0] = 1;
  for (int i = 0; i < a.size(); i++)
    for (int isLess = 0; isLess < 2; isLess++)
      for (int x = 0; x < 2; x++)
        for (int y = 0; y < 2 - x; y++)
          if (isLess || (x ^ y) <= a[i] - '0')
          {
            int newIsLess = isLess | ((x ^ y) < a[i] - '0');
            f[i + 1][newIsLess] = (f[i + 1][newIsLess] + f[i][isLess]) % BASE;
          }
  cout << (f[a.size()][0] + f[a.size()][1]) % BASE << endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 


ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}



int main()
{
     ll n,a,b;
     cin>>n>>a>>b;
     ll dp[n+1];
     memset(dp,0,sizeof(dp));
     ll x[n];
     for(int i=0;i<n;i++)cin>>x[i];
     for(int i=1;i<n;i++)
     {
          ll dx=(x[i]-x[i-1]);
          ll fi=1LL*dx*a;
          dp[i]=min(fi,b);
     }
    ll res=0;
    for(int i=0;i<=n;i++)res+=dp[i];
    cout<<res;
}















 














 
 

















Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
    char A[3];
    int a=0;
    int b=0;
    int c=0;
    scanf("%s",A);
    if (A[0]==A[1])
    {a=1;
}
if (A[1]==A[2])
    {b=1;
}
if(A[0]==A[2])
{c=1;
}
    if (a==1&&b==1&&c==1)
    {
       printf("No");
    }else{
        printf("Yes");
    }
}



Measured memory_bytes: 128
r, c = gets.split.map(&:to_i)
sums = [0] * (c + 1)

r.times do
	nums = gets.split.map(&:to_i)
	nums << nums.inject(&:+)
	puts nums.join(' ')
	nums.each_with_index {|n, i| sums[i] += n}
end

puts sums.join(' ')

Measured memory_bytes: 6120
use proconio::input;
// dbg {{{
#[allow(dead_code)]
mod dbg {
    use std::fmt::{Debug, Formatter};

    #[derive(Clone)]
    pub struct Tabular<'a, T: Debug>(pub &'a [Vec<T>]);

    impl<'a, T: Debug> Debug for Tabular<'a, T> {
        fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
            for i in 0..self.0.len() {
                writeln!(f, "{:2} | {:?}", i, &self.0[i])?;
            }
            Ok(())
        }
    }
}
// }}}

fn main() {
    input!(
        n: usize,
        p: [proconio::marker::Usize1; n - 1],
        a: [usize; n]
    );
    let mut g = vec![vec![]; n];
    for (i, x) in p.iter().enumerate().map(|(i, &x)| (i + 1, x)) {
        g[x].push(i);
    }
    let mut dp = vec![0; n];
    fn dfs(x: usize, dp: &mut [usize], g: &[Vec<usize>], a: &[usize]) {
        for &y in &g[x] {
            dfs(y, dp, g, a);
        }
        let mut table = vec![false; a[x] + 1];
        table[0] = true;
        for (w0, w1) in g[x].iter().copied().map(|y| (a[y], dp[y])) {
            for i in (0..=a[x]).rev() {
                for w in [w0, w1].iter() {
                    if i + w <= a[x] {
                        table[i + w] |= table[i];
                    }
                }
                if w0 != 0 && w1 != 0 {
                    table[i] = false;
                }
            }
        }
        if let Some(z) = (0..=a[x]).rfind(|&w| table[w]) {
            dp[x] = g[x].iter().map(|&y| a[y] + dp[y]).sum::<usize>() - z;
        } else {
            println!("IMPOSSIBLE");
            std::process::exit(0);
        }
    }
    dfs(0, &mut dp, &g, &a);
    println!("POSSIBLE");
}


Measured memory_bytes: 2504
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int> h(n+1);
    int ans;
    for(int i=0;i<n+1;++i) cin>>h[i];
    for(int i=0;i<n+1;++i){
    	vector<int> t;
    	for(int j=0;j<n+1;++j) if(i!=j) t.push_back(h[j]);
    	//sort(t.begin(),t.end());
    	int mx=t[1]-t[0],mn=t[1]-t[0];
    	for(int j=1;j<n;++j){
    		int d=t[j]-t[j-1];
    		if(d>mx)mx=d;
    		if(d<mn)mn=d;
    	}
    	if(mx==mn){
    		ans=h[i];
    		break;
    	}
    }
    cout<<ans<<endl;
	}
  return 0;
}

Measured memory_bytes: 1216
Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim b As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
    Dim a(0 To n - 1) As Long
    a(0) = b(0)
    a(1) = b(0)
    For i As Integer = 1 To n - 2
      a(i) = If(a(i) > b(i), b(i), a(i))
      a(i + 1) = b(i)
    Next
    Dim ans As Long = 0
    For i As Integer = 0 To n - 1
      ans += a(i)
    Next
    Console.WriteLine(ans.ToString())
  End Sub
End Class

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int32_t main(){
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int suffixSum[n+1];
    for(int i=n;i>=1;i--){
        if(i==n){
            suffixSum[i]=a[i];
        } else{
            suffixSum[i]=a[i]+suffixSum[i+1];
            suffixSum[i]%=mod;
        }
    }
    int ans=0;
    for(int i=1;i<n;i++){
        ans+=(a[i]*suffixSum[i+1])%mod;
    }
    cout<<ans%mod;
}

Measured memory_bytes: 6660
/* 133b */
#include<stdio.h>
#include<math.h>
int main(void)
{
  int n,d,x[10][10],i,j,f,a,k,c;
  double b;
  scanf("%d %d",&n,&d);
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      scanf("%d",&x[i][j]);
    }
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      a=0;
      for(k=0;k<d;k++){
	a=a+pow(x[i][k]-x[j][k],2);
      }
      b=sqrt(a);
      int c=b;
	if((double)c==b){
	f++;
      }
    }
  }
  printf("%d\n",f);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll INF =  1LL << 60;
const int inf = 1 << 20;
int n, m, x, y, q, d,z, w = 0, sum, ans = 0;
vector<int>a;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
	cin >> n; map<int, int> mp;
	set<int> st;
	rep(i, n) {
		cin >> m;
		mp[m]++;
		st.insert(m);
	}
	for (auto it = st.begin(); it != st.end(); it++) {
		if (mp[*it] % 2 == 1) ans++;
	}cout << ans << endl;
}

Measured memory_bytes: 12892
#include<bits/stdc++.h>
#define ll long long
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define MOD1 1000000007
#define MOD2 998244353
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define print(a) for(auto x : a)    cout<<x<<" "; cout<<"\n";
using namespace std;

int main(){

    IOS;
    int n, m;
    long long sum = 0, x;
    cin >> n >> m;
    FOR(i, 0, m)    cin >> x, sum += x;

    n -= sum;
    if(n < 0)
        cout<<"-1\n";
    else    
        cout<<n<<"\n";
    


    return 0;
}
// long double r;
//     cin >> r;
//     long double pi = 22.0/7.0;
//     long double c = 2 * pi * r;

//     cout<<setprecision(20)<<c<<"\n";
// string s;
//     cin >> s;
//     set<int> val;
//     if(s.length() < 4)
//         cout<<"0\n";
//     else
//     {
//         int n = s.length();
//         int arr[n] = {0};
//         FOR(i, 0, n)    arr[i] = s[i] - '0';

//         // FOR(i, 1, 101)  cout<<2019*i<<"\n";

//         for(int i = 1; i*i <= 2019; i++)
//         {
//             if(2019 % i == 0)
//                 val.insert(i);
//             if(i != 2019 / i)
//                 val.insert(2019 / i);

//         }
//         print(val);
//     }

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(void){
    
    int x,y;
    while(true){
        cin>>x;
        cin>>y;
        if(x==0&&y==0){
            break;//whileから抜ける
        }
        if(x<y){
            cout<<x<<" "<<y<<endl;
        }
        else{
            cout<<y<<" "<<x<<endl;
            
        }
        
    }
    
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

#define LLincID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)

LL f(LL x) {
	LL s = 0;
	LLincID(i, x / 4 * 4, x) { s ^= i; }
	return s;
}

int main() {
	LL a, b;
	cin >> a >> b;
	
	cout << (f(a) ^ f(b + 1)) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

char C[] = {'I', 'O', 'T', 'J', 'L', 'S', 'Z'};

LL func1(map<char, LL> mp) {
    LL ans = 0;


    LL buf = mp['I'] / 2;
    ans += (buf) * 2;
    buf = mp['L'] / 2;
    ans += (buf) * 2;
    buf = mp['J'] / 2;
    ans += (buf) * 2;



    return ans;
}
LL func2(map<char, LL> mp) {
    LL ans =0;

    if (mp['I'] > 0 && mp['L'] > 0 && mp['J'] > 0) {
        mp['I'] --;
        mp['J'] --;
        mp['L'] --;
        ans += 3;
    }
    LL buf = mp['I'] / 2;
    ans += (buf) * 2;
    buf = mp['L'] / 2;
    ans += (buf) * 2;
    buf = mp['J'] / 2;
    ans += (buf) * 2;


    return ans;
}

int main(void) {
    map<char, LL> mp;
    REP(i, 7) {
        LL buf;
        scanf("%lld", &buf);
        mp[C[i]] = buf;
    }

    cout << max(func1(mp), func2(mp)) + mp['O'] << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define incant() cin.tie(0), ios::sync_with_stdio(false)
#define int long long
#define uint unsigned long long
#define double long double
using str = string;
template <class T> using vec = vector<T>;
template <class T> using vvec = vec<vec<T>>;
template <class T> using que = queue<T>;
template <class T> using pque = priority_queue<T>;
template <class... T> using tup = tuple<T...>;
using vint = vec<int>;
using vvint = vvec<int>;
using vstr = vec<str>;
using pint = pair<int, int>;
using vp = vec<pint>;
using tll = tup<int, int, int>;
using vt = vec<tll>;
using mint = map<int, int>;
using dict = map<str, int>;
using qint = que<int>;
using qp = que<pint>;
using pqint = pque<int>;
using pqp = pque<pint>;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fir first
#define sec second
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define ms(v, x) memset(v, x, sizeof(v))
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload3(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) out(x), indent()
#define debug(x) cerr << __LINE__ << ": " << #x << ": " << (x) << '\n'
#define YN(x) print((x) ? "YES" : "NO")
#define Yn(x) print((x) ? "Yes" : "No")
#define yn(x) print((x) ? "yes" : "no")
#define POS(x) print((x) ? "POSSIBLE" : "IMPOSSIBLE")
#define Pos(x) print((x) ? "Possible" : "Impossible")
#define pos(x) print((x) ? "possible" : "impossible")
const int INF = LLONG_MAX - INT_MAX, MOD = 1e9 + 7, LIMIT = 100001;
const int dx4[] = {-1, 0, 1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const double EPS = 1e-9;
int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
int factorial(int a){return a < 2 ? 1 : factorial(a - 1) * a;}
int summation(int a){return a < 1 ? 0 : (a * a + a) / 2;}
int combination(int n, int r){int res = 1; rep(i, 1, r + 1) res *= n--, res /= i; return res;}
const str alphabet = "abcdefghijklmnopqrstuvwxyz";
int a, b, c, k, n, m, x, y, z, w, h, res = 0, cnt = 0, sum = 0, mx = -INF, mn = INF;
str s, t;
bool flag = true;

signed main(){
    incant();
    cin >> n >> m;
    rep(i, 1, sqrt(m) + 1){
        if(m % i == 0){
            if(i <= m / n){
                chmax(res, i);
            }
            if(i >= n){
                chmax(res, max(i, m / i));
            }
        }
    }
    print(res);
}


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

using namespace std;

int main() {
    string t;
    cin >> t;
    char before = '?';
    for (auto& c : t) {
        if (c == '?') {
            // if (before == 'P') {
            //     c = 'D';
            // } else if (before == 'D') {
            //     c = 'P';
            // }
            c = 'D';
        }
        before = c;
    }
    cout << t << endl;
    return 0;
}


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

ll mod(ll n, ll MOD){
    if(n >= 0 && MOD > 0)return n % MOD;
    else if(n < 0 && MOD > 0){
        return(((abs(n)+MOD-1)/MOD)*MOD+n) % MOD ;
    }else if(n <= 0 && MOD < 0){
        n *= -1;
        MOD *= -1;
        return mod(n,MOD);
    }else if(n > 0 && MOD < 0){
        n *= -1;
        MOD *= -1;
        return mod(n,MOD);
    }
}

string base_minus2(ll n){
    string S = "";
    ll i = 2;//mod
    while(n != 0){
        if(mod(n,abs(i)) < abs(i/2) ){
            S += "0";
        }else{
            S += "1";
            n -= i/2;
        }
        i *= -2;
    }
    reverse(S.begin(),S.end());
    return S;
}

int main(){
    ll n;
    //while(true){
    cin >> n;
    if(n == 0)cout << 0 << endl;
    else cout << base_minus2(n) << endl;
    //}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K, x, ans=0;
    cin >> N >> K;
    for(int i=0; i<N;i++){
        cin >> x;
        ans += min(x, K-x);
    }
    cout << ans * 2 << endl;
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int K, T;
  cin >> K >> T;
  int a, m = 0;
  for(int i = 0; i < T; i++){
    cin >> a;
    m = max(m, a);
  }
  if(m - 1 <= K - m)cout << 0 << endl;
  else cout << m - 1 - K + m; 
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<stdlib.h>

int main(){
    int s[6],s2[6];
    int t[6];
    int c = 0;
     char h[4] = {'N','S','W','E'};
    for(int i = 0;i < 6; i++){
        scanf("%d",&s[i]);
    }
    for(int i = 0;i < 6 ; i++){
        scanf("%d",&s2[i]);
    }
     while(1){
            int k = rand() % 4;
                if(h[k] == 'N'){
                    t[4] = s[0];
                    t[0] = s[1];
                    t[1] = s[5];
                    t[5] = s[4];
                    t[2] = s[2];
                    t[3] = s[3];
                }
                if(h[k] == 'S'){
                    t[0] = s[4];
                    t[1] = s[0];
                    t[5] = s[1];
                    t[4] = s[5];
                    t[2] = s[2];
                    t[3] = s[3];
                }
                if(h[k] == 'W'){
                    t[0] = s[2];
                    t[2] = s[5];
                    t[5] = s[3];
                    t[3] = s[0];
                    t[1] = s[1];
                    t[4] = s[4];
                }
                if(h[k] == 'E'){
                    t[2] = s[0];
                    t[5] = s[2];
                    t[3] = s[5];
                    t[0] = s[3];
                    t[1] = s[1];
                    t[4] = s[4];
                }
                for(int j = 0;j < 6;j++){
                    s[j] = t[j];
                }
                if(s[0] == s2[0] && s[1] == s2[1] && s[2] == s2[2] && s[3] == s2[3] && s[4] == s2[4] && s[5] == s2[5]){
                printf("Yes\n");
                break;
                }
                if(c == 1000){
                    printf("No\n");
                    break;
                }
             c += 1;
        }

}


Measured memory_bytes: 2684
from collections import deque
h , w , d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
zahyo = [-1 for i in range(h*w+1)]
for i in range(h):
    for j in range(w):
        zahyo[a[i][j]] = (a[i][j],i,j)
ans = [-1 for i in range(h*w + 1)]
for i in range(1,h*w+1):
    if ans[i] == -1:
        ans[i] = 0
        p = deque()
        p.append(zahyo[i])
        while p:
            now , nowx , nowy = p.popleft()
            if now + d > h*w:
                break
            tugi , nexx , nexy = zahyo[now+d]
            p.append(zahyo[now+d])
            ans[tugi] = ans[now] + abs(nowx-nexx) + abs(nowy-nexy)

    else:
        continue

q = int(input())
for i in range(q):
    l , r = map(int,input().split())
    print(ans[r]-ans[l])


Measured memory_bytes: 96344
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int main(){
	fast
	int a[5];
	int an=0;
	int x;
	FORQ(1,5){
		cin>>x;
		if(x==0) an=i;
	}
	cout<<an;
}



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

using namespace std;

const int MAXN = 2e5 + 10;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;	cin >> s;
	string ans;
	for (char c:s){
		if (ans.size() && ans.back() == 'S' && c == 'T')
			ans.pop_back();
		else
			ans += c;
	}
	cout << ans.size() << endl;
	return 0;
}


Measured memory_bytes: 1228
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

const int N=200010;

typedef long long ll;

int n,prd;
int fail[N];
char a[N];
ll l,r,pre[N][30];

inline ll fib(ll p,int c){
  if(p<=n) return pre[p][c];
  if(p<=n*2) return pre[n][c]+pre[p-n][c];
  ll ret1=pre[n][c]+pre[prd][c],ret2=pre[n][c],a=n+prd,b=n;
  while(p>a+b){
    ll c=ret1; ret1+=ret2; ret2=c;
    c=a; a+=b; b=c;
  }
  return ret1+fib(p-a,c);
}

inline ll calc(ll p,int c){
  if(p<=n) return pre[p][c];
  if(n%prd==0){
    ll ret=1LL*(p-n)/prd*pre[prd][c]+pre[n][c];
    p-=n; p%=prd;
    return ret+pre[p][c];  
  }
  else return fib(p,c);
}

int main(){
  scanf("%s",a+1); n=strlen(a+1)/2;
  for(int i=1;i<=n;i++){
    for(int j=0;j<26;j++) pre[i][j]=pre[i-1][j];
    pre[i][a[i]-'a']++;
  }
  scanf("%lld%lld",&l,&r);
  int k=0;
  for(int i=2;i<=n;i++){
    while(k&&a[k+1]!=a[i]) k=fail[k];
    if(a[k+1]==a[i]) k++;
    fail[i]=k;
  }
  prd=n-fail[n];
  for(int i=0;i<26;i++)
    printf("%lld ",calc(r,i)-calc(l-1,i));
  return 0;
}

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

#define ll long long

using namespace std;

int main() {

    int n;
    cin >> n;
    
    ll arr[n], dp[n];
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    
        if(i == 0) {
            dp[0] = 0;
            continue;
        }
        
        if(i == 1) {
            dp[1] = abs(arr[1] - arr[0]);
            continue;
        }
        
        dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]), dp[i - 2] + abs(arr[i] - arr[i - 2]));
    }
    
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0

for num_A in [num_A for num_A in range(A + 1) if (num_A * 500 <= X)]:
    rest_XA = X - num_A * 500
    for num_B in [num_B for num_B in range(B + 1) if num_B * 100 <= rest_XA]:
        rest_XAB = rest_XA - num_B * 100
        if rest_XAB % 50 == 0 and rest_XAB <= C * 50:
            cnt += 1
print(cnt)


Measured memory_bytes: 38896
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;

namespace competitive
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine()
            .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
            .Select(x => int.Parse(x))
            .Sum();
            if (ab >= 10)
            {
                Console.WriteLine("error");
            }
            else
            {
                Console.WriteLine(ab);
            }
        }
    }
}


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

typedef long long ll;

vector<pair<char, int> > command;
string s;
int string_num, com_num; //文字列長,命令数 
//点pが最終的にどの場所にいるか判定
int func_goal(int p)
{
    int overflag = 0;
    //printf("%d:",p);
    for(int i = 0; i < com_num; i++)
    {
        if (s[p] == command[i].first){
            p += command[i].second;
        }
        if (p < 0) {overflag = -1; break;}
        if (p >= string_num) {overflag = 1; break;}
    }
    //printf("%d\n",overflag);
    return overflag;
}

int main()
{
    cin >> string_num >> com_num;
    cin >> s;
    for(int i = 0; i < com_num; i++)
    {
        char t, d;
        int dint;
        cin >> t >> d;
        dint = (d == 'L') ? -1 : 1;
        command.push_back(make_pair(t, dint));
    }

    //for(int i = 0; i < string_num; i++)
    //{
    //    func_goal(i);
    //}
    

    int left_it = 0;
    int right_it = string_num;
    while(1){
        if (right_it - left_it <= 1) break;
        int tmp_it = (left_it + right_it) /2;
        if(func_goal(tmp_it) ==  -1){
            left_it = tmp_it;
        } else {
            right_it = tmp_it;
        }
    }
    int left_limit = right_it;

    left_it = 0;
    right_it = string_num;
    while(1){
        if (right_it - left_it <= 1) break;
        int tmp_it = (left_it + right_it) /2;
        if(func_goal(tmp_it) !=  1){
            left_it = tmp_it;
        } else {
            right_it = tmp_it;
        }
    }
    int right_limit = right_it;

    int ans = 0;
   //printf("%d %d %d\n", string_num, left_limit, right_limit);
    cout << string_num - (left_limit) - (string_num - right_limit) << endl;
}



Measured memory_bytes: 2680
import java.util.Arrays;
import java.util.Scanner;

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

		final int n = sc.nextInt();
		int[] arr = new int[n];
		
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		
		for(int i = n - 1; i >= 0; i--){
			if(i != n - 1){
				System.out.print(" ");
			}
			System.out.print(arr[i]);
		}
		System.out.println();
	}

}

Measured memory_bytes: 19696
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;
const ll MAX_N = 8;

ll N, M;
bool graph[MAX_N][MAX_N];

ll dfs(ll v, bool visited[MAX_N]) {
  bool all_visited = true;

  for (ll i = 0; i < N; i++) {
    if (visited[i] == false) {
      all_visited = false;
    }
  }

  if (all_visited) {
    return 1;
  }

  int ret = 0;

  for (ll i = 0; i < N; i++) {
    if (graph[v][i] == false) {
      continue;
    }
    if (visited[i]) {
      continue;
    }

    visited[i] = true;
    ret += dfs(i, visited);
    visited[i] = false;
  }

  return ret;
}

int main(int argc, char* argv[])
{
  std::cin >> N >> M;

  for (ll i = 0; i < M; i++) {
    ll A, B;
    std::cin >> A >> B;
    graph[A-1][B-1] = true;
    graph[B-1][A-1] = true;
  }

  bool visited[MAX_N];
  for (ll i = 0; i < N; i++) {
    visited[i] = false;
  }

  visited[0] = true;
  
  ll ans = dfs(0, visited);
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
a=list(map(int,input().split()))
r=a[0]
ans=0
for i in range(1,n):
    if a[i]<r:
        ans+=(r-a[i])
    else:
        r=a[i]
print(ans)

Measured memory_bytes: 96548
#include <stdio.h>
#include <iostream>

#include <bits/stdc++.h>


using namespace std;

#define INPUT_INT(valName) int valName; cin >> valName
#define INPUT_LLINT(valName) long long int valName; cin >> valName;
#define INPUT_STR(valName) string valName; cin >> valName;
#define INPUT_LINE(valName) string valName; getline(cin,s);
#define INPUT_VECTOR_INT(valName, N) vector<int> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }
#define INPUT_VECTOR_DOUBLE(valName, N) vector<double> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }

#define OUTPUT(A) cout << (A) << endl;
#define OUTPUT2(A, B) cout << (A) << " " << (B) << endl;
#define OUTPUT3(A, B, C) cout << (A) << " " << (B) << " " << (C) << endl;

#define REP(valName, N) for(int valName = 0; valName < N; ++valName)

vector<string> split(const string& str, char delimiter) {
	vector<string> ret;
	string tmp = "";
	for (auto c : str) {
		if (c != delimiter) {
			tmp.push_back(c);
		} else {
			ret.push_back(tmp);
			tmp = "";
		}
	}
	ret.push_back(tmp);
	return ret;
}

template <typename T> void sortAsc(vector<T>& v) { sort(v.begin(), v.end(), less<T>()); }
template <typename T> void sortDesc(vector<T>& v) { sort(v.begin(), v.end(), greater<T>()); }

template <typename T> void insert(vector<T>& dest, const vector<T>& src) { copy(src.begin(), src.end(), back_inserter(dest)); }

template <long long int MOD> long long int mod_inv(long long int a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}

template <long long int MOD> long long int mod_add(long long int a, long long int b) {
	return (a + b) % MOD;
}

template <long long int MOD> long long int mod_sum(long long int a, long long int b) {
	return (a - b) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b) {
	return (a % MOD) * (b % MOD) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b, long long int c) {
	return mod_mul<MOD>(a, mod_mul<MOD>(b, c));
}

template <long long int MOD> long long int mod_div(long long int a, long long int b) {
	return (a % MOD) * mod_inv<MOD>(b) % MOD;
}


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

map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

int main() {

	// TODO: streamやめる

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

	INPUT_INT(N);

	int X = ceilf((float)N / 1.08f);

	int n = (int)(X * 1.08f);
	if ( n == N ){
		OUTPUT(X);
	} else {
		OUTPUT(":(")
	}


	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]

ans = []
dl = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1)]
for i, row in enumerate(S):
    row_list = []
    for j, grid in enumerate(row):
        if grid == '#':
            print('#', end='')
            continue

        cnt = 0
        for dx, dy in dl:
            if i + dx < 0 or H - 1 < i + dx or j + dy < 0 or W - 1 < j + dy:
                continue
            elif S[i+dx][j+dy] == '#':
                cnt += 1
        print(cnt, end='')
    print('\n', end='')

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

int N,L;
int buf[10];
int data[30];
int main(){
  while( cin >> N >> L && (N||L) ){
    int ic=0;
    while(1){
      data[ic] = N;
      for(int i=0;i<ic;i++){
	if( data[i] == N ){
	  cout << i << " " << data[i] << " " << ic - i << endl;
	  goto ende;
	}
      }
      for(int i=0;i<L;i++){
	buf[i] = N%10;
	N/=10;
      }
      sort(buf,buf+L);
      int maxi = 0, mini = 0;
      for(int i=0;i<L;i++){
	maxi *= 10;
	mini *= 10;
	maxi += buf[L-i-1];
	mini += buf[i];
      }
      N = maxi - mini;
      ic++;
    }
  ende:;
  }  
}

Measured memory_bytes: 1180
<?php

fscanf(STDIN, "%d", $n);

$array = explode(' ',trim(fgets(STDIN)));
sort($array);
$cnt = 0;

for ($i=0; $i < $n; $i++) { 
    for ($j=$i + 1; $j < $n; $j++) { 
        for ($k=$j + 1; $k < $n; $k++) { 
            if($array[$i] !== $array[$j] && $array[$j] !== $array[$k] && $array[$i] + $array[$j] > $array[$k]){
                $cnt++;

            }
        }
    }
}

echo $cnt;




Measured memory_bytes: 16160
#include<stdio.h>

int main(void){
    long int i,N;
    scanf("%ld",&N);
    if(N <= 2){
        printf("0");
        return 0;
    }
    char S[10];
    long int count[5] = {0,0,0,0,0};
    
    for(i = 0;i < N;i++){
        scanf("%s",S);
        if(S[0] == 'M') count[0]++;
        if(S[0] == 'A') count[1]++;
        if(S[0] == 'R') count[2]++;
        if(S[0] == 'C') count[3]++;
        if(S[0] == 'H') count[4]++;
    }
    
    long int ans = 0;
    ans += count[0]*count[1]*count[2];
    ans += count[0]*count[1]*count[3];
    ans += count[0]*count[1]*count[4];
    ans += count[0]*count[2]*count[3];
    ans += count[0]*count[2]*count[4];
    ans += count[0]*count[3]*count[4];
    ans += count[1]*count[2]*count[3];
    ans += count[1]*count[2]*count[4];
    ans += count[1]*count[3]*count[4];
    ans += count[2]*count[3]*count[4];

    printf("%ld",ans);

}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
#define rep(i, n) for ( int i= 0; i < n; i++)
#define MAX 100000
#define LIM 200

double power2(int n){
    double p = 1.0;
    for ( int i = 0; i < n; i++ ) p *= 2.0;
    return p;
}

main(){
  double P[LIM+1], T[LIM+1];
  double E[MAX+1];
  double R[LIM+1];
  
  for ( int i = 0; i <= LIM; i++ ) R[i] = 1.0/power2(i);
  
  rep(i, MAX+1) E[i] = 0.0;
  rep(j, LIM+1) P[j] = 0.0;
  P[1]  = E[1] = 1.0;

  for ( int i = 1; i <= MAX; i++ ){

    rep(a, LIM+1) T[a] = 0.0;
    for ( int j = 0; j <= min(i, LIM); j++ ){
      if ( j+1 <= LIM ){
	T[j+1] += P[j]*(R[j]);
      }
      T[0] += P[j]*(1.0 - R[j]);
    }

    for ( int j = 0; j <= min(i, LIM); j++ ){
      if ( i+1 <= MAX ) E[i+1] += P[j]*(R[j]);
    }
    rep(a, LIM+1) P[a] = T[a];
  }

  for ( int i = 2; i <= MAX; i++ ) E[i] += E[i-1];


  int n;
  while( cin>> n && n ) printf("%.12lf\n", E[n]);

}

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

using namespace std;

using ll = long long;
using ld = long double;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<string>
#include<algorithm>
#include <utility>
#include<stdio.h>
#include<climits>

using namespace std;

int main(void){
    int n,m;
    int c,d;
    int f[1000] = {};
    cin >> n >> m;
    int i,j;
    for(i = 0;i < m;i++){
        cin >> c >> d;
        for(j = c;j < d;j++){
            f[j] = 1;
        }
    }
    for(i = 0,j = 0;i < n;i++){
        if(f[i]) j++;
    }
    cout << n+1+2*j << endl;
}

Measured memory_bytes: 1164