akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long>h(n);
    vector<long long>d(n-1);
    for(int i=0; i<n; ++i){
        cin >> h[i];
    }
    for(int i=0; i<n-1; ++i){
        d[i]=h[i]-h[i+1];
    }
    vector<long long>b;
    int a;
    a=0;
    for(int i=0; i<n-1; ++i){
        if(d[i]>=0){
            a +=1;
        }
        else{
            b.push_back(a);
            a=0;
        }
    }
    b.push_back(a);
    int ans;
    ans =0;
    for(int i=0; i<b.size();++i){
        if(ans<b[i]){
            ans = b[i];
        }
    }
    cout << ans << endl;
}


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

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)


print(str.lower(num2alpha(n)))

Measured memory_bytes: 61728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(), b=sc.nextInt(), c=sc.nextInt(), x=sc.nextInt();
		int temp=0,ans=0;
		for(int i=0; i<=a;i++) {
			for(int j=0; j<=b; j++) {
				for(int k=0; k<=c; k++) {
					temp=(i*500)+(j*100)+(k*50);
					if(temp == x) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
}


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

using namespace std;

int main(){
    ios:: sync_with_stdio(0);

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    vector<long long> dp(n);

    for(int i = 0; i < n; ++i)
        cin >> h[i];

    for(int i = 1; i < n; ++i){
        long long mi = LLONG_MAX;
        for(int j = 1; j <= k && (i - j >= 0); ++j){
            mi = min(mi, dp[i - j] + abs(h[i] - h[i - j]));
        }
        dp[i] = mi;
    }

    cout << dp[n - 1];
}


Measured memory_bytes: 1408
MOD = 10**9+7
r1, c1, r2, c2 = map(int, input().split())
n = (2 * 10 ** 6) + 2
from math import factorial

class Facts():
    # 階乗のメモ化
    # 組み合わせ数、順列数の計算を高速に行う
    def __init__(self, max_num=10**5, p=10**9 + 7):
        self.p = p
        self.max_num = max_num
        self.fact = [1] * (self.max_num + 1)
        for i in range(1, self.max_num + 1):
            self.fact[i] = self.fact[i-1] * i
            self.fact[i] %= self.p

    def comb(self, n, k):
        # nCk mod p を求める
        if n < 0 or k < 0 or n < k:
            return 0
        if n == 0 or k == 0:
            return 1
        a = self.fact[n]
        b = self.fact[k]
        c = self.fact[n-k]
        return (a*self.power_func(b, self.p-2) *
                self.power_func(c, self.p-2)) % self.p

    def perm(self, n, k):
        # nPk mod p を求める
        if n < 0 or k < 0 or n < k:
            return 0
        if n == 0 or k == 0:
            return 1
        a = self.fact[n]
        b = self.fact[n-k]
        return (a * self.power_func(b, self.p-2)) % self.p


    def power_func(self, a, b):
        # a^b mod p　を繰り返し二乗法で求める
        if b == 0:
            return 1
        if b % 2 == 0:
            d = self.power_func(a, b//2)
            return d*d % self.p
        if b % 2 == 1:
            return (a*self.power_func(a, b-1)) % self.p

class FLT:
    #フェルマーの小定理
    # a^(-1) = a^(m-2) mod p
    def __init__(self, mod=10**9+7):
        self.mod = mod

    def rep_sqr(self, base, k):
        if k == 0:
            return 1
        elif k % 2 == 0:
            return (self.rep_sqr(base, k // 2) ** 2) % self.mod
        else:
            return (self.rep_sqr(base, k - 1) * base) % self.mod

    def inv(self, a):
        # 逆元を取る
        return self.rep_sqr(a, self.mod-2)

fact = Facts(n)

def f(x, y):
    return fact.comb(x+y, y)

def g(x, y):
    return f(x+1, y+1)

print((g(r2, c2) - g(r2, c1-1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % MOD)



Measured memory_bytes: 54128
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  vector<bool> ans(26);
  for(int i=0;i<s.size();i++){
    ans.at(s.at(i)-'a')=true;
  }
  bool ok=false;
  for(int i=0;i<26;i++){
    if(!ans.at(i)){
      cout<<(char)(i+'a')<<endl;
      ok=true;
      return 0;
    }
  }
  if(!ok){
    cout<<"None"<<endl;
  }
  return 0;
}

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

int main(){
  int n,m,x,j=0,ans=0,c=0,a;cin>>n>>m>>x;
  REP(i,m){
    cin>>a;
    if(a<x) ans++;
    else c++;
  }
  ans=min(ans,c);
  cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int vec[n][26]={};
  
  vector<string>S(n);
  for(int i=0;i<n;i++){
    cin>>S[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<S[i].size();j++){
      for(char k='a';k<='z';k++){
        if(S[i][j]==k) vec[i][k-'a']++;
      }
    }
  }
  vector<int> ans(26);
  for(int j=0;j<26;j++){
    int min=vec[0][j];
    for(int i=0;i<n;i++){
      min=(vec[i][j]>min)?min:vec[i][j];
    }
    ans[j]=min;
  }
  vector<char> str;
  for(int j=0;j<26;j++){
    for(int i=0;i<ans[j];i++){
      str.push_back('a'+j);
    }
  }
  
  for(auto &e:str){
    cout<<e;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int train[10];
  int in;
  int i = 0;
  int ii =0;
  int out[100];
  while( scanf("%d", &in ) != EOF) {
    if( in == 0 ) {
      out[i] = train[ii-1];
      train[ii -1] =0;
      ii--;
    } else if( in != 0){
      train[ii] = in;
      out[i] = 0;
      ii++;
    }
    i++;
  }
  for( int c = 0; c < i; c++ ) {
    if( out[c] != 0 ) {
      printf( "%d\n", out[c] );
    }
  }
  return 0;
}

Measured memory_bytes: 1028
(defparameter *char-list*
  (loop for i below 26 collect (code-char (+ (char-code #\a)
                                             i))))
(defun lst-equal-p (xs ys)
  (if (null xs)
      t
      (if (equal (first xs) (first ys))
          (lst-equal-p (rest xs)
                       (rest ys))
          nil)))

(defun make-pos-list (lst chr &optional (acc nil) (cnt 0))
  (if (null lst)
      (reverse acc)
      (progn
        (when (char-equal (first lst) chr)
          (push cnt acc))
        (make-pos-list (rest lst) chr acc (1+ cnt)))))

(defun solve (s1 s2)
  (let ((p1 (sort (remove-if #'null
                             (mapcar (lambda (c) (make-pos-list s1 c))
                                     *char-list*))
                  (lambda (xs ys) (< (first xs) (first ys)))))
        (p2 (sort (remove-if #'null
                             (mapcar (lambda (c) (make-pos-list s2 c))
                                     *char-list*))
                  (lambda (xs ys) (< (first xs) (first ys))))))
    (if (/= (length p1) (length p2))
        "No")
    (if (lst-equal-p p1 p2)
        "Yes"
        "No")))

(defun main ()
  (let ((str1 (concatenate 'list (read-line)))
        (str2 (concatenate 'list (read-line))))
    (format t "~a~%" (solve str1 str2))))

(main)


Measured memory_bytes: 47628
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  char a,b;
  cin>>a>>b;
  if(a=='9'||b=='9')cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#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++)
#define VL vector<ll>

int main(){
  ll N, M;  cin >> N >> M;
  if(N >= M){cout << 0 << endl; return 0;}
  VL x(M); rep(i,0,M) cin >> x[i];
  sort(x.begin(), x.end());
  
  ll L = x[M-1] - x[0];
  VL l(M-1);
  rep(i,1,M){
    l[i-1] = x[i] - x[i-1];
    //cout << l[i-1] <<endl;
  }
  sort(l.rbegin(), l.rend());

  rep(i,0,N-1){
    L -= l[i];
  }
  cout << L << endl;
  return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  map<char, int> m;
  for (auto &i : s) m[i] = 1;
  if (m['N'] == m['S'] && m['W'] == m['E']) {
    cout << "Yes" << '\n';
  }
  else cout << "No" << '\n';
}


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

void swap(char *a,char *b){
	int w=*a;
	*a=*b;
	*b=w;
}
int main(){
	string str;
	cin >> str;
	for(int i=0;i<str.size()/2;i++){
		swap(str[i],str[str.size()-i-1]);
	}
	cout << str << endl;

		return 0;
}

Measured memory_bytes: 1172
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [h, a] <- getIntList
  print $ (h + a - 1) `div` a

Measured memory_bytes: 380
//In the name of God:)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;

long long dp[MAXN] , w[MAXN] , v[MAXN];


int main(){
    long long n , mw;
    long long ans = 0;
    scanf("%lld%lld" , &n , &mw);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld%lld" , w + i , v + i);
        for(int j = mw ; j >= w[i] ; j--){
            dp[j] = max(dp[j] , dp[j-w[i]] + v[i]);
            ans = max(ans , dp[j]);
        }
    }
    printf("%lld\n" , ans);
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <math.h>
int main(void){
    int a,b,C;
    double S,l,h,c;
    double PI = acos(-1);
    scanf("%d %d %d",&a,&b,&C);
    c = C*PI/180;
    S = (double)a*b*sin(c)/2;
    l = (double)a+b+(sqrt(a*a+b*b-2*a*b*cos(c)));
    h = (double)b*sin(c);
    printf("%.8f %.8f %.8f\n",S,l,h);
    return 0;
}





Measured memory_bytes: 2128
n = int(input())
B = [input() for i in range(n)]
A = ["AC","WA","TLE","RE"]
C = [0] * 4
for i in range(n):
    for j in range(4):
        if B[i] == A[j]:
            C[j] += 1

for i in range(4):
    print("{} x {}".format(A[i],C[i]))

Measured memory_bytes: 82820
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  int count=0;

   
  cin >> a >>b;
  
  for (int i = a; i <=b; i++) {
 
   int c;
   int d;
   int e;
   int f;
   int g;
   g=i;
   c=g%10;
   g/=10;
   d=g%10;
   g/=100;
   e=g%10;
   g/=10;
   f=g%10;
        if(c==f&&d==e){
       count++;
   }
 
  }
  cout <<count<<endl;
}


Measured memory_bytes: 3600
local n = io.read("*n")
local t = {}
for i = 1, n do t[i] = io.read("*n") end
local c = 0
for i = 2, n - 1 do
  if (t[i - 1] - t[i]) * (t[i + 1] - t[i]) < 0 then
    c = c + 1
  end
end
print(c)


Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

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

    vector<int> a(n);
    int index = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 1)index = 1;
    
    }
    bool flag = true;

    if(index == 0){
        flag = false;
    }
    index = 1;

    for(int i = 0; i < n; i++){
        if(a[i] == index){
            index++;
        }
    }

    int ans = n - (index - 1) ;
    if(flag){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }


}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int gcd(int a, int b){ 
    if (a == 0) 
        return b; 
    return gcd(b%a, a); 
} 
void solve(){
    int n;
  	cin>>n;
  	int lcm=n*360/gcd(n,360);
  	cout<<lcm/n<<"\n";
}

int main(){
    fastio
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  
  int num = 0;
  int sum = 0;
  int dig = 0;
  int ans = 0;
  for (int i=1; i<=n; i++){
    num = i;
    sum = 0;
    while (num) {
      dig = num % 10;
      sum = sum + dig;
      num = num / 10;
    }
    if (a <= sum && sum <=b){
      ans = ans + i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	int b=s.length(),l=b,c=0,cm=0;
	FOR(i,0,l){
		if(s[i]=='S'){
			c++;
		}else{
			if(c>0){
				c--;
				cm+=2;
			}

		}
	}
	cout<<l-cm;
    return 0;
}


Measured memory_bytes: 952
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ll i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();

    int a,b;
    cin>>a>>b;
    for(int i = b-a+1;i<b+a;i++)
    	cout<<i<<" ";

	return 0;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement

N,M,Q=map(int,input().split())
abcd=[]
A=[]
ans=0
for _ in range(Q):
    abcd.append(list(map(int,input().split())))

for A in combinations_with_replacement(range(1,M+1),N):
    tensu=0
    for abcd_i in abcd:
        ai=abcd_i[0]
        bi=abcd_i[1]
        ci=abcd_i[2]
        di=abcd_i[3]

        if A[bi-1]-A[ai-1]==ci:
            tensu+=di
        
    ans=max(ans,tensu)

print(ans)

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

int main(){
  int r, d;
  vector<int> x(11);
  cin >> r >> d >> x.at(0);
  for(int i = 1; i <= 10; i++){
    x.at(i) = r * x.at(i-1) - d;
  }
  for(int i = 1; i <= 10; i++) cout << x.at(i) << endl;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top;
int S[1000];
int pop(){
	top--;
	return S[top+1];
}
void push(int x){
	S[++top]=x;
}
int main(){
	char s[100];
	int a,b;
	top=0;
	while(~scanf("%s",s)){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}
		else if(s[0]=='-'){
			b=pop();
			a=pop();
			push(a-b);
		}
		else if(s[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}
		else{
			push(atoi(s));
		}
	}
	printf("%d\n",pop());
}

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

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

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    val cs = CharArray(200000) + s.toCharArray() + CharArray(200000)

    var l = 200000
    var r = l + s.length
    var d = 0

    val n = readLine()!!.toInt()
    repeat(n) {
        val q = readLine()!!
        if (q[0] == '1') {
            d += 1
            d %= 2
            return@repeat
        }

        val f = (q[2] - '1' + d) % 2
        if (f == 0) {
            cs[l - 1] = q[4]
            l--
        } else {
            cs[r] = q[4]
            r++
        }
    }

    println(cs.slice(l until r).let { if (d == 0) it else it.reversed() }.joinToString(""))
}


Measured memory_bytes: 52864
#include <bits/stdc++.h>
#include <cstdio>
#include <string>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 100;

int N;
int X[MAX_N], Y[MAX_N], H[MAX_N];

signed main()
{
    cin >> N;
    int k = 0;
    for(int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> H[i];
        if(H[i] != 0) {
            k = i;
        }
    }

    for(int x = 0; x <= 100; x++) {
        for(int y = 0; y <= 100; y++) {
            int h = H[k] + abs(X[k] - x) + abs(Y[k] - y);
            // cerr << x << " " << y << " " << h << endl;
            if(1 <= h) {
                bool flag = true;
                for(int i = 0; i < N && flag; i++) {
                    if(max(h - abs(X[i] - x) - abs(Y[i] - y), (LL)0) != H[i]) {
                        flag = false;
                    }
                }
                if(flag) {
                    cout << x << " " << y << " " << h << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))

import collections
c= collections.Counter(A)

counter = 0
for j in c.keys():
    if c[j]>=2:
        counter += c[j]*(c[j]-1)/2


for i in A:
    c[i]
    print(int(counter-c[i]+1))


Measured memory_bytes: 26140
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	LL n;
	cin >> n;
	LL t = n;
	for(LL i = 1; i * i <= n; ++i){
		if(n % i == 0){
			t = n / i;
		}
	}
	char buf[21];
	printf("%d\n", sprintf(buf, "%lld", t));
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,ans;
//最大公約数
ll gcd(ll a,ll b){
    
    if(a==0 || b==0)return 0;
    if(a<b){
        ll sw;
        sw=a;
        a=b;
        b=sw;
    }
    
    ll r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
//最小公倍数
ll lcm(ll a,ll b){


    if(a==0 || b==0)return 0;

    return a/gcd(a,b)*b;

}
signed main(){
	cin>>n>>m;
	if(n%m==0)cout<<0<<endl;
	else{
		n=n%m;
		cout<<min(m-n,n)<<endl;
	}
	
}

Measured memory_bytes: 256
n = int(input())
high = list(map(int,input().split()))

a = True

for x in reversed(range(1,n)):
  if high[x-1] >= high[x] + 2:
    a = False
    break
  elif high[x-1] == high[x] + 1:
    high[x-1] = high[x]
    
if a:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 20744
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        Integer[] a = new Integer[N];
        int alice = 0;
        int bob = 0;
        for(int i = 0; i < N; i++){
            a[i] = in.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());
        for(int i = 0; i < N; i++){
            if(i%2==0){
                alice += a[i];
            }else{
                bob += a[i];
            }
        }
        System.out.println(alice-bob);
        in.close();
    }
}


Measured memory_bytes: 22100
fun main(args: Array<String>) {
    val aMap = (1..3).map { readLine()!!.split(' ').map(String::toInt).toMutableList() }
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        val b = readLine()!!.toInt()
        for (j in 0..2)
            for (k in 0..2)
                if (aMap[j][k] == b) aMap[j][k] = 0
    }

    var isBingo = false
    for (j in 0..2) {
        if (aMap[j][0] == 0 && aMap[j][1] == 0 && aMap[j][2] == 0) isBingo = true
        if (aMap[0][j] == 0 && aMap[1][j] == 0 && aMap[2][j] == 0) isBingo = true
    }
    if (aMap[0][0] == 0 && aMap[1][1] == 0 && aMap[2][2] == 0)isBingo = true
    if (aMap[0][2] == 0 && aMap[1][1] == 0 && aMap[2][0] == 0)isBingo = true

    if (isBingo) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 38040
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;

const int BIG_NUM = 1e9;

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

    ll a, b, k;
    cin >> a >> b >> k;
    if(k <= a) {
        cout << a - k << " " << b;
    } else if(k <= a + b) {
        cout << 0 << " " << b - (k - a);
    } else {
        cout << 0 << " " << 0;
    }
    return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int N=4e5+5;
int n,a[N],b[N],x[N],y[N];
int s[N*3];ll hb,h[N];
ll p[N];
void init()
{
	p[0]=1;
	for(int i=1;i<=2*n;i++)p[i]=p[i-1]*173%mod;
	for(int i=1;i<n;i++)x[i]=a[i]^a[i+1];x[n]=a[1]^a[n];
	for(int i=1;i<n;i++)y[i]=b[i]^b[i+1];y[n]=b[1]^b[n];
	for(int i=1;i<=n;i++)s[i]=s[i+n]=x[i];
	for(int i=1;i<=2*n;i++)h[i]=(h[i-1]*173%mod+s[i])%mod;
	for(int i=1;i<=n;i++)hb=(hb*173%mod+y[i])%mod;
	return;
}
bool same(int l,int r)
{
	return ((h[r]-h[l-1]*p[r-l+1]%mod+mod)%mod)==hb;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	init();
	for(int i=1;i<=n;i++)
		if(same(i,i+n-1))
			cout<<i-1<<" "<<(a[i]^b[1])<<"\n";
	return 0;
}

Measured memory_bytes: 17792
a,b = map(int,input().split())
li = [-int(x) for x in input().split()]
import heapq
heapq.heapify(li)
for i in range(b):
    c = heapq.heappop(li)
    heapq.heappush(li,c/2)
li = [int(x) for x in li]
print(-sum(li))

Measured memory_bytes: 14224
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  i64 X, K, D;
  cin >> X >> K >> D;

  if (abs(X) >= D) {
    i64 a = min(abs(X) / D, K);
    X = abs(X) - D * a;
    K -= a;
  }

  if (K & 1) {
    X = abs(X - D);
  }
  X = abs(X);
  cout << X;
}
#endif


Measured memory_bytes: 3660
# -*- coding: utf-8 -*-
"""
D - Megalomania
https://atcoder.jp/contests/abc131/tasks/abc131_d

"""
import sys


from heapq import heappop, heappush

def solve(N, tasks):
    ct = 0
    hq = []
    for a, b in tasks:
        heappush(hq, (b, a))

    while hq:
        b, a = heappop(hq)
        ct += a
        if ct > b:
            return 'No'
    return 'Yes'


def main(args):
    N = int(input())
    tasks = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, tasks)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 52348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		scanner.close();

		if (1 <= N && N <= 999) {
			System.out.println("ABC");
		} else {
			System.out.println("ABD");
		}
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>

int cmp(const void* a,const void* b){
	return *(int*)a - *(int*)b;
}
int b[200000]={};
int main(void){
	int n,k;
	scanf("%d%d",&n,&k);
	int i,c=0;
	int a[n];
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	qsort(a,n,sizeof(int),cmp);
	for(i=0;i<n;i++){
		b[c]++;
		while(a[i]==a[i+1]){
			i++;
			b[c]++;
		}
		c++;
	}
	//cはボールの種類数で,b[i]にはその数が入る
	//ボールに書かれている整数がK種類以下にする最適な方法は、
	//b[i]が小さいヤツから消していく
	qsort(b,c,sizeof(int),cmp);
	int ans = 0;
	for(i=0;i<c-k;i++){
		ans += b[i];
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 2156
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N, K;
	cin >> N >> K;

	int del = (N - 1) * (N - 2) / 2 - K;

	if (del < 0) {
		cout << -1 << "\n";
		return 0;
	}

	vector<pair<int, int>> ans;
	ans.reserve(N * (N - 1) / 2);
	for (int i = 2; i <= N; i++) ans.emplace_back(1, i);

	int l = 2, r = 2;
	while (del--) {
		ans.emplace_back(l, ++r);
		if (r == N) r = ++l;
	}

	cout << ans.size() << "\n";
	for (const auto &e : ans) cout << e.first << " " << e.second << "\n";

	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
int main(){
  int N,K,i,j,tmp,sum;
  sum=0;
  scanf("%d %d",&N,&K);
  int P[N+1];
  for(i=0;i<N;i++) scanf("%d",&P[i]);
  for(i=0;i<N;i++){
	for(j=i+1;j<N;j++){
	    if(P[i]>P[j]){
          tmp=P[i];
          P[i]=P[j];
          P[j]=tmp;
        }
    }
  }
  for(i=0;i<K;i++) sum=sum+P[i];
  printf("%d",sum);
  return 0;
}

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

int main(){
    string S;
    cin >> S;
    
    for (int i=0;i<2;i++){
        if (S[i]!=S[i+1]){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;


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

	int N,R;
	cin >> N >> R;
	int ans = 0;
	int sum = 0;

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


Measured memory_bytes: 3604
S = int(input())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


n = S//3
ans = 0

for i in range(1,n+1):
    s = S-i*3
    ans += cmb(s+i-1,i-1,mod)
    ans %= mod
    
print(ans)

Measured memory_bytes: 10316
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long int lo;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e10 + 7
#define FOR for(lo i = 0 ; i < n ; i++)
#define FORV for(lo i = 0 ; i < (lo)v.size() ; i++)
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
#define si pair<string,lo>
lo a,b,c,d,e,n,m,k,t,h,x,y,a1[20][20],a2[100005];
char c1,c2,c3,c4;
string s1,s2,s3,s4;
double d1,d2,d3;
vector <lo> v;
map <lo,lo> mp1;
map <lo,lo> mp2;
set <lo> stt;
queue <lo> q;
priority_queue <lo> pq;
lo vis [10000];
int main() {
    // freopen("gir.gir", "r", stdin);
    // freopen("cik.cik", "w", stdout);
    lo ans = 0;
    cin >> a;
    ans += (a / 500) * 1000;
    a = a % 500;
    ans += (a / 5) * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    for(int i = 0;;i++)
    {
        int sum = 1;
        sum = sum + i * (a - 1);      
        if(sum >= b)
        {
            cout << i;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 100;
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int main()
{
    Fast_IO();
    int n ;
    cin >> n ;
    vector<pair<int , int >> v (n ) ;

    for ( pii &x : v)
        cin >> x.ss >> x.ff;

    sort(all(v)) ;
    int nxt = 0 ;
    for ( auto i : v)
    {
        if ( nxt + i.ss  > i.ff )
        {   cout << "No";
            return 0 ;
        }
    nxt = nxt + i.ss ;

    }
    cout << "Yes" ;
    return 0 ;
}


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

int main() {
    int n, k, d, s[101] = {}, t;
    cin >> n >> k;
    int cnt = 0;
    for (int j = 0; j < k; ++j) {
        cin >> d;
        for (int i = 0; i < d; ++i) {
            cin >> t;
            s[t] = 1;
        }
    }
    for (int j = 1; j <= n; ++j) {
        if (s[j] == 0) ++cnt;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
	int i,j,H,W; //input
	while(1)
	{
		cin >> H >> W;
		if( (H==0) && (W==0)) break; //??????????????????????????????????????????????????¶
		for ( i=0; i<H; i++)//??????????????? for????????????;????????????
		{
			for ( j=0; j<W; j++) //?¨?????????????
			{
				cout  <<  "#" ;
			}
			cout << endl; //?¨?????????????????????????????????????????????????
		}
		cout << endl; //????¨??????¨????????????????????????????????£????????§??????????????????
	}
	return 0;
}

Measured memory_bytes: 3076
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    K = I()
    N = 50
    a = [49] * 50
    k = K // 50
    kp = K % 50
    for i in range(N):
        t = k
        if i < kp:
            t += 1
        for j in range(N):
            if i == j:
                continue
            a[j] -= t
        a[i] += t * 50
    return '{}\n{}'.format(N, ' '.join(map(str,a)))



print(main())



Measured memory_bytes: 7876
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<ll>>;
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;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};int dy[4] = {0,-1,0,1};
int dz[4] = {1,-1,-1,1};int dw[4] = {1,1,-1,-1};
using Graph = vector<vector<int> >;
vector<int> ans(200100,0);
int seen[200100]={false};

void dfs(Graph &G,int a){
    seen[a] = true;
    for(auto nv : G[a]){ 
	if(seen[nv]) continue;
	ans[nv] += ans[a];
	dfs(G,nv);
    }
}
int dfs_root(Graph &G,int a,int b=0){
    if(G[a].size()==0) b = a;
    for(auto nv : G[a]){
	b = dfs_root(G,nv);
    }
    return b;
}
int main() {
    int n,q; cin >> n >> q;
    Graph G(n+1),G1(n+1);
    for(int i=0;i<n-1;i++){
	int a,b;cin >> a >> b;
	G[a].push_back(b);
	G[b].push_back(a);

	G1[b].push_back(a);
    }
    int root = dfs_root(G1,1);
//    cout << "root = " << root << endl;
    for(int i=0;i<q;i++){
	int a,b;cin >> a >> b;
	ans[a] += b;
    }
    dfs(G,root);
    for(int i=1;i<=n;i++){
	cout << ans[i];
	if(i!=n)cout << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 35200
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//227
	int a,b;
	cin>>a>>b;
	if(a%b!=0) {
		cout<<1;
	} else cout<<0;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

int main()
{
    string s;
    cin >> s;
    int a = 0, b = 0;
    for (int i = 0; i < s.size(); i++)
    {
        a += (s[i] == '0');
        b += (s[i] == '1');
    }
    cout << min(a, b) * 2 << endl;
}

Measured memory_bytes: 512
#
# 2d
#

def main():
    W, H, x, y, r = map(int, input().split())
    if x-r < 0 or x+r > W or y-r < 0 or y+r > H:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
double P[505],Q[505],dp[505][505],S[505][505];
int main()
{
	int n; cin>>n;
	for(int i=1;i<=n;i++) scanf("%lf",&P[i]);
	for(int i=0;i<=n;i++) scanf("%lf",&Q[i]);
	for(int i=1;i<=n;i++){
		dp[i][i] = P[i]+2*(Q[i-1]+Q[i]);
		S[i][i] = P[i]+Q[i-1]+Q[i];
	}
	double a1,a2;
	for(int k=1;k<n;k++)
		for(int i=1;i<=n-k;i++){
			int j = i+k;
			S[i][j] = S[i][j-1]+P[j]+Q[j];
			a1 = S[i][j]+Q[i-1]+dp[i+1][j];
			a2 = S[i][j]+Q[j]+dp[i][j-1];
			dp[i][j] = min(a1,a2);
			for(int m=i+1;m<j;m++)
				dp[i][j] = min(dp[i][j],S[i][j]+dp[i][m-1]+dp[m+1][j]);
		}
	printf("%.8lf\n",dp[1][n]);
	return 0;
}


Measured memory_bytes: 7144
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll b,c=0,d,e,k,l,m,n,o=1,p=0,q,x,y,z,max1=0,ans=0,min1=10000000000000000;
    string s,t,u;
    ll a[5];
    cin>>n>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
   
    for(ll i=0;i<5;i++){
    min1=min(min1,a[i]);
      
    }
    cout<<(n-1)/min1+5<<endl;
    
}



Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
B = []
C = []
for num in A:
    if len(B) >= 3:
        print("No")
        break
    elif num in B: 
        C[B.index(num)] += 1
    else:
        B.append(num)
        C.append(1)


if len(B) >= 3:
    pass
elif len(B) == 1:
    if n == B[0] +1:
        print('Yes')
    elif n//B[0] >= 2:
        print('Yes')
    else:
        print('No')
elif B[0]  == (B[1]+1):
    k = C[1]
    m = B[1]
    if m-k+1 <= 0:
        print('No')
    elif (n-k) % (m-k+1) == 0:
        print('Yes')
    else:
        print('No')
elif B[1] == (B[0]+1):
    k = C[0]
    m = B[0]
    if m-k+1 <= 0:
        print('No')
    elif (n-k) % (m-k+1) == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')
    

Measured memory_bytes: 14008
#include<iostream>
#include<stack>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll sum=0;
int num[1000005];
int main()
{
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++) cin>>num[i],sum+=num[i];
	if(sum>n)
	{
		cout<<"-1";
		return 0;
	}
	else cout<<n-sum;
	return 0;
 } 

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int>S(m);
    vector<int>C(m);
    for (int i=0; i<m; i++) cin >> S[i] >> C[i];
    for (int i=0; i<1000; i++){
        string st = to_string(i);
        bool jud = true;
        if (st.size() != n) jud = false;
        for (int j=0; j<m; j++){
            if (st[S[j]-1] != (char)(C[j]+'0')) jud = false;
        }
        if (jud){
            cout << i;
            return 0;
        }
    }
    cout << -1;
}

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

int main() {
	
	int n;
	cin >> n;
	
	int ans = 0;
	rep(i, 3){
		if(n % 10 == 9) ans += 100;
		else ans += 900; 
		
		n /= 10;
		if(i < 2) ans /= 10;
	}
	cout << ans << endl;
	return 0;
}

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

int N;
int d_i[110];

int main(){
    int tmp=0,count=0;
    int num[110]={0};

    scanf("%d",&N);
    for(int i=0;i<N;i++)
	scanf("%d",&d_i[i]);

    for(int i=0;i<N;i++)
	num[d_i[i]]++;

    for(int i=1;i<=100;i++){
	if(num[i]>0)
	count++;
    }

    printf("%d\n",count);
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  for (int k = 1; k <= 1000; ++k) {
    if (k * (k - 1) / 2 == n) {
      cout << "Yes\n" << k << endl;
      vvi s(k);
      int t = 1;
      for (int i = 0; i < k; ++i) for (int j = i + 1; j < k; ++j) {
        s[i].push_back(t);
        s[j].push_back(t);
        ++t;
      }
      for (int i = 0; i < k; ++i) {
        cout << s[i].size();
        for (int x : s[i]) cout << ' ' << x;
        cout << endl;
      }
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF = 1000000007;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
int main(){
  int n;
  cin>>n;
  vector<long double>x(n);
  vector<long double>y(n);
  vector<int>next(n);
  rep(i,n){
    cin>>x[i]>>y[i];
    next[i] = i;
  }
  long double ans = 0;
  do{
    rep(i,n-1){
      ans += sqrt(pow(x[next[i]] - x[next[i+1]],2) + pow(y[next[i]] - y[next[i+1]],2));
    }
  } while (next_permutation(next.begin(),next.end()));
  
  cout << setprecision(10) << ans / facctorialMethod(n)<< endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R cin>>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
#define MIN(X,Y) ((X)>(Y)?(Y):(X))
using namespace std;
typedef long long ll;

int main(){
    int arr[5];
    int ans=0;
    int m=-1;
    rep(i, 5){
        R arr[i];
    }
    rep(i, 5){
        int x = ceil(arr[i]/10.0)*10;
        ans += x;
        m = max(m, x-arr[i]);
    }
    cout << ans - m << "\n";
}


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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n = 0;
	for(int i = 0; i < 4; i++)
	{
		char c;
		cin >> c;
		if(c == '+')
			n++;
		else
			n--;
	}
	cout << n;
	return 0;
}

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

int main(){

    int N;
    cin >> N;

    string S;
    cin >> S;

    string ans;

    char buf=S[0];

    for (size_t i = 0; i < N; i++)
    {
        if(buf != S[i]){
            ans.push_back(buf);
            buf=S[i];
        }
    }
    
    cout << ans.length()+1 << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int X;
    cin >> X;
    int ans = 0;
    ans += ((X / 500) * 1000);
    X %= 500;
    ans += ((X / 5) * 5);
    X %= 5;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        stack<int> S;
        int a, b;
        string s;

        while (cin >> s)
        {
                if (s[0] == '+')
                {
                        a = S.top();
                        S.pop();
                        b = S.top();
                        S.pop();
                        S.push(a + b);
                }
                else if (s[0] == '-')
                {
                        b = S.top();
                        S.pop();
                        a = S.top();
                        S.pop();
                        S.push(a - b);
                }
                else if (s[0] == '*')
                {
                        a = S.top();
                        S.pop();
                        b = S.top();
                        S.pop();
                        S.push(a * b);
                }
                else
                {
                        S.push(atoi(s.c_str()));
                }
        }
        cout << S.top() << endl;

        return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a[100001];
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>a[i];
  set<int> s;
  int c=0;
  for(int i=n-1;i>=0;i--){
    if(!s.count(a[i]))c++,cout<<a[i]<<endl;
    if(c==m)break;
    s.insert(a[i]);
  }
  return 0;
}

Measured memory_bytes: 5968
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

struct Edge {
    int to, id;
};

int n;
vector<int> ans;

void dfs(vector<vector<Edge>> &G, int v, int c=-1, int p=-1) {
    int k = 1;
    rep(i, G[v].size()) {
        int nv = G[v][i].to;
        int ei = G[v][i].id;
        if (nv == p) continue;
        if (k == c) ++k;
        ans[ei] = k;
        ++k;
        dfs(G, nv, ans[ei], v);
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n;
    vector<vector<Edge>> G(n);
    ans.resize(n, 0);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back((Edge){b, i});
        G[b].push_back((Edge){a, i});
    }

    dfs(G, 0);

    int mx = 0;
    rep(i, n) {
        chmax(mx, int(G[i].size()));
    }

    cout << mx << endl;
    rep(i, n - 1) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  ll n,k;
  cin >> n >> k;
  ll sum = 0;
  for(ll i = k; i<=n+1; i++){
    ll a = (i*(2*n-i+1)/2);
    ll b = (i*(i-1)/2);
    sum = (((a-b+1)%MOD)+sum)%MOD;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3632