akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
#define ll long long
#define ull unsigned ll
#define pb push_back
#define eps 1e-7
#define pi acos(-1)
#define F first
#define S second
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).X
#define dot(a,b) (conj(a)*(b)).Y
const int mod = 1e9+7 ;
typedef complex <ld> point ;
typedef vector <point> polygon ;
typedef tuple <int , int , int> line ;
//====================================
ll arr[1000005][3] ;
ll ans[1000005][3] ;
int main()
{
	_K
	ll n ;
	cin >> n ;
	for (int i =0 ; i  < n ;  i++){
		for (int j =0 ; j < 3 ; j++)
		{
			cin >> arr[i][j] ;
			if (i == 0) ans[0][j] = arr[i][j] ;
		}
	}
	for (int i = 1 ; i < n ; i++)
	{
		for (int j = 0 ; j < 3 ; j++)
		{
			if (j == 0)
				ans[i][j] = max(ans[i-1][j+1] , ans[i-1][j+2]) + arr[i][j] ;
			if (j == 1)
				ans[i][j] = max(ans[i-1][j-1] , ans[i-1][j+1]) + arr[i][j] ;
			if (j == 2)
				ans[i][j] = max(ans[i-1][j-1] , ans[i-1][j-2]) + arr[i][j] ;
		}
	}
	cout << max(ans[n-1][0] , max(ans[n-1][1] , ans[n-1][2])) ;
	return 0;
}

Measured memory_bytes: 8448
void main() {
  problem();
}

class LunlunNumber {
  immutable long number;

  this(long n) {
    deb([n]);
    number = n;

    if (!isValid) {
      throw new Exception("invalid number");
    }
  }

  bool isValid() {
    long n = number;
    while(n > 10) {
      const tail = n % 10;
      n /= 10;
      const preTail = n % 10;
      const spread = tail - preTail;
      if (-1 > spread || spread > 1) return false;
    }

    return true;
  }

  LunlunNumber next() {
    if (number < 10) return new LunlunNumber(number + 1);

    long n = number;
    long next = number;
    long dec = 1;
    bool isMiddle;
    while(n >= 10) {
      const tail = n%10;
      next -= dec*tail;
      n /= 10;

      const preTail = n%10;
      if (tail < 9 && preTail >= tail) {
        next += dec*(tail);
        isMiddle = true;
        break;
      }

      dec *= 10;
    }

    if (n < number) {
      next += dec;
    }

    if (isMiddle) dec *= 10;

    while(dec > 1) {
      const head = (next % (dec * 10)) / dec;
      const postHead = (next % dec) * 10 / dec;
      deb([dec, head, postHead]);
      dec /= 10;
      if (head - postHead > 1) {
        next -= dec * postHead;
        next += head == 0 ? 0 : dec * (head - 1);
      }
    }

    return new LunlunNumber(next);
  }

  override string toString() {
    return number.to!string;
  }

}

void problem() {
  const K = scan!long;

  long solve() {
    auto lunlun = new LunlunNumber(1);
    foreach(i; 1..K) {
      lunlun = lunlun.next();
    }

    return lunlun.number;
  }

  solve().writeln;
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.functional;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 1276
#include<stdio.h>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int main()
{
	int a[3];
	for(int i=0;i<3;i++)
		scanf("%d",&a[i]);
	sort(a,a+3);
	if(a[0]+a[1]==a[2])
	puts("Yes");
	else
	puts("No");	
	 
	return 0;
}

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

using namespace std;
const long long MOD = 1e18;

vector<pair<long long, long long>> factorize(long long n) {
    vector<pair<long long, long long>> a;

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            int cnt = 0;
            while (n % i == 0) {
                n /= i;
                cnt++;
            }
            a.push_back(make_pair(i, cnt));
        }
    }
    if (n > 1) a.push_back(make_pair(n, 1));
    return a;

}

int main() {
    int n, k;
    cin >> n >> k;
    if (k % 2) {
        cout << "No";
        return 0;
    }
    if (n * 4 >= k && k >= n * 2) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }


    return 0;
}

Measured memory_bytes: 3620
S = input()

def solve(S):
    buf = [1] * len(S)

    for i in range(len(buf) - 2):
        if S[i:i+2] == "RR":
            buf[i+2] += buf[i]
            buf[i] = 0

    for i in range(len(buf) - 1, 1, -1):
        if S[i-1:i+1] == "LL":
            buf[i-2] += buf[i]
            buf[i] = 0

    return buf

