akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;			
	   
int main() {
			fast
			// #ifndef ONLINE_JUDGE
			// freopen("input.txt","r",stdin);
			// freopen("output.txt","w",stdout);
			// #endif

			ll t;
			t=1;
			while(t--)
			{
				ll n;
				cin>>n;
				map<ll,ll>id;
				ll sum=0;
				for(ll i=0;i<n;i++)
				{
					ll x;
					cin>>x;
					id[x]+=1;
					sum+=x;
				}
				ll q;
				cin>>q;
				while(q--)
				{
					ll a,b;
					cin>>a>>b;
					sum-=(a*id[a]);
					
					sum+=(b*id[a]);
					id[b]+=id[a];
					id[a]=0;
					cout<<sum<<endl;
					
					
				}
			

                
			}
			return 0;
		 }	


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

int main()
{
  
  string s;
  cin>>s;
   
  for(int i=0;i<s.size();i++)
  {
  if(s[i]== 'R' && (i+1)%2 == 0)
  {
    cout<<"No"<<endl;
    return 0;
  }
    else if(s[i]== 'L' && (i+1)%2 != 0)
  {
    cout<<"No"<<endl;
    return 0;
  }
   
  }
   cout<<"Yes"<<endl;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
 
signed main()
{
    gearup;
    int x;cin>>x;
    if(x >= 30)out("Yes");
    else out("No");
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];

int main(){
	int n,m,T;
	cin>>T>>n;
	cout<<(T*1.0/n)<<endl; 
	return 0; 
}


Measured memory_bytes: 256
/*input
2
abcab 5
cba 3
*/

#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<ll, int>;

struct E {
  int to, co;
  E(int to = 0, int co = 0): to(to), co(co) {}
};

string rev(string s) {
  reverse(s.begin(), s.end());
  return s;
}

int main() {
  int m;
  cin >> m;
  vector<string> s(m);
  vector<int> c(m);
  rep(i, m) cin >> s[i] >> c[i];
  rep(i, m) {
    s.push_back(rev(s[i]));
    c.push_back(c[i]);
  }
  int n = 1;
  vector<vector<int>> id(m*2);
  rep(i, m*2) {
    int l = s[i].size();
    id[i].resize(l);
    rep(j, l) {
      id[i][j] = n++;
    }
  }

  vector<vector<E>> g(n);
  rep(i, m*2) {
    int l = s[i].size();
    rep(j, l) {
      int v = id[i][j];
      rep(ni, m*2) {
        if (i/m == ni/m) continue;
        int nl = s[ni].size();
        int w = min(nl, l-j);
        if (s[i].substr(j, w) != s[ni].substr(0, w)) continue;
        int u = 0;
        if (nl > w) {
          u = id[ni][w];
        }
        else if (l > j+w) {
          u = id[i][j+w];
        }
        else u= 0;
        g[v].emplace_back(u, c[ni]);
      }
    }
  }

  const ll INF = 1e18;
  vector<ll> dist(n, INF);
  priority_queue<P, vector<P>, greater<P>> q;
  auto push = [&](int v, ll x) {
    if (dist[v] <= x) return;
    dist[v] = x;
    q.emplace(x, v);
  };

  rep(i, m) push(id[i][0], c[i]);
  while (!q.empty()) {
    ll x = q.top().first;
    int v = q.top().second;
    q.pop();
    if (dist[v] != x) continue;
    for (E e: g[v]) {
      push(e.to, x+e.co);
    }
  }

  ll ans = dist[0];
  rep(i, m*2) {
    int l = s[i].size();
    rep(j, l) {
      string t = s[i].substr(j);
      if (t == rev(t)) {
        ans = min(ans, dist[id[i][j]]);
      }
    }
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3724
import java.util.*;
public class Main {
    private static long dp[][];
    private static int N;
    private static int A[];
    private static int B[];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt() * 1000;
        int A = sc.nextInt() * 1000;
        int H[] = new int[N];
        for(int i=0; i<N; i++) {
            H[i] = sc.nextInt();
        }

        int X[] = new int[N];
        for(int i=0; i<N; i++) {
            X[i] = Math.abs((T - H[i] * 6) - A);
        }

        int res = 0;
        int minval = X[0];
        for(int i=0; i<N; i++) {
            if(minval > X[i]) {
                minval = X[i];
                res = i;
            }
        }
        System.out.println(String.format("%d", res + 1));
    }
}


Measured memory_bytes: 23784
str = gets.chomp
q = gets.chomp.to_i

q.times do |i|
   order = gets.chomp.split
   partial_str = str[(order[1].to_i)..(order[2].to_i)]
   if order[0] == "print"
      puts partial_str
   elsif order[0] == "reverse"
      reverse_partial_str = partial_str.reverse
      str = str.sub(/#{partial_str}/, reverse_partial_str)
   elsif order[0] == "replace"
      str[(order[1].to_i)..(order[2].to_i)] = order[3]
   end
end

Measured memory_bytes: 8828
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        maximumProfit();
    }

    private static void maximumProfit() {
        Scanner in = new Scanner(System.in);
        int length = in.nextInt();
        int min = in.nextInt();
        int next = in.nextInt();
        int maxDiff = next - min;
        if (next < min) { min = next; }
        for (int i = 0; i < length - 2; i++) {
            int value = in.nextInt();
            if (value - min > maxDiff) {
                maxDiff = value - min;
            }
            if (value < min) {
                min = value;
            }
        }
        System.out.println(maxDiff);
    }
}


Measured memory_bytes: 99432
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
dic = {'SUN':0,'MON':1,'TUE':2,'WED':3,'THU':4,'FRI':5,'SAT':6}
print(7 - dic[input()])


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



int main()
{
    string s;
    cin>>s;
    int i,j,k=0,l=s.length();
    stack <char> stk;
    for(i=0;i<l;i++)
    {
        if(stk.empty())
        {
            stk.push(s[i]);
        }
        else
        {
            if(stk.top()!=s[i])
            {
                stk.pop();
                k+=2;
            }
            else
            {
                stk.push(s[i]);
            }
        }
    }
    cout<<k;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
int n,x[505],a[250005],st[250005],top,now;
bool check[250005];
struct sd{int w,pos;bool operator < (const sd &fu) const {return pos<fu.pos;};}in[505];
int main() {
	scanf("%d",&n);for(int i=1;i<=n;++i) {scanf("%d",&x[i]);a[x[i]]=i;in[i]=(sd){i,x[i]};check[x[i]]=true;}
	sort(in+1,in+1+n);for(int i=1;i<=n*n;++i) if(!check[i]) st[++top]=i;
	for(int i=1;i<=n;++i) {
		for(int j=1;j<in[i].w;++j) a[st[++now]]=in[i].w;
		if(st[now]>in[i].pos) {printf("No");return 0;}
	}st[++top]=2147483647;
	for(int i=n;i;--i) {
		for(int j=n;j>in[i].w;--j) a[st[--top]]=in[i].w;
		if(st[top]<in[i].pos) {printf("No");return 0;}
	}
	puts("Yes");
	for(int i=1;i<=n*n;++i) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\n'
#define pii pair<int, int>
#define min3(a,b,c) min(a, min(b, c))
#define max3(a,b,c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n; cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n,greater<int>());
    int cnt=1,ans=arr[0];
    for(int i=1;i<n-1;i++){
        cnt++; ans+=arr[i];
        if(cnt==n-1) break;
        cnt++; ans+=arr[i];
        if(cnt==n-1) break;
    }
    cout<<ans<<endl;

}

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

int main(){
    int N; cin>>N;
    int h[N],now[N];
    rep(i,N)cin>>h[i];
    int stop[N];
    rep(i,N){
        if(h[i]==0)stop[i]=1;
        else stop[i]=0;    
        now[i]=0;
    }
    int ans=0;
    while(1){
        int cnt=1,flag=1;
        rep(i,N){
            if(flag==0&&stop[i]==1){
                cnt++;
                flag=1;
            }
            if(flag==1&&stop[i]==0)flag=0;
            if(stop[i]==0)now[i]++;
            if(flag==1&&i==N-1)cnt--;
        }
        ans+=cnt;
        rep(i,N)if(now[i]==h[i]&&stop[i]==0)stop[i]=1;
        int fin=0;
        rep(i,N)if(stop[i]==1)fin++;
        if(fin==N)break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

vi c,d;

struct edge {
    int to,a,b;
};

vector<vl> dijkstra(P start,const vector<vector<edge>>& v) {
    int n = v.size();
    vector<vl> dist(n,vl(6000,linf));
    priority_queue<pair<ll,P>,vector<pair<ll,P>>,greater<pair<ll,P>>> q;
    q.emplace(0LL,start);
    dist[start.first][start.second] = 0;
    while(!q.empty()) {
        auto p = q.top();
//        cout << p.second.first << " " << p.second.second << endl;
        q.pop();
        if(dist[p.second.first][p.second.second] < p.first) continue;
        for(auto e : v[p.second.first]) {
            if(p.second.second-e.a < 0) continue;
            if(chmin(dist[e.to][p.second.second-e.a],p.first+e.b)) {
                q.push({p.first+e.b,{e.to,p.second.second-e.a}});
            }
        }
        int nc = c[p.second.first];
        int nd = d[p.second.first];
        if(p.second.second+nc < 6000) {
            if(chmin(dist[p.second.first][p.second.second+nc],p.first+nd)) {
                q.push({p.first+nd,{p.second.first,p.second.second+nc}});
            }
        }
    }
    return dist;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m,s;
    cin >> n >> m >> s;
    vector<vector<edge>> G(n);
    rep(_,m) {
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G[u].pb(edge{v,a,b});
        G[v].pb(edge{u,a,b});
    }
    c.resize(n);
    d.resize(n);
    rep(i,n) cin >> c[i] >> d[i];
    auto v = dijkstra({0,min(s,5999)},G);
    rep2(i,1,n) {
        ll ans = linf;
        rep(j,6000) chmin(ans,v[i][j]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 9780
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#define ll long long int
#define skip cin>>ws;
#define vll vector<ll> 
#define vb vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define vs vector<string>
#define vvpll vector<vector<pair<ll, ll>>>
#define pb push_back
#define pob pop_back()
#define MOD (ll)(1e9 + 7)
#define test ll t; cin>>t; while(t--)

using namespace std;

void enter(vll &ar)
{
    ll n = ar.size();

    for(ll i=0;i<n;i++)
    {
        cin>>ar[i];
    }
}

void show(vll &a)
{
    ll n = a.size();

    for(ll i=0;i<n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void SieveOfErat1sthenes(int n, vll &pri) 
{ 
    vb prime(n+1, true); 
   
    for (int p=2; p*p<=n; p++) 
    { 
        
        if (prime[p] == true) 
        { 
            pri.pb(p);
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll mo(ll a)
{
    return a%MOD;
}

bool compare(pll a, pll b)
{
    return a.first>b.first;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll h, w;
    cin>>h>>w;

    vvll mat(h, vll(w));

    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
        {
            char ch;
            cin>>ch;

            if(ch=='.') mat[i][j] = 1;
            else mat[i][j] = 0;
        }
    }

    vvll ans(h, vll(w));

    if(mat[0][0]) ans[0][0] = 1;

    for(ll i=1;i<w;i++) if(mat[0][i]) ans[0][i] = ans[0][i-1];
    for(ll i=1;i<h;i++) if(mat[i][0]) ans[i][0] = ans[i-1][0];

    for(ll i=1;i<h;i++)
    {
        for(ll j=1;j<w;j++)
        {
            if(mat[i][j]) 
            {
                ans[i][j] = mo(mo(ans[i-1][j]) + mo(ans[i][j-1]));
            }
        }
    }

    cout<<ans[h-1][w-1]<<"\n";

    return 0;
}


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

int main(){
  int N;
  cin>>N;
  int a[N];
  int i;
  for(i=0;i<N;++i) cin>>a[i];
  int cnt=0;
  while(true){
      bool isOdd=false;
    for(i=0;i<N;++i){
      if(a[i]%2!=0) isOdd=true;
    }
    if(isOdd) break;
    
    for(i=0;i<N;++i) a[i]/=2;
    ++cnt;
  }
  cout<<cnt<<endl;
  return 0;
  }
      


Measured memory_bytes: 3084
#include<stdio.h>
int main()
{
    int A,B,C,X,Y,Z,temp;
    A=X;
    B=Y;
    C=Z;
    scanf("%d %d %d",&X,&Y,&Z);
    if(X>=1 && X<=100 && Y>=1 && Y<=100 && Z>=1 && Z<=100)
    {
        temp=X;
        X=Y;
        Y=temp;
        temp=X;
        X=Z;
        Z=temp;
    }



    printf("%d %d %d\n",X,Y,Z);
    return 0;





}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;

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

  int n; cin >> n;
  string s;
  int p;
  vector<tuple<string, int, int> > tp(n);
  rep(i, n) {
    cin >> s >> p;
    tp[i] = make_tuple(s, -p, i+1);
  }
  sort(all(tp));

  rep(i, n) cout << get<2>(tp[i]) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
  char mark;
  int num;
}Data;

void isStable(Data[] ,Data[],int);
void trace(Data A[], int n){
  int i;

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%c%d", A[i].mark, A[i].num);
  }
  printf("\n");
}

int main(){
  int n, i, j, flag = 1, minj;
  Data A[100],B[100],tmp,key[100];
  
  scanf("%d%*c", &n);

  for ( i = 1; i <= n; i++ ){
    scanf("%c%d%*c", &A[i].mark, &A[i].num);
  }
 
  for(i = 1;i <= n ; i++)B[i] = A[i];
  
  while(flag!=0){
    
    flag = 0;
    
    for(j = n ;1 < j ;j--){
      
      if(B[j].num < B[j-1].num){
	tmp = B[j];
	B[j] = B[j-1]; 
	B[j-1] = tmp;

	flag = 1;	
      }
    }
  }
  
  trace(B, n);
  printf("Stable\n");
  
  for(i = 1;i <= n ; i++){
    key[i] = B[i];
    B[i] = A[i];
  }
  
  for ( i = 1; i <= n; i++ ){
    minj = i;
    
    for ( j = i; j <= n ; j++){
      if( B[j].num< B[minj].num ){
	minj = j;
      }
    }
    if(minj != i){
      tmp = B[i];
      B[i] = B[minj];
      B[minj] = tmp;
    }
  }
  
  trace(B, n);
  isStable(key,B,n);
  
  return 0;
}
void isStable(Data A[],Data B[],int n){
  int i,key = 0;

  for(i=1;i<=n;i++){
    if(A[i].num == B[i].num){
      if(A[i].mark != B[i].mark)key = 1;
    }
  }
  if(key==0) printf("Stable\n");
  else printf("Not stable\n");
  
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll N;
    cin >> N;
    map<ll,ll> mp;
    ll ans = 0;
    for (ll i = 0;i<N;i++) {
        ll a;
        cin >> a;
        mp[a]++;
        ans += a;
    }
    ll Q;
    cin >> Q;
    for (ll i = 0;i<Q;i++) {
        ll b,c;
        cin >> b >> c;
        ans -= b*mp[b];  //差分
        mp[c] += mp[b]; //追加
        ans += c*mp[b];  //差分
        mp[b] = 0; //０になる
        cout << ans << endl;
    }
}

Measured memory_bytes: 9576
# dp[j][i]=(区間[i,j]が残っているとき次の手番の得点-そうじゃない人の得点)
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
INF=-10**14
dp=[[0]*(i+1) for i in range(n)]
for i in range(n):
    dp[i][i]=a[i]
for i in range(1,n):
    for j in range(i-1,-1,-1):
        dp[i][j]=max(a[i]-dp[i-1][j],a[j]-dp[i][j+1])
print(dp[-1][0])

Measured memory_bytes: 77148
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

# define inOut(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
# define RESET(a) memset(a,0,sizeof(a))
# define MEMO(a) memset(a,-1,sizeof(a))
# define DEBUG puts("Debug-Has-Come-Until-Here")


typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	cin.tie(NULL);
	
	int height, max1(0), max2(0), max3(0);
	while(scanf("%d", &height) != EOF){
		if (height >= max1){
			max3 = max2;
			max2 = max1;
			max1 = height;
		}else if (height >= max2){
			max3 = max2;
			max2 = height;
		}else if (height >= max3){
			max3 = height;
		}
	}
	printf("%d\n%d\n%d\n", max1, max2, max3);

	return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

struct UnionFind
{
	vector<long long> par, wei;

	void init(long long n) {par.assign(n, -1); wei.assign(n, 0);}

	long long root(long long x)
	{
		if (par[x] < 0) return x;
		else
		{
			ll r = root(par[x]);
			assert(par[x] >= 0);
			wei[x] += wei[par[x]];
			return par[x] = r;
		}
	}

	ll weight(ll x)
	{
		root(x);
		return wei[x];
	}

	ll diff(ll x, ll y)
	{
		return wei[y] - wei[x];
	}

	bool merge(long long x, long long y, long long w)
	{
		w += weight(x);
		w -= weight(y);
		
		x = root(x);
		y = root(y);
		if(x == y) return false;
		// if (rank(x) < rank(y))
		if (par[x] > par[y]) swap(x, y), w *= -1;
		par[x] += par[y];
		par[y] = x;

		wei[y] = w;
		return true;
	}

	bool issame(long long x, long long y)
	{
		return root(x) == root(y);
	}

	long long rank(long long x)
	{
		return -par[root(x)];
	}
};


int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	UnionFind uf;
	uf.init(N);

	REP(i, M)
	{
		ll l, r, d; cin >> l >> r >> d;
		--l, --r;
		if (uf.issame(l, r))
		{
			if (uf.diff(l, r) != d)
			{
				std::cout << "No" << std::endl;
				return 0;
			}
		}
		else
		{
			uf.merge(l, r, d);
		}
	}

	std::cout << "Yes" << std::endl;
	
}


Measured memory_bytes: 1792
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string w;
  int p;
  map<string, vi> m;
  while (cin >> w >> p) m[w].pb(p);
  for (auto x : m) {
    cout << x.fi << endl;
    sort(all(x.se));
    if (x.se.size()) cout << x.se[0];
    loop(i, 1, x.se.size()) cout << ' ' << x.se[i];
    cout << endl;
  }
}

Measured memory_bytes: 3180
import java.io.*;
import java.util.*;
 
public class Main{
	public void solve(){
		int H = nextInt();
		int W = nextInt();
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(next().equals("snuke")){
					out.print((char)(j + 'A'));
					out.println(i + 1);
				}
			}
		}
		
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

Measured memory_bytes: 8396
#include<stdio.h>
#include<math.h>

int main (void){
	
	long int n,dis[1001]={},manD=0,eucD=0,p3D=0,cheD=0,d,i;
	long int disx[1001]={},x;
	long int disy[1001]={},y;
	long int max=0;
	
	x=0;
	y=0;
	
	scanf("%ld",&n);
	//x??§?¨?
	for(i=0;i<n;i++){
		scanf("%ld",&disx[i]);
	}
	//y??§?¨?
	for(i=0;i<n;i++){
		scanf("%ld",&disy[i]);
	}
	
	for(i=0;i<n;i++){
	
	x=disx[i];
	y=disy[i];
	d=x-y;
	
	if(d<0){
		d = -1*d;
	}
	if(max<d){
		max=d;
	}
	//p=1
	manD +=d;
	
	//p=2
	eucD += d*d;
	
	//p=3
	
	p3D += d*d*d;
	}
	printf("%lf\n",(double)manD);
	printf("%lf\n",sqrt(eucD));
	printf("%lf\n",pow(p3D,1.0/3.0));
	printf("%lf\n",(double)max);

return 0;
}

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

int main()
{
	int n, k;
	cin >> n >> k;

	string s;
	cin >> s;

	char pre;
	pre = s[0];
	int ret = 0;
	int diff = 0;
	for (int i = 1; i < n; ++i) {
		if (pre == s[i]) {
			++ret;
		}
		else {
			++diff;
		}
		pre = s[i];
	}

	if (2 * k < diff) {
		ret += 2 * k;
	}
	else {
		ret += diff;
	}

	cout << ret << endl;

	return 0;
}

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

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

    if(a >= k)
        cout << k << "\n";
    else if(a + b >=k)
        cout << a << "\n";
    else
        cout << a - (k - a - b) << "\n";
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define FOR(i,x) for(i=1;i<=x;i++)
using namespace std;
using ll = long long int;
typedef vector<ll> vi;
ll k,b,ar[11]={};
void Next_letter()
{
	char k;
	cin>>k,k++;
	cout<<k<<"\n";
}
void concat()
{
	string a,b;
	cin>>b>>a;
	cout<<a+b<<"\n";
}
void pass()
{
	cin>>k>>b;
	cout<<(k==b?"Yes":"No")<<"\n";
	return;
}
int main()
{
    pass();
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0033
public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N; 
	static int[] is = new int[10];
	public static void main(String[] args) {
		N = sc.nextInt();
		while (N-- > 0) {
			for (int i = 0; i < 10; i++) is[i] = sc.nextInt();
			if (rec(0, 0, 0)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
	
	static boolean rec(int idx, int l, int r) {
		if (idx == 10)
			return true;
		
		boolean ret = false;
		if (l < is[idx])
			ret |= ret | rec(idx + 1, is[idx], r);
		if (r < is[idx])
			ret |= rec(idx + 1, l, is[idx]);
		
		return ret;
	}
	
}

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

using P = pair<int, int>;
using ll = long long;

int main() {
  int N;
  cin >> N;
  int a, b;
  vector<P> p(N);
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    p[i] = P(a, b);
  }

  sort(p.begin(), p.end());
  ll ans = 0;
  ans += p[0].first - 1;
  for (int i = 0; i < N - 1; i++) {
    ans += min(p[i+1].first - p[i].first, p[i].second - p[i+1].second);
  }
  ans += p[N-1].second;

  cout << ans + 1 << endl;

  return 0;
}


Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = LS()
    t = sorted(s)
    if s[0] == s[1]:
        print("=")
    elif s[0] == t[0]:
        print("<")
    else:
        print(">")

#B
def B():
    x,y,z = LI()
    k = 0
    for i in range(1000000000):
        k += y+z
        if k+z>x:
            print(i)
            quit()

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
       ll n=0;
       string s,t;
       cin>>s>>t;
       for(ll i=0;i<s.size();i++)
       {
           if(s[i]!=t[i])
           n++;
       }
       cout<<n;
       
        
    }
    return 0;
}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
#define MS(x, i) memset(x, i, sizeof x)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define NOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-5;
char F[200];

inline ll read() {
    ll ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-') sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        ret = ret*10 + ch - '0';
        ch = getchar();
    } 
    return ret*sgn;
}

inline void write( ll x ) {
    ll tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
       F[cnt++] = tmp % 10 + '0';
       tmp /= 10;
    }
    while(cnt > 0) putchar(F[--cnt]);
}

int main()
{
    NOS
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    
    vector<ll > sums;

    int n, m, k;
    cin >> n >> m >> k;

    for(int i = 0; i < n; i++)
    {
        ll nums;
        cin >> nums;

        if(i == 0)
            sums.push_back(nums);
        else
        {
            sums.push_back(sums[i - 1] + nums);
        }
    }

    ll maxans = upper_bound(sums.begin(), sums.end(), k) - sums.begin();
    ll nowsum = 0;
    ll flag = 0;
    for(int i = 1; i <= m; i++)
    {
        ll nums;
        cin >> nums;
        nowsum += nums;

        if(nowsum > k) flag = 1;
        if(!flag)
            maxans = max(maxans, (ll)(upper_bound(sums.begin(), sums.end(), k - nowsum) - sums.begin() + i));
    }

    cout << maxans << endl;
    
    return 0;
}

Measured memory_bytes: 5276
a, b, c, x, y = map(int, input().split())
ans = 0
ans += 2*c*min(x, y)
if x < y:
  ans += (y-x)*b
else:
  ans += (x-y)*a

ans = min(ans, a*x+b*y)
print(min(ans, 2*c*max(x, y)))

Measured memory_bytes: 9176
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

int main()
{
    ll N;
    cin >> N;

    
    vector<ll> a(1000000);
    vector<ll> cnt;

    ll n = N;
    FOR(i, 2, 1000000)
    {
        ll c = 0;
        while (n % i == 0)
        {
            c++;
            n /= i;
        }

        cnt.push_back(c);
    }

    if(n >= 2){
        cnt.push_back(1);
    }

    ll ans = 0;
    for(auto b : cnt){
        ll x = 1;
        while(b - x >= 0){
            ans++;
            b -= x;
            x++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 19392
#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>;
const int INF = 1 << 29;
 
int main() {
	int a, b;
	cin >> a >> b;
	if (a * b == 0) cout << "Zero" << endl;
	else if (a > 0 && b > 0) cout << "Positive" << endl;
	else if (a < 0 && b > 0) cout << "Zero" << endl;
	else {
		int now = b - a + 1;
		if (now % 2 == 0) cout << "Positive" << endl;
		else cout << "Negative" << endl; 
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main() {
	string s,t;
	cin>>s>>t;
	int n=s.size(),m=t.size();
	vector<vector<int>> is(26);
	rep(i,n) is[s[i]-'a'].push_back(i);
	rep(i,n) is[s[i]-'a'].push_back(i+n);
	ll ans=0;
	int p=0;
	rep(i,m){
		int c=t[i]-'a';
		if(is[c].size()==0){
			puts("-1");
			return 0;
		}
		p=*lower_bound(is[c].begin(),is[c].end(),p)+1;
		if(p>=n){
			p-=n;
			ans+=n;
		}
	}
	ans+=p;
	cout<<ans<<endl;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

string f(int x){
  string t;
  for(int i=0;i<3;i++){
    t+=x%10+'0';
    x/=10;
  }
  reverse(t.begin(),t.end());
  return t;
}
int main() {
  int N;
  cin>>N;
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<=999;i++){
    string t=f(i);
    int v=0;
    for(int j=0;j<N;j++){
      if(s[j]==t[v]){v++;}
    }
    if(v==3){ans++;}
  }
  cout<<ans<<endl;
  return 0;  
}

Measured memory_bytes: 3620
#include <iostream>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <array>
#include <memory>

#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int __i = 0; __i<(int)a.size();__i++){cin>>a[__i];}

// jimjam

template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
	if (c.size() == 0) {os << "{}"; return os;}
	os << "{" << c[0];
	for (int64_t i = 1; i < (int)c.size(); i++) {os <<", "<<c[i];}
	os << "}";
	return os;
}

using namespace std;

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

	int n; cin >> n;
	vector<string> v = {
		"AC",
		"WA",
		"TLE",
		"RE"
	};

	map<string,int> cnt;
	for (string s: v) cnt[s]=0;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		cnt[s]++;
	}
	for (string s: v) {
		cout << s << " x " << cnt[s] << endl;
	}

	return 0;
}




Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
using namespace std;
typedef pair<int, int> P;
 
int main(void) {
    string s;
    cin >> s;
 
    int sum_all = 0, sum, lev = 0;
    stack<int> st;
    stack<P> stP;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '\\')
            st.push(i);
        else if (s[i] == '/') {
            if (st.empty()) continue;
            int j = st.top(); st.pop();
 
            sum_all += i - j;
            sum = i - j;
            while (stP.size() > 0 && j < stP.top().first) {
                sum += stP.top().second;
                stP.pop();
            }
            stP.push(P(j, sum));
        }
    }
 
    vector<int> v;
    while (stP.size()) {
        v.push_back(stP.top().second);
        stP.pop();
    }
    reverse(v.begin(), v.end());
 
 
    cout << sum_all << endl;
    cout << v.size();
    for (int  i = 0; i < v.size(); i++)
        cout << " " << v[i];
    cout << endl;
 
    return 0;
}


Measured memory_bytes: 3340
N, D = [int(nd) for nd in input().split()]
X = []
for n in range(N):
  X.append([int(x) for x in input().split()])
  
ans = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    d_ij = 0
    for d in range(D):
      d_ij += (X[i][d] - X[j][d]) ** 2
    d_ij = (d_ij) ** (1/2)
    if d_ij == int(d_ij):
      ans += 1
print(ans)

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 998244353;

    string S;
    cin >> S;
    reverse(begin(S), end(S));
    unsigned long K;
    cin >> K;
    K = min<unsigned long>(count(begin(S), end(S), '1'), K);

    vector<vector<unsigned long>> dp(K + 1), tmp(K + 1);
    for(unsigned long i{0}; i <= K; ++i)dp[i] = vector(i + 1, 0UL);
    for(unsigned long i{0}; i <= K; ++i)tmp[i] = vector(i + 1, 0UL);
    dp[0][0] = 1;
    
    unsigned long cnt{0};
    for(const auto& c : S)if(c == '1')++cnt;
    else{
        for(auto&& i : tmp)fill(begin(i), end(i), 0UL);
        for(unsigned long i{0}; i < K; ++i)for(unsigned long j{0}; j + i < K; ++j){
            tmp[j + i + 1][i] = tmp[j + i][i] + dp[j + i][i];
            if(j >= cnt)tmp[j + i + 1][i] -= dp[j - cnt + i][i];
        }
        for(auto&& i : dp)partial_sum(begin(i), end(i), begin(i));
        for(unsigned long i{0}; i <= K; ++i)for(unsigned long j{0}; j <= i; ++j)(dp[i][j] += tmp[i][j]) %= MOD;
        cnt = 0;
    }
    for(auto&& i : dp)partial_sum(begin(i), end(i), begin(i));
    
    unsigned long ans{0};
    for(const auto& i : dp)ans += i.back();
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 4220
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <chrono>
#include <ctime>

using namespace std;

#define en '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double EPS = 1e-9;
const int INF = 1e9 + 7;
const ll LINF = 1e18;
const double PI = 3.1415926535897932384626433832795;
const int MAX_SIZE = 5e5;
ld START_TIME, TIME;

void fast_in_out() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    START_TIME = clock();
}

void solve() {
    int n, m;
    cin >> n >> m;
    int s = 0;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        s += x;
    }
    cout << max(n - s, -1) << en;
}

int main() {
    fast_in_out();
    TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    cerr << en << TIME << " sec." << en;
    return 0;
}

/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int N;

	cin >> N;
	vector<int> C(N), S(N), F(N);
	for (int i = 1; i < N; i++)
	{
		cin >> C[i] >> S[i] >> F[i];
	}

	for (int i = 1; i < N; i++) {
		int ans = 0;
		for (int j = i; j < N; j++)
		{
			if (ans <= S[j]) ans = S[j] + C[j];
			else ans = S[j] + C[j] + ceil((double)(ans - S[j]) / F[j])*F[j];
		}
		cout << ans << endl;
	}
	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
gets
x = gets.split.map(&:to_f)
y = gets.split.map(&:to_f)

def distance(x, y, p)
	sum = x.size.times.map{|i|(x[i] - y[i]).abs ** p}.inject(:+)
	sum ** (1.0/p)
end

puts distance(x, y, 1)
puts distance(x, y, 2)
puts distance(x, y, 3)
puts x.size.times.map{|i|(x[i]-y[i]).abs}.max

Measured memory_bytes: 8888
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] s = sc.next().split("");
    int start = 0;
    int end =0;
    for(int i=0; i<s.length; i++){
      if(s[s.length-1-i].equals("A")){
        start = s.length-1-i;
      }
      if(s[i].equals("Z")){
        end = i;
      }
    }
    System.out.println(end - start + 1);
  }
}

