akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>){
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val s = IntArray(m)
    val c = IntArray(m)
    for(i in 0 until m){
        readLine()!!.split(" ").map { it.toInt() }.let {
            s[i] = it[0] - 1
            c[i] = it[1]
        }
    }
    for(i in (if(n == 1) 0 else pow(10, n - 1)) until pow(10, n)){
        (0 until m).map {
            i.toString()[s[it]].toString().toInt() == c[it]
        }.all {
            it
        }.let {
            if(it){
                println(i)
                return
            }
        }
    }
    println(-1)
}

fun pow(a: Int, b: Int): Int{
    return Math.pow(a.toDouble(), b.toDouble()).toInt()
}

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

int main(){
  int n;
  cin >> n;
  if(n%1000 == 0) cout << 0 << endl;
  else cout << 1000 - n%1000 << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int freq[40];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;++i)
    {
        int x;
        cin>>x;
        for(int j=0;j<x;++j)
        {
            int b;
            cin>>b;
            freq[b]++;
        }
    } int ans=0;
    for(int i=0;i<40;++i)
    {
        if(freq[i]>=n)
            ans++;
    }
    cout<<ans;
}



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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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 main(void){
    int N; cin >> N;
    VI isP(55556); REP(i,55556) isP[i] = 1;
    isP[0] = 0; isP[1] = 0;
    REP(i,55556){
        if(isP[i]){
            for(int j=2*i; j<55557; j+=i) isP[j] = 0;
        }
    }

    VI ans;
    REP(i,55556){
        if(isP[i] && i%5==2) ans.push_back(i);
        if(ans.size() == N) break;
    }
    REP(i,ans.size()) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

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

#define MAXINF 1000000005
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rrepc(it, x) for(auto it = (x).rbegin(); it != (x).rend(); ++it)
#define all(x) (x).begin(), (x).end()
#define P pair<int, int>

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w;
    cin >> h >> w;

    if(h == 1 || w == 1) {
        cout << 1 << endl;
    } else {
        cout << (h*w+1)/2 << endl;
    }
    return 0;
}

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