print(*solve(S))

Measured memory_bytes: 10356
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  ll N,A,B,C,D,E;
  cin >>N>>A>>B>>C>>D>>E;
  vector<ll> vec={N,0,0,0,0,0};
  vector<ll> key={A,B,C,D,E};
  B=min(A,B);
  C=min(B,C);
  D=min(C,D);
  E=min(D,E);
  ll k;
  if(N%E==0) k=N/E;
  else k= N/E+1;
  cout <<4+k<<endl;
}
 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
	int n,k;
	cin >> n >> k;
	string a;
	cin >> a;
	a=' '+a;
	int now=1,ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i-1]!='0'&&a[i]=='0')
			--k;
		while(k<0&&now<=i)
		{
			if(a[now]=='0'&&a[now+1]=='1') 
				++k;
			++now;
		}
		if(k>=0) ans=max(ans,i-now+1);
	//	cout << now << " " << i << "\n";
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
s = input()

if s =='SUN':
    ans = 7
elif s == 'MON':
    ans = 6
elif s == 'TUE':
    ans = 5
elif s == 'WED':
    ans = 4
elif s == 'THU':
    ans = 3
elif s == 'FRI':
    ans = 2
elif s == 'SAT':
    ans = 1

print(ans)

Measured memory_bytes: 38384
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> a_min(n);
  for(int i = 0;i < n;i++)cin >> a[i];


  int now = a[0];
  for(int i = 0;i < n;i++){
    a_min[i] = min(a[i],now);
    now = a_min[i];
  }

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

  cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    int cnt = 0;
    REP(i, h) {
        string a;
        cin >> a;
        REP(j, a.size())if(a[j] == '#') cnt++;
    }
    cout << (cnt == h + w - 1 ? "Possible" : "Impossible") << endl;
    return 0;
}


Measured memory_bytes: 256
import collections

N = int(input())
a = [int(i) for i in input().split()]
check = []
dict = collections.Counter(a)
for a, b in dict.items():
    if b >= 2:
        check.append(a)

if len(check) >=2:
    check.sort()
    if dict[check[-1]] >= 4:
        print(check[-1] ** 2)
    else:
        print(check[-1] * check[-2])
elif len(check) == 1:
    if dict[check[-1]] >= 4:
        print(check[-1] ** 2)
    else:
        print(0)
else:
    print(0)

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int i,j,n,m;
    cin>>n>>m;
    string s[n];
    long long int dp[n][m];
    for(i=0;i<n;i++){
        cin>>s[i];
    }
    dp[0][0]=1;
    for(i=1;i<m;i++){
        if(s[0][i]=='.')
            dp[0][i]=dp[0][i-1];
        else
            dp[0][i]=0;
    }
    for(i=1;i<n;i++){
        if(s[i][0]=='.')
            dp[i][0]=dp[i-1][0];
        else
            dp[i][0]=0;
    }
    for(i=1;i<n;i++){
        for(j=1;j<m;j++){
            if(s[i][j]=='.')
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
                else
                    dp[i][j]=0;
        }
    }
    cout<<dp[n-1][m-1];
    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k,s;
    int ans = 0;
    cin >> k >> s;
    for(int i=0;i<=k;i++) {
        for(int j=0;j<=k;j++) {
            int z=s-i-j;
            if(0<=z && z<=k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main( )
{
	int a,b,c;
	int max,min,total;
	scanf("%d %d %d",&a,&b,&c);
	total = a + b + c ;
	if(a > b && a > c)
	{
		max = a;
	}
	else if (b > a && b > c )
	{
	    max = b;	
	}	
	else 
	{
		max = c;
	}
	if(a < b && a < c)
	{
		min = a;
	}
	else if(b < a && b < c )
	{
		min = b;
	}
	else
	{
		min = c;
	}
	    printf("%d %d %d\n",min,total-max-min,max);
    return 0;
}



Measured memory_bytes: 2068
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <chrono>
#include <string>
#define Kami02
#define taskname "TEST"

using namespace std;
const int maxn=3e3+1;
const int mod=1e9+7;

int n,f[maxn][maxn];
string s;

inline void Enter(){
    cin>>n;
    cin>>s;
    s=' '+s;
    s=' '+s;
}
inline void Init(){
    f[1][1]=1;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=i;j++){
            if(s[i]=='<' && j==1) f[i][j]=0;
            else if(s[i]=='>' && j==i) f[i][j]=0;
            else{
                if(s[i]=='<') f[i][j]=f[i-1][j-1];
                else f[i][j]=(f[i-1][i-1]-f[i-1][j-1]+mod)%mod;
            }
            f[i][j]=(f[i][j]+f[i][j-1])%mod;
        }
    }
}

inline void Solve(){
    cout<<f[n][n];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); if(fopen(taskname".INP","r"))
    freopen(taskname".INP","r",stdin),
    freopen(taskname".OUT","w",stdout);
    #ifdef Kami
    auto start=chrono::steady_clock::now();
    #endif

    Enter();
    Init();
    Solve();

    #ifdef Kami
    auto end=chrono::steady_clock::now();
    cerr<<"\nIn milliseconds : "
        <<chrono::duration_cast<chrono::milliseconds>(end-start).count();
    cerr<<'\n'<<"In seconds : "<<fixed<<setprecision(3)
        <<(double)chrono::duration_cast<chrono::milliseconds>(end-start).count()/1000<<'\n';
    #endif

    return 0;
}


