akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	if(count(s.begin(),s.end(),'7')) cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int A = rei();
	int B = rei();
	int C = rei();
	int ans = A+B+C-max(A,max(B,C));
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
/* 
 * Author: pawanmsr
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //
int n;

// Functions //

// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    /* code */
    cin >> n;
    bool seven = false;
    while (n) {
        if (n%10 == 7) {
            seven=true;
            break;
        }
        n /= 10;
    }
    if (seven) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); if (n == 0) cout << endl; REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi c(n - 1);
    vi s(n - 1);
    vi f(n - 1);
    REP(i, n - 1) cin >> c[i] >> s[i] >> f[i];

    REP(i, n - 1) {
        int t = 0;
        FOR(j, i, n - 1) {
            if (t <= s[j]) {
                t = s[j] + c[j];
            } else {
                t += (f[j] - t % f[j]) % f[j] + c[j];
            }
        }
        cout << t << endl;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 3624
import math

N, D = [int(item) for item in input().split()]
X=[]
res = 0
for i in range(N):
  X.append([int(item) for item in input().split()])
for i in range(N):
  for j in range(i+1, N):
    x1 = X[i]
    x2 = X[j]
    dis = 0
    for d in range(D):
      dis += abs(x1[d]-x2[d])**2
    dis = math.sqrt(dis)
    if int(dis) == float(dis):
      res += 1
print (res)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string s;
    cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3588
using System;

class CF2016QAC
{
	static public void Main(string[] args)
	{
		string s = Console.ReadLine();
		int K = int.Parse(Console.ReadLine());

		int[] c = new int[s.Length];
		for(int i=0; i < c.Length; i++)
		{
			c[i] = s[i] - 'a';
		}


		for(int i=0; i < c.Length; i++)
		{
			if(c[i] == 0)
				continue;
			else
			{
				if(26-c[i] <= K)
				{
					K -= 26-c[i];
					c[i] = 0;
				}
			}
			//Console.WriteLine("K={0}", K);
			//Console.WriteLine("c[{0}]={1}", i, c[i]);
		}
		c[c.Length-1] = (c[c.Length-1] + K) % 26;

		for(int i=0; i < c.Length; i++)
		{
			Console.Write((char)('a' + c[i]));
		}
		Console.WriteLine();
	}
}


Measured memory_bytes: 11744
#include <iostream>
#include <string>

using namespace std;

int main(){
    int N, cnt = 0;
    cin >> N;

    for(int i = 1; i < N; i ++){
        for(int j = 1; j < N; j ++){
            if(i * j < N){
                cnt ++;
            }else{
                break;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/f.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int P = 1'000'000'007;
void solve(std::istream &in, std::ostream &out) {
  int n, m;
  in >> n >> m;
  vector<int> xs(n), ys(m);
  for (int &i : xs) in >> i, i = (i + P) % P;
  for (int &i : ys) in >> i, i = (i + P) % P;
  int sum1 = 0, sum2 = 0;
  for (int i = 1; i < n; ++i) {
    int delta = (xs[i] + P - xs[i - 1]) % P;
    (sum1 += (int64_t) delta * i % P * (n - i) % P) %= P;
  }
  for (int i = 1; i < m; ++i) {
    int delta = (ys[i] + P - ys[i - 1]) % P;
    (sum2 += (int64_t) delta * i % P * (m - i) % P) %= P;
  }
  out << (int64_t) sum1 * sum2 % P;
}

Measured memory_bytes: 4004
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, ans[11][3], an;
	an = 0;
	while (1) {
		cin >> n;
		if (n == 0) {
			goto a;
		}
		an = an + 1;
		int a, b;
		ans[an][1] = 0;
		ans[an][2] = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a >> b;
			if (a == b) {
				ans[an][1] = ans[an][1] + a;
				ans[an][2] = ans[an][2] + b;
				goto b;
			}
			if (a > b) {
				ans[an][1] = a + b + ans[an][1];
			}
			if (a < b) {
				ans[an][2] = a + b + ans[an][2];
			}
		b:;
		}
	}
a:;
	for (int i = 1; i <= an; i++) {
		cout << ans[i][1] << " " << ans[i][2] << endl;
	}
}


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

int main(){

 int i,N,m,ans;

 cin >> N;
 ans=0;

 for(i=0;i<N;i++){
    cin >> m;
    while(m%2==0){
         ans++;
         m/=2;
    }
 }

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

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

int main(){
  string s;
  cin>>s;
  if(s.at(0)==s.at(1)){
    if(s.at(2)==s.at(3)&&s.at(2)!=s.at(0)){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  if(s.at(0)==s.at(2)){
    if(s.at(1)==s.at(3)&&s.at(0)!=s.at(3)){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  if(s.at(0)==s.at(3)){
    if(s.at(1)==s.at(2)&&s.at(2)!=s.at(0)){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  
}


Measured memory_bytes: 256
import numpy as np
from numba import njit


@njit('i8[:](i8,i8,i8[:])')
def solve(N, K, A):
    E = np.arange(0, N)
    for _ in range(K):
        B = np.zeros(N + 1, dtype=np.int64)
        for i_l, i_r in zip(np.maximum(0, E - A), np.minimum(E + A + 1, N)):
            B[i_l] += 1
            B[i_r] -= 1
        A = np.cumsum(B)[:-1]
        if np.all(A == N):
            return A
    return A


N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)
print(' '.join(map(str, solve(N, K, A))))

Measured memory_bytes: 140584
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
	ll h, w, k; cin >> h >> w >> k;
	string s[h];
	for(ll i = 0; i < h; ++i) cin >> s[i];
	set<pair<ll, ll>> se;
	pair<ll, ll> start;
	for(ll i = 0; i < h; ++i){
		for(ll j = 0; j < w; ++j){
			if(s[i][j] == 'S') start = pair<ll, ll>(i, j);
		}
	}
	se.insert(start);
	queue<pair<pair<ll, ll>, ll>> q;
	q.push(pair<pair<ll, ll>, ll>(start, 0));
	ll dx[] = {1, 0, -1, 0};
	ll dy[] = {0, 1, 0, -1};
	while(q.size()){
		pair<pair<ll, ll>, ll> now = q.front();
		q.pop();
		for(ll i = 0; i < 4; ++i){
			pair<ll, ll> next = pair<ll, ll>(now.first.first + dx[i], now.first.second + dy[i]);
			if(!(0 <= next.first && next.first < h && 0 <= next.second && next.second < w)) continue;
			if(s[next.first][next.second] == '#') continue;
			if(se.find(next) != se.end()) continue;
			if(now.second + 1 > k) continue;
			se.insert(next);
			q.push(pair<pair<ll, ll>, ll>(next, now.second + 1));
		}
	}

	ll ans = 1145148931919;
	for(auto ite = se.begin(); ite != se.end(); ++ite) ans = min(ans, min(min(ite->first, (h - 1) - ite->first), min(ite->second, (w - 1) - ite->second)));
	cout << 1 + ans / k + (ans % k > 0) << endl;
	return 0;
}

Measured memory_bytes: 40320
#include <bits/stdc++.h>
using namespace std;
#define fr(i,n) for (int i=0;i<n;i++)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define f first
#define s second
#define mset(m,v) memset(m,v,sizeof(m))
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
long double EPS = 1e-9;
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(ll a, ll b) { if (a < b)swap(a, b); return (((a%mod) - (b%mod) + mod) % mod); }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
void pre() {
}
void solve() {
	int n;
	cin >> n;
	vi v(n-1);
	in(v);
	map<int, int>m;
	fr(i, n-1) {
		m[v[i]]++;
	}
	fr(i, n) {
		cout << m[i + 1] << endl;
	}
}
signed main()
{
	fastio;
	cout << fixed << setprecision(3);
	//clock_t begin = clock();
	//pre();
	int tc;
	tc = 1;
	//cin >> tc;
	while (tc--) {
		solve();
	}
	//clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}


Measured memory_bytes: 17232
#include <stdio.h>

int hai[100];
int n;

int f1(int i, int m){
  if (m==0)
    return 1;
  if (i>=n)
    return 0;
 return f1(i+1,m)||f1(i+1,m-hai[i]);
}

int main(int argc, char const *argv[]) {
  /* code */
  int s,m,i;

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

  scanf("%d",&s);
  for(i=0;i<s;i++){
    scanf("%d",&m);
    if(f1(0,m)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

const bool debug = true;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
//const int inf = 1e9;
//const long long infLL = 1e16;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 300500; //       e5
//const int SZ = 2100;
//const int delta = 1 << 19;

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
//freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int a, b, c;
    cin >> a >> b >> c;
    if(c >= a && c <= b) {cout << "Yes" << endl; } else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    s.append(input())
jg = ['AC', 'WA', 'TLE', 'RE']
co = [0] * 4
for i in s:
    co[jg.index(i)] += 1
for i in range(4):
    print('{} x {}'.format(jg[i], co[i]))

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

int main(){
    int n;
    int all = 196470;
    cin >> n;
    rep(i, 0, n){
        int y, m, d;
        cin >> y >> m >> d;
        int cnt = 0;
        rep(i, 1, y + 1){
            rep(j, 1, 11){
                if(i == y && j == m) break;
                if(i % 3 == 0 || j % 2 == 1) cnt += 20;
                else cnt += 19;
            }
        }
        cnt += d - 1;
        cout << all - cnt << endl;
    }
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        last[memo]=i;
        a+=A[i][memo];
        rep(j,0,N) a-=(i-last[j])*C[j];
    }
    return a;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    vi ans(D);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        last[memo]=i;
        ans[i]=memo;
    }
    ll max=solve(D,A,C,ans);
    rep(_,0,45){
        if(_%4<2){
            rep(i,0,D){
                rep(j,0,N){
                    vi S=ans;
                    S[i]=j;
                    ll X=solve(D,A,C,S);
                    if(max<X){
                        max=X;
                        ans[i]=j;
                    }
                }
            }
        }
        else{
            per(i,D-1,0){
                rep(j,0,N){
                    vi S=ans;
                    S[i]=j;
                    ll X=solve(D,A,C,S);
                    if(max<X){
                        max=X;
                        ans[i]=j;
                    }
                }
            }
        }
    }
    rep(i,0,D) cout<<ans[i]+1<<endl;
}


Measured memory_bytes: 3748
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=200000+10;

int n,a[N];

inline int check(int mid) {
    for (re int i=0;i<n-1;++i) {
        if (a[n-i]<mid&&a[n-i-1]<mid) return 0;
        if (a[n+i]<mid&&a[n+i+1]<mid) return 0;
        if (a[n-i]>=mid&&a[n-i-1]>=mid) return 1;
        if (a[n+i]>=mid&&a[n+i+1]>=mid) return 1;
    }
    return a[1]<mid?0:1;
}

int main() {
    n=read();
    for (re int i=1;i<n<<1;++i) a[i]=read();
    int L=1,R=(n<<1)-1;
    while (L<R) {
        int mid=(L+R+1)>>1;
        if (check(mid)) L=mid;
        else R=mid-1;
    }
    printf("%d\n",L);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vector<vector<bool> > m;
ll ans;
ll w, h;
P s, g;
void dfs(P p, ll n) {
	if(n == 10) return;
	ll det = false;
	REP(i, 4) {
		if(det) break;
		ll nh = p.first + dx[i];
		ll nw = p.second + dy[i];
		ll cnt = 0;
		while(nh >= 0 && nh < h && nw >= 0 && nw < w) {
			if(P(nh, nw) == g) {
				ans = min(ans, n + 1);
				det = true;
				break;
			}
			if(m[nh][nw]) {
				if(cnt > 0) {
					m[nh][nw] = false;
					dfs(P(nh - dx[i], nw - dy[i]), n + 1);
					m[nh][nw] = true;
				}
				break;
			} else {
				nh += dx[i];
				nw += dy[i];
				++cnt;
			}
		}
	}
}

int main(void) {
	while(true) {
		cin>>w>>h;
		if(w == 0 && h == 0) break;
		m.resize(h);
		REP(i, h) m[i].resize(w);
		REP(i, h) {
			REP(j, w) {
				int x;
				cin>>x;
				if(x == 0) m[i][j] = false;
				else if(x == 1) m[i][j] = true;
				else if(x == 2) {
					s.first = i;
					s.second = j;
					m[i][j] = false;
				}
				else if(x == 3) {
					g.first = i;
					g.second = j;
					m[i][j] = false;
				}
			}
		}
		ans = INF;
		dfs(s, 0);
		if(ans != INF) cout<<ans<<endl;
		else cout<<-1<<endl;
	}
}

Measured memory_bytes: 3060
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N-2):
        if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
            ans += 1
    print(ans)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
S=input()
T=input()
for i in range(len(S)-len(T),-1,-1):
  a=0
  for j in range(len(T)):
    if S[i+j]=="?":
      continue
    if S[i+j]!=T[j]:
      a=1
      break
  if a==0:
    for j in range(i):
      if S[j]=="?":
        print("a",end="")
      else:
        print(S[j],end="")
    print(T,end="")
    for j in range(i+len(T),len(S)):
      if S[j]=="?":
        print("a",end="")
      else:
        print(S[j],end="")
    exit()
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;


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

	int64_t minus = a - b;
	if (minus > 1000000000000000000 || minus < -1000000000000000000)
		cout << "Unfair" << endl;
	else if (k % 2 == 0)
		cout << minus << endl;
	else
		cout << -minus << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Beg123C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var nums = new long[5];
            nums[0] = long.Parse(Console.ReadLine());
            nums[1] = long.Parse(Console.ReadLine());
            nums[2] = long.Parse(Console.ReadLine());
            nums[3] = long.Parse(Console.ReadLine());
            nums[4] = long.Parse(Console.ReadLine());

            var min = nums.Min();

            var ans = min > N ? 5 : N % min == 0 ? 4 + N / min : 4 + N / min + 1;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>

int main(void){
    int h,w;
    while(1){
        scanf("%d%d",&h,&w);
        if(h==0&&w==0)break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if((i+j)%2==0)printf("#");
                else printf(".");
            }printf("\n");
        }printf("\n");
    }return 0;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    string ans = "";
    for (char c : s) {
        switch (c) {
            case '0':
                ans += "0";
                break;
            case '1':
                ans += "1";
                break;
            case 'B':
                if (!ans.empty()) ans.pop_back();
                break;
        }
    }

    cout << ans;
}


Measured memory_bytes: 3580
#include <set>
#include <cmath>
#include <stack>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <numeric>
#include <vector>
#include <ctime>
#include <queue>
#include <list>
#include <map>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define clr(x)  memset(x,0,sizeof(x));
#define clrto(x,siz,y)  for(int xx=0;xx<=siz;xx++)  x[xx]=y;
#define clrset(x,siz)  for(int xx=0;xx<=siz;xx++)  x[xx]=xx;
#define clr_1(x) memset(x,-1,sizeof(x));
#define clrmax(x) memset(x,0x3f,sizeof(x));
#define clrvec(x,siz) for(int xx=0;xx<=siz;xx++)  x[xx].clear();
#define fop2   freopen(".in","r",stdin); //freopen(".out","w",stdout);
#define fop   freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
#define getfile sprintf(fin, "%d.in", i); sprintf(fout, "%d.out", i); freopen(fin, "r", stdin); freopen(fout, "w", stdout);
#define myprogram By_135678942570
#define clrcpy(x,siz,y)  for(int xx=0;xx<siz;xx++)  x[xx]=y[xx];
#define pb push_back
using namespace std;
int main()
{
	int n;
	while(1)
	{
		scanf("%d", &n);
		if(n == 0)
			break;
		int num[1001] = {0};
		for(int i = 0; i < n; i++)
		{
			char s[11] = {0};
			scanf("%s", s);
			if(s[0] == 'x')
			{
				num[i] = -0x3f3f3f3f;
				continue;
			}
			int pos = 0;
			int flag = 0;
			if(s[pos] == '-')
			{
				pos++;
				flag = 1;
			}
			while(s[pos] != 0)
			{
				num[i] = num[i] * 10 + s[pos] - '0';
				pos++;
			}
			if(flag) num[i] = -num[i];
		}
		// for(int i = 0; i < n; i++)
		// 	printf("%d ", num[i]);
		int cont = 0;
		for(int i = 0; i < n - 1; i++)
			if(num[i] == -0x3f3f3f3f && num[i + 1] == -0x3f3f3f3f)
			{
				cont = 1;
				break;
			}
		if(cont)
		{
			puts("none");
			continue;
		}
		int maxn = 2000000000;
		int minn = -2000000000;
		int invalid = 0;
		for(int i = 0; i < n; i++)
		{
			if(num[i] == -0x3f3f3f3f)
			{
				if(i == 0)
					maxn = min(maxn, num[i + 1] - 1);
				else if(i % 2 == 0)
				{
					num[n] = 0x3f3f3f3f;
					maxn = min(maxn, min(num[i - 1], num[i + 1]) - 1);
				}
				else
				{
					num[n] = -0x3f3f3f3f;
					minn = max(minn, max(num[i - 1], num[i + 1]) + 1);
				}
			}
			else
			{
				if(i == 0 && num[i + 1] != -0x3f3f3f3f && num[i] > num[i + 1])
				{
					invalid = 1;
					break;
				}
				else if(i != 0 && i % 2 == 0)
				{
					num[n] = -0x3f3f3f3f;
					if(num[i - 1] != -0x3f3f3f3f && num[i] >= num[i - 1] || num[i] >= num[i + 1] && num[i + 1] != -0x3f3f3f3f)
					{
						invalid = 1;
						break;
					}
				}
				else if(i != 0)
				{
					num[n] = -0x3f3f3f3f;
					if(num[i - 1] != -0x3f3f3f3f && num[i] <= num[i - 1] || num[i] <= num[i + 1] && num[i + 1] != -0x3f3f3f3f)
					{
						invalid = 1;
						break;
					}
				}
			}
		}
		// printf("%d %d\n", minn, maxn);
		if(invalid)
		{
			puts("none");
			continue;
		}
		if(minn > maxn)
			puts("none");
		else if(minn == maxn)
			printf("%d\n", minn);
		else puts("ambiguous");
	}
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll n;
    cin >> n;
    vll l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));

    auto sum = [&](ll left, ll right, ll m){
        auto lb = lower_bound(l.begin()+m, l.end(), left+1);
        auto ub = lower_bound(l.begin()+m, l.end(), right);
        if(lb==l.end() || lb>=ub) return 0ll;
        else return (ll)(ub-lb);
    };

    ll count = 0;
    rep(i, n){
        REP(j, i+1, n){
            count += sum(abs(l[i]-l[j]), l[i]+l[j], j+1);
        }
    }
    cout << count << endl;
}


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

typedef long long ll;
const int N = 2e5;
const ll inf = -1e18;
int a[N+100];
ll dp[N+100][2];

int main()
{
	int n;;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
	}
	for(int i=1;i<=N;i++){
		dp[i][0] = dp[i][1] = inf;
	}
	if((n&1)==0){
		dp[1][0] = a[1];
		dp[2][0] = a[2];
		for(int i=3;i<=n;i++){
			if(i&1){
				dp[i][0] = dp[i-2][0]+a[i];
			}
			else{
				dp[i][0] = max(dp[i][0],dp[i-2][0]+a[i]);
				dp[i][0] = max(dp[i][0],dp[i-3][0]+a[i]);
			}
		}
		printf("%lld\n",max(dp[n][0],dp[n-1][0]));
	}
	else{
		dp[1][0] = 0;
		dp[1][1] = a[1];
		dp[2][1] = a[2];
		dp[3][0] = a[3];
		dp[3][1] = a[3]+a[1];
		for(int i=4;i<=n;i++){
			if(i&1){
				dp[i][0] = max(dp[i][0],dp[i-2][0]+a[i]);
				dp[i][0] = max(dp[i][0],dp[i-3][1]+a[i]);
				dp[i][0] = max(dp[i][0],dp[i-4][1]+a[i]);
				dp[i][1] = dp[i-2][1]+a[i];
			}
			else{
				dp[i][1] = max(dp[i][1],dp[i-2][1]+a[i]);
				dp[i][1] = max(dp[i][1],dp[i-3][1]+a[i]);
			}
		}
		printf("%lld\n",max(dp[n][0],max(dp[n-1][1],dp[n-2][1])));
	}
}


Measured memory_bytes: 7708
N = int(input())
A = list(map(int, input().split()))
B = 0
i = 1
while i < N:
    if A[i] - A[i-1] < 0:
        B += A[i-1] - A[i]
        A[i] = A[i-1]
    i += 1
print(B)

Measured memory_bytes: 32268
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;

int main(){
    map<ll,ll> mp;
    rep(i,3){
        ll a; cin >> a;
        mp[a]++;
    }
    for(auto i : mp){
        if(i.second == 1){
            cout << i.first << endl;
            break;
        }
    }
}

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

char a[7][7];
char b[7][7];
int n,m;int k;
void row(int x){
	for(int i=0;i<m;i++){
		b[x][i] = '.';
	}
}

void col(int x){
	for(int i=0;i<n;i++){
		b[i][x] = '.';
	}
}


void sol(int x,int y){
	for(int i=0;i<n;i++){
		if(x>>i&1){
			row(i);
		}
	}
	
	for(int j=0;j<m;j++){
		if(y>>j&1){
			col(j);
		}
	}
}

int cal(){
	int ans =0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(b[i][j] == '#') ans++;
		}
	}
	return ans;
}

int main(){
	//freopen("in.txt","r",stdin);
	
	cin>>n>>m;cin>>k;
	char c;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			
		}
	}
	
	
	int ans = 0;
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<(1<<m);j++){
			memcpy(b,a,sizeof(a));
			sol(i,j);
			if (cal() == k) ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}






Measured memory_bytes: 3592
package main

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

const maxBuf = 200100

var debug = false

var buf []byte = make([]byte, maxBuf)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	if debug {
		testFile, _ := os.Open("./test/in22.in")
		sc = bufio.NewScanner(testFile)
	}
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

/* #### main #### */
func main() {
	n := readInt()

	x := make([]int, 50000+1)
	for i := 0; i < 46297+1; i++ {
		x[int(float64(i)*1.08)] = i
	}

	if x[n] == 0 {
		fmt.Println(":(")
	} else {
		fmt.Println(x[n])
	}
}


Measured memory_bytes: 2188
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int n, m, ct;
vvi graph;
vi used;
pair <int, int> toranai;
void dfs(int a){
    used[a] = true;
    rep(i, graph[a].size()){
        if(!used[graph[a][i]]){
            if(a == toranai.first && graph[a][i] == toranai.second)continue;
            if(a == toranai.second && graph[a][i] == toranai.first)continue;
            dfs(graph[a][i]);
        }
    }
 
}
 
int main(){
    cin >> n >> m;
    graph = vvi(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    rep(i, n){
        rep(j, graph[i].size()){
            toranai = make_pair(i, graph[i][j]);
            used = vi(n);
            dfs(0);
            rep(k, n)
                if(!used[k]){
                    ct++;
                    break;
                }
        }
    }
    cout << ct / 2 << endl;
}

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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    vector<long> a(3*n);
    rep(i, 3*n) { cin >> a[i]; }
    sort(a.rbegin(), a.rend());
    unsigned long long ans = 0;
    int idx = 1;
    for(int i = 0; i < n; i++) {
        ans += a[idx];
        idx += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=5003,M=N<<1,maxn=1e18;

ll f[N];

ll qz[N][N];

int n,p[N];
ll A,B;

inline ll min(ll a,ll b)
{return a<b?a:b;}
inline ll max(ll a,ll b)
{return a>b?a:b;}

int main()
{
	scanf("%d%lld%lld",&n,&A,&B);
	fo(i,1,n)scanf("%d",&p[i]);
	++n; p[n]=n;
	fo(i,1,n){
		qz[i][i]=0;
		fd(l,i-1,1)qz[i][l]=qz[i][l+1]+(p[l]>p[i]);
	}
	p[0]=0;
	fo(i,1,n)f[i]=maxn;
	fo(i,0,n){
		int gs=0;
		fo(l,i+1,n){
			if(gs+qz[l][i+1]==l-i-1&&p[l]>p[i])
			f[l]=min(f[l],f[i]+gs*B+qz[l][i+1]*A);
			gs=gs+(p[l]<p[i]);
		}
	}
	cout<<f[n];
}

Measured memory_bytes: 194048
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt(); int m = sc.nextInt(); int homeworkDays = 0;
		int[] arr = new int[m];
		while (m-- > 0) {
			arr[m] = sc.nextInt();
			homeworkDays+=arr[m];
		}
			int vacation = n-homeworkDays;
			System.out.println(vacation >= 0 ? vacation : "-1");
	}
}


Measured memory_bytes: 46108
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=min(a)+min(b)

for i in range(M):
    c=list(map(int,input().split()))
    maybe_ans=a[c[0]-1]+b[c[1]-1]-c[2]
    if maybe_ans<ans:
        ans=maybe_ans
    else:
        pass

print(ans)



Measured memory_bytes: 18612
def main():
    N = int(input())
    p = list(map(float, input().split()))
    a = [[0] * (N + 1) for _ in range(N)]
    a[0][1] = p[0]
    a[0][0] = 1 - p[0]
    for i in range(1, N):
        a[i][0] = a[i - 1][0] * (1 - p[i])
        for j in range(1, i + 2):
            a[i][j] = a[i - 1][j - 1] * p[i] + a[i - 1][j]* (1 - p[i])
    print(sum(a[-1][(N+1)//2:]))
main()


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

int main(){

  int a[1111], b[1111], c[1111], d[1111], p[333], n;
  
  while(cin >> a[0] >> b[0] >> c[0], *a+=*b+*c){
    for(int i=332;i;) p[i--] = 2;
    
    cin >> n;
    for(int i=0;i++<n;) cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    for(int i=0;i++<n;){
      for(int j=0;j++<n;){
	if(d[j]) p[a[j]] = p[b[j]] = p[c[j]] = 1;
	else{
	  if(p[a[j]] == 1 && p[b[j]] == 1) p[c[j]] = 0;
	  if(p[a[j]] == 1 && p[c[j]] == 1) p[b[j]] = 0;
	  if(p[b[j]] == 1 && p[c[j]] == 1) p[a[j]] = 0;
	}
      }
    }
    for(int i=0;i<*a;) cout << p[++i] << endl;
  }
  
}

Measured memory_bytes: 1180
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int x = Integer.parseInt(sc.next());
    for (int i = x; ; i++) {
      if (isPrime(i)) {
        pw.println(i);
        return;
      }
    }
  }

  static boolean isPrime(int i) {
    if (i == 1) {
      return false;
    }
    if (i == 2) {
      return true;
    }
    for (int j = 2; j < i / 2 + 1; j++) {
      if (i % j == 0) {
        return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 23892
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        int swapCount = 0;
        for (int i = 0; i < size; i++) {
            for (int j = size - 1; j > i; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                }
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    }

    private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    }

    private static void swap(int i, int j, int[] array) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}

Measured memory_bytes: 26208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<ll> L(Q), R(Q);
    rep(i, 0, Q) cin >> L[i] >> R[i];

    vector<ll> acc(N+1, 0);
    rep(i, 1, N){
        if(S[i-1] == 'A' && S[i] == 'C'){
            acc[i+1] = acc[i] + 1;
        }else{
            acc[i+1] = acc[i];
        }
    }

    //rep(i, 0, N) cerr << acc[i] << " ";
    //cerr << endl;

    rep(q, 0, Q){
        ll l = L[q], r = R[q];
        cout << acc[r] - acc[l] << endl;
    }
    return 0;
}

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

int main(){
  string a,b;
  cin >> a >> b;
  if(a.at(0)==b.at(2)&&a.at(1)==b.at(1)&&a.at(2)==b.at(0)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3624
max = 0
li = []
N = int(input())
for i in range(1,N+1):
  count = 0
  while True:
    if i % 2 == 0:
      i = i / 2
      count += 1
    else:
      break
  li.append(count)
for i in li:
  if max < i:
    max = i
print(li.index(max) + 1)

Measured memory_bytes: 3060
N, M = map(int, input().split())

Done = [False] * N
W = [0] * N
AC = 0
WA = 0
for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if Done[p]:
        continue
    else:
        if S == 'WA':
            W[p] += 1
        else:
            AC += 1
            WA += W[p]
            Done[p] = True
print(AC, WA)


Measured memory_bytes: 77628
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

void solve(){
	ll n,m;
	cin>>n>>m;
	ll x;
	ll sum=0;
	rep(i,0,m)	cin>>x, sum+=x;
	if(n<sum)	cout<<-1<<endl;
	else cout<<n-sum<<endl;
	return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll no;
	// cin>>no;
	no = 1;
	while(no--){
		solve();
	}
    return 0;
}

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

struct st { int p, b, c; };
bool operator<(st a, st b) { return a.c>b.c; }
unordered_map<int, vector<int>>E[100000];
vector<int>G[100000];
unordered_map<int, int>d[100000];
int main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, m) {
		int p, q, c; scanf("%d%d%d", &p, &q, &c); p--; q--;
		E[p][c].push_back(q); E[q][c].push_back(p);
		G[p].push_back(c); G[q].push_back(c);
	}
	priority_queue<st>que;
	d[0][0] = 0; que.push({ 0,0,0 });
	while (!que.empty()) {
		st p = que.top(); que.pop();
		if (d[p.p][p.b] != p.c)continue;
		if (d[p.p].find(0) == d[p.p].end() || d[p.p][0] > p.c) {
			d[p.p][0] = p.c;
			que.push({ p.p,0,p.c });
		}
		if (p.b == 0) {
			for (int v : G[p.p]) {
				if (d[p.p].find(v) == d[p.p].end() || d[p.p][v] > p.c + 1) {
					d[p.p][v] = p.c + 1;
					que.push({ p.p,v,p.c + 1 });
				}
			}
			continue;
		}
		for (int v : E[p.p][p.b]) {
			if (d[v].find(p.b) == d[v].end() || d[v][p.b] > p.c) {
				d[v][p.b] = p.c;
				que.push({ v,p.b,p.c });
			}
		}
	}
	if (d[n - 1].find(0) == d[n - 1].end())puts("-1");
	else printf("%d\n", d[n - 1][0]);
}

Measured memory_bytes: 80176
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0 && a[i] % 2 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define random_shuffle asdasdd

int a, b, c, x;

int main() { 

  cin >> a >> b >> c >> x;

  int ans = 0;

  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if (i * 500 + j * 100 + k * 50 == x) {
          ans++;
        } 
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;

    i64 m=0,a=0,r=0,c=0,h=0;
    rep(i,0,N){
        string S;
        cin >> S;
        switch(S[0]){
        case 'M':
            ++m;
            break;
        case 'A':
            ++a;
            break;
        case 'R':
            ++r;
            break;
        case 'C':
            ++c;
            break;
        case 'H':
            ++h;
            break;
        default:
            break;
        }
    }

    cout << m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int totalLength = Integer.parseInt(sc.next());
      	double length=(double)totalLength/3;
    	System.out.println(BigDecimal.valueOf(Math.pow(length,3d)).toPlainString());
    }

}

Measured memory_bytes: 22356
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
signed main()
{
	char n[3];
	scanf("%s", n);
	for(int i = 0; i < 3; ++i)
	{
		if(n[i] == '0' + 7)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

 
int vector_finder(std::vector<int> vec, int number) {
  size_t index = std::distance( vec.begin(), std::find(vec.begin(), vec.end(), number) );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
 
int main()
{
	int A, B;
	cin >> A >> B;

	int sum = 0;

	if(A>B){
		sum += A;
		A--;
	}
	else
	{
		sum += B;
		B--;
	}
	if(A>B){
		sum += A;
		A--;
	}
	else
	{
		sum += B;
		B--;
	}
	cout << sum << endl;

	return 0;
}

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


int main(){

    int chokudai;
    cin>>chokudai;
    if(chokudai < 1200){
        cout << "ABC" << endl;
        return 0;
    }
    if(chokudai < 2800){
        cout << "ARC" << endl;
        return 0;
    }

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

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] t = new int[sc.nextInt()];
    int sum = 0;
    for(int i = 0; i < t.length; i++){
      t[i] = sc.nextInt();
      sum += t[i];
    }
    int[] P = new int[sc.nextInt()];
    int[] X = new int[P.length];
    for(int i = 0; i < P.length; i++){
      System.out.println(sum - t[sc.nextInt()-1] + sc.nextInt());
    }
  }
}

Measured memory_bytes: 22100
N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i-1:i+1] == "AC" else 0)

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

for l, r in lr:
    print(t[r]-t[l])

Measured memory_bytes: 32244