int main()
{
	int N, K;
	string S;
	cin >> N >> K;
	cin >> S;
	S[K-1] = tolower(S[K-1]);
	cout << S;
	return 0;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
const int MOD = 1e9+7;
//}}}

int a[100];
int main(void){
	int N;
	cin >> N;
	rep(i, N) cin >> a[i];
	sort(a, a + N);
	reverse(a, a + N);

	int al = 0;
	int bo = 0;
	rep(i, N){
		(i % 2 ? bo : al) += a[i];
	}
	printf("%d\n", al - bo);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#define MAX_N 100005
#include<string>
typedef long long ll;
using namespace std;
ll gcd(ll a,ll b){
    if(b == 0){return a;}
    else{
        gcd(b,a%b);
    }
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);

}
int main(){
    ll a,b;
    while(cin>>a>>b){
        cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
    }


}

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

int N,X,L[110];

int main(void)
{
  int i, cnt=0;
  cin >> N >> X;
  for(i=0;i<N;i++) {
    cin >> L[i];
    cnt +=L[i];
    if(X<cnt) {
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << N+1<< endl;
}

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

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl

typedef long long ll;

int n, q, k[100];
string s;

vector<int> posA;
vector<ll> cntB, sum1, sum2;
int m;
int idx[100];
ll sol[100];

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

    cin >> n >> s >> q;
    for (int i = 0; i < q; i++) cin >> k[i];
    
    for (int i = 0; i < n; i++) {
        if (s[i] == 'D') {
            posA.push_back(i);
            cntB.push_back(0);

            if (m == 0) {
                sum1.push_back(0);
                sum2.push_back(0);
            } else {
                sum1.push_back(sum1.back());
                sum2.push_back(sum2.back());
            }
            
            m++;
        } else if (s[i] == 'M') {
            if (m > 0) {
                cntB.back()++;
                sum1.back()++;
                sum2.back() += m;
            }
        } else if (s[i] == 'C') {
            if (m == 0) continue;

            for (int j = 0; j < q; j++) {
                while (idx[j] < m && i - posA[idx[j]] >= k[j]) idx[j]++;
                
                if (idx[j] < m) {
                    sol[j] += sum2.back() - sum1.back() * idx[j];
                    if (idx[j] > 0) sol[j] -= sum2[idx[j] - 1] - sum1[idx[j] - 1] * idx[j];
                }
            }
        }
    }
   
    for (int i = 0; i < q; i++) cout << sol[i] << "\n";

    return 0;
}



Measured memory_bytes: 28788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MOD=1000000007;


int main() {
  int n;
  cin >> n;
  map<int,int> mp;
  for(int x = n; x > 1; x--) {
    int m = x;
    for(int i=2; i*i <= m; i++) {
      while(m%i==0) {
        m /= i;
        mp[i]++;
      }
    }
    if(m!=1) mp[m]++;
  }
  ll ans = 1;
  for(auto p : mp) {
    ans *= p.second+1;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int n, m;
VI a(1999);
signed main()
{
    cin >> n >> m;
    a.resize(n);
    REP(i, n){
        cin >> a[i];
    }

    sort(ALL(a));
    reverse(ALL(a));

    int sum = accumulate(ALL(a), 0);

    if (a[m-1] * 4 * m >= sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i=0; i<N; i++){
    cin >> P.at(i);
  }
  int count=0;
  
  int min=P.at(0);
  for(int i=0; i<N; i++){
    if(i==0){
      count++;
    }
    
    else{
      if(P.at(i) < min){
        min = P.at(i);
        count++;
      }
    }
  }
  cout << count << endl;
}

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

int main(){
  long long l,r; cin>>l>>r;
  long long ans=2018;
  
  if(r-l>=2019) cout<<0<<endl;
  else{
    for(long long i=l;i<r;i++){
      for(long long j=i+1;j<=r;j++){
	    ans=min(ans,(i*j)%2019);
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;


double q[200005];

int main() {
	int n;
	cin >> n;
	vector<int>L(n);
	for (int i = 0; i < n; i++) {
		cin >> L[i];
	}
	sort(L.begin(),L.end());
	ll count = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			int sum = L[i] + L[j];
			int x = lower_bound(L.begin(), L.end(), sum) - L.begin();
			int b = i + 1;
			count += x - b;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<math.h>
#include<utility>
const int MOD = 1e9 + 7;
typedef long long ll;
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<pair<ll,ll>> vec;
    for (int i = 0; i < N; i++) {
        ll A,B;
        cin >> A >> B;
        pair<ll,ll> p = make_pair(B,A);
        vec.push_back(p);
    }
    sort(vec.begin(),vec.end());
    ll sum = 0;
    string S = "Yes";
    for (int i = 0; i < N; i++) {
        sum += vec.at(i).second;
        if(sum > vec.at(i).first) {
            S = "No";
            break;
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 6512
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_SIZE = 1000000;
vector<long long> a(1000000);
int s;
void solve() {
    cin >> s;
    a[1] = s;
    for(long long i = 2; i < MAX_SIZE; i++) {
        if(a[i - 1] % 2 == 0) {
            a[i] = a[i - 1] / 2;
        } else {
            a[i] = (3 * a[i - 1]) + 1;
        }
        for(long long j = 1; j < i; j++) {
           if(a[i] == a[j]) {
               cout << i << endl;
               return;
           } 
        }
    }
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 8064
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

l = [i for i in range(5)]
p = [int(input()) for _ in range(5)]

res = 10**100
for ll in perm(l):
    now = 0
    for ii,i in enumerate(ll):
        now += p[i]
        if now % 10 != 0 and ii!=4:
            now //= 10
            now += 1
            now *= 10
    res = min(res, now)
print(res)


Measured memory_bytes: 5072
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <string>
using namespace std;

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	int n;
	int a[2][100] = { {0} };
	int score[2][100] = { {0} };
	cin >> n;
	FOR(i, 0, n) cin >> a[0][i];
	FOR(i, 0, n) cin >> a[1][i];
	score[0][0] = a[0][0];
	FOR(i, 1, n) score[0][i] = score[0][i - 1] + a[0][i];
	score[1][0] = a[0][0] + a[1][0];
	FOR(i, 1, n) score[1][i] = max(score[0][i], score[1][i - 1]) + a[1][i];
   
	cout << score[1][n - 1] << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    priority_queue<P> pq;
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
        pq.push(P(B[i], i));
    }
    ll ans = 0;
    while (!pq.empty()) {
        P now = pq.top();
        pq.pop();
        ll now_b = now.first;
        int idx = now.second;
        ll sum = B[(idx - 1 + N) % N] + B[(idx + 1) % N];
        ll cnt = (now_b - A[idx]) / sum;
        if (cnt <= 0) continue;
        now_b -= cnt * sum;
        B[idx] = now_b;
        ans += cnt;
        if (now_b > A[idx]) pq.push(P(now_b, idx));
    }
    for (int i = 0; i < N; ++i) {
        if (A[i] != B[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//変数//
		int N;		//問題数
		int M;		//ドリンクの種類
		
		int[] T;	//各問題にかかる時間
		int[] P;	//各ドリンクの効果が発生する問題位置
		int[] X;	//上記の効果後の問題にかかる時間
		int[] ans;	//出力結果
		
		Scanner scan = new Scanner(System.in);
		//入力//
		N = scan.nextInt();
		
		T = new int[N];
		for(int i = 0; i < N; i++){
			T[i] = scan.nextInt();
		}
		
		M = scan.nextInt();
		
		P = new int[M];
		X = new int[M];
		for(int i = 0; i < M; i++){
			P[i] = scan.nextInt();
			X[i] = scan.nextInt();
		}
		
		scan.close();
		//処理//
		
		//結果用配列の初期化
		ans = new int[M];
		for(int i = 0; i < M; i++){
			ans[i] = 0;
		}
		
		//各ドリンクを使用した場合の合計を計算する
		for(int i = 0; i < M; i++){
			for(int j = 0; j < N; j++){
				if( P[i] == j + 1 ){
					ans[i] += X[i];
				}else{
					ans[i] += T[j];
				}
			}
		}
		
		//結果//
		for(int i = 0; i < M; i++){
			System.out.println(ans[i]);
		}

	}

}


Measured memory_bytes: 10576
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	int X;
	cin >> X;
	int now = 0;
	for(int i=1; i<INT_MAX; i++){
		now += i;
		if(now >= X){
			cout << i << endl;
			break;
		}
	}

	return 0;
}


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

int main()
{
    string A, B, C;
    cin >> A >> B >> C;
    if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll from,to,cost;};
 
const ll MXE=5000,MXV=2500;
edge es[MXE];
ll d[MXV];//dを最小化していく中で、負の回路があったらダメ？
ll V,E;
ll DA,ans;

void bellman_ford(ll s){
  rep(i,MXV){
    d[i]=INF;
  }
  d[s]=0;
  rep(i,2*V){
    bool update=false;
    rep(j,E){
      edge e=es[j];
      if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        if(i>=V){
            d[e.to]=-INF;
        }
        update=true;
      }
    }
    if(!update){
      break;
    }
    if(i==V-1){
      DA=d[V-1];
    }
    if(i==2*V-1){
      if(d[V-1]!=DA&&!(d[V-1]>=0&&DA>=0)){
        ans=-1;
      }
    }
  }
}

int main(){
  ll P;
  cin >> V >> E >> P;
  rep(i,E){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;b--;c=P-c;
    es[i]={a,b,c};
  }
  ans=0;
  bellman_ford(0);
  if(ans==-1){
    cout << ans << endl;
  }
  else{
    cout << max((ll)0,-d[V-1]) << endl;
  }
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//

int main(){
    ll x;
    cin >> x;
    vector<ll> div;
    for(int i = 1; i <= sqrt(x); i++){
        if(x % i == 0){
            div.push_back(i);
            if(i != x / i){
                div.push_back(x / i);
            }
        }
    }
    sort(div.begin(), div.end());
    for(int i = 0; i < div.size(); i++){
        const ll a = div[i];
        const ll b = x / a;
        ll right = a / 2;
        ll left = right - a;
        while(true){
            int mendo = pow(right,4) + pow(right,3) * left + pow(right,2) * pow(left,2) + right * pow(left,3) + pow(left,4);
            if(mendo == b){
                cout << right << " " << left;
                return 0;
            }else if(mendo > b){
                break;
            }else{
                right++; left++;
            }
        }
        right = a / 2;
        left = right - a;
        while(true){
            int mendo = pow(right,4) + pow(right,3) * left + pow(right,2) * pow(left,2) + right * pow(left,3) + pow(left,4);
            if(mendo == b){
                cout << right << " " << left;
                return 0;
            }else if(mendo > b){
                break;
            }else{
                right--; left--;
            }
        }
    }
}

Measured memory_bytes: 4016
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  rep(i, n){
    int a;cin>>a;
    if(a%2==0){
      if (a%3==0 || a%5==0){
      }
      else{
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
# dic = [[-1]*(N+1) for _ in range(N+1)]
M = [[] for _ in range(N+1)]
used = [-1]*(N+1) 
for i in range(N-1):
    u,v,w = map(int,input().split())
    M[u-1].append([v-1,w])
    M[v-1].append([u-1,w])


# from collections import deque 
q = []
q.append(0)
used[0] = 0
# print(M)
while q:
    # print(q)
    e = q.pop()
    for i,d in M[e]:
        if used[i]==-1:
            C = (used[e]+d)%2
            used[i] = C
            q.append(i)  
for i in used[:-1]:
    print(i)


Measured memory_bytes: 45772
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String mozi = sc.next();
        if (mozi.equals("a") || mozi.equals("i") || mozi.equals("u") || mozi.equals("e") || mozi.equals("o")){
            System.out.println("vowel");
        }else System.out.println("consonant");
    }
}


Measured memory_bytes: 21716
n = int(input())

b1 = [[0] * 10 for i in range(3)]
b2 = [[0] * 10 for i in range(3)]
b3 = [[0] * 10 for i in range(3)]
b4 = [[0] * 10 for i in range(3)]

cnt = 0

FF =[b1,b2,b3,b4]

for i in range(n):
    b,f,r,v = map(int,input().split())
    if b == 1:
        b1[f-1][r-1] += v
    elif b == 2:
        b2[f-1][r-1] += v
    elif b == 3:
        b3[f-1][r-1] += v
    else:
        b4[f-1][r-1] += v
for k in FF:
    for i in range(3):
        for j in range(10):
            print("",k[i][j],end="")
        print()
    if cnt < 3:
        print('#'*20)
        cnt += 1


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
string str;
vector<string>vec;
map<string,int>mp;

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int n,i,a;
    cin>>n;
    a=-1;
    while(n--)
    {
        cin>>str;
        if(mp[str]==0)vec.push_back(str);
        mp[str]++;
        a=max(a,mp[str]);
    }
    sort(vec.begin(),vec.end());
    for(auto x : vec)
    {
        if(mp[x]==a)cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 27340
while 1:
    n=input()
    if n==0:break
    s=""
    d={}
    for i in range(n):
        a=raw_input().split()
        d[a[0]]=a[1]
    for i in range(input()):
        b=raw_input().split()
        if b[0] in d:
            s+=d.get(b[0])
        else:
            s+=b[0]
    print s

Measured memory_bytes: 7376
//It doesn't matter as long as you rise to the top - Katsuki Bakugo
#include<bits/stdc++.h>
using namespace std;
     
     
#define Fast_as_duck ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back 
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define rev(i,st,n) for(int i = st; i >= n ; i--)
#define ss second
#define ff first
#define ll long long 

typedef pair <int , int> pii;

const int N = 1e5 + 10 , mod =  1000000007;

void solve(){

    int n; cin >> n;
    std::vector<int> arr(n);
    forn(i,0,n){
        cin >> arr[i];
        
    }

    ll ans = 0;
    
    forn(i,0,n){
        forn(j,i+1,n){
            if(arr[j] == arr[i])continue;
            forn(k,j+1,n){
                if(arr[k] == arr[i] || arr[k] == arr[j])continue;
                if(arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[j] + arr[k] > arr[i]){
                    ans++;
                }
            }
        }
    }

    cout << ans << "\n";


    
    

    
    
        


}

int main(){
    Fast_as_duck;

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
*/
    int t = 1; 
    
    // cin >> t;
    

    while(t--){
        solve();
    }




    return 0;
}
      
       


Measured memory_bytes: 3656
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin, (v).end);


typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    lint N;
    lint A, B;

    //入力
    cin >> N;


    for(lint i=sqrt(N); i > 0; i--){
        if(N%i==0)  {A=i; B=N/i; break;}
    }
    //cout << A << " " << B << " ";
    cout << (A-1)+(B-1) << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
MOD = 10**9 + 7
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    p = [list(map(int,input().split())) for _ in range(n)]
    p = sorted(p,key=lambda x: -x[2])
    for x in range(0,101):
        for y in range(0,101):
            h = p[0][2] + abs(x-p[0][0]) + abs(y-p[0][1])
            flag = 1
            for (a,b,c) in p:
                if c != max(0,h-abs(x-a)-abs(y-b)):
                    flag = 0
                    break
            if flag == 1:
                print(x,y,h)
                exit(0)
if __name__ == '__main__':
    main()


Measured memory_bytes: 73644
s = str(input())
for i in range(len(s)):
  if s[i] == 'A':
    a_idx = i
    break
for i in range(len(s)-1, -1, -1):
  if s[i] == 'Z':
    z_idx = i
    break
print(z_idx - a_idx + 1)

Measured memory_bytes: 3516
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
if T1*A1+T2*A2==T1*B1+T2*B2:
    cnt="infinity"
elif T1*A1+T2*A2>T1*B1+T2*B2:
    L = T1*(B1-A1)
    d = T1*A1+T2*A2-(T1*B1+T2*B2)
    if L<0:
        cnt = 0
    elif L==0:
        cnt = 1
    else:
        cnt = 1
        n = L//d
        r = L%d
        if r>0:
            cnt += 2*n
        else:
            cnt += 2*(n-1)+1
elif T1*A1+T2*A2<T1*B1+T2*B2:
    L = T1*(A1-B1)
    d = (T1*B1+T2*B2)-(T1*A1+T2*A2)
    if L<0:
        cnt = 0
    elif L==0:
        cnt = 1
    else:
        cnt = 1
        n = L//d
        r = L%d
        if r>0:
            cnt += 2*n
        else:
            cnt += 2*(n-1)+1
print(cnt)        

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int a, b, c; cin >> a >> b >> c;
    if(a <= c && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
from itertools import combinations
s = input()
n = len(s)
t = input()
m = len(t)

dp = [[0 for i in range(m+1)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j],dp[i-1][j-1] + 1)
        elif s[i-1] != t[j-1]:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

i = n
j = m
ans = ""

while i > 0 and j > 0:

    if s[i-1] == t[j-1]:
        ans = s[i-1] + ans 
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
print(ans)

Measured memory_bytes: 153212
#include<iostream>
#include<algorithm>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)

using namespace std;

int main(){
	int n,q;
	cin>>n>>q;
	string ans="kogakubu10gokan";
	rep(i,n){
		int y;
		string name;
		cin>>y>>name;
		if(y<=q)ans=name;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define int ll
signed main(){
    ios::sync_with_stdio(false);
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> s(n-1);
    rep(i,n-1) s[i] = a[i] + a[i+1];
    int ans = 0;    
    rep(i,n-1) {
        if(s[i] > x) {
            if(s[i] - x <= a[i+1]) {
                int op = s[i] - x;
                ans+= op;
                s[i] -= op;
                s[i+1] -= op;
            } else {
                int op1 = a[i+1]; //a[i+1]から引く
                int op2 = (s[i]-x) - a[i+1]; //a[i]から引く
                ans+= op1 + op2;
                s[i] -= op1 + op2; 
                s[i+1] -= op1;
            }
        }
    }
    cout << ans << endl;
}


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

const int kN = 1000 + 5;
const int kMod = 1'000'000'000 + 7;
int a[kN], tab[kN][kN], dp[kN][kN];

int main() {
    int n, k; scanf("%d%d", &n, &k);
    for (int i = 1; i <= k; ++i) scanf("%d", &a[i]);
    tab[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        tab[i][0] = 1;
        for (int j = 1; j <= i; ++j) tab[i][j] = (tab[i - 1][j] + tab[i - 1][j - 1]) % kMod;
    }
    dp[0][0] = 1;
    for (int i = 1; i <= k; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (dp[i - 1][j] == 0) continue;
            for (int x = 0; x <= min(a[i], n - j); ++x) {
                int r = 1LL * tab[n - j][x] * tab[n - x][a[i] - x] % kMod;
                dp[i][j + x] += 1LL * r * dp[i - 1][j] % kMod;
                dp[i][j + x] %= kMod;
            }
        }
    }
    printf("%d\n", dp[k][n]);
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    ll x; cin>>x;
    for(ll a=-1000;a<=1000;a++){
        for(ll b=-1000;b<=1000;b++){
            if(a*a*a*a*a-b*b*b*b*b==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
    
}


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

const int maxn = 2e5+1;



int cnt[maxn];
int main()
{
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i)
    {
      int a;
      scanf("%d", &a);
      cnt[a] += 1;
    }
  sort(cnt, cnt+maxn, greater<int>());
  int ans = n;
  for (int i = 0; i < k; ++i)
    ans -= cnt[i];
  printf("%d\n", ans);
}


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

int main() {
  long ans=0;
  string s;
  cin >> s;
  vector<long> a(s.size()+1);

  a[0]=0;
  long j=1;
  for (long i = s.size() - 1; i >= 0; i--) {
    a[s.size()-i]=((s[i]-'0')*j+a[s.size()-i-1])%2019;
    j=j*10%2019;
  }
  sort(a.begin(),a.end());
  j=1;
  for(long i=1;i<s.size()+1;i++) {
    if(a[i]==a[i-1]) {
      ans+=j;
      j++;
    } else {
      j=1;
    }
  }
  
  cout << ans << endl;
}

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

int main()
{
  int N, bottuns[100010], bucket[100010] = {0}, target;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> bottuns[i];

  target = bottuns[0];
  bucket[1] = 1;
  for (int i = 1; i < N; i++)
  {
    if (target == 2)
    {
      cout << i << endl;
      return 0;
    }
    if (bucket[target] != 0) break;
    bucket[target] = 1;
    target = bottuns[target - 1];
  }
  cout << -1 << endl;
  return 0;
}


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

using namespace std;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const  long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second



//誤差を考慮して足し算
double add(double a, double b) {
	if (abs(a + b) < eps*(abs(a) + abs(b))) {
		return 0;
	}
	return a + b;
}

//二次元ベクトル構造体
struct pp {
	double x, y;
	pp() {}
	pp(double x, double y) :x(x), y(y) {}
	pp operator+(pp p) {
		return pp(add(x, p.x), add(y, p.y));
	}
	pp operator-(pp p) {
		return pp(add(x, -p.x), add(y, -p.y));
	}
	pp operator*(double d) {
		return pp(add(x, d), add(y, d));
	}
	double dot(pp p) {//内積
		return add(x*p.x, y*p.y);
	}
	double det(pp p) {//外積
		return add(x*p.y, -y * p.x);
	}
};

double dist(pp p, pp q) {//距離の二乗
	return (p - q).dot(p - q);
}

bool cmp_x(const pp& p, const pp& q) {
	if (p.x != q.x)return p.x < q.x;
	return p.y < q.y;
}

//凸包
vector< pp >convex_full(pp* ps, int N) {
	sort(ps, ps + N, cmp_x);
	int k = 0;
	vector< pp >qs(N * 2);
	//下側凸包
	for (int i = 0;i < N;i++) {
		while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0)k--;
		qs[k++] = ps[i];
	}
	//上側凸包
	for (int i = N - 2, t = k;i >= 0;i--) {
		while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0)k--;
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

struct Union_Find_Tree {
private:
	vector< long long >par;
	vector< long long >Rank;
	int N;
public:
	void init(int n) {
		N = n;
		par.resize(N + 1);
		Rank.resize(N + 1);
		for (int i = 0;i <= N;i++)par[i] = i, Rank[i] = 0;
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (Rank[x] < Rank[y])par[x] = y;
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};


int V, r, a, b;
double ans;
pp po[110];
vector< int >v[110];
map< pair< int, int >, int >mp;
vector< pair< double, pair< int, int > > >edge;

int main() {
	cin >> V >> r;
	edge.resize(r);
	for (int i = 0;i < V;i++) {
		cin >> po[i].x >> po[i].y;
		mp[make_pair((int)po[i].x, (int)po[i].y)] = i;
	}
	for (int i = 0;i < r;i++) {
		cin >> a >> b;
		a--, b--;
		edge[i] = make_pair(dist(po[a], po[b]), make_pair(a, b));
	}
	vector< pp >qs = convex_full(po, V);
	Union_Find_Tree uf;
	uf.init(V);
	for (int i = 0;i < qs.size();i++) {
		ans += sqrt(dist(qs[i], qs[(i + 1) % qs.size()]));
		uf.unite(mp[make_pair((int)qs[i].x, (int)qs[i].y)], mp[make_pair((int)qs[(i + 1) % qs.size()].x, (int)qs[(i + 1) % qs.size()].y)]);
	}
	sort(ALL(edge));
	for (int i = 0;i < edge.size();i++) {
		if (uf.same(edge[i].sc.fr, edge[i].sc.sc))continue;
		uf.unite(edge[i].sc.fr, edge[i].sc.sc);
		ans += sqrt(edge[i].fr);
	}
	cout << setprecision(10) << ans << endl;
	return 0;
}



Measured memory_bytes: 3336
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll m = b*d;
    m = max(m, a*d);
    m = max(m, b*c);
    m = max(m, a*c);
    cout << m << "\n";
}


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

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

Measured memory_bytes: 4736
#include<stdio.h>

#define MAX 100

static const int INFTY=(1<<21);
static const int Wh=0;
static const int Gr=1;
static const int Bl=2;

int n,M[MAX][MAX];

void dijkstra(void);

int main(void)
{
  int i,j;
  
  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  M[i][j]=INFTY;
	}
    }

  int k,c,u,v;

  for(i=0;i<n;i++)
    {
      scanf("%d%d",&u,&k);
      
      for(j=0;j<k;j++)
	{
	  scanf("%d%d",&v,&c);
	    
	    M[u][v]=c;
	}
    }

      
  dijkstra();

  return 0;
}

void dijkstra(void)
{
  int i,u,v;
  int minv;
  int d[MAX],color[MAX];

  for(i=0;i<n;i++)
    {
      d[i]=INFTY;

      color[i]=Wh;
    }

  d[0]=0;

  color[0]=Gr;

  while(1)
    {
      minv=INFTY;
      u=-1;

      for(i=0;i<n;i++)
	{
	  if(minv>d[i]&&color[i]!=Bl)
	    {
	      u=i;
	      minv=d[i];
	    }
	}

      if(u==-1)
	{
	  break;
	}

      color[u]=Bl;

      for(v=0;v<n;v++)
	{
	  if(color[v]!=Bl&&M[u][v]!=INFTY)
	    {
	      if(d[v]>d[u]+M[u][v])
		{
		  d[v]=d[u]+M[u][v];
		  color[v]=Gr;
		}
	    }
	}
    }

  for(i=0;i<n;i++)
    {
      printf("%d %d\n",i,d[i]==INFTY?-1:d[i]);
    }
}



Measured memory_bytes: 2104
import fractions 
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
sna=a[n-1]
Ans=[ans]*n
Sna=[sna]*n
for j in range(1,n):
  ans=fractions.gcd(ans,a[j])
  Ans[j]=ans
  sna=fractions.gcd(sna,a[n-j-1])
  Sna[j]=sna
m=Sna[n-2]
for k in range(n-2):
  m=max(m,fractions.gcd(Ans[k],Sna[n-3-k]))
m=max(m,Ans[n-2])
print(m)

  

  

  


Measured memory_bytes: 16136
import java.util.Scanner;
class Main {
	int W = 0,H = 0,I = 0,F = 0,A = 0,Z = 0;
	public void pr() {
		Scanner sc = new Scanner(System.in);
		H = sc.nextInt();
		W = sc.nextInt();
		while(H != 0 || W != 0) {
			for(I = 0;I < H; I++) {
				for(F = 0;F < W; F++) {
					if(I == 0||I == H - 1||F == W - 1) {
						System.out.print("#");
					} else {
						if(F == 0) {
							Z = 0;
						}
						if(Z == 0) {
							System.out.print("#");
							Z++;
						}
						for(A = W - 3;A < W-2&&F != 0;A++) {
							System.out.print(".");
						}
					}
					if(F == W - 1) {
						System.out.println();
					}
				}
			}
				System.out.println();
			H = sc.nextInt();
			W = sc.nextInt();
		}
	}
	public static void main(String[] args) {
		new Main().pr();
	}
}

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


int main() {
  int n,m;
  int a;
  cin>>n>>m;
  while(m--) {
    cin>>a;
    n-=a;
  }
  if(n<0) {
    cout<<-1;
    return 0;
  }
  cout<<n;
  return 0;
}

Measured memory_bytes: 3636
/**********************************************************
* @Author: 			   Kirito
* @Date:   			   2020-07-25 20:37:51
* @Last Modified by:   Kirito
* @Last Modified time: 2020-07-25 21:48:12
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn=111;
int n,a[maxn];

int main()
{
	CSE(a,0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	ll mon=1000;
	for(int i=2;i<=n;i++){
		if(a[i]>a[i-1]){
			ll num=mon/a[i-1];
			mon=mon%a[i-1];
			mon+=num*a[i];
		}
	}
	cout<<mon<<endl;
	return 0;
}

Measured memory_bytes: 3628
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

def possible(x):
    count = 0
    for a in A:
        if a <= x:
            return True
        count += int(ceil(a/x)) - 1
        if count > K:
            return False
    return True

def solve():
    lo, hi = 0, A[0]
    while lo < hi-1:
        mi = (hi + lo) // 2
        if possible(mi):
            hi = mi
        else:
            lo = mi
    return hi

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 93932
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int  N;
    cin >> N;
    vector<int> A(N);

    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }

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

    int answer = 0;
    for (int i = 1; i < N; i++){
        answer += A.at(i) - A.at(i-1); 
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int freq[N];

int main() {

//	freopen("readin.txt", "r", stdin);

	int n, m;
	scanf("%d%d", &n, &m);
	vector<pair<int, int> > v;
	for (int i = 0, a, b; i < m; i++) {
		scanf("%d%d", &a, &b);
		if (a > b) swap(a, b);
		if (a == 1) {
			freq[b]++;
		} else {
			freq[a]++, freq[b]++;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (freq[i] % 2) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");

	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, M;
        cin >> N >> M;
        vector<Int> A(M);
//        vector<vector<Int>> C(M);
        vector<Int> C(M);
        for (int i = 0; i < M; ++i) {
            Int b;
            cin >> A[i] >> b;
            Int bit = 0;
            for (int j = 0; j < b; ++j) {
                Int tmp;
                cin >> tmp;
                tmp--;
                bit |= (1 << tmp);
            }
            C[i] = bit;
        }

        vector<vector<Int>> dp(M + 1, vector<Int>(1 << N, INFl));
        dp[0][0] = 0;

        for (int i = 0; i < M; ++i) {
            for (int bit = 0; bit < 1 << N; ++bit) {
                chmin(dp[i + 1][bit], dp[i][bit]);
                chmin(dp[i + 1][bit | C[i]], dp[i][bit] + A[i]);
            }
        }
        Int ans = dp[M][(1 << N) - 1];
        if (ans == INFl) ans = -1;

        cout << ans << endl;


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std ;
int main()
{
    long long n , k ;
    vector <long long> v ;
    cin >> n >> k ;
    long long temp ;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> temp ;
        v.push_back(temp) ;
    }
    sort(v.begin(), v.end(), greater <int>() ) ;
    if(k >= n)
    {
        cout <<0 << endl ;
    }
    else
    {
        long long sum = 0 ;
        for(auto it = v.begin() + k ; it != v.end() ;it++)
        {
            sum += *it ;
        }
        cout <<sum << endl ;
    }

}


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

int main() {
	int n, san = 200, defa = 195;
	cin >> n;
	for(int q = 0; q < n; ++q){
		int ans = 0, y, m, d;
		cin >> y >> m >> d;
		if(y % 3){
			if(m % 2){
				ans += (20 - d);
			}
			else{
				ans += (19 - d);
			}
			m++;
			if(m != 11){
				if(m % 2){
					ans += ((10 - m) / 2 + 1) * 19 + ((10 - m) / 2 + 1) * 20;
				}
				else{
					ans += ((10 - m) / 2 + 1) * 19 + (10 - m) / 2 * 20;
				}
			}
				
		}
		else{
			ans += (20 - d);
			m++;
			if(m != 11){
				ans += (10 - m + 1) * 20;
			}
		}
		y++;
		if(y == 1000){
			cout << ans + 1 << endl;
			continue;
		}
		while(y % 3){
			ans += defa;
			y++;
		}
		ans += ((1000 - y) / 3 + 1) * san;
		ans += ((1000 - y - 1) - ((1000 - y) / 3)) * defa;
		cout << ans + 1 << endl;
	}
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }

int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;

    for (int i = 0; i < N; i++) {
        cout << S[i] << T[i];
    }
    cout << el;
    return (0);
}

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

long long int check[100005];

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

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

    cin>>k;
    string s1;
    cin>>s1;
    n=s1.size();
    if(n<=k)
        cout<<s1<<"\n";
    else
        cout<<s1.substr(0,k)<<"...\n";


    return 0;


}


Measured memory_bytes: 3620
BIG_NUM = 2000000000

N = int(input())

table = list(map(int,input().split()))

maximum = -BIG_NUM
minimum = BIG_NUM
total = 0

for x in table:
    if maximum < x:
        maximum = x
    if minimum > x:
        minimum = x
    total += x

print("%d %d %d"%(minimum,maximum,total))


Measured memory_bytes: 6592
#include<iostream>
#include<utility>
#include<vector>
#include<cstdio>
#include<queue>
#include <map>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
//int in(){int x;cin>>x;return x;}

int main ()
{
	int c,n,m,s,d;
	while(cin>>c>>n>>m>>s>>d&&c&&n&&m&&s&&d)
	{
		int flg[110][20]={};
		for(int i=0;i<110;i++)for(int j=0;j<20;j++)flg[i][j]=9999999;
		int ans =-1;
		priority_queue < PP, vector<PP>, greater<PP> > q;
		vector< P > way[110];
		for(int i=0;i<m;i++)
		{
			int a,b,f;
			cin>>a>>b>>f;
			way[a].push_back(P(b,f));
			way[b].push_back(P(a,f));
		}
		PP next;
		q.push(PP(0,P(s,c)));
		while(!q.empty())
		{
			PP now=q.top();q.pop();
			if(flg[now.second.first][now.second.second]!=9999999){
				continue;
			}
			flg[now.second.first][now.second.second]=now.first;
			if(now.second.first==d)
			{
				ans=now.first;
				break;
			}
			
			for(int i=0;i<way[now.second.first].size();i++)
			{
				if(flg[way[now.second.first][i].first][now.second.second]>=now.first+way[now.second.first][i].second){
					next.first=now.first+way[now.second.first][i].second;
					next.second.first=way[now.second.first][i].first;
					next.second.second=now.second.second;
					q.push(next);
				}
				if(now.second.second==0)continue;
				if(flg[way[now.second.first][i].first][now.second.second-1]>=now.first+way[now.second.first][i].second/2){
					next.first=now.first+way[now.second.first][i].second/2;
					next.second.first=way[now.second.first][i].first;
					next.second.second=now.second.second-1;
					q.push(next);
				}
			}
			
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 1312