Measured memory_bytes: 34176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define pii pair<int , int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
bool good(string s , int l , int r)
{
	for(int i = l; i <= r; i++)
		if(s[i] != s[r - (i - l)])
			return false;
	return true;
}
int main()
{
	string s;
	cin >> s;
	int n = sz(s);
	if(good(s , 0 , (n - 1) / 2 - 1) && good(s , 0 , n - 1) && good(s , (n + 3) / 2 - 1 , n - 1))
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
		
}


Measured memory_bytes: 256
#include<queue>
#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define SC(x) scanf("%d",&x);
#define pr(x)  cout << x << endl;
#define mem(arr,v) memset(arr,v,sizeof arr);
#define bug(x) cout << "#x = " << x <<endl;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
typedef long long ll;
using namespace std;

//set<Node> S;
map <string,int> dp;
int dir[4] = {1,-1,4,-4};

bool f(int pos) {
	return pos >= 0 && pos < 8;
}


//
//void bfs() {
//	queue<string> q;
//	q.push("01234567");
//	M["01234567"] = 0;
//	
//	while(!q.empty()) {
//		string s = q.front();	q.pop();
//		int pos;
//		for(int i = 0 ; i < 8 ; i++)
//			if(s[i] == '1') {
//				pos = i;
//				break;
//			}
//
//		for(int i = 0 ; i < 4; i++) {
//			int px = pos + dir[i];
//			if(!f(px) || (px == 3 && i == 0) || (px == 4 && i == 1) )	continue;
//				
//			string cur = s;
//			swap(cur[pos],cur[px]);
//			if(M.count(cur) == 0){
//				M[cur] = M[s] + 1;
//				q.push(cur);
//			}
//		}
//	}
//}
void bfs()  
{  
    queue<string> que;  
    que.push("01234567");  
    dp["01234567"] = 0;  
    while (!que.empty())  
    {  
        string now = que.front(); que.pop();  
        // p是'0'的位置  
        int p = 0;  
        for (int j = 0; j < 8; ++j)  
        {  
            if (now[j] == '0')  
            {  
                p = j;  
                break;  
            }  
        }  
   
        for (int i = 0; i < 4; ++i)  
        {  
            int n = p + dir[i];  
            if (0 <= n && n < 8 &&   
                !(p == 3 && i == 0) && // 右上角不能再往右了  
                !(p == 4 && i == 1))   // 左下角不能再往左了  
            {  
                string next = now;  
                swap(next[p], next[n]);  
                if (dp.find(next) == dp.end())  
                {  
                    dp[next] = dp[now] + 1;  
                    que.push(next);  
                }  
            }  
        }  
    }  
}  

int main() {
	bfs();
	string str;
	while(getline(cin,str)){
		str.erase(remove(str.begin(),str.end(),' '),str.end());
		pr(dp[str]);
	}
}

Measured memory_bytes: 5368
loop do
    n = gets.to_i
    break if n == 0
    events = []
    n.times do
        t1, t2 = gets.chomp.split
        events += [[t1, 1], [t2, -1]]
    end
    count = max = 0
    events.sort.each do |t, d|
        count += d
        max = count if count > max
    end
    p max
end

Measured memory_bytes: 100468
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
from functools import reduce