Measured memory_bytes: 51600
judge = 1

while judge == 1:
    H, W = (int(x) for x in input().split())
    if H == 0 and W == 0:
        judge = 0
        break
    for h in range(H):
        for w in range(W):
            print("#",end="")
            if w == W-1:
                print("")
    print("")


Measured memory_bytes: 7024
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
	string c;
	cin >> c;
	int l;
	l = c.length();
	int t;
	int check = 0;
	int o00 = 0, o01 = 0, o10 = 0,o11 = 0;
	int max1=0, max2=0;
	for (t = 0; t < l; t++) {
		if (check == 0) {
			if (c[t] == '0') {
				o00 += 1;
			}
			else {
				o01 += 1;
			}
			check = 1;
		}
		else {
			if (c[t] == '0') {
				o10 += 1;
			}
			else {
				o11 += 1;
			}
			check = 0;
		}
	}
	int check1, check2;
	int mini1, mini2;
	int total = 0;
	if (o00 > o01){
		max1 = o00;
		mini1 = o01;
		check1 = 0;
	}
	else{
		max1 = o01;
		mini1 = o00;
		check1 = 1;
	}

	if (o10 > o11){
		max2 = o10;
		mini2 = o11;
		check2 = 0;
	}
	else{
		max2 = o11;
		mini2 = o10;
		check2 = 1;
	}

	if (max1 > max2) {
		total = mini1;
		if (check1 == 0) {
			total += o10;
		}
		else {
			total += o11;
		}
	}
	else {
		total = mini2;
		if (check2 == 0) {
			total += o00;
		}
		else {
			total += o01;
		}

	}

	cout << total;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  long long same;
  same = 0;
  cin >> n;
  vector<int> tall(n);
  for(i=0;i<n;i++) {
    cin >> tall.at(i);
  }
  for(i=0;i<n-1;i++) {
    if(tall.at(i) > tall.at(i+1)) {
      same += tall.at(i) - tall.at(i+1);
      tall.at(i+1) = tall.at(i);
    }
  }
  cout << same << endl;
  return 0;
}

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