def main():
    N, K = MI()
    H = LI()
    H.sort(reverse=True)
    ans = sum(H[K:])
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 102404
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    ll A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B), x(Q);
    REP(i, A) cin >> s[i];
    REP(i, B) cin >> t[i];
    REP(i, Q) cin >> x[i];

    ll s1, s2, t1, t2;
    REP(i, Q){
        auto s_tmp = lower_bound(s.begin(), s.end(), x[i]);
        auto t_tmp = lower_bound(t.begin(), t.end(), x[i]);
        if (s_tmp == s.end()) {
            s1 = *(s.end() - 1);
            s2 = INF;
        } else if (s_tmp == s.begin()){
            s1 = -INF;
            s2 = *s.begin();
        } else{
            s1 = *(s_tmp - 1);
            s2 = *s_tmp;
        }
        if (t_tmp == t.end()) {
            t1 = *(t.end() - 1);
            t2 = INF;
        } else if (t_tmp == t.begin()){
            t1 = -INF;
            t2 = *t.begin();
        } else{
            t1 = *(t_tmp - 1);
            t2 = *t_tmp;
        }
        //cout << "s1: " << s1 << " s2:" << s2 << endl;
        //cout << "t1: " << t1 << " t2:" << t2 << endl;
        ll tmp = INF;
        tmp = min(tmp, max(s2, t2) - x[i]);
        tmp = min(tmp, x[i] - min(s1, t1));
        tmp = min(tmp, 2 * s2 - x[i] - t1);
        tmp = min(tmp, 2 * t2 - x[i] - s1);
        tmp = min(tmp, t2 + x[i] - 2 * s1);
        tmp = min(tmp, s2 + x[i] - 2 * t1);
        cout << tmp << endl;
    }

    return 0;
}


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

int main() {
  int N,A;
  cin>>N>>A;
  int x=N/500;
  int y=N-500*x;
  if(A>=y){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M; cin >> N >> M;
    ll A[N]; rep(i, N) cin >> A[i];
    //forall k,exists p, X = A[k]*(p+0.5)
    //2X = A[k]*(2p+1)
    //X = B[k]*(2p+1) (B[k]=A[k]/2)
    rep(i, N) A[i]/=2;
    //Xはlcm(B)の倍数で,XをB[k]で割ったものは常に奇数
    //Bに含まれる素因数2の個数は全て同じ
    int base = 0;
    ll temp = A[0]; while(temp % 2 == 0){base++; temp/=2;};
    for(int i = 1; i < N; i++){
        temp = A[i];
        int acc = 0;
        while(temp % 2 == 0){
            temp /= 2;
            acc++;
        }
        if(acc != base){
            cout << 0 << endl;
            return 0;
        }
    }
    ll lcm = 1;
    rep(i, N){
        lcm = lcm*A[i]/__gcd(lcm, A[i]);
        if(lcm > M){
            cout << 0 << endl;
            return 0;
        }
    }
    //lcmの奇数倍はいくつあるか
    //lcm*(2k+1) <= M, 2lcm*k <= M-lcm
    cout << (M-lcm)/(lcm*2) + 1 << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
                int N = sc.nextInt();
                int j;
                for(int i=0; i<N; i++){
                        j = sc.nextInt();
                        if(map.containsKey(j)){
                                map.put(j,map.get(j)+1);
                        }else{
                                map.put(j,1);
                        }
                }
                int count = 0;
                for(Integer Key : map.keySet()){
                        if(Key <= map.get(Key)){
                                count += map.get(Key) - Key;
                        }else{
                                count += map.get(Key);
                        }
                }

                System.out.println(count);
        }
}



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

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    string ans;
    for (int i = 0; i < n; i++)
    {
        cin >> s.at(i);
    }

    sort(s.begin(), s.end());
    ans = s.at(0);
    for (int i = 1; i < n; i++)
    {
        ans += s.at(i);
    }

    cout << ans << endl;
}

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

if N >= M:
    print(0)
else:
    X = sorted(X)
    X_diff = [X[i] - X[i-1] for i in range(1, len(X))]
    X_diff = sorted(X_diff, reverse=True)
    print(sum(X_diff[N-1:]))


Measured memory_bytes: 13960
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7; 
const int N=2e5 + 5;
bool visit[N];
ll pre[N];
int OO=1e6; 
 
ll n,m,k,cnt,SU,idx,len,MN,MX,T,prime;
ll l,r,mid;
ll a,b,c,d;
vector<int> vec,v;
string str="BGR",s;

ll Power(ll n,ll m,ll p){
	ll res=1;
	n%=p;
	
	while(m){
		
		if(m&1)
			res=(res * n)%p;
		
		n=(n*n)%p;
		m>>=1;
	}
	
	return res;
	
}

int main(){
	
	cin>>n>>m;
//	Seive();
	
	for(int i=m;i;--i){
		pre[i]=Power(m/i,n,MOD);
		
		for(int j=2*i;j<=m;j+=i){
			pre[i]-=pre[j];
			pre[i]+=MOD;
			pre[i]%=MOD;
		}
		
		cnt+=(i*pre[i]);
		cnt%=MOD;
		
	}
	

	
	cout<<cnt<<endl;
	
	
	
}
 
 
 
 
 
 
 
 

Measured memory_bytes: 4356
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s[3];
    rep(i, 0, 3) cin >> s[i];
    int ans = 0;
    rep(i, 0, n){
        set<char> st;
        rep(j, 0, 3) st.insert(s[j][i]);
        ans += st.size() - 1;
    }
    cout << ans << endl;
}

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

if n % 2 == 1:
    left = a[0::2][::-1]
    right = a[1::2]
else:
    left = a[1::2][::-1]
    right = a[0::2]

ans = left + right

print(*ans)

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


int main(){

    long A,B,C,K;
    cin >> A >> B >> C >> K;

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

    return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
using namespace std;
int n,m,a[105],sum,cnt,t;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		sum+=a[i];
	}
	t=sum/(4*m);
	for(int i=1;i<=n;++i){
		if(1.0*a[i]>=1.0*sum/(4*m))++cnt;
	}
	if(cnt>=m)printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<long long> A(N);
  for (int i=0; i<N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  vector<vector<long long>> BC(M, vector<long long>(2));
  for (int i=0; i<M; i++){
    cin >> BC[i][0] >> BC[i][1];
  }
  sort(BC.begin(), BC.end(), [](const auto &x, const auto &y){return x[1] > y[1];});
  long long ans = 0;
  int changed = 0;

  // for (int i=0; i<M; i++){
  //   cout << BC[i][0] << ' ' << BC[i][1] << endl;
  // }

  for (int i=0; i<M; i++){
    int check = (lower_bound(A.begin(), A.end(), BC[i][1]) - A.begin());
    // cout << ans << endl;
    // cout << check << endl;
    if (check <= changed) continue;
    else if (check-changed <= BC[i][0]){
      ans += (check-changed) * BC[i][1];
      changed = check;
      break;
    }
    else {
      ans += BC[i][0] * BC[i][1];
      changed += BC[i][0];
    }
    if (changed == N) break;
  }
  // cout << ans << endl;
  for (int i=changed; i<N; i++){
    ans += A[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	int n;cin>>n;
	set<string>se;
	rep(i,s.size())rep(j,5)se.insert(s.substr(i,j+1));
	auto it=se.begin();
	rep(i,n-1)it++;
	cout<<*it<<endl;
}










Measured memory_bytes: 1664
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<limits.h>
#include<string.h>

int main(void){
	int n,m,x,y,tmp,i;
	int xs=-100,ys=100;

	scanf("%d %d %d %d",&n,&m,&x,&y);
	for(i=0;i<n;i++){
		scanf("%d",&tmp);
		if(xs<tmp) xs=tmp;
	}
	for(i=0;i<m;i++){
		scanf("%d",&tmp);
		if(ys>tmp) ys=tmp;
	}
	printf((xs<ys && xs>=x && ys<=y)?"No War\n":"War\n");
	return 0;
}


Measured memory_bytes: 128
K, A, B = map(int, input().split())

if A+2>=B:
    ans = 1+K
else:
    k = K-A+1 #初回にA枚まで増やした後の回数
    ans = A + k//2 * (B-A)
    if k%2:
        ans += 1
print(ans)

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    if(N/10 == 9 || (N%10) == 9) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int l[10];
	for(int i = 0; i < n; i++){
		cin >> l[i];
	}


	int max = l[0];
	int sumx = l[0];

	for(int i = 1; i < n; i++){
		if(l[i] > max){
			max = l[i];
		}

		sumx += l[i];
	}

	sumx -= max;


	if(max < sumx){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,a,b,ca,cb,i,bo;
  char s[100001];
  scanf("%d %d %d",&n,&a,&b);
  scanf("%s",s);
  bo=a+b;
  ca=cb=0;
  for(i=0;i<n;i++){
    if(s[i]=='a'){
      if(ca<bo){
	puts("Yes");
	ca++;
      }
      else puts("No");
    }
    else if(s[i]=='b'){
      if(ca<bo&&cb<b){
	puts("Yes");
	ca++;
	cb++;
      }
      else puts("No");
    }
    else puts("No");
  }
  return 0;
}


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

int main () {
  int N, X;
  cin >> N >> X;
  
  vector<int> l(N);
  for (int i=0; i<N; i++) {
    cin >> l.at(i);
  }
  
  int ans = 0;
  int vec = 0;
  while (ans < N) {
    vec += l.at(ans);
    ans++;
    if (vec > X) {
      ans--;
      break;
    }
  }
  
  cout << ans + 1 << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vll;
ll INF = 1e9;
int main(){
  ll n, m, R;
  cin >> n >> m >> R;
  vll r(R);
  for (ll i = 0; i < R; i++) cin >> r[i];
  sort(r.begin(), r.end());
  vector<vll> d(n, vll(n, INF));
  for (ll i = 0; i < m; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    d[a - 1][b - 1] = c;
    d[b - 1][a - 1] = c;
  }
  
  for (ll k = 0; k < n; k++) {
    for (ll i = 0; i < n; i++) {
      for (ll j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  
  do {
    ll dist = 0;
    for (ll i = 0; i < R - 1; i++) {
      dist += d[r[i] - 1][r[i + 1] - 1];
    }
    if (INF > dist) INF = dist;
  } while (next_permutation(r.begin(), r.end()));
  
  cout << INF << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    fast_io;
    string a;
    ll s = 0;
    cin >> a;
    for (auto f: a) s += (f - '0');
    cout << (s % 9 ? "No" : "Yes");
    return 0;
}

Measured memory_bytes: 3748
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

//collections
//use std::collections::BTreeMap;
use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        n: usize,
        m: usize,
        py: [(usize,u64);m],
    }

    let mut ans = vec![String::new(); m];
    let mut dics = vec![BTreeSet::new(); n];

    for i in 0..m {
        dics[py[i].0 - 1].insert((py[i].1, i));
    }

    for (p, x) in dics.iter().enumerate() {
        for (j, &(_, i)) in x.iter().enumerate() {
            ans[i] = format!("{:06}{:06}", p + 1, j + 1);
        }
    }

    for e in ans {
        println!("{}", e);
    }
}


Measured memory_bytes: 38396
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int[] a = cin.ReadIntArray(n);

            int tmp = -1;
            int result = 0;
            for(int i = 0; i < n; i++)
            {
                if(a[i] != tmp)
                {
                    tmp = a[i];
                    continue;
                }
                else
                {
                    tmp = -1;
                    result++;
                }
            }

            Console.WriteLine(result);
        }
    }

    class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;

        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

vector<vector<ll>> dist(1010, vector<ll>(1010, 1e9));

void dijkstra(int s, vector<vector<P>> &G){
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s][s] = 0;
    que.emplace(0, s);

    while(que.size()){
        ll ccost, cv;
        tie(ccost, cv) = que.top();
        que.pop();

        if(dist[s][cv] < ccost) continue;

        for(auto x : G[cv]){
            ll nv, ncost;
            tie(nv, ncost) = x;
            
            if(dist[s][cv] + ncost < dist[s][nv]){
                dist[s][nv] = dist[s][cv] + ncost;
                que.emplace(dist[s][nv], nv);
            }
        }
    }
}

int main(){
    int n, m, k, p; cin>>n>>m>>k>>p;
    p--;
    vector<vector<P>> G(n);
    for(int i=0; i<m; i++){
        int x, y, w; cin>>x>>y>>w;
        x--, y--;
        G[x].emplace_back(y, w);
        G[y].emplace_back(x, w);
    }

    for(int i=0; i<n; i++){
        dijkstra(i, G);
    }

    vector<int> s(k), t(k);
    vector<int> v;
    for(int i=0; i<k; i++){
        cin>>s[i]>>t[i];
        s[i]--, t[i]--;
        v.emplace_back(i);
        v.emplace_back(i);
    }

    ll ans = 1e18;
    do{
        ll sum = dist[p][s[v[0]]];
        bool valid = true;
        if(sum == 1e9) valid = false;
        vector<int> visited(k, 0);
        visited[v[0]]++;
        for(int i=0; i<2*k-1; i++){
            ll cdist = 0;
            if(visited[v[i+1]] == 0){
                if(visited[v[i]] == 1){
                    cdist = dist[s[v[i]]][s[v[i+1]]];
                }
                else{
                    cdist = dist[t[v[i]]][s[v[i+1]]];
                }
            }
            else{
                if(visited[v[i]] == 1){
                    cdist = dist[s[v[i]]][t[v[i+1]]];
                }
                else{
                    cdist = dist[t[v[i]]][t[v[i+1]]];
                }
            }

            visited[v[i+1]]++;

            if(cdist == 1e9) valid = false;
            else sum += cdist;
        }

        if(valid) ans = min(ans, sum);

    }while(next_permutation(v.begin(), v.end()));

    if(ans == 1e18){
        cout << "Cannot deliver" << endl;
    }
    else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 11192
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
import std.numeric;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void main()
{
    auto s = readln.chomp;
    auto t = readln.chomp;
    char[char] dict1;
    char[char] dict2;

    foreach (i; 0 .. s.length)
    {
        if (s[i] in dict1 && dict1[s[i]] != t[i])
        {
            writeln("No");
            return;
        }
        else
            dict1[s[i]] = t[i];

        if (t[i] in dict2 && dict2[t[i]] != s[i])
        {
            writeln("No");
            return;
        }
        else
            dict2[t[i]] = s[i];
    }
    writeln("Yes");
}


Measured memory_bytes: 2656
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
int a,b,c;
int main() {
	//freopen("1.txt","r",stdin);
	read(a); read(b); read(c);
	printf("%d\n",max(0,c-(a-b)));
	return 0;
}

Measured memory_bytes: 256
n=int(input())
buff=[]
ans=1
for i in range(n):
    buff.append(input())

a=sorted(buff)

for i in range(1,n):
    if a[i] == a[i-1]:
        a[i-1]= -1
        a[i]= -1
        if ans>0:
            ans -= 1
    else:
        ans += 1

print(ans)

Measured memory_bytes: 11484
#include <stdio.h>
#include <inttypes.h>

int main(void)
{
    uint_fast8_t a, b;
    scanf("%" SCNuFAST8 " %" SCNuFAST8, &a, &b);
    if (a + b >= 10) {
        puts("error");
    } else {
        printf("%" PRIuFAST8 "\n", a + b);
    }
    return 0;
}


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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK\n";
            return 0;
        }
    }
    cout<<"NG\n";
}



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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
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()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m; cin >> n >> m; ll s = 0;
  vector<ll> a(m); FOR(i,m){ cin >> a[i]; s+=a[i]; }


  //main
  ll ans = 0;
  if(s>n){
      ans = -1;
  }else{
      ans = n-s;
  }
  
  // output
  cout << ans << endl;

  return 0;
}

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

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

	int p[10];
	int sum = 0;
	int max = 0;
	for (int i = 0; i < n; i++) {
		cin >> p[i];

		sum += p[i];
		if (max < p[i]) max = p[i];
	}

	cout << sum - max/2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#include<algorithm>