#define F first
#define S second

using namespace std;
typedef long double ld;
typedef long long ll;

const int max_n = 100011, inf = 1000111222;
const ll inff = 1000111222333444;

int a[max_n], n, b[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    int s = 0;
    for (int i = 0; i < n + 1; ++i) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        int k1 = min(b[i], a[i]);
        a[i] -= k1;
        b[i] -= k1;
        int k2 = min(b[i], a[i + 1]);
        a[i + 1] -= k2;
        b[i] -= k2;
        ans += k1 + k2;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int x, y, z, stock = 0;
	cin >> x >> y >> z;
	stock = x;
	x = y;
	y = stock;
	stock = x;
	x = z;
	z = stock;
	cout << x << ' ' << y << ' ' << z << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long int lli;
lli gcd(lli m, lli n) {
  if (m % n == 0) {
    return n;
  } else {
    return gcd(n, m % n);
  }
}
int main() {
  lli A, B, C, D;
  cin >> A >> B >> C >> D;
  lli X = C / gcd(C, D) * D;
  lli ans = B - A + 1;
  lli res = B / C + B / D - B / X;
  A--;
  res -= A / C + A / D - A / X;
  cout << ans - res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int H;
        int W;
        while ((H = scanner.nextInt()) != 0 && (W = scanner.nextInt()) != 0) {
            for (int h = 0; h < H; h++) {
                if (h == 0 || h == H-1) {
                    for (int w = 0; w < W; w++) {
                        System.out.print('#');
                    }
                } else {
                    for (int w = 0; w < W; w++) {
                        char c = '.';
                        if (w == 0 || w == W-1) c = '#';
                        System.out.print(c);
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 36120
n,m = map(int, input().split())
h = list(map(int, input().split()))
A = [1 for i in range(n)]

for i in range(m):
    a = list(map(int, input().split()))
    #print(a)
    #print(h)
    if h[a[0]-1] < h[a[1]-1]:
        A[a[0]-1] = 0
    elif h[a[0]-1] == h[a[1]-1]:
        A[a[0]-1] = 0
        A[a[1]-1] = 0
    
    else:
        A[a[1]-1] = 0

print(sum(A))

Measured memory_bytes: 20116
#include <bits/stdc++.h>
using namespace std;
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; }

int n;
struct xydata {
    int x, y;
};

bool cmp1 (const xydata &left, const xydata &right) {
    return left.y > right.y;
}
bool cmp2 (const xydata &left, const xydata &right) {
    return left.x < right.x;
}

int main() {
    cin >> n;
    vector<xydata> red;
    vector<xydata> blue;
    for(int i = 0; i < n; ++i) {
        xydata r;
        cin >> r.x >> r.y;
        red.push_back(r);
    }
    for(int i = 0; i < n; ++i) {
        xydata b;
        cin >> b.x >> b.y;
        blue.push_back(b);
    }

    sort(red.begin(), red.end(), cmp1);
    sort(blue.begin(), blue.end(), cmp2);

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        int cbx = blue.at(i).x;
        int cby = blue.at(i).y;

        for(int j = 0; j < n; ++j) {
            if(red.at(j).x < cbx) {
                if(red.at(j).y < cby) {
                    ans++;
                    red.at(j).x = red.at(j).y = 10000;
                    break;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256