#include<queue>
typedef long long ll;
#include<vector>
#define cin(n) scanf("%lld",&(n))
#define cout(n) printf("%lld",(n))
#define couc(c) printf("%c",(c))
#define coutn printf("\n")
#define cout_ printf(" ")
#define debug() printf("haha\n")
const int MAXN= 1e6 + 5 ;
ll t;
ll n,k;
ll a[MAXN];
ll an;
int main()
{
    cin(n);
    if(n==25)
        printf("Christmas\n");
    else if(n==24)
        printf("Christmas Eve\n");
    else if(n==23)
        printf("Christmas Eve Eve\n");
    else if(n==22)
        printf("Christmas Eve Eve Eve\n");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int fib[45];

void fibonacci(int n)
{
    fib[0] = fib[1] = 1;
    for(int i = 2; i <= n; i++)
        fib[i] = fib[i - 1] + fib[i - 2];
}

int main()
{
    int n;
    cin >> n;
    fibonacci(n);
    cout << fib[n] << endl;
}



Measured memory_bytes: 3096
#include <stdio.h>
int main(void){
    int A,B;
    scanf("%d %d",&A,&B);

    if(A==1&&B==1){
        //draw
        printf("Draw\n");
    }else if(A==1){
        //alice
        printf("Alice\n");
    }else if(B==1){
        //bob
        printf("Bob\n");
    }else{
        if(A==B){
            printf("Draw\n");
        }else if(A>B){
            printf("Alice\n");
        }else{
            printf("Bob\n");
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define LL long long
#define rl r-l+1
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    cout<<"ABC"<<n<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

typedef struct {char a,b;} Card;

void bs(Card[],int);
void ss(Card[],int);
void str(Card*,char[]);
void print(Card[],int);

int isStable(Card[],Card[],int);

void bs(Card x[],int y){
    int i,j;
    Card v;

/*    for(i=0;i<=y;i++){*/
    for(i=0;i<y;i++){
        for(j=y-1;j>=i;j--){
            if(x[j].b<x[j-1].b){
                v=x[j];
                x[j]=x[j-1];
                x[j-1]=v;
            }
        }
    }
    return;
}

void ss(Card s[],int t){
    int i,j,minj;
    Card h;
    for(i=0;i<t;i++){
/*    for(i=0;i<=t;i++){ */
        minj=i;
        for(j=i;j<t;j++){
            if(s[minj].b>s[j].b){
                minj=j;
            }
        }
        h=s[minj];
        s[minj]=s[i];
        s[i]=h;
    }
    return;
}
void str(Card *u,char str[]){
    u->a=str[0];
    u->b=str[1]-'0';
    return;
}
void print(Card q[],int r){
    int i;
    for(i=0;i<r;i++){
        if(i!=0){
            printf(" ");
        }
        printf("%c%d",q[i].a,q[i].b);
    }
    printf("\n");
/*    return;*/
}
int isStable(Card a[],Card b[],int n){
    int i;

    for(i=0;i<n;i++){
/*    for(i=0;i<=n;i++){ */
        if(a[i].a!=b[i].a){
            return 0;
        }
    }
    return 1;
}
int main(void){
    int a,d,n;
/*    int a,d,N,n; */
    char ch[3];
    scanf("%d",&n);
/*
    scanf("%d",&N);
    n=N-1;
*/
    Card C1[100],C2[100];
/*    Card C1[n],C2[n];*/
    for(d=0;d<n;d++){
/*    for(d=0;d<=n;d++){ */
        scanf("%s",ch);
        str(&C1[d],ch);
    }
    for(d=0;d<n;d++){
/*    for(d=0;d<=n;d++){ */
        C2[d]=C1[d];
    }
    bs(C1,n);
    ss(C2,n);
    print(C1,n);
    printf("Stable\n");
    print(C2,n);
    a=isStable(C1,C2,n);
    if(a==1){
        printf("Stable\n");
    }
    else if(a==0){
        printf("Not stable\n");
    }
    return 0;
}



Measured memory_bytes: 2040
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>


using namespace std;



int main() {
	int N;
	int sum = 0;

	cin >> N;
	vector<int> v(N);
	vector<int> c(N);

	for (int i = 0; i < N; i++)
		cin >> v[i];

	for (int i = 0; i < N; i++)
		cin >> c[i];

	for (int i = 0; i < N; i++) {
		if (v[i] > c[i])
			sum += v[i] - c[i];
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
#define rep(x,from,to) for(int x=(from);(x)<=(to);(x)++)

int n, s;
int main() {
	while(1) {
		cin >> n >> s;
		if(n == 0 && s == 0) break;
		int ret = 0;
		rep(i,1,n) {
			for(int j = 1; j <= n, j != i; ++j) {
				for(int k = 1; k <= n, k != i, k != j; ++k) {
					if(i + j + k == s) ++ret;
				}
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main() {
    string S;
    cin >> S;
    bool flg = true;
    for (int i=0; i<S.length(); i++) {
        if (i % 2 == 0) {
            if (S[i] != 'R' && S[i] != 'U' && S[i] != 'D') {
               flg = false;
               break;
            }
        } else {
            if (S[i] != 'L' && S[i] != 'U' && S[i] != 'D') {
               flg = false;
               break;
            }
        }
    }
    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n" 
#define pi 3.1415926536
#define mod  1000003
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    set<string> s;
    int n;cin>>n;
    while(n--){
        string a;cin>>a;
        s.insert(a);
        
    }
    cout<<s.size();
    
    
    
    return 0;
  
}

Measured memory_bytes: